Question: new _ trans nfa qs Type: ( ' q , ' s ) nfa _ t - > ' q list - > ( '

new_trans nfa qs
Type:('q,'s) nfa_t ->'q list ->('q list, 's) transition list
Description: The inputs are an NFA and a list of states. The output is a transition list. Each element in the returned list is a tuple in the form of (src, char, dest), where 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 (sigma), followed by any number of epsilon transitions. This may seem a little confusing at first, so make sure you look at the examples below!
Examples:
type ('q,'s) transi ='q *'s option *'q
type ('q,'s) nfa_y ={ sigma : 's list; qs : 'q list; q0 : 'q; fs : 'q list; delta : ('q,'s) transi list; }
let nfa2={ sigma =['z']; qs =[1; 2; 3]; q0=1; fs =[3]; delta =[(1, Some 'z',2); (2, None, 3)]}
let dfa2={sigma =['z'; 'y'; 'x']; qs =[1; 2; 3]; q0=1; fs =[3]; delta =[(1, Some 'z',2); (2, Some 'y',1); (2, Some 'x',3)]};;
transFresh nfa2[1]=[([1], Some 'z',[2; 3])]
transFresh dfa2[1; 2]=[([1; 2], Some 'z',[2]); ([1; 2], Some 'y',[1]); ([1; 2], Some 'x',[3])]
transFresh dfa2[2; 3]=[([2; 3], Some 'z',[]); ([2; 3], Some 'y',[1]); ([2; 3], Some 'x',[3])]
Explanation:
Starting from state 1 in nfa2, we can move only to state 2 on 'z' and then from state 2 to state 3 on epsilon, which gives us the tuple ([1], Some 'z',[2; 3]).'z' is the only character in the alphabet. So, we return [([1], Some 'z',[2; 3])].
Starting from either state 1 or state 2 in dfa2, we want to see where we can move to. If we start at 1, we can move to 2 on 'z', and if we start at 2, there isn't an 'z' transition. There are no states we can move to from 2 via epsilons (because it's a DFA), so we have the tuple ([1; 2], Some 'z',[2]). Then, starting again from either state 1 or state 2, we can move to 1 on 'y' from 2, and there isn't a 'y' transition from 1 to another state. There are no states we can move to from 1 via epsilons, so we have the tuple ([1; 2], Some 'y',[1]). Then, starting again from either state 1 or state 2, we can move to 3 on 'x' from 2, and there isn't a 'x' transition from 1 to another state. There are no states we can move to from 3 via epsilons, so we have the tuple ([1; 2], Some 'x',[3]). So, our overall returned list is [([1; 2], Some 'z',[2]); ([1; 2], Some 'y',[1]); ([1; 2], Some 'x',[3])].
Starting from either state 2 or state 3 in dfa2, there is no 'z' transition that starts from either state 2 or state 3. So, we have ([2;3], Some 'z',[]). Then, starting again from either state 2 or state 3, we can move to 1 on 'y' from 2, and there isn't a 'y' transition from 3 to another state. There are no states we can move to from 1 via epsilons (because it's a DFA), so we have ([2;3], Some 'y',[1]). Then, starting again from either state 2 or state 3, we can move to state 3 on 'x' from 2, and there isn't a 'x' transition from 3 to another state. There are no states we can move to from 3 via epsilons, so we have ([2;3], Some 'x',[3]). So, our overall returned list is [([2;3], Some 'z',[]); ([2;3], Some 'y',[1]); ([2;3], Some 'x',[3])].

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!