def do_bit(bit): if bit == 'true': return True valid = eval_model_bool(m, bit) if simplify: # looks a bit strange to do this now but some pointer # lookups have to be done with unmodified s-exprs bit = simplify_sexp(bit, rep, m, flatten=False) print ' %s: %s' % (valid, solver.flat_s_expression(bit)) return valid
def investigate_cond(rep, m, cond, simplify=True, rec=True): cond_def = rep.solv.defs[cond] while rec and type(cond_def) == str and cond_def in rep.solv.defs: cond_def = rep.solv.defs[cond_def] bits = solver.split_hyp_sexpr(cond_def, []) for bit in bits: if bit == "true": continue valid = eval_model_bool(m, bit) if simplify: # looks a bit strange to do this now but some pointer # lookups have to be done with unmodified s-exprs bit = simplify_sexp(bit, rep, m, flatten=False) print " %s: %s" % (valid, solver.flat_s_expression(bit))
def simplify_sexp(smt_xp, rep, m, flatten=True): if type(smt_xp) == str: smt_xp = solver.parse_s_expression(smt_xp) if smt_xp[0] == "ite": (_, c, x, y) = smt_xp if eval_model_bool(m, c): return simplify_sexp(x, rep, m, flatten) else: return simplify_sexp(y, rep, m, flatten) if type(smt_xp) == tuple: smt_xp = tuple([simplify_sexp(x, rep, m, False) for x in smt_xp]) if flatten: return solver.flat_s_expression(smt_xp) else: return smt_xp
def simplify_sexp(smt_xp, rep, m, flatten=True): if type(smt_xp) == str: smt_xp = solver.parse_s_expression(smt_xp) if smt_xp[0] == 'ite': (_, c, x, y) = smt_xp if eval_model_bool(m, c): return simplify_sexp(x, rep, m, flatten) else: return simplify_sexp(y, rep, m, flatten) if type(smt_xp) == tuple: smt_xp = tuple([simplify_sexp(x, rep, m, False) for x in smt_xp]) if flatten: return solver.flat_s_expression(smt_xp) else: return smt_xp
def simplify_expr_whyps(sexpr, rep, hyps, cache=None, extra_defs={}, bool_hyps=None): if cache == None: cache = {} if bool_hyps == None: bool_hyps = [] if sexpr in extra_defs: sexpr = extra_defs[sexpr] if sexpr in rep.solv.defs: sexpr = rep.solv.defs[sexpr] if sexpr[0] == 'ite': (_, cond, x, y) = sexpr cond_exp = solver.mk_smt_expr(solver.flat_s_expression(cond), syntax.boolT) (mk_nimp, mk_not) = (syntax.mk_n_implies, syntax.mk_not) if rep.test_hyp_whyps(mk_nimp(bool_hyps, cond_exp), hyps, cache=cache): return x elif rep.test_hyp_whyps(mk_nimp(bool_hyps, mk_not(cond_exp)), hyps, cache=cache): return y x = simplify_expr_whyps(x, rep, hyps, cache=cache, extra_defs=extra_defs, bool_hyps=bool_hyps + [cond_exp]) y = simplify_expr_whyps(y, rep, hyps, cache=cache, extra_defs=extra_defs, bool_hyps=bool_hyps + [syntax.mk_not(cond_exp)]) if x == y: return x return ('ite', cond, x, y) return sexpr
def simplify_expr_whyps (sexpr, rep, hyps, cache = None, extra_defs = {}): if cache == None: cache = {} if sexpr in extra_defs: sexpr = extra_defs[sexpr] if sexpr[0] == 'ite': (_, cond, x, y) = sexpr cond_exp = solver.mk_smt_expr (solver.flat_s_expression (cond), syntax.boolT) if rep.test_hyp_whyps (cond_exp, hyps, cache = cache): return x elif rep.test_hyp_whyps (syntax.mk_not (cond_exp), hyps, cache = cache): return y x = simplify_expr_whyps (x, rep, hyps, cache = cache, extra_defs = extra_defs) y = simplify_expr_whyps (y, rep, hyps, cache = cache, extra_defs = extra_defs) if x == y: return x return ('ite', cond, x, y) return sexpr
def unfold_defs(defs, hyp, depthlimit=-1): return solver.flat_s_expression(unfold_defs_sexpr(defs, solver.parse_s_expression(hyp), depthlimit))
def unfold_defs(defs, hyp, depthlimit=-1): return solver.flat_s_expression( unfold_defs_sexpr(defs, solver.parse_s_expression(hyp), depthlimit))