Esempio n. 1
0
    def unique_intersection_predicate(self) -> mona.Formula:
        x = mona.Variable("x")
        y = mona.Variable("y")
        one_states = [mona.Variable(f"one{s}") for s in self.system.states]
        two_states = [mona.Variable(f"two{s}") for s in self.system.states]
        pairs = list(zip(one_states, two_states))

        statements: List[mona.Formula] = []
        # fix x in intersection of one state:
        for pair in pairs:
            pos = [cast(mona.Formula, mona.ElementIn(x, state))
                   for state in pair]
            different_pairs = [p for p in pairs if p != pair]
            neg = [  # negated statement from above
                    cast(mona.Formula, mona.Negation(
                        mona.Conjunction(
                            [mona.ElementIn(x, state) for state in pair])))
                    # for all other pairs
                    for pair in different_pairs]
            statements.append(mona.Conjunction(pos + neg))
        fix_x = mona.Disjunction(statements)
        # make sure x is unique:
        # y is in intersection
        y_in_intersection = mona.Disjunction([
            mona.Conjunction([mona.ElementIn(y, state) for state in pair])
            for pair in pairs])
        # y is x if y is in intersection
        unique_x = mona.UniversalFirstOrder(
                [y],
                mona.Implication(y_in_intersection, mona.Equal(x, y)))
        formula = mona.ExistentialFirstOrder([x], mona.Conjunction([fix_x,
                                                                    unique_x]))
        return mona.PredicateDefinition(
                "unique_intersection",
                one_states + two_states, [], formula).simplify()
Esempio n. 2
0
 def intersects_initial_predicate(self) -> mona.Formula:
     x = mona.Variable("x")
     initial_states = [mona.Variable(c.initial_state)
                       for c in self.system.components]
     x_initial = mona.Disjunction(
             [mona.ElementIn(x, init) for init in initial_states])
     formula = mona.ExistentialFirstOrder([x], x_initial)
     return mona.PredicateDefinition("intersects_initial",
                                     self.system.state_variables,
                                     [], formula).simplify()
Esempio n. 3
0
 def intersection_predicate(self) -> mona.Formula:
     x = mona.Variable("x")
     one_states = [mona.Variable(f"one{s}") for s in self.system.states]
     two_states = [mona.Variable(f"two{s}") for s in self.system.states]
     in_both_states = cast(List[mona.Formula],
                           [mona.Conjunction([mona.ElementIn(x, o),
                                              mona.ElementIn(x, t)])
                            for o, t in zip(one_states, two_states)])
     quantified_formula = mona.ExistentialFirstOrder(
             [x], mona.Disjunction(in_both_states))
     return mona.PredicateDefinition("intersection",
                                     one_states + two_states,
                                     [], quantified_formula
                                     ).simplify()
Esempio n. 4
0
 def marking_predicate(self) -> mona.Formula:
     m = mona.Variable("m")
     unique_in_component = mona.UniversalFirstOrder(
             [m],
             mona.Conjunction([
                 mona.Disjunction([
                     mona.Conjunction(
                         [cast(mona.Formula, mona.ElementIn(m, pos))]
                         + [cast(mona.Formula, mona.ElementNotIn(m, neg))
                            for neg in c.state_variables
                            if neg != pos])
                     for pos in c.state_variables])
                 for c in self.system.components]))
     flow_invariant = mona.PredicateCall("flow_invariant",
                                         self.system.state_variables)
     trap_invariant = mona.PredicateCall("trap_invariant",
                                         self.system.state_variables)
     return mona.PredicateDefinition(
             "marking",
             self.system.state_variables,
             [],
             mona.Conjunction([
                 unique_in_component,
                 flow_invariant,
                 trap_invariant,
             ])).simplify()
Esempio n. 5
0
 def miss_post(self) -> mona.ElementNotIn:
     argument = self.argument.as_mona()
     if not type(argument) is mona.Variable:
         raise FormulaError(f"Predicate {self} is not normalized")
     argument = cast(mona.Variable, argument)
     return mona.ElementNotIn(
             argument,
             mona.Variable(self.post))
Esempio n. 6
0
 def trap_invariant_predicate(self) -> mona.Formula:
     trap_states = [mona.Variable(f"T{s}") for s in self.system.states]
     precondition = mona.PredicateCall("initially_marked_trap", trap_states)
     postcondition = mona.PredicateCall(
             "intersection",
             trap_states + self.system.state_variables)
     return mona.PredicateDefinition(
             "trap_invariant",
             self.system.state_variables,
             [],
             mona.UniversalSecondOrder(trap_states,
                                       mona.Implication(precondition,
                                                        postcondition))
             ).simplify()
Esempio n. 7
0
 def flow_invariant_predicate(self) -> mona.Formula:
     flow_states = [mona.Variable(f"F{s}") for s in self.system.states]
     precondition = mona.PredicateCall(
             "initially_uniquely_marked_flow",
             flow_states)
     postcondition = mona.PredicateCall(
             "unique_intersection",
             flow_states + self.system.state_variables)
     return mona.PredicateDefinition(
             "flow_invariant",
             self.system.state_variables,
             [], mona.UniversalSecondOrder(
                 flow_states, mona.Implication(precondition, postcondition))
             ).simplify()
Esempio n. 8
0
 def uniquely_intersects_initial_predicate(self) -> mona.Formula:
     x = mona.Variable("x")
     y = mona.Variable("y")
     initial_states = [mona.Variable(c.initial_state)
                       for c in self.system.components]
     statements: List[mona.Formula] = []
     for init in initial_states:
         other_initial_states = [i for i in initial_states if i != init]
         x_only_in_init = mona.Conjunction(
                 [cast(mona.Formula, mona.ElementIn(x, init))]
                 + [cast(mona.Formula, mona.ElementNotIn(x, i))
                    for i in other_initial_states])
         statements.append(x_only_in_init)
     x_in_only_one_initial = mona.Disjunction(statements)
     y_in_initial = mona.Disjunction(
             [mona.ElementIn(y, i) for i in initial_states])
     x_unique = mona.UniversalFirstOrder([y], mona.Implication(
         y_in_initial, mona.Equal(x, y)))
     formula = mona.ExistentialFirstOrder(
             [x],
             mona.Conjunction([x_in_only_one_initial, x_unique]))
     return mona.PredicateDefinition(
             "uniquely_intersects_initial",
             self.system.state_variables, [], formula).simplify()
Esempio n. 9
0
 def as_mona(self):
     return mona.Variable(self.name)
Esempio n. 10
0
 def state_variables(self) -> List[mona.Variable]:
     return sorted([mona.Variable(s) for s in self.states],
                   key=str)  # type: ignore # noqa: E501, F723
Esempio n. 11
0
 def state_variables(self) -> List[mona.Variable]:
     return sorted([mona.Variable(s) for s in self.states], key=str)