Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork4
A Python library for simulating and visualizing finite automata
License
rohaquinlop/automathon
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A Python library for simulating and visualizing finite automata.
Documentation:https://rohaquinlop.github.io/automathon/
Source Code:https://github.com/rohaquinlop/automathon
PyPI:https://pypi.org/project/automathon/
- Python >= 3.10
- You also need to install Graphviz on your computer (download page,installation procedure for Windows,archived versions).Make sure that the directory containing thedot executable is on your systems’ path.
pip install automathon
pip install automathon --upgrade
Here is are some examples about what you can do withautomathon, you cancheck the documentation aboutDeterministic Finite Automata andNon-Deterministic Finite Automata to know more about the functions andmethods that are available.
This image was created usingautomathon.
Let's create the previous automata using the library:
fromautomathonimportDFAq= {'q0','q1','q2'}sigma= {'0','1'}delta= {'q0' : {'0' :'q0','1' :'q1'},'q1' : {'0' :'q2','1' :'q0'},'q2' : {'0' :'q1','1' :'q2'} }initial_state='q0'f= {'q0'}automata=DFA(q,sigma,delta,initial_state,f)
automata.is_valid()# True
In this case, the automata is valid but if it wasn't, the library would raise anexception with the error message.
Errors that the library can raise are:
SigmaError:
- The automata contain an initial state, or a final state that's not defined in Q.
- The automata contain a delta transition that's not defined in Q nor Sigma.
InputError:
- The automata is trying to consume a letter that's not defined in sigma.
automata.accept("001001")# Trueautomata.accept("00100")# False
not_automata=automata.complement()not_automata.accept("00100")#True
Note that this function returns a new automata, it doesn't modify the originalone.
For both,DFA andNFA, the view method enables to visualize the automaton, receives as parameter a String as the file name for the png and svg files.
More information about the graphviz attributeshere.
# Default stylingautomata.view("DFA Visualization")# You can decide between png and svg file formats# If you want to add custom styling, you can use the followingautomata.view(file_name="DFA Custom Styling",file_format="png"or"svg",node_attr={'fontsize':'20'},edge_attr={'fontsize':'20pt'})
If you want to explore more about the functions and methods of the DFA class,you can check theDFA documentation. And if you want to know more aboutthe NFA class, you can check theNFA documentation.
Image taken from:r9paul.org
fromautomathonimportNFA## Epsilon Transition is denoted by '' -> Empty stringq= {'q1','q2','q3','q4'}sigma= {'0','1'}delta= {'q1' : {'0' : {'q1'},'1' : {'q1','q2'} },'q2' : {'0' : {'q3'},'' : {'q3'} },'q3' : {'1' : {'q4'}, },'q4' : {'0' : {'q4'},'1' : {'q4'}, },}initial_state='q1'f= {'q4'}automata=NFA(q,sigma,delta,initial_state,f)
automata.is_valid()# True
automata.accept("0000011")#Trueautomata.accept("000001")#False
not_automata=automata.complement()not_automata.accept("000001")#True
# Default stylingautomata.view("NFA Visualization")# You can decide between png and svg file formats# If you want to add custom styling, you can use the followingautomata.view(file_name="NFA Custom Styling",file_format="png"or"svg",node_attr={'fontsize':'20'},edge_attr={'fontsize':'20pt'})
This project is licensed under the terms of the MIT license.
About
A Python library for simulating and visualizing finite automata
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.


