Skip to content

Commit 7757a9b

Browse files
committed
Pytomata v.1.0.0
Automata project from github.com/arhcoder/Automata v.1.6.0 + Documentation for a real PyPi publication :3
1 parent a67c489 commit 7757a9b

24 files changed

+2167
-392
lines changed

.gitignore

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/

Examples/dfa-example-1.py

+25-27
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
from Automata.dfa import DFA
1+
from pytomata.dfa import DFA
22

3-
if __name__ == "__main__":
3+
# First example of DFA Automata instance:
4+
# Language of the Automata:
5+
# L(Automata) = {(b^n)a(w): n>=0, w in {a, b}*};
6+
# Any string with at least one "a";
7+
Automata = DFA()
8+
Automata.setStates({"q0", "q1"})
9+
Automata.setAlphabet({"a", "b"})
10+
Automata.setInitial("q0")
11+
Automata.setFinals({"q1"})
12+
Automata.addTransition(("q0", "a", "q1"))
13+
Automata.addTransition(("q0", "b", "q0"))
14+
Automata.addTransition(("q1", "a", "q1"))
15+
Automata.addTransition(("q1", "b", "q1"))
416

5-
# First example of DFA Automata instance:
6-
# Language of the Automata:
7-
# L(Automata) = {(b^n)a(w): n>=0, w in {a, b}*};
8-
# Any string with at least one "a";
9-
Automata = DFA()
10-
Automata.setStates({"q0", "q1"})
11-
Automata.setAlphabet({"a", "b"})
12-
Automata.setInitial("q0")
13-
Automata.setFinals({"q1"})
14-
Automata.addTransition(("q0", "a", "q1"))
15-
Automata.addTransition(("q0", "b", "q0"))
16-
Automata.addTransition(("q1", "a", "q1"))
17-
Automata.addTransition(("q1", "b", "q1"))
18-
19-
Automata.show()
17+
Automata.show()
2018

21-
#/ Executes the Automata:
22-
while True:
23-
print()
24-
word = input("String: ")
25-
if Automata.accepts(word, stepByStep=True):
26-
print(f"The string \"{word}\" IS accepted!")
27-
else:
28-
print(f"The string \"{word}\" IS NOT accepted!")
29-
print()
30-
print("═"*40)
19+
#/ Executes the Automata:
20+
while True:
21+
print()
22+
word = input("String: ")
23+
if Automata.accepts(word, stepByStep=True):
24+
print(f"The string \"{word}\" IS accepted!")
25+
else:
26+
print(f"The string \"{word}\" IS NOT accepted!")
27+
print()
28+
print("═"*40)

Examples/dfa-example-2.py

+56-58
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,56 @@
1-
from Automata.dfa import DFA
2-
3-
if __name__ == "__main__":
4-
5-
# Second example of DFA Automata instance:
6-
# Language of the Automata:
7-
# L(Automata) = All strings with at least one "a",
8-
# and exactly two b's:
9-
#* States:
10-
Q = {"q0", "qa", "q1", "qb", "q2", "qf", "qx"}
11-
12-
#* Alphabet:
13-
A = {"a", "b"}
14-
15-
#* Starting state:
16-
S = "q0"
17-
18-
#* Finals states:
19-
F = {"qf"}
20-
21-
#* Transitions:
22-
T = [
23-
("q0", "a", "qa"),
24-
("q0", "b", "q1"),
25-
26-
("qa", "a", "qa"),
27-
("qa", "b", "qb"),
28-
29-
("q1", "a", "qb"),
30-
("q1", "b", "q2"),
31-
32-
("qb", "a", "qb"),
33-
("qb", "b", "qf"),
34-
35-
("q2", "a", "qf"),
36-
("q2", "b", "qx"),
37-
38-
("qf", "a", "qf"),
39-
("qf", "b", "qx"),
40-
41-
("qx", "a", "qx"),
42-
("qx", "b", "qx")
43-
]
44-
45-
#? Automata:
46-
Automata = DFA(Q, A, T, S, F)
47-
Automata.show()
48-
49-
#/ Executes the Automata:
50-
while True:
51-
print()
52-
word = input("String: ")
53-
if Automata.accepts(word, stepByStep=True):
54-
print(f"The string \"{word}\" IS accepted!")
55-
else:
56-
print(f"The string \"{word}\" IS NOT accepted!")
57-
print()
58-
print("═"*40)
1+
from pytomata.dfa import DFA
2+
3+
# Second example of DFA Automata instance:
4+
# Language of the Automata:
5+
# L(Automata) = All strings with at least one "a",
6+
# and exactly two b's:
7+
#* States:
8+
Q = {"q0", "qa", "q1", "qb", "q2", "qf", "qx"}
9+
10+
#* Alphabet:
11+
A = {"a", "b"}
12+
13+
#* Starting state:
14+
S = "q0"
15+
16+
#* Finals states:
17+
F = {"qf"}
18+
19+
#* Transitions:
20+
T = [
21+
("q0", "a", "qa"),
22+
("q0", "b", "q1"),
23+
24+
("qa", "a", "qa"),
25+
("qa", "b", "qb"),
26+
27+
("q1", "a", "qb"),
28+
("q1", "b", "q2"),
29+
30+
("qb", "a", "qb"),
31+
("qb", "b", "qf"),
32+
33+
("q2", "a", "qf"),
34+
("q2", "b", "qx"),
35+
36+
("qf", "a", "qf"),
37+
("qf", "b", "qx"),
38+
39+
("qx", "a", "qx"),
40+
("qx", "b", "qx")
41+
]
42+
43+
#? Automata:
44+
Automata = DFA(Q, A, T, S, F)
45+
Automata.show()
46+
47+
#/ Executes the Automata:
48+
while True:
49+
print()
50+
word = input("String: ")
51+
if Automata.accepts(word, stepByStep=True):
52+
print(f"The string \"{word}\" IS accepted!")
53+
else:
54+
print(f"The string \"{word}\" IS NOT accepted!")
55+
print()
56+
print("═"*40)

Examples/nfa-example-1.py

+25-27
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
from Automata.nfa import NFA
1+
from pytomata.nfa import NFA
22

3-
if __name__ == "__main__":
3+
# Second example of NFA Automata instance:
4+
# Language of the Automata:
5+
# L(Automata) = {(a^n): n>=0} U {(b^n)a: n>=1};
6+
Automata = NFA()
7+
Automata.setStates({"q0", "qb", "qa", "qba"})
8+
Automata.setAlphabet({"a", "b"})
9+
Automata.setInitial("q0")
10+
Automata.setFinals({"qa", "qba"})
11+
Automata.addTransition(("q0", "", "qa"))
12+
Automata.addTransition(("q0", "b", "qb"))
13+
Automata.addTransition(("qa", "a", "qa"))
14+
Automata.addTransition(("qb", "a", "qba"))
15+
Automata.addTransition(("qb", "b", "qb"))
416

5-
# Second example of NFA Automata instance:
6-
# Language of the Automata:
7-
# L(Automata) = {(a^n): n>=0} U {(b^n)a: n>=1};
8-
Automata = NFA()
9-
Automata.setStates({"q0", "qb", "qa", "qba"})
10-
Automata.setAlphabet({"a", "b"})
11-
Automata.setInitial("q0")
12-
Automata.setFinals({"qa", "qba"})
13-
Automata.addTransition(("q0", "", "qa"))
14-
Automata.addTransition(("q0", "b", "qb"))
15-
Automata.addTransition(("qa", "a", "qa"))
16-
Automata.addTransition(("qb", "a", "qba"))
17-
Automata.addTransition(("qb", "b", "qb"))
17+
Automata.show()
1818

19-
Automata.show()
20-
21-
#/ Executes the Automata:
22-
while True:
23-
print()
24-
word = input("String: ")
25-
if Automata.accepts(word, stepByStep=True):
26-
print(f"The string \"{word}\" IS accepted!")
27-
else:
28-
print(f"The string \"{word}\" IS NOT accepted!")
29-
print()
30-
print("═"*40)
19+
#/ Executes the Automata:
20+
while True:
21+
print()
22+
word = input("String: ")
23+
if Automata.accepts(word, stepByStep=True):
24+
print(f"The string \"{word}\" IS accepted!")
25+
else:
26+
print(f"The string \"{word}\" IS NOT accepted!")
27+
print()
28+
print("═"*40)

0 commit comments

Comments
 (0)