Exemple #1
0
    def _build_label_from_proc_index(self, proc_index: int) -> Label:
        bits = bin_fixed_list(proc_index, self._nof_proc_bits)

        label = Label(
            dict(zip(map(lambda at: at[0], self._proc_arg_type_pairs), bits)))

        return label
Exemple #2
0
def to_boolean_nusmv(lts: LTS, specification: SpecProperty) -> str:
    nof_state_bits = int(max(1, math.ceil(math.log(len(lts.states), 2))))
    bits_by_state = dict((state, bin_fixed_list(i, nof_state_bits))
                         for (i, state) in enumerate(sorted(lts.states)))

    state_bits = lmap(_ith_state_bit, range(nof_state_bits))

    _assert_no_intersection(state_bits,
                            list(lts.input_signals) + lts.output_signals)

    dot_lines = StrAwareList()
    dot_lines += 'MODULE main'
    dot_lines += 'IVAR'
    dot_lines += [
        '  {signal} : boolean;'.format(signal=s.name)
        for s in lts.input_signals
    ]

    dot_lines += 'VAR'
    dot_lines += ['  {si} : boolean;'.format(si=si) for si in state_bits]

    dot_lines += 'DEFINE'
    dot_lines += [
        '  {out_name} := {formula} ;'.format(out_name=out_name,
                                             formula=_get_formula(
                                                 out_name, out_model,
                                                 bits_by_state))
        for (out_name, out_model) in lts.model_by_name.items()
    ]

    dot_lines += 'ASSIGN'
    for i, sb in enumerate(state_bits):
        sb_init = str(bits_by_state[list(lts.init_states)[0]][i]).upper()

        dot_lines += '  init({sb}) := {init_sb};'.format(sb=sb,
                                                         init_sb=sb_init)

        dot_lines += '  next({sb}) := '.format(sb=sb)
        dot_lines += '    case'

        for (label, next_state) in lts.tau_model.items():
            sb_next = str(bits_by_state[next_state][i]).upper()
            dot_lines += '      {formula} : {next_state};'.format(
                formula=_clause_to_formula(label, bits_by_state),
                next_state=sb_next)

        dot_lines += '    TRUE : FALSE;'  # default: unreachable states, don't care
        dot_lines += '    esac;'

    expr = BinOp('->', and_expressions(specification.assumptions),
                 and_expressions(specification.guarantees))
    expr = WeakToUntilConverterVisitor().dispatch(
        expr)  # SMV does not have Weak until

    dot_lines += 'LTLSPEC ' + AstToSmvProperty().dispatch(expr)

    return '\n'.join(dot_lines)
Exemple #3
0
def _get_log_encoded_expr(signal:QuantifiedSignal, new_sched_signal_name:str, cutoff:int) -> Expr:
    assert len(signal.binding_indices) == 1

    proc_index = signal.binding_indices[0]

    nof_sched_bits = int(max(1, math.ceil(math.log(cutoff, 2))))
    bits = bin_fixed_list(proc_index, nof_sched_bits)

    #TODO: use quantified signal or signal?
    conjuncts = [BinOp('=',
                       QuantifiedSignal(new_sched_signal_name, bit_index),
                       Number(1 if bit_value else 0))
                 for bit_index, bit_value in enumerate(bits)]

    conjunction = and_expressions(conjuncts)

    return conjunction
Exemple #4
0
def to_boolean_nusmv(lts:LTS, specification:SpecProperty) -> str:
    nof_state_bits = int(max(1, math.ceil(math.log(len(lts.states), 2))))
    bits_by_state = dict((state, bin_fixed_list(i, nof_state_bits))
                         for (i,state) in enumerate(sorted(lts.states)))

    state_bits = lmap(_ith_state_bit, range(nof_state_bits))

    _assert_no_intersection(state_bits, list(lts.input_signals) + lts.output_signals)

    dot_lines = StrAwareList()
    dot_lines += 'MODULE main'
    dot_lines += 'IVAR'
    dot_lines += ['  {signal} : boolean;'.format(signal=s.name) for s in lts.input_signals]

    dot_lines += 'VAR'
    dot_lines += ['  {si} : boolean;'.format(si=si) for si in state_bits]

    dot_lines += 'DEFINE'
    dot_lines += ['  {out_name} := {formula} ;'.format(out_name=out_name,
                                                       formula=_get_formula(out_name, out_model, bits_by_state))
                  for (out_name,out_model) in lts.model_by_name.items()]

    dot_lines += 'ASSIGN'
    for i,sb in enumerate(state_bits):
        sb_init = str(bits_by_state[list(lts.init_states)[0]][i]).upper()

        dot_lines += '  init({sb}) := {init_sb};'.format(sb=sb, init_sb=sb_init)

        dot_lines += '  next({sb}) := '.format(sb=sb)
        dot_lines += '    case'

        for (label,next_state) in lts.tau_model.items():
            sb_next = str(bits_by_state[next_state][i]).upper()
            dot_lines += '      {formula} : {next_state};'.format(formula=_clause_to_formula(label, bits_by_state),
                                                                  next_state=sb_next)

        dot_lines += '    TRUE : FALSE;'  # default: unreachable states, don't care
        dot_lines += '    esac;'

    expr = BinOp('->', and_expressions(specification.assumptions), and_expressions(specification.guarantees))
    expr = WeakToUntilConverterVisitor().dispatch(expr)  # SMV does not have Weak until

    dot_lines += 'LTLSPEC ' + AstToSmvProperty().dispatch(expr)

    return '\n'.join(dot_lines)
Exemple #5
0
    def _build_label_from_proc_index(self, proc_index:int) -> Label:
        bits = bin_fixed_list(proc_index, self._nof_proc_bits)

        label = Label(dict(zip(map(lambda at: at[0], self._proc_arg_type_pairs), bits)))

        return label
Exemple #6
0
 def to_smt_bools(int_val):
     return list(map(lambda b: str(b).lower(), bin_fixed_list(int_val, self._nof_proc_bits)))
Exemple #7
0
 def to_smt_bools(int_val):
     return list(
         map(lambda b: str(b).lower(),
             bin_fixed_list(int_val, self._nof_proc_bits)))