---
title: "Path Integral Formalism"
format:
  html:
    toc: true
    number-sections: true
execute:
  echo: false
---

::: {.hidden}
$$
\newcommand{\braket}[2]{\langle{#1}|{#2}\rangle}
$$
:::

[Pre-class notes](HandWrittenNotes/PathIntegralFormalismF25Class.pdf)

[In-class notes](HandWrittenNotes/PathIntegralFormalismF25ClassPost1.pdf)

## Learning Goals

- Describe how quantum algorithms gain an advantage over probabilistic algorithms
- Analyze circuits using the path integral formalism

## Superposition

Is superposition the quantum secret sauce??

Superposition does seem pretty awesome. For example, suppose you have $3$ qubits in the $\ket{0}$ state, and you apply $H$ to each. You will end up with the state
$$
(H\otimes H\otimes H)\ket{000}=\ket{+}\ket{+}\ket{+}=\frac{1}{2\sqrt{2}}\left(\ket{000}+\ket{001}+\ket{010}+\ket{011}+\ket{100}+\ket{101}+\ket{110}+\ket{111}\right)
$$
So with three qubits, we can access 8 standard basis states - it seems like we have exponential scaling!
For example, if we then apply a 3-bit function $U_f$ to the state $\ket{+}\ket{+}\ket{+}\ket{0}$, in one query, we can get information about all 8 function values.

But actually, this exponential scaling is not that special. Consider flipping a coin 3 times: there are 8 possible sequences of outcomes. Seems like we have exponential scaling!

Since both quantum and probabilistic systems seem to have this same ability to quickly access an exponentially large space, by comparing quantum and probabilistic systems, we can learn what it is about quantum systems that really gives them their speed up

|     |Quantum computing | Probabilistic Computing|
|-----|------------------|------------------------|
| state:| $\sum_{i\in\{0,1\}^n}a_i\ket{i}$ such that $\sum_{i\in\{0,1\}^n}|a_i|^2=1$, $a_i\in\mathbb{C}$| $\sum_{i\in\{0,1\}^n}a_i\ket{i}$ such that $\sum_{i\in\{0,1\}^n}a_i=1$, $\quad a_i\geq 1$ ($a_i$'s are probabilities)|
|measurement: | Probability of outcome $i$ is $|a_i|^2$|Probability of outcome $i$ is $a_i$|
|gate: | unitary (preserves normalization, reversibility) | left stochastic (preserves normalization, positivity)|

We will look at what happens if we try to do Deutsch's algorithm with probabilistic gates instead of quantum gates.

## Probabilistic Vs Quantum Computing

Recall Deutsch's Algorithm:

![Circuit diagram of Detusch's Algorithm](QuartoImages/Deutsch_Path1.png){#fig-Deutsch1 width=70%}

There are only 3 gates in @fig-Deutsch1, 

- $X$,
\begin{align}
\ket{0}&\rightarrow \ket{1}\\
\ket{1}&\rightarrow \ket{0}
\end{align} 
- $H$
\begin{align}
\ket{0}&\rightarrow \frac{1}{\sqrt{2}}\ket{0}+\frac{1}{\sqrt{2}}\ket{1}\\
\ket{1}&\rightarrow \frac{1}{\sqrt{2}}\ket{0}-\frac{1}{\sqrt{2}}\ket{1}
\end{align}
- $U_f$
\begin{align}
\ket{0}\ket{0}&\rightarrow \ket{0}\ket{f(0)}\\
\ket{0}\ket{1}&\rightarrow \ket{0}\ket{\bar{f(0)}}\\
\ket{1}\ket{0}&\rightarrow \ket{1}\ket{f(1)}\\
\ket{1}\ket{1}&\rightarrow \ket{1}\ket{\bar{f(1)}}.
\end{align}

Two of these gates, $X$ and $U_f$, are unitary and left stochastic, so are valid quantum or probabilistic gates. The only gate that is not probabilistic is $H:$

If we want to try to run Deutsch's algorithm with a probabilistic computer, we will need to replace $H$. We will replace it with the gate $F$ (which takes any input and replaces it with an equal mixture of both $\ket{0}$ and $\ket{1}$):
$$
\begin{align}
\ket{0}&\rightarrow \frac{1}{2}\ket{0}+\frac{1}{2}\ket{1}\\
\ket{1}&\rightarrow \frac{1}{2}\ket{0}+\frac{1}{2}\ket{1}.
\end{align}
$$

Now we have a circuit that we can run on a probabilistic computer:

![](QuartoImages/Prob_Deutsch.png){#fig-Deutsch-prob width=70%}

### Path integral analysis of probabilistic computation

To analyze this circuit, we will use a path integral approach. To do this we create a diagram of the
four possible standard basis states:

After each gate, we use paths (lines) to show which other standard basis states the initial state is transformed into, and we put the the probabilities of each outcome state on the lines. @fig-path-prob shows how the diagram should look after applying the first three gates:

![Path integral picture of the probabilistic circuit](QuartoImages/Path_Prob.png){#fig-path-prob width=100%}

To analyze the output of this probabilistic circuit:

- Multiply probabilities on a path to get the probability of that path
- Add probabilities of all paths terminating at a state to get the probability of that outcome

### Path integral analysis of quantum computation

We can do the a similar path integral analysis of the quantum version of Deutsch's algorithm. @fig-path-quant shows how the diagram looks after the first three gates

![Path integral picture of the probabilistic circuit](QuartoImages/Path_Quant.png){#fig-path-quant width=100%}

To analyze the output of this quantum circuit:

- Multiply ~~probabilities~~ *amplitudes* on a path to get the ~~probabilities~~ *amplitude* of that path
- Add ~~probabilities~~ *amplitudes* of all paths terminating at a state, *then take the absolute value squared*, to get the probability of that outcome

It turns out that each of the 4 outcomes has probability $1/4$. This circuit is equivalent to flipping 2 coins. This means the circuit is *not* successfully solving Deutsch's problm. This makes sense because we previously discussed how any classical algorithm will require 2 queries to solve Deutsch's problem, and this algorithm only makes $1$ query.

The point of analyzing this circuit is not to create a good algorithm, but rather to compare to the quantum circuit, which does successfully solve Deutsch's problem. 

::: {.callout-tip appearance="simple"}
### Group Exercises

Finish filling out the two path diagrams (@fig-path-prob and @fig-path-quant) in the case that $f(0)=f(1)=1$, and in each case, calculate the probability of the 1st qubit being $1$ at the end of the circuit.

Comparing these two diagrams, how would you describe the power of quantum computing versus probabilistic computing?
:::