Skip to content

Instantly share code, notes, and snippets.

@HYUNSEONG-KIM
Created August 19, 2023 11:55
Show Gist options
  • Save HYUNSEONG-KIM/813b1ec944889791afb9820673f36c9e to your computer and use it in GitHub Desktop.
Save HYUNSEONG-KIM/813b1ec944889791afb9820673f36c9e to your computer and use it in GitHub Desktop.
Simple Quantum Gate calculator
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 141,
"metadata": {},
"outputs": [],
"source": [
"import sympy as sp\n",
"from sympy.physics.quantum import TensorProduct as tp\n",
"from sympy.physics.quantum.dagger import Dagger as dag\n",
"from functools import reduce"
]
},
{
"cell_type": "code",
"execution_count": 131,
"metadata": {},
"outputs": [],
"source": [
"def combie_circuit_gate(circuit):\n",
" return reduce(lambda x,y: x*y, circuit)"
]
},
{
"cell_type": "code",
"execution_count": 156,
"metadata": {},
"outputs": [],
"source": [
"# Default Gates\n",
"Xg = sp.Matrix([[0, 1], [1,0]])\n",
"Yg = sp.Matrix([[0, complex(0, 1)], [complex(0, -1),0]])\n",
"Zg = sp.Matrix([[1, 0], [0,-1]])\n",
"Ig = sp.eye(2)\n",
"Hg = sp.Matrix([[1, 1],[1, -1]])/sp.sqrt(2)\n",
"Sg = sp.Matrix([[1, 0],[0, -complex(0,1)]])\n",
"CNOT0 = sp.Matrix([[1,0],[0,0]])\n",
"CNOT1 = sp.Matrix([[0,0],[0,1]])\n",
"\n",
"def RX(theta):\n",
" return sp.Matrix([\n",
" [sp.cos(theta/2), complex(0,-1)*sp.sin(theta/2)],\n",
" [complex(0,-1)*sp.sin(theta/2), sp.cos(theta/2)]\n",
" ])\n",
"def RY(theta):\n",
" return sp.Matrix([\n",
" [sp.cos(theta/2), -1*sp.sin(theta/2)],\n",
" [sp.sin(theta/2), sp.cos(theta/2)]\n",
" ])\n",
"def RZ(theta):\n",
" return sp.Matrix([\n",
" [sp.exp(-complex(0,1)*theta/2),0],\n",
" [0, sp.exp(complex(0,1)*theta/2)]\n",
" ])\n",
"# Multi-qubit gates\n",
"def X(i, n:int):\n",
" assert type(i) is int, \"Index i must be integer.\" \n",
" assert type(n) is int, \"Qubit number n must be integer.\"\n",
" assert i<n, \"Index must be smaller than total qubit number.\"\n",
" assert i>-1, \"Index must be positive integer including 0.\"\n",
" glist = n*[Ig]\n",
" glist[i] = Xg\n",
" return tp(*glist)\n",
"def Y(i, n:int):\n",
" assert type(i) is int, \"Index i must be integer.\" \n",
" assert type(n) is int, \"Qubit number n must be integer.\"\n",
" assert i<n, \"Index must be smaller than total qubit number.\"\n",
" assert i>-1, \"Index must be positive integer including 0.\"\n",
" glist = n*[Ig]\n",
" glist[i] = Yg\n",
" return tp(*glist)\n",
"def Z(i, n:int):\n",
" assert type(i) is int, \"Index i must be integer.\" \n",
" assert type(n) is int, \"Qubit number n must be integer.\"\n",
" assert i<n, \"Index must be smaller than total qubit number.\"\n",
" assert i>-1, \"Index must be positive integer including 0.\"\n",
" glist = n*[Ig]\n",
" glist[i] = Zg\n",
" return tp(*glist)\n",
"def CNOT(i:int, j:int, n:int):\n",
" assert i != j, \"Two qubit gate must have 2 different qubit index.\"\n",
" assert type(i) is int, \"Index i must be integer.\" \n",
" assert type(j) is int, \"Index j must be integer.\" \n",
" assert type(n) is int, \"Qubit number n must be integer.\"\n",
" assert i<n and j<n, \"Index must be smaller than total qubit number.\"\n",
" assert i>-1 and j>-1, \"Index must be positive integer including 0.\"\n",
" \n",
" glist0 = n*[Ig]\n",
" glist1 = n*[Ig]\n",
" \n",
" glist0[i] = CNOT0\n",
" glist1[i] = CNOT1\n",
" glist1[j] = Xg \n",
" return tp(*glist0) + tp(*glist1) \n",
"def Uni(U, i, n:int): # Using this function for multi-qubit Rx,Ry,and Rz and arbitary single gates. \n",
" assert type(i) is int, \"Index i must be integer.\" \n",
" assert type(n) is int, \"Qubit number n must be integer.\"\n",
" assert i<n, \"Index must be smaller than total qubit number.\"\n",
" assert i>-1, \"Index must be positive integer including 0.\"\n",
" glist = n*[Ig]\n",
" glist[i] = U\n",
" return tp(*glist)\n",
"def ArbiUnitary(sym_st):\n",
" sy = sym_st.lower()\n",
" a1, a2, a3, a4 = sp.symbols([f\"{sy}_{i}\" for i in range(1,5)])\n",
" return sp.Matrix([[a1, a2],[a3, a4]]), (a1, a2, a3, a4)"
]
},
{
"cell_type": "code",
"execution_count": 157,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2}}{2} & \\frac{\\sqrt{2}}{2}\\\\\\frac{\\sqrt{2}}{2} & - \\frac{\\sqrt{2}}{2}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[sqrt(2)/2, sqrt(2)/2],\n",
"[sqrt(2)/2, -sqrt(2)/2]])"
]
},
"execution_count": 157,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Hg"
]
},
{
"cell_type": "code",
"execution_count": 158,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}1 & 0\\\\0 & - 1.0 i\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[1, 0],\n",
"[0, -1.0*I]])"
]
},
"execution_count": 158,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Sg"
]
},
{
"cell_type": "code",
"execution_count": 159,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}1 & 0\\\\0 & 1.0 i\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[1, 0],\n",
"[0, 1.0*I]])"
]
},
"execution_count": 159,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dag(Sg)"
]
},
{
"cell_type": "code",
"execution_count": 160,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}1 & 0 & 0 & 0\\\\0 & 0 & 0 & 1\\\\0 & 0 & 1 & 0\\\\0 & 1 & 0 & 0\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[1, 0, 0, 0],\n",
"[0, 0, 0, 1],\n",
"[0, 0, 1, 0],\n",
"[0, 1, 0, 0]])"
]
},
"execution_count": 160,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"wires = 2\n",
"CNOT(1,0, wires)"
]
},
{
"cell_type": "code",
"execution_count": 163,
"metadata": {},
"outputs": [],
"source": [
"theta = sp.Symbol(r\"\\theta\")"
]
},
{
"cell_type": "code",
"execution_count": 164,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\cos{\\left(\\frac{\\theta}{2} \\right)} & - 1.0 i \\sin{\\left(\\frac{\\theta}{2} \\right)} & 0 & 0\\\\- 1.0 i \\sin{\\left(\\frac{\\theta}{2} \\right)} & \\cos{\\left(\\frac{\\theta}{2} \\right)} & 0 & 0\\\\0 & 0 & \\cos{\\left(\\frac{\\theta}{2} \\right)} & - 1.0 i \\sin{\\left(\\frac{\\theta}{2} \\right)}\\\\0 & 0 & - 1.0 i \\sin{\\left(\\frac{\\theta}{2} \\right)} & \\cos{\\left(\\frac{\\theta}{2} \\right)}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ cos(\\theta/2), -1.0*I*sin(\\theta/2), 0, 0],\n",
"[-1.0*I*sin(\\theta/2), cos(\\theta/2), 0, 0],\n",
"[ 0, 0, cos(\\theta/2), -1.0*I*sin(\\theta/2)],\n",
"[ 0, 0, -1.0*I*sin(\\theta/2), cos(\\theta/2)]])"
]
},
"execution_count": 164,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Uni(RX(theta), 1, wires)"
]
},
{
"cell_type": "code",
"execution_count": 87,
"metadata": {},
"outputs": [],
"source": [
"U, u_sym = ArbiUnitary(\"U\")\n",
"A, a_sym = ArbiUnitary(\"A\")\n",
"B, b_sym = ArbiUnitary(\"B\")\n",
"C, c_sym = ArbiUnitary(\"C\")"
]
},
{
"cell_type": "code",
"execution_count": 149,
"metadata": {},
"outputs": [],
"source": [
"# symbols\n",
"a1, a2, a3, a4 = a_sym\n",
"b1, b2, b3, b4 = b_sym\n",
"c1, c2, c3, c4 = c_sym"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. You can multiply gates directly."
]
},
{
"cell_type": "code",
"execution_count": 88,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}u_{1} & u_{2} & 0 & 0 & 0 & 0 & 0 & 0\\\\u_{3} & u_{4} & 0 & 0 & 0 & 0 & 0 & 0\\\\0 & 0 & u_{4} & u_{3} & 0 & 0 & 0 & 0\\\\0 & 0 & u_{2} & u_{1} & 0 & 0 & 0 & 0\\\\0 & 0 & 0 & 0 & u_{4} & u_{3} & 0 & 0\\\\0 & 0 & 0 & 0 & u_{2} & u_{1} & 0 & 0\\\\0 & 0 & 0 & 0 & 0 & 0 & u_{1} & u_{2}\\\\0 & 0 & 0 & 0 & 0 & 0 & u_{3} & u_{4}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[u_1, u_2, 0, 0, 0, 0, 0, 0],\n",
"[u_3, u_4, 0, 0, 0, 0, 0, 0],\n",
"[ 0, 0, u_4, u_3, 0, 0, 0, 0],\n",
"[ 0, 0, u_2, u_1, 0, 0, 0, 0],\n",
"[ 0, 0, 0, 0, u_4, u_3, 0, 0],\n",
"[ 0, 0, 0, 0, u_2, u_1, 0, 0],\n",
"[ 0, 0, 0, 0, 0, 0, u_1, u_2],\n",
"[ 0, 0, 0, 0, 0, 0, u_3, u_4]])"
]
},
"execution_count": 88,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"wires = 3\n",
"CNOT(0, 2, wires) * CNOT(1, 2, wires) * Uni(U, 2, wires) * CNOT(1, 2, wires) * CNOT(0, 2, wires)"
]
},
{
"cell_type": "code",
"execution_count": 89,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}u_{4} & u_{3}\\\\u_{2} & u_{1}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[u_4, u_3],\n",
"[u_2, u_1]])"
]
},
"execution_count": 89,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Xg*U*Xg"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2. Or defining sequential gates and multiply at onces."
]
},
{
"cell_type": "code",
"execution_count": 148,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}u_{1} & u_{2} & 0 & 0 & 0 & 0 & 0 & 0\\\\u_{3} & u_{4} & 0 & 0 & 0 & 0 & 0 & 0\\\\0 & 0 & u_{4} & u_{3} & 0 & 0 & 0 & 0\\\\0 & 0 & u_{2} & u_{1} & 0 & 0 & 0 & 0\\\\0 & 0 & 0 & 0 & u_{4} & u_{3} & 0 & 0\\\\0 & 0 & 0 & 0 & u_{2} & u_{1} & 0 & 0\\\\0 & 0 & 0 & 0 & 0 & 0 & u_{1} & u_{2}\\\\0 & 0 & 0 & 0 & 0 & 0 & u_{3} & u_{4}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[u_1, u_2, 0, 0, 0, 0, 0, 0],\n",
"[u_3, u_4, 0, 0, 0, 0, 0, 0],\n",
"[ 0, 0, u_4, u_3, 0, 0, 0, 0],\n",
"[ 0, 0, u_2, u_1, 0, 0, 0, 0],\n",
"[ 0, 0, 0, 0, u_4, u_3, 0, 0],\n",
"[ 0, 0, 0, 0, u_2, u_1, 0, 0],\n",
"[ 0, 0, 0, 0, 0, 0, u_1, u_2],\n",
"[ 0, 0, 0, 0, 0, 0, u_3, u_4]])"
]
},
"execution_count": 148,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"circuit001 = [\n",
" CNOT(0, 2, wires), \n",
" CNOT(1, 2, wires),\n",
" Uni(U, 2, wires),\n",
" CNOT(1, 2, wires),\n",
" CNOT(0, 2, wires)\n",
"]\n",
"combie_circuit_gate(circuit001)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "code",
"execution_count": 151,
"metadata": {},
"outputs": [],
"source": [
"circuit002 = [\n",
" CNOT(0, 1, 2),\n",
" tp(Hg, Hg),\n",
" CNOT(0, 1, 2),\n",
" Uni(C, 1, 2),\n",
" CNOT(0, 1, 2),\n",
" tp(Hg,Hg),\n",
" CNOT(0, 1, 2)\n",
"]\n"
]
},
{
"cell_type": "code",
"execution_count": 152,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\frac{c_{1}}{2} + \\frac{c_{2}}{2} + \\frac{c_{3}}{2} + \\frac{c_{4}}{2} & 0 & \\frac{c_{1}}{2} - \\frac{c_{2}}{2} + \\frac{c_{3}}{2} - \\frac{c_{4}}{2} & 0\\\\0 & \\frac{c_{1}}{2} - \\frac{c_{2}}{2} - \\frac{c_{3}}{2} + \\frac{c_{4}}{2} & 0 & \\frac{c_{1}}{2} + \\frac{c_{2}}{2} - \\frac{c_{3}}{2} - \\frac{c_{4}}{2}\\\\\\frac{c_{1}}{2} + \\frac{c_{2}}{2} - \\frac{c_{3}}{2} - \\frac{c_{4}}{2} & 0 & \\frac{c_{1}}{2} - \\frac{c_{2}}{2} - \\frac{c_{3}}{2} + \\frac{c_{4}}{2} & 0\\\\0 & \\frac{c_{1}}{2} - \\frac{c_{2}}{2} + \\frac{c_{3}}{2} - \\frac{c_{4}}{2} & 0 & \\frac{c_{1}}{2} + \\frac{c_{2}}{2} + \\frac{c_{3}}{2} + \\frac{c_{4}}{2}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[c_1/2 + c_2/2 + c_3/2 + c_4/2, 0, c_1/2 - c_2/2 + c_3/2 - c_4/2, 0],\n",
"[ 0, c_1/2 - c_2/2 - c_3/2 + c_4/2, 0, c_1/2 + c_2/2 - c_3/2 - c_4/2],\n",
"[c_1/2 + c_2/2 - c_3/2 - c_4/2, 0, c_1/2 - c_2/2 - c_3/2 + c_4/2, 0],\n",
"[ 0, c_1/2 - c_2/2 + c_3/2 - c_4/2, 0, c_1/2 + c_2/2 + c_3/2 + c_4/2]])"
]
},
"execution_count": 152,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"combie_circuit_gate(circuit002)"
]
},
{
"cell_type": "code",
"execution_count": 153,
"metadata": {},
"outputs": [],
"source": [
"Param_Circuit = combie_circuit_gate(circuit002)"
]
},
{
"cell_type": "code",
"execution_count": 154,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\frac{c_{3}}{2} + \\frac{c_{4}}{2} + \\frac{5}{2} & 0 & \\frac{c_{3}}{2} - \\frac{c_{4}}{2} - \\frac{3}{2} & 0\\\\0 & - \\frac{c_{3}}{2} + \\frac{c_{4}}{2} - \\frac{3}{2} & 0 & - \\frac{c_{3}}{2} - \\frac{c_{4}}{2} + \\frac{5}{2}\\\\- \\frac{c_{3}}{2} - \\frac{c_{4}}{2} + \\frac{5}{2} & 0 & - \\frac{c_{3}}{2} + \\frac{c_{4}}{2} - \\frac{3}{2} & 0\\\\0 & \\frac{c_{3}}{2} - \\frac{c_{4}}{2} - \\frac{3}{2} & 0 & \\frac{c_{3}}{2} + \\frac{c_{4}}{2} + \\frac{5}{2}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ c_3/2 + c_4/2 + 5/2, 0, c_3/2 - c_4/2 - 3/2, 0],\n",
"[ 0, -c_3/2 + c_4/2 - 3/2, 0, -c_3/2 - c_4/2 + 5/2],\n",
"[-c_3/2 - c_4/2 + 5/2, 0, -c_3/2 + c_4/2 - 3/2, 0],\n",
"[ 0, c_3/2 - c_4/2 - 3/2, 0, c_3/2 + c_4/2 + 5/2]])"
]
},
"execution_count": 154,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Param_Circuit.subs([(c1, 1), (c2, 4)])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Examples"
]
},
{
"cell_type": "code",
"execution_count": 102,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}c_{1} & c_{2} & 0 & 0\\\\c_{3} & c_{4} & 0 & 0\\\\a_{3} c_{3} & a_{3} c_{4} & a_{4} c_{4} & a_{4} c_{3}\\\\a_{3} c_{1} & a_{3} c_{2} & a_{4} c_{2} & a_{4} c_{1}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ c_1, c_2, 0, 0],\n",
"[ c_3, c_4, 0, 0],\n",
"[a_3*c_3, a_3*c_4, a_4*c_4, a_4*c_3],\n",
"[a_3*c_1, a_3*c_2, a_4*c_2, a_4*c_1]])"
]
},
"execution_count": 102,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(CNOT(0, 1, 2) * tp(A, C)* CNOT(0, 1, 2)).subs([(a1,1),(a2, 0)])"
]
},
{
"cell_type": "code",
"execution_count": 126,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right) + \\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right) & 0 & 0 & 0 & 0 & 0 & 0 & \\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right) - \\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)\\\\\\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & 0 & 0 & 0 & 0 & - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2}\\\\\\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & 0 & - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & 0 & 0 & - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & 0 & \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2}\\\\\\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & 0 & 0 & - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & 0 & 0 & \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2}\\\\\\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & 0 & 0 & - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & 0 & 0 & \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2}\\\\\\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & 0 & - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & 0 & 0 & - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & 0 & \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2}\\\\\\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & 0 & 0 & 0 & 0 & - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} & \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} + \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} + \\frac{\\sqrt{2} c_{3}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(- \\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2} - \\frac{\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} + \\frac{\\sqrt{2} c_{4}}{4}\\right)}{2}\\\\\\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right) + \\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right) & 0 & 0 & 0 & 0 & 0 & 0 & \\sqrt{2} \\left(\\frac{\\sqrt{2} c_{1}}{4} - \\frac{\\sqrt{2} c_{3}}{4}\\right) - \\sqrt{2} \\left(\\frac{\\sqrt{2} c_{2}}{4} - \\frac{\\sqrt{2} c_{4}}{4}\\right)\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ sqrt(2)*(sqrt(2)*c_1/4 + sqrt(2)*c_3/4) + sqrt(2)*(sqrt(2)*c_2/4 + sqrt(2)*c_4/4), 0, 0, 0, 0, 0, 0, sqrt(2)*(sqrt(2)*c_1/4 + sqrt(2)*c_3/4) - sqrt(2)*(sqrt(2)*c_2/4 + sqrt(2)*c_4/4)],\n",
"[sqrt(2)*(-sqrt(2)*c_1/4 + sqrt(2)*c_3/4)/2 + sqrt(2)*(sqrt(2)*c_1/4 - sqrt(2)*c_3/4)/2 + sqrt(2)*(-sqrt(2)*c_2/4 + sqrt(2)*c_4/4)/2 + sqrt(2)*(sqrt(2)*c_2/4 - sqrt(2)*c_4/4)/2, -sqrt(2)*(-sqrt(2)*c_1/4 + sqrt(2)*c_3/4)/2 + sqrt(2)*(sqrt(2)*c_1/4 - sqrt(2)*c_3/4)/2 + sqrt(2)*(-sqrt(2)*c_2/4 + sqrt(2)*c_4/4)/2 - sqrt(2)*(sqrt(2)*c_2/4 - sqrt(2)*c_4/4)/2, 0, 0, 0, 0, -sqrt(2)*(-sqrt(2)*c_1/4 + sqrt(2)*c_3/4)/2 + sqrt(2)*(sqrt(2)*c_1/4 - sqrt(2)*c_3/4)/2 - sqrt(2)*(-sqrt(2)*c_2/4 + sqrt(2)*c_4/4)/2 + sqrt(2)*(sqrt(2)*c_2/4 - sqrt(2)*c_4/4)/2, sqrt(2)*(-sqrt(2)*c_1/4 + sqrt(2)*c_3/4)/2 + sqrt(2)*(sqrt(2)*c_1/4 - sqrt(2)*c_3/4)/2 - sqrt(2)*(-sqrt(2)*c_2/4 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sqrt(2)*c_1/4 + sqrt(2)*c_3/4)/2 + sqrt(2)*(-sqrt(2)*c_2/4 - sqrt(2)*c_4/4)/2 - sqrt(2)*(sqrt(2)*c_2/4 + sqrt(2)*c_4/4)/2, 0, 0, 0, 0, -sqrt(2)*(-sqrt(2)*c_1/4 - sqrt(2)*c_3/4)/2 + sqrt(2)*(sqrt(2)*c_1/4 + sqrt(2)*c_3/4)/2 - sqrt(2)*(-sqrt(2)*c_2/4 - sqrt(2)*c_4/4)/2 + sqrt(2)*(sqrt(2)*c_2/4 + sqrt(2)*c_4/4)/2, sqrt(2)*(-sqrt(2)*c_1/4 - sqrt(2)*c_3/4)/2 + sqrt(2)*(sqrt(2)*c_1/4 + sqrt(2)*c_3/4)/2 - sqrt(2)*(-sqrt(2)*c_2/4 - sqrt(2)*c_4/4)/2 - sqrt(2)*(sqrt(2)*c_2/4 + sqrt(2)*c_4/4)/2],\n",
"[ sqrt(2)*(sqrt(2)*c_1/4 - sqrt(2)*c_3/4) + sqrt(2)*(sqrt(2)*c_2/4 - sqrt(2)*c_4/4), 0, 0, 0, 0, 0, 0, sqrt(2)*(sqrt(2)*c_1/4 - sqrt(2)*c_3/4) - sqrt(2)*(sqrt(2)*c_2/4 - sqrt(2)*c_4/4)]])"
]
},
"execution_count": 126,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"CNOT(0, 2, wires) * CNOT(1, 2, wires)* tp(Hg, Hg, Hg)*CNOT(1, 2, wires) * CNOT(0, 2, wires) * Uni(C, 2, wires) * CNOT(0, 2, wires) * CNOT(1, 2, wires)*tp(Hg, Hg, Hg)*CNOT(1, 2, wires) * CNOT(0, 2, wires)"
]
},
{
"cell_type": "code",
"execution_count": 115,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}c_{1} & c_{2} & 0 & 0 & 0 & 0 & 0 & 0\\\\c_{3} & c_{4} & 0 & 0 & 0 & 0 & 0 & 0\\\\0 & 0 & c_{4} & c_{3} & 0 & 0 & 0 & 0\\\\0 & 0 & c_{2} & c_{1} & 0 & 0 & 0 & 0\\\\0 & 0 & 0 & 0 & c_{4} & c_{3} & 0 & 0\\\\0 & 0 & 0 & 0 & c_{2} & c_{1} & 0 & 0\\\\0 & 0 & 0 & 0 & 0 & 0 & c_{1} & c_{2}\\\\0 & 0 & 0 & 0 & 0 & 0 & c_{3} & c_{4}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[c_1, c_2, 0, 0, 0, 0, 0, 0],\n",
"[c_3, c_4, 0, 0, 0, 0, 0, 0],\n",
"[ 0, 0, c_4, c_3, 0, 0, 0, 0],\n",
"[ 0, 0, c_2, c_1, 0, 0, 0, 0],\n",
"[ 0, 0, 0, 0, c_4, c_3, 0, 0],\n",
"[ 0, 0, 0, 0, c_2, c_1, 0, 0],\n",
"[ 0, 0, 0, 0, 0, 0, c_1, c_2],\n",
"[ 0, 0, 0, 0, 0, 0, c_3, c_4]])"
]
},
"execution_count": 115,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"CNOT(1, 2, wires) * CNOT(0, 2, wires) * Uni(C, 2, wires) * CNOT(0, 2, wires) * CNOT(1, 2, wires)"
]
},
{
"cell_type": "code",
"execution_count": 91,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}a_{1} b_{1} c_{1} & a_{1} b_{1} c_{2} & a_{1} b_{2} c_{2} & a_{1} b_{2} c_{1} & a_{2} b_{1} c_{2} & a_{2} b_{1} c_{1} & a_{2} b_{2} c_{1} & a_{2} b_{2} c_{2}\\\\a_{1} b_{1} c_{3} & a_{1} b_{1} c_{4} & a_{1} b_{2} c_{4} & a_{1} b_{2} c_{3} & a_{2} b_{1} c_{4} & a_{2} b_{1} c_{3} & a_{2} b_{2} c_{3} & a_{2} b_{2} c_{4}\\\\a_{1} b_{3} c_{3} & a_{1} b_{3} c_{4} & a_{1} b_{4} c_{4} & a_{1} b_{4} c_{3} & a_{2} b_{3} c_{4} & a_{2} b_{3} c_{3} & a_{2} b_{4} c_{3} & a_{2} b_{4} c_{4}\\\\a_{1} b_{3} c_{1} & a_{1} b_{3} c_{2} & a_{1} b_{4} c_{2} & a_{1} b_{4} c_{1} & a_{2} b_{3} c_{2} & a_{2} b_{3} c_{1} & a_{2} b_{4} c_{1} & a_{2} b_{4} c_{2}\\\\a_{3} b_{1} c_{3} & a_{3} b_{1} c_{4} & a_{3} b_{2} c_{4} & a_{3} b_{2} c_{3} & a_{4} b_{1} c_{4} & a_{4} b_{1} c_{3} & a_{4} b_{2} c_{3} & a_{4} b_{2} c_{4}\\\\a_{3} b_{1} c_{1} & a_{3} b_{1} c_{2} & a_{3} b_{2} c_{2} & a_{3} b_{2} c_{1} & a_{4} b_{1} c_{2} & a_{4} b_{1} c_{1} & a_{4} b_{2} c_{1} & a_{4} b_{2} c_{2}\\\\a_{3} b_{3} c_{1} & a_{3} b_{3} c_{2} & a_{3} b_{4} c_{2} & a_{3} b_{4} c_{1} & a_{4} b_{3} c_{2} & a_{4} b_{3} c_{1} & a_{4} b_{4} c_{1} & a_{4} b_{4} c_{2}\\\\a_{3} b_{3} c_{3} & a_{3} b_{3} c_{4} & a_{3} b_{4} c_{4} & a_{3} b_{4} c_{3} & a_{4} b_{3} c_{4} & a_{4} b_{3} c_{3} & a_{4} b_{4} c_{3} & a_{4} b_{4} c_{4}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[a_1*b_1*c_1, a_1*b_1*c_2, a_1*b_2*c_2, a_1*b_2*c_1, a_2*b_1*c_2, a_2*b_1*c_1, a_2*b_2*c_1, a_2*b_2*c_2],\n",
"[a_1*b_1*c_3, a_1*b_1*c_4, a_1*b_2*c_4, a_1*b_2*c_3, a_2*b_1*c_4, a_2*b_1*c_3, a_2*b_2*c_3, a_2*b_2*c_4],\n",
"[a_1*b_3*c_3, a_1*b_3*c_4, a_1*b_4*c_4, a_1*b_4*c_3, a_2*b_3*c_4, a_2*b_3*c_3, a_2*b_4*c_3, a_2*b_4*c_4],\n",
"[a_1*b_3*c_1, a_1*b_3*c_2, a_1*b_4*c_2, a_1*b_4*c_1, a_2*b_3*c_2, a_2*b_3*c_1, a_2*b_4*c_1, a_2*b_4*c_2],\n",
"[a_3*b_1*c_3, a_3*b_1*c_4, a_3*b_2*c_4, a_3*b_2*c_3, a_4*b_1*c_4, a_4*b_1*c_3, a_4*b_2*c_3, a_4*b_2*c_4],\n",
"[a_3*b_1*c_1, a_3*b_1*c_2, a_3*b_2*c_2, a_3*b_2*c_1, a_4*b_1*c_2, a_4*b_1*c_1, a_4*b_2*c_1, a_4*b_2*c_2],\n",
"[a_3*b_3*c_1, a_3*b_3*c_2, a_3*b_4*c_2, a_3*b_4*c_1, a_4*b_3*c_2, a_4*b_3*c_1, a_4*b_4*c_1, a_4*b_4*c_2],\n",
"[a_3*b_3*c_3, a_3*b_3*c_4, a_3*b_4*c_4, a_3*b_4*c_3, a_4*b_3*c_4, a_4*b_3*c_3, a_4*b_4*c_3, a_4*b_4*c_4]])"
]
},
"execution_count": 91,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"CNOT(1, 2, wires) * CNOT(0, 2, wires) * tp(A, B, C) * CNOT(0, 2, wires) * CNOT(1, 2, wires)"
]
},
{
"cell_type": "code",
"execution_count": 92,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\frac{c_{1}}{2} + \\frac{c_{4}}{2} & \\frac{c_{2}}{2} + \\frac{c_{3}}{2} & 0 & 0 & \\frac{c_{1}}{2} - \\frac{c_{4}}{2} & \\frac{c_{2}}{2} - \\frac{c_{3}}{2} & 0 & 0\\\\\\frac{c_{2}}{2} + \\frac{c_{3}}{2} & \\frac{c_{1}}{2} + \\frac{c_{4}}{2} & 0 & 0 & - \\frac{c_{2}}{2} + \\frac{c_{3}}{2} & - \\frac{c_{1}}{2} + \\frac{c_{4}}{2} & 0 & 0\\\\0 & 0 & \\frac{c_{1}}{2} + \\frac{c_{4}}{2} & \\frac{c_{2}}{2} + \\frac{c_{3}}{2} & 0 & 0 & - \\frac{c_{1}}{2} + \\frac{c_{4}}{2} & - \\frac{c_{2}}{2} + \\frac{c_{3}}{2}\\\\0 & 0 & \\frac{c_{2}}{2} + \\frac{c_{3}}{2} & \\frac{c_{1}}{2} + \\frac{c_{4}}{2} & 0 & 0 & \\frac{c_{2}}{2} - \\frac{c_{3}}{2} & \\frac{c_{1}}{2} - \\frac{c_{4}}{2}\\\\\\frac{c_{1}}{2} - \\frac{c_{4}}{2} & \\frac{c_{2}}{2} - \\frac{c_{3}}{2} & 0 & 0 & \\frac{c_{1}}{2} + \\frac{c_{4}}{2} & \\frac{c_{2}}{2} + \\frac{c_{3}}{2} & 0 & 0\\\\- \\frac{c_{2}}{2} + \\frac{c_{3}}{2} & - \\frac{c_{1}}{2} + \\frac{c_{4}}{2} & 0 & 0 & \\frac{c_{2}}{2} + \\frac{c_{3}}{2} & \\frac{c_{1}}{2} + \\frac{c_{4}}{2} & 0 & 0\\\\0 & 0 & - \\frac{c_{1}}{2} + \\frac{c_{4}}{2} & - \\frac{c_{2}}{2} + \\frac{c_{3}}{2} & 0 & 0 & \\frac{c_{1}}{2} + \\frac{c_{4}}{2} & \\frac{c_{2}}{2} + \\frac{c_{3}}{2}\\\\0 & 0 & \\frac{c_{2}}{2} - \\frac{c_{3}}{2} & \\frac{c_{1}}{2} - \\frac{c_{4}}{2} & 0 & 0 & \\frac{c_{2}}{2} + \\frac{c_{3}}{2} & \\frac{c_{1}}{2} + \\frac{c_{4}}{2}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ c_1/2 + c_4/2, c_2/2 + c_3/2, 0, 0, c_1/2 - c_4/2, c_2/2 - c_3/2, 0, 0],\n",
"[ c_2/2 + c_3/2, c_1/2 + c_4/2, 0, 0, -c_2/2 + c_3/2, -c_1/2 + c_4/2, 0, 0],\n",
"[ 0, 0, c_1/2 + c_4/2, c_2/2 + c_3/2, 0, 0, -c_1/2 + c_4/2, -c_2/2 + c_3/2],\n",
"[ 0, 0, c_2/2 + c_3/2, c_1/2 + c_4/2, 0, 0, c_2/2 - c_3/2, c_1/2 - c_4/2],\n",
"[ c_1/2 - c_4/2, c_2/2 - c_3/2, 0, 0, c_1/2 + c_4/2, c_2/2 + c_3/2, 0, 0],\n",
"[-c_2/2 + c_3/2, -c_1/2 + c_4/2, 0, 0, c_2/2 + c_3/2, c_1/2 + c_4/2, 0, 0],\n",
"[ 0, 0, -c_1/2 + c_4/2, -c_2/2 + c_3/2, 0, 0, c_1/2 + c_4/2, c_2/2 + c_3/2],\n",
"[ 0, 0, c_2/2 - c_3/2, c_1/2 - c_4/2, 0, 0, c_2/2 + c_3/2, c_1/2 + c_4/2]])"
]
},
"execution_count": 92,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Uni(Hg, 0, wires) * CNOT(1, 2, wires) * CNOT(0, 2, wires) * Uni(C, 2, wires) * CNOT(0, 2, wires) * CNOT(1, 2, wires) * Uni(Hg, 0, wires)"
]
},
{
"cell_type": "code",
"execution_count": 93,
"metadata": {},
"outputs": [],
"source": [
"ABC_eq = (CNOT(1, 2, wires) * CNOT(0, 2, wires) * tp(A, B, C) * CNOT(0, 2, wires) * CNOT(1, 2, wires))"
]
},
{
"cell_type": "code",
"execution_count": 95,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}a_{1} b_{1} c_{1} & a_{1} b_{1} c_{2} & 0 & 0 & a_{2} b_{1} c_{2} & a_{2} b_{1} c_{1} & 0 & 0\\\\a_{1} b_{1} c_{3} & a_{1} b_{1} c_{4} & 0 & 0 & a_{2} b_{1} c_{4} & a_{2} b_{1} c_{3} & 0 & 0\\\\0 & 0 & a_{1} b_{4} c_{4} & a_{1} b_{4} c_{3} & 0 & 0 & a_{2} b_{4} c_{3} & a_{2} b_{4} c_{4}\\\\0 & 0 & a_{1} b_{4} c_{2} & a_{1} b_{4} c_{1} & 0 & 0 & a_{2} b_{4} c_{1} & a_{2} b_{4} c_{2}\\\\a_{3} b_{1} c_{3} & a_{3} b_{1} c_{4} & 0 & 0 & a_{4} b_{1} c_{4} & a_{4} b_{1} c_{3} & 0 & 0\\\\a_{3} b_{1} c_{1} & a_{3} b_{1} c_{2} & 0 & 0 & a_{4} b_{1} c_{2} & a_{4} b_{1} c_{1} & 0 & 0\\\\0 & 0 & a_{3} b_{4} c_{2} & a_{3} b_{4} c_{1} & 0 & 0 & a_{4} b_{4} c_{1} & a_{4} b_{4} c_{2}\\\\0 & 0 & a_{3} b_{4} c_{4} & a_{3} b_{4} c_{3} & 0 & 0 & a_{4} b_{4} c_{3} & a_{4} b_{4} c_{4}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[a_1*b_1*c_1, a_1*b_1*c_2, 0, 0, a_2*b_1*c_2, a_2*b_1*c_1, 0, 0],\n",
"[a_1*b_1*c_3, a_1*b_1*c_4, 0, 0, a_2*b_1*c_4, a_2*b_1*c_3, 0, 0],\n",
"[ 0, 0, a_1*b_4*c_4, a_1*b_4*c_3, 0, 0, a_2*b_4*c_3, a_2*b_4*c_4],\n",
"[ 0, 0, a_1*b_4*c_2, a_1*b_4*c_1, 0, 0, a_2*b_4*c_1, a_2*b_4*c_2],\n",
"[a_3*b_1*c_3, a_3*b_1*c_4, 0, 0, a_4*b_1*c_4, a_4*b_1*c_3, 0, 0],\n",
"[a_3*b_1*c_1, a_3*b_1*c_2, 0, 0, a_4*b_1*c_2, a_4*b_1*c_1, 0, 0],\n",
"[ 0, 0, a_3*b_4*c_2, a_3*b_4*c_1, 0, 0, a_4*b_4*c_1, a_4*b_4*c_2],\n",
"[ 0, 0, a_3*b_4*c_4, a_3*b_4*c_3, 0, 0, a_4*b_4*c_3, a_4*b_4*c_4]])"
]
},
"execution_count": 95,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ABC_eq.subs([(b_sym[1], 0), (b_sym[2], 0)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.11.4"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment