I need to show that using following Hamiltonian (for a closed bipartite system), we are able to implement the Controlled-Not gate.
The Hamiltonian is :
𝐻=g/4 (𝐼 − 𝜎z )⊗ (𝐼 − 𝜎x)
Any tips will be appreciated.
I am not sure whether there is a typo in your Hamiltonian. If the Hamiltonian is $\hat{H} = g/4 (I - \sigma_z) \otimes (I - \sigma_z) $, then by explicit calculation
$$ \hat{H} = g/4
\begin{pmatrix}
0 & 0 & 0 & 0 \
0 & 0 & 0 & 0 \
0 & 0 & 0 & 0 \
0 & 0 & 0 & 4 \
\end{pmatrix}
$$
Then, with appropriate evolution time $t$ with respect to $g$, we have the unitary generated by the Hamiltonian
$$U = e^{-i \hat{H} t } = \begin{pmatrix}
1 & 0 & 0 & 0 \
0 & 1 & 0 & 0 \
0 & 0 & 1 & 0 \
0 & 0 & 0 & -1 \
\end{pmatrix}
$$
which is the CPHASE gate or called controlled-Z gate.
reference: https://inst.eecs.berkeley.edu/~cs191/fa14/lectures/lecture5.pdf
CNOT gate can be related to CPHASE by conjugating Hadamard gate $H$ (Phase kickback trick), that is, $$CNOT=(I\otimes H) CPHASE (I\otimes H)$$
Related
#include <stdio.h>
int main(){
printf("%d,%d\n", 2 & (1<<1) , 2 & (1<<1)>0 );
return 0;
}
the output of this program is 2,0.
2 & (1<<1) is equal to 2 which is more than 0.
so why does 2 & (1<<1) > 0 evaluate to zero??
This expression
2 & (1<<1)>0
is equivalent to
2 & ( (1<<1)>0 )
due to the precedence of the operators. That is the relational operator > has a higher precedence than the bitwise AND operator. As 1 << 1 is greater than 0 then the sub-expression ( ( 1 << 1 ) > 0 ) yields the value 1.
So 2 & 1 yields 0 because in binary 1 can be represented (for simplicity) like 01 and 2 - like 10 and
01
&
10
---
00
It seems what you mean is the following expression
( 2 & ( 1 << 1 ) ) > 0
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
getHexDigit - Extract hex digit n from word x
Digits numbered from 0 (least significant) to 7 (most significant)
Examples: getHexDigit(0x12345678,2) = 0x6
Legal ops: ! ~ & ^ | + << >>
I'm confused because I don't understand how to extract and write only using those ops. Please help!!
int getHexDigit(int x, int n) {
return (x >> (n >> 4)) & 0xff; // How do I fix this
}
A single digit corresponds to 4 bits, such that you have to shift n*4 bits right; So you have to multiply n by 4, and since you must not use n * 4, you can simply write n << 2; shifting two bits left means 2*2:
return (x >> (n << 2)) & 0x0F;
Then you have to "unmask" all the digits except the one you want to have; Therefore the & 0x0F.
This should do it:
int getHexDigit(int x, int n) {
return (x >> (n << 2)) & 0xf;
}
First, multiply n by 4 (by shifting left by 2-bits) because each hex digit is 4 bits, and then just take that group out by shifting right and masking with 0x0f.
For example, see how it works for getHexDigit(0x1234, 2):
bit pos 1 1 1 1 1 1
5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
(val) 1 2 3 4
x = 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0
n = 2
n << 2 = 4
(val) 0 1 2 3
x >> 4 = 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1
(val) 0 0 0 3
(x >> 4) & 0x0f = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
I'm working on a homework problem and I already got the answer correct, but it was the result of adding operators out of frustration so I'm hoping someone can clarify this for me.
I'm testing to see if a number is positive or negative, return 1 if x > 0, return 0 otherwise. Only using the bit operations ! ~ & ^ | + << >>
Here's my answer: !(x >> 31 | !x)
When I work this out on paper my understanding of it falls apart.
move the sign bit all the way to the right
OR that bit with !x
positive would be 0 | 1
negative would be 1 | 0
! the result, which always, not matter what, ends up as 0
!(0 | 1) = 0
!(1 | 0) = 0
What am I understanding wrong?
Where you're off is in #2:
if x is positive, x >> 31 == 0 and !x == 0 so !(0 | 0) == 1
if x is negative, x >> 31 == 1 and !x == 0 so !(1 | 0) == 0
if x is zero, x >> 31 == 0 and !x == 1 so !(0 | 1) == 0
I think you're looking for :
size_t shift = sizeof(x) * 8 - 1;
bool ans = x | ~(1 << shift);
hi I'm programming a microcontroller using MikroC, and I have this variable which is less than 1024 (2^10bit) and I needed to convert that int value; to unsigned char value8bits; and put the least significant bits in the unsigned char value2bits;
I was actually thinking of using >> bit shifting don't know how yet? so what do you think ?
10bitvar = 956;
8bitvar = (10bitvar >> 2) & 0xff;
2bitvar = (10bitvar & 0x03);
10bitvar = 1 1 1 0 1 1 1 1 1 0
(10bitvar >> 2) = ? ? 1 1 1 0 1 1 1 1
& & & & & & & & &
0xff = 1 1 1 1 1 1 1 1
----------------
8bitvar 1 1 1 0 1 1 1 1
10bitvar = 1 1 1 0 1 1 1 1 1 0
& & & & & & & & &
0x03 = 0 0 0 0 0 0 1 1
----------------
2bitvar 0 0 0 0 0 0 1 0