mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 00:55:31 +00:00
Add simplification customization for SMTLIB2
Add the ability to customize incremental pre-processing simplification for the SMTLIB2 front-end. The main new capability is to use pre-processing tactics in incremental mode that were previously not available. The main new capabilities are - solve-eqs - reduce-args - elim-unconstrained There are several more. Documentation and exposed simplifiers are populated incrementally. The current set of supported simplifiers can be inspected by using z3 with the --simplifiers flag or referring to https://microsoft.github.io/z3guide/docs/strategies/simplifiers Some pending features are: - add the ability to update parameters to simplifiers similar to how tactics can be controlled using parameters. - expose simplification solvers over the binary API.
This commit is contained in:
parent
dd0decfe5d
commit
6022c17131
32 changed files with 370 additions and 69 deletions
|
@ -672,6 +672,7 @@ def mk_install_tactic_cpp_internal(h_files_full_path, path):
|
|||
components.
|
||||
"""
|
||||
ADD_TACTIC_DATA = []
|
||||
ADD_SIMPLIFIER_DATA = []
|
||||
ADD_PROBE_DATA = []
|
||||
def ADD_TACTIC(name, descr, cmd):
|
||||
ADD_TACTIC_DATA.append((name, descr, cmd))
|
||||
|
@ -679,9 +680,13 @@ def mk_install_tactic_cpp_internal(h_files_full_path, path):
|
|||
def ADD_PROBE(name, descr, cmd):
|
||||
ADD_PROBE_DATA.append((name, descr, cmd))
|
||||
|
||||
def ADD_SIMPLIFIER(name, descr, cmd):
|
||||
ADD_SIMPLIFIER_DATA.append((name, descr, cmd))
|
||||
|
||||
eval_globals = {
|
||||
'ADD_TACTIC': ADD_TACTIC,
|
||||
'ADD_PROBE': ADD_PROBE,
|
||||
'ADD_SIMPLIFIER': ADD_SIMPLIFIER
|
||||
}
|
||||
|
||||
assert isinstance(h_files_full_path, list)
|
||||
|
@ -691,9 +696,11 @@ def mk_install_tactic_cpp_internal(h_files_full_path, path):
|
|||
fout.write('// Automatically generated file.\n')
|
||||
fout.write('#include "tactic/tactic.h"\n')
|
||||
fout.write('#include "cmd_context/tactic_cmds.h"\n')
|
||||
fout.write('#include "cmd_context/simplifier_cmds.h"\n')
|
||||
fout.write('#include "cmd_context/cmd_context.h"\n')
|
||||
tactic_pat = re.compile('[ \t]*ADD_TACTIC\(.*\)')
|
||||
probe_pat = re.compile('[ \t]*ADD_PROBE\(.*\)')
|
||||
probe_pat = re.compile('[ \t]*ADD_PROBE\(.*\)')
|
||||
simplifier_pat = re.compile('[ \t]*ADD_SIMPLIFIER\(.*\)')
|
||||
for h_file in sorted_headers_by_component(h_files_full_path):
|
||||
added_include = False
|
||||
try:
|
||||
|
@ -719,17 +726,31 @@ def mk_install_tactic_cpp_internal(h_files_full_path, path):
|
|||
_logger.error("Failed processing ADD_PROBE command at '{}'\n{}".format(
|
||||
fullname, line))
|
||||
raise e
|
||||
if simplifier_pat.match(line):
|
||||
if not added_include:
|
||||
added_include = True
|
||||
fout.write('#include "%s"\n' % path_after_src(h_file))
|
||||
try:
|
||||
eval(line.strip('\n '), eval_globals, None)
|
||||
except Exception as e:
|
||||
_logger.error("Failed processing ADD_SIMPLIFIER command at '{}'\n{}".format(
|
||||
fullname, line))
|
||||
raise e
|
||||
|
||||
except Exception as e:
|
||||
_logger.error("Failed to read file {}\n".format(h_file))
|
||||
raise e
|
||||
# First pass will just generate the tactic factories
|
||||
fout.write('#define ADD_TACTIC_CMD(NAME, DESCR, CODE) ctx.insert(alloc(tactic_cmd, symbol(NAME), DESCR, [](ast_manager &m, const params_ref &p) { return CODE; }))\n')
|
||||
fout.write('#define ADD_PROBE(NAME, DESCR, PROBE) ctx.insert(alloc(probe_info, symbol(NAME), DESCR, PROBE))\n')
|
||||
fout.write('#define ADD_SIMPLIFIER_CMD(NAME, DESCR, FUNCTION) ctx.insert(alloc(simplifier_cmd, symbol(NAME), DESCR, FUNCTION))\n')
|
||||
fout.write('void install_tactics(tactic_manager & ctx) {\n')
|
||||
for data in ADD_TACTIC_DATA:
|
||||
fout.write(' ADD_TACTIC_CMD("%s", "%s", %s);\n' % data)
|
||||
for data in ADD_PROBE_DATA:
|
||||
fout.write(' ADD_PROBE("%s", "%s", %s);\n' % data)
|
||||
for data in ADD_SIMPLIFIER_DATA:
|
||||
fout.write(' ADD_SIMPLIFIER_CMD("%s", "%s", %s);\n' % data)
|
||||
fout.write('}\n')
|
||||
fout.close()
|
||||
return fullname
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue