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

Get arbitrary word using DFS #413

Merged
merged 1 commit into from
Jun 26, 2024
Merged

Get arbitrary word using DFS #413

merged 1 commit into from
Jun 26, 2024

Conversation

Adda0
Copy link
Collaborator

@Adda0 Adda0 commented Jun 26, 2024

This PR adds a method to get an arbitrary word accepted by an NFA using DFS. Since we are using a bit vector of searched states, the NFA does not need to be trimmed to prevent cycling in DFS.

This PR resolves #411.

result.insert(new_word);
}
}
if (move.symbol < first_epsilon) { new_word.push_back(move.symbol); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curr_length is not correctly updated with epsilon transitions. So it should be updated here I think.
But then, you cannot have epsilon loops, otherwise this procedure will never finish.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current length (and the maximal length) here was (and still is) implemented as the number of transitions made, not the length of the words (which it should be, as per the function description). That is OK until you start working with epsilons.

We could, for example, remove epsilon transitions to solve this issue (or simply start the removal by checking that the computation of epsilon closure for a given state does not try to add the same state twice, otherwise perform the actual removal).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require a larger refactorization of the epsilon removal function and the function to get words of a specific length. Therefore, I will remove these changes from this PR and rework this in another PR. The only changes kept in this PR are the changes introducing get_word() which works correctly even with epsilons.

result.insert(mata::Word());
}
worklist.emplace_back(init_state, Word{});
if (final.contains(init_state)) { result.insert(Word{}); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for putting this on one line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not. Just that it is shorter. A matter of taste change (caused by the fact that I earlier modified the body of the condition and later removed the added code again).

@Adda0
Copy link
Collaborator Author

Adda0 commented Jun 26, 2024

Since the addition of the new method was approved, I will merge the trimmed PR.

@Adda0 Adda0 merged commit 9c9924e into devel Jun 26, 2024
18 checks passed
@Adda0 Adda0 deleted the get_word branch June 26, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add function to return arbitrary accepting word
2 participants