def equivalentPairs( invL1: List[EsprimaNode], invL2: List[EsprimaNode], typeEnv: JSONTypeEnv, mturkId: MturkIdT ) -> List[Tuple[EsprimaNode, EsprimaNode]]: #pylint: disable=unused-argument """ Given lists of invariants invL1, invL2, return all pairs (I1, I2) where I1 <==> I2, I1 \in invL1, I2 \in invL2 Not currently in use. """ boogieEnv: BoogieTypeEnv = jsonToTypeEnv(typeEnv) z3Env: Z3TypeEnv = boogieToZ3TypeEnv(boogieEnv) z3InvL1 = [esprimaToZ3(x, z3Env) for x in invL1] z3InvL2 = [esprimaToZ3(x, z3Env) for x in invL2] res = [] for x in z3InvL1: for y in z3InvL2: try: equiv = equivalent(x, y) except Unknown: equiv = False # Conservative assumption if (equiv): res.append((x, y)) return [(boogieToEsprima(z3_expr_to_boogie(x)), boogieToEsprima(z3_expr_to_boogie(y))) for (x, y) in res]
def impliedPairs( invL1: List[EsprimaNode], invL2: List[EsprimaNode], typeEnv: JSONTypeEnv, mturkId: MturkIdT ) -> List[Tuple[EsprimaNode, EsprimaNode]]: #pylint: disable=unused-argument """ Given lists of invariants invL1, invL2, return all pairs (I1, I2) where I1 ==> I2, I1 \in invL1, I2 \in invL2 Used by game.html """ boogieEnv = jsonToTypeEnv(typeEnv) z3Env = boogieToZ3TypeEnv(boogieEnv) z3InvL1 = [esprimaToZ3(x, z3Env) for x in invL1] z3InvL2 = [esprimaToZ3(x, z3Env) for x in invL2] res = [] for x in z3InvL1: for y in z3InvL2: try: impl = implies(x, y) except Unknown: impl = False # Conservative assumption if (impl): res.append((x, y)) return [(boogieToEsprima(z3_expr_to_boogie(x)), boogieToEsprima(z3_expr_to_boogie(y))) for (x, y) in res]
def simplifyInv(inv: EsprimaNode, typeEnv: JSONTypeEnv, mturkId: MturkIdT) -> EsprimaNode: #pylint: disable=unused-argument """ Given an invariant inv return its 'simplified' version. We treat that as the canonical version of an invariant. Simplification is performed by z3 """ boogieEnv = jsonToTypeEnv(typeEnv) z3Env = boogieToZ3TypeEnv(boogieEnv) boogieInv = esprimaToBoogie(inv, {}) noDivBoogie = divisionToMul(boogieInv) z3_inv = expr_to_z3(noDivBoogie, z3Env) simpl_z3_inv = ccast(simplify(z3_inv, arith_lhs=True), z3.ExprRef) simpl_boogie_inv = z3_expr_to_boogie(simpl_z3_inv) return boogieToEsprima(simpl_boogie_inv)