{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercise 8\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Delayed measurement with Clifford only circuits\n",
    "\n",
    "In general, we can consider quantum circuits with classically-controlled operations: this is when measurements are made throught the circuit, with the outcomes being used to determine what gates are subsequently applied.\n",
    "\n",
    "Nevertheless, when reasoning about what kind of computations we can do with quantum circuits, it is simplest to consider only circuits of the form represented below.\n",
    "\n",
    "![](circuit_model.png)\n",
    "\n",
    "Here all measurements are deferred to the end, and so there are no classically-controlled operations.\n",
    "\n",
    "Remarkably, this comes with no loss of generality. This is because all classically-controlled operations (with measurement) can be replaced by fully quantum controlled gates (unitary and without measurement). For example\n",
    "\n",
    "<div>\n",
    "<img src=\"delayed.png\" width=\"500\"/>\n",
    "</div>\n",
    "\n",
    "Any circuit with classically-controlled gates can therefore be replaced by an equivalent one with only fully quantum gates and with all measurements deferred to the end. However, the gate set required for the latter will typically need to be more powerful that the set of unitary gates used in the former."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To show this, consider circuits for which classically-control is allowed, but for which the unitary part of all gates must be Clifford. Show that, in general, the equivalent circuit without classically-controlled gates requires non-Clifford gates."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Unitarity of the order-finding operator\n",
    "\n",
    "For integers $x$, $N$ and $L$ with $x < N \\leq 2^L-1$ and $\\rm { gcd} (x,N) = 1$, consider the following operation,\n",
    "\n",
    "$$\n",
    "U = \\sum_{y=0}^{2^L-1} \\left| \\, f(y) \\, \\right\\rangle \\left\\langle \\,y \\, \\right|,\n",
    "$$\n",
    "\n",
    "Where $f(y) = x \\times y \\,\\,\\, {\\rm mod}\\, N$ for $0 \\leq y <N$ and $f(y)=y$ otherwise. Show that $U$ is unitary."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.  Eigenstates of the order-finding operator\n",
    "\n",
    "* (a) Show that the following states are eigenstates of $U$,\n",
    "\n",
    "$$\n",
    "\\left| u_s \\right\\rangle = \\frac{1}{\\sqrt{r}} \\sum_{k=0}^{r-1} \\exp \\left[ \\frac{-2 \\pi i s k}{r} \\right] \\left| x^k \\,\\,\\, {\\rm mod}\\, N \\right\\rangle.\n",
    "$$\n",
    "\n",
    "Here $0 \\leq s \\leq r-1$, where $r$ is the smallest integer such that $x^r = 1 \\,\\,\\, {\\rm mod}\\, N$. Show also that the corresponding eigenvalues are $u_s = \\exp ( {2 \\pi i s}/{r} )$.\n",
    "\n",
    "* (b) There are also many states with eigenvalue $1$. What are these?\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
