Difference between density matrix and completeness relation - quantum-computing

The expression for completeness relation in quantum mechanics is -
Σ |ψ_n><ψ_n| = 1
where the expression for density matrix in statistical mechanics is -
ρ = Σ p_n |ψ_n><ψ_n|
Both of the equation looks the same. So what are the differences between the density matrix and completeness relation?
What is the basic difference between them?

Formally the difference is that for the density matrix there are pre-factors p_n which sum up to 1 rather than all being 1 as in the completeness relation.
The meaning is also quite different.
Here is a rough illustration what they mean:
This object is a projection operator:
|ψ_n><ψ_n|
It projects on the n-th basis vector.
For simplicity lets take a simple example. Say our Hilbert space is 3 dimensional. Then the sum runs from 1 to 3. Each so-called pure state can be represented by a vector of length 1 in a 3 dimensional space like these examples:
|ψ_1> = (1, 0, 0)T
|ψ_2> = (0, 1, 0)T
|ψ_3> = (0, 0, 1)T
|φ> := (0, 1/2^0.5, 1/2^0.5)T
(The "T" stands for transposed)
These projection operators can be written as a matrix like for example:
/ 0 0 0 \
|ψ_2><ψ_2| = | 0 1 0 |
\ 0 0 0 /
Now what these projection operators do is projecting a vector on one of the coordinate axes. E.g. for n=2 we project to the y-axis.
|ψ_2><ψ_2|φ> = (0, 1/2^0.5, 0)
Now what the completeness relation says is that the sum of those 3 vectors you get when projection on each coordinate axis is once again the original vector (see Basis Decomposition).
As this is true for any vector, this means the operation is the identity matrix:
/ 1 0 0 \ + / 0 0 0 \ + / 0 0 0 \ / 1 0 0 \
|ψ_1><ψ_1| + |ψ_2><ψ_2| + |ψ_3><ψ_3| = | 0 0 0 | + | 0 1 0 | + | 0 0 0 | = | 0 1 0 | = 1
\ 0 0 0 / + \ 0 0 0 / + \ 0 0 1 / \ 0 0 1 /
Now the density matrix is a completely different matter. The weights p_n describe how one state is a mixture of several "pure" states. See e.g. https://en.wikipedia.org/wiki/Density_matrix

Related

How to unfold a Matrix on Matlab?

I have a given matrix H and I would like to unfold (expand) it to find a matrix B by following the method below :
Let H be a matrix of dimension m × n. Let x = gcd (m,n)
The matrix H is cut in two parts.
The cutting pattern being such that :
The "diagonal cut" is made by alternately moving c = n/x units to the right (we move c units to the right several times).
We alternately move c-b = m/x units down (i.e. b = (n-m)/x) (we move b units down several times).
After applying this "diagonal cut" of the matrix, we copy and paste the two parts repeatedly to obtain the matrix B.
Exemple : Let the matrix H of dimension m × n = 5 × 10 defined by :
1 0 1 1 1 0 1 1 0 0
0 1 1 0 0 1 1 0 1 1
1 1 0 1 1 1 0 1 0 0
0 1 1 0 1 0 1 0 1 1
1 0 0 1 0 1 0 1 1 1
Let's calculate x = gcd (m,n) = gcd (5,10) = 5,
Alternatively move to the right : c = n/x = 10/5 = 2,
Alternatively move down : b = (n-m)/x = (10-5)/5 = 1.
Diagonal cutting diagram : The matrix H is cut in two parts.
The cutting pattern is such that :
We move c = 2 units to the right several times c = 2 units to the right,
We repeatedly move c - b = 1 unit downwards.
We get :
After applying this "diagonal cut" of the matrix, we copy and paste the two parts repeatedly to obtain the matrix :
Remark : In the matrices X, X1 and X2 the dashes are zeros.
The resulting matrix B is (L is factor) :
Any suggestions?
This can be done by creating a logical mask with the cutting pattern, and then element-wise multiplying the input by the mask and by its negation. Repeating by L can be done with blkdiag.
H = [1 0 1 1 1 0 1 1 0 0
0 1 1 0 0 1 1 0 1 1
1 1 0 1 1 1 0 1 0 0
0 1 1 0 1 0 1 0 1 1
1 0 0 1 0 1 0 1 1 1];
L = 2;
[m, n] = size(H);
x = gcd(m, n);
c = n / x;
b = (n-m)/x;
mask = repelem(tril(true(m/b)), b, c);
A = [H.*mask; H.*~mask];
A = repmat({A}, L, 1);
B = blkdiag(A{:});

Reverse process of a matrix expansion on Matlab

My program allows to multiply a given B matrix with a z factor with some characteristics listed below, to give an H matrix. I would like to have a programming idea to do the inverse of what I programmed. That is to say with a given H matrix find the value of the B matrix.
For example with a matrix B = [-1 -1 ; 1 0]
I get with my code a matrix :
H = [ 0 0 0 0 0 0 ;
0 0 0 0 0 0 ;
0 0 0 0 0 0 ;
0 1 0 1 0 0 ;
0 0 1 0 1 0 ;
1 0 0 0 0 1 ]
I would like to have from a code H the value of the matrix B.
To specify the matrix H from the matrix B, it is necessary that:
Each coefficient -1 is replaced by a null matrix of dimension z*z;
Each coefficient 0 is replaced by an identity matrix of dimension z*z;
Each coefficient 1,2,...,z-1 is replaced by a circulating permutation matrix of dimension z*z shifted by 1,2,...,z-1 position to the right.
From a matrix B and the expansion factors z , we construct an extended binary H matrix with n-k rows and n columns.
My code :
clear;
close all;
B = [-1 -1 ; 1 0];
z = 3;
H = zeros(size(B)*z);
Y = eye(z);
for X1 = 1:size(B,1)
for X2 = 1:size(B,2)
X3 = B(X1,X2);
if (X3 > -1)
X4 = circshift(Y,[0 X3]);
else
X4 = zeros(z);
end
Y1 = (X1-1)*z+1:X1*z;
Y2 = (X2-1)*z+1:X2*z;
H(Y1,Y2) = X4;
end
end
[M,N] = size(H);
Any suggestions?
Assuming that all of the input matrices are well-formed, you can determine the mapping based on the first row of each block. For example, the block mapping to 1:
0 1 0
0 0 1
1 0 0
has a 1 in column 2 of row 1. Similarly, a one in column 1 maps to 0, and column 3 maps to 2. No ones in the row maps to -1. So we just need to find the column containing the 1 in the first row.
Annoyingly, find returns null when it doesn't find a nonzero value rather than 0 (which is what we would want in this case). We can adjust to this by adding a value to the matrix row that is only 1 when all of the others are 0.
If you have the Image Processing Toolbox, you can use blockproc to handle the looping for you:
B = blockproc(H, [z z], #(A)find([~any(A.data(1,:)) A.data(1,:)])-2);
Otherwise, just loop over the blocks and apply the function to each one.

Effect of S-gate on one qubit of a combined(maybe entangled) state of 3 qubits

Suppose I have a register(qs) of 3 qubits (first 2 being used solely for control, the last one is the input) . The first two control qubits are in the |+> state and the state of the 3rd input is unknown. Let it be a|0> + b|1>.
Now I apply CCNOT(qs[0],qs[1],qs[2]) so their combined state becomes 0.5(a,b,a,b,a,b,b,a) in Transposed matrix form [Please correct if I'm wrong here] . Now I apply S-gate to the 3rd qubit which transforms |1> -> i|1> .
I am unable to guess the state of the combined state of 'qs' now.
What I thought:
One logic is to multiply every state by 'i' if it has the form|XY1> so the combined state becomes 0.5(a,ib,a,ib,a,ib,b,ia) [Transposed]
Another logic is to find tensor product of (I x I x S) since I'm not changing the first 2 qubits. Performing this yields a different result which is 0.5(a,b,a,b,ia,ib,ib,ia) [Transposed] [Again, correct me if I'm wrong].
Which is the correct output after passing through S-gate (if any) ?
The first two qubits can't start in |+> state, since |+> is a single-qubit state. I assume that the starting state of the first two qubits in the register is 0.5 (|00> + |01> + |10> + |11>).
Both approaches are correct, because they are different ways to represent the same transformation. The first answer 0.5(a,ib,a,ib,a,ib,b,ia) [Transposed] is correct. Your second answer 0.5(a,b,a,b,ia,ib,ib,ia) [Transposed] seems to be obtained by multiplying by S x I x I, i.e., applying S gate on the first qubit instead of the third one.
The tensor product I x I x S can be calculated as tensor product of I x I (which is just a 4x4 identity matrix) and S. The result is an 8x8 matrix which consists of 16 copies of S matrix, multiplied by corresponding elements of I x I:
1 0 | 0 0 | 0 0 | 0 0
0 i | 0 0 | 0 0 | 0 0
- - - - - - - -
0 0 | 1 0 | 0 0 | 0 0
0 0 | 0 i | 0 0 | 0 0
- - - - - - - -
0 0 | 0 0 | 1 0 | 0 0
0 0 | 0 0 | 0 i | 0 0
- - - - - - - -
0 0 | 0 0 | 0 0 | 1 0
0 0 | 0 0 | 0 0 | 0 i
If you multiply the state of the qubits by this matrix, you'll get the same answer as in the first approach.

How to see if an array is contained (in the same order) of another array in matlab?

I have an array A of 1s and 0s and want to see if the larger array of bits B contains those bits in that exact order?
Example: A= [0 1 1 0 0 0 0 1]
B= [0 1 0 0 1 1 0 0 0 0 1 0 1 0 1]
would be true as A is contained in B
Most solutions I have found only determine if a value IS contained in another matrix, this is no good here as it is already certain that both matrices will be 1s and 0s
Thanks
One (albeit unusual) option, since you're dealing with integer values, is to convert A and B to character arrays and use the contains function:
isWithin = contains(char(B), char(A));
There are some obtuse vectorized ways to to do this, but by far the easiest, and likely just as efficient, is to use a loop with a sliding window,
A = [0 1 1 0 0 0 0 1];
B = [0 1 0 0 1 1 0 0 0 0 1 0 1 0 1];
vec = 0:(numel(A)-1);
for idx = 1:(numel(B)-numel(A)-1)
if all(A==B(idx+vec))
fprintf('A is contained in B\n');
break; % exit the loop as soon as 1 match is found
end
end
Or if you want to know the location(s) in B (of potentially multiple matches) then,
A = [0 1 1 0 0 0 0 1];
B = [0 1 0 0 1 1 0 0 0 0 1 0 1 0 1];
C = false(1,numel(B)-numel(A)-1);
vec = 0:(numel(A)-1);
for idx = 1:numel(C)
C(idx) = all(A==B(idx+vec));
end
if any(C)
fprintf('A is contained in B\n');
end
In this case
>> C
C =
1×6 logical array
0 0 0 1 0 0
You can use the cross-correlation between two signals for this, as a measure of local similarity.
For achieving good results, you need to shift A and B so that you don't have the value 0 any more. Then compute the correlation between the two of them with conv (keeping in mind that the convolution is the cross-correlation with one signal flipped), and normalize with the energy of A so that you get a perfect match whenever you get the value 1:
conv(B-0.5, flip(A)-0.5, 'valid')/sum((A-0.5).^2)
In the normalization term, flipping is removed as it does not change the value.
It gives:
[0 -0.5 0.25 1 0 0 -0.25 0]
4th element is 1, so starting from index equal to 4 you get a perfect match.

Create a matrix with a diagonal and left-diagonal of all 1s in MATLAB

I would like to create a square matrix of size n x n where the diagonal elements as well as the left-diagonal are all equal to 1. The rest of the elements are equal to 0.
For example, this would be the expected result if the matrix was 5 x 5:
1 0 0 0 0
1 1 0 0 0
0 1 1 0 0
0 0 1 1 0
0 0 0 1 1
How could I do this in MATLAB?
Trivial using the tril function:
tril(ones(n),0) - tril(ones(n),-2)
And if you wanted a thicker line of 1s just adjust that -2:
n = 10;
m = 4;
tril(ones(n),0) - tril(ones(n),-m)
If you prefer to use diag like excaza suggested then try
diag(ones(n,1)) + diag(ones(n-1,1),-1)
but you can't control the 'thickness' of the stripe this way. However, for a thickness of 2, it might perform better. You'd have to test it though.
You can also use spdiags too to create that matrix:
n = 5;
v = ones(n,1);
d = full(spdiags([v v], [-1 0], n, n));
We get:
>> d
d =
1 0 0 0 0
1 1 0 0 0
0 1 1 0 0
0 0 1 1 0
0 0 0 1 1
The first two lines define the desired size of the matrix, assuming a square n x n as well as a vector of all ones that is of length n x 1. We then call spdiags to define where along the diagonal of this matrix this vector will be populating. We want to define the main diagonal to have all ones as well as the diagonal to the left of the main diagonal, or -1 away from the main diagonal. spdiags will adjust the total number of elements for the diagonal away from the main to compensate.
We also ensure that the output is of size n x n, but this matrix is actually sparse . We need to convert the matrix to full to complete the result.,
With a bit of indices juggling, you can also do this:
N = 5;
ind = repelem(1:N, 2); % [1 1 2 2 3 3 ... N N]
M = full(sparse(ind(2:end), ind(1:end-1), 1))
Simple approach using linear indexing:
n = 5;
M = eye(n);
M(2:n+1:end) = 1;
This can also be done with bsxfun:
n = 5; %// matrix size
d = [0 -1]; %// diagonals you want set to 1
M = double(ismember(bsxfun(#minus, 1:n, (1:n).'), d));
For example, to obtain a 5x5 matrix with the main diagonal and the two diagonals below set to 1, define n=5 and d = [0 -1 -2], which gives
M =
1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
0 1 1 1 0
0 0 1 1 1

Resources