Skip to main content

Simulates Automatons Acceptors DFA, NFA, PDA and Turing Machines

Project description

🤖 Pytomatas

📌 Version 1.1.4


Pytomatas allows to simulate Acceptor Automata in the console with Python, implementing its characteristics using different definitions (mathematics included), with the following types:

  • DFA (Deterministic Finite Automaton);
  • NFA (Non-deterministic Finite Automaton);
  • PDA (Push-Down Automaton);
  • TM (Turing Machine);

What can do?

  • Create and manage various types of automaton: DFA, NFA, PDA, TM.
  • Visualize automata information in console.
  • Simulate automata acceptors based on strings.
  • Observe the processes of steps and transitions when introducing a string to the automaton.

📍 Index


🛠 Installation

You can install Pytomatas using pip:

pip install Pytomatas

💻 Usage

There are two ways in which automata can be implemented:

  1. Creating the empty automaton and then adding the properties.
  2. Creating the automaton by passing its characteristics as in the mathematical definition.

Example of a DFA implementation...

🧿 First implementation

1. Creating empty automata and then give the data:

from Pytomatas.dfa import DFA

# Creates a DFA called "my_dfa":
my_dfa = DFA()

# Define to "my_dfa" a set of states names:
my_dfa.setStates( {"q0", "q1", "qfinal"} )

# Define to "my_dfa" a set of states characters of the alphabet:
my_dfa.setAlphabet( {"a", "b"} )

# Set the "Initial state" name of "my_dfa":
my_dfa.setInitial( "q0" )

# Define to "my_dfa" the set of "Final states" names:
my_dfa.setFinals( {"qfinal", "qf2"} )

# Add transitions to the DFA:
my_dfa.addTransition( ("q0", "a", "q1") )
my_dfa.addTransition( ("q0", "b", "qfinal") )
my_dfa.addTransition( ("q1", "a", "q1") )
my_dfa.addTransition( ("q1", "b", "q1") )
my_dfa.addTransition( ("qfinal", "a", "qfinal") )
my_dfa.addTransition( ("qfinal", "b", "qfinal") )

# Add more data to the existing one already in the automata:
my_dfa.addSymbol("c")
my_dfa.addState("qx")
my_dfa.addState("finalState2")
my_dfa.addFinal("finalState2")

# Prints the DFA information:
my_dfa.show()

# Check if a string is accepted on the defined automata "my_dfa":
# It returns True or False if the string is accepted or not:
word = "aaabb"
my_dfa.accepts(word)

# Checks if the string is accepted, but prints all the process and steps on transitions;
# Shows the flow of states while reading the string;
my_dfa.accepts(word, stepByStep=True)

🧿 Second implementation

2. Creating the automata passing the data:

from Pytomatas.dfa import DFA

# Declare the States:
Q = {"q0", "qa", "q1", "qb", "q2", "qf", "qx"}

# Declare the Alphabet:
A = {"a", "b"}

# Declare the Initial (start) state:
S = "q0"

# Declare the Finals states:
F = {"q2", "q3"}

# Declare the Transitions:
T = [
	("q0", "a", "qa"),
	("q0", "b", "q1"),
	("qa", "a", "qa"),
	("qa", "b", "qb"),
	("qf", "b", "qf"),
	("qx", "a", "qx"),
	("qx", "b", "qx")
]

# Declare the Automata:
my_dfa = DFA(Q, A, T, S, F)

# Show the automata information:
my_dfa.show()

# Check if a string is accepted on the defined automata "my_dfa":
# It returns True or False if the string is accepted or not:
word = "aaabb"
my_dfa.accepts(word)

# Checks if the string is accepted, but prints all the process and steps on transitions;
# Shows the flow of states while reading the string;
# It returns True or False if the string is accepted or not:
my_dfa.accepts(word, stepByStep=True)

🛑 NOTE: These are only implementation examples, not actual implementations, so they are not complete real automata definitions 👆

  • For more detailed information about the attributes and methods of the class, refer to Documentation.

  • For more detailed usage instructions and examples, please refer to Examples.


📓 Documentation

Go to THIS LINK to see the documentation on all the features of the different types of automata, the functions they have, and examples of their implementation.


📚 Examples

  1. DFA (Deterministic Finite Automaton).

  2. NFA (Non-deterministic Finite Automaton).

  3. PDA (Push-Down Automaton).

  4. TM (Turing Machine).

  5. Safebox Automata Implementation Project.


📁 Repository

Go to THIS LINK to check out the source code.


✍ Contributing

Contributions are welcome! If you encounter any issues, have suggestions, or would like to contribute to the project, please feel free to open an issue or submit a pull request on this repository.


📜 License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with 💜 by @arhcoder;


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Pytomatas-1.1.4.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Pytomatas-1.1.4-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file Pytomatas-1.1.4.tar.gz.

File metadata

  • Download URL: Pytomatas-1.1.4.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for Pytomatas-1.1.4.tar.gz
Algorithm Hash digest
SHA256 5a63a8b5c2631934cabe54694f20706df7fd65cb9d9e23b313fc25afb7a8c169
MD5 951d90460817bc570f1b3bd06408ac34
BLAKE2b-256 44dd9e6ec13991e106ab75fc1ede95cc31df5a5467fe31efcf84ca8b72080832

See more details on using hashes here.

File details

Details for the file Pytomatas-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: Pytomatas-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for Pytomatas-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e3437047c1668e3cd00540b33b9a23d7435cd141913a9ce3444f3fa3fcb780f5
MD5 73cc7a2652944effc4b8e84161c7c01f
BLAKE2b-256 087e6005ff2607a823b5efdae72971af79abbd338c7e0684cdb066a6f0a7ef41

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page