*I was having a conversation with a friend who is studying Quantum Programming as a part of his Masters degree. As he described the concept of state entanglement to me, I started to feel like the concept is very close to Redux and state management on the web. So, I wrote this post to elaborate some of my thoughts.*

## What is a quantum programming language?

A quantum programming language is really a specific type of machine code targeting a quantum computer, which is based on quantum mechanics compared to classical mechanics.

A classical computer has a memory made up of bits, where each bit is represented by either a 0 or a 1.

A quantum computer, on the other hand, maintains a sequence of qubits, which can represent a 0, a 1, or any quantum superposition of those two qubit states.

Quantum computers may be able to efficiently solve problems which are not practically feasible on classical computers, and thanks to the Church–Turing thesis, we know that a classical computer can technically simulate a quantum algorithm.

## Why Quantum Programming?

IBM has unveiled it's cloud quantum computer for public use, Microsoft has revealed the Q# quantum programming language, and D-Wave Systems partnered with NASA to release the D-Wave-2. It looks like Quantum Computing is becoming a reality!

Since quantum programming is based on quantum mechanics, it benefits from some of the cool phenomena associated with it.

**Quantum entanglement** is a physical phenomenon which occurs when a group of particles interacts in ways such that the quantum state of each particle cannot be described independently of the state of the others, even when the particles are separated by a large distance.

Let’s say we have two particles A and B. Both particles are in superposition of possible states — in this case they both turn red and blue at the same time. If we measure the colour of A, and it picks red, and someone else an instant later measures B — B will always be blue.

Entanglement means that somehow B knew, instantaneously, what A picked, regardless of the distance between A and B.

## States in Web Applications

In web applications today, we face a similar challenge in maintaining the same state on the front end and the back end. With growing use of various modern hacks such as Redux/Flux, it is clear that we need a more elegant solution to state management across physical distance.

## Quantum State Entanglement

How is the actual data represented? This is done based on a process called superdense coding. Superdense coding is a method of sending two traditional bits of information (00, 01, 10, or 11) using a single qubit.

Lets assume the state of our web app is encoded into an array of such qubits. Our goal would be to entangle the state from the server side with the state on the client side.

- We add the Hadamard gate (H) with 1 qubit for adding superposition property.
- We add Controlled-NOT gate (CX) , a two-qubit gate that flips the target qubit if the control is in state 1. This gate generates entanglement.

The combination of these two quantum logic operations brings our pair of qubits to a Bell state.

### Bell State

The Bell states are specific quantum states of two qubits that represent the simplest examples of quantum entanglement.

## Code

The following code can really only run on a quantum computer :P

```
# Assuming we have two qubits, qr[0] and qr[1]
# Add the H gate in the Qubit 1, putting this qubit in superposition.
qc.h(qr[1])
# Add the CX gate on control qubit 1 and target qubit 0, putting the qubits in a Bell state i.e entanglement
qc.cx(qr[1], qr[0])
# Add a Measure gate to see the state.
qc.measure(qr[0],cr[0])
qc.measure(qr[1],cr[1])
# Compile and execute the Quantum Program, since it needs to be simulated
results = qp.execute(['HelloWorldCircuit'], backend,timeout=2400)
```

Quantum programming is still a highly theoretical field, and we won't really see the performance improvements from it until we build a much more practical quantum processor. However, I hope that being more aware of the paradigms makes you have more to worry about in your future work and projects. :D

## Top comments (0)