rohaquinlop / automathon

A Python library for simulating and visualizing finite automata
https://rohaquinlop.github.io/automathon/
MIT License
63 stars 3 forks source link

Improving the documentation #54

Open Buitragox opened 1 day ago

Buitragox commented 1 day ago

Hi Robin, I'm currently working on rewriting a lot of the current documentation for better readability.

I found an inconsistency while rewriting the documentation of the renumber method from nfa.md. It says, "The new states will be named as q0, q1, q2, and so on."

But this is what I get with the following code:

from automathon import NFA

q = {'state1', 'state2', 'state3', 'state4'}
sigma = {'0', '1'}
delta = {
    'state1' : {
            '0' : {'state1'},
            '1' : {'state1', 'state2'}
            },
    'state2' : {
            '0' : {'state3'},
            '' : {'state3'}
            },
    'state3' : {
            '1' : {'state4'},
            },
    'state4' : {
            '0' : {'state4'},
            '1' : {'state4'},
            },
}
initial_state = 'state1'
f = {'state4'}

automaton = NFA(q, sigma, delta, initial_state, f)

print(automaton.q) # {'state2', 'state3', 'state1', 'state4'}

automaton.renumber()

print(automaton.q) # {'0', '2', '3', '1'}

It's renaming them to numbers and not putting a 'q' as a prefix. Is this intended and the documentation is incorrect? Or is this a bug?

rohaquinlop commented 1 day ago

Hey @Buitragox thank you for your contribution! That's an error, isn't intended to work like that. I think that should be interesting to add an optional argument like prefix = "q" to allow the user to use a custom prefix.

class NFA:
    ...
    def renumber(self, states_prefix = "q") -> None:
    ...

If you want, you can open a PR with this refactor :)

Buitragox commented 18 hours ago

If you want, you can open a PR with this refactor :)

Sure, I'll be working on it.