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

Check for bug in .union for transitions that go backwards #11

Open
andrew-johnson-4 opened this issue Mar 1, 2023 · 8 comments
Open
Labels
bug Something isn't working
Milestone

Comments

@andrew-johnson-4
Copy link
Owner

This may be bugged, the current solution seems shaky. Try union on some more complex state machines in tests.

@andrew-johnson-4 andrew-johnson-4 added this to the 0.1 milestone Mar 1, 2023
@andrew-johnson-4 andrew-johnson-4 added the bug Something isn't working label Mar 1, 2023
@andrew-johnson-4
Copy link
Owner Author

The theoretical logic for union is

  • If a sequence of input could be in both state machines, stay in the middle
  • If a sequence falls off of the intersection, but is still on track for one state machine, then continue to follow the sequence of that machine
  • otherwise reject

I think this algorithm provides closure for all possible DFAs. It would be nice to avoid NFA construction for such a basic operation.

@andrew-johnson-4
Copy link
Owner Author

Maybe something like a(bc)*d union (ab)*cd union ab(cd)*.

@andrew-johnson-4
Copy link
Owner Author

#12

@andrew-johnson-4
Copy link
Owner Author

Update with solution: Since this is union, we don't care if one or both machines could potentially accept, so these states can be merged. Thus "backwards" transitions can move back onto the middle path and we don't care about the implication. Any accept states from either machine will be final states for the union.

@andrew-johnson-4
Copy link
Owner Author

The precise union of DFAs is defined simply as the union of final states + the product of transitions.

@andrew-johnson-4
Copy link
Owner Author

(ab)* union aa could yield a 3x3 dfa where:

(0,0) -> a -> (1,1)
(1,1) -> a -> (2,0)
(1,1) -> b -> (0,2)
(0,1) -> b -> (0,2)
(0,2) -> a -> (0,1)

which is still xy bounded in space and time complexity, but this bugs out with current union op.

@andrew-johnson-4
Copy link
Owner Author

I heard a rumor that a.union(b) is equivalent to a.complement().intersect(b.complement()).complement(). I think the reason it didn't work previously was because complement is not completely correct.

@andrew-johnson-4
Copy link
Owner Author

The simplest union algorithm that I can think of is that a union state is either

  • rejected
  • on the left
  • on the right
  • on the intersection

This algorithm would still yield an O(xy) upper bound, so it is a good fallback to cover the problematic cases with back edges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant