A Python package for automata theory.
Python implementation of automata theory.
pip install pythomata
develop
branch):pip install git+https://github.com/whitemech/pythomata.git@develop
git clone https://github.com/whitemech/pythomata.git
cd pythomata
pip install .
from pythomata import SimpleDFA
alphabet = {"a", "b", "c"}
states = {"s1", "s2", "s3"}
initial_state = "s1"
accepting_states = {"s3"}
transition_function = {
"s1": {
"b" : "s1",
"a" : "s2"
},
"s2": {
"a" : "s2",
"b" : "s1",
"c" : "s3",
},
"s3":{
"c" : "s3"
}
}
dfa = SimpleDFA(states, alphabet, initial_state, accepting_states, transition_function)
# a word is a list of symbols
word = "bbbac"
dfa.accepts(word) # True
# without the last symbol c, the final state is not reached
dfa.accepts(word[:-1]) # False
dfa_minimized = dfa.minimize()
dfa_trimmed = dfa.trim()
graphviz.Digraph
instance:graph = dfa.minimize().trim().to_graphviz()
To print the automaton:
graph.render("path_to_file")
For that you will need to install Graphviz. Please look at their download page for detailed instructions depending on your system.
The output looks like the following:
To run the tests:
tox
To run only the code style checks:
tox -e flake8 -e mypy
To build the docs:
mkdocs build
To view documentation in a browser
mkdocs serve
and then go to http://localhost:8000
Pythomata is released under the GNU Lesser General Public License v3.0 or later (LGPLv3+).
Copyright 2018-2020 WhiteMech