# Task One : Fundamentals of Quantum Computation

## Basic Arithmetic Operations & Complex Numbers


```python
#Adding Two Numbers
x=2+5
print(x)
```

    7



```python
#Subtracting Two Numbers
y=8-5
print(y)
```

    3



```python
#Multiplying Two Numbers
a=3*5
print(a)
```

    15



```python
#Dividing Two Numbers
b=8/4
print(b)
```

    2.0



```python
#Calculate the Remainder
r=4%3
print(r)
```

    1



```python
#Exponent of a Number
e=5**3
print(e)
```

    125


Complex numbers are always of the form

\begin{align}
\alpha = a + bi
\end{align}


```python
c1=1j*1j
print(c1)
```

    (-1+0j)



```python
#Initialize two complex numbers
z=4+8j
w=5-5j
```


```python
import numpy as np
```


```python
print("Real part of z is:", np.real(z))
```

    Real part of z is: 4.0



```python
print("Imaginary part of w is:", np.imag(w))
```

    Imaginary part of w is: -5.0



```python
#Add two complex numbers
add=z+w
print(add)
```

    (9+3j)



```python
#Subtract two complex numbers
sub=z-w
print(sub)
```

    (-1+13j)


## Complex conjugate


```python
#complex conjugate of w
print(w)
print("Complex conjugate of w is:", np.conj(w))
```

    (5-5j)
    Complex conjugate of w is: (5+5j)


## Norms/Absolute Values



\begin{align} ||z|| &= \sqrt{zz^*} = \sqrt{|z|^2},\\ ||w|| &= \sqrt{ww^*} = \sqrt{|w|^2}, \end{align} 


```python
#Calculating absolute values for z and w
print(z)
print("Norm/Absolute value of z is:", np.abs(z))
print(w)
print("Norm/Absolute value of w is:", np.abs(w))
```

    (4+8j)
    Norm/Absolute value of z is: 8.94427190999916
    (5-5j)
    Norm/Absolute value of w is: 7.0710678118654755


## Row Vectors, Column Vectors, and Bra-Ket Notation

\begin{align} \text{Column Vector:} \ \begin{pmatrix}
a_1 \\ a_2 \\ \vdots \\ a_n
\end{pmatrix} 
\quad \quad \text{Row Vector:} \ \begin{pmatrix}
a_1, & a_2, & \cdots, & a_n
\end{pmatrix} \end{align}


```python
#Initialize a row vector
row_vector=np.array([1, 2+2j, 3])
print(row_vector)
```

    [1.+0.j 2.+2.j 3.+0.j]



```python
#Initialize a column vector
column_vector=np.array([[1],[2+2j],[3j]])
print(column_vector)
```

    [[1.+0.j]
     [2.+2.j]
     [0.+3.j]]


Row vectors in quantum mechanics are also called **bra-vectors**, and are denoted as follows:

\begin{align} \langle A| = \begin{pmatrix}
a_1, & a_2, \cdots, & a_n
\end{pmatrix} \end{align}

Column vectors are also called **ket-vectors** in quantum mechanics denoted as follows:

\begin{align} |B\rangle = \begin{pmatrix}
b_1 \\ b_2 \\ \vdots \\ b_n
\end{pmatrix} \end{align}

In general, if we have a column vector, i.e. a ket-vector:

\begin{align} |A\rangle = \begin{pmatrix}
a_1 \\ a_2 \\ \vdots \\ a_n
\end{pmatrix} \end{align}

the corresponding bra-vector:

\begin{align} \langle A| = \begin{pmatrix}
a_1^*, & a_2^*, & \cdots, & a_n^*
\end{pmatrix} \end{align}


## Inner Product

\begin{align} \langle A| = \begin{pmatrix}
a_1, & a_2, & \cdots, & a_n
\end{pmatrix}, \quad \quad
|B\rangle = \begin{pmatrix}
b_1 \\ b_2 \\ \vdots \\ b_n
\end{pmatrix} \end{align}

Taking the inner product of $\langle A|$ and $|B\rangle$ gives the following:

\begin{align} \langle A| B \rangle &= \begin{pmatrix} 
a_1, & a_2, & \cdots, & a_n
\end{pmatrix}
\begin{pmatrix}
b_1 \\ b_2 \\ \vdots \\ b_n
\end{pmatrix}\\
&= 
a_1b_1 + a_2b_2 + \cdots + a_nb_n\\
&= \sum_{i=1}^n a_ib_i
\end{align}


```python
# Define the 4x1 matrix version of a column vector 
A=np.array([[1],[4-5j],[5],[-3]])
```


```python
# Define B as a 1x4 matrix
B=np.array([1, 5, -4j, -1j])
```


```python
# Compute <B|A>
np.dot(B,A)
```




    array([21.-42.j])



## Matrices

\begin{align}
M = \begin{pmatrix}
2-i & -3 \\
-5i & 2
\end{pmatrix}
\end{align}


```python
M=np.array([[2-1j, -3], [-5j, 2]])
#Note how the brackets are placed!
print(M)
```

    [[ 2.-1.j -3.+0.j]
     [-0.-5.j  2.+0.j]]



```python
M=np.matrix([[2-1j, 3],[-5j, 2]])
print(M)
```

    [[ 2.-1.j  3.+0.j]
     [-0.-5.j  2.+0.j]]


Hermitian conjugates are given by taking the conjugate transpose of the matrix


```python
#To calculate hermitian matrix simple follow: <your matrix>.H 
hermitian = M.H
print(hermitian)
```

    [[ 2.+1.j -0.+5.j]
     [ 3.-0.j  2.-0.j]]


## Tensor Products of Matrices

\begin{align}
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix} \otimes 
\begin{pmatrix}
x & y \\
z & w
\end{pmatrix} = 
\begin{pmatrix}
a \begin{pmatrix}
x & y \\
z & w
\end{pmatrix} & b \begin{pmatrix}
x & y \\
z & w
\end{pmatrix} \\
c \begin{pmatrix}
x & y \\
z & w
\end{pmatrix} & d \begin{pmatrix}
x & y \\
z & w
\end{pmatrix}
\end{pmatrix} = 
\begin{pmatrix}
ax & ay & bx & by \\
az & aw & bz & bw \\
cx & cy & dx & dy \\
cz & cw & dz & dw
\end{pmatrix}
\end{align}


```python
#Use the np.kron method 
np.kron(M,M)
```




    matrix([[  3. -4.j,   6. -3.j,   6. -3.j,   9. +0.j],
            [ -5.-10.j,   4. -2.j,   0.-15.j,   6. +0.j],
            [ -5.-10.j,   0.-15.j,   4. -2.j,   6. +0.j],
            [-25. +0.j,   0.-10.j,   0.-10.j,   4. +0.j]])



# That's all for Task 1
## Thank You!

Where can you find me?

LinkedIn : https://www.linkedin.com/in/arya--shah/

Twitter : https://twitter.com/aryashah2k

Github : https://github.com/aryashah2k

If you Like My Work, Follow me/ Connect with me on these platforms.
Show some Love ❤️ Sponsor me on Github!


```python

```

7411d2e951f8375006480ae7ef7e2f41be40eafc
ipynb
Jupyter Notebook
Guided Project - Programming a Quantum Computer with Qiskit - IBM SDK/Task 1/Task 1 - Fundamentals of Quantum Computation.ipynb
bobsub218/exercise-qubit
32e1b851f65b98dcdf90ceaca1bd52ac6553e63a
MIT
2020-11-13T07:11:20.000Z
2022-03-06T02:27:45.000Z
Guided Project - Programming a Quantum Computer with Qiskit - IBM SDK/Task 1/Task 1 - Fundamentals of Quantum Computation.ipynb
bobsub218/Exercise-qubit
32e1b851f65b98dcdf90ceaca1bd52ac6553e63a
MIT
2020-12-25T17:25:14.000Z
2021-04-26T07:56:06.000Z
Guided Project - Programming a Quantum Computer with Qiskit - IBM SDK/Task 1/Task 1 - Fundamentals of Quantum Computation.ipynb
trial1user/Quantum-Computing-Collection-Of-Resources
6953854769adef05e705fa315017c459e5e581ce
MIT
2020-11-13T08:55:28.000Z
2022-03-14T21:16:07.000Z
Qwen/Qwen-72B
1. YES
2. YES