Exemplo n.º 1
0
def createInputAlteringSIDTrans(n, sigmaSet):
    """Create an input-altering SID transducer based

    :param int n: max number of errors
    :param set sigmaSet: alphabet
    :return: a transducer representing the SID channel
    :rtype: SFT"""
    new = SFT()
    new.setSigma(sigmaSet)
    new.setOutput(sigmaSet)
    init = new.stateIndex((0, None), True)
    new.addInitial(init)
    for sy in new.Sigma:
        new.addTransition(init, sy, sy, init)
    i = 1
    while i <= n:
        d1 = new.stateIndex((i, None), True)
        new.addFinal(d1)
        for s in new.Sigma:
            new.addTransition(d1, s, s, d1)
            d = new.stateIndex((i, s), True)
            new.addFinal(d)
            if i == 1:
                new.addTransition(init, s, Epsilon, d)
                for s1 in new.Sigma - {s}:
                    new.addTransition(init, s, s1, d1)
            else:
                bar = new.stateIndex((i - 1, None))
                new.addTransition(bar, s, Epsilon, d1)
                new.addTransition(bar, Epsilon, s, d1)
                for s1 in new.Sigma:
                    foo = new.stateIndex((i - 1, s))
                    new.addTransition(foo, s1, Epsilon, d)
                    if s1 != s:
                        new.addTransition(bar, s, s1, d1)
                        new.addTransition(foo, Epsilon, s1, d1)
                        for s2 in new.Sigma:
                            new.addTransition(foo, s2, s1, d1)
            for s1 in new.Sigma - {s}:
                new.addTransition(d, s1, s1, d1)
        i += 1
    return new
Exemplo n.º 2
0
    def notSatisfiesW(self, aut):
        """Test whether the language is a code.

        :param DFA|NFA aut: the automaton
        :return: two different factorizations of the same word
        :rtype: tuple of list"""
        def _findFactors(w, m):
            l = []
            i1 = 0
            while True:
                j = m.find('1', i1)
                if j < 0:
                    break
                l.append(w[i1:j + 1])
                i1 = j + 1
            return l

        n = aut.toNFA()   # .eliminateEpsilonTransitions()
        for i in n.Initial:
            if i in n.Final:
                return [Epsilon], [Epsilon, Epsilon]
        t = SFT()
        t.States = copy.deepcopy(n.States)
        t.setInitial(n.Initial)
        t.setFinal(n.Initial)
        t.setSigma(n.Sigma)
        t.setOutput(['1', '0'])
        for si in n.delta:
            for sym in n.delta[si]:
                for so in n.delta[si][sym]:
                    if so not in n.Final:
                        t.addTransition(si, sym, '0', so)
                    else:
                        t.addTransition(si, sym, '0', so)
                        for ss in t.Initial:
                            t.addTransition(si, sym, '1', ss)
        t.trim()
        foo = t.nonFunctionalW()
        if foo == (None, None, None):
            return None, None
        else:
            return _findFactors(foo[0], foo[1]), _findFactors(foo[0], foo[2])