def localize(property:SpecProperty): """ sound, but incomplete forall(i) a_i -> forall(j) g_j => forall(i) (a_i -> g_i) forall(i,j) a_i_j -> forall(k) g_k => forall(i,j) (a_i_j -> g_i) """ if not is_quantified_property(property): return property normalized_ass = normalize_conjuncts(property.assumptions) normalized_gua = normalize_conjuncts(property.guarantees) binding_indices_ass = _get_indices(normalized_ass) binding_indices_gua = _get_indices(normalized_gua) if len(binding_indices_ass) > len(binding_indices_gua): max_expr, other_expr = normalized_ass, normalized_gua else: max_expr, other_expr = normalized_gua, normalized_ass assert isinstance(max_expr, ForallExpr) max_binding_indices = max_expr.arg1 ass_newindex_by_old = dict((o, max_binding_indices[i]) for i, o in enumerate(binding_indices_ass)) gua_newindex_by_old = dict((o, max_binding_indices[i]) for i, o in enumerate(binding_indices_gua)) replaced_ass = _replace_indices(ass_newindex_by_old, normalized_ass) replaced_gua = _replace_indices(gua_newindex_by_old, normalized_gua) replaced_underlying_ass = replaced_ass.arg2 if is_quantified_expr(replaced_ass) else replaced_ass replaced_underlying_gua = replaced_gua.arg2 if is_quantified_expr(replaced_gua) else replaced_gua new_gua = ForallExpr(max_binding_indices, BinOp('->', replaced_underlying_ass, replaced_underlying_gua)) new_property = SpecProperty([Bool(True)], [new_gua]) return new_property
def _denormalize(conjunct:Expr) -> list: """ Forall(i) a_i and b_i replaced by Forall(i) a_i and Forall(i) b_i """ normalized_conjunct = normalize_conjuncts([conjunct]) if not is_quantified_property(SpecProperty([normalized_conjunct], [])): return [normalized_conjunct] #: :type: ForallExpr forall_expr = conjunct quantified_expr = forall_expr.arg2 conjunctions = _get_conjuncts(quantified_expr) return [_reduce_quantifiers(ForallExpr(forall_expr.arg1, c)) for c in conjunctions]
def _get_rank(property:SpecProperty) -> int: if not is_quantified_property(property): return 0 #forall(i) a_i -> g_0 # since the initial token distribution is random # <=> #forall(i) a_i -> forall(i) g_i, which is 2-indexed # a_0 -> forall(i) g_i # <=> ??? # (exists(i) a_i) -> forall(i) g_i, which is 2-indexed # # Currently we forbid concrete assumptions/guarantees ass_max_len = max(map(lambda e: len(e.arg1) if is_quantified_expr(e) else 0, property.assumptions)) gua_max_len = max(map(lambda e: len(e.arg1) if is_quantified_expr(e) else 0, property.guarantees)) rank = ass_max_len + gua_max_len return rank
def _get_rank(property: SpecProperty) -> int: if not is_quantified_property(property): return 0 #forall(i) a_i -> g_0 # since the initial token distribution is random # <=> #forall(i) a_i -> forall(i) g_i, which is 2-indexed # a_0 -> forall(i) g_i # <=> ??? # (exists(i) a_i) -> forall(i) g_i, which is 2-indexed # # Currently we forbid concrete assumptions/guarantees ass_max_len = max( map(lambda e: len(e.arg1) if is_quantified_expr(e) else 0, property.assumptions)) gua_max_len = max( map(lambda e: len(e.arg1) if is_quantified_expr(e) else 0, property.guarantees)) rank = ass_max_len + gua_max_len return rank
def is_quantified_expr(expr: Expr): return is_quantified_property(SpecProperty([], [expr]))
def is_quantified_expr(expr:Expr): return is_quantified_property(SpecProperty([], [expr]))