{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "b4570c73",
      "metadata": {},
      "source": [
        "---\n",
        "title: Fidelity\n",
        "description: A free IBM course on quantum information and computation\n",
        "---\n",
        "\n",
        "{/* cspell:ignore operatorname */}\n",
        "\n",
        "{/* cspell:ignore biggr */}\n",
        "\n",
        "# Fidelity\n",
        "\n",
        "In this part of the lesson, we'll discuss the *fidelity* between quantum states, which is a measure of their similarity — or how much they \"overlap.\"\n",
        "\n",
        "Given two quantum state vectors, the fidelity between the pure states associated with these quantum state vectors equals the absolute value of the inner product between the quantum state vectors.\n",
        "This provides a basic way to measure their similarity: the result is a value between $0$ and $1,$ with larger values indicating greater similarity.\n",
        "In particular, the value is zero for orthogonal states (by definition), while the value is $1$ for states equivalent up to a global phase.\n",
        "\n",
        "Intuitively speaking, the fidelity can be seen as an extension of this basic measure of similarity, from quantum state vectors to density matrices.\n",
        "\n",
        "## Definition of fidelity\n",
        "\n",
        "It's fitting to begin with a definition of fidelity.\n",
        "At first glance, the definition that follows might look unusual or mysterious, and perhaps not easy to work with.\n",
        "The function it defines, however, turns out to have many interesting properties and multiple alternative formulations, making it much nicer to work with than it may initially appear.\n",
        "\n",
        "<Figure title=\"Definition\">\n",
        "  Let $\\rho$ and $\\sigma$ be density matrices representing quantum states of the same system.\n",
        "  The *fidelity* between $\\rho$ and $\\sigma$ is defined as\n",
        "\n",
        "  $$\n",
        "  \\operatorname{F}(\\rho,\\sigma) = \\operatorname{Tr}\\sqrt{\\sqrt{\\rho} \\sigma \\sqrt{\\rho}}.\n",
        "  $$\n",
        "</Figure>\n",
        "\n",
        "<Figure title=\"Remark\">\n",
        "  Although this is a common definition, it is also common that the fidelity is defined as the *square* of the quantity defined here, which is then referred to as the *root-fidelity*.\n",
        "  Neither definition is right or wrong — it's essentially a matter of preference.\n",
        "  Nevertheless, one must always be careful to understand or clarify which definition is being used.\n",
        "</Figure>\n",
        "\n",
        "To make sense of the formula in the definition, notice first that $\\sqrt{\\rho} \\sigma \\sqrt{\\rho}$ is a positive semidefinite matrix:\n",
        "\n",
        "$$\n",
        "\\sqrt{\\rho} \\sigma \\sqrt{\\rho} = M^{\\dagger} M\n",
        "$$\n",
        "\n",
        "for $M = \\sqrt{\\sigma}\\sqrt{\\rho}.$\n",
        "Like all positive semidefinite matrices, this positive semidefinite matrix has a unique positive semidefinite square root, the trace of which is the fidelity.\n",
        "\n",
        "For every square matrix $M,$ the eigenvalues of the two positive semidefinite matrices $M^{\\dagger} M$ and $M M^{\\dagger}$ are always the same, and hence the same is true for the square roots of these matrices.\n",
        "Choosing $M = \\sqrt{\\sigma}\\sqrt{\\rho}$ and using the fact that the trace of a square matrix is the sum of its eigenvalues, we find that\n",
        "\n",
        "$$\n",
        "\\begin{aligned}\n",
        "\\operatorname{F}(\\rho,\\sigma)\n",
        "& = \\operatorname{Tr}\\sqrt{\\sqrt{\\rho} \\sigma \\sqrt{\\rho}}\\\\\n",
        "& = \\operatorname{Tr}\\sqrt{M^{\\dagger} M} = \\operatorname{Tr}\\sqrt{M M^{\\dagger}}\\\\\n",
        "& = \\operatorname{Tr}\\sqrt{\\sqrt{\\sigma} \\rho \\sqrt{\\sigma}}\\\\\n",
        "& = \\operatorname{F}(\\sigma,\\rho).\n",
        "\\end{aligned}\n",
        "$$\n",
        "\n",
        "So, although it is not immediate from the definition, the fidelity is symmetric in its two arguments.\n",
        "\n",
        "### Fidelity in terms of the trace norm\n",
        "\n",
        "An equivalent way to express the fidelity is by this formula:\n",
        "\n",
        "$$\n",
        "\\operatorname{F}(\\rho,\\sigma) = \\bigl\\|\\sqrt{\\sigma}\\sqrt{\\rho}\\bigr\\|_1.\n",
        "$$\n",
        "\n",
        "Here we see the *trace norm*, which we encountered in the previous lesson in the context of state discrimination.\n",
        "The trace norm of a (not necessarily square) matrix $M$ can be defined as\n",
        "\n",
        "$$\n",
        "\\| M \\|_1 = \\operatorname{Tr}\\sqrt{M^{\\dagger} M},\n",
        "$$\n",
        "\n",
        "and by applying this definition to the matrix $\\sqrt{\\sigma}\\sqrt{\\rho}$ we obtain the formula in the definition.\n",
        "\n",
        "An alternative way to express the trace norm of a (square) matrix $M$ is through this formula.\n",
        "\n",
        "$$\n",
        "\\| M \\|_1 = \\max_{U\\:\\text{unitary}} \\bigl\\vert \\operatorname{Tr}(M U) \\bigr\\vert.\n",
        "$$\n",
        "\n",
        "Here the maximum is over all *unitary* matrices $U$ having the same number of rows and columns as $M.$\n",
        "Applying this formula in the situation at hand reveals another expression of the fidelity.\n",
        "\n",
        "$$\n",
        "\\operatorname{F}(\\rho,\\sigma)\n",
        "= \\max_{U\\:\\text{unitary}} \\bigl\\vert\\operatorname{Tr}\\bigl( \\sqrt{\\sigma}\\sqrt{\\rho}\\, U\\bigr) \\bigr\\vert\n",
        "$$\n",
        "\n",
        "### Fidelity for pure states\n",
        "\n",
        "One last point on the definition of fidelity is that every pure state is (as a density matrix) equal to its own square root, which allows the formula for the fidelity to be simplified considerably when one or both of the states is pure.\n",
        "In particular, if one of the two states is pure we have the following formula.\n",
        "\n",
        "$$\n",
        "\\operatorname{F}\\bigl( \\vert\\phi\\rangle\\langle\\phi\\vert, \\sigma \\bigr)\n",
        "= \\sqrt{\\langle \\phi\\vert \\sigma \\vert \\phi \\rangle}\n",
        "$$\n",
        "\n",
        "If both states are pure, the formula simplifies to the absolute value of the inner product of the corresponding quantum state vectors, as was mentioned at the start of the section.\n",
        "\n",
        "$$\n",
        "\\operatorname{F}\\bigl( \\vert\\phi\\rangle\\langle\\phi\\vert, \\vert\\psi\\rangle\\langle\\psi\\vert \\bigr)\n",
        "= \\bigl\\vert \\langle \\phi\\vert \\psi \\rangle \\bigr\\vert\n",
        "$$\n",
        "\n",
        "## Basic properties of fidelity\n",
        "\n",
        "The fidelity has many remarkable properties and several alternative formulations.\n",
        "Here are just a few basic properties listed without proofs.\n",
        "\n",
        "1. For any two density matrices $\\rho$ and $\\sigma$ having the same size, the fidelity $\\operatorname{F}(\\rho,\\sigma)$ lies between zero and one: $0\\leq \\operatorname{F}(\\rho,\\sigma) \\leq 1.$ It is the case that $\\operatorname{F}(\\rho,\\sigma)=0$ if and only if $\\rho$ and $\\sigma$ have orthogonal images (so they can be discriminated without error), and $\\operatorname{F}(\\rho,\\sigma)=1$ if and only if $\\rho = \\sigma.$\n",
        "2. The fidelity is *multiplicative,* meaning that the fidelity between two product states is equal to the product of the individual fidelities:\n",
        "   $$\n",
        "   \\operatorname{F}(\\rho_1\\otimes\\cdots\\otimes\\rho_m,\\sigma_1\\otimes\\cdots\\otimes\\sigma_m)\n",
        "   = \\operatorname{F}(\\rho_1,\\sigma_1)\\cdots \\operatorname{F}(\\rho_m,\\sigma_m).\n",
        "   $$\n",
        "3. The fidelity between states is nondecreasing under the action of any channel. That is, if $\\rho$ and $\\sigma$ are density matrices and $\\Phi$ is a channel that can take these two states as input, then it is necessarily the case\n",
        "   that\n",
        "   $$\n",
        "   \\operatorname{F}(\\rho,\\sigma) \\leq \\operatorname{F}(\\Phi(\\rho),\\Phi(\\sigma)).\n",
        "   $$\n",
        "4. The *Fuchs-van de Graaf inequalities* establish a close (though not exact) relationship between fidelity and trace distance: for any two states $\\rho$ and $\\sigma$ we have\n",
        "   $$\n",
        "   1 - \\frac{1}{2}\\|\\rho - \\sigma\\|_1 \\leq \\operatorname{F}(\\rho,\\sigma)\n",
        "   \\leq \\sqrt{1 - \\frac{1}{4}\\|\\rho - \\sigma\\|_1^2}.\n",
        "   $$\n",
        "\n",
        "The final property can be expressed in the form of a figure:\n",
        "\n",
        "![A plot relating trace distance and fidelity](https://quantum.cloud.ibm.com/learning/images/courses/general-formulation-of-quantum-information/purifications-and-fidelity/FvdG-plot.svg)\n",
        "\n",
        "Specifically, for any choice of states $\\rho$ and $\\sigma$ of the same system, the horizontal line that crosses the $y$-axis at $\\operatorname{F}(\\rho,\\sigma)$ and the vertical line that crosses the $x$-axis at $\\frac{1}{2}\\|\\rho-\\sigma\\|_1$ must intersect within the gray region bordered below by the line $y = 1-x$ and above by the unit circle.\n",
        "The most interesting region of this figure from a practical viewpoint is the upper left-hand corner of the gray region:\n",
        "if the fidelity between two states is close to one, then their trace distance is close to zero, and *vice versa*.\n",
        "\n",
        "## Gentle measurement lemma\n",
        "\n",
        "Next we'll take a look at a simple but important fact, known as the *gentle measurement lemma*, which connects fidelity to non-destructive measurements.\n",
        "It's a very useful lemma that comes up from time to time, and it's also noteworthy because the seemingly clunky definition for the fidelity actually makes the lemma very easy to prove.\n",
        "\n",
        "The set-up is as follows.\n",
        "Let $\\mathsf{X}$ be a system in a state $\\rho$ and let $\\{P_0,\\ldots,P_{m-1}\\}$ be a collection of positive semidefinite matrices representing a general measurement of $\\mathsf{X}.$\n",
        "Suppose further that if this measurement is performed on the system $\\mathsf{X}$ while it's in the state $\\rho,$ one of the outcomes is highly likely.\n",
        "To be concrete, let's assume that the likely measurement outcome is $0,$ and specifically let's assume that\n",
        "\n",
        "$$\n",
        "\\operatorname{Tr}(P_0 \\rho) > 1 - \\varepsilon\n",
        "$$\n",
        "\n",
        "for a small positive real number $\\varepsilon > 0.$\n",
        "\n",
        "What the gentle measurement lemma states is that, under these assumptions, the non-destructive measurement obtained from $\\{P_0,\\ldots,P_{m-1}\\}$ through Naimark's theorem causes only a small disturbance to $\\rho$ in case the likely measurement outcome $0$ is observed.\n",
        "\n",
        "More specifically, the lemma states that the fidelity-squared between $\\rho$ and the state we obtain from the non-destructive measurement, conditioned on the outcome being $0,$ is greater than $1-\\varepsilon.$\n",
        "\n",
        "$$\n",
        "\\operatorname{F}\\Biggl(\\rho,\\frac{\\sqrt{P_0}\\rho\\sqrt{P_0}}{\\operatorname{Tr}(P_0\\rho)}\\Biggr)^2 > 1-\\varepsilon.\n",
        "$$\n",
        "\n",
        "We'll need a basic fact about measurements to prove this.\n",
        "The measurement matrices $P_0, \\ldots, P_{m-1}$ are positive semidefinite and sum to the identity, which allows us to conclude that all of the eigenvalues of $P_0$ are real numbers between $0$ and $1.$\n",
        "This follows from the fact that, for any unit vector $\\vert\\psi\\rangle,$ the value\n",
        "$\\langle \\psi \\vert P_a \\vert \\psi \\rangle$ is a nonnegative real number for each $a\\in\\{0,\\ldots,m-1\\}$ (because each $P_a$ is positive semidefinite), together with these numbers summing to one.\n",
        "\n",
        "$$\n",
        "\\sum_{a = 0}^{m-1} \\langle \\psi \\vert P_a \\vert \\psi \\rangle\n",
        "= \\langle \\psi \\vert \\Biggl(\\sum_{a = 0}^{m-1}  P_a \\Biggr) \\vert \\psi \\rangle\n",
        "= \\langle \\psi \\vert \\mathbb{I} \\vert \\psi \\rangle = 1.\n",
        "$$\n",
        "\n",
        "Hence $\\langle \\psi \\vert P_0 \\vert \\psi \\rangle$ is always a real number between $0$ and $1,$ and this implies that every eigenvalue of $P_0$ is a real number between $0$ and $1$ because we can choose $\\vert\\psi\\rangle$ specifically to be a unit eigenvector corresponding to whichever eigenvalue is of interest.\n",
        "\n",
        "From this observation we can conclude the following inequality for every density matrix $\\rho.$\n",
        "\n",
        "$$\n",
        "\\operatorname{Tr}\\bigl( \\sqrt{P_0} \\rho\\bigr) \\geq \\operatorname{Tr}\\bigl( P_0 \\rho\\bigr)\n",
        "$$\n",
        "\n",
        "In greater detail, starting from a spectral decomposition\n",
        "\n",
        "$$\n",
        "P_0 = \\sum_{k=0}^{n-1} \\lambda_k \\vert\\psi_k\\rangle\\langle\\psi_k\\vert\n",
        "$$\n",
        "\n",
        "we conclude that\n",
        "\n",
        "$$\n",
        "\\operatorname{Tr}\\bigl( \\sqrt{P_0} \\rho\\bigr)\n",
        "= \\sum_{k = 0}^{n-1} \\sqrt{\\lambda_k} \\langle \\psi_k \\vert \\rho \\vert \\psi_k \\rangle\n",
        "\\geq \\sum_{k = 0}^{n-1} \\lambda_k \\langle \\psi_k \\vert \\rho \\vert \\psi_k \\rangle\n",
        "= \\operatorname{Tr}\\bigl( P_0 \\rho\\bigr)\n",
        "$$\n",
        "\n",
        "from the fact that $\\langle \\psi_k \\vert \\rho \\vert \\psi_k \\rangle$ is a nonnegative real number and $\\sqrt{\\lambda_k} \\geq \\lambda_k$ for each $k = 0,\\ldots,n-1.$ (Squaring numbers between $0$ and $1$ can never make them larger.)\n",
        "\n",
        "Now we can prove the gentle measurement lemma by evaluating the fidelity and then using our inequality.\n",
        "First, let's simplify the expression we're interested in.\n",
        "\n",
        "$$\n",
        "\\begin{aligned}\n",
        "\\operatorname{F}\\Biggl(\\rho,\\frac{\\sqrt{P_0}\\rho\\sqrt{P_0}}{\\operatorname{Tr}(P_0\\rho)}\\Biggr)\n",
        "& = \\operatorname{Tr}\\sqrt{\\frac{\\sqrt{\\rho}\\sqrt{P_0}\\rho\\sqrt{P_0}\\sqrt{\\rho}}{\n",
        "\\operatorname{Tr}(P_0\\rho)}}\\\\\n",
        "& = \\operatorname{Tr}\\sqrt{\\Biggl(\\frac{\\sqrt{\\rho}\\sqrt{P_0}\\sqrt{\\rho}}{\n",
        "\\sqrt{\\operatorname{Tr}(P_0\\rho)}}\\Biggr)^2}\\\\\n",
        "& = \\operatorname{Tr}\\Biggl(\\frac{\\sqrt{\\rho}\\sqrt{P_0}\\sqrt{\\rho}}{\n",
        "\\sqrt{\\operatorname{Tr}(P_0\\rho)}}\\Biggr)\\\\\n",
        "& = \\frac{\\operatorname{Tr}\\bigl(\\sqrt{P_0}\\rho\\bigr)}{\\sqrt{\\operatorname{Tr}(P_0\\rho)}}\n",
        "\\end{aligned}\n",
        "$$\n",
        "\n",
        "Notice that these are all equalities — we've not used our inequality (or any other inequality) at this point, so we have an exact expression for the fidelity.\n",
        "We can now use our inequality to conclude\n",
        "\n",
        "$$\n",
        "\\operatorname{F}\\Biggl(\\rho,\\frac{\\sqrt{P_0}\\rho\\sqrt{P_0}}{\\operatorname{Tr}(P_0\\rho)}\\Biggr)\n",
        "= \\frac{\\operatorname{Tr}\\bigl(\\sqrt{P_0}\\rho\\bigr)}{\\sqrt{\\operatorname{Tr}(P_0\\rho)}}\n",
        "\\geq \\frac{\\operatorname{Tr}\\bigl(P_0\\rho\\bigr)}{\\sqrt{\\operatorname{Tr}(P_0\\rho)}}\n",
        "= \\sqrt{\\operatorname{Tr}\\bigl(P_0\\rho\\bigr)}\n",
        "$$\n",
        "\n",
        "and therefore, by squaring both sides,\n",
        "\n",
        "$$\n",
        "\\operatorname{F}\\Biggl(\\rho,\\frac{\\sqrt{P_0}\\rho\\sqrt{P_0}}{\\operatorname{Tr}(P_0\\rho)}\\Biggr)^2\n",
        "\\geq \\operatorname{Tr}\\bigl(P_0\\rho\\bigr) > 1-\\varepsilon.\n",
        "$$\n",
        "\n",
        "## Uhlmann's theorem\n",
        "\n",
        "To conclude the lesson, we'll take a look at *Uhlmann's theorem*, which is a fundamental fact about the fidelity that connects it with the notion of a purification.\n",
        "What the theorem says, in simple terms, is that the fidelity between any two quantum states is equal to the *maximum* inner product (in absolute value) between two purifications of those states.\n",
        "\n",
        "<Figure title=\"Theorem\">\n",
        "  Uhlmann's theorem: Let $\\rho$ and $\\sigma$ be density matrices representing states of a system $\\mathsf{X},$ and let $\\mathsf{Y}$ be a system having at least as many classical states as $\\mathsf{X}.$ The fidelity between $\\rho$ and $\\sigma$ is given by\n",
        "\n",
        "  $$\n",
        "   \\operatorname{F}(\\rho,\\sigma) = \\max\\bigl\\{ \\vert \\langle \\phi \\vert \\psi \\rangle \\vert \\,:\\, \\operatorname{Tr}_{\\mathsf{Y}}\\bigl(\\vert\\phi\\rangle\\langle\\phi\\vert\\bigr) = \\rho,\\; \\operatorname{Tr}_{\\mathsf{Y}}\\bigl(\\vert\\psi\\rangle\\langle\\psi\\vert\\bigr) = \\sigma\\bigr\\},\n",
        "  $$\n",
        "\n",
        "  where the maximum is taken over all quantum state vectors $\\vert\\phi\\rangle$ and $\\vert\\psi\\rangle$ of $(\\mathsf{X},\\mathsf{Y}).$\n",
        "</Figure>\n",
        "\n",
        "We can prove this theorem using the unitary equivalence of purifications — but it isn't completely straightforward and we'll make use of a trick along the way.\n",
        "\n",
        "To begin, consider spectral decompositions of the two density matrices $\\rho$ and $\\sigma.$\n",
        "\n",
        "$$\n",
        "\\begin{aligned}\n",
        "\\rho & = \\sum_{a = 0}^{n-1} p_a \\vert u_a\\rangle\\langle u_a\\vert \\\\[2mm]\n",
        "\\sigma & = \\sum_{b = 0}^{n-1} q_b \\vert v_b\\rangle\\langle v_b\\vert\n",
        "\\end{aligned}\n",
        "$$\n",
        "\n",
        "The two collections $\\{\\vert u_0 \\rangle,\\ldots,\\vert u_{n-1}\\rangle\\}$ and $\\{\\vert v_0 \\rangle,\\ldots,\\vert v_{n-1}\\rangle\\}$ are orthonormal bases of eigenvectors of $\\rho$ and $\\sigma,$ respectively, and $p_0,\\ldots,p_{n-1}$ and $q_0,\\ldots,q_{n-1}$ are the corresponding eigenvalues.\n",
        "\n",
        "We'll also define $\\vert \\overline{u_0} \\rangle,\\ldots,\\vert \\overline{u_{n-1}}\\rangle$ and\n",
        "$\\vert \\overline{v_0} \\rangle,\\ldots,\\vert \\overline{v_{n-1}}\\rangle$ to be the vectors obtained by taking the complex conjugate of each entry of $\\vert u_0 \\rangle,\\ldots,\\vert u_{n-1}\\rangle$ and $\\vert v_0 \\rangle,\\ldots,\\vert v_{n-1}\\rangle.$\n",
        "That is, for an arbitrary vector $\\vert w\\rangle$ we can define $\\vert\\overline{w}\\rangle$ according to the following equation for each $c\\in\\{0,\\ldots,n-1\\}.$\n",
        "\n",
        "$$\n",
        "\\langle c \\vert \\overline{w}\\rangle = \\overline{\\langle c \\vert w\\rangle}\n",
        "$$\n",
        "\n",
        "Notice that for any two vectors $\\vert u\\rangle$ and $\\vert v\\rangle$ we have\n",
        "$\\langle \\overline{u} \\vert \\overline{v}\\rangle = \\langle v\\vert u\\rangle.$\n",
        "More generally, for any square matrix $M$ we have the following formula.\n",
        "\n",
        "$$\n",
        "\\langle \\overline{u} \\vert M \\vert \\overline{v}\\rangle = \\langle v\\vert M^T \\vert u\\rangle\n",
        "$$\n",
        "\n",
        "It follows that $\\vert u\\rangle$ and $\\vert v\\rangle$ are orthogonal if and only if $\\vert \\overline{u}\\rangle$ and $\\vert \\overline{v}\\rangle$ are orthogonal, and therefore\n",
        "$\\{\\vert \\overline{u_0} \\rangle,\\ldots,\\vert \\overline{u_{n-1}}\\rangle\\}$ and\n",
        "$\\{\\vert \\overline{v_0} \\rangle,\\ldots,\\vert \\overline{v_{n-1}}\\rangle\\}$ are both orthonormal bases.\n",
        "\n",
        "Now consider the following two vectors $\\vert\\phi\\rangle$ and $\\vert\\psi\\rangle,$ which are purifications of $\\rho$ and $\\sigma,$ respectively.\n",
        "\n",
        "$$\n",
        "\\begin{aligned}\n",
        "\\vert\\phi\\rangle & = \\sum_{a = 0}^{n-1} \\sqrt{p_a}\\, \\vert u_a\\rangle \\otimes \\vert \\overline{u_a}\\rangle \\\\[2mm]\n",
        "\\vert\\psi\\rangle & = \\sum_{b = 0}^{n-1} \\sqrt{q_b}\\, \\vert v_b\\rangle \\otimes \\vert\n",
        "\\overline{v_b}\\rangle\n",
        "\\end{aligned}\n",
        "$$\n",
        "\n",
        "This is the trick referred to previously.\n",
        "Nothing indicates explicitly at this point that it's a good idea to make these particular choices for purifications of $\\rho$ and $\\sigma,$ but they are valid purifications, and the complex conjugations will allow the algebra to work out the way we need.\n",
        "\n",
        "By the unitary equivalence of purifications, we know that every purification of $\\rho$ for the pair of systems $(\\mathsf{X},\\mathsf{Y})$ must take the form\n",
        "$(\\mathbb{I}_{\\mathsf{X}}\\otimes U)\\vert\\phi\\rangle$ for some unitary matrix $U,$ and likewise every purification of $\\sigma$ for the pair $(\\mathsf{X},\\mathsf{Y})$ must take the form\n",
        "$(\\mathbb{I}_{\\mathsf{X}}\\otimes V)\\vert\\psi\\rangle$ for some unitary matrix $V.$\n",
        "The inner product of two such purifications can be simplified as follows.\n",
        "\n",
        "$$\n",
        "\\begin{aligned}\n",
        "\\langle \\phi \\vert (\\mathbb{I}\\otimes U^{\\dagger}) (\\mathbb{I}\\otimes V) \\vert \\psi \\rangle\n",
        "\\hspace{-2.5cm}\\\\\n",
        "& = \\sum_{a,b = 0}^{n-1} \\sqrt{p_a} \\sqrt{q_b}\\, \\langle u_a \\vert v_b \\rangle\n",
        "\\langle \\overline{u_a} \\vert U^{\\dagger} V \\vert \\overline{v_b} \\rangle \\\\\n",
        "& = \\sum_{a,b = 0}^{n-1} \\sqrt{p_a} \\sqrt{q_b}\\, \\langle u_a \\vert v_b \\rangle\n",
        "\\langle v_b \\vert (U^{\\dagger} V)^T \\vert u_a \\rangle \\\\\n",
        "& = \\operatorname{Tr}\\Biggl(\n",
        "\\sum_{a,b = 0}^{n-1} \\sqrt{p_a} \\sqrt{q_b}\\, \\vert u_a \\rangle\\langle u_a \\vert v_b \\rangle\n",
        "\\langle v_b \\vert (U^{\\dagger} V)^T\\Biggr)\\\\\n",
        "& = \\operatorname{Tr}\\Bigl(\n",
        "\\sqrt{\\rho}\\sqrt{\\sigma}\\, (U^{\\dagger} V)^T\\Bigr)\n",
        "\\end{aligned}\n",
        "$$\n",
        "\n",
        "As $U$ and $V$ range over all possible unitary matrices, the matrix $(U^{\\dagger} V)^T$ also ranges over all possible unitary matrices.\n",
        "Thus, maximizing the absolute value of the inner product of two purifications of $\\rho$ and $\\sigma$ yields the following equation.\n",
        "\n",
        "$$\n",
        "\\begin{aligned}\n",
        "\\max_{U,V\\:\\text{unitary}} \\biggl\\vert \\operatorname{Tr}\\Bigl(\n",
        "\\sqrt{\\rho}\\sqrt{\\sigma}\\, (U^{\\dagger} V)^T\\Bigr)\\biggr\\vert\n",
        "& = \\max_{W\\:\\text{unitary}} \\biggl\\vert \\operatorname{Tr}\\Bigl(\n",
        "\\sqrt{\\rho}\\sqrt{\\sigma}\\, W\\Bigr)\\biggr\\vert\\\\[2mm]\n",
        "& = \\bigl\\| \\sqrt{\\rho}\\sqrt{\\sigma} \\bigr\\|_1\\\\[2mm]\n",
        "& = \\operatorname{F}(\\rho,\\sigma)\n",
        "\\end{aligned}\n",
        "$$\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "786e016d",
      "metadata": {},
      "source": [
        "## Post-course survey\n",
        "\n",
        "Congratulations on completing this course! Please take a moment to help us improve our course by filling out the following [quick survey](https://your.feedback.ibm.com/jfe/form/SV_bNoS9Adav7L8z9s). Your feedback will be used to enhance our content offering and user experience. Thank you!\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "id": "a1b8767d",
      "source": "© IBM Corp., 2017-2026"
    }
  ],
  "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"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}