Skip to content

Latest commit

 

History

History
204 lines (137 loc) · 6.29 KB

README.md

File metadata and controls

204 lines (137 loc) · 6.29 KB

🤖 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;