Abstract

This document the formal definitions and constructs for 3 primary DFAs/NFAs, with two extra considered for extra credit. We seek to prove that a language is regular by providing a DFA that recognizes it.

IMPORTANT NOTE: My image rendered is currently a bit broken, and will sometimes jump a page(will rewrite myself soon). For now, refer to figure caption to match images to their respective location.


Definitions

We define a DFA/NFA as a 5 tuple:

Where:

  • is a finite set of states
  • is a finite set of symbols
  • is the transition function
  • is the start state
  • is the Set of accepting states

Problem 1

Construct a DFA that recognizes the language:

Provide a formal definition and a state diagram. 

Formal Definition

States

  • is state where next symbol is odd position
  • is state where next symbol is even position
  • is the sink state for all error

Language/Alphabet

Transition Function

Start State

Accepting States

State Diagram

provided by mermaid

  • white dot is start state entry point
  • highlighted state is accepted state

see figure 1

Problem 1 State Diagram


Problem 2

For any string , the reverse of w, written , is the string in reverse order, . For any language , let .

Prove that if is regular, so is . For this, consider how, starting with any arbitrary NFA to recognize , you’d modify the NFA to recognize . Once you have the idea, write a recipe that would work for any NFA.

Idea / Goal

We are looking to show that when is regular, so is . Suppose is an NFA that:

Where this NFA can be represented as . We want to create an NFA that recognizes

Construction

We define this new NFA as :

It remains relatively unchanged compared to the original, except for a few key differences:

  • we add a new state, to the states set , where , which is essentially the new entry point for the NFA
  • we add a new accept state, which is now
  • we reverse the transitions in the transition function:
    • if can transition to through , then we reverse the transition
    • new transition function should look something like:

where “p to q through a” is representing

  • epsilon transition is added for the new start state to the next state in line :

Formal Definition

We now define the NFA with the following:

States:

States is and which is

Alphabet/Finite Set of Symbols:

Alphabet stays the same as so just treat it as such

Transition Function

where new start state is taking path of

Start State

New start state is

Accept States

For this theoretical NFA, the accept state is

Reason This Works

This works for this example, as in the original NFA, we use a string w that is accepted if there is such path from to a state in that is labeled by w. When all the transitions are reversed, any of these paths now become f to labeled by the modified w, .

We have to add a new start state with the transition for the states in because we need to allow the automaton to “start” at any of the original accept states for it to be truly reversed.

The new accepting condition comes by finding if there is a string that can take from to that is labeled as . Essentially, there needs to be some path in from to some in that is labeled by the inverse, . So: for this point in .

For this reason, can recognize exactly.

Constructing a DFA. for

Using this we can effectively reverse any NFA to an equivalent DFA ( using our rules of subset construction, etc ), to ensure that there is a DFA that can recognize as required

All we need to do is take the NFA for , find for by reversing all transitions, creating new start state epsilon transition to original accept states, and making sure that the original start state is only accept state.

We can convert this to a DFA if we want to, but we know how to do this with subset construction.

Example of Reversing NFA

Original NFA :

see figure 2

Original NFA M

Reversed NFA with new entry point

see figure 3

Reversed NFA M^R


Problem 3

Let . Show that for each , the language is regular.

Hint: Construct the base case for and then construct a DFA for and notice what changes. Then use what you learned to complete the proof.

Hint: If you really get stuck, and you’ve already produced state diagrams for the and cases, try producing a state diagram for the case and consider what changes when going from to .

Given/Goal

We are looking to prove that for every time , language

is a regular language.

We can do this by constructing a DFA that will recognize it. We are looking to count the occurrences of in modulo .

Cases

We have cases to go through, so we will construct a state diagram for each one

Base Case

For , we know that all non negative integers are multiples of 1, so:

This is a very simple DFA, with only a single state that is both the start and the accepting.

see figure 4

Case n=

Case

When , we get:

This means that the language consists of all strings that have an even number of ‘s.

For this we only need two states:

  • all we have seen is even
  • all we have seen i odd

Transitions for these two should be:

  • points to when received
  • points to when received

see figure 5

Case n=

Case

When we get:

Which represents when the strings received have a number of ‘s that is divisible by 3

This DFA consists of 3 states:

  • when remainder is 0, multiple of 3
  • when remainder is 1 when
  • when remainder is 2 when

The transitions for these states are as follows:

  • points to when a received
  • points to when a received
  • points to when a received

see figure 6

Case n=

Expanding This out to All case

For any amount , we can construct a DFA with states:

  • will always be the start and accepting state
  • amount of states is dictated by number of

We can define a transition function for this relation with the following:

Essentially, we can conclude that for any number we can construct a finite automaton with a regular pattern.

Thus, is a regular language for all as required


Extra Credit Problem A

Convert the following NFA to an equivalent DFA. For subset construction, follow the recipe provided by Sipser Theorem 1.39 and the corresponding proof (as presented in class). Leave your construction unpruned, but be sure to indicate any unnecessary or unreachable states in the DFA thus constructed, if any.

see figure 7

Extra Credit Problem Demo

Listing Transitions

For state 1:

and has no b transition

For state 2:

For state 3:

since the b route goes to 2 and 3

Defining New DFA

  1. We define the start state as
  2. Going from to:
    • :
    • :
  3. Going from to:
    • :
    • :
  4. Going from to: ( note we define this as accept state )
    • :
    • :
  5. Going from to: ( also contains accept state )
    • :
    • :
  6. Going from to: (also contains accept state )
    • :
    • :
  7. Going from to:
    • :
    • :
  8. For Dead States :
    • for and :

Constructing Table Of Transitions

DFA StateOn On Accepting
No
No
Yes
Yes
Yes
No
No

Note:

I could be wrong, but it seems as though all states are reachable here, so no pruning would be needed even if we wanted to.

Constructing the DFA

Defining a DFA for:

  • States:
  • Alphabet:
  • Start State:
  • Accepting States:
  • Transitions:
    • 1 goes to 3 and
    • 3 goes to 2 and 2,3
    • 2 goes to 1 and
    • 2,3 goes to 1,2 and 2,3
    • 1,2 goes to 1,3 and
    • 1,3 goes to 2,3 and 2,3
    • goes to and

Diagram

provided by mermaid

see figure 8

Resulting Constructed DFA