NFA to DFA where a state only has an epsilon transition - dfa

If when converting the NFA table to the DFA table there is a state that only as an epsilon transition, how is it converted onto the DFA table.
For example if state 1 only accepts 2 in the ε column, how will it look in the DFA conversion?
Transition table:
a b c ε
1 {} {} {} {2}
2 {3} {} {} {}
3 {4} {3,4} {} {}
4 {4} {} {} {}

I think it's better if you first eliminate epsilon transition to get NFA (without epsilon transition). From NFA it should be easier to get the equivalent DFA.
How to eliminate epsilon transition?
First, we have term ECLOSE of a state. ECLOSE(q) is defined as set of all states (including state q itself) that can be reached by following epsilon transition.
In your case:
ECLOSE(1) = {1,2}
To eliminate epsilon transition, follow below steps:
If ECLOSE(1) contains the final state, then set state 1 as final
state
Add transition (with respective label) from state 1 to state q if and only if there is a transition from some states in ECLOSE(1) to state q
Now you can remove all epsilon transitions.
After above steps (you didn't specify which states are start and or final states), you should get:
a b c
1 {3} {} {}
2 {3} {} {}
3 {4} {3,4} {}
4 {4} {} {}

Related

Difference between different Quantum states with the same result

What is the practical and theoretical difference is between these 3 states, which ultimately produce the same output result.
Could you tell me some examples of different results obtained starting from these 3 states and doing the same operations below.
The concept is unclear to me.
Thank you
|0> -> RY(pi/2) -> RX(pi) -> cnot q[0] q[1]
|0> -> RX(pi/2) -> cnot q[0] q[1]
|0> -> H -> cnot q[0] q[1]
Not all of these states are the same, assuming that you're talking about the single-qubit states obtained before application of the CNOT gate (otherwise please specify which single-qubit gates are applied to which qubit in the 2-qubit state).
The last state is H|0⟩ = 1/sqrt(2) (|0⟩ + |1⟩).
The first state ends up being the same state, up to a global phase, which means there is no way to observe a difference between these two states.
But the second state is 1/sqrt(2) (|0⟩ - i|1⟩), which behaves differently.
To observe the difference between the second and the last states, apply a Hadamard gate to both and measure them multiple times: you'll always get 0 result for the last state, but you'll get both 0 and 1 for the second state.
To quickly run this experiment, you can use Q#: running the following snippet will give you ~50 0 measurements for the state prepared using Rx and 100 0 measurements for the state prepared using H.
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Math;
operation RunTests (prep : (Qubit => Unit)) : Unit {
mutable n0 = 0;
use q = Qubit();
for _ in 1 .. 100 {
// Prepare the qubit in the given state.
prep(q);
// Apply Hadamard gate and measure.
H(q);
if M(q) == Zero {
set n0 += 1;
}
Reset(q);
}
Message($"{n0} zeros measured");
}
operation QubitsDemo () : Unit {
RunTests(Rx(PI() / 2.0, _));
RunTests(H);
}

How does the epsilon conversion work for NFA to DFA conversion?

This is the NFA:
Here are two tables I made for DFA and then my attempt for the DFA equivalent:
(source: yimg.com)
The problem is that it doesn't account for the epsilon, because I don't know how to convert when there are epsilon arrows.
This is an epsilon-NFA, just transform the epsilon-NFA into an equivalent NFA without the epsilon transitions. Make a table as you would do while transforming an NFA to a DFA, and instead of just checking where that state goes with an input, first, check the where it can go with epsilon transitions then with the input then again with the epsilon transition (this is called the epsilon-closure ). This way you will have sets of states you will reach with your inputs. The only thing you need to do is to mark any state that can reach a final state using only epsilon transition as final states as well. Then you can build an NFA without epsilon transitions and then you can use your knowledge to transform it into a DFA. Just an example; In your table, you show B has an empty set for the input 0 but it can actually take an epsilon transition to C and take a 0 there so it is actually not an empty set.
To account for the epsilon transitions you can do any number of epsilon transitions before and after your read the next symbol. So you don't only consider where you can go when you read the symbol 0 (as an example) but also consider where you can go when you do epsilon transitions before and after, like ε* 0 ε*.
This means that when you start at the state {A} and read the symbol 0 you can go to the following states:
A --0--> B
A --0--> B --ε--> C
A --0--> C
A --ε--> B --ε--> C --0--> C
And for reading the symbol 1 you can go to the following states:
A --1--> A
A --1--> A --ε--> B
A --1--> A --ε--> B --ε--> C
A --ε--> B --1--> B
A --ε--> B --1--> B --ε--> C
A --ε--> B --ε--> C --1--> C
So in your resulting DFA, the transition will look as follow:
+-------+---------+---------+
| state | 0 | 1 |
+-------+---------+---------+
| {A} | {B,C} | {A,B,C} |
+-------+---------+---------+

Quantum V gate 1/sqrt(5) ( I + 2iZ)

By definition, the gate 1/sqrt(5) (I + 2iZ) should act on a qubit a|0> + b|1> to transform it into 1/sqrt(5) ((1+2i)a|0> + (1-2i)b|1>) but transformations of each RUS step does the following-
The ancillas are in |+> state at first
Starting form: 1/sqrt(2) (a,b,a,b,a,b,a,b)
CCNOT(ancillas, input): 1/sqrt(2) (a,b,a,b,a,b,b,a)
S(input): 1/sqrt(2) (a,ib,a,ib,a,ib,b,ia)
CCNOT(ancillas, input): 1/sqrt(2) (a,ib,a,ib,a,ib,ia,b)
Z(input) : 1/sqrt(2) (a,-ib,a,-ib,a,-ib,ia,-b)
Now measuring the ancillas in PauliX basis is equivalent to PauliZ measurement after applying H() to the state. Now I have 2 confusions, should I apply H x H x I or H x H x H to the combined state. Also neither of these transformations turn out to be equivalent to the V-gate defined in the first paragraph when both measurements are Zero. Where did I go wrong?
Reference: https://github.com/microsoft/Quantum/blob/master/samples/diagnostics/unit-testing/RepeatUntilSuccessCircuits.qs (1st sample code)
The transformation is correct, though it takes some time with pen and paper to verify it.
As a side note, we start with a state |+>|+>(a|0> + b|1>), which is 0.5 (a,b,a,b,a,b,a,b) in vector form (both |+> states contribute a 1/sqrt(2) to the coefficients). It will not affect our calculations of the state after the measurement, since it will have to be renormalized, but it's still worth noting.
After a sequence of CCNOT, S, CCNOT, Z we get 0.5 (a,-ib,a,-ib,a,-ib,ia,-b). Since we're measuring only the first two qubits in PauliX basis, we need to apply Hadamards only to the first two qubits, or H x H x I to the combined state.
I'll take the liberty to skip writing out the whole expression after applying Hadamards and fast-forward to the results of measurements, and here is why. We're only interested in the state of the input qubit if both measurements yielded 0, so it's sufficient to gather only the terms of the overall state which have |00> as the state of the first two qubits.
The state of the third qubit after measuring |00> on the first qubit will be: (3+i)a |0> - (3i+1)b |1>, multiplied by some normalization coefficient c.
c = 1/sqrt(|3+i|^2 + |3i+1|^2) = 1/sqrt(10)).
Now we need to check whether the state we got, |S_actual> = 1/sqrt(10) ((3+i)a |0> - (3i+1)b |1>)
is the same state as we'd expect to get from applying the V gate,
|S_expected> = 1/sqrt(5) ((1+2i)a |0> + (1-2i)b |1>). They do not look the same, but remember that in quantum computing the states are defined up to a global phase. Thus, if we can find a complex number p with an absolute value 1 for which |S_actual> = p * |S_expected>, the states will be effectively the same.
This translates into the following equations for p and amplitudes of |0> and |1>: (3+i)/sqrt(2) = p (1+2i) and -(3i+1)/sqrt(2) = p (1-2i). We solve both equations to get p = (1-i)/sqrt(2) which has indeed the absolute value 1.
Thus, we can conclude that indeed the state we got after all the transformations is indeed equivalent to the state we'd get by applying a V gate.

Show that the language is decidable

How do I show this language
{<C,A,B> | C,A,B are DFAs, L(C) contains the shuffle of L(A) and L(B)}
is decidable ?
I believe if I can construct automatas for A and B, then I can get an automata that contains the shuffle of them.
I am also thinking about using emptiness testing but I have not made any progress yet.
Given DFAs A and B, construct a DFA D such that L(D) is equal to the shuffle of L(A) and L(B).
Then, construct two DFAs using the Cartesian Product Machine construction for the languages L(M1) = L(C) \ L(D) and L(M2) = L(D) \ L(C).
Determine which, if either of L(M1) and/or L(M2) is empty.
if L(M1) is empty and L(M2) is empty, L(C) is the shuffle of L(A) and L(B)
if L(M1) is empty, L(C) is a subset of the shuffle of L(A) and L(B)
if L(M2) is empty, L(C) is a superset of the shuffle of L(A) and L(B)
To do #1: create a new DFA whose states are triples (x, y, z) where:
x is a state from A
y is a state from B
z is either 1 or 2
The initial state of the DFA will be (qi_A, qi_B, 1). The input alphabet will be the union of the input alphabets of A and B. The transitions will be such that:
f((x,y,1), a) = (x',y,2) where f(x,a) = x' in machine A
f((x,y,2), b) = (x,y',1) where f(y,b) = y' in machine B
The accepting states shall be the states with are accepting in either A or B (or just B if you prefer).
To do #2: create a new DFA whose states are pairs (x, y) where:
x is a state from D
y is a state from C
The initial state of he DFA will be (qi_D, qi_C). The input alphabet will be the union of input alphabets of A and C. The transitions will be such that:
f((x,y),c) = (x',y') where f(x,c) = x' in D and f(y,c) = y' in C.
The accepting states will be:
states that are accepting in D but not C, for L(D) \ L(C)
states that are accepting in C but not D, for L(C) \ L(D)
To do #3:
You can minimize the DFAs using the well-known DFA minimization algorithm. Iff you end up with a DFA that has a single non-accepting state, the language is empty.
You can try all input strings up to the pumping length for the resulting DFA (strings that don't cause the DFA to enter any state more than once). If none of these are accepted by the DFA, then the DFA accepts no strings and the language is empty.

Can a DFA state have two arrows pointing to it with the same value?

I know that to be considered a DFA, each state cannot have more than one arrow with the same value pointing to another state. However, can a DFA have a state that has two arrows pointing to it with the same value?
Sure. As long as each response is deterministic, several states might go to the same state on the same next input. Since you can only be in one of the states, determinism isn't lost.
x
A ----> B
| |
|y |z
| |
V z V
C ----> D

Resources