def testproducts(): NFA.VISULANG = 5 NFA.VISU_INITIAL_ARROW = False Char = NFA.spec(""" 0 1 0 1 1 1 0 0 """).map(g=int).named("Char").visu() _ = NFA.Stay C1 = Char.copy().map(g=lambda x: "b" if x else "a").named("C1") C2 = Char.copy().map(g=lambda x: "B" if x else "A").named("C2") from itertools import product NFA._sprod2_brutal(Char, Char, {(0, 0), (1, 1)}).visu() NFA._sprod2_brutal(Char, Char, set(product([0, 1], repeat=2))).visu() NFA._sprod2_brutal(Char, Char, {(_, 0), (_, 1), (1, _)}).visu() NFA._sprod2_brutal(Char, Char, {(_, 0), (_, 1), (1, 1)}).visu() NFA._sprod2_brutal(Char, Char, {x for y in [0, 1] for x in {(_, y), (y, _)}}).visu() (Char @ Char).visu() C1.visu() NFA._sprod2_brutal(Char, C1, set(product([0, 1, _], ["a", 'b', _]))).visu() (NFA.of_word([1, 2, 3]) @ NFA.of_word([_, _])).visu() NFA.sprod_brutal(Char, C1, svec=set(product([0, 1, _], ["a", 'b', _]))).visu() X = NFA.sprod_brutal(Char, C1, C2, svec=set( product([0, 1, _], ["a", 'b', _], ["A", "B", _]))).visu() Y = NFA.sprod_brutal(Char, Char, Char, svec=set(product([0, 1, _], repeat=3))).visu() # on the fly version tests svec = NFA.shuffle([1, 1], [_]) | NFA.shuffle([0], [_, _]) P = NFA.sprod_brutal(Char, Char, Char, svec=svec).visu() svec = NFA.shuffle([1, 1], [_]) | NFA.shuffle([0], [_, _]) P = NFA.sprod(Char, Char, Char, svec=svec, record_steps=True).visu() P.visusteps(P._grow_step) svec = {(1, 1)} P = NFA.sprod_brutal(Char, Char, svec=svec, silent=[0]).visu() Q = NFA.sprod(Char, Char, svec=svec, silent=[0]).visu() NFA.VISULANG = 10 NFA.VISU_INITIAL_ARROW = True
def digicode(): NFA.VISULANG = 15 Digi = NFA.of_word("123").visu() # for c in "01234567890": for c in "x123": Digi.add_rule(0, c, 0) Digi.name = "Digicode" Digi.texvisu("0 > 1 > 2 > 3") #.table() Digi.visu().dfa().visu().texvisu("0 > 1 > 2 > 3", "0 lb 0 3 <40,ns 0 3 < 1 2 >70,ns,~ 0", renum=True)
def shuffles(): Big = NFA.of_set({"aAbBcC", "aaaBBB"}, "two").visu() A = Big.proj("abc").visu().renum().visu() B = Big.proj("ABC").renum().visu() C = (A @ B).setnop(name="Shuffle") C.visu().dfa().visu().mini().visu() Bad = (C - Big).mini().visu() C.run("aABbcC") A = NFA.universal('abc').visu() B = NFA.of_word("abc").visu() C = (A - B).visu().mini().visu() # fun case where determinising is removing redundant loops. S = (A @ B).setnop(name="Shuffle").visu().dfa().visu() ##print(A[0], A[1], list(A[:10])) (A | B).visu().mini().visu() NFA.union(A, A, B, A).visu().dfa().visu().mini().visu()
def hard_minimisation(): tab = False def fib(n): if n == 0: return "0" if n == 1: return "1" return fib(n - 1) + fib(n - 2) def FIB(n): return {fib(k) for k in range(n)} S = FIB(6) A = NFA.of_set(S).dfa().renum().visu().mini(table=tab).visu() # starts with final, need to ensure I, II and not II, I, prev bug. B = NFA.spec(""" 0 0 0 a 1 b 1 1 b 0 a 1 """).visu().mini(table=tab).visu() C = NFA.of_word("aaaa").complete().visu().mini(table=tab).visu()
def arun(): NFA.of_word("aaa").add_rule(0, 'b', 1).run("baa")
exo_explosive_det() arun() concatenation() shuffles() ofset() isomorphisms() testproducts() digicode() simplifyArdenSystem() ctl_tests() exam2020() decExam2020Verif() interfaceAutomataProduct() verif_mini_prog() synchro_prod_poly_example() hard_minimisation() # NFA.sanity_check() ##main() # exo_explosive_det() Digi = NFA.of_word("123") # for c in "01234567890": for c in "x123": Digi.add_rule(0, c, 0) Digi.name = "Digicode" Digi.visu() Digi.run("123123")
OA, OB = A, B A = A.complete(Σ).visu() B = B.complete(Σ).visu() NFA.visutext("UNION THROUGH PRODUCT OF COMPLETE") U = ( A & B ).named("A ∪(prod) B") U.F = set(product(A.F,B.Q)) | set(product(A.Q,B.F)) U = U.visu().trim().visu().dfa().visu().mini().visu().renum().visu() # U.run("cc") AUB = (A | B).mini().renum().visu() NFA.visutext(U.iso(AUB)) NFA.visutext("SHUFFLE: UNSYNCHRONISED PRODUCT") A, B = OA, OB Shu = A.visu() @ B.visu() Shu.visu().mini().visu() S = NFA.of_word("abc").visu() @ NFA.of_word("ABC").visu() S.visu() (-S).visu() S = NFA.of_word("a") @ NFA.of_word("ABC") S.visu() S = NFA.of_word("abc") @ NFA.of_word("abc") S.visu().mini().visu() S = NFA.of_word("abc") @ NFA.of_word("abc") @ NFA.of_word("abc") S.renum().visu().mini().visu()