Esempio n. 1
0
def ResetZ3():
    z3._main_ctx = None
    z3.main_ctx()
    z3.set_param('smt.random_seed',
                 random.SystemRandom().randint(0, sys.maxint))
    z3.set_param('smt.mbqi.max_iterations', 10000)
    z3.set_param('smt.mbqi.max_cexs', 100)
Esempio n. 2
0
def ResetZ3 ():
    z3._main_ctx = None
    z3.main_ctx()
    z3.set_param('auto_config', False)
    z3.set_param('smt.mbqi', True)
    z3.set_param('model.compact', True)
    z3.set_param('smt.pull_nested_quantifiers', True)
    z3.set_param('smt.mbqi.max_iterations', 10000)
    z3.set_param('smt.random_seed', random.SystemRandom().randint(0, sys.maxint))
Esempio n. 3
0
def define_fun_to_lambda(env, cmd):
    converter = pyz3.Z3Converter(env, z3.main_ctx())
    name, params, ret_sort, body = cmd.args
    zparams = [converter.convert(p) for p in params]
    zbody = converter.convert(body)
    res = z3.Lambda(zparams, zbody)
    return res
Esempio n. 4
0
 def _context(self):
     try:
         return self._tls.context
     except AttributeError:
         self._tls.context = z3.Context() if threading.current_thread(
         ).name != 'MainThread' else z3.main_ctx()
         return self._tls.context
Esempio n. 5
0
 def __init__(self, environment, logic=None):
     QuantifierEliminator.__init__(self)
     self.environment = environment
     self.logic = logic
     self.converter = Z3Converter(environment, z3.main_ctx())
     self._cache = {}
     self._cache_term = {}
Esempio n. 6
0
def is_sat(solver,f):
    solver.push()
    ctx = z3.main_ctx()
    z3.Z3_solver_assert(ctx.ref(), solver.solver, f.as_ast())
    #solver.add(f)
    res = solver.check() != z3.unsat
    solver.pop()
    return res
Esempio n. 7
0
def is_sat(solver, f):
    solver.push()
    ctx = z3.main_ctx()
    z3.Z3_solver_assert(ctx.ref(), solver.solver, f.as_ast())
    #solver.add(f)
    res = solver.check() != z3.unsat
    solver.pop()
    return res
Esempio n. 8
0
 def __init__(self, name="horn", simplify_queries=True, ctx=z3.main_ctx(), env = None):
     self._ctx = ctx
     self._name = name
     self._rules = []
     self._queries = []
     self._rels_set = frozenset()
     self._rels = dict()
     self._sealed = True
     self._fp = None
     self._env = env
     self._simple_query = simplify_queries
Esempio n. 9
0
    def __init__(
        self,
        params: Params,
        formula_params: FormulaParamsZ3,
    ):
        super().__init__(
            params,
            FormulaParamsZ3(
                # translates the contexts, thus the formula and variables need not be created with the context
                # the z3 runner will use
                formula=formula_params.formula.translate(z3.main_ctx())
                if formula_params.formula.ctx != z3.main_ctx() else
                formula_params.formula,
                variables=[
                    x.translate(z3.main_ctx()) if x.ctx != z3.main_ctx() else x
                    for x in formula_params.variables
                ],
            ))

        # maps q to a solver that has a q-times conjunction asserted
        self._solver_map: Dict[int, Tuple[z3.Solver, List[z3.BitVecRef]]] = {}
def get_behaviour_change_dt_from_constraintset(solver,
                                               constraints,
                                               dt,
                                               ctx=z3.main_ctx()):
    times = {
        cs: cs.check_behaviour_change(solver, dt, ctx)
        for cs in constraints
    }
    times = {cs: time for cs, time in times.items() if time is not None}
    if len(times) > 0:
        minimum = min(times, key=times.get)
        return times[minimum], minimum.label
    else:
        return None, None
Esempio n. 11
0
def main():
    db = load_horn_db_from_file(sys.argv[1], z3.main_ctx())
    print(db)
    print(db.get_rels())
    print(db._rels)
    rel = db.get_rel("main@_bb723")
    lemma_stream = io.StringIO(
        "(=> (< main@_bb723_0_n 1) (>= (+ main@_bb723_4_n main@_bb723_5_n) 0))"
    )
    lemma = rel.pysmt_parse_lemma(lemma_stream)
    print(lemma)
    print(lemma._content._asdict())
    # import json
    # json.dumps(lemma._content._asdict())
    return 0
Esempio n. 12
0
def z3_translate(x, ctx):
    """ A version of z3.AstRef.translate that handles sorts and function declarations correctly"""
    if x.ctx == ctx: return x
    if isinstance(x, z3.BoolSortRef): return z3.BoolSort(ctx=ctx)
    if z3.is_arith_sort(x):
        if x.is_int(): return z3.IntSort(ctx=ctx)
        else:
            assert x.is_real()
            return z3.RealSort(ctx=ctx)
    if isinstance(x, z3.FuncDeclRef):
        sorts = [z3_translate(x.domain(i), ctx) for i in range(x.arity())]
        sorts.append(z3_translate(x.range(), ctx))
        return z3.Function(x.name(), *sorts)
    if ctx is None: return x.translate(ctx=z3.main_ctx())
    return x.translate(ctx)
Esempio n. 13
0
 def btn_stop_thread_clicked(self):
     if self.current_worker_thread and self.current_worker_thread.isRunning():
         self.plugin.stop_analysis = True
         # woow hacky
         try:
             import z3
             frames = sys._current_frames().values()
             for f in frames:
                 if 'a0' in f.f_locals:
                     #print("Found Z3 frame: {}".format(f.f_code))
                     c = f.f_locals['a0']
                     ctx = z3.main_ctx()
                     ctx.ctx = c
                     ctx.interrupt()
                     break
             self.current_worker_thread.terminate()
         except:
             print("Ex: {}, {}".format(sys.exc_info(), frame.f_code))
         #print("Bla 2")
         if self.current_worker_thread.isRunning():
             print("Termination failed")
         else:
             print("Terminated thread")
Esempio n. 14
0
z3strlib.z3str_regexunion_decl.argtypes = []
z3strlib.z3str_regexconcat_decl.restype = z3.FuncDecl
z3strlib.z3str_regexconcat_decl.argtypes = []
z3strlib.z3str_unroll_decl.restype = z3.FuncDecl
z3strlib.z3str_unroll_decl.argtypes = []
z3strlib.z3str_regexdigit_decl.restype = z3.FuncDecl
z3strlib.z3str_regexdigit_decl.argtypes = []
z3strlib.z3str_register_vars.restype = None
z3strlib.z3str_register_vars.argtypes = [z3.Ast]
z3strlib.setAlphabet.restype = None
z3strlib.setAlphabet.argtypes = []
z3strlib.setAlphabet7bit.restype = None
z3strlib.setAlphabet7bit.argtypes = []

## Set the default Z3py context to use z3str
ctx = z3.main_ctx()
ctx.ctx = z3strlib.z3str_context()
z3strlib.setAlphabet7bit()

## Wrappers around the various z3str_*() functions in libz3str2.so
def StringSort():
  ctx = z3.main_ctx()
  sort = z3strlib.z3str_mk_string_sort()
  return z3.SortRef(sort, ctx)

def RegexSort():
  ctx = z3.main_ctx()
  sort = z3strlib.z3str_mk_regex_sort()
  return z3.SortRef(sort, ctx)

def string_concat():
Esempio n. 15
0
def ResetZ3 (seed):
    z3._main_ctx = None
    z3.main_ctx()
    z3.set_param('smt.random_seed', seed)
Esempio n. 16
0
def ResetZ3(seed):
    z3._main_ctx = None
    z3.main_ctx()
    z3.set_param('smt.random_seed', seed)
Esempio n. 17
0
File: z3.py Progetto: mpreiner/pysmt
 def __init__(self, environment, logic=None):
     Interpolator.__init__(self)
     self.environment = environment
     self.logic = logic
     self.converter = Z3Converter(environment, z3_ctx=z3.main_ctx())
Esempio n. 18
0
def ResetZ3 ():
    z3._main_ctx = None
    z3.main_ctx()
    z3.set_param('smt.random_seed', random.SystemRandom().randint(0, sys.maxint))
    z3.set_param('smt.mbqi.max_iterations', 10000)
    z3.set_param('smt.mbqi.max_cexs', 100)
Esempio n. 19
0
def ResetZ3():
    z3._main_ctx = None
    z3.main_ctx()
    z3.set_param('smt.random_seed',
                 random.SystemRandom().randint(0, sys.maxint))
Esempio n. 20
0
def my_and(*args):
    ctx = z3.main_ctx()
    _args, sz = z3._to_ast_array(args)
    return z3.BoolRef(z3.Z3_mk_and(ctx.ref(), sz, _args), ctx)
Esempio n. 21
0
def ResetZ3():
    z3._main_ctx = None
    z3.main_ctx()
Esempio n. 22
0
def load_horn_db_from_file(fname, context = z3.main_ctx(), env = None):
    fp = z3.Fixedpoint(ctx = context)
    queries = fp.parse_file(fname)
    db = HornClauseDb(fname, ctx = context, env = env)
    db.load_from_fp(fp, queries)
    return db
Esempio n. 23
0
def string_concat():
    ctx = z3.main_ctx()
    decl = z3strlib.z3str_concat_decl()
    return z3.FuncDeclRef(decl, ctx)
Esempio n. 24
0
def StringSort():
    ctx = z3.main_ctx()
    sort = z3strlib.z3str_mk_string_sort()
    return z3.SortRef(sort, ctx)
Esempio n. 25
0
def string_lastindexof():
    ctx = z3.main_ctx()
    decl = z3strlib.z3str_lastindexof_decl()
    return z3.FuncDeclRef(decl, ctx)
Esempio n. 26
0
def string_replace():
    ctx = z3.main_ctx()
    decl = z3strlib.z3str_replace_decl()
    return z3.FuncDeclRef(decl, ctx)
Esempio n. 27
0
def string_unroll():
  ctx = z3.main_ctx()
  decl = z3strlib.z3str_unroll_decl()
  return z3.FuncDeclRef(decl, ctx)
Esempio n. 28
0
def string_endswith():
    ctx = z3.main_ctx()
    decl = z3strlib.z3str_endswith_decl()
    return z3.FuncDeclRef(decl, ctx)
Esempio n. 29
0
def my_eq(x, y):
    ctx = z3.main_ctx()
    #    print "my_eq: {} = {}".format(x,y)
    return z3.BoolRef(z3.Z3_mk_eq(ctx.ref(), x.as_ast(), y.as_ast()), ctx)
Esempio n. 30
0
def my_eq(x, y):
    ctx = z3.main_ctx()
    return z3.BoolRef(z3.Z3_mk_eq(ctx.ref(), x.as_ast(), y.as_ast()), ctx)
Esempio n. 31
0
def my_eq(x, y):
    ctx = z3.main_ctx()
    #    print "my_eq: {} = {}".format(x,y)
    return z3.BoolRef(z3.Z3_mk_eq(ctx.ref(), x.as_ast(), y.as_ast()), ctx)
Esempio n. 32
0
#z3strlib.z3str_regexconcat_decl.argtypes = []
#z3strlib.z3str_unroll_decl.restype = z3.FuncDecl
#z3strlib.z3str_unroll_decl.argtypes = []
#z3strlib.z3str_regexdigit_decl.restype = z3.FuncDecl
#z3strlib.z3str_regexdigit_decl.argtypes = []
z3strlib.z3str_register_vars.restype = None
z3strlib.z3str_register_vars.argtypes = [z3.Ast]
z3strlib.setAlphabet.restype = None
z3strlib.setAlphabet.argtypes = []
z3strlib.setAlphabet7bit.restype = None
z3strlib.setAlphabet7bit.argtypes = []
z3strlib.z3str_basic_str_var_axioms.restype = None
z3strlib.z3str_basic_str_var_axioms.argtypes = []

## Set the default Z3py context to use z3str
ctx = z3.main_ctx()
ctx.ctx = z3strlib.z3str_mk_context()
z3strlib.setAlphabet7bit()


## Wrappers around the various z3str_*() functions in libz3str2.so
def StringSort():
    ctx = z3.main_ctx()
    sort = z3strlib.z3str_mk_string_sort()
    return z3.SortRef(sort, ctx)


"""
def RegexSort():
  ctx = z3.main_ctx()
  sort = z3strlib.z3str_mk_regex_sort()
Esempio n. 33
0
def StringSort():
  ctx = z3.main_ctx()
  sort = z3strlib.z3str_mk_string_sort()
  return z3.SortRef(sort, ctx)
Esempio n. 34
0
File: z3.py Progetto: mpreiner/pysmt
 def __init__(self, environment, logic=None):
     QuantifierEliminator.__init__(self)
     self.environment = environment
     self.logic = logic
     self.converter = Z3Converter(environment, z3.main_ctx())
Esempio n. 35
0
def string_concat():
  ctx = z3.main_ctx()
  decl = z3strlib.z3str_concat_decl()
  return z3.FuncDeclRef(decl, ctx)
Esempio n. 36
0
 def __init__(self, environment, logic=None):
     Interpolator.__init__(self)
     self.environment = environment
     self.logic = logic
     self.converter = Z3Converter(environment, z3_ctx=z3.main_ctx())
Esempio n. 37
0
def string_substring():
  ctx = z3.main_ctx()
  decl = z3strlib.z3str_substring_decl()
  return z3.FuncDeclRef(decl, ctx)
Esempio n. 38
0
 def _context(self):
     try:
         return self._tls.context
     except AttributeError:
         self._tls.context = z3.Context() if threading.current_thread().name != 'MainThread' else z3.main_ctx()
         return self._tls.context
Esempio n. 39
0
def convertAstToZ3(triton_ctx, ast_node):
    return z3.ExprRef(_convertAstToZ3(triton_ctx, z3.main_ctx().ctx, ast_node))
Esempio n. 40
0
#!/usr/bin/env python3
import z3
from z3 import *
import sys
import random

z3._main_ctx = None
z3.main_ctx()
z3.set_param('smt.random_seed', random.SystemRandom().randint(0, sys.maxsize))

a = z3.Int('a')
b = z3.Int('b')
c = z3.Int('c')

f = z3.Function('f', IntSort(), IntSort())
s = z3.Solver()
# s.add(ForAll([a, b], (c == f(a+b)) == (c == a+f(b)) == (c == f(a)+b)))
s.add(ForAll([a, b], f(a + b) == a + f(b)))

x = z3.Int('x')
y = z3.Int('y')
s.add(f(x + y) != x + f(y))
print(s.check())
Esempio n. 41
0
def ResetZ3 ():
    z3._main_ctx = None
    z3.main_ctx()
    z3.set_param('smt.random_seed', random.SystemRandom().randint(0, sys.maxint))
Esempio n. 42
0
def string_replace():
  ctx = z3.main_ctx()
  decl = z3strlib.z3str_replace_decl()
  return z3.FuncDeclRef(decl, ctx)
Esempio n. 43
0
def string_substring():
    ctx = z3.main_ctx()
    decl = z3strlib.z3str_substring_decl()
    return z3.FuncDeclRef(decl, ctx)
Esempio n. 44
0
def string_regexdigit():
  ctx = z3.main_ctx()
  decl = z3strlib.z3str_regexdigit_decl()
  return z3.FuncDeclRef(decl, ctx)
Esempio n. 45
0
def string_indexof2():
    ctx = z3.main_ctx()
    decl = z3strlib.z3str_indexof2_decl()
    return z3.FuncDeclRef(decl, ctx)
Esempio n. 46
0
def RegexSort():
  ctx = z3.main_ctx()
  sort = z3strlib.z3str_mk_regex_sort()
  return z3.SortRef(sort, ctx)
Esempio n. 47
0
def my_and(*args):
    ctx = z3.main_ctx()
    _args, sz = z3._to_ast_array(args)
    return z3.BoolRef(z3.Z3_mk_and(ctx.ref(), sz, _args), ctx)
Esempio n. 48
0
def string_length():
  ctx = z3.main_ctx()
  decl = z3strlib.z3str_length_decl()
  return z3.FuncDeclRef(decl, ctx)
Esempio n. 49
0
def my_eq(x,y):
    ctx = z3.main_ctx()
    return z3.BoolRef(z3.Z3_mk_eq(ctx.ref(), x.as_ast(), y.as_ast()), ctx)
Esempio n. 50
0
def string_indexof():
  ctx = z3.main_ctx()
  decl = z3strlib.z3str_indexof_decl()
  return z3.FuncDeclRef(decl, ctx)
Esempio n. 51
0
def ResetZ3 ():
    z3._main_ctx = None
    z3.main_ctx()