Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior when directly instantiating NFA #220

Closed
irisdyoung opened this issue May 16, 2024 · 2 comments
Closed

Unexpected behavior when directly instantiating NFA #220

irisdyoung opened this issue May 16, 2024 · 2 comments
Labels
correct-behavior The reported issue is not actually a bug, but represents the correct and intended behavior

Comments

@irisdyoung
Copy link

When working through the examples I tried instantiating some NFAs as we had previously done for DFAs, and the same example inputs aren't valid. After trying a few more cases, it looks to me like NFAs will only accept state identifiers one character long, and more specifically they seem to be truncating end states to the first character during instantiation. For example, this example worked for a DFA:

my_dfa = DFA(
    states={'00', '11', '22'},
    input_symbols={'0', '1'},
    transitions={
        '00':{'0':'00', '1':'11'},
        '11':{'0':'00', '1':'22'},
        '22':{'0':'22', '1':'11'}
    },
    initial_state='00',
    final_states={'11'}
)

but not for an NFA:

my_nfa = NFA(
    states={'00', '11', '22'},
    input_symbols={'0', '1'},
    transitions={
        '00':{'0':'00', '1':'11'},
        '11':{'0':'00', '1':'22'},
        '22':{'0':'22', '1':'11'}
    },
    initial_state='00',
    final_states={'11'}
)

This latter one reports InvalidStateError: end state 0 for transition on 00 is not valid

Acknowledging that I'm out of my depth subject-matter-wise, this looks like a bug to me. I'm running the latest command line version in python 3.12.3 on a mac.

@eliotwrobson
Copy link
Collaborator

eliotwrobson commented May 16, 2024

This is expected behavior. The transition dictionary for NFAs ends on a set of states rather than a single state (the weird error message is because it's iterating through the string for the state name the way it would a set). The reason for this has to do with how these objects are defined mathematically. This difference is present in the API documentation, but we can add an example of an NFA defined by hand to the first example.

To directly create an NFA equivalent to an input DFA, you can use the NFA.from_dfa method.

Related to review: pyOpenSci/software-submission#152

@caleb531 caleb531 added the correct-behavior The reported issue is not actually a bug, but represents the correct and intended behavior label May 16, 2024
@caleb531
Copy link
Owner

caleb531 commented Jun 4, 2024

Closing this issue as per @eliotwrobson's comment, this is the expected behavior.

@caleb531 caleb531 closed this as completed Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
correct-behavior The reported issue is not actually a bug, but represents the correct and intended behavior
Projects
None yet
Development

No branches or pull requests

3 participants