def __init__(self, term_signature, spec):
        super().__init__()
        self.term_signature = term_signature
        self.synth_funs = spec.synth_funs
        self.spec = spec
        self.syn_ctx = self.spec.syn_ctx
        self.point_var_exprs =  [ exprs.VariableExpression(v) for v in spec.point_vars ]

        self.smt_ctx = z3smt.Z3SMTContext()
        self.eval_ctx = evaluation.EvaluationContext()
        self.canon_apps = [ self.spec.canon_application[sf] for sf in self.synth_funs ]

        self.outvars = []
        for fn in self.synth_funs:
            self.outvars.append(
                    exprs.VariableExpression(exprs.VariableInfo(
                        exprtypes.IntType(), 'outvar_' + fn.function_name,
                        len(self.point_var_exprs) + len(self.outvars))))
        self.all_vars = self.point_var_exprs + self.outvars
        self.all_vars_z3 = [ _expr_to_smt(v, self.smt_ctx) for v in self.all_vars ]

        # self.clauses = spec.get_canon_clauses()
        self.lia_clauses = [ [ 
            LIAInequality.from_expr(exprs.substitute_all(disjunct, list(zip(self.canon_apps, self.outvars))))
            for disjunct in clause  ]
            for clause in spec.get_canon_clauses() ]
        self.rewritten_spec = exprs.substitute_all(
                self.spec.get_canonical_specification(),
                list(zip(self.canon_apps, self.outvars)))
Esempio n. 2
0
    def __init__(self, syn_ctx, spec):
        self.syn_ctx = syn_ctx
        self.spec = spec
        self.synth_funs = syn_ctx.get_synth_funs()

        self.smt_ctx = z3smt.Z3SMTContext()
        self.smt_solver = self.smt_ctx.make_solver()

        # This var_info_list is the order of variables in cex points
        self.var_info_list = spec.get_point_variables()
        var_expr_list = [
            exprs.VariableExpression(x) for x in self.var_info_list
        ]
        self.var_smt_expr_list = [
            _expr_to_smt(x, self.smt_ctx) for x in var_expr_list
        ]

        self.intro_vars = spec.get_intro_vars()
        self.smt_intro_vars = [
            _expr_to_smt(x, self.smt_ctx) for x in self.intro_vars
        ]

        fun_apps = [
            syn_ctx.make_function_expr(f, *self.intro_vars)
            for f in self.synth_funs
        ]
        fun_app_subst_vars = [
            syn_ctx.make_variable_expr(f.range_type,
                                       '__output__' + f.function_name)
            for f in self.synth_funs
        ]
        self.outvar_cnstr = syn_ctx.make_function_expr(
            'and', *[
                syn_ctx.make_function_expr('eq', v, a)
                for (v, a) in zip(fun_app_subst_vars, fun_apps)
            ])
        self.canon_spec = spec.get_canonical_specification()
        canon_spec_with_outvar = exprs.substitute_all(
            self.canon_spec, list(zip(fun_apps, fun_app_subst_vars)))
        neg_canon_spec_with_outvar = syn_ctx.make_function_expr(
            'not', canon_spec_with_outvar)
        self.frozen_smt_cnstr = _expr_to_smt(neg_canon_spec_with_outvar,
                                             self.smt_ctx)
        self.smt_solver.push()
        self.smt_solver.add(self.frozen_smt_cnstr)
Esempio n. 3
0
    def __init__(self, syn_ctx, spec):
        self.syn_ctx = syn_ctx
        self.spec = spec

        self.canon_spec = spec.get_canonical_specification()
        self.neg_canon_spec = syn_ctx.make_function_expr(
            'not', self.canon_spec)
        self.synth_funs = syn_ctx.get_synth_funs()

        self.smt_ctx = z3smt.Z3SMTContext()
        self.smt_solver = self.smt_ctx.make_solver()
        self.var_info_list = spec.get_point_variables()

        var_expr_list = [
            exprs.VariableExpression(x) for x in self.var_info_list
        ]
        self.var_smt_expr_list = [
            _expr_to_smt(x, self.smt_ctx) for x in var_expr_list
        ]
Esempio n. 4
0
def dt_rewrite_boolean_combs(syn_ctx, sol, synth_fun):
    orig_sol = sol
    smt_ctx = z3smt.Z3SMTContext()
    vs = exprs.get_all_variables(sol)
    dummy_vars = [
        exprs.VariableExpression(
            exprs.VariableInfo(v.variable_info.variable_type,
                               "D" + v.variable_info.variable_name, i))
        for (i, v) in enumerate(vs)
    ]
    argvars = [
        semantics.semantics_types.expression_to_smt(v, smt_ctx)
        for v in dummy_vars
    ]
    sol = exprs.substitute_all(sol, list(zip(vs, dummy_vars)))
    preds = get_atomic_preds(sol)
    terms = get_terms(sol)

    points = []

    from exprs import evaluation
    eval_ctx = evaluation.EvaluationContext()

    def add_point(point, pred_sig_list, term_sig_list):
        points.append(point)
        eval_ctx.set_valuation_map(point)
        solv = evaluation.evaluate_expression_raw(sol, eval_ctx)
        new_pred_sig_list = [
            utils.bitset_extend(
                sig, evaluation.evaluate_expression_raw(pred, eval_ctx))
            for (sig, pred) in zip(pred_sig_list, preds)
        ]
        new_term_sig_list = [
            utils.bitset_extend(
                sig,
                solv == evaluation.evaluate_expression_raw(term, eval_ctx))
            for (sig, term) in zip(term_sig_list, terms)
        ]
        return (new_pred_sig_list, new_term_sig_list)

    pred_sig_list = [BitSet(0) for p in preds]
    term_sig_list = [BitSet(0) for t in terms]

    expr = terms[0]
    fsol = None
    while True:
        z3point = exprs.sample(syn_ctx.make_function_expr('ne', expr, sol),
                               smt_ctx, argvars)
        if z3point is None:
            fsol = expr
            break
        else:
            point = list(
                map(lambda v, d: z3smt.z3value_to_value(v, d.variable_info),
                    z3point, dummy_vars))
            (pred_sig_list, term_sig_list) = add_point(point, pred_sig_list,
                                                       term_sig_list)
            dt = eusolver.eus_learn_decision_tree_for_ml_data(
                pred_sig_list, term_sig_list)
            expr = verifiers.naive_dt_to_expr(syn_ctx, dt, preds, terms)
    sol = exprs.substitute_all(fsol, list(zip(dummy_vars, vs)))
    return sol