Question: In Ocaml: Write: n _ to _ d n Type: ( ' q , ' s ) nfa _ t - > ( ' q
In Ocaml:
Write:
ntod n
Type: qsnfat q list, snfat
Which takes an input NFA and converts it to an equivalent DFA. Assume that, for all NFAs nfa and for all strings saccept nfa s accept nfatodfa nfas
YOU MAY NOT USE ANY IMPERATIVE FUNCTIONS.
THIS INCLUDES REFERENCES, FOR AND WHILE LOOPS.
Suggestions
The ntod algorithm is pretty substantial. While you are free to design it in whatever manner you like, we suggest you consider writing a helper function ntodstep. Efficiency matters here, and if your code times out, it will fail the tests. Try to minimize the calls to List and Set to prevent this. We time out at minutes
OPTIONAL: Skip if you feel you have a better implementation
ntodstep n d wrk
Type: qsnfat q list, snfat q list list q list, snfat
Description: First, let's take a look at what is being passed into the function for clarity:
Parameters
nfa: the NFA to be converted into a DFA.
dfa: the DFA to be created from the NFA. This will act as the accumulator in the function. Each time this function is called, the DFA should be updated based on the worklist.
wrk: a list of unvisited states.
Given an NFA, a partial DFA, and a worklist, this function will compute one step of the subset construction algorithm. This means that we take an unvisited DFA state from the worklist and add it to our DFA that we are creating updating the list of all states, transitions, and final states appropriately
Our worklist is then updated for the next iteration by removing the newly processed state. You will want to use the previous three functions as helpers. They can be used to update the DFA's states, transitions, and final states.
Below is a list of all functions and types already written that you have access to:
type qstransi q s option q
type qsnfay sigma : s list; qs : q list; q: q; fs : q list; delta : qstransi list;
So: let nfa sigma z; qs ; ; ; q; fs ; delta Some z; None
let dfa sigma z; y; x; qs ; ; ; q; fs ; delta Some z; Some y; Some x;;
mo n ql tof Type: qsnfay q list s option q list, takes an NFA na set of initial states qland a symbol option tIt returns a set of states that the NFA might be in after starting from any state in ql and making one transition on the symbol t
So: mo nfa Some z
mo nfa Some z
mo nfa Some z
mo nfa ;Some z
mo nfa None
eclo n qlof Type: qsnfay q list q list, takes an NFA n and a set of initial states qlIt returns a set of states that the NFA might be in after making zero or more epsilon transitions from any state in ql
So: eclo nfa
eclo nfa ;
eclo nfa
eclo nfa ;;;
acce n tof Type: qcharnfay string bool which takes an NFA nfa and a string sand returns true if the NFA accepts the string.
So: acce dfa false;; dfaex is the NFA defined above
acce dfa zxtrue;;
acce dfa zyxfalse;;
acce dfa zyzxtrue;;
stateFresh n qtof Type: qsnfat q list q list list, which takes an NFA and a list of states and outputs a list of state lists. Each element in the returned list is the list you can get to by starting from any state in the inputted list and moving on one character of the alphabet sigmafollowed by any number of epsilon transitions.
So: stateFresh nfa ; ;;
stateFresh dfa ; ; ; ;;
stateFresh dfa ; ; ; ;;
transFresh n qtof Type: qsnfat q list q list, stransition list, takes an NFA and a list of statesand returns list of transitions. Each element in the returned list is a tuple in the form of srcchar destwhere dest is the list of states you can get to after starting from any state in the inputted list and moving on one character of the alphabet sigmafollowed by any number of epsilon transitions.
So: transFresh nfa Some z;
transFresh dfa ; ; Some z; ; Some y; ; Some x
transFresh dfa ; ; Some z; ; Some y; ; Some x
finalFresh n qtof Type: qsnfat q list q list list, takes an NFA and a list of states, return qtif an element of qt is a final state in the given NFA. Return otherwise
So: finalFresh dfa ; ; ; ;
finalFresh dfa ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
