This is a python project that allow you to create and manipulate finite-state automatons (FA). See below the list of available fonctionalities.
- writing and modifications of FAs
- generate a textual or graphic representation of FAs
- export and import FAs from/to json files
- test if a word can be generated by a FA
- test if a FA is complete, deterministic, emondistic or minimal
- test if two FAs are equivalent
- generate the complete, deterministic, emondistic or minial version of a FA
- generate a regex expression of a FA
- generate the complement or the mirror of a FA
- generate the product or the concatenation of two FA
To execute the program, open the console and go into the src folder, and start the main.py file. For this, you must have python installed. Start by checking that the version you're using is functional by starting the tests.py file. If you're using Windows, then type :
python tests.py
If you're using Linux, then type the same command, or if you have python3 installed, then type
python3 tests.py
If the tests are successful, then use the same command to start the main.py file.
When executing the main.py file, select a FA or enter one. To enter a new FA, the syntax must be the following one :
start_state , transition , end_state
To delete a transition, re-enter it. After typing the FA, you will be able to use some other editing function, like delete all occurrences of a state, or rename one.
Once you finished typing the FA, to exit you must enter a void line. Then you will have to enter the initial and final(s) states of the FA. To delete one type it again, and to exit, enter a void line.
After that, you will see the main menu, and you'll just have to select an option.
Beyond the classic operations to manipulate FAs, this program have a few practical options like renaming a state of the FA. It can also be used to fuse two states. Another option allow you to delete all occurrences of a state without having to do it one at once.
The graphviz library is used to generate an image of the FA, by generating a .dot file. The program contain a function to install the library by itself that is functional on Windows and Linux.
The project contain a file named tests.py that execute all the functions of the program and check the result to detect any inconsistency.
The functions to change an automate into a minimal one are in the file minimal.py The functions are an adaption an adaption of Moore's algorithme explain here: https://home.mis.u-picardie.fr/~leve/Enseign/LF1415/chapitre5_LF.pdf (page 28)
This function allows the user to check if the automate is a minimalized one or not. It returns True or False
This function calculates a new bilan (partition) using the Moore minimization algorithm.
-
The function initializes the alphabet and an outcome dictionary based on the provided starting bilan.
-
Update Outcome with Transitions
-
Count Different Arrangements
-
Recursively Call the Function: If the new bilan is the same as the starting bilan, return the final outcome. Otherwise, recursively call the function with the new bilan.
This function creates a minimalistic version of the input automate using the Moore minimization algorithm.
-
Create Start Bilan where each state is represented as a list with the first element being 1 if the state is a final state, and 0 otherwise.
-
Use the MooreMinimal function to calculate the minimalized map.
-
Create a table to map unique IDs to state names.
-
Initialize the new automate structure. Iterate over IDs and create states in the new automate. Mark initial and final states accordingly.
-
Iterate over the minimalized map and create transitions in the new automaton.
The minimal function provides an interface for the user to interactively minimize an automate stored in a provided list.
The functions in this file create a new automate as the outcome of the concatenation of two automates. This algorithme is an adapation of the one explain here: https://www.desmontils.net/emiage/Module209EMiage/c5/Ch5_10.htm (section 10.2)
- this automate has a new structure which includes :
- "Alphabet": Union of the alphabets of automate1 and automate2.
- "Etats": A dictionary representing states in the new automaton.
- "Etats_initiaux": An empty list for initial states.
- "Etats_finaux": An empty list for final states.
- Create State Mappings (oldToNew1 and oldToNew2):
- These two dictionaries (oldToNew1 and oldToNew2) will store mappings from the old state names to the corresponding new state names in automateFinal. This is necessary because when combining two automates, we need to ensure that the state names are unique across both automate.
-
For each state in automate1, a new state is created in automateFinal with a unique name (e.g., "e0", "e1", etc.). The transitions and properties of the state are copied to the new state in automateFinal. The mapping (oldToNew1) is updated to link the old state name to the new state name.
-
Similarly, for each state in automate2, a new state is created in automateFinal with a unique name. The transitions and properties of the state are copied to the new state in automateFinal. The mapping (oldToNew2) is updated to link the old state name to the new state name.
- Update the transitions in automateFinal by replacing old state names with the new state names.
- Copy transitions from the initial state of automate2 to the final state of automate1.
- Update the initial states and final states lists in automateFinal based on the mappings.
- Remove the initial states of automate2 from automateFinal and replace them with the final states of automate1.
This function allows the user to interactively choose the second automate and do the concatenation operations on automates stored in a list.
The functions in this file create a new automate as the outcome of the product of two automates. This algorithme is an adapation of the one explain here: https://www.desmontils.net/emiage/Module209EMiage/c5/Ch5_10.htm (section 10.4)
This function calculates a line (a set of transitions) for the product of two automates.
The function initializes an empty dictionary line where each key represents a symbol in the alphabet, and each value is a list of two lists. The first list corresponds to transitions from automate1, and the second list corresponds to transitions from the second automate2. If a symbol is present in the transition set of the current state for the respective automaton, add the transitions to the corresponding list in the line dictionary. The resulting line dictionary contains information about the transitions for each symbol in the alphabet from the states in stateList.
This function performs the product of two automates. The function initializes the alphabet as the union of alphabets from automate1 and automate2. Lists existingSet and newAutomateBP are initialized to keep track of existing sets of states and the blueprint for the new automaton.
-
Collect the initial states of each automate (automate1 and automate2).
-
Initialize the existingSet list with the starting state of each automate as the first set.
-
For each existing set, calculate transitions using calculLineProduct and add it to the newAutomateBP list.
-
Check for new sets generated during the process.
-
Create a new automate based on the collected information.States are created based on the sets in newAutomateBP, and transitions are added accordingly.
This function allows the user to interactively do the product operations on automates stored in a list.