Load the badic package:
from badic import *
a = dag.MatricesGraph([matrix([[1,0],[1,2]]), matrix([[1, 1],[1,0]])])
print(a.is_complete())
a.alphabet
True
[ [1 0] [1 1] [1 2], [1 0] ]
d = a.invariant_density()
print(a.is_invariant_density(d))
d
True
[1/((2*x0 + x1)*(x0 + x1))]
a.domains_polyhedra()
[[ [2 1] [1 1] ]]
a = DetAutomaton([(0,1,1),(0,2,2),(1,0,0),(1,2,2),(2,0,0),(2,1,1)])
a.plot()
Display 10 steps of the algorithm from state 1:
a.plot_algo(1,10)
Compute an exact invariant density:
a.invariant_density()
[1/((x0 + x1 + x2)*(x0 + x1)*(x0 + x2)), 1/((x0 + x1 + x2)*(x0 + x1)*(x1 + x2)), 1/((x0 + x1 + x2)*(x0 + x2)*(x1 + x2))]
Plot domains:
a.plot_domains()
Display corresponding matrices:
a.domains_polyhedra()
[[ [1 1 1] [1 0 1] [0 1 1] ], [ [1 1 0] [1 1 1] [0 1 1] ], [ [1 1 0] [0 1 1] [1 1 1] ]]
Convert the win-lose graph to a matrices graph:
a.winlose_to_matrices().plot()
# compute the flip-flop for some set of edges
AS = [[(2,0,0),(0,1,1)],[(2,1,1)]]
a2 = a.flip_flop(AS)
a2.plot()
Plot domains of the extension:
a2.plot_domains()
Display corresponding matrices:
ls = a2.domains_polyhedra()
ls
[[ [2 2 1] [1 2 1] [1 1 1] ], [ [1 1 0] [2 2 1] [1 2 1] [1 2 1] [2 2 1], [2 3 2] ], [ [1 2 2] [1 2 1] [1 1 2] [0 1 1] [0 1 1], [1 1 1] ], [ [1 1 0] [1 2 1] [1 1 1] ], [ [1 2 1] [1 1 1] [1 2 2] [0 1 1] [1 1 2] [1 1 2] [1 2 2], [1 2 2], [1 2 3] ], [ [1 1 1] [1 1 2] [0 1 1] ]]
Compute an exact invariant density:
ld = a2.invariant_density()
ld
[1/((2*x0 + 2*x1 + x2)*(2*x0 + x1 + x2)*(x0 + x1 + x2)), 1/((2*x0 + 2*x1 + 3*x2)*(2*x0 + x1 + 2*x2)*(x0 + x1 + 2*x2)) + 1/((x0 + 2*x1 + 2*x2)*(x0 + x1 + 2*x2)*(x1 + x2)), 1/((2*x0 + 2*x1 + x2)*(2*x0 + x1 + x2)*(x0 + x1)) + 1/((2*x0 + x1 + x2)*(x0 + x1 + x2)*(x0 + x2)), 1/((x0 + 2*x1 + x2)*(x0 + x1 + x2)*(x1 + x2)), 1/((2*x0 + 2*x1 + 3*x2)*(2*x0 + x1 + 2*x2)*(x0 + x1 + x2)) + 1/((x0 + 2*x1 + 2*x2)*(x0 + x1 + 2*x2)*(x0 + x1 + x2)) + 1/((2*x0 + x1 + 2*x2)*(x0 + x1 + 2*x2)*(x0 + x2)), 1/((x0 + 2*x1 + x2)*(x0 + x1 + x2)*(x0 + x1))]
Check that it is indeed an invariant density:
a2.is_invariant_density(ld)
True
# compute the flip-flop for another set of edges
AS = [[(2,0,0),(0,1,1)],[(0,1,1),(2,1,1)]]
a2 = a.flip_flop(AS)
print(a2.strongly_connected_components())
a2 = a2.sub_automaton([0,1,2,3,4])
a2.plot()
dict_values([[0, 1, 2, 3, 4], [5]])
Show domains:
a2.plot_domains()