qsharp-lang 1.7.1-dev → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/dist/katas-content.generated.js +56 -56
  2. package/dist/katas-content.generated.md.js +56 -56
  3. package/docs/Microsoft.Quantum.Arrays/All.md +2 -2
  4. package/docs/Microsoft.Quantum.Arrays/Any.md +2 -2
  5. package/docs/Microsoft.Quantum.Arrays/Chunks.md +2 -2
  6. package/docs/Microsoft.Quantum.Arrays/CircularlyShifted.md +2 -2
  7. package/docs/Microsoft.Quantum.Arrays/ColumnAt.md +2 -2
  8. package/docs/Microsoft.Quantum.Arrays/Count.md +2 -2
  9. package/docs/Microsoft.Quantum.Arrays/Diagonal.md +2 -2
  10. package/docs/Microsoft.Quantum.Arrays/DrawMany.md +2 -2
  11. package/docs/Microsoft.Quantum.Arrays/Enumerated.md +2 -2
  12. package/docs/Microsoft.Quantum.Arrays/Excluding.md +2 -2
  13. package/docs/Microsoft.Quantum.Arrays/Filtered.md +2 -2
  14. package/docs/Microsoft.Quantum.Arrays/FlatMapped.md +2 -2
  15. package/docs/Microsoft.Quantum.Arrays/Flattened.md +2 -2
  16. package/docs/Microsoft.Quantum.Arrays/Fold.md +2 -2
  17. package/docs/Microsoft.Quantum.Arrays/ForEach.md +2 -2
  18. package/docs/Microsoft.Quantum.Arrays/Head.md +2 -2
  19. package/docs/Microsoft.Quantum.Arrays/HeadAndRest.md +2 -2
  20. package/docs/Microsoft.Quantum.Arrays/IndexOf.md +2 -2
  21. package/docs/Microsoft.Quantum.Arrays/IndexRange.md +2 -2
  22. package/docs/Microsoft.Quantum.Arrays/Interleaved.md +2 -2
  23. package/docs/Microsoft.Quantum.Arrays/IsEmpty.md +2 -2
  24. package/docs/Microsoft.Quantum.Arrays/IsRectangularArray.md +2 -2
  25. package/docs/Microsoft.Quantum.Arrays/IsSorted.md +2 -2
  26. package/docs/Microsoft.Quantum.Arrays/IsSquareArray.md +2 -2
  27. package/docs/Microsoft.Quantum.Arrays/Mapped.md +2 -2
  28. package/docs/Microsoft.Quantum.Arrays/MappedByIndex.md +2 -2
  29. package/docs/Microsoft.Quantum.Arrays/MappedOverRange.md +2 -2
  30. package/docs/Microsoft.Quantum.Arrays/Most.md +2 -2
  31. package/docs/Microsoft.Quantum.Arrays/MostAndTail.md +2 -2
  32. package/docs/Microsoft.Quantum.Arrays/Padded.md +2 -2
  33. package/docs/Microsoft.Quantum.Arrays/Partitioned.md +2 -2
  34. package/docs/Microsoft.Quantum.Arrays/Rest.md +2 -2
  35. package/docs/Microsoft.Quantum.Arrays/Reversed.md +2 -2
  36. package/docs/Microsoft.Quantum.Arrays/SequenceI.md +2 -2
  37. package/docs/Microsoft.Quantum.Arrays/SequenceL.md +2 -2
  38. package/docs/Microsoft.Quantum.Arrays/Sorted.md +2 -2
  39. package/docs/Microsoft.Quantum.Arrays/Subarray.md +2 -2
  40. package/docs/Microsoft.Quantum.Arrays/Swapped.md +2 -2
  41. package/docs/Microsoft.Quantum.Arrays/Tail.md +2 -2
  42. package/docs/Microsoft.Quantum.Arrays/Transposed.md +2 -2
  43. package/docs/Microsoft.Quantum.Arrays/Unzipped.md +2 -2
  44. package/docs/Microsoft.Quantum.Arrays/Where.md +2 -2
  45. package/docs/Microsoft.Quantum.Arrays/Windows.md +2 -2
  46. package/docs/Microsoft.Quantum.Arrays/Zipped.md +2 -2
  47. package/docs/Microsoft.Quantum.Canon/ApplyCNOTChain.md +2 -2
  48. package/docs/Microsoft.Quantum.Canon/ApplyControlledOnBitString.md +2 -2
  49. package/docs/Microsoft.Quantum.Canon/ApplyControlledOnInt.md +2 -2
  50. package/docs/Microsoft.Quantum.Canon/ApplyP.md +2 -2
  51. package/docs/Microsoft.Quantum.Canon/ApplyPauli.md +2 -2
  52. package/docs/Microsoft.Quantum.Canon/ApplyPauliFromBitString.md +2 -2
  53. package/docs/Microsoft.Quantum.Canon/ApplyPauliFromInt.md +2 -2
  54. package/docs/Microsoft.Quantum.Canon/ApplyQFT.md +2 -2
  55. package/docs/Microsoft.Quantum.Canon/ApplyToEach.md +2 -2
  56. package/docs/Microsoft.Quantum.Canon/ApplyToEachA.md +2 -2
  57. package/docs/Microsoft.Quantum.Canon/ApplyToEachC.md +2 -2
  58. package/docs/Microsoft.Quantum.Canon/ApplyToEachCA.md +2 -2
  59. package/docs/Microsoft.Quantum.Canon/ApplyXorInPlace.md +2 -2
  60. package/docs/Microsoft.Quantum.Canon/ApplyXorInPlaceL.md +2 -2
  61. package/docs/Microsoft.Quantum.Canon/CX.md +2 -2
  62. package/docs/Microsoft.Quantum.Canon/CY.md +2 -2
  63. package/docs/Microsoft.Quantum.Canon/CZ.md +2 -2
  64. package/docs/Microsoft.Quantum.Canon/Fst.md +2 -2
  65. package/docs/Microsoft.Quantum.Canon/Snd.md +2 -2
  66. package/docs/Microsoft.Quantum.Canon/SwapReverseRegister.md +2 -2
  67. package/docs/Microsoft.Quantum.Convert/BigIntAsBoolArray.md +2 -2
  68. package/docs/Microsoft.Quantum.Convert/BoolArrayAsBigInt.md +2 -2
  69. package/docs/Microsoft.Quantum.Convert/BoolArrayAsInt.md +2 -2
  70. package/docs/Microsoft.Quantum.Convert/BoolArrayAsResultArray.md +2 -2
  71. package/docs/Microsoft.Quantum.Convert/BoolAsResult.md +2 -2
  72. package/docs/Microsoft.Quantum.Convert/ComplexAsComplexPolar.md +2 -2
  73. package/docs/Microsoft.Quantum.Convert/ComplexPolarAsComplex.md +2 -2
  74. package/docs/Microsoft.Quantum.Convert/DoubleAsStringWithPrecision.md +2 -2
  75. package/docs/Microsoft.Quantum.Convert/IntAsBigInt.md +2 -2
  76. package/docs/Microsoft.Quantum.Convert/IntAsBoolArray.md +2 -2
  77. package/docs/Microsoft.Quantum.Convert/IntAsDouble.md +2 -2
  78. package/docs/Microsoft.Quantum.Convert/ResultArrayAsBoolArray.md +2 -2
  79. package/docs/Microsoft.Quantum.Convert/ResultArrayAsInt.md +2 -2
  80. package/docs/Microsoft.Quantum.Convert/ResultAsBool.md +2 -2
  81. package/docs/Microsoft.Quantum.Core/IsRangeEmpty.md +2 -2
  82. package/docs/Microsoft.Quantum.Core/Length.md +2 -2
  83. package/docs/Microsoft.Quantum.Core/RangeEnd.md +2 -2
  84. package/docs/Microsoft.Quantum.Core/RangeReverse.md +2 -2
  85. package/docs/Microsoft.Quantum.Core/RangeStart.md +2 -2
  86. package/docs/Microsoft.Quantum.Core/RangeStep.md +2 -2
  87. package/docs/Microsoft.Quantum.Core/Repeated.md +2 -2
  88. package/docs/Microsoft.Quantum.Diagnostics/DumpMachine.md +2 -2
  89. package/docs/Microsoft.Quantum.Diagnostics/DumpRegister.md +2 -2
  90. package/docs/Microsoft.Quantum.Diagnostics/Fact.md +2 -2
  91. package/docs/Microsoft.Quantum.Intrinsic/AND.md +2 -2
  92. package/docs/Microsoft.Quantum.Intrinsic/CCNOT.md +2 -2
  93. package/docs/Microsoft.Quantum.Intrinsic/CNOT.md +2 -2
  94. package/docs/Microsoft.Quantum.Intrinsic/Exp.md +2 -2
  95. package/docs/Microsoft.Quantum.Intrinsic/H.md +2 -2
  96. package/docs/Microsoft.Quantum.Intrinsic/I.md +2 -2
  97. package/docs/Microsoft.Quantum.Intrinsic/M.md +2 -2
  98. package/docs/Microsoft.Quantum.Intrinsic/Measure.md +2 -2
  99. package/docs/Microsoft.Quantum.Intrinsic/Message.md +2 -2
  100. package/docs/Microsoft.Quantum.Intrinsic/R.md +2 -2
  101. package/docs/Microsoft.Quantum.Intrinsic/R1.md +2 -2
  102. package/docs/Microsoft.Quantum.Intrinsic/R1Frac.md +2 -2
  103. package/docs/Microsoft.Quantum.Intrinsic/RFrac.md +2 -2
  104. package/docs/Microsoft.Quantum.Intrinsic/Reset.md +2 -2
  105. package/docs/Microsoft.Quantum.Intrinsic/ResetAll.md +2 -2
  106. package/docs/Microsoft.Quantum.Intrinsic/Rx.md +2 -2
  107. package/docs/Microsoft.Quantum.Intrinsic/Rxx.md +2 -2
  108. package/docs/Microsoft.Quantum.Intrinsic/Ry.md +2 -2
  109. package/docs/Microsoft.Quantum.Intrinsic/Ryy.md +2 -2
  110. package/docs/Microsoft.Quantum.Intrinsic/Rz.md +2 -2
  111. package/docs/Microsoft.Quantum.Intrinsic/Rzz.md +2 -2
  112. package/docs/Microsoft.Quantum.Intrinsic/S.md +2 -2
  113. package/docs/Microsoft.Quantum.Intrinsic/SWAP.md +2 -2
  114. package/docs/Microsoft.Quantum.Intrinsic/T.md +2 -2
  115. package/docs/Microsoft.Quantum.Intrinsic/X.md +2 -2
  116. package/docs/Microsoft.Quantum.Intrinsic/Y.md +2 -2
  117. package/docs/Microsoft.Quantum.Intrinsic/Z.md +2 -2
  118. package/docs/Microsoft.Quantum.Logical/Xor.md +2 -2
  119. package/docs/Microsoft.Quantum.Math/AbsComplex.md +2 -2
  120. package/docs/Microsoft.Quantum.Math/AbsComplexPolar.md +2 -2
  121. package/docs/Microsoft.Quantum.Math/AbsD.md +2 -2
  122. package/docs/Microsoft.Quantum.Math/AbsI.md +2 -2
  123. package/docs/Microsoft.Quantum.Math/AbsL.md +2 -2
  124. package/docs/Microsoft.Quantum.Math/AbsSquaredComplex.md +2 -2
  125. package/docs/Microsoft.Quantum.Math/AbsSquaredComplexPolar.md +2 -2
  126. package/docs/Microsoft.Quantum.Math/ApproximateFactorial.md +2 -2
  127. package/docs/Microsoft.Quantum.Math/ArcCos.md +2 -2
  128. package/docs/Microsoft.Quantum.Math/ArcCosh.md +2 -2
  129. package/docs/Microsoft.Quantum.Math/ArcSin.md +2 -2
  130. package/docs/Microsoft.Quantum.Math/ArcSinh.md +2 -2
  131. package/docs/Microsoft.Quantum.Math/ArcTan.md +2 -2
  132. package/docs/Microsoft.Quantum.Math/ArcTan2.md +2 -2
  133. package/docs/Microsoft.Quantum.Math/ArcTanh.md +2 -2
  134. package/docs/Microsoft.Quantum.Math/ArgComplex.md +2 -2
  135. package/docs/Microsoft.Quantum.Math/ArgComplexPolar.md +2 -2
  136. package/docs/Microsoft.Quantum.Math/Binom.md +2 -2
  137. package/docs/Microsoft.Quantum.Math/BitSizeI.md +2 -2
  138. package/docs/Microsoft.Quantum.Math/BitSizeL.md +2 -2
  139. package/docs/Microsoft.Quantum.Math/Ceiling.md +2 -2
  140. package/docs/Microsoft.Quantum.Math/Complex.md +2 -2
  141. package/docs/Microsoft.Quantum.Math/ComplexPolar.md +2 -2
  142. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentI.md +2 -2
  143. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentL.md +2 -2
  144. package/docs/Microsoft.Quantum.Math/Cos.md +2 -2
  145. package/docs/Microsoft.Quantum.Math/Cosh.md +2 -2
  146. package/docs/Microsoft.Quantum.Math/DivRemI.md +2 -2
  147. package/docs/Microsoft.Quantum.Math/DivRemL.md +2 -2
  148. package/docs/Microsoft.Quantum.Math/DividedByC.md +2 -2
  149. package/docs/Microsoft.Quantum.Math/DividedByCP.md +2 -2
  150. package/docs/Microsoft.Quantum.Math/E.md +2 -2
  151. package/docs/Microsoft.Quantum.Math/ExpModI.md +2 -2
  152. package/docs/Microsoft.Quantum.Math/ExpModL.md +2 -2
  153. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorI.md +2 -2
  154. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorL.md +2 -2
  155. package/docs/Microsoft.Quantum.Math/FactorialI.md +2 -2
  156. package/docs/Microsoft.Quantum.Math/FactorialL.md +2 -2
  157. package/docs/Microsoft.Quantum.Math/Floor.md +2 -2
  158. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorI.md +2 -2
  159. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorL.md +2 -2
  160. package/docs/Microsoft.Quantum.Math/HammingWeightI.md +2 -2
  161. package/docs/Microsoft.Quantum.Math/InverseModI.md +2 -2
  162. package/docs/Microsoft.Quantum.Math/InverseModL.md +2 -2
  163. package/docs/Microsoft.Quantum.Math/IsCoprimeI.md +2 -2
  164. package/docs/Microsoft.Quantum.Math/IsCoprimeL.md +2 -2
  165. package/docs/Microsoft.Quantum.Math/IsInfinite.md +2 -2
  166. package/docs/Microsoft.Quantum.Math/IsNaN.md +2 -2
  167. package/docs/Microsoft.Quantum.Math/LargestFixedPoint.md +2 -2
  168. package/docs/Microsoft.Quantum.Math/Lg.md +2 -2
  169. package/docs/Microsoft.Quantum.Math/Log.md +2 -2
  170. package/docs/Microsoft.Quantum.Math/Log10.md +2 -2
  171. package/docs/Microsoft.Quantum.Math/LogFactorialD.md +2 -2
  172. package/docs/Microsoft.Quantum.Math/LogGammaD.md +2 -2
  173. package/docs/Microsoft.Quantum.Math/LogOf2.md +2 -2
  174. package/docs/Microsoft.Quantum.Math/Max.md +2 -2
  175. package/docs/Microsoft.Quantum.Math/MaxD.md +2 -2
  176. package/docs/Microsoft.Quantum.Math/MaxI.md +2 -2
  177. package/docs/Microsoft.Quantum.Math/MaxL.md +2 -2
  178. package/docs/Microsoft.Quantum.Math/Min.md +2 -2
  179. package/docs/Microsoft.Quantum.Math/MinD.md +2 -2
  180. package/docs/Microsoft.Quantum.Math/MinI.md +2 -2
  181. package/docs/Microsoft.Quantum.Math/MinL.md +2 -2
  182. package/docs/Microsoft.Quantum.Math/MinusC.md +2 -2
  183. package/docs/Microsoft.Quantum.Math/MinusCP.md +2 -2
  184. package/docs/Microsoft.Quantum.Math/ModulusI.md +2 -2
  185. package/docs/Microsoft.Quantum.Math/ModulusL.md +2 -2
  186. package/docs/Microsoft.Quantum.Math/NegationC.md +2 -2
  187. package/docs/Microsoft.Quantum.Math/NegationCP.md +2 -2
  188. package/docs/Microsoft.Quantum.Math/PI.md +2 -2
  189. package/docs/Microsoft.Quantum.Math/PNorm.md +2 -2
  190. package/docs/Microsoft.Quantum.Math/PNormalized.md +2 -2
  191. package/docs/Microsoft.Quantum.Math/PlusC.md +2 -2
  192. package/docs/Microsoft.Quantum.Math/PlusCP.md +2 -2
  193. package/docs/Microsoft.Quantum.Math/PowC.md +2 -2
  194. package/docs/Microsoft.Quantum.Math/PowCP.md +2 -2
  195. package/docs/Microsoft.Quantum.Math/RealMod.md +2 -2
  196. package/docs/Microsoft.Quantum.Math/Round.md +2 -2
  197. package/docs/Microsoft.Quantum.Math/SignD.md +2 -2
  198. package/docs/Microsoft.Quantum.Math/SignI.md +2 -2
  199. package/docs/Microsoft.Quantum.Math/SignL.md +2 -2
  200. package/docs/Microsoft.Quantum.Math/Sin.md +2 -2
  201. package/docs/Microsoft.Quantum.Math/Sinh.md +2 -2
  202. package/docs/Microsoft.Quantum.Math/SmallestFixedPoint.md +2 -2
  203. package/docs/Microsoft.Quantum.Math/Sqrt.md +2 -2
  204. package/docs/Microsoft.Quantum.Math/SquaredNorm.md +2 -2
  205. package/docs/Microsoft.Quantum.Math/Tan.md +2 -2
  206. package/docs/Microsoft.Quantum.Math/Tanh.md +2 -2
  207. package/docs/Microsoft.Quantum.Math/TimesC.md +2 -2
  208. package/docs/Microsoft.Quantum.Math/TimesCP.md +2 -2
  209. package/docs/Microsoft.Quantum.Math/TrailingZeroCountI.md +2 -2
  210. package/docs/Microsoft.Quantum.Math/TrailingZeroCountL.md +2 -2
  211. package/docs/Microsoft.Quantum.Math/Truncate.md +2 -2
  212. package/docs/Microsoft.Quantum.Measurement/MResetEachZ.md +2 -2
  213. package/docs/Microsoft.Quantum.Measurement/MResetX.md +2 -2
  214. package/docs/Microsoft.Quantum.Measurement/MResetY.md +2 -2
  215. package/docs/Microsoft.Quantum.Measurement/MResetZ.md +2 -2
  216. package/docs/Microsoft.Quantum.Measurement/MeasureAllZ.md +2 -2
  217. package/docs/Microsoft.Quantum.Measurement/MeasureEachZ.md +2 -2
  218. package/docs/Microsoft.Quantum.Measurement/MeasureInteger.md +2 -2
  219. package/docs/Microsoft.Quantum.ResourceEstimation/AccountForEstimates.md +2 -2
  220. package/docs/Microsoft.Quantum.ResourceEstimation/AuxQubitCount.md +2 -2
  221. package/docs/Microsoft.Quantum.ResourceEstimation/BeginEstimateCaching.md +2 -2
  222. package/docs/Microsoft.Quantum.ResourceEstimation/BeginRepeatEstimates.md +2 -2
  223. package/docs/Microsoft.Quantum.ResourceEstimation/CczCount.md +2 -2
  224. package/docs/Microsoft.Quantum.ResourceEstimation/EndEstimateCaching.md +2 -2
  225. package/docs/Microsoft.Quantum.ResourceEstimation/EndRepeatEstimates.md +2 -2
  226. package/docs/Microsoft.Quantum.ResourceEstimation/MeasurementCount.md +2 -2
  227. package/docs/Microsoft.Quantum.ResourceEstimation/PSSPCLayout.md +2 -2
  228. package/docs/Microsoft.Quantum.ResourceEstimation/RepeatEstimates.md +2 -2
  229. package/docs/Microsoft.Quantum.ResourceEstimation/RotationCount.md +2 -2
  230. package/docs/Microsoft.Quantum.ResourceEstimation/RotationDepth.md +2 -2
  231. package/docs/Microsoft.Quantum.ResourceEstimation/SingleVariant.md +2 -2
  232. package/docs/Microsoft.Quantum.ResourceEstimation/TCount.md +2 -2
  233. package/docs/Microsoft.Quantum.Unstable.Arithmetic/AddLE.md +2 -2
  234. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualL.md +2 -2
  235. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualLE.md +2 -2
  236. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterL.md +2 -2
  237. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterLE.md +2 -2
  238. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualL.md +2 -2
  239. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualLE.md +2 -2
  240. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessL.md +2 -2
  241. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessLE.md +2 -2
  242. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualL.md +2 -2
  243. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualLE.md +2 -2
  244. package/docs/Microsoft.Quantum.Unstable.Arithmetic/FourierTDIncByLE.md +2 -2
  245. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByI.md +2 -2
  246. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByIUsingIncByLE.md +2 -2
  247. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByL.md +2 -2
  248. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLE.md +2 -2
  249. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLEUsingAddLE.md +2 -2
  250. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLUsingIncByLE.md +2 -2
  251. package/docs/Microsoft.Quantum.Unstable.Arithmetic/LookAheadDKRSAddLE.md +2 -2
  252. package/docs/Microsoft.Quantum.Unstable.Arithmetic/MAJ.md +2 -2
  253. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ReflectAboutInteger.md +2 -2
  254. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGAddLE.md +2 -2
  255. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGIncByLE.md +2 -2
  256. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryTTKIncByLE.md +2 -2
  257. package/docs/Microsoft.Quantum.Unstable.StatePreparation/ApproximatelyPreparePureStateCP.md +2 -2
  258. package/docs/Microsoft.Quantum.Unstable.StatePreparation/PreparePureStateD.md +2 -2
  259. package/docs/Microsoft.Quantum.Unstable.TableLookup/Select.md +2 -2
  260. package/lib/node/qsc_wasm_bg.wasm +0 -0
  261. package/lib/web/qsc_wasm_bg.wasm +0 -0
  262. package/package.json +1 -1
@@ -1945,7 +1945,7 @@ export default {
1945
1945
  "items": [
1946
1946
  {
1947
1947
  "type": "text-content",
1948
- "content": "<p>This kata continues the introduction to quantum gates, focusing on applying quantum gates to multi-qubit systems.</p>\n<p><strong>This kata covers the following topics:</strong></p>\n<ul>\n<li>Applying quantum gates to a part of the system</li>\n<li>$CNOT$, $CZ$, $CCNOT$, and $SWAP$ gates</li>\n<li>Controlled gates</li>\n</ul>\n<p><strong>What you should know to start working on this kata:</strong></p>\n<ul>\n<li>Basic linear algebra</li>\n<li>The concept of qubit and multi-qubit systems</li>\n<li>Single-qubit and multi-qubit quantum gates</li>\n</ul>\n"
1948
+ "content": "<p>This kata continues the introduction to quantum gates, focusing on applying quantum gates to multi-qubit systems.</p>\n<p><strong>This kata covers the following topics:</strong></p>\n<ul>\n<li>Applying quantum gates to a part of the system</li>\n<li>$CNOT$, $CZ$, $CCNOT$, and $SWAP$ gates</li>\n<li>Controlled gates</li>\n</ul>\n<p><strong>What you should know to start working on this kata:</strong></p>\n<ul>\n<li>Basic concepts of linear algebra</li>\n<li>The concept of qubit and multi-qubit systems</li>\n<li>Single-qubit and multi-qubit quantum gates</li>\n</ul>\n<p>If you need a refresher on these topics, you can check out the previous katas.</p>\n"
1949
1949
  }
1950
1950
  ]
1951
1951
  },
@@ -1956,7 +1956,7 @@ export default {
1956
1956
  "items": [
1957
1957
  {
1958
1958
  "type": "text-content",
1959
- "content": "<p>As a reminder, single-qubit gates are represented by $2\\times2$ unitary matrices.\nThe effect of a gate applied to a qubit can be calculated by multiplying the corresponding matrix by the state vector of the qubit to get the resulting state vector.</p>\n<p>Multi-qubit gates are represented by $2^N\\times2^N$ matrices, where $N$ is the number of qubits the gate operates on. To apply this gate, you multiply the matrix by the state vector of the $N$-qubit quantum system.</p>\n<h2>Applying Gates to a Part of the System</h2>\n<p>The simplest thing we can do with multi-qubit systems is to apply gates to only a subset of qubits in the system.\nSimilar to how it is sometimes possible to represent the state of a multi-qubit system as a tensor product of single-qubit states, you can construct gates that modify the state of a multi-qubit system as tensor products of gates that affect parts of the system.</p>\n<p>Let's consider an example of applying a single-qubit gate to one of the qubits of a two-qubit system.\nIf you want to apply an $X$ gate to the first qubit of the system and do nothing to the second qubit, the resulting gate will be represented as a tensor product of an $X$ gate and the identity gate $I$ which corresponds to doing nothing:</p>\n<p>$$\nX \\otimes I =\n\\begin{bmatrix} 0 &amp; 1 \\\\ 1 &amp; 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 &amp; 0 \\\\ 0 &amp; 1 \\end{bmatrix} =\n\\begin{bmatrix}\n 0 &amp; 0 &amp; 1 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 1 \\\\ \n 1 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 1 &amp; 0 &amp; 0\n\\end{bmatrix}\n$$</p>\n<p>You can use the same approach when applying several gates to independent parts of the system at the same time.\nFor example, applying the $X$ gate to the first qubit and the $H$ gate to the second qubit would be represented as follows:</p>\n<p>$$\nX \\otimes H =\n\\begin{bmatrix} 0 &amp; 1 \\\\ 1 &amp; 0 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 &amp; 1 \\\\ 1 &amp; -1 \\end{bmatrix} =\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n 0 &amp; 0 &amp; 1 &amp; 1 \\\\ \n 0 &amp; 0 &amp; 1 &amp; -1 \\\\ \n 1 &amp; 1 &amp; 0 &amp; 0 \\\\ \n 1 &amp; -1 &amp; 0 &amp; 0\n\\end{bmatrix}\n$$</p>\n<blockquote>\n<p>Note that we can use mixed-multiplication property of tensor product to see that this is equivalent to applying $X$ gate to the first qubit and applying $H$ gate to the second qubit, in either order:</p>\n<p>$$X \\otimes H = (I X) \\otimes (H I) = (I \\otimes H) (X \\otimes I)$$\n$$X \\otimes H = (X I) \\otimes (I H) = (X \\otimes I) (I \\otimes H)$$</p>\n</blockquote>\n<p>This approach can be generalized to larger systems and gates that act on multiple qubits as well.\nIt can be less straightforward when a multi-qubit gate is applied to a subset of qubits that are not &quot;adjacent&quot; to each other in the tensor product; we'll see an example later in this kata.</p>\n"
1959
+ "content": "<p>As a reminder, single-qubit gates are represented by $2\\times2$ unitary matrices.\nThe effect of a gate applied to a qubit can be calculated by multiplying the corresponding matrix by the state vector of the qubit to get the resulting state vector.</p>\n<p>Multi-qubit gates are represented by $2^N\\times2^N$ matrices, where $N$ is the number of qubits the gate operates on. To apply this gate, you multiply the matrix by the state vector of the $N$-qubit quantum system.</p>\n<h2>Applying Gates to a Part of the System</h2>\n<p>The simplest thing you can do with multi-qubit systems is to apply gates to only a subset of qubits in the system.\nSimilar to how it is sometimes possible to represent the state of a multi-qubit system as a tensor product of single-qubit states, you can construct gates that modify the state of a multi-qubit system as tensor products of gates that affect parts of the system.</p>\n<p>Let's consider an example of applying a single-qubit gate to one of the qubits of a two-qubit system.\nIf you want to apply an $X$ gate to the first qubit of the system and do nothing to the second qubit, the resulting gate will be represented as a tensor product of an $X$ gate and the identity gate $I$ which corresponds to doing nothing:</p>\n<p>$$\nX \\otimes I =\n\\begin{bmatrix} 0 &amp; 1 \\\\ 1 &amp; 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 &amp; 0 \\\\ 0 &amp; 1 \\end{bmatrix} =\n\\begin{bmatrix}\n 0 &amp; 0 &amp; 1 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 1 \\\\ \n 1 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 1 &amp; 0 &amp; 0\n\\end{bmatrix}\n$$</p>\n<p>You can use the same approach when applying several gates to independent parts of the system at the same time.\nFor example, applying the $X$ gate to the first qubit and the $H$ gate to the second qubit would be represented as follows:</p>\n<p>$$\nX \\otimes H =\n\\begin{bmatrix} 0 &amp; 1 \\\\ 1 &amp; 0 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 &amp; 1 \\\\ 1 &amp; -1 \\end{bmatrix} =\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n 0 &amp; 0 &amp; 1 &amp; 1 \\\\ \n 0 &amp; 0 &amp; 1 &amp; -1 \\\\ \n 1 &amp; 1 &amp; 0 &amp; 0 \\\\ \n 1 &amp; -1 &amp; 0 &amp; 0\n\\end{bmatrix}\n$$</p>\n<blockquote>\n<p>Note that you can use mixed-multiplication property of tensor product to see that this is equivalent to applying $X$ gate to the first qubit and applying $H$ gate to the second qubit, in either order:</p>\n<p>$$X \\otimes H = (I X) \\otimes (H I) = (I \\otimes H) (X \\otimes I)$$\n$$X \\otimes H = (X I) \\otimes (I H) = (X \\otimes I) (I \\otimes H)$$</p>\n</blockquote>\n<p>This approach can be generalized to larger systems and gates that act on multiple qubits as well.\nIt can be less straightforward when a multi-qubit gate is applied to a subset of qubits that aren't &quot;adjacent&quot; to each other in the tensor product; you'll see an example later in this kata.</p>\n"
1960
1960
  }
1961
1961
  ]
1962
1962
  },
@@ -1966,7 +1966,7 @@ export default {
1966
1966
  "title": "Compound Gate",
1967
1967
  "description": {
1968
1968
  "type": "text-content",
1969
- "content": "<p><strong>Inputs:</strong> $3$ qubits in an arbitrary superposition state $\\ket{\\psi}$, stored in an array of length $3$.</p>\n<p><strong>Goal:</strong> Apply the following matrix to the system. This matrix can be represented as applying $3$ single-qubit gates.</p>\n<p>$$\nQ =\n\\begin{bmatrix}\n0 &amp; -i &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \ni &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n0 &amp; 0 &amp; 0 &amp; -i &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n0 &amp; 0 &amp; i &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\ \n0 &amp; 0 &amp; 0 &amp; 0 &amp; -1 &amp; 0 &amp; 0 &amp; 0 \\\\ \n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 \\\\ \n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; -1 &amp; 0\n\\end{bmatrix}\n$$</p>\n<blockquote>\n<p>We recommend to keep a list of common quantum gates on hand.</p>\n</blockquote>\n<details>\n <summary><b>Need a hint?</b></summary>\n <p>Start by noticing that the top right and bottom left quadrants of the matrix are filled with $0$s, and the bottom right quadrant equals to the top left one, multiplied by $i$. Does this look like a tensor product of a 1-qubit and 2-qubit matrices? Which ones?</p>\n</details>\n"
1969
+ "content": "<p><strong>Inputs:</strong> $3$ qubits in an arbitrary superposition state $\\ket{\\psi}$, stored in an array of length $3$.</p>\n<p><strong>Goal:</strong> Apply the following matrix to the system. This matrix can be represented as applying $3$ single-qubit gates.</p>\n<p>$$\nQ =\n\\begin{bmatrix}\n0 &amp; -i &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \ni &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n0 &amp; 0 &amp; 0 &amp; -i &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n0 &amp; 0 &amp; i &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\ \n0 &amp; 0 &amp; 0 &amp; 0 &amp; -1 &amp; 0 &amp; 0 &amp; 0 \\\\ \n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 \\\\ \n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; -1 &amp; 0\n\\end{bmatrix}\n$$</p>\n<blockquote>\n<p>It's recommended to keep a list of common quantum gates on hand.</p>\n</blockquote>\n<details>\n <summary><b>Need a hint?</b></summary>\n <p>Start by noticing that the top right and bottom left quadrants of the matrix are filled with $0$s, and the bottom right quadrant equals to the top left one, multiplied by $i$. Does this look like a tensor product of a 1-qubit and 2-qubit matrices? Which ones?</p>\n</details>\n"
1970
1970
  },
1971
1971
  "sourceIds": [
1972
1972
  "multi_qubit_gates__compound_gate__Verification.qs",
@@ -1995,7 +1995,7 @@ export default {
1995
1995
  "items": [
1996
1996
  {
1997
1997
  "type": "text-content",
1998
- "content": "<p>Our first proper multi-qubit gate is the $CNOT$ (&quot;controlled NOT&quot;) gate. The $CNOT$ gate is a two-qubit gate, with one qubit referred to as the <strong>control</strong> qubit, and the other qubit as the <strong>target</strong> qubit (usually the first qubit is the control, and the second qubit is the target).</p>\n<p>$CNOT$ acts as a conditional gate of sorts: if the control qubit is in state $\\ket{1}$, it applies the $X$ gate to the target qubit, otherwise it does nothing.</p>\n<blockquote>\n<p>If the system is in a superposition of several basis states, the effects of the gate will be a linear combination of the effects of it acting separately on each of the basis states.\nThis will be the case for all quantum gates you'll encounter later that are specified in terms of basis states: since all unitary gates are linear, it is sufficient to define their effect on the basis states, and use linearity to figure out their effect on any state.</p>\n</blockquote>\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{00} + \\beta\\ket{01} + \\gamma\\ket{10} + \\delta\\ket{11}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$CNOT$</td>\n <td>$\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 1 & 0 \\end{bmatrix}$</td>\n <td>$CNOT\\ket{\\psi} = \\alpha\\ket{00} + \\beta\\ket{01} + \\delta\\ket{10} + \\gamma\\ket{11}$</td>\n <td>\n $$CNOT\\ket{00} = \\ket{00}$$\n $$CNOT\\ket{01} = \\ket{01}$$\n $$CNOT\\ket{10} = \\ket{11}$$\n $$CNOT\\ket{11} = \\ket{10}$$\n </td>\n </tr>\n</table>\n<p>The $CNOT$ gate is particularly useful for preparing entangled states. Consider the following separable state:</p>\n<p>$$\\big(\\alpha\\ket{0} + \\beta\\ket{1}\\big) \\otimes \\ket{0} = \\alpha\\ket{00} + \\beta\\ket{10}$$</p>\n<p>If we apply the $CNOT$ gate to it, with the first qubit as the control, and the second as the target, we get the following state, which is not separable any longer:</p>\n<p>$$\\alpha\\ket{00} + \\beta\\ket{11}$$</p>\n<p>The $CNOT$ gate is self-adjoint: applying it for the second time reverses its effect.</p>\n"
1998
+ "content": "<p>The first multi-qubit gate this kata introduces is the $CNOT$ (&quot;controlled NOT&quot;) gate. The $CNOT$ gate is a two-qubit gate, with one qubit referred to as the <strong>control</strong> qubit, and the other qubit as the <strong>target</strong> qubit (usually the first qubit is the control, and the second qubit is the target).</p>\n<p>$CNOT$ acts as a conditional gate of sorts: if the control qubit is in state $\\ket{1}$, it applies the $X$ gate to the target qubit, otherwise it does nothing.</p>\n<blockquote>\n<p>If the system is in a superposition of several basis states, the effects of the gate will be a linear combination of the effects of it acting separately on each of the basis states.\nThis will be the case for all quantum gates you'll encounter later that are specified in terms of basis states: since all unitary gates are linear, it's sufficient to define their effect on the basis states, and use linearity to figure out their effect on any state.</p>\n</blockquote>\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{00} + \\beta\\ket{01} + \\gamma\\ket{10} + \\delta\\ket{11}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$CNOT$</td>\n <td>$\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 1 & 0 \\end{bmatrix}$</td>\n <td>$CNOT\\ket{\\psi} = \\alpha\\ket{00} + \\beta\\ket{01} + \\delta\\ket{10} + \\gamma\\ket{11}$</td>\n <td>\n $$CNOT\\ket{00} = \\ket{00}$$\n $$CNOT\\ket{01} = \\ket{01}$$\n $$CNOT\\ket{10} = \\ket{11}$$\n $$CNOT\\ket{11} = \\ket{10}$$\n </td>\n </tr>\n</table>\n<p>The $CNOT$ gate is particularly useful for preparing entangled states. Consider the following separable state:</p>\n<p>$$\\big(\\alpha\\ket{0} + \\beta\\ket{1}\\big) \\otimes \\ket{0} = \\alpha\\ket{00} + \\beta\\ket{10}$$</p>\n<p>If you apply the $CNOT$ gate to it, with the first qubit as the control, and the second as the target, you get the following state, which is not separable any longer:</p>\n<p>$$\\alpha\\ket{00} + \\beta\\ket{11}$$</p>\n<p>The $CNOT$ gate is self-adjoint: applying it for the second time reverses its effect.</p>\n"
1999
1999
  }
2000
2000
  ]
2001
2001
  },
@@ -2017,7 +2017,7 @@ export default {
2017
2017
  "items": [
2018
2018
  {
2019
2019
  "type": "text-content",
2020
- "content": "<p>Let's denote the first qubit in state $\\alpha \\ket{0} + \\beta \\ket{1}$ as A and the second qubit in state $\\ket{0}$ as B.</p>\n<p>Compare our input state $\\alpha \\ket{0_A0_B} + \\beta \\ket{1_A0_B}$ with the goal state $\\alpha \\ket{0_A0_B} + \\beta \\ket{1_A1_B}$.\nWe want to pass our input qubit through a gate or gates (to be decided) that do the following. If qubit A is in the $\\ket{0}$ state, then we want to leave qubit B alone (the first term of the superposition).\nHowever, if A is in the $\\ket{1}$ state, we want to flip qubit B from $\\ket{0}$ into $\\ket{1}$ state. In other words, the state of B is to be made contingent upon the state of A.\nThis is exactly the effect of the $CNOT$ gate. Depending upon the state of the <strong>control</strong> qubit (A in our case), the value of the controlled or <strong>target</strong> qubit (B in our case) is inverted or unchanged. Thus, we get the goal state $\\alpha \\ket{00} + \\beta \\ket{11}$.</p>\n"
2020
+ "content": "<p>Let's denote the first qubit in state $\\alpha \\ket{0} + \\beta \\ket{1}$ as A and the second qubit in state $\\ket{0}$ as B.</p>\n<p>Compare the input state $\\alpha \\ket{0_A0_B} + \\beta \\ket{1_A0_B}$ with the goal state $\\alpha \\ket{0_A0_B} + \\beta \\ket{1_A1_B}$.\nYou want to pass our input qubit through a gate or gates (to be decided) that do the following. If qubit A is in the $\\ket{0}$ state, then you want to leave qubit B alone (the first term of the superposition).\nHowever, if A is in the $\\ket{1}$ state, you want to flip qubit B from $\\ket{0}$ into $\\ket{1}$ state. In other words, the state of B is to be made contingent upon the state of A.\nThis is exactly the effect of the $CNOT$ gate. Depending upon the state of the <strong>control</strong> qubit (A in this case), the value of the controlled or <strong>target</strong> qubit (B in this case) is inverted or unchanged. Thus, you get the goal state $\\alpha \\ket{00} + \\beta \\ket{11}$.</p>\n"
2021
2021
  },
2022
2022
  {
2023
2023
  "type": "solution",
@@ -2045,7 +2045,7 @@ export default {
2045
2045
  "items": [
2046
2046
  {
2047
2047
  "type": "text-content",
2048
- "content": "<p>We've seen this state before in the Multi-Qubit Systems kata, where we established that this state is not separable, i.e., it can not be prepared using just the single-qubit gates. To prepare it, we need to use $CNOT$ gate.</p>\n<p>Let's look at the effect of the $CNOT$ gate on a separable state described in the tutorial:\n$$CNOT_{1,2}\\big(\\alpha\\ket{0} + \\beta\\ket{1}\\big) \\otimes \\ket{0} = CNOT_{1,2}(\\alpha\\ket{00} + \\beta\\ket{10}) = \\alpha\\ket{00} + \\beta\\ket{11}$$</p>\n<p>This resulting state is exactly the state we need to prepare, with $\\alpha = \\beta = \\frac{1}{\\sqrt{2}}$!</p>\n<p>The solution takes two steps:</p>\n<ol>\n<li>Prepare a state $\\big(\\frac{1}{\\sqrt{2}}\\ket{0} + \\frac{1}{\\sqrt{2}}\\ket{1}\\big) \\otimes \\ket{0}$.\nWe can use the Hadamard gate to do this.</li>\n<li>Apply a $CNOT$ gate with the first qubit as the control and the second qubit as the target.</li>\n</ol>\n"
2048
+ "content": "<p>You've seen this state before in the Multi-Qubit Systems kata, where you established that this state is not separable, that is, it can't be prepared using just the single-qubit gates. To prepare it, you need to use $CNOT$ gate.</p>\n<p>Let's look at the effect of the $CNOT$ gate on a separable state described in the tutorial:\n$$CNOT_{1,2}\\big(\\alpha\\ket{0} + \\beta\\ket{1}\\big) \\otimes \\ket{0} = CNOT_{1,2}(\\alpha\\ket{00} + \\beta\\ket{10}) = \\alpha\\ket{00} + \\beta\\ket{11}$$</p>\n<p>This resulting state is exactly the state you need to prepare, with $\\alpha = \\beta = \\frac{1}{\\sqrt{2}}$!</p>\n<p>The solution takes two steps:</p>\n<ol>\n<li>Prepare a state $\\big(\\frac{1}{\\sqrt{2}}\\ket{0} + \\frac{1}{\\sqrt{2}}\\ket{1}\\big) \\otimes \\ket{0}$.\nYou can use the Hadamard gate to do this.</li>\n<li>Apply a $CNOT$ gate with the first qubit as the control and the second qubit as the target.</li>\n</ol>\n"
2049
2049
  },
2050
2050
  {
2051
2051
  "type": "solution",
@@ -2062,7 +2062,7 @@ export default {
2062
2062
  "items": [
2063
2063
  {
2064
2064
  "type": "text-content",
2065
- "content": "<p>The $CZ$ (&quot;controlled-Z&quot;) gate is a two-qubit gate, with one qubit referred to as the <strong>control</strong> qubit, and the other as the <strong>target</strong> qubit. Interestingly, for the $CZ$ gate it doesn't matter which qubit is control and which is target - the effect of the gate is the same either way!</p>\n<p>The $CZ$ gate acts as a conditional gate: if the control qubit is in state $\\ket{1}$, it applies the $Z$ gate to the target qubit, otherwise it does nothing.</p>\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{00} + \\beta\\ket{01} + \\gamma\\ket{10} + \\delta\\ket{11}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$CZ$</td>\n <td>\n $$\\begin{bmatrix}\n 1 & 0 & 0 & 0 \\\\\n 0 & 1 & 0 & 0 \\\\\n 0 & 0 & 1 & 0 \\\\\n 0 & 0 & 0 & -1\n \\end{bmatrix}$$\n </td>\n <td>$CZ\\ket{\\psi} = \\alpha\\ket{00} + \\beta\\ket{01} + \\gamma\\ket{10} - \\delta\\ket{11}$</td>\n <td>\n $$CZ\\ket{00} = \\ket{00}$$\n $$CZ\\ket{01} = \\ket{01}$$\n $$CZ\\ket{10} = \\ket{10}$$\n $$CZ\\ket{11} = -\\ket{11}$$\n </td>\n </tr>\n</table>\n<p>The $CZ$ gate is particularly useful for creating and manipulating entangled states where the phase of the quantum state is crucial. Consider the following separable state:</p>\n<p>$$\\big(\\alpha\\ket{0} + \\beta\\ket{1}\\big) \\otimes \\big(\\gamma\\ket{0} + \\delta\\ket{1}\\big) = \\alpha\\gamma\\ket{00} + \\alpha\\delta\\ket{01} + \\beta\\gamma\\ket{10} + \\beta\\delta\\ket{11}$$</p>\n<p>If we apply the $CZ$ gate to it, with the first qubit as the control and the second as the target (or vice versa), we get the following state, which can no longer be separated:</p>\n<p>$$\\alpha\\gamma\\ket{00} + \\alpha\\delta\\ket{01} + \\beta\\gamma\\ket{10} - \\beta\\delta\\ket{11}$$</p>\n<p>The $CZ$ gate is also self-adjoint: applying it a second time reverses its effect, similar to the $CNOT$ gate.</p>\n"
2065
+ "content": "<p>The $CZ$ (&quot;controlled-Z&quot;) gate is a two-qubit gate, with one qubit referred to as the <strong>control</strong> qubit, and the other as the <strong>target</strong> qubit. Interestingly, for the $CZ$ gate it doesn't matter which qubit is control and which is target - the effect of the gate is the same either way!</p>\n<p>The $CZ$ gate acts as a conditional gate: if the control qubit is in state $\\ket{1}$, it applies the $Z$ gate to the target qubit, otherwise it does nothing.</p>\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{00} + \\beta\\ket{01} + \\gamma\\ket{10} + \\delta\\ket{11}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$CZ$</td>\n <td>\n $$\\begin{bmatrix}\n 1 & 0 & 0 & 0 \\\\\n 0 & 1 & 0 & 0 \\\\\n 0 & 0 & 1 & 0 \\\\\n 0 & 0 & 0 & -1\n \\end{bmatrix}$$\n </td>\n <td>$CZ\\ket{\\psi} = \\alpha\\ket{00} + \\beta\\ket{01} + \\gamma\\ket{10} - \\delta\\ket{11}$</td>\n <td>\n $$CZ\\ket{00} = \\ket{00}$$\n $$CZ\\ket{01} = \\ket{01}$$\n $$CZ\\ket{10} = \\ket{10}$$\n $$CZ\\ket{11} = -\\ket{11}$$\n </td>\n </tr>\n</table>\n<p>The $CZ$ gate is particularly useful for creating and manipulating entangled states where the phase of the quantum state is crucial. Consider the following separable state:</p>\n<p>$$\\big(\\alpha\\ket{0} + \\beta\\ket{1}\\big) \\otimes \\big(\\gamma\\ket{0} + \\delta\\ket{1}\\big) = \\alpha\\gamma\\ket{00} + \\alpha\\delta\\ket{01} + \\beta\\gamma\\ket{10} + \\beta\\delta\\ket{11}$$</p>\n<p>If you apply the $CZ$ gate to it, with the first qubit as the control and the second as the target (or vice versa), you get the following state, which can no longer be separated:</p>\n<p>$$\\alpha\\gamma\\ket{00} + \\alpha\\delta\\ket{01} + \\beta\\gamma\\ket{10} - \\beta\\delta\\ket{11}$$</p>\n<p>The $CZ$ gate is also self-adjoint: applying it a second time reverses its effect, similar to the $CNOT$ gate.</p>\n"
2066
2066
  }
2067
2067
  ]
2068
2068
  },
@@ -2084,7 +2084,7 @@ export default {
2084
2084
  "items": [
2085
2085
  {
2086
2086
  "type": "text-content",
2087
- "content": "<p>Firstly we notice that we are dealing with an unentangled pair of qubits.\nIn vector form the transformation we need is\n$$\n\\frac{1}{2}\\begin{bmatrix}1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{bmatrix}\n\\rightarrow\n\\frac{1}{2}\\begin{bmatrix}1 \\\\ 1 \\\\ 1 \\\\ -1 \\end{bmatrix}\n$$</p>\n<p>All that needs to happen to change the input into the goal is that the $\\ket{11}$ basis state needs to have its sign flipped.</p>\n<p>We remember that the Pauli $Z$ gate flips signs in the single qubit case, and that $CZ$ is the 2-qubit version of this gate. And indeed, the effect of the $CZ$ gate is exactly the transformation we're looking for here.</p>\n"
2087
+ "content": "<p>Firstly, notice that you're dealing with an unentangled pair of qubits.\nIn vector form the transformation you need is\n$$\n\\frac{1}{2}\\begin{bmatrix}1 \\\\ 1 \\\\ 1 \\\\ 1 \\end{bmatrix}\n\\rightarrow\n\\frac{1}{2}\\begin{bmatrix}1 \\\\ 1 \\\\ 1 \\\\ -1 \\end{bmatrix}\n$$</p>\n<p>All that needs to happen to change the input into the goal is that the $\\ket{11}$ basis state needs to have its sign flipped.</p>\n<p>Remember that the Pauli Z gate flips signs in the single qubit case, and that $CZ$ is the 2-qubit version of this gate. And indeed, the effect of the $CZ$ gate is exactly the transformation you're looking for here.</p>\n"
2088
2088
  },
2089
2089
  {
2090
2090
  "type": "solution",
@@ -2093,7 +2093,7 @@ export default {
2093
2093
  },
2094
2094
  {
2095
2095
  "type": "text-content",
2096
- "content": "<p>Alternatively, we can express this gate using the intrinsic gate Z and its controlled variant using the Controlled functor:</p>\n"
2096
+ "content": "<p>Alternatively, you can express this gate using the intrinsic $Z$ gate and its controlled variant using the Controlled functor:</p>\n"
2097
2097
  },
2098
2098
  {
2099
2099
  "type": "solution",
@@ -2110,7 +2110,7 @@ export default {
2110
2110
  "items": [
2111
2111
  {
2112
2112
  "type": "text-content",
2113
- "content": "<p>Same as in the case of single-qubit gates, we can represent multi-qubit gates using Dirac notation.</p>\n<blockquote>\n<p>Recall that kets represent column vectors and bras represent row vectors. For any ket $\\ket{\\psi}$, the corresponding bra is its adjoint (conjugate transpose): $\\bra{\\psi} = \\ket{\\psi}^\\dagger$.</p>\n<p>Kets and bras are used to express inner and outer products. The inner product of $\\ket{\\phi}$ and $\\ket{\\psi}$ is the matrix product of $\\bra{\\phi}$ and $\\ket{\\psi}$, denoted as $\\braket{\\phi|\\psi}$, and their outer product is the matrix product of $\\ket{\\phi}$ and $\\bra{\\psi}$, denoted as $\\ket{\\phi}\\bra{\\psi}$.</p>\n<p>As we've seen in the Single-Qubit Gates kata, kets and bras can be used to represent matrices. The outer product of two vectors of the same size produces a square matrix. We can use a linear combination of several outer products of simple vectors (such as basis vectors) to express any square matrix.</p>\n</blockquote>\n<p>Let's consider ket-bra representation of the $CNOT$ gate:</p>\n<p>$$CNOT =$$\n$$= \\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\ket{10}\\bra{11} + \\ket{11}\\bra{10} =$$\n$$=\n\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 1 &amp; 0 &amp; 0 &amp; 0 \\end{bmatrix} +\n\\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 &amp; 1 &amp; 0 &amp; 0 \\end{bmatrix} +\n\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 &amp; 0 &amp; 0 &amp; 1 \\end{bmatrix} +\n\\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\\begin{bmatrix} 0 &amp; 0 &amp; 1 &amp; 0 \\end{bmatrix} =\n$$\n$$=\n\\begin{bmatrix} 1 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\end{bmatrix} +\n\\begin{bmatrix} 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 1 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\end{bmatrix} +\n\\begin{bmatrix} 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 1 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\end{bmatrix} +\n\\begin{bmatrix} 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 1 &amp; 0 \\end{bmatrix} =\n$$\n$$=\\begin{bmatrix} 1 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 1 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 1 \\\\ 0 &amp; 0 &amp; 1 &amp; 0 \\\\ \\end{bmatrix}$$</p>\n<p>This representation can be used to carry out calculations in Dirac notation without ever switching back to matrix representation:</p>\n<p>$$\nCNOT\\ket{10} =\n\\big(\\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\ket{10}\\bra{11} + \\ket{11}\\bra{10}\\big)\\ket{10} =$$\n$$=\\ket{00}\\braket{00|10} + \\ket{01}\\braket{01|10} + \\ket{10}\\braket{11|10} + \\ket{11}\\braket{10|10} =$$\n$$=\\ket{00}\\big(\\braket{00|10}\\big) + \\ket{01}\\big(\\braket{01|10}\\big) + \\ket{10}\\big(\\braket{11|10}\\big) + \\ket{11}\\big(\\braket{10|10}\\big) =$$\n$$=\\ket{00}(0) + \\ket{01}(0) + \\ket{10}(0) + \\ket{11}(1) = \\ket{11}$$</p>\n<blockquote>\n<p>Notice how a lot of the inner product terms turn out to equal 0, and our expression is easily simplified. We have expressed the $CNOT$ gate in terms of outer product of computational basis states, which are orthonormal, and apply it to another computational basis state, so the individual inner products are going to always be 0 or 1.</p>\n</blockquote>\n<p>In general case, a $4 \\times 4$ matrix that describes a 2-qubit gate\n$$A =\n\\begin{bmatrix}\n a_{00} &amp; a_{01} &amp; a_{02} &amp; a_{03} \\\\\n a_{10} &amp; a_{11} &amp; a_{12} &amp; a_{13} \\\\\n a_{20} &amp; a_{21} &amp; a_{22} &amp; a_{23} \\\\\n a_{30} &amp; a_{31} &amp; a_{32} &amp; a_{33} \\\\\n\\end{bmatrix}\n$$</p>\n<p>will have the following ket-bra representation:\n$$A =$$\n$$=a_{00} \\ket{00}\\bra{00} + a_{01} \\ket{00}\\bra{01} + a_{02} \\ket{00}\\bra{10} + a_{03} \\ket{00}\\bra{11} +$$\n$$+a_{10} \\ket{01}\\bra{00} + a_{11} \\ket{01}\\bra{01} + a_{12} \\ket{01}\\bra{10} + a_{13} \\ket{01}\\bra{11} +$$\n$$+a_{20} \\ket{10}\\bra{00} + a_{21} \\ket{10}\\bra{01} + a_{22} \\ket{10}\\bra{10} + a_{23} \\ket{10}\\bra{11} +$$\n$$+a_{30} \\ket{11}\\bra{00} + a_{31} \\ket{11}\\bra{01} + a_{32} \\ket{11}\\bra{10} + a_{33} \\ket{11}\\bra{11}$$</p>\n<p>A similar expression can be extended for matrices that describe $N$-qubit gates, where $N &gt; 2$:</p>\n<p>$$A = \\sum_{i=0}^{2^N-1} \\sum_{j=0}^{2^N-1} a_{ij} \\ket{i}\\bra{ j}$$</p>\n<p>Dirac notation is particularly useful for expressing sparse matrices - matrices that have few non-zero elements. Indeed, consider the $CNOT$ gate again: it is a $4 \\times 4$ matrix described with 16 elements, but its Dirac notation has only 4 terms, one for each non-zero element of the matrix.</p>\n<p>With enough practice you'll be able to perform computations in Dirac notation without spelling out all the bra-ket terms explicitly!</p>\n"
2113
+ "content": "<p>Same as in the case of single-qubit gates, you can represent multi-qubit gates using Dirac notation.</p>\n<blockquote>\n<p>Recall that kets represent column vectors and bras represent row vectors. For any ket $\\ket{\\psi}$, the corresponding bra is its adjoint (conjugate transpose): $\\bra{\\psi} = \\ket{\\psi}^\\dagger$.</p>\n<p>Kets and bras are used to express inner and outer products. The inner product of $\\ket{\\phi}$ and $\\ket{\\psi}$ is the matrix product of $\\bra{\\phi}$ and $\\ket{\\psi}$, denoted as $\\braket{\\phi|\\psi}$, and their outer product is the matrix product of $\\ket{\\phi}$ and $\\bra{\\psi}$, denoted as $\\ket{\\phi}\\bra{\\psi}$.</p>\n<p>As you've seen in the Single-Qubit Gates kata, kets and bras can be used to represent matrices. The outer product of two vectors of the same size produces a square matrix. You can use a linear combination of several outer products of simple vectors (such as basis vectors) to express any square matrix.</p>\n</blockquote>\n<p>Let's consider ket-bra representation of the $CNOT$ gate:</p>\n<p>$$CNOT =$$\n$$= \\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\ket{10}\\bra{11} + \\ket{11}\\bra{10} =$$\n$$=\n\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 1 &amp; 0 &amp; 0 &amp; 0 \\end{bmatrix} +\n\\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 &amp; 1 &amp; 0 &amp; 0 \\end{bmatrix} +\n\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 &amp; 0 &amp; 0 &amp; 1 \\end{bmatrix} +\n\\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\\begin{bmatrix} 0 &amp; 0 &amp; 1 &amp; 0 \\end{bmatrix} =\n$$\n$$=\n\\begin{bmatrix} 1 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\end{bmatrix} +\n\\begin{bmatrix} 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 1 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\end{bmatrix} +\n\\begin{bmatrix} 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 1 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\end{bmatrix} +\n\\begin{bmatrix} 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 1 &amp; 0 \\end{bmatrix} =\n$$\n$$=\\begin{bmatrix} 1 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 1 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 1 \\\\ 0 &amp; 0 &amp; 1 &amp; 0 \\\\ \\end{bmatrix}$$</p>\n<p>This representation can be used to carry out calculations in Dirac notation without ever switching back to matrix representation:</p>\n<p>$$\nCNOT\\ket{10} =\n\\big(\\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\ket{10}\\bra{11} + \\ket{11}\\bra{10}\\big)\\ket{10} =$$\n$$=\\ket{00}\\braket{00|10} + \\ket{01}\\braket{01|10} + \\ket{10}\\braket{11|10} + \\ket{11}\\braket{10|10} =$$\n$$=\\ket{00}\\big(\\braket{00|10}\\big) + \\ket{01}\\big(\\braket{01|10}\\big) + \\ket{10}\\big(\\braket{11|10}\\big) + \\ket{11}\\big(\\braket{10|10}\\big) =$$\n$$=\\ket{00}(0) + \\ket{01}(0) + \\ket{10}(0) + \\ket{11}(1) = \\ket{11}$$</p>\n<blockquote>\n<p>Notice how a lot of the inner product terms turn out to equal 0, and the expression is easily simplified. The $CNOT$ gate is expressed in terms of the outer product of computational basis states, which are orthonormal, and is applied to another computational basis state, so the individual inner products will always be 0 or 1.</p>\n</blockquote>\n<p>In general case, a $4 \\times 4$ matrix that describes a 2-qubit gate\n$$A =\n\\begin{bmatrix}\n a_{00} &amp; a_{01} &amp; a_{02} &amp; a_{03} \\\\\n a_{10} &amp; a_{11} &amp; a_{12} &amp; a_{13} \\\\\n a_{20} &amp; a_{21} &amp; a_{22} &amp; a_{23} \\\\\n a_{30} &amp; a_{31} &amp; a_{32} &amp; a_{33} \\\\\n\\end{bmatrix}\n$$</p>\n<p>will have the following ket-bra representation:\n$$A =$$\n$$=a_{00} \\ket{00}\\bra{00} + a_{01} \\ket{00}\\bra{01} + a_{02} \\ket{00}\\bra{10} + a_{03} \\ket{00}\\bra{11} +$$\n$$+a_{10} \\ket{01}\\bra{00} + a_{11} \\ket{01}\\bra{01} + a_{12} \\ket{01}\\bra{10} + a_{13} \\ket{01}\\bra{11} +$$\n$$+a_{20} \\ket{10}\\bra{00} + a_{21} \\ket{10}\\bra{01} + a_{22} \\ket{10}\\bra{10} + a_{23} \\ket{10}\\bra{11} +$$\n$$+a_{30} \\ket{11}\\bra{00} + a_{31} \\ket{11}\\bra{01} + a_{32} \\ket{11}\\bra{10} + a_{33} \\ket{11}\\bra{11}$$</p>\n<p>A similar expression can be extended for matrices that describe $N$-qubit gates, where $N &gt; 2$:</p>\n<p>$$A = \\sum_{i=0}^{2^N-1} \\sum_{j=0}^{2^N-1} a_{ij} \\ket{i}\\bra{ j}$$</p>\n<p>Dirac notation is particularly useful for expressing sparse matrices - matrices that have few non-zero elements. Indeed, consider the $CNOT$ gate again: it's a $4 \\times 4$ matrix described with 16 elements, but its Dirac notation has only 4 terms, one for each non-zero element of the matrix.</p>\n<p>With enough practice you'll be able to perform computations in Dirac notation without spelling out all the bra-ket terms explicitly!</p>\n"
2114
2114
  }
2115
2115
  ]
2116
2116
  },
@@ -2121,7 +2121,7 @@ export default {
2121
2121
  "items": [
2122
2122
  {
2123
2123
  "type": "text-content",
2124
- "content": "<p>This section describes a more formal process of finding the ket-bra decompositions of multi-qubit quantum gates.\nThis section is not necessary to start working with quantum gates, so feel free to skip it for now, and come back to it later.</p>\n<p>You can use the properties of eigenvalues and eigenvectors to find the ket-bra decomposition of any gate. Consider an $N$-qubit gate $A$; the matrix representation of the gate is a square matrix of size $2^N$. Therefore it also has $2^N$ orthogonal eigenvectors $\\ket{\\psi_i}$</p>\n<p>$$A\\ket{\\psi_i} = x_i\\ket{\\psi_i}, 0 \\leq i \\leq 2^N -1$$</p>\n<p>Then its ket-bra decomposition is:</p>\n<p>$$A = \\sum_{i=0}^{2^N-1} x_i\\ket{\\psi_i}\\bra{\\psi_i}$$</p>\n<p>Let's use our $CNOT$ gate as a simple example.\nThe $CNOT$ gate has four eigenvectors.</p>\n<ul>\n<li>Two, as we can clearly see, are computational basis states $\\ket{00}$ and $\\ket{01}$ with eigenvalues $1$ and $1$, respectively (the basis states that are not affected by the gate).</li>\n<li>The other two are $\\ket{1} \\otimes \\ket{+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{10} + \\ket{11}\\big)$ and $\\ket{1} \\otimes \\ket{-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{10} - \\ket{11}\\big)$ with eigenvalues $1$ and $-1$, respectively:</li>\n</ul>\n<p>$$CNOT\\ket{00} = \\ket{00}$$\n$$CNOT\\ket{01} = \\ket{01}$$\n$$CNOT\\ket{1+} = \\ket{1+}$$\n$$CNOT\\ket{1-} = -\\ket{1-}$$</p>\n<p>Here's what the decomposition looks like:</p>\n<p>$$CNOT =$$\n$$=\\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\ket{1+}\\bra{1+} - \\ket{1-}\\bra{1-} =$$\n$$=\\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\frac{1}{2}\\big[\\big(\\ket{10} + \\ket{11}\\big)\\big(\\bra{10} + \\bra{11}\\big) - \\big(\\ket{10} - \\ket{11}\\big)\\big(\\bra{10} - \\bra{11}\\big)\\big] =$$\n$$=\\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\frac{1}{2}\\big(\\ket{10}\\bra{10} + \\ket{10}\\bra{11} + \\ket{11}\\bra{10} + \\ket{11}\\bra{11} - \\ket{10}\\bra{10} + \\ket{10}\\bra{11} + \\ket{11}\\bra{10} - \\ket{11}\\bra{11}\\big) =$$\n$$=\\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\frac{1}{2}\\big(2\\ket{10}\\bra{11} + 2\\ket{11}\\bra{10}\\big) =$$\n$$=\\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\ket{10}\\bra{11} + \\ket{11}\\bra{10}$$</p>\n"
2124
+ "content": "<p>This section describes a more formal process of finding the ket-bra decompositions of multi-qubit quantum gates.\nThis section isn't necessary to start working with quantum gates, so feel free to skip it for now, and come back to it later.</p>\n<p>You can use the properties of eigenvalues and eigenvectors to find the ket-bra decomposition of any gate. Consider an $N$-qubit gate $A$; the matrix representation of the gate is a square matrix of size $2^N$. Therefore it also has $2^N$ orthogonal eigenvectors $\\ket{\\psi_i}$</p>\n<p>$$A\\ket{\\psi_i} = x_i\\ket{\\psi_i}, 0 \\leq i \\leq 2^N -1$$</p>\n<p>Then its ket-bra decomposition is:</p>\n<p>$$A = \\sum_{i=0}^{2^N-1} x_i\\ket{\\psi_i}\\bra{\\psi_i}$$</p>\n<p>Let's use our $CNOT$ gate as a simple example.\nThe $CNOT$ gate has four eigenvectors.</p>\n<ul>\n<li>Two, as you can clearly see, are computational basis states $\\ket{00}$ and $\\ket{01}$ with eigenvalues $1$ and $1$, respectively (the basis states that aren't affected by the gate).</li>\n<li>The other two are $\\ket{1} \\otimes \\ket{+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{10} + \\ket{11}\\big)$ and $\\ket{1} \\otimes \\ket{-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{10} - \\ket{11}\\big)$ with eigenvalues $1$ and $-1$, respectively:</li>\n</ul>\n<p>$$CNOT\\ket{00} = \\ket{00}$$\n$$CNOT\\ket{01} = \\ket{01}$$\n$$CNOT\\ket{1+} = \\ket{1+}$$\n$$CNOT\\ket{1-} = -\\ket{1-}$$</p>\n<p>Here's what the decomposition looks like:</p>\n<p>$$CNOT =$$\n$$=\\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\ket{1+}\\bra{1+} - \\ket{1-}\\bra{1-} =$$\n$$=\\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\frac{1}{2}\\big[\\big(\\ket{10} + \\ket{11}\\big)\\big(\\bra{10} + \\bra{11}\\big) - \\big(\\ket{10} - \\ket{11}\\big)\\big(\\bra{10} - \\bra{11}\\big)\\big] =$$\n$$=\\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\frac{1}{2}\\big(\\ket{10}\\bra{10} + \\ket{10}\\bra{11} + \\ket{11}\\bra{10} + \\ket{11}\\bra{11} - \\ket{10}\\bra{10} + \\ket{10}\\bra{11} + \\ket{11}\\bra{10} - \\ket{11}\\bra{11}\\big) =$$\n$$=\\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\frac{1}{2}\\big(2\\ket{10}\\bra{11} + 2\\ket{11}\\bra{10}\\big) =$$\n$$=\\ket{00}\\bra{00} + \\ket{01}\\bra{01} + \\ket{10}\\bra{11} + \\ket{11}\\bra{10}$$</p>\n"
2125
2125
  }
2126
2126
  ]
2127
2127
  },
@@ -2154,7 +2154,7 @@ export default {
2154
2154
  "items": [
2155
2155
  {
2156
2156
  "type": "text-content",
2157
- "content": "<p>The $SWAP$ gate allows us to swap the state of any two qubits. In this exercise you need to apply it to two qubits given by their indices in an array of qubits; you can access individual qubits of the array as <code>qs[index of a qubit]</code>.</p>\n"
2157
+ "content": "<p>The $SWAP$ gate allows you to swap the state of any two qubits. In this exercise, you need to apply it to two qubits given by their indices in an array of qubits; you can access individual qubits of the array as <code>qs[index of a qubit]</code>.</p>\n"
2158
2158
  },
2159
2159
  {
2160
2160
  "type": "solution",
@@ -2171,7 +2171,7 @@ export default {
2171
2171
  "items": [
2172
2172
  {
2173
2173
  "type": "text-content",
2174
- "content": "<p>In the above examples the $CNOT$ gate acted on two adjacent qubits. However, multi-qubit gates can act on non-adjacent qubits as well. Let's see how to work out the math of the system state change in this case.</p>\n<p>Take 3 qubits in an arbitrary state $\\ket{\\psi} = x_{000} \\ket{000} + x_{001}\\ket{001} + x_{010}\\ket{010} + x_{011}\\ket{011} + x_{100}\\ket{100} + x_{101}\\ket{101} + x_{110}\\ket{110} + x_{111}\\ket{111} $.</p>\n<p>We can apply the $CNOT$ gate on 1st and 3rd qubits, with the 1st qubit as control and the 3rd qubit as target. Let's label the 3-qubit gate that describes the effect of this on the whole system as $CINOT$. The $CINOT$ ignores the 2nd qubit (leaves it unchanged) and applies the $CNOT$ gate as specified above.</p>\n<h2>Q#</h2>\n<p>In Q# we describe the operation as the sequence of gates that are applied to the qubits, regardless of whether the qubits are adjacent or not.</p>\n<pre><code class=\"language-qsharp\">operation CINOT (qs: Qubit[]) : Unit {\n CNOT(qs[0], qs[2]); // Length of qs is assumed to be 3\n}\n</code></pre>\n<h2>Dirac Notation</h2>\n<p>In Dirac notation we can consider the effect of the gate on each basis vector separately: each basis vector $\\ket{a_1a_2a_3}$ remains unchanged if $a_1 = 0$, and becomes $\\ket{a_1a_2(\\neg a_3)}$ if $a_1 = 1$. The full effect on the state becomes:</p>\n<p>$$CINOT\\ket{\\psi} = x_{000} CINOT\\ket{000} + x_{001} CINOT\\ket{001} + x_{010} CINOT\\ket{010} + x_{011} CINOT\\ket{011}+$$\n$$+x_{100} CINOT\\ket{100} + x_{101} CINOT\\ket{101} + x_{110} CINOT\\ket{110} + x_{111} CINOT\\ket{111} =$$\n$$= x_{000}\\ket{000} + x_{001}\\ket{001} + x_{010}\\ket{010} + x_{011}\\ket{011} + x_{101}\\ket{100} + x_{100}\\ket{101} + x_{111}\\ket{110} + x_{110}\\ket{111} $$</p>\n<h2>Matrix Form</h2>\n<p>$CINOT$ can also be represented in matrix form as a $2^3 \\times 2^3$ matrix:\n$$\n\\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0\n\\end{bmatrix}\n$$</p>\n<p>Applying $CINOT$ to $\\ket{\\psi}$ gives us\n$$\nCINOT \\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0\n\\end{bmatrix}\n\\begin{bmatrix}\n x_{000} \\\\ x_{001} \\\\ x_{010} \\\\ x_{011} \\\\ x_{100} \\\\ x_{101} \\\\ x_{110} \\\\ x_{111}\n\\end{bmatrix} =\n\\begin{bmatrix}\n x_{000} \\\\ x_{001} \\\\ x_{010} \\\\ x_{011} \\\\ x_{101} \\\\ x_{100} \\\\ x_{111} \\\\ x_{110}\n\\end{bmatrix}\n$$</p>\n<p>However, as $N$ gets larger, creating a full size matrix can be extremely unwieldy. To express the matrix without spelling out its elements, we can use the following trick:</p>\n<ol>\n<li>Apply the $SWAP$ gate on the 1st and 2nd qubits.\nThis will bring the qubits on which the $CNOT$ gate acts next to each other, without any extra qubits between them.</li>\n<li>Apply the $CNOT$ on 2nd and 3rd qubits.\nSince now the gate acts on adjacent qubits, this can be represented as a tensor product of the gate we're applying and <code>I</code> gates.</li>\n<li>Apply the $SWAP$ gate on the 1st and 2nd qubits again.</li>\n</ol>\n<p>These can be represented as applying the following gates on the 3 qubits.</p>\n<ol>\n<li>$\\text{SWAP} \\otimes I$</li>\n</ol>\n<p>$$\nx_{000}\\ket{000} + x_{001}\\ket{001} + x_{100}\\ket{010} + x_{101}\\ket{011} +\nx_{010}\\ket{100} + x_{011}\\ket{101} + x_{110}\\ket{110} + x_{111}\\ket{111}\n$$</p>\n<ol start=\"2\">\n<li>$I \\otimes CNOT$</li>\n</ol>\n<p>$$\nx_{000}\\ket{000} + x_{001}\\ket{001} + x_{101}\\ket{010} + x_{100}\\ket{011} +\nx_{010}\\ket{100} + x_{011}\\ket{101} + x_{111}\\ket{110} + x_{110}\\ket{111}\n$$</p>\n<ol start=\"3\">\n<li>$\\text{SWAP} \\otimes I$</li>\n</ol>\n<p>$$\nx_{000}\\ket{000} + x_{001}\\ket{001} + x_{010}\\ket{010} + x_{011}\\ket{011} +\nx_{101}\\ket{100} + x_{100}\\ket{101} + x_{111}\\ket{110} + x_{110}\\ket{111}\n$$</p>\n<p>The result is the $CINOT$ gate as we intended; so we can write</p>\n<p>$$CINOT = (SWAP \\otimes I)(I \\otimes CNOT)(SWAP \\otimes I)$$</p>\n<blockquote>\n<p>Note that in matrix notation we always apply a gate to the complete system, so we must apply $SWAP \\otimes I$, spelling the identity gate explicitly.\nHowever, when implementing the unitary $SWAP \\otimes I$ in Q#, we need only to call <code>SWAP(qs[0], qs[1])</code> - the remaining qubit <code>qs[2]</code> will not change, which is equivalent to applying an implicit identity gate.</p>\n<p>We can also spell out all gates applied explicitly (this makes for a much longer code, though):</p>\n<pre><code class=\"language-qsharp\">operation CINOT (qs: Qubit[]) : Unit {\n // First step\n SWAP(qs[0], qs[1]);\n I(qs[2]);\n // Second step\n I(qs[0]);\n CNOT(qs[1], qs[2]);\n // Third step\n SWAP(qs[0], qs[1]);\n I(qs[2]);\n}\n</code></pre>\n</blockquote>\n"
2174
+ "content": "<p>In the above examples, the $CNOT$ gate acted on two adjacent qubits. However, multi-qubit gates can act on non-adjacent qubits as well. Let's see how to work out the math of the system state change in this case.</p>\n<p>Take 3 qubits in an arbitrary state $\\ket{\\psi} = x_{000} \\ket{000} + x_{001}\\ket{001} + x_{010}\\ket{010} + x_{011}\\ket{011} + x_{100}\\ket{100} + x_{101}\\ket{101} + x_{110}\\ket{110} + x_{111}\\ket{111} $.</p>\n<p>You can apply the $CNOT$ gate on 1st and 3rd qubits, with the 1st qubit as control and the 3rd qubit as target. Let's label the 3-qubit gate that describes the effect of this on the whole system as $CINOT$. The $CINOT$ ignores the 2nd qubit (leaves it unchanged) and applies the $CNOT$ gate as specified above.</p>\n<h2>Q#</h2>\n<p>In Q#, the operation is described as the sequence of gates that are applied to the qubits, regardless of whether the qubits are adjacent or not.</p>\n<pre><code class=\"language-qsharp\">operation CINOT (qs: Qubit[]) : Unit {\n CNOT(qs[0], qs[2]); // Length of qs is assumed to be 3\n}\n</code></pre>\n<h2>Dirac Notation</h2>\n<p>In Dirac notation, you can consider the effect of the gate on each basis vector separately: each basis vector $\\ket{a_1a_2a_3}$ remains unchanged if $a_1 = 0$, and becomes $\\ket{a_1a_2(\\neg a_3)}$ if $a_1 = 1$. The full effect on the state becomes:</p>\n<p>$$CINOT\\ket{\\psi} = x_{000} CINOT\\ket{000} + x_{001} CINOT\\ket{001} + x_{010} CINOT\\ket{010} + x_{011} CINOT\\ket{011}+$$\n$$+x_{100} CINOT\\ket{100} + x_{101} CINOT\\ket{101} + x_{110} CINOT\\ket{110} + x_{111} CINOT\\ket{111} =$$\n$$= x_{000}\\ket{000} + x_{001}\\ket{001} + x_{010}\\ket{010} + x_{011}\\ket{011} + x_{101}\\ket{100} + x_{100}\\ket{101} + x_{111}\\ket{110} + x_{110}\\ket{111} $$</p>\n<h2>Matrix Form</h2>\n<p>$CINOT$ can also be represented in matrix form as a $2^3 \\times 2^3$ matrix:\n$$\n\\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0\n\\end{bmatrix}\n$$</p>\n<p>Applying $CINOT$ to $\\ket{\\psi}$ gives us\n$$\nCINOT \\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0\n\\end{bmatrix}\n\\begin{bmatrix}\n x_{000} \\\\ x_{001} \\\\ x_{010} \\\\ x_{011} \\\\ x_{100} \\\\ x_{101} \\\\ x_{110} \\\\ x_{111}\n\\end{bmatrix} =\n\\begin{bmatrix}\n x_{000} \\\\ x_{001} \\\\ x_{010} \\\\ x_{011} \\\\ x_{101} \\\\ x_{100} \\\\ x_{111} \\\\ x_{110}\n\\end{bmatrix}\n$$</p>\n<p>However, as $N$ gets larger, creating a full size matrix can be extremely unwieldy. To express the matrix without spelling out its elements, you can use the following trick:</p>\n<ol>\n<li>Apply the $SWAP$ gate on the 1st and 2nd qubits.\nThis will bring the qubits on which the $CNOT$ gate acts next to each other, without any extra qubits between them.</li>\n<li>Apply the $CNOT$ on 2nd and 3rd qubits.\nSince now the gate acts on adjacent qubits, this can be represented as a tensor product of the gate you're applying and $I$ gates.</li>\n<li>Apply the $SWAP$ gate on the 1st and 2nd qubits again.</li>\n</ol>\n<p>These can be represented as applying the following gates on the 3 qubits.</p>\n<ol>\n<li>$\\text{SWAP} \\otimes I$</li>\n</ol>\n<p>$$\nx_{000}\\ket{000} + x_{001}\\ket{001} + x_{100}\\ket{010} + x_{101}\\ket{011} +\nx_{010}\\ket{100} + x_{011}\\ket{101} + x_{110}\\ket{110} + x_{111}\\ket{111}\n$$</p>\n<ol start=\"2\">\n<li>$I \\otimes CNOT$</li>\n</ol>\n<p>$$\nx_{000}\\ket{000} + x_{001}\\ket{001} + x_{101}\\ket{010} + x_{100}\\ket{011} +\nx_{010}\\ket{100} + x_{011}\\ket{101} + x_{111}\\ket{110} + x_{110}\\ket{111}\n$$</p>\n<ol start=\"3\">\n<li>$\\text{SWAP} \\otimes I$</li>\n</ol>\n<p>$$\nx_{000}\\ket{000} + x_{001}\\ket{001} + x_{010}\\ket{010} + x_{011}\\ket{011} +\nx_{101}\\ket{100} + x_{100}\\ket{101} + x_{111}\\ket{110} + x_{110}\\ket{111}\n$$</p>\n<p>The result is the $CINOT$ gate as you intended; so you can write</p>\n<p>$$CINOT = (SWAP \\otimes I)(I \\otimes CNOT)(SWAP \\otimes I)$$</p>\n<blockquote>\n<p>Note that in matrix notation you always apply a gate to the complete system, so you must apply $SWAP \\otimes I$, spelling the identity gate explicitly.\nHowever, when implementing the unitary $SWAP \\otimes I$ in Q#, you need only to call <code>SWAP(qs[0], qs[1])</code> - the remaining qubit <code>qs[2]</code> won't change, which is equivalent to applying an implicit identity gate.</p>\n<p>You can also spell out all gates applied explicitly (this makes for a much longer code, though):</p>\n<pre><code class=\"language-qsharp\">operation CINOT (qs: Qubit[]) : Unit {\n // First step\n SWAP(qs[0], qs[1]);\n I(qs[2]);\n // Second step\n I(qs[0]);\n CNOT(qs[1], qs[2]);\n // Third step\n SWAP(qs[0], qs[1]);\n I(qs[2]);\n}\n</code></pre>\n</blockquote>\n"
2175
2175
  }
2176
2176
  ]
2177
2177
  },
@@ -2182,7 +2182,7 @@ export default {
2182
2182
  "items": [
2183
2183
  {
2184
2184
  "type": "text-content",
2185
- "content": "<p><strong>Controlled gates</strong> are a class of gates derived from other gates as follows: they act on a control qubit and a target qubit, just like the $CNOT$ gate.\nA controlled-$U$ gate applies the $U$ gate to the target qubit if the control qubit is in state $\\ket{1}$, and does nothing otherwise.</p>\n<p>Given a gate $U = \\begin{bmatrix} \\alpha &amp; \\beta \\\\ \\gamma &amp; \\delta \\end{bmatrix}$, its controlled version looks like this:</p>\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Q# Documentation</th>\n </tr>\n <tr>\n <td>$\\text{Controlled }U$</td>\n <td>\n $$\n \\begin{bmatrix}\n 1 & 0 & 0 & 0 \\\\ \n 0 & 1 & 0 & 0 \\\\ \n 0 & 0 & \\alpha & \\beta \\\\ \n 0 & 0 & \\gamma & \\delta\n \\end{bmatrix}\n $$\n </td>\n <td><a href=\"https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/functorapplication#controlled-functor\" target=\"_blank\">Controlled functor</a></td>\n </tr>\n</table>\n<blockquote>\n<p>The $CNOT$ gate is en example of a controlled gate, which is why it is also known as the controlled $NOT$ or controlled $X$ gate.</p>\n</blockquote>\n<p>The concept of controlled gates can be generalized beyond controlling single-qubit gates.\nFor any multi-qubit gate, its controlled version will have an identity matrix in the top left quadrant, the gate itself in the bottom right, and $0$ everywhere else.\nHere, for example, is the Controlled $SWAP$, or <strong>Fredkin gate</strong>:</p>\n<p>$$\n\\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1\n\\end{bmatrix}\n$$</p>\n<p>In Q#, controlled gates are applied using the <a href=\"https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/functorapplication#controlled-functor\" target=\"_blank\"><code>Controlled</code></a> functor.\nThe controlled version of a gate accepts an array of control qubits (in this case an array of a single qubit), followed by the arguments to the original gate.\nFor example, these two lines are equivalent:</p>\n<pre><code class=\"language-qsharp\">Controlled X([control], target);\nCNOT(control, target);\n</code></pre>\n<p>If the original gate was implemented as an operation with multiple parameters, the controlled version of this gate will take those parameters as a tuple. For example, to apply Fredkin gate, you'd have to call:</p>\n<pre><code class=\"language-qsharp\">Controlled SWAP([control], (q1, q2));\n</code></pre>\n<p>You can use the controlled version of a Q# operation only if that operation has a controlled version defined.\nThe Q# compiler will often be able to generate a controlled version of the operation automatically if you put <code>is Ctl</code> after the operation's return type.\nIn other cases, you'll need to define the controlled version of an operation manually.</p>\n"
2185
+ "content": "<p><strong>Controlled gates</strong> are a class of gates derived from other gates as follows: they act on a control qubit and a target qubit, just like the $CNOT$ gate.\nA controlled-$U$ gate applies the $U$ gate to the target qubit if the control qubit is in state $\\ket{1}$, and does nothing otherwise.</p>\n<p>Given a gate $U = \\begin{bmatrix} \\alpha &amp; \\beta \\\\ \\gamma &amp; \\delta \\end{bmatrix}$, its controlled version looks like this:</p>\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Q# Documentation</th>\n </tr>\n <tr>\n <td>$\\text{Controlled }U$</td>\n <td>\n $$\n \\begin{bmatrix}\n 1 & 0 & 0 & 0 \\\\ \n 0 & 1 & 0 & 0 \\\\ \n 0 & 0 & \\alpha & \\beta \\\\ \n 0 & 0 & \\gamma & \\delta\n \\end{bmatrix}\n $$\n </td>\n <td><a href=\"https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/functorapplication#controlled-functor\" target=\"_blank\">Controlled functor</a></td>\n </tr>\n</table>\n<blockquote>\n<p>The $CNOT$ gate is en example of a controlled gate, which is why it's also known as the controlled $NOT$ or controlled $X$ gate.</p>\n</blockquote>\n<p>The concept of controlled gates can be generalized beyond controlling single-qubit gates.\nFor any multi-qubit gate, its controlled version will have an identity matrix in the top left quadrant, the gate itself in the bottom right, and $0$ everywhere else.\nHere, for example, is the Controlled $SWAP$, or <strong>Fredkin gate</strong>:</p>\n<p>$$\n\\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1\n\\end{bmatrix}\n$$</p>\n<p>In Q#, controlled gates are applied using the <a href=\"https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/functorapplication#controlled-functor\" target=\"_blank\"><code>Controlled</code></a> functor.\nThe controlled version of a gate accepts an array of control qubits (in this case an array of a single qubit), followed by the arguments to the original gate.\nFor example, these two lines are equivalent:</p>\n<pre><code class=\"language-qsharp\">Controlled X([control], target);\nCNOT(control, target);\n</code></pre>\n<p>If the original gate was implemented as an operation with multiple parameters, the controlled version of this gate will take those parameters as a tuple. For example, to apply Fredkin gate, you'd have to call:</p>\n<pre><code class=\"language-qsharp\">Controlled SWAP([control], (q1, q2));\n</code></pre>\n<p>You can use the controlled version of a Q# operation only if that operation has a controlled version defined.\nThe Q# compiler will often be able to generate a controlled version of the operation automatically if you put <code>is Ctl</code> after the operation's return type.\nIn other cases, you'll need to define the controlled version of an operation manually.</p>\n"
2186
2186
  }
2187
2187
  ]
2188
2188
  },
@@ -2192,7 +2192,7 @@ export default {
2192
2192
  "title": "Fredkin Gate",
2193
2193
  "description": {
2194
2194
  "type": "text-content",
2195
- "content": "<p><strong>Input:</strong> Three qubits (stored in an array of length 3) in an arbitrary three-qubit state\n$\\alpha \\ket{000} + \\beta \\ket{001} + \\gamma \\ket{010} + \\delta \\ket{011} + \\epsilon \\ket{100} + {\\color{blue}\\zeta}\\ket{101} + {\\color{blue}\\eta}\\ket{110} + \\theta\\ket{111}$.</p>\n<p><strong>Goal:</strong> Swap the states of second and third qubit if and only if the state of the first qubit is $\\ket{1}$, i.e., change the three-qubit state to $\\alpha \\ket{000} + \\beta \\ket{001} + \\gamma \\ket{010} + \\delta \\ket{011} + \\epsilon \\ket{100} + {\\color{red}\\eta}\\ket{101} + {\\color{red}\\zeta}\\ket{110} + \\theta\\ket{111}$.</p>\n"
2195
+ "content": "<p><strong>Input:</strong> Three qubits (stored in an array of length 3) in an arbitrary three-qubit state\n$\\alpha \\ket{000} + \\beta \\ket{001} + \\gamma \\ket{010} + \\delta \\ket{011} + \\epsilon \\ket{100} + {\\color{blue}\\zeta}\\ket{101} + {\\color{blue}\\eta}\\ket{110} + \\theta\\ket{111}$.</p>\n<p><strong>Goal:</strong> Swap the states of second and third qubit if and only if the state of the first qubit is $\\ket{1}$, that is, change the three-qubit state to $\\alpha \\ket{000} + \\beta \\ket{001} + \\gamma \\ket{010} + \\delta \\ket{011} + \\epsilon \\ket{100} + {\\color{red}\\eta}\\ket{101} + {\\color{red}\\zeta}\\ket{110} + \\theta\\ket{111}$.</p>\n"
2196
2196
  },
2197
2197
  "sourceIds": [
2198
2198
  "multi_qubit_gates__fredkin_gate__Verification.qs",
@@ -2204,7 +2204,7 @@ export default {
2204
2204
  "items": [
2205
2205
  {
2206
2206
  "type": "text-content",
2207
- "content": "<p>This is essentially bookwork, because there is only one gate that performs this state change (and the task title already gave it away!)\nThe Fredkin gate is also known as the controlled $SWAP$ gate:\n$$\n\\begin{bmatrix}\n1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1\n\\end{bmatrix}\n$$\nand our initial state is:\n$$\n\\begin{bmatrix}\n\\alpha \\\\ \\beta \\\\ \\gamma \\\\ \\delta \\\\ \\epsilon \\\\ \\zeta \\\\ \\eta \\\\ \\theta\n\\end{bmatrix}\n$$\nSo we have:\n$$\n\\begin{bmatrix}\n1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1\n\\end{bmatrix}\n\\begin{bmatrix}\n\\alpha \\\\ \\beta \\\\ \\gamma \\\\ \\delta \\\\ \\epsilon \\\\ \\color{blue}\\zeta \\\\ \\color{blue}\\eta \\\\ \\theta\n\\end{bmatrix} =\n\\begin{bmatrix}\n\\alpha \\\\ \\beta \\\\ \\gamma \\\\ \\delta \\\\ \\epsilon \\\\ \\color{red}\\eta \\\\ \\color{red}\\zeta \\\\ \\theta\n\\end{bmatrix} =\n\\alpha \\ket{000} + \\beta \\ket{001} + \\gamma \\ket{010} + \\delta \\ket{011} + \\epsilon \\ket{100} + {\\color{red}\\eta}\\ket{101} + {\\color{red}\\zeta}\\ket{110} + \\theta\\ket{111}\n$$</p>\n<p>Notice carefully how the qubits are passed to the gate: <code>[qs[0]], (qs[1], [qs[2])</code>. The <code>Controlled</code> functor produces an operation that takes two parameters: the first one is an array of control qubits (in this case a single-element array consisting of the first qubit), and the second parameter is a tuple of all parameters you'd pass to the original gate (in this gate two individual qubit parameters that would be arguments to a $SWAP$ gate).</p>\n"
2207
+ "content": "<p>This is essentially bookwork, because there's only one gate that performs this state change (and the task title already gave it away!)\nThe Fredkin gate is also known as the controlled $SWAP$ gate:\n$$\n\\begin{bmatrix}\n1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1\n\\end{bmatrix}\n$$\nand the initial state is:\n$$\n\\begin{bmatrix}\n\\alpha \\\\ \\beta \\\\ \\gamma \\\\ \\delta \\\\ \\epsilon \\\\ \\zeta \\\\ \\eta \\\\ \\theta\n\\end{bmatrix}\n$$\nSo you have:\n$$\n\\begin{bmatrix}\n1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1\n\\end{bmatrix}\n\\begin{bmatrix}\n\\alpha \\\\ \\beta \\\\ \\gamma \\\\ \\delta \\\\ \\epsilon \\\\ \\color{blue}\\zeta \\\\ \\color{blue}\\eta \\\\ \\theta\n\\end{bmatrix} =\n\\begin{bmatrix}\n\\alpha \\\\ \\beta \\\\ \\gamma \\\\ \\delta \\\\ \\epsilon \\\\ \\color{red}\\eta \\\\ \\color{red}\\zeta \\\\ \\theta\n\\end{bmatrix} =\n\\alpha \\ket{000} + \\beta \\ket{001} + \\gamma \\ket{010} + \\delta \\ket{011} + \\epsilon \\ket{100} + {\\color{red}\\eta}\\ket{101} + {\\color{red}\\zeta}\\ket{110} + \\theta\\ket{111}\n$$</p>\n<p>Notice carefully how the qubits are passed to the gate: <code>[qs[0]], (qs[1], [qs[2])</code>. The <code>Controlled</code> functor produces an operation that takes two parameters: the first one is an array of control qubits (in this case a single-element array consisting of the first qubit), and the second parameter is a tuple of all parameters you'd pass to the original gate (in this gate two individual qubit parameters that would be arguments to a $SWAP$ gate).</p>\n"
2208
2208
  },
2209
2209
  {
2210
2210
  "type": "solution",
@@ -2232,7 +2232,7 @@ export default {
2232
2232
  "items": [
2233
2233
  {
2234
2234
  "type": "text-content",
2235
- "content": "<p>In Q# the <code>Rx</code> intrinsic gate takes the angle $\\theta$ and the target qubit as inputs. To create a controlled version of this gate, we can use the <code>Controlled</code> functor.</p>\n<p>A matrix representation of this operation would be:</p>\n<p>$$\n\\begin{bmatrix} 1 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 1 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; \\cos\\frac{\\theta}{2} &amp; -i\\sin\\frac{\\theta}{2} \\\\ 0 &amp; 0 &amp; -i\\sin\\frac{\\theta}{2} &amp; \\cos\\frac{\\theta}{2} \\end{bmatrix}\n$$</p>\n<p>The parameters of the new gate are changed a bit:</p>\n<ul>\n<li>The first parameter has to be the array of control qubits; the <code>Rx</code> gate will be applied to the target only if these are all in the $\\ket{1}$ state. Note that this parameter has to be an array, even if there is just one control qubit!</li>\n<li>The second parameter is a tuple with the parameters that you would've passed to the original <code>Rx</code> gate. You can create a tuple of values by putting round brackets around them.</li>\n</ul>\n<blockquote>\n<p>The <code>Controlled</code> functor can be used before any single-qubit gate to make it a controlled gate. The first argument will be an array of qubits even if you are using a single control qubit, like in the $CNOT$ gate. The second argument is a tuple <code>()</code> with the parameters of the gate. For example, these two gates are equivalent: <code>CNOT(qs[0], qs[1])</code> and <code>Controlled X([qs[0]], (qs[1]));</code></p>\n</blockquote>\n"
2235
+ "content": "<p>In Q#, the <code>Rx</code> intrinsic gate takes the angle $\\theta$ and the target qubit as inputs. To create a controlled version of this gate, you can use the <code>Controlled</code> functor.</p>\n<p>A matrix representation of this operation would be:</p>\n<p>$$\n\\begin{bmatrix} 1 &amp; 0 &amp; 0 &amp; 0 \\\\ 0 &amp; 1 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; \\cos\\frac{\\theta}{2} &amp; -i\\sin\\frac{\\theta}{2} \\\\ 0 &amp; 0 &amp; -i\\sin\\frac{\\theta}{2} &amp; \\cos\\frac{\\theta}{2} \\end{bmatrix}\n$$</p>\n<p>The parameters of the new gate are changed a bit:</p>\n<ul>\n<li>The first parameter has to be the array of control qubits; the <code>Rx</code> gate will be applied to the target only if these are all in the $\\ket{1}$ state. Note that this parameter has to be an array, even if there is just one control qubit!</li>\n<li>The second parameter is a tuple with the parameters that you would've passed to the original <code>Rx</code> gate. You can create a tuple of values by putting round brackets around them.</li>\n</ul>\n<blockquote>\n<p>The <code>Controlled</code> functor can be used before any single-qubit gate to make it a controlled gate. The first argument will be an array of qubits even if you're using a single control qubit, like in the $CNOT$ gate. The second argument is a tuple <code>()</code> with the parameters of the gate. For example, these two gates are equivalent: <code>CNOT(qs[0], qs[1])</code> and <code>Controlled X([qs[0]], (qs[1]));</code></p>\n</blockquote>\n"
2236
2236
  },
2237
2237
  {
2238
2238
  "type": "solution",
@@ -2259,7 +2259,7 @@ export default {
2259
2259
  "title": "Toffoli Gate",
2260
2260
  "description": {
2261
2261
  "type": "text-content",
2262
- "content": "<p><strong>Input:</strong> Three qubits (stored in an array of length 3) in an arbitrary three-qubit state\n$\\alpha \\ket{000} + \\beta \\ket{001} + \\gamma \\ket{010} + \\delta \\ket{011} + \\epsilon \\ket{100} + \\zeta\\ket{101} + {\\color{blue}\\eta}\\ket{110} + {\\color{blue}\\theta}\\ket{111}$.</p>\n<p><strong>Goal:</strong> Flip the state of the third qubit if the state of the first two is $\\ket{11}$, i.e., change the three-qubit state to $\\alpha \\ket{000} + \\beta \\ket{001} + \\gamma \\ket{010} + \\delta \\ket{011} + \\epsilon \\ket{100} + \\zeta\\ket{101} + {\\color{red}\\theta}\\ket{110} + {\\color{red}\\eta}\\ket{111}$.</p>\n"
2262
+ "content": "<p><strong>Input:</strong> Three qubits (stored in an array of length 3) in an arbitrary three-qubit state\n$\\alpha \\ket{000} + \\beta \\ket{001} + \\gamma \\ket{010} + \\delta \\ket{011} + \\epsilon \\ket{100} + \\zeta\\ket{101} + {\\color{blue}\\eta}\\ket{110} + {\\color{blue}\\theta}\\ket{111}$.</p>\n<p><strong>Goal:</strong> Flip the state of the third qubit if the state of the first two is $\\ket{11}$, that is, change the three-qubit state to $\\alpha \\ket{000} + \\beta \\ket{001} + \\gamma \\ket{010} + \\delta \\ket{011} + \\epsilon \\ket{100} + \\zeta\\ket{101} + {\\color{red}\\theta}\\ket{110} + {\\color{red}\\eta}\\ket{111}$.</p>\n"
2263
2263
  },
2264
2264
  "sourceIds": [
2265
2265
  "multi_qubit_gates__toffoli_gate__Verification.qs",
@@ -2271,7 +2271,7 @@ export default {
2271
2271
  "items": [
2272
2272
  {
2273
2273
  "type": "text-content",
2274
- "content": "<p>This is essentially bookwork, because there is only one gate that performs this state change (and the task title already gave it away!) The Toffoli gate is:\n$$\n \\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0\n \\end{bmatrix}\n$$\nand our initial state is:\n$$\n\\begin{bmatrix} \\alpha \\\\ \\beta \\\\ \\gamma \\\\ \\delta \\\\ \\epsilon \\\\ \\zeta \\\\ \\eta \\\\ \\theta\n\\end{bmatrix}\n$$</p>\n<p>So we have:</p>\n<p>$$\n \\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0\n \\end{bmatrix}\n \\begin{bmatrix}\n \\alpha \\\\ \\beta \\\\ \\gamma \\\\ \\delta \\\\ \\epsilon \\\\ \\zeta \\\\ \\color{blue}\\eta \\\\ \\color{blue}\\theta\n \\end{bmatrix}=\n \\begin{bmatrix}\n \\alpha \\\\ \\beta \\\\ \\gamma \\\\ \\delta \\\\ \\epsilon \\\\ \\zeta \\\\ \\color{red}\\theta \\\\ \\color{red}\\eta\n \\end{bmatrix}=\n\\alpha \\ket{000} + \\beta \\ket{001} + \\gamma \\ket{010} + \\delta \\ket{011} + \\epsilon \\ket{100} + \\zeta\\ket{101} + {\\color{red}\\theta}\\ket{110} + {\\color{red}\\eta}\\ket{111}\n$$</p>\n"
2274
+ "content": "<p>This is essentially bookwork, because there's only one gate that performs this state change (and the task title already gave it away!) The Toffoli gate is:\n$$\n \\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0\n \\end{bmatrix}\n$$\nand the initial state is:\n$$\n\\begin{bmatrix} \\alpha \\\\ \\beta \\\\ \\gamma \\\\ \\delta \\\\ \\epsilon \\\\ \\zeta \\\\ \\eta \\\\ \\theta\n\\end{bmatrix}\n$$</p>\n<p>So you have:</p>\n<p>$$\n \\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 \\\\\n 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0\n \\end{bmatrix}\n \\begin{bmatrix}\n \\alpha \\\\ \\beta \\\\ \\gamma \\\\ \\delta \\\\ \\epsilon \\\\ \\zeta \\\\ \\color{blue}\\eta \\\\ \\color{blue}\\theta\n \\end{bmatrix}=\n \\begin{bmatrix}\n \\alpha \\\\ \\beta \\\\ \\gamma \\\\ \\delta \\\\ \\epsilon \\\\ \\zeta \\\\ \\color{red}\\theta \\\\ \\color{red}\\eta\n \\end{bmatrix}=\n\\alpha \\ket{000} + \\beta \\ket{001} + \\gamma \\ket{010} + \\delta \\ket{011} + \\epsilon \\ket{100} + \\zeta\\ket{101} + {\\color{red}\\theta}\\ket{110} + {\\color{red}\\eta}\\ket{111}\n$$</p>\n"
2275
2275
  },
2276
2276
  {
2277
2277
  "type": "solution",
@@ -2288,7 +2288,7 @@ export default {
2288
2288
  "items": [
2289
2289
  {
2290
2290
  "type": "text-content",
2291
- "content": "<p>Typically, the term &quot;controlled $U$ gate&quot; refers to the type of gate we've described previously, which applies the gate $U$ only if the control qubit(s) are in the $\\ket{1}$ state.</p>\n<p>It is possible, however, to define variants of controlled gates that use different states as control states.\nFor example, an <strong>anti-controlled</strong> $U$ gate (sometimes called <strong>zero-controlled</strong>) applies a gate only if the control qubit is in the $\\ket{0}$ state.\nIt is also possible to define control conditions in other bases, for example, applying the gate if the control qubit is in the $\\ket{+}$ state.</p>\n<p>All the variants of controlled gates can be expressed in terms of the controls described in previous sections, using the following sequence of steps:</p>\n<ul>\n<li>First, apply a transformation on control qubits that will transform the state you want to use as control into the $\\ket{1...1}$ state.</li>\n<li>Apply the regular controlled version of the gate.</li>\n<li>Finally, undo the transformation on control qubits from the first step using the adjoint version of it.</li>\n</ul>\n<p>Why do we need this last step? Remember that controlled gates are defined in terms of their effect on the basis states:\nwe apply the gate on the target qubit if and only if the control qubit is in the state we want to control on, and we don't change the state of the control qubit at all.\nIf we don't undo the transformation we did on the first step, applying our gate to a basis state will modify not only the state of the target qubit but also the state of the control qubit, which is not what we're looking for.</p>\n<p>For example, consider an anti-controlled $X$ gate - a gate that should apply an $X$ gate to the second qubit if the first qubit is in the $\\ket{0}$ state.\nHere is the effect we expect this gate to have on each of the 2-qubit basis states:</p>\n<table>\n <tr>\n <th>Input state</th>\n <th>Output state</th>\n </tr>\n <tr>\n <td>$\\ket{00}$</td>\n <td>$\\ket{01}$</td>\n </tr>\n <tr>\n <td>$\\ket{01}$</td>\n <td>$\\ket{00}$</td>\n </tr>\n <tr>\n <td>$\\ket{10}$</td>\n <td>$\\ket{10}$</td>\n </tr>\n <tr>\n <td>$\\ket{11}$</td>\n <td>$\\ket{11}$</td>\n </tr>\n</table>\n<p>Let's apply the anti-controlled $X$ gate to the $\\ket{00}$ state step by step:</p>\n<ol>\n<li>Transform the state of the control qubit to $\\ket{1}$: we can do that by applying the $X$ gate to the first qubit:\n$$\\ket{00} \\rightarrow \\ket{10}$$</li>\n<li>Apply the regular $CNOT$ gate:\n$$\\ket{10} \\rightarrow \\ket{11}$$</li>\n<li>Now, if we don't undo the change we did on the first step, we'll end up with a gate that transforms $\\ket{00}$ into $\\ket{11}$, which is not the transformation we're trying to implement.\nHowever, if we undo it by applying the $X$ gate to the first qubit again, we'll get the correct state:\n$$\\ket{11} \\rightarrow \\ket{01}$$</li>\n</ol>\n<p>You can check that getting the right behavior of the operation on the rest of the basis states also requires that last step.</p>\n<p>Finally, let's take a look at a very useful operation <code>ApplyControlledOnBitString</code> provided by the Q# standard library.\nIt applies a variant of a gate controlled on a basis state specified by a bit mask; for example, bit mask <code>[true, false]</code> means that the gate should be applied only if the two control qubits are in the $\\ket{10}$ state.\nThis operation takes four arguments: the control bit mask as a Boolean array, the gate $U$ that needs its controlled variant defined, the array of control qubits, and the arguments to the $U$ gate (the target qubit(s) and any additional parameters it takes).</p>\n<p>The sequence of steps that implement this variant are:</p>\n<ol>\n<li>Apply the $X$ gate to each control qubit that corresponds to a <code>false</code> element of the bit mask (in the example, that's just the second qubit). After this, if the control qubits started in the $\\ket{10}$ state, they'll end up in the $\\ket{11}$ state, and if they started in any other state, they'll end up in any state but $\\ket{11}$.</li>\n<li>Apply the regular controlled version of the gate.</li>\n<li>Apply the $X$ gate to the same qubits to return them to their original state.</li>\n</ol>\n"
2291
+ "content": "<p>Typically, the term &quot;controlled $U$ gate&quot; refers to the type of gate you've seen previously, which applies the gate $U$ only if the control qubit(s) are in the $\\ket{1}$ state.</p>\n<p>It's possible, however, to define variants of controlled gates that use different states as control states.\nFor example, an <strong>anti-controlled</strong> $U$ gate (sometimes called <strong>zero-controlled</strong>) applies a gate only if the control qubit is in the $\\ket{0}$ state.\nIt's also possible to define control conditions in other bases, for example, applying the gate if the control qubit is in the $\\ket{+}$ state.</p>\n<p>All the variants of controlled gates can be expressed in terms of the controls described in previous sections, using the following sequence of steps:</p>\n<ul>\n<li>First, apply a transformation on control qubits that will transform the state you want to use as control into the $\\ket{1...1}$ state.</li>\n<li>Apply the regular controlled version of the gate.</li>\n<li>Finally, undo the transformation on control qubits from the first step using the adjoint version of it.</li>\n</ul>\n<p>Why do you need this last step? Remember that controlled gates are defined in terms of their effect on the basis states:\nyou apply the gate on the target qubit if and only if the control qubit is in the state you want to control on, and you don't change the state of the control qubit at all.\nIf you don't undo the transformation you did on the first step, applying your gate to a basis state will modify not only the state of the target qubit but also the state of the control qubit, which is not what you're looking for.</p>\n<p>For example, consider an anti-controlled $X$ gate - a gate that should apply an $X$ gate to the second qubit if the first qubit is in the $\\ket{0}$ state.\nHere is the effect you expect this gate to have on each of the 2-qubit basis states:</p>\n<table>\n <tr>\n <th>Input state</th>\n <th>Output state</th>\n </tr>\n <tr>\n <td>$\\ket{00}$</td>\n <td>$\\ket{01}$</td>\n </tr>\n <tr>\n <td>$\\ket{01}$</td>\n <td>$\\ket{00}$</td>\n </tr>\n <tr>\n <td>$\\ket{10}$</td>\n <td>$\\ket{10}$</td>\n </tr>\n <tr>\n <td>$\\ket{11}$</td>\n <td>$\\ket{11}$</td>\n </tr>\n</table>\n<p>Let's apply the anti-controlled $X$ gate to the $\\ket{00}$ state step by step:</p>\n<ol>\n<li>Transform the state of the control qubit to $\\ket{1}$: you can do that by applying the $X$ gate to the first qubit:\n$$\\ket{00} \\rightarrow \\ket{10}$$</li>\n<li>Apply the regular $CNOT$ gate:\n$$\\ket{10} \\rightarrow \\ket{11}$$</li>\n<li>Now, if you don't undo the change you did on the first step, you'll end up with a gate that transforms $\\ket{00}$ into $\\ket{11}$, which is not the transformation you're trying to implement.\nHowever, if you undo it by applying the $X$ gate to the first qubit again, you'll get the correct state:\n$$\\ket{11} \\rightarrow \\ket{01}$$</li>\n</ol>\n<p>You can check that getting the right behavior of the operation on the rest of the basis states also requires that last step.</p>\n<p>Finally, let's take a look at a very useful operation <code>ApplyControlledOnBitString</code> provided by the Q# standard library.\nIt applies a variant of a gate controlled on a basis state specified by a bit mask; for example, bit mask <code>[true, false]</code> means that the gate should be applied only if the two control qubits are in the $\\ket{10}$ state.\nThis operation takes four arguments: the control bit mask as a Boolean array, the gate $U$ that needs its controlled variant defined, the array of control qubits, and the arguments to the $U$ gate (the target qubit(s) and any additional parameters it takes).</p>\n<p>The sequence of steps that implement this variant are:</p>\n<ol>\n<li>Apply the $X$ gate to each control qubit that corresponds to a <code>false</code> element of the bit mask (in the example, that's just the second qubit). After this, if the control qubits started in the $\\ket{10}$ state, they'll end up in the $\\ket{11}$ state, and if they started in any other state, they'll end up in any state but $\\ket{11}$.</li>\n<li>Apply the regular controlled version of the gate.</li>\n<li>Apply the $X$ gate to the same qubits to return them to their original state.</li>\n</ol>\n"
2292
2292
  }
2293
2293
  ]
2294
2294
  },
@@ -2310,7 +2310,7 @@ export default {
2310
2310
  "items": [
2311
2311
  {
2312
2312
  "type": "text-content",
2313
- "content": "<p>In vector form the transformation we need is:</p>\n<p>$$\n\\begin{bmatrix}\\color{blue}\\alpha\\\\ \\color{blue}\\beta\\\\ \\gamma\\\\ \\delta \\end{bmatrix}\n\\rightarrow\n\\begin{bmatrix} \\color{red}\\beta\\\\ \\color{red}\\alpha\\\\ \\gamma\\\\ \\delta \\end{bmatrix}\n$$</p>\n<p>This can be represented by a matrix:\n$$\nU = \\begin{bmatrix}0 &amp; 1 &amp; 0 &amp; 0\\\\ 1 &amp; 0 &amp; 0 &amp; 0\\\\ 0 &amp; 0 &amp; 1 &amp; 0\\\\ 0 &amp; 0 &amp; 0 &amp; 1 \\end{bmatrix}\n$$</p>\n<p>We remember a two-qubit gate with a similar matrix representation - the $CNOT$ gate:</p>\n<p>$$\nCNOT = \n \\begin{bmatrix}1 &amp; 0 &amp; 0 &amp; 0\\\\ 0 &amp; 1 &amp; 0 &amp; 0\\\\ 0 &amp; 0 &amp; 0 &amp; 1\\\\ 0 &amp; 0 &amp; 1 &amp; 0 \\end{bmatrix}\n$$</p>\n<p>We need a way to transform the $CNOT$ gate into the unitary transformation represented by $U$.<br />\nWe remember that the Pauli X gate flips the state in the single-qubit case. Here we need to use a 2-qubit version of this gate, which would affect only the second qubit. We conclude, that the idenity gate needs to be used on the first qubit. In the end, the required gate is a tensor product: $I \\otimes X$.</p>\n<p>We validate that composition of $I \\otimes X$ and the $CNOT$ gate produces the required unitary transformation represented by $U$.</p>\n<p>$$\n (I \\otimes X)\\cdot CNOT = \n \\left(\n\\begin{bmatrix}1 &amp; 0 \\\\ 0 &amp; 1 \\end{bmatrix}\\otimes\n\\begin{bmatrix} 0 &amp; 1 \\\\ 1 &amp; 0 \\end{bmatrix}\n\\right) \\cdot\n\\begin{bmatrix}1 &amp; 0 &amp; 0 &amp; 0\\\\ 0 &amp; 1 &amp; 0 &amp; 0\\\\ 0 &amp; 0 &amp; 0 &amp; 1\\\\ 0 &amp; 0 &amp; 1 &amp; 0 \\end{bmatrix}=\n\\begin{bmatrix}0 &amp; 1 &amp; 0 &amp; 0\\\\ 1 &amp; 0 &amp; 0 &amp; 0\\\\ 0 &amp; 0 &amp; 0 &amp; 1\\\\ 0 &amp; 0 &amp; 1 &amp; 0 \\end{bmatrix}\n\\begin{bmatrix} 1 &amp; 0 &amp; 0 &amp; 0\\\\ 0 &amp; 1 &amp; 0 &amp; 0\\\\ 0 &amp; 0 &amp; 0 &amp; 1\\\\ 0 &amp; 0 &amp; 1 &amp; 0 \\end{bmatrix}=\n\\begin{bmatrix} 0 &amp; 1 &amp; 0 &amp; 0\\\\ 1 &amp; 0 &amp; 0 &amp; 0\\\\ 0 &amp; 0 &amp; 1 &amp; 0\\\\ 0 &amp; 0 &amp; 0 &amp; 1 \\end{bmatrix}=\nU\n$$</p>\n<blockquote>\n<p>Note that the order in which the gates $I \\otimes X$ and $CNOT$ are applied doesn't matter in this case.</p>\n</blockquote>\n"
2313
+ "content": "<p>In vector form, the transformation you need is:</p>\n<p>$$\n\\begin{bmatrix}\\color{blue}\\alpha\\\\ \\color{blue}\\beta\\\\ \\gamma\\\\ \\delta \\end{bmatrix}\n\\rightarrow\n\\begin{bmatrix} \\color{red}\\beta\\\\ \\color{red}\\alpha\\\\ \\gamma\\\\ \\delta \\end{bmatrix}\n$$</p>\n<p>This can be represented by a matrix:\n$$\nU = \\begin{bmatrix}0 &amp; 1 &amp; 0 &amp; 0\\\\ 1 &amp; 0 &amp; 0 &amp; 0\\\\ 0 &amp; 0 &amp; 1 &amp; 0\\\\ 0 &amp; 0 &amp; 0 &amp; 1 \\end{bmatrix}\n$$</p>\n<p>Remember a two-qubit gate with a similar matrix representation - the $CNOT$ gate:</p>\n<p>$$\nCNOT = \n \\begin{bmatrix}1 &amp; 0 &amp; 0 &amp; 0\\\\ 0 &amp; 1 &amp; 0 &amp; 0\\\\ 0 &amp; 0 &amp; 0 &amp; 1\\\\ 0 &amp; 0 &amp; 1 &amp; 0 \\end{bmatrix}\n$$</p>\n<p>You need a way to transform the $CNOT$ gate into the unitary transformation represented by $U$.<br />\nRemember that the Pauli X gate flips the state in the single-qubit case. Here you need to use a 2-qubit version of this gate, which would affect only the second qubit. You can conclude that the identity gate needs to be used on the first qubit. In the end, the required gate is a tensor product: $I \\otimes X$.</p>\n<p>You validate that composition of $I \\otimes X$ and the $CNOT$ gate produces the required unitary transformation represented by $U$.</p>\n<p>$$\n (I \\otimes X)\\cdot CNOT = \n \\left(\n\\begin{bmatrix}1 &amp; 0 \\\\ 0 &amp; 1 \\end{bmatrix}\\otimes\n\\begin{bmatrix} 0 &amp; 1 \\\\ 1 &amp; 0 \\end{bmatrix}\n\\right) \\cdot\n\\begin{bmatrix}1 &amp; 0 &amp; 0 &amp; 0\\\\ 0 &amp; 1 &amp; 0 &amp; 0\\\\ 0 &amp; 0 &amp; 0 &amp; 1\\\\ 0 &amp; 0 &amp; 1 &amp; 0 \\end{bmatrix}=\n\\begin{bmatrix}0 &amp; 1 &amp; 0 &amp; 0\\\\ 1 &amp; 0 &amp; 0 &amp; 0\\\\ 0 &amp; 0 &amp; 0 &amp; 1\\\\ 0 &amp; 0 &amp; 1 &amp; 0 \\end{bmatrix}\n\\begin{bmatrix} 1 &amp; 0 &amp; 0 &amp; 0\\\\ 0 &amp; 1 &amp; 0 &amp; 0\\\\ 0 &amp; 0 &amp; 0 &amp; 1\\\\ 0 &amp; 0 &amp; 1 &amp; 0 \\end{bmatrix}=\n\\begin{bmatrix} 0 &amp; 1 &amp; 0 &amp; 0\\\\ 1 &amp; 0 &amp; 0 &amp; 0\\\\ 0 &amp; 0 &amp; 1 &amp; 0\\\\ 0 &amp; 0 &amp; 0 &amp; 1 \\end{bmatrix}=\nU\n$$</p>\n<blockquote>\n<p>Note that the order in which the gates $I \\otimes X$ and $CNOT$ are applied doesn't matter in this case.</p>\n</blockquote>\n"
2314
2314
  },
2315
2315
  {
2316
2316
  "type": "solution",
@@ -2319,7 +2319,7 @@ export default {
2319
2319
  },
2320
2320
  {
2321
2321
  "type": "text-content",
2322
- "content": "<p>Alternatively, we can notice that the task requires application of a Pauli X gate on the second qubit when the first qubit is in the $\\ket{0}$ state. This can be achieved with <a href=\"https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.canon/applycontrolledonint\"><code>ApplyControlledOnInt</code></a> library operation.</p>\n<p>Notice that the <code>ApplyControlledOnInt</code> operation uses an array of qubits as control, not by a single qubit.</p>\n"
2322
+ "content": "<p>Alternatively, you can notice that the task requires application of a Pauli X gate on the second qubit when the first qubit is in the $\\ket{0}$ state. This can be achieved with <a href=\"https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.canon/applycontrolledonint\"><code>ApplyControlledOnInt</code></a> library operation.</p>\n<p>Notice that the <code>ApplyControlledOnInt</code> operation uses an array of qubits as control, not by a single qubit.</p>\n"
2323
2323
  },
2324
2324
  {
2325
2325
  "type": "solution",
@@ -2347,7 +2347,7 @@ export default {
2347
2347
  "items": [
2348
2348
  {
2349
2349
  "type": "text-content",
2350
- "content": "<p>We are asked to perform an $X$ gate on the <code>target</code> qubit controlled by the state of <code>controls</code> qubits; this state should correspond to the mask given by <code>controlBits</code>.</p>\n<p>If the <code>controlBits</code> mask consists of all <code>true</code> values, we can use a familiar <code>Controlled X</code> gate. What can we do if the mask has some <code>false</code> values in it?</p>\n<p>Turns out we can transform the state of the control qubits depending on the corresponding elements of <code>controlBits</code>: if the element is <code>false</code>, we apply an $X$ gate to the corresponding qubit in the <code>controls</code> array. After this, <code>Controlled X</code> gate will apply an $X$ gate in the exact case that we want.\nFinally, we'll need to remember to undo (&quot;uncompute&quot;) the first step, otherwise our controlled gate will affect the state of the control qubits as well as the state of the target.</p>\n<p>As you can see in the first cell below, this can take quite some coding.</p>\n"
2350
+ "content": "<p>You're asked to perform an $X$ gate on the <code>target</code> qubit controlled by the state of <code>controls</code> qubits; this state should correspond to the mask given by <code>controlBits</code>.</p>\n<p>If the <code>controlBits</code> mask consists of all <code>true</code> values, you can use a familiar <code>Controlled X</code> gate. What can you do if the mask has some <code>false</code> values in it?</p>\n<p>Turns out you can transform the state of the control qubits depending on the corresponding elements of <code>controlBits</code>: if the element is <code>false</code>, you apply an $X$ gate to the corresponding qubit in the <code>controls</code> array. After this, <code>Controlled X</code> gate will apply an $X$ gate in the exact case that you want.\nFinally, you'll need to remember to undo (&quot;uncompute&quot;) the first step, otherwise your controlled gate will affect the state of the control qubits as well as the state of the target.</p>\n<p>As you can see in the first cell below, this can take quite some coding.</p>\n"
2351
2351
  },
2352
2352
  {
2353
2353
  "type": "solution",
@@ -2356,7 +2356,7 @@ export default {
2356
2356
  },
2357
2357
  {
2358
2358
  "type": "text-content",
2359
- "content": "<p>We can shorten the code a bit using the <code>within ... apply</code> construct which takes care of uncomputing the steps done in the first code block automatically:</p>\n"
2359
+ "content": "<p>You can shorten the code a bit using the <code>within ... apply</code> construct which takes care of uncomputing the steps done in the first code block automatically:</p>\n"
2360
2360
  },
2361
2361
  {
2362
2362
  "type": "solution",
@@ -3379,7 +3379,7 @@ export default {
3379
3379
  "items": [
3380
3380
  {
3381
3381
  "type": "text-content",
3382
- "content": "<p>In the previous kata, we discussed the concept of measurements done on single-qubit systems.\nBuilding upon those ideas, this kata will introduce you to measurements done on multi-qubit systems, and how to implement such measurements in Q#.\nThis will include measuring a single qubit in a multi-qubit system, as well as measuring multiple qubits simultaneously.</p>\n<p><strong>This kata covers the following topics:</strong></p>\n<ul>\n<li>Measuring a single qubit in a multi-qubit system</li>\n<li>Measuring multiple qubits simultaneously</li>\n<li>Implementing different kinds of measurements in Q#</li>\n</ul>\n<p><strong>What you should know to start working on this kata:</strong></p>\n<ul>\n<li>Basic linear algebra</li>\n<li>Single and multi-qubit systems</li>\n<li>Single and multi-qubit gates</li>\n<li>Single-qubit system measurements</li>\n</ul>\n<h2>Types of Measurements</h2>\n<p>There are several types of measurements you can perform on an $n$-qubit system ($n&gt;1$):</p>\n<ul>\n<li>Measuring all the qubits simultaneously in an orthogonal basis ($2^n$ possible outcomes). As we shall see below, this is a direct generalization of orthogonal basis measurements done in single-qubit systems introduced in the previous kata.</li>\n<li>Partial measurement: measuring $m$ qubits out of $n$, for $m&lt;n$ ($2^m$ possible outcomes). Partial measurements involve a partial collapse of the system's wave function, since only some of the qubits are measured.</li>\n<li>Joint measurement: measuring a joint property of all $n$ qubits ($2$ possible outcomes).</li>\n</ul>\n<p>We will discuss these concepts in the same order as in the list above.</p>\n"
3382
+ "content": "<p>The previous kata discussed the concept of measurements done on single-qubit systems.\nBuilding upon those ideas, this kata will introduce you to measurements done on multi-qubit systems, and how to implement such measurements in Q#.\nThis will include measuring a single qubit in a multi-qubit system, as well as measuring multiple qubits simultaneously.</p>\n<p><strong>This kata covers the following topics:</strong></p>\n<ul>\n<li>Measuring a single qubit in a multi-qubit system</li>\n<li>Measuring multiple qubits simultaneously</li>\n<li>Implementing different kinds of measurements in Q#</li>\n</ul>\n<p><strong>What you should know to start working on this kata:</strong></p>\n<ul>\n<li>Basic concepts of linear algebra</li>\n<li>Single and multi-qubit systems</li>\n<li>Basic single and multi-qubit gates</li>\n<li>Single-qubit system measurements</li>\n</ul>\n<p>If you need a refresher on any of these topics, you can check out the previous katas.</p>\n<h2>Types of Measurements</h2>\n<p>There are several types of measurements you can perform on an $n$-qubit system ($n&gt;1$):</p>\n<ul>\n<li>Measuring all the qubits simultaneously in an orthogonal basis ($2^n$ possible outcomes). As you'll see below, this is a direct generalization of orthogonal basis measurements done in single-qubit systems introduced in the previous kata.</li>\n<li>Partial measurement: measuring $m$ qubits out of $n$, for $m&lt;n$ ($2^m$ possible outcomes). Partial measurements involve a partial collapse of the system's wave function, since only some of the qubits are measured.</li>\n<li>Joint measurement: measuring a joint property of all $n$ qubits ($2$ possible outcomes).</li>\n</ul>\n<p>The following sections discuss these concepts in the same order as in the list above.</p>\n"
3383
3383
  }
3384
3384
  ]
3385
3385
  },
@@ -3390,7 +3390,7 @@ export default {
3390
3390
  "items": [
3391
3391
  {
3392
3392
  "type": "text-content",
3393
- "content": "<p>Consider a system consisting of $n\\geq1$ qubits. The wave function of such a system belongs to a vector space of dimension $2^n$. Thus, the vector space is spanned by an orthogonal basis, such as the computational basis which consists of the vectors $\\ket{0\\dotsc0}, \\dotsc, \\ket{1\\dotsc 1}$. For generality, we consider an arbitrary orthonormal basis, which we denote by $\\{ \\ket{b_0}, \\ket{b_1}, \\dotsc, \\ket{b_{2^n-1}} \\}$.</p>\n<p>Then, the state $\\ket{\\psi}$ of the multi-qubit system can be expressed as a linear combination of the $2^n$ basis vectors $\\ket{b_i}$. That is, there exist complex numbers $c_0,c_1,\\dotsc, c_{2^n-1}$ such that</p>\n<p>$$\n\\ket{\\psi} = \\sum_{i=0}^{2^n-1} c_i\\ket{b_i} \\equiv \\begin{pmatrix} c_0 \\\\ c_1 \\\\ \\vdots \\\\ c_{2^n-1} \\end{pmatrix}\n$$</p>\n<p>In line with the usual convention, we choose the wave function to be normalized, so that $|c_0|^2 + \\dotsc + |c_{2^n-1}|^2 =1$. Then, a quantum measurement in the basis $\\{ \\ket{b_0}, \\ket{b_1}, \\dotsc, \\ket{b_{2^n-1}} \\}$ satisfies the following rules:</p>\n<ul>\n<li>The measurement outcome $b_i$ occurs with probability $|c_i|^2$.</li>\n<li>Whenever the measurement outcome is $b_i$, the wave function collapses to the state $\\ket{b_i}$. That is, the post-measurement state of the system is equal to $\\ket{b_i}$.</li>\n</ul>\n<p>This can be summarized in the following table:</p>\n<table>\n <tr>\n <th>Measurement outcome</th>\n <th>Probability of outcome</th>\n <th>State after measurement</th>\n </tr>\n <tr>\n <td>$b_i$</td>\n <td>$|c_i|^2$</td>\n <td>$\\ket{b_i}$</td>\n </tr>\n</table>\n<blockquote>\n<p>Similar to measurements in single-qubit systems, the assumption of normalization of the original wave function is required in order to ensure that the sum of all the outcome probabilities is 1.</p>\n</blockquote>\n<h2>🔎 Analyze</h2>\n<h3>Multi-Qubit Measurement Outcome Probabilities I</h3>\n<p>You are given a two-qubit system in the following state:\n$$\\ket \\psi = \\frac{2}{3}\\ket {00} + \\frac{1}{3} \\ket {01} + \\frac{2}{3}\\ket {11}$$</p>\n<p>If all the qubits are measured simultaneously in the computational basis, what are the outcome probabilities?</p>\n<details>\n<summary><b>Solution</b></summary>\n<p>The wave function $\\ket{\\psi}$ is normalized, since $\\left(\\frac{2}{3}\\right)^2 + \\left(\\frac{1}{3}\\right)^2 + \\left(\\frac{2}{3}\\right)^2 = 1$. Hence, the probabilities of measuring each of the computational basis states is simply the square of the absolute value of the corresponding coefficients. That is, the probabilities of measuring $00$, $01$ and $11$ are $\\frac{4}{9}$, $\\frac{1}{9}$ and $\\frac{4}{9}$, respectively, and the probability of measuring the basis state $10$ that is not part of the superposition is $0$:</p>\n<table>\n <tr>\n <th>Measurement outcome</th>\n <th>Probability of outcome</th>\n </tr>\n <tr>\n <td>$00$</td>\n <td>$\\left( \\frac{2}{3}\\right)^2 = \\frac{4}{9}$</td>\n </tr>\n <tr>\n <td>$01$</td>\n <td>$\\left( \\frac{1}{3}\\right)^2 = \\frac{1}{9}$</td>\n </tr>\n <tr>\n <td>$10$</td>\n <td>$\\left( 0\\right)^2 = 0$</td>\n </tr>\n <tr>\n <td>$11$</td>\n <td>$\\left( \\frac{2}{3}\\right)^2 = \\frac{4}{9}$</td>\n </tr>\n</table>\n</details>\n<h3>Multi-Qubit Measurement Outcome Probabilities II</h3>\n<p>You are given a two-qubit system in the same state as in the previous exercise:\n$$\\ket \\psi = \\frac{2}{3}\\ket {00} + \\frac{1}{3} \\ket {01} + \\frac{2}{3}\\ket {11}$$</p>\n<p>If all the qubits are measured simultaneously in the Pauli X basis, that is, in the $\\{ \\ket{++}, \\ket{+-}, \\ket{-+}, \\ket{--}\\}$ basis, what are the outcome probabilities?</p>\n<details>\n<summary><b>Solution</b></summary>\n<p>Using the expressions $\\ket{0} = \\frac{1}{\\sqrt{2}} \\big( \\ket{+} + \\ket{-} \\big)$ and $\\ket{1} = \\frac{1}{\\sqrt{2}} \\big( \\ket{+} - \\ket{-} \\big)$, we first express $\\ket{\\psi}$ in the Pauli X basis. This gives us\n$$\\ket \\psi = \\frac{2}{3}\\ket {00} + \\frac{1}{3} \\ket {01} + \\frac{2}{3}\\ket {11} =$$</p>\n<p>$$= \\frac{2}{3} \\big[ \\frac{1}{\\sqrt{2}}\\big(\\ket{+} + \\ket{-}\\big) \\otimes \\frac{1}{\\sqrt{2}} \\big(\\ket{+} + \\ket{-}\\big) \\big] + \\frac{1}{3} \\big[ \\frac{1}{\\sqrt{2}}\\big(\\ket{+} + \\ket{-}\\big) \\otimes \\frac{1}{\\sqrt{2}} \\big(\\ket{+} - \\ket{-}\\big) \\big] + \\frac{2}{3} \\big[ \\frac{1}{\\sqrt{2}}\\big(\\ket{+} - \\ket{-}\\big) \\otimes \\frac{1}{\\sqrt{2}} \\big(\\ket{+} - \\ket{-}\\big) \\big] =$$</p>\n<p>$$= \\frac{1}{3} \\big[ \\big(\\ket{+} + \\ket{-}\\big) \\otimes \\big(\\ket{+} + \\ket{-}\\big) \\big] + \\frac{1}{6} \\big[ \\big(\\ket{+} + \\ket{-}\\big) \\otimes \\big(\\ket{+} - \\ket{-}\\big) \\big] + \\frac{1}{3} \\big[ \\big(\\ket{+} - \\ket{-}\\big) \\otimes \\big(\\ket{+} - \\ket{-}\\big) \\big] =$$</p>\n<p>$$= \\frac{1}{3} \\big[ \\ket{++} + \\ket{+-} + \\ket{-+} + \\ket{--} \\big] + \\frac{1}{6} \\big[ \\ket{++} - \\ket{+-} + \\ket{-+} - \\ket{--} \\big] + \\frac{1}{3} \\big[ \\ket{++} - \\ket{+-} - \\ket{-+} + \\ket{--} \\big] =$$</p>\n<p>$$= (\\frac{1}{3} + \\frac{1}{6} + \\frac{1}{3})\\ket{++} + (\\frac{1}{3} - \\frac{1}{6} - \\frac{1}{3})\\ket{+-} + (\\frac{1}{3} + \\frac{1}{6} - \\frac{1}{3})\\ket{-+} + (\\frac{1}{3} - \\frac{1}{6} + \\frac{1}{3})\\ket{--} =$$</p>\n<p>$$= \\frac{5}{6}\\ket{++} - \\frac{1}{6}\\ket{+-} + \\frac{1}{6}\\ket{-+} + \\frac{1}{2}\\ket{--}$$</p>\n<p>After this, the probabilities of measuring each of the four basis vectors is given by the square of the absolute value of its amplitude in the superposition:</p>\n<table>\n <tr>\n <th>Measurement outcome</th>\n <th>Probability of outcome</th>\n </tr>\n <tr>\n <td>$++$</td>\n <td>$\\left( \\frac{5}{6}\\right)^2 = \\frac{25}{36}$</td>\n </tr>\n <tr>\n <td>$+-$</td>\n <td>$\\left( -\\frac{1}{6}\\right)^2 = \\frac{1}{36}$</td>\n </tr>\n <tr>\n <td>$-+$</td>\n <td>$\\left( \\frac{1}{6}\\right)^2 = \\frac{1}{36}$</td>\n </tr>\n <tr>\n <td>$--$</td>\n <td>$\\left( \\frac{1}{2}\\right)^2 = \\frac{1}{4}$</td>\n </tr>\n</table>\n</details>\n<p>Now, let's see how we can use Q# to solve these two problems.</p>\n<ol>\n<li>We start by preparing the state $\\ket \\psi$.\nTo do this, we can represent $\\ket \\psi$ as follows:\n$$\\frac 2 3 \\ket{00} + \\big( \\frac 1 {\\sqrt 5} \\ket{0} + \\frac 2 {\\sqrt 5} \\ket{1} \\big) \\frac {\\sqrt 5} 3 \\ket{1}$$\nThis representation tells us how we should rotate individual qubits.</li>\n<li>To figure out the measurement outcome probabilities in the computational basis, we can just use the <code>DumpMachine</code> function that lists probabilities associated with each basis state present in the superposition.</li>\n<li>To figure out the measurement outcome probabilities in the Pauli X basis, we can apply a transformation that maps the two-qubit Pauli X basis into the two-qubit computational basis. This transformation just applies a Hadamard gate to each of the qubits.</li>\n<li>View probabilities of each basis state with the <code>DumpMachine</code> function. Thanks to the previous step, the following state equivalence holds:</li>\n</ol>\n<table>\n <tr>\n <th>Before basis transformation</th>\n <th>After basis transformation</th>\n </tr>\n <tr>\n <td>$\\ket {++}$</td>\n <td>$\\ket {00}$</td>\n </tr>\n <tr>\n <td>$\\ket {+-}$</td>\n <td>$\\ket {01}$</td>\n </tr>\n <tr>\n <td>$\\ket {-+}$</td>\n <td>$\\ket {10}$</td>\n </tr>\n <tr>\n <td>$\\ket {--}$</td>\n <td>$\\ket {11}$</td>\n </tr>\n</table>\n<p>The amplitudes of the computational basis states after the transformation are the same as the amplitudes of the basis states of the Pauli X basis before the transformation!</p>\n"
3393
+ "content": "<p>Consider a system consisting of $n\\geq1$ qubits. The wave function of such a system belongs to a vector space of dimension $2^n$. Thus, the vector space is spanned by an orthogonal basis, such as the computational basis which consists of the vectors $\\ket{0\\dotsc0}, \\dotsc, \\ket{1\\dotsc 1}$. For generality, consider an arbitrary orthonormal basis, which is denoted by $\\{ \\ket{b_0}, \\ket{b_1}, \\dotsc, \\ket{b_{2^n-1}} \\}$.</p>\n<p>Then, the state $\\ket{\\psi}$ of the multi-qubit system can be expressed as a linear combination of the $2^n$ basis vectors $\\ket{b_i}$. That is, there exist complex numbers $c_0,c_1,\\dotsc, c_{2^n-1}$ such that</p>\n<p>$$\n\\ket{\\psi} = \\sum_{i=0}^{2^n-1} c_i\\ket{b_i} \\equiv \\begin{pmatrix} c_0 \\\\ c_1 \\\\ \\vdots \\\\ c_{2^n-1} \\end{pmatrix}\n$$</p>\n<p>In line with the usual convention, let's choose the wave function to be normalized, so that $|c_0|^2 + \\dotsc + |c_{2^n-1}|^2 =1$. Then, a quantum measurement in the basis $\\{ \\ket{b_0}, \\ket{b_1}, \\dotsc, \\ket{b_{2^n-1}} \\}$ satisfies the following rules:</p>\n<ul>\n<li>The measurement outcome $b_i$ occurs with probability $|c_i|^2$.</li>\n<li>Whenever the measurement outcome is $b_i$, the wave function collapses to the state $\\ket{b_i}$. That is, the post-measurement state of the system is equal to $\\ket{b_i}$.</li>\n</ul>\n<p>This can be summarized in the following table:</p>\n<table>\n <tr>\n <th>Measurement outcome</th>\n <th>Probability of outcome</th>\n <th>State after measurement</th>\n </tr>\n <tr>\n <td>$b_i$</td>\n <td>$|c_i|^2$</td>\n <td>$\\ket{b_i}$</td>\n </tr>\n</table>\n<blockquote>\n<p>Similar to measurements in single-qubit systems, the assumption of normalization of the original wave function is required in order to ensure that the sum of all the outcome probabilities is 1.</p>\n</blockquote>\n<h2>🔎 Analyze</h2>\n<h3>Multi-Qubit Measurement Outcome Probabilities I</h3>\n<p>You are given a two-qubit system in the following state:\n$$\\ket \\psi = \\frac{2}{3}\\ket {00} + \\frac{1}{3} \\ket {01} + \\frac{2}{3}\\ket {11}$$</p>\n<p>If all the qubits are measured simultaneously in the computational basis, what are the outcome probabilities?</p>\n<details>\n<summary><b>Solution</b></summary>\n<p>The wave function $\\ket{\\psi}$ is normalized, since $\\left(\\frac{2}{3}\\right)^2 + \\left(\\frac{1}{3}\\right)^2 + \\left(\\frac{2}{3}\\right)^2 = 1$. Hence, the probabilities of measuring each of the computational basis states is simply the square of the absolute value of the corresponding coefficients. That is, the probabilities of measuring $00$, $01$ and $11$ are $\\frac{4}{9}$, $\\frac{1}{9}$ and $\\frac{4}{9}$, respectively, and the probability of measuring the basis state $10$ that is not part of the superposition is $0$:</p>\n<table>\n <tr>\n <th>Measurement outcome</th>\n <th>Probability of outcome</th>\n </tr>\n <tr>\n <td>$00$</td>\n <td>$\\left( \\frac{2}{3}\\right)^2 = \\frac{4}{9}$</td>\n </tr>\n <tr>\n <td>$01$</td>\n <td>$\\left( \\frac{1}{3}\\right)^2 = \\frac{1}{9}$</td>\n </tr>\n <tr>\n <td>$10$</td>\n <td>$\\left( 0\\right)^2 = 0$</td>\n </tr>\n <tr>\n <td>$11$</td>\n <td>$\\left( \\frac{2}{3}\\right)^2 = \\frac{4}{9}$</td>\n </tr>\n</table>\n</details>\n<h3>Multi-Qubit Measurement Outcome Probabilities II</h3>\n<p>You are given a two-qubit system in the same state as in the previous exercise:\n$$\\ket \\psi = \\frac{2}{3}\\ket {00} + \\frac{1}{3} \\ket {01} + \\frac{2}{3}\\ket {11}$$</p>\n<p>If all the qubits are measured simultaneously in the Pauli X basis, that is, in the $\\{ \\ket{++}, \\ket{+-}, \\ket{-+}, \\ket{--}\\}$ basis, what are the outcome probabilities?</p>\n<details>\n<summary><b>Solution</b></summary>\n<p>Using the expressions $\\ket{0} = \\frac{1}{\\sqrt{2}} \\big( \\ket{+} + \\ket{-} \\big)$ and $\\ket{1} = \\frac{1}{\\sqrt{2}} \\big( \\ket{+} - \\ket{-} \\big)$, you first express $\\ket{\\psi}$ in the Pauli X basis. This gives you\n$$\\ket \\psi = \\frac{2}{3}\\ket {00} + \\frac{1}{3} \\ket {01} + \\frac{2}{3}\\ket {11} =$$</p>\n<p>$$= \\frac{2}{3} \\big[ \\frac{1}{\\sqrt{2}}\\big(\\ket{+} + \\ket{-}\\big) \\otimes \\frac{1}{\\sqrt{2}} \\big(\\ket{+} + \\ket{-}\\big) \\big] + \\frac{1}{3} \\big[ \\frac{1}{\\sqrt{2}}\\big(\\ket{+} + \\ket{-}\\big) \\otimes \\frac{1}{\\sqrt{2}} \\big(\\ket{+} - \\ket{-}\\big) \\big] + \\frac{2}{3} \\big[ \\frac{1}{\\sqrt{2}}\\big(\\ket{+} - \\ket{-}\\big) \\otimes \\frac{1}{\\sqrt{2}} \\big(\\ket{+} - \\ket{-}\\big) \\big] =$$</p>\n<p>$$= \\frac{1}{3} \\big[ \\big(\\ket{+} + \\ket{-}\\big) \\otimes \\big(\\ket{+} + \\ket{-}\\big) \\big] + \\frac{1}{6} \\big[ \\big(\\ket{+} + \\ket{-}\\big) \\otimes \\big(\\ket{+} - \\ket{-}\\big) \\big] + \\frac{1}{3} \\big[ \\big(\\ket{+} - \\ket{-}\\big) \\otimes \\big(\\ket{+} - \\ket{-}\\big) \\big] =$$</p>\n<p>$$= \\frac{1}{3} \\big[ \\ket{++} + \\ket{+-} + \\ket{-+} + \\ket{--} \\big] + \\frac{1}{6} \\big[ \\ket{++} - \\ket{+-} + \\ket{-+} - \\ket{--} \\big] + \\frac{1}{3} \\big[ \\ket{++} - \\ket{+-} - \\ket{-+} + \\ket{--} \\big] =$$</p>\n<p>$$= (\\frac{1}{3} + \\frac{1}{6} + \\frac{1}{3})\\ket{++} + (\\frac{1}{3} - \\frac{1}{6} - \\frac{1}{3})\\ket{+-} + (\\frac{1}{3} + \\frac{1}{6} - \\frac{1}{3})\\ket{-+} + (\\frac{1}{3} - \\frac{1}{6} + \\frac{1}{3})\\ket{--} =$$</p>\n<p>$$= \\frac{5}{6}\\ket{++} - \\frac{1}{6}\\ket{+-} + \\frac{1}{6}\\ket{-+} + \\frac{1}{2}\\ket{--}$$</p>\n<p>After this, the probabilities of measuring each of the four basis vectors is given by the square of the absolute value of its amplitude in the superposition:</p>\n<table>\n <tr>\n <th>Measurement outcome</th>\n <th>Probability of outcome</th>\n </tr>\n <tr>\n <td>$++$</td>\n <td>$\\left( \\frac{5}{6}\\right)^2 = \\frac{25}{36}$</td>\n </tr>\n <tr>\n <td>$+-$</td>\n <td>$\\left( -\\frac{1}{6}\\right)^2 = \\frac{1}{36}$</td>\n </tr>\n <tr>\n <td>$-+$</td>\n <td>$\\left( \\frac{1}{6}\\right)^2 = \\frac{1}{36}$</td>\n </tr>\n <tr>\n <td>$--$</td>\n <td>$\\left( \\frac{1}{2}\\right)^2 = \\frac{1}{4}$</td>\n </tr>\n</table>\n</details>\n<p>Now, let's see how you can use Q# to solve these two problems.</p>\n<ol>\n<li>You start by preparing the state $\\ket \\psi$.\nTo do this, you can represent $\\ket \\psi$ as follows:\n$$\\frac 2 3 \\ket{00} + \\big( \\frac 1 {\\sqrt 5} \\ket{0} + \\frac 2 {\\sqrt 5} \\ket{1} \\big) \\frac {\\sqrt 5} 3 \\ket{1}$$\nThis representation tells you how you should rotate individual qubits.</li>\n<li>To figure out the measurement outcome probabilities in the computational basis, you can just use the <code>DumpMachine</code> function that lists probabilities associated with each basis state present in the superposition.</li>\n<li>To figure out the measurement outcome probabilities in the Pauli X basis, you can apply a transformation that maps the two-qubit Pauli X basis into the two-qubit computational basis. This transformation just applies a Hadamard gate to each of the qubits.</li>\n<li>View probabilities of each basis state with the <code>DumpMachine</code> function. Thanks to the previous step, the following state equivalence holds:</li>\n</ol>\n<table>\n <tr>\n <th>Before basis transformation</th>\n <th>After basis transformation</th>\n </tr>\n <tr>\n <td>$\\ket {++}$</td>\n <td>$\\ket {00}$</td>\n </tr>\n <tr>\n <td>$\\ket {+-}$</td>\n <td>$\\ket {01}$</td>\n </tr>\n <tr>\n <td>$\\ket {-+}$</td>\n <td>$\\ket {10}$</td>\n </tr>\n <tr>\n <td>$\\ket {--}$</td>\n <td>$\\ket {11}$</td>\n </tr>\n</table>\n<p>The amplitudes of the computational basis states after the transformation are the same as the amplitudes of the basis states of the Pauli X basis before the transformation!</p>\n"
3394
3394
  },
3395
3395
  {
3396
3396
  "type": "example",
@@ -3399,7 +3399,7 @@ export default {
3399
3399
  },
3400
3400
  {
3401
3401
  "type": "text-content",
3402
- "content": "<h2>Measuring Each Qubit in a System Sequentially</h2>\n<p>As described in the previous sections, in theory it is possible to measure all the qubits in an $n$-qubit system simultaneously in an orthogonal basis. The post-measurement state of the qubits is then exactly one of the $2^n$ possible basis states.</p>\n<p>In practice, this is implemented by measuring all the qubits one after another. For example, if one wants to measure a two-qubit system in the computational basis, one can implement this by first measuring the first qubit in the computational basis to obtain $0$ or $1$, and then measuring the second qubit in the computational basis. This can result in one of the four possible outcomes: $00, 01, 10, 11$.</p>\n<p>This can be generalized to measurements in other bases, such as the 2-qubit Pauli X basis $\\ket{++}, \\ket{+-}, \\ket{-+}, \\ket{--}$, and the bases for larger numbers of qubits.</p>\n<blockquote>\n<p>Note that measurement of all qubits sequentially can only be done in orthogonal bases $\\{ \\ket{b_i}\\}$, such that each $\\ket{b_i}$ is a <strong>tensor product state</strong>. That is, each $\\ket{b_i}$ must be of the form $\\ket{v_0} \\otimes \\ket{v_1} \\dotsc \\otimes \\ket{v_{n-1}}$, with each $\\ket{v_j}$ being a single-qubit basis state.\nFor example, for the two-qubit Pauli X basis $\\ket{++}, \\ket{+-}, \\ket{-+}, \\ket{--}$ each basis state is a tensor product of states $\\ket{+}$ and $\\ket{-}$, which form a single-qubit basis state.</p>\n<p>Measuring in orthogonal bases which contain states which are not tensor product states, such as the Bell basis, are trickier to implement, and require appropriate unitary rotations in addition to measuring all qubits one after another.\nWe will not discuss such measurements in this kata.</p>\n<p>If we restrict ourselves to measurements in tensor product states, the distinction between measuring all the qubits simultaneously versus one after another is not important for an ideal quantum computer: in terms of the outcomes and measurement probabilities, both are identical. Furthermore, as long as all the qubits are measured, the sequence in which they are measured is also inconsequential. These factors can be important in the case of real quantum computers with imperfect qubits, but we restrict the discussion to ideal systems in this kata.</p>\n</blockquote>\n"
3402
+ "content": "<h2>Measuring Each Qubit in a System Sequentially</h2>\n<p>As described in the previous sections, in theory it's possible to measure all the qubits in an $n$-qubit system simultaneously in an orthogonal basis. The post-measurement state of the qubits is then exactly one of the $2^n$ possible basis states.</p>\n<p>In practice, this is implemented by measuring all the qubits one after another. For example, if one wants to measure a two-qubit system in the computational basis, one can implement this by first measuring the first qubit in the computational basis to obtain $0$ or $1$, and then measuring the second qubit in the computational basis. This can result in one of the four possible outcomes: $00, 01, 10, 11$.</p>\n<p>This can be generalized to measurements in other bases, such as the 2-qubit Pauli X basis $\\ket{++}, \\ket{+-}, \\ket{-+}, \\ket{--}$, and the bases for larger numbers of qubits.</p>\n<blockquote>\n<p>Note that measurement of all qubits sequentially can only be done in orthogonal bases $\\{ \\ket{b_i}\\}$, such that each $\\ket{b_i}$ is a <strong>tensor product state</strong>. That is, each $\\ket{b_i}$ must be of the form $\\ket{v_0} \\otimes \\ket{v_1} \\dotsc \\otimes \\ket{v_{n-1}}$, with each $\\ket{v_j}$ being a single-qubit basis state.\nFor example, for the two-qubit Pauli X basis $\\ket{++}, \\ket{+-}, \\ket{-+}, \\ket{--}$ each basis state is a tensor product of states $\\ket{+}$ and $\\ket{-}$, which form a single-qubit basis state.</p>\n<p>Measuring in orthogonal bases which contain states which aren't tensor product states, such as the Bell basis, are trickier to implement, and require appropriate unitary rotations in addition to measuring all qubits one after another.\nSuch measurements aren't discussed in this kata.</p>\n<p>If measurements are restricted to tensor product states, the distinction between measuring all the qubits simultaneously versus one after another is not important for an ideal quantum computer: in terms of the outcomes and measurement probabilities, both approaches are identical. Furthermore, as long as all the qubits are measured, the sequence in which they are measured is also inconsequential. These factors can be important in the case of real quantum computers with imperfect qubits, but the discussion in this kata is limited to ideal systems.</p>\n</blockquote>\n"
3403
3403
  }
3404
3404
  ]
3405
3405
  },
@@ -3410,7 +3410,7 @@ export default {
3410
3410
  "items": [
3411
3411
  {
3412
3412
  "type": "text-content",
3413
- "content": "<p>This demo illustrates the equivalence of the measurement probabilities for simultaneous measurement on all qubits, and measurements on each of the qubits executed one after another. We show that the measurement probabilities obtained using the <code>M</code> operation in Q# are the same as those expected theoretically, using the two-qubit state from the first exercise as an example:</p>\n<p>$$\\ket \\psi = \\frac{1}{3}\\ket {00} + \\frac{2}{3} \\ket {01} + \\frac{2}{3}\\ket {11}$$</p>\n<p>The simulated probabilities will be different for each run of <code>DemoBasisMeasurement</code>. The simulated and theoretical probabilities are not expected to be identical, since measurements are probabilistic. However, we expect the values to be similar, and the simulated probabilities to approach the theoretical probabilities as the parameter <code>numRuns</code> is increased.</p>\n"
3413
+ "content": "<p>This demo illustrates the equivalence of the measurement probabilities for simultaneous measurement on all qubits, and measurements on each of the qubits executed one after another. It shows that the measurement probabilities obtained using the <code>M</code> operation in Q# are the same as those expected theoretically, using the two-qubit state from the first exercise as an example:</p>\n<p>$$\\ket \\psi = \\frac{1}{3}\\ket {00} + \\frac{2}{3} \\ket {01} + \\frac{2}{3}\\ket {11}$$</p>\n<p>The simulated probabilities will be different for each run of <code>DemoBasisMeasurement</code>. The simulated and theoretical probabilities are not expected to be identical, since measurements are probabilistic. However, the values are expected to be similar, and the simulated probabilities to approach the theoretical probabilities as the parameter <code>numRuns</code> is increased.</p>\n"
3414
3414
  },
3415
3415
  {
3416
3416
  "type": "example",
@@ -3419,7 +3419,7 @@ export default {
3419
3419
  },
3420
3420
  {
3421
3421
  "type": "text-content",
3422
- "content": "<p>Full measurements can also be used to identify the state of the system, if it is guaranteed to be in one of several possible orthogonal states.</p>\n"
3422
+ "content": "<p>Full measurements can also be used to identify the state of the system, if it's guaranteed to be in one of several possible orthogonal states.</p>\n"
3423
3423
  }
3424
3424
  ]
3425
3425
  },
@@ -3429,7 +3429,7 @@ export default {
3429
3429
  "title": "Distinguish Four Basis States",
3430
3430
  "description": {
3431
3431
  "type": "text-content",
3432
- "content": "<p><strong>Input:</strong> Two qubits (stored in an array of length 2) which are guaranteed to be in one of the four basis states ($\\ket{00}$, $\\ket{01}$, $\\ket{10}$, or $\\ket{11}$).</p>\n<p><strong>Output:</strong></p>\n<ul>\n<li>0 if the qubits were in the $\\ket{00}$ state,</li>\n<li>1 if they were in the $\\ket{01}$ state,</li>\n<li>2 if they were in the $\\ket{10}$ state,</li>\n<li>3 if they were in the $\\ket{11}$ state.</li>\n</ul>\n<p>In this task and the subsequent ones the order of qubit states in task description matches the order of qubits in the array (i.e., $\\ket{10}$ state corresponds to <code>qs[0]</code> in state $\\ket{1}$ and <code>qs[1]</code> in state $\\ket{0}$).</p>\n<p>The state of the qubits at the end of the operation does not matter.</p>\n"
3432
+ "content": "<p><strong>Input:</strong> Two qubits (stored in an array of length 2) which are guaranteed to be in one of the four basis states ($\\ket{00}$, $\\ket{01}$, $\\ket{10}$, or $\\ket{11}$).</p>\n<p><strong>Output:</strong></p>\n<ul>\n<li>0 if the qubits were in the $\\ket{00}$ state,</li>\n<li>1 if they were in the $\\ket{01}$ state,</li>\n<li>2 if they were in the $\\ket{10}$ state,</li>\n<li>3 if they were in the $\\ket{11}$ state.</li>\n</ul>\n<p>In this task and the subsequent ones the order of qubit states in task description matches the order of qubits in the array (that is, $\\ket{10}$ state corresponds to <code>qs[0]</code> in state $\\ket{1}$ and <code>qs[1]</code> in state $\\ket{0}$).</p>\n<p>The state of the qubits at the end of the operation doesn't matter.</p>\n"
3433
3433
  },
3434
3434
  "sourceIds": [
3435
3435
  "multi_qubit_measurements__full_measurements__Verification.qs",
@@ -3441,7 +3441,7 @@ export default {
3441
3441
  "items": [
3442
3442
  {
3443
3443
  "type": "text-content",
3444
- "content": "<p>First, we measure each of the qubits in the input array, convert the measurement results into integers\nand store them in variables <code>m1</code> and <code>m2</code>. We can decode these results like this:</p>\n<ul>\n<li><code>m1</code> is $\\ket{0}$ and <code>m2</code> is $\\ket{0}$: we return $0\\cdot2+0 = 0$</li>\n<li><code>m1</code> is $\\ket{0}$ and <code>m2</code> is $\\ket{1}$: we return $0\\cdot2+1 = 1$</li>\n<li><code>m1</code> is $\\ket{1}$ and <code>m2</code> is $\\ket{0}$: we return $1\\cdot2+0 = 2$</li>\n<li><code>m1</code> is $\\ket{1}$ and <code>m2</code> is $\\ket{1}$: we return $1\\cdot2+1 = 3$</li>\n</ul>\n<p>In other words, we treat the measurement results as the binary notation of the return value in big-endian notation.</p>\n"
3444
+ "content": "<p>First, you measure each of the qubits in the input array, convert the measurement results into integers\nand store them in variables <code>m1</code> and <code>m2</code>. You can decode these results like this:</p>\n<ul>\n<li><code>m1</code> is $\\ket{0}$ and <code>m2</code> is $\\ket{0}$: the return value is $0\\cdot2+0 = 0$</li>\n<li><code>m1</code> is $\\ket{0}$ and <code>m2</code> is $\\ket{1}$: the return value is $0\\cdot2+1 = 1$</li>\n<li><code>m1</code> is $\\ket{1}$ and <code>m2</code> is $\\ket{0}$: the return value is $1\\cdot2+0 = 2$</li>\n<li><code>m1</code> is $\\ket{1}$ and <code>m2</code> is $\\ket{1}$: the return value is $1\\cdot2+1 = 3$</li>\n</ul>\n<p>In other words, you treat the measurement results as the binary notation of the return value in big-endian notation.</p>\n"
3445
3445
  },
3446
3446
  {
3447
3447
  "type": "solution",
@@ -3450,7 +3450,7 @@ export default {
3450
3450
  },
3451
3451
  {
3452
3452
  "type": "text-content",
3453
- "content": "<p>We can generalize this code to read out an integer in big-endian notation from a qubit array of arbitrary length using several library operations and functions:</p>\n<ul>\n<li><code>MeasureEachZ</code> measures each of the qubits in the array in the computational basis and returns an array of <code>Result</code> data type.</li>\n<li><code>Reversed</code> reverses the given array.</li>\n<li><code>ResultArrayAsInt</code> converts an array of bits given as <code>Result</code> to an integer, assuming little-endian notation (that's why we have to reverse the array before converting it).</li>\n</ul>\n"
3453
+ "content": "<p>You can generalize this code to read out an integer in big-endian notation from a qubit array of arbitrary length using several library operations and functions:</p>\n<ul>\n<li><code>MeasureEachZ</code> measures each of the qubits in the array in the computational basis and returns an array of <code>Result</code> data type.</li>\n<li><code>Reversed</code> reverses the given array.</li>\n<li><code>ResultArrayAsInt</code> converts an array of bits given as <code>Result</code> to an integer, assuming little-endian notation (that's why you have to reverse the array before converting it).</li>\n</ul>\n"
3454
3454
  },
3455
3455
  {
3456
3456
  "type": "solution",
@@ -3467,7 +3467,7 @@ export default {
3467
3467
  "items": [
3468
3468
  {
3469
3469
  "type": "text-content",
3470
- "content": "<p>For a system with $n&gt;1$ qubits, it is possible to measure $m&lt;n$ qubits one after another. The number of measurement outcomes is then $2^m$ instead of $2^n$. The probabilities of each of the outcomes and the post-measurement states of the qubits can be found using the projection formalism for measurements.</p>\n<p>First, we recall the concept of projection operators introduced in the Measurements in Single-Qubit Systems kata. Measurements are modeled by orthogonal projection operators - matrices that satisfy\n$$P^2 = P^\\dagger = P$$\nConsider an $n$-qubit system in a state $\\ket{\\psi}$, for which the first $m&lt;n$ qubits are measured in an orthogonal basis $\\{ \\ket{b_0} , \\ket{b_1}, \\dotsc, \\ket{b_{2^m-1}}\\}$ corresponding to the $m$ qubits being measured. Then we define $2^m$ projectors corresponding to each of the $\\ket{b_i}$ states as</p>\n<p>$$P_i = \\ket{b_i} \\bra{ b_i} \\otimes \\mathbb{1}_{n-m} $$</p>\n<p>where $\\mathbb{1}_{n-m}$ is the identity operator over the remaining $(n-m)$ qubits.</p>\n<blockquote>\n<p>The symbol $\\otimes$ represents the tensor product or the Kronecker product of two matrices. It is different from the usual matrix multiplication.\nIn the current context, $\\ket{b_i} \\bra{ b_i} \\otimes \\mathbb{1}_{n-m}$ simply means that</p>\n<ul>\n<li>The operator $\\ket{b_i} \\bra{ b_i}$ acts only on the $m$ qubits being measured.</li>\n<li>The effect of $P_i$ on the remaining qubits is $\\mathbb{1}_{n-m} $, i.e., the identity operator.</li>\n</ul>\n</blockquote>\n<p>Analogous to the case for measurements for single-qubit systems, the rules for partial measurement probabilities and outcomes can be summarized as follows:</p>\n<ul>\n<li>When a measurement is done, one of these projectors is chosen randomly. The probability of choosing projector $P_i$ is $\\big|P_i\\ket{\\psi}\\big|^2$.</li>\n<li>If the projector $P_i$ is chosen, the measurement outcome is $b_i$, and the state of the system after the measurement is given by</li>\n</ul>\n<p>$$\n\\frac{P_i \\ket{\\psi}}{\\big|P_i \\ket{\\psi}\\big|}.\n$$</p>\n<p>For example, consider a two-qubit system in the state $\\ket \\psi = \\frac{1}{\\sqrt{2}}\\ket{01} - \\frac{1}{\\sqrt 2}\\ket{10}$. Consider a measurement of the first qubit in the computational basis, i.e., in the $\\{\\ket 0 , \\ket 1 \\}$ basis. Then, we have two projectors that represent this measurement:\n$$P_0 = \\ket 0\\bra 0 \\otimes \\mathbb{1}$$\n$$P_1 = \\ket 1 \\bra 1 \\otimes \\mathbb{1}$$</p>\n<p>The action of $P_0$ on $\\ket \\psi$ is</p>\n<p>$$P_0 \\ket \\psi = \\left(\\ket 0\\bra 0 \\otimes \\mathbb{1}\\right) \\frac{1}{\\sqrt 2}\\big(\\ket{01} - \\ket{10}\\big) =$$</p>\n<p>$$= \\frac{1}{\\sqrt 2} \\big( \\ket 0 \\braket{0|0} \\otimes \\mathbb{1} \\ket{1} - \\ket 0 \\braket{0|1} \\otimes \\mathbb{1} \\ket 0 \\big) = \\frac{1}{\\sqrt 2} \\ket{01}$$</p>\n<p>Similarly, we obtain\n$$P_1 \\ket\\psi = -\\frac{1}{\\sqrt 2} \\ket{10}$$</p>\n<p>Clearly, we have $\\big|P_0 \\ket \\psi\\big| = \\big|P_1 \\ket \\psi\\big| = \\frac{1}{2}$ in this case. Thus, the probabilities of measuring $0$ and $1$ are both $0.5$, with the post-measurement states of system being $\\ket{01}$ and $\\ket{10}$, respectively.</p>\n<blockquote>\n<p>Similar to the case of single-qubit system measurements, the applicability of the formalism above requires the state of the multi-qubit system, $\\ket \\psi$, to be normalized. This is required to ensure that all the probabilities of individual outcomes add up to 1.</p>\n</blockquote>\n<h2>🔎 Analyze</h2>\n<h3>Partial measurement probabilities for the Hardy state</h3>\n<p>Consider a 2-qubit system in the state $\\ket \\psi = \\frac{1}{\\sqrt{12}} \\big(3\\ket{00} + \\ket{01} + \\ket{10} + \\ket{11}\\big)$.</p>\n<p>If only the first qubit is measured in the computational basis, what are the probabilities of the outcomes, and the post-measurement states of the system?</p>\n<details>\n<summary><b>Solution</b></summary>\nA measurement outcome of $0$ on the first qubit corresponds to the projection operator $P_0 = \\ket{0}\\bra{ 0} \\otimes \\mathbb{1}$. Applying it to the state $\\ket \\psi$ gives us\n$$\\big|P_0 \\ket{\\psi}\\big|^2 = \\big|\\frac{1}{\\sqrt{12}} \\left(3\\ket {00} + \\ket{01}\\right) \\big|^2 = \\frac{5}{6}$$\nand\n$$\\frac{P_0 \\ket{\\psi}}{\\big|P_0 \\ket{\\psi}\\big|} = \\frac{1}{\\sqrt{10}} \\left( 3\\ket{00} + \\ket{01}\\right)$$\n<p>Similarly, $P_1 = \\ket{1} \\bra{ 1 } \\otimes \\mathbb{1}$ is the projector corresponding to a measurement outcome of $1$ on the first qubit. Applying $P_1$ on $\\ket{\\psi}$ gives us $\\big|P_1 \\ket{\\psi}\\big|^2 = \\frac{1}{6}$ and</p>\n<p>$$\\frac{P_1 \\ket{\\psi}}{\\big|P_1 \\ket{\\psi}\\big|} = \\frac{1}{\\sqrt{2}} \\left(\\ket{10} + \\ket{11}\\right)$$</p>\n<table>\n <tr>\n <th>Measurement outcome</th>\n <th>Probability of outcome</th>\n <th>Post-measurement state</th>\n </tr>\n <tr>\n <td>$0$</td>\n <td>$\\frac{5}{6}$</td>\n <td>$\\frac{1}{\\sqrt{10}} \\left( 3\\ket{00} + \\ket{01}\\right)$</td>\n </tr>\n <tr>\n <td>$1$</td>\n <td>$\\frac{1}{6}$</td>\n <td>$\\frac{1}{\\sqrt{2}} \\left(\\ket{10} + \\ket{11}\\right)$</td>\n </tr>\n</table>\n</details>"
3470
+ "content": "<p>For a system with $n&gt;1$ qubits, it's possible to measure $m&lt;n$ qubits one after another. The number of measurement outcomes is then $2^m$ instead of $2^n$. The probabilities of each of the outcomes and the post-measurement states of the qubits can be found using the projection formalism for measurements.</p>\n<p>First, recall the concept of projection operators introduced in the Measurements in Single-Qubit Systems kata. Measurements are modeled by orthogonal projection operators - matrices that satisfy\n$$P^2 = P^\\dagger = P$$\nConsider an $n$-qubit system in a state $\\ket{\\psi}$, for which the first $m&lt;n$ qubits are measured in an orthogonal basis $\\{ \\ket{b_0} , \\ket{b_1}, \\dotsc, \\ket{b_{2^m-1}}\\}$ corresponding to the $m$ qubits being measured. Then, you define $2^m$ projectors corresponding to each of the $\\ket{b_i}$ states as</p>\n<p>$$P_i = \\ket{b_i} \\bra{ b_i} \\otimes \\mathbb{1}_{n-m} $$</p>\n<p>where $\\mathbb{1}_{n-m}$ is the identity operator over the remaining $(n-m)$ qubits.</p>\n<blockquote>\n<p>The symbol $\\otimes$ represents the tensor product or the Kronecker product of two matrices. It's different from the usual matrix multiplication.\nIn the current context, $\\ket{b_i} \\bra{ b_i} \\otimes \\mathbb{1}_{n-m}$ simply means that</p>\n<ul>\n<li>The operator $\\ket{b_i} \\bra{ b_i}$ acts only on the $m$ qubits being measured.</li>\n<li>The effect of $P_i$ on the remaining qubits is $\\mathbb{1}_{n-m} $, that is, the identity operator.</li>\n</ul>\n</blockquote>\n<p>Analogous to the case for measurements for single-qubit systems, the rules for partial measurement probabilities and outcomes can be summarized as follows:</p>\n<ul>\n<li>When a measurement is done, one of these projectors is chosen randomly. The probability of choosing projector $P_i$ is $\\big|P_i\\ket{\\psi}\\big|^2$.</li>\n<li>If the projector $P_i$ is chosen, the measurement outcome is $b_i$, and the state of the system after the measurement is given by</li>\n</ul>\n<p>$$\n\\frac{P_i \\ket{\\psi}}{\\big|P_i \\ket{\\psi}\\big|}.\n$$</p>\n<p>For example, consider a two-qubit system in the state $\\ket \\psi = \\frac{1}{\\sqrt{2}}\\ket{01} - \\frac{1}{\\sqrt 2}\\ket{10}$. Consider a measurement of the first qubit in the computational basis, that is, in the $\\{\\ket 0 , \\ket 1 \\}$ basis. Then, you have two projectors that represent this measurement:\n$$P_0 = \\ket 0\\bra 0 \\otimes \\mathbb{1}$$\n$$P_1 = \\ket 1 \\bra 1 \\otimes \\mathbb{1}$$</p>\n<p>The action of $P_0$ on $\\ket \\psi$ is</p>\n<p>$$P_0 \\ket \\psi = \\left(\\ket 0\\bra 0 \\otimes \\mathbb{1}\\right) \\frac{1}{\\sqrt 2}\\big(\\ket{01} - \\ket{10}\\big) =$$</p>\n<p>$$= \\frac{1}{\\sqrt 2} \\big( \\ket 0 \\braket{0|0} \\otimes \\mathbb{1} \\ket{1} - \\ket 0 \\braket{0|1} \\otimes \\mathbb{1} \\ket 0 \\big) = \\frac{1}{\\sqrt 2} \\ket{01}$$</p>\n<p>Similarly, you obtain\n$$P_1 \\ket\\psi = -\\frac{1}{\\sqrt 2} \\ket{10}$$</p>\n<p>Clearly, you have $\\big|P_0 \\ket \\psi\\big| = \\big|P_1 \\ket \\psi\\big| = \\frac{1}{2}$ in this case. Thus, the probabilities of measuring $0$ and $1$ are both $0.5$, with the post-measurement states of system being $\\ket{01}$ and $\\ket{10}$, respectively.</p>\n<blockquote>\n<p>Similar to the case of single-qubit system measurements, the applicability of the formalism above requires the state of the multi-qubit system, $\\ket \\psi$, to be normalized. This is required to ensure that all the probabilities of individual outcomes add up to 1.</p>\n</blockquote>\n<h2>🔎 Analyze</h2>\n<h3>Partial measurement probabilities for the Hardy state</h3>\n<p>Consider a 2-qubit system in the state $\\ket \\psi = \\frac{1}{\\sqrt{12}} \\big(3\\ket{00} + \\ket{01} + \\ket{10} + \\ket{11}\\big)$.</p>\n<p>If only the first qubit is measured in the computational basis, what are the probabilities of the outcomes, and the post-measurement states of the system?</p>\n<details>\n<summary><b>Solution</b></summary>\nA measurement outcome of $0$ on the first qubit corresponds to the projection operator $P_0 = \\ket{0}\\bra{ 0} \\otimes \\mathbb{1}$. Applying it to the state $\\ket \\psi$ gives you\n$$\\big|P_0 \\ket{\\psi}\\big|^2 = \\big|\\frac{1}{\\sqrt{12}} \\left(3\\ket {00} + \\ket{01}\\right) \\big|^2 = \\frac{5}{6}$$\nand\n$$\\frac{P_0 \\ket{\\psi}}{\\big|P_0 \\ket{\\psi}\\big|} = \\frac{1}{\\sqrt{10}} \\left( 3\\ket{00} + \\ket{01}\\right)$$\n<p>Similarly, $P_1 = \\ket{1} \\bra{ 1 } \\otimes \\mathbb{1}$ is the projector corresponding to a measurement outcome of $1$ on the first qubit. Applying $P_1$ on $\\ket{\\psi}$ gives us $\\big|P_1 \\ket{\\psi}\\big|^2 = \\frac{1}{6}$ and</p>\n<p>$$\\frac{P_1 \\ket{\\psi}}{\\big|P_1 \\ket{\\psi}\\big|} = \\frac{1}{\\sqrt{2}} \\left(\\ket{10} + \\ket{11}\\right)$$</p>\n<table>\n <tr>\n <th>Measurement outcome</th>\n <th>Probability of outcome</th>\n <th>Post-measurement state</th>\n </tr>\n <tr>\n <td>$0$</td>\n <td>$\\frac{5}{6}$</td>\n <td>$\\frac{1}{\\sqrt{10}} \\left( 3\\ket{00} + \\ket{01}\\right)$</td>\n </tr>\n <tr>\n <td>$1$</td>\n <td>$\\frac{1}{6}$</td>\n <td>$\\frac{1}{\\sqrt{2}} \\left(\\ket{10} + \\ket{11}\\right)$</td>\n </tr>\n</table>\n</details>"
3471
3471
  }
3472
3472
  ]
3473
3473
  },
@@ -3478,7 +3478,7 @@ export default {
3478
3478
  "items": [
3479
3479
  {
3480
3480
  "type": "text-content",
3481
- "content": "<p>In this demo, we show that the simulated outcome probabilities and post-measurement outcomes match the theoretical values obtained using the projection operators as described above.\nWe use the Hardy state $\\ket \\psi = \\frac{1}{\\sqrt{12}} \\big(3\\ket{00} + \\ket{01} + \\ket{10} + \\ket{11}\\big)$ from the previous exercise and do a computational basis measurement on the first qubit for this purpose.</p>\n<p>The simulated and theoretical measurement probabilities are not expected to match exactly, but should be close to each other, since measurement is probabilistic. However, the post-measurement states from the simulation should match the expected states calculated in the exercise precisely, since partial state collapse is not a probabilistic process.</p>\n"
3481
+ "content": "<p>This demo shows that the simulated outcome probabilities and post-measurement outcomes match the theoretical values obtained using the projection operators as described above. It uses the Hardy state $\\ket \\psi = \\frac{1}{\\sqrt{12}} \\big(3\\ket{00} + \\ket{01} + \\ket{10} + \\ket{11}\\big)$ from the previous exercise and do a computational basis measurement on the first qubit for this purpose.</p>\n<p>The simulated and theoretical measurement probabilities aren't expected to match exactly, but should be close to each other, since measurement is probabilistic. However, the post-measurement states from the simulation should match the expected states calculated in the exercise precisely, since partial state collapse isn't a probabilistic process.</p>\n"
3482
3482
  },
3483
3483
  {
3484
3484
  "type": "example",
@@ -3487,7 +3487,7 @@ export default {
3487
3487
  },
3488
3488
  {
3489
3489
  "type": "text-content",
3490
- "content": "<p>In certain situations, it is possible to distinguish between orthogonal states of multi-qubit systems using partial measurements, as illustrated in the next exercise.</p>\n"
3490
+ "content": "<p>In certain situations, it's possible to distinguish between orthogonal states of multi-qubit systems using partial measurements, as illustrated in the next exercise.</p>\n"
3491
3491
  }
3492
3492
  ]
3493
3493
  },
@@ -3509,7 +3509,7 @@ export default {
3509
3509
  "items": [
3510
3510
  {
3511
3511
  "type": "text-content",
3512
- "content": "<p>Since the state of the first qubit is different in these states ($\\ket +$ and $\\ket -$, respectively), it is sufficient to measure only the first qubit in the Pauli X basis in order to distinguish the two states. Furthermore, this measurement will not change the state of the system, since the post-projection state is identical to the original state regardless of the input state.</p>\n"
3512
+ "content": "<p>Since the state of the first qubit is different in these states ($\\ket +$ and $\\ket -$, respectively), it's sufficient to measure only the first qubit in the Pauli X basis in order to distinguish the two states. Furthermore, this measurement won't change the state of the system, since the post-projection state is identical to the original state regardless of the input state.</p>\n"
3513
3513
  },
3514
3514
  {
3515
3515
  "type": "solution",
@@ -3526,7 +3526,7 @@ export default {
3526
3526
  "items": [
3527
3527
  {
3528
3528
  "type": "text-content",
3529
- "content": "<p>Entanglement has an effect on the measurement statistics of the system. If two qubits are entangled, then their measurement outcomes will be correlated, while separable states (which are by definition not entangled) have uncorrelated measurement outcomes.</p>\n<blockquote>\n<p>It is useful to revisit the concepts of entanglement and separable states, which were introduced in the Multi-Qubit Systems kata. Consider a system of $n&gt;1$ qubits, which we divide into two parts: A, consisting of $m$ qubits, and B, consisting of the remaining $n-m$ qubits. We say that the state $\\ket \\psi$ of the entire system is separable if it can be expressed as a tensor product of the states of parts A and B:\n$$\\ket \\psi = \\ket {\\phi_A} \\otimes \\ket{\\phi_B}$$\nHere $\\ket{\\phi_A}$ and $\\ket{\\phi_B}$ are wave functions that describe parts $A$ and $B$, respectively. If it is not possible to express $\\ket \\psi$ in such a form, then we say that system A is entangled with system B.</p>\n</blockquote>\n<p>Consider a measurement on the subsystem $A$ of a separable state. Let the measurement be done in a basis $\\{ \\ket{b_0},\\dotsc,\\ket{b_{2^m-1}}\\}$. According to the projection formalism, a projection operator $P_i = \\ket{b_i}\\bra{b_i} \\otimes \\mathbb{1}$ is chosen randomly. The corresponding post-measurement state of the system is then given by</p>\n<p>$$\\ket{\\psi}_{i} \\equiv \\frac{P_i \\ket{\\psi}}{\\big|P_i \\ket{\\psi}\\big|}\n= \\frac{ \\ket{b_i} \\braket{b_i|\\phi_A} \\otimes \\ket{\\phi_B} }{\\big| \\ket{b_i}\\braket{b_i|\\phi_A} \\otimes \\ket {\\phi_B} \\big|}=$$</p>\n<p>$$= \\frac{\\braket{b_i|\\phi_A} \\cdot \\ket{b_i} \\otimes \\ket {\\phi_B}}{\\big|\\ket{b_i}\\big| \\cdot \\braket{b_i|\\phi_A} \\cdot \\big| \\ket {\\phi_B}\\big|}\n= \\ket{b_i} \\otimes \\ket{\\phi_B}$$</p>\n<p>Thus, the state of subsystem $B$ after the measurement is $\\ket{\\phi_B}$ independently of the outcome $i$ of the measurement on the first qubit. The results of a subsequent measurement on subsystem $B$, including outcome probabilities, will be independent of the result of the first measurement. In other words, the outcomes of the two measurements will be uncorrelated.</p>\n<p>On the other hand, if the system is entangled, then the measurement outcomes will be correlated, in a manner dictated by the bases chosen for the measurements on the two subsystems. The following exercise illustrates this phenomenon.</p>\n<h2>🔎 Analyze</h2>\n<h3>Sequential measurements on an entangled state and a separable state</h3>\n<p>Consider two two-qubit states:</p>\n<ul>\n<li>The Bell state $\\ket{\\Phi^{+}} = \\frac{1}{\\sqrt{2}} \\big (\\ket{00} + \\ket{11}\\big)$.</li>\n<li>A state $\\ket \\Theta = \\frac{1}{2} \\big( \\ket{00} + \\ket{01} + \\ket{10} + \\ket{11} \\big)$.</li>\n</ul>\n<p>For both states, consider a measurement on the first qubit, followed by a measurement on the second qubit, both done in the computational basis. For which state can we expect the measurement outcomes to be correlated? Verify by calculating the sequential measurement probabilities explicitly for both states.</p>\n<details>\n<summary><b>Solution</b></summary>\n<p><b>The Bell state</b>: If the measurement outcome on the first qubit is $0$, a subsequent measurement on the second qubit <i>always</i> results in an outcome of $0$, with probability $1$. Similarly, if the measurement outcome on the first qubit is $1$, then the second qubit measurement always results in $1$. Thus, sequential measurements are perfectly <b>correlated</b>.</p>\n<p><b>Separable state $\\ket \\Theta$</b>: Irrespective of whether the first qubit measurement outcome is $0$ of $1$ (each of which occurs with a probability of $0.5$), a subsequent measurement on the second qubit results in an outcome of $0$ or $1$ (both with a probability of $0.5$). Thus, sequential measurements are perfectly <b>uncorrelated</b>.</p>\n<p>This aligns with the fact that the Bell state is entangled, while the state $\\ket{\\Theta}$ is separable and can be expressed as $\\ket \\Theta = \\ket + \\otimes \\ket +$.</p>\n</details>\n<h2>State Modification Using Partial Measurements</h2>\n<p>For certain multi-qubit systems prepared in a superposition state, it is possible to use partial measurements to collapse a part of the system to some desired state.</p>\n"
3529
+ "content": "<p>Entanglement has an effect on the measurement statistics of the system. If two qubits are entangled, then their measurement outcomes will be correlated, while separable states (which are by definition not entangled) have uncorrelated measurement outcomes.</p>\n<blockquote>\n<p>It's useful to revisit the concepts of entanglement and separable states, which were introduced in the Multi-Qubit Systems kata. Consider a system of $n&gt;1$ qubits, which is divided into two parts: A, consisting of $m$ qubits, and B, consisting of the remaining $n-m$ qubits. The state $\\ket \\psi$ of the entire system is separable if it can be expressed as a tensor product of the states of parts A and B:\n$$\\ket \\psi = \\ket {\\phi_A} \\otimes \\ket{\\phi_B}$$\nHere $\\ket{\\phi_A}$ and $\\ket{\\phi_B}$ are wave functions that describe parts $A$ and $B$, respectively. If it isn't possible to express $\\ket \\psi$ in such a form, then system A is entangled with system B.</p>\n</blockquote>\n<p>Consider a measurement on the subsystem $A$ of a separable state. Let the measurement be done in a basis $\\{ \\ket{b_0},\\dotsc,\\ket{b_{2^m-1}}\\}$. According to the projection formalism, a projection operator $P_i = \\ket{b_i}\\bra{b_i} \\otimes \\mathbb{1}$ is chosen randomly. The corresponding post-measurement state of the system is then given by</p>\n<p>$$\\ket{\\psi}_{i} \\equiv \\frac{P_i \\ket{\\psi}}{\\big|P_i \\ket{\\psi}\\big|}\n= \\frac{ \\ket{b_i} \\braket{b_i|\\phi_A} \\otimes \\ket{\\phi_B} }{\\big| \\ket{b_i}\\braket{b_i|\\phi_A} \\otimes \\ket {\\phi_B} \\big|}=$$</p>\n<p>$$= \\frac{\\braket{b_i|\\phi_A} \\cdot \\ket{b_i} \\otimes \\ket {\\phi_B}}{\\big|\\ket{b_i}\\big| \\cdot \\braket{b_i|\\phi_A} \\cdot \\big| \\ket {\\phi_B}\\big|}\n= \\ket{b_i} \\otimes \\ket{\\phi_B}$$</p>\n<p>Thus, the state of subsystem $B$ after the measurement is $\\ket{\\phi_B}$ independently of the outcome $i$ of the measurement on the first qubit. The results of a subsequent measurement on subsystem $B$, including outcome probabilities, will be independent of the result of the first measurement. In other words, the outcomes of the two measurements will be uncorrelated.</p>\n<p>On the other hand, if the system is entangled, then the measurement outcomes will be correlated, in a manner dictated by the bases chosen for the measurements on the two subsystems. The following exercise illustrates this phenomenon.</p>\n<h2>🔎 Analyze</h2>\n<h3>Sequential measurements on an entangled state and a separable state</h3>\n<p>Consider two two-qubit states:</p>\n<ul>\n<li>The Bell state $\\ket{\\Phi^{+}} = \\frac{1}{\\sqrt{2}} \\big (\\ket{00} + \\ket{11}\\big)$.</li>\n<li>A state $\\ket \\Theta = \\frac{1}{2} \\big( \\ket{00} + \\ket{01} + \\ket{10} + \\ket{11} \\big)$.</li>\n</ul>\n<p>For both states, consider a measurement on the first qubit, followed by a measurement on the second qubit, both done in the computational basis. For which state can you expect the measurement outcomes to be correlated? Verify by calculating the sequential measurement probabilities explicitly for both states.</p>\n<details>\n<summary><b>Solution</b></summary>\n<p><b>The Bell state</b>: If the measurement outcome on the first qubit is $0$, a subsequent measurement on the second qubit <i>always</i> results in an outcome of $0$, with probability $1$. Similarly, if the measurement outcome on the first qubit is $1$, then the second qubit measurement always results in $1$. Thus, sequential measurements are perfectly <b>correlated</b>.</p>\n<p><b>Separable state $\\ket \\Theta$</b>: Irrespective of whether the first qubit measurement outcome is $0$ of $1$ (each of which occurs with a probability of $0.5$), a subsequent measurement on the second qubit results in an outcome of $0$ or $1$ (both with a probability of $0.5$). Thus, sequential measurements are perfectly <b>uncorrelated</b>.</p>\n<p>This aligns with the fact that the Bell state is entangled, while the state $\\ket{\\Theta}$ is separable and can be expressed as $\\ket \\Theta = \\ket + \\otimes \\ket +$.</p>\n</details>\n<h2>State Modification Using Partial Measurements</h2>\n<p>For certain multi-qubit systems prepared in a superposition state, it's possible to use partial measurements to collapse a part of the system to some desired state.</p>\n"
3530
3530
  }
3531
3531
  ]
3532
3532
  },
@@ -3536,7 +3536,7 @@ export default {
3536
3536
  "title": "State Selection Using Partial Measurements",
3537
3537
  "description": {
3538
3538
  "type": "text-content",
3539
- "content": "<p><strong>Input</strong>:</p>\n<ol>\n<li>A 2-qubit system in the state\n$$\n\\ket{\\psi} = \\frac{1}{\\sqrt{2}} \\ket{0} \\otimes ( a \\ket{0} + b\\ket{1}) + \\frac{1}{\\sqrt{2}} \\ket{1} \\otimes (b\\ket{0} + a \\ket{1}),\n$$\nwhere the constants $a$ and $b$ satisfying $|a|^2 + |b|^2 = 1$ are unknown.</li>\n<li>An integer $ind$ which is either $0$ or $1$.</li>\n</ol>\n<p><strong>Goal</strong>:</p>\n<ul>\n<li>If $ind$ equals 0, convert the state of the second qubit into $a\\ket{0} + b\\ket{1}$</li>\n<li>If $ind$ equals 1, convert the state of the second qubit into $b\\ket{0} + a\\ket{1}$.</li>\n</ul>\n<p>The state of the first qubit at the end does not matter (it has to be not entangled with the second qubit).</p>\n"
3539
+ "content": "<p><strong>Input</strong>:</p>\n<ol>\n<li>A 2-qubit system in the state\n$$\n\\ket{\\psi} = \\frac{1}{\\sqrt{2}} \\ket{0} \\otimes ( a \\ket{0} + b\\ket{1}) + \\frac{1}{\\sqrt{2}} \\ket{1} \\otimes (b\\ket{0} + a \\ket{1}),\n$$\nwhere the constants $a$ and $b$ satisfying $|a|^2 + |b|^2 = 1$ are unknown.</li>\n<li>An integer $ind$ which is either $0$ or $1$.</li>\n</ol>\n<p><strong>Goal</strong>:</p>\n<ul>\n<li>If $ind$ equals 0, convert the state of the second qubit into $a\\ket{0} + b\\ket{1}$</li>\n<li>If $ind$ equals 1, convert the state of the second qubit into $b\\ket{0} + a\\ket{1}$.</li>\n</ul>\n<p>The state of the first qubit at the end doesn't matter (it has to be not entangled with the second qubit).</p>\n"
3540
3540
  },
3541
3541
  "sourceIds": [
3542
3542
  "multi_qubit_measurements__state_modification__Verification.qs",
@@ -3548,7 +3548,7 @@ export default {
3548
3548
  "items": [
3549
3549
  {
3550
3550
  "type": "text-content",
3551
- "content": "<p>We note that if we measure the first qubit in the computational basis, then an outcome of $0$ collapses the second qubit to the state $a\\ket 0 + b \\ket 1$, while an outcome of $1$ collapses the second qubit to the state $b\\ket 0 + a \\ket 1$.</p>\n<p>Thus, if $ind=0$ and we measure $0$ or if $ind=1$ and we measure $1$, then after the measurement the second qubit will be in the desired state. On the other hand, if $ind=1$ and we measure $0$, or if $ind=0$ and we measure $1$, then the state of the second qubit after the measurement is not what we're looking for, but we can adjust it using the Pauli X gate.</p>\n"
3551
+ "content": "<p>Note that if you measure the first qubit in the computational basis, then an outcome of $0$ collapses the second qubit to the state $a\\ket 0 + b \\ket 1$, while an outcome of $1$ collapses the second qubit to the state $b\\ket 0 + a \\ket 1$.</p>\n<p>Thus, if $ind=0$ and you measure $0$ or if $ind=1$ and we measure $1$, then after the measurement the second qubit will be in the desired state. On the other hand, if $ind=1$ and you measure $0$, or if $ind=0$ and you measure $1$, then the state of the second qubit after the measurement isn't what you're looking for, but you can adjust it using the Pauli X gate.</p>\n"
3552
3552
  },
3553
3553
  {
3554
3554
  "type": "solution",
@@ -3565,7 +3565,7 @@ export default {
3565
3565
  "items": [
3566
3566
  {
3567
3567
  "type": "text-content",
3568
- "content": "<p>Any multi-qubit state can be prepared from the $\\ket{0...0}$ state using an appropriate combination of quantum gates.\nHowever, sometimes it is easier and more efficient to prepare a state using partial measurements.\nYou could prepare a simpler state involving additional qubits, which, when measured, result in a collapse of the remaining qubits to the desired state with a high probability. This is called <strong>post-selection</strong>, and is particularly useful if it is easier to prepare the pre-measurement state with the extra qubits than to prepare the desired state directly using unitary gates alone. This is demonstrated by the following exercise.</p>\n"
3568
+ "content": "<p>Any multi-qubit state can be prepared from the $\\ket{0...0}$ state using an appropriate combination of quantum gates.\nHowever, sometimes it's easier and more efficient to prepare a state using partial measurements.\nYou could prepare a simpler state involving additional qubits, which, when measured, result in a collapse of the remaining qubits to the desired state with a high probability. This is called <strong>post-selection</strong>, and is particularly useful if it's easier to prepare the pre-measurement state with the extra qubits than to prepare the desired state directly using unitary gates alone. This is demonstrated by the following exercise.</p>\n"
3569
3569
  }
3570
3570
  ]
3571
3571
  },
@@ -3575,7 +3575,7 @@ export default {
3575
3575
  "title": "State Preparation Using Partial Measurements",
3576
3576
  "description": {
3577
3577
  "type": "text-content",
3578
- "content": "<p><strong>Input:</strong> Two qubits in the state $\\ket{00}$.</p>\n<p><strong>Goal:</strong> Modify the qubits to the state $\\frac{1}{\\sqrt{3}} \\big(\\ket{00} + \\ket{01} + \\ket{10}\\big)$ using post-selection.</p>\n<br/>\n<details>\n <summary><b>Need a hint?</b></summary>\n Consider a 3-qubit state $\\frac{1}{2}(\\ket{00} + \\ket{01} + \\ket{11}) \\otimes \\ket{0} + \\frac{1}{2} \\ket{11} \\otimes \\ket{1}$.\n What happens when one measures the third qubit?\n</details>\n"
3578
+ "content": "<p><strong>Input:</strong> Two qubits in the state $\\ket{00}$.</p>\n<p><strong>Goal:</strong> Modify the qubits to the state $\\frac{1}{\\sqrt{3}} \\big(\\ket{00} + \\ket{01} + \\ket{10}\\big)$ using post-selection.</p>\n<br/>\n<details>\n <summary><b>Need a hint?</b></summary>\n Consider a 3-qubit state $\\frac{1}{2}(\\ket{00} + \\ket{01} + \\ket{11}) \\otimes \\ket{0} + \\frac{1}{2} \\ket{11} \\otimes \\ket{1}$.\n What happens when you measure the third qubit?\n</details>\n"
3579
3579
  },
3580
3580
  "sourceIds": [
3581
3581
  "multi_qubit_measurements__state_preparation__Verification.qs",
@@ -3587,7 +3587,7 @@ export default {
3587
3587
  "items": [
3588
3588
  {
3589
3589
  "type": "text-content",
3590
- "content": "<p>While it is possible to prepare the state $\\ket \\psi$ directly using unitary rotations, it is simpler to use post-selection for preparing it.</p>\n<p>Initially we will prepare an equal superposition of all basis states on the first two qubits by applying the <strong>H</strong> gate to each of them, and allocate an extra qubit in the $\\ket{0}$ state:\n$$\\frac{1}{2} \\big(\\ket{00} + \\ket{01} + \\ket{10} + \\ket{11}\\big) \\otimes \\ket 0$$</p>\n<p>The state of the first two qubits is a superposition of the state we want to prepare and the $\\ket{11}$ state that we would like to discard.</p>\n<p>Now, we want to separate the first three basis states from the last one and to store this separation in the extra qubit.\nFor example, we can keep the state of the extra qubit $\\ket{0}$ for the basis states that we want to keep, and switch it to $\\ket{1}$ for the basis states that we would like to discard.\nA $CCNOT$ gate can do this, with the first two qubits used as control qubits and the extra qubit as target.\nWhen the gate is applied, the state of the extra qubit will only change to $\\ket{1}$ if both control qubits are in the $\\ket{11}$ state, which marks exactly the state that we want to discard:</p>\n<p>$$CCNOT\\frac{1}{2} \\big(\\ket{00\\textbf{0}} + \\ket{01\\textbf{0}} + \\ket{10\\textbf{0}} + \\ket{11\\textbf{0}}\\big) =\n\\frac{1}{2}\\big(\\ket{00} + \\ket{01} + \\ket{10} \\big) \\otimes \\ket{\\textbf{0}} + \\frac{1}{2}\\ket{11} \\otimes \\ket{\\textbf{1}} $$</p>\n<p>Finally, we measure just the extra qubit; this causes a partial collapse of the system to the state defined by the measurement result:</p>\n<ul>\n<li>If the result is $\\ket{0}$, the first two qubits collapse to a state that is a linear combination of basis states which had the extra qubit in state $\\ket{0}$, i.e., they end up in the target state $\\frac{1}{\\sqrt3}\\big(\\ket{00} + \\ket{01} + \\ket{10}\\big)$.</li>\n<li>If the result is $\\ket{1}$, the first two qubits collapse to a state $\\ket{11}$, so our goal is not achieved. The good thing is, this only happens in 25% of the cases, and we can just reset our qubits to the $\\ket{00}$ state and try again.</li>\n</ul>\n<blockquote>\n<p>Q# has a built-in <a href=\"https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/conditionalloops#repeat-expression\" target=\"_blank\">repeat-until-success (RUS) loop</a>, which comes in handy in this case.</p>\n<ul>\n<li>We will describe the main operations (applying $H$ and $CCNOT$ gates and the measurement) in the <code>repeat</code> part of the loop, which specifies its body.</li>\n<li><code>until</code> section specifies the condition which will break the loop. In this case the result of the measurement needs to be <code>Zero</code> to indicate our success.</li>\n<li>Finally, the <code>fixup</code> section allows us to clean up the results of the loop body execution before trying again if the success criteria is not met. In this case we reset the first two qubits back to the $\\ket{00}$ state.</li>\n</ul>\n</blockquote>\n"
3590
+ "content": "<p>While it's possible to prepare the state $\\ket \\psi$ directly using unitary rotations, it's simpler to use post-selection for preparing it.</p>\n<p>Initially, you prepare an equal superposition of all basis states on the first two qubits by applying the $H$ gate to each of them, and allocate an extra qubit in the $\\ket{0}$ state:\n$$\\frac{1}{2} \\big(\\ket{00} + \\ket{01} + \\ket{10} + \\ket{11}\\big) \\otimes \\ket 0$$</p>\n<p>The state of the first two qubits is a superposition of the state you want to prepare and the $\\ket{11}$ state that you want to discard.</p>\n<p>Now, you want to separate the first three basis states from the last one and to store this separation in the extra qubit.\nFor example, you can keep the state of the extra qubit $\\ket{0}$ for the basis states that you want to keep, and switch it to $\\ket{1}$ for the basis states that you want to discard.\nA $CCNOT$ gate can do this, with the first two qubits used as control qubits and the extra qubit as target.\nWhen the gate is applied, the state of the extra qubit will only change to $\\ket{1}$ if both control qubits are in the $\\ket{11}$ state, which marks exactly the state that you want to discard:</p>\n<p>$$CCNOT\\frac{1}{2} \\big(\\ket{00\\textbf{0}} + \\ket{01\\textbf{0}} + \\ket{10\\textbf{0}} + \\ket{11\\textbf{0}}\\big) =\n\\frac{1}{2}\\big(\\ket{00} + \\ket{01} + \\ket{10} \\big) \\otimes \\ket{\\textbf{0}} + \\frac{1}{2}\\ket{11} \\otimes \\ket{\\textbf{1}} $$</p>\n<p>Finally, you measure just the extra qubit; this causes a partial collapse of the system to the state defined by the measurement result:</p>\n<ul>\n<li>If the result is $\\ket{0}$, the first two qubits collapse to a state that is a linear combination of basis states which had the extra qubit in state $\\ket{0}$, that is, they end up in the target state $\\frac{1}{\\sqrt3}\\big(\\ket{00} + \\ket{01} + \\ket{10}\\big)$.</li>\n<li>If the result is $\\ket{1}$, the first two qubits collapse to a state $\\ket{11}$, so your goal is not achieved. The good thing is, this only happens in 25% of the cases, and you can just reset our qubits to the $\\ket{00}$ state and try again.</li>\n</ul>\n<blockquote>\n<p>Q# has a built-in <a href=\"https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/conditionalloops#repeat-expression\" target=\"_blank\">repeat-until-success (RUS) loop</a>, which comes in handy in this case.</p>\n<ul>\n<li>The main operations (applying $H$ and $CCNOT$ gates and the measurement) are described in the <code>repeat</code> part of the loop, which specifies its body.</li>\n<li><code>until</code> section specifies the condition which will break the loop. In this case, the result of the measurement needs to be <code>Zero</code> to indicate your success.</li>\n<li>Finally, the <code>fixup</code> section allows you to clean up the results of the loop body execution before trying again if the success criteria isn't met. In this case, you reset the first two qubits back to the $\\ket{00}$ state.</li>\n</ul>\n</blockquote>\n"
3591
3591
  },
3592
3592
  {
3593
3593
  "type": "solution",
@@ -3604,7 +3604,7 @@ export default {
3604
3604
  "items": [
3605
3605
  {
3606
3606
  "type": "text-content",
3607
- "content": "<p>Joint measurements, also known as Pauli measurements, are a generalization of two-outcome measurements to multiple qubits and other bases. In Q#, joint measurements in Pauli bases are implemented using the <code>Measure</code> operation. Let's review single-qubit measurements in a different light before discussing joint measurements.</p>\n<h2>Single-Qubit Pauli Measurements</h2>\n<p>For single-qubit systems, any measurement corresponding to an orthogonal basis can be associated with a Hermitian matrix with eigenvalues $\\pm 1$. The possible measurement outcomes (represented as <code>Result</code> in Q#) are the eigenvalues of the Hermitian matrix, and the corresponding projection matrices for the measurement are the projection operators onto the <em>eigenspaces</em> corresponding to the eigenvalues.</p>\n<p>For example, consider the computational basis measurement, which can result in outcomes <code>Zero</code> or <code>One</code> corresponding to states $\\ket 0$ and $\\ket 1$. This measurement is associated with the Pauli Z operator, which is given by</p>\n<p>$$Z = \\begin{bmatrix} 1 &amp; 0 \\\\ 0 &amp; -1\\end{bmatrix} = \\ket{0}\\bra{0} - \\ket{1}\\bra{1}$$</p>\n<p>The $Z$ operator has two eigenvalues, $1$ and $-1$, with corresponding eigenvectors $\\ket{0}$ and $\\ket{1}$. A $Z$-measurement is then a measurement in the $\\{\\ket{0},\\ket{1}\\}$ basis, with the measurement outcomes being $1$ and $-1$, respectively. In Q#, by convention, an eigenvalue of $1$ corresponds to a <code>Result</code> of <code>Zero</code>, while an eigenvalue of $-1$ corresponds to a <code>Result</code> of <code>One</code>.</p>\n<p>Similarly, one can implement measurements corresponding to the Pauli X and Y operators. We summarize the various properties below:</p>\n<table>\n <tr>\n <th>Pauli Operator</th>\n <th>Matrix</th>\n <th>Eigenvalue</th>\n <th>Eigenvector/post-measurement state</th>\n <th>Measurement Result in Q#</th>\n </tr>\n <tr>\n <td rowspan=\"2\">$X$</td>\n <td rowspan=\"2\">$\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$</td>\n <td>+1</td>\n <td>$\\ket{+}$</td>\n <td>Zero</td>\n </tr><tr>\n <td>-1</td>\n <td>$\\ket{-}$</td>\n <td>One</td>\n </tr>\n <tr>\n <td rowspan=\"2\">$Y$</td>\n <td rowspan=\"2\">$\\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}$</td>\n <td>+1</td>\n <td>$\\ket{i}$</td>\n <td>Zero</td>\n </tr><tr>\n <td>-1</td>\n <td>$\\ket{-i}$</td>\n <td>One</td>\n </tr>\n <tr>\n <td rowspan=\"2\">$Z$</td>\n <td rowspan=\"2\">$\\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}$</td>\n <td>+1</td>\n <td>$\\ket{0}$</td>\n <td>Zero</td>\n </tr><tr>\n <td>-1</td>\n <td>$\\ket{1}$</td>\n <td>One</td>\n </tr>\n</table>\n<p>In general, any measurement on a single qubit which results in two outcomes corresponds to the Hermitian operator $U Z U^\\dagger$, for some $2\\times 2$ unitary matrix $U$.</p>\n<p>Joint measurements are a generalization of this principle for multi-qubit matrices.</p>\n<h2>Parity Measurements</h2>\n<p>The simplest joint measurement is a parity measurement. A parity measurement treats computational basis vectors differently depending on whether the number of 1s in the basis vector is even or odd.</p>\n<p>For example, the operator $Z\\otimes Z$, or $ZZ$ in short, is the parity measurement operator for a two-qubit system. The eigenvalues $1$ and $-1$ correspond to the subspaces spanned by basis vectors $\\{ \\ket{00}, \\ket{11} \\}$ and $\\{ \\ket{01}, \\ket{10} \\}$, respectively. That is, when a $ZZ$ measurement results in a <code>Zero</code> (i.e., the eigenvalue $+1$), the post-measurement state is a superposition of only those computational basis vectors which have an even number of 1s. On the other hand, a result of <code>One</code> corresponds to a post-measurement state with only computational basis vectors which have an odd number of 1s.</p>\n<blockquote>\n<p>Let's see what happens to various two-qubit states after the parity measurement. The $Z \\otimes Z$ matrix for two qubits is:</p>\n<p>$$\nZ \\otimes Z =\n\\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; -1 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; -1 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 1 \n\\end{bmatrix}\n$$</p>\n<p>When this transformation is applied to a basis state $\\ket{00}$, we get</p>\n<p>$$\n\\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; -1 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; -1 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 1 \n\\end{bmatrix}\n\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix}\n$$</p>\n<p>Comparing this to the characteristic equation for eigenvectors of $Z \\otimes Z$ given by\n$ Z \\otimes Z \\ket{\\psi} = \\lambda \\ket{\\psi}$,\nit is easy to see that $\\ket{00}$ belongs to the $+1$ eigenspace, hence the $Z \\otimes Z$ measurement will return <code>Zero</code> and leave the state unchanged.</p>\n<p>Similarly, it can easily be verified that $\\ket{11}$ also belongs to $+1$ eigenspace, while $\\ket{01}$ and $\\ket{10}$ belong to the $-1$ eigenspace.</p>\n<p>Now, what happens if we apply a $Z \\otimes Z$ measurement to a superposition state $\\alpha \\ket{00} + \\beta \\ket{11}$? We can see that</p>\n<p>$$\n\\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; -1 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; -1 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 1 \n\\end{bmatrix}\n\\begin{bmatrix} \\alpha \\\\ 0 \\\\ 0 \\\\ \\beta \\end{bmatrix} =\n\\begin{bmatrix} \\alpha \\\\ 0 \\\\ 0 \\\\ \\beta \\end{bmatrix}\n$$</p>\n<p>So this state also belongs to the $+1$ eigenspace, and measuring it will return <code>Zero</code> and leave the state unchanged. Similarly, we can verify that an $\\alpha \\ket{01} + \\beta \\ket{10}$ state belongs to the $-1$ eigenspace, and measuring it will return <code>One</code> without changing the state.</p>\n</blockquote>\n<p>Similarly, a parity measurement on a higher number of qubits can be implemented using a $Z \\otimes \\dotsc \\otimes Z$ measurement.</p>\n"
3607
+ "content": "<p>Joint measurements, also known as Pauli measurements, are a generalization of two-outcome measurements to multiple qubits and other bases. In Q#, joint measurements in Pauli bases are implemented using the <code>Measure</code> operation. Let's review single-qubit measurements in a different light before discussing joint measurements.</p>\n<h2>Single-Qubit Pauli Measurements</h2>\n<p>For single-qubit systems, any measurement corresponding to an orthogonal basis can be associated with a Hermitian matrix with eigenvalues $\\pm 1$. The possible measurement outcomes (represented as <code>Result</code> in Q#) are the eigenvalues of the Hermitian matrix, and the corresponding projection matrices for the measurement are the projection operators onto the <em>eigenspaces</em> corresponding to the eigenvalues.</p>\n<p>For example, consider the computational basis measurement, which can result in outcomes <code>Zero</code> or <code>One</code> corresponding to states $\\ket 0$ and $\\ket 1$. This measurement is associated with the Pauli Z operator, which is given by</p>\n<p>$$Z = \\begin{bmatrix} 1 &amp; 0 \\\\ 0 &amp; -1\\end{bmatrix} = \\ket{0}\\bra{0} - \\ket{1}\\bra{1}$$</p>\n<p>The $Z$ operator has two eigenvalues, $1$ and $-1$, with corresponding eigenvectors $\\ket{0}$ and $\\ket{1}$. A $Z$-measurement is then a measurement in the $\\{\\ket{0},\\ket{1}\\}$ basis, with the measurement outcomes being $1$ and $-1$, respectively. In Q#, by convention, an eigenvalue of $1$ corresponds to a <code>Result</code> of <code>Zero</code>, while an eigenvalue of $-1$ corresponds to a <code>Result</code> of <code>One</code>.</p>\n<p>Similarly, one can implement measurements corresponding to the Pauli X and Y operators. This table summarizes the various properties:</p>\n<table>\n <tr>\n <th>Pauli Operator</th>\n <th>Matrix</th>\n <th>Eigenvalue</th>\n <th>Eigenvector/post-measurement state</th>\n <th>Measurement Result in Q#</th>\n </tr>\n <tr>\n <td rowspan=\"2\">$X$</td>\n <td rowspan=\"2\">$\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$</td>\n <td>+1</td>\n <td>$\\ket{+}$</td>\n <td>Zero</td>\n </tr><tr>\n <td>-1</td>\n <td>$\\ket{-}$</td>\n <td>One</td>\n </tr>\n <tr>\n <td rowspan=\"2\">$Y$</td>\n <td rowspan=\"2\">$\\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}$</td>\n <td>+1</td>\n <td>$\\ket{i}$</td>\n <td>Zero</td>\n </tr><tr>\n <td>-1</td>\n <td>$\\ket{-i}$</td>\n <td>One</td>\n </tr>\n <tr>\n <td rowspan=\"2\">$Z$</td>\n <td rowspan=\"2\">$\\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}$</td>\n <td>+1</td>\n <td>$\\ket{0}$</td>\n <td>Zero</td>\n </tr><tr>\n <td>-1</td>\n <td>$\\ket{1}$</td>\n <td>One</td>\n </tr>\n</table>\n<p>In general, any measurement on a single qubit which results in two outcomes corresponds to the Hermitian operator $U Z U^\\dagger$, for some $2\\times 2$ unitary matrix $U$.</p>\n<p>Joint measurements are a generalization of this principle for multi-qubit matrices.</p>\n<h2>Parity Measurements</h2>\n<p>The simplest joint measurement is a parity measurement. A parity measurement treats computational basis vectors differently depending on whether the number of 1s in the basis vector is even or odd.</p>\n<p>For example, the operator $Z\\otimes Z$, or $ZZ$ in short, is the parity measurement operator for a two-qubit system. The eigenvalues $1$ and $-1$ correspond to the subspaces spanned by basis vectors $\\{ \\ket{00}, \\ket{11} \\}$ and $\\{ \\ket{01}, \\ket{10} \\}$, respectively. That is, when a $ZZ$ measurement results in a <code>Zero</code> (that is, the eigenvalue $+1$), the post-measurement state is a superposition of only those computational basis vectors which have an even number of 1s. On the other hand, a result of <code>One</code> corresponds to a post-measurement state with only computational basis vectors which have an odd number of 1s.</p>\n<blockquote>\n<p>Let's see what happens to various two-qubit states after the parity measurement. The $Z \\otimes Z$ matrix for two qubits is:</p>\n<p>$$\nZ \\otimes Z =\n\\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; -1 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; -1 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 1 \n\\end{bmatrix}\n$$</p>\n<p>When this transformation is applied to a basis state $\\ket{00}$, you get</p>\n<p>$$\n\\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; -1 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; -1 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 1 \n\\end{bmatrix}\n\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix}\n$$</p>\n<p>Comparing this to the characteristic equation for eigenvectors of $Z \\otimes Z$ given by\n$ Z \\otimes Z \\ket{\\psi} = \\lambda \\ket{\\psi}$,\nit's easy to see that $\\ket{00}$ belongs to the $+1$ eigenspace, hence the $Z \\otimes Z$ measurement will return <code>Zero</code> and leave the state unchanged.</p>\n<p>Similarly, it can easily be verified that $\\ket{11}$ also belongs to $+1$ eigenspace, while $\\ket{01}$ and $\\ket{10}$ belong to the $-1$ eigenspace.</p>\n<p>Now, what happens if you apply a $Z \\otimes Z$ measurement to a superposition state $\\alpha \\ket{00} + \\beta \\ket{11}$? You can see that</p>\n<p>$$\n\\begin{bmatrix}\n 1 &amp; 0 &amp; 0 &amp; 0 \\\\ \n 0 &amp; -1 &amp; 0 &amp; 0 \\\\ \n 0 &amp; 0 &amp; -1 &amp; 0 \\\\ \n 0 &amp; 0 &amp; 0 &amp; 1 \n\\end{bmatrix}\n\\begin{bmatrix} \\alpha \\\\ 0 \\\\ 0 \\\\ \\beta \\end{bmatrix} =\n\\begin{bmatrix} \\alpha \\\\ 0 \\\\ 0 \\\\ \\beta \\end{bmatrix}\n$$</p>\n<p>So this state also belongs to the $+1$ eigenspace, and measuring it will return <code>Zero</code> and leave the state unchanged. Similarly, you can verify that an $\\alpha \\ket{01} + \\beta \\ket{10}$ state belongs to the $-1$ eigenspace, and measuring it will return <code>One</code> without changing the state.</p>\n</blockquote>\n<p>Similarly, a parity measurement on a higher number of qubits can be implemented using a $Z \\otimes \\dotsc \\otimes Z$ measurement.</p>\n"
3608
3608
  }
3609
3609
  ]
3610
3610
  },
@@ -3626,7 +3626,7 @@ export default {
3626
3626
  "items": [
3627
3627
  {
3628
3628
  "type": "text-content",
3629
- "content": "<p>If we were not asked to maintain the state of the qubits, one approach would be to measure both the qubits separately in the computational basis, and check if the result is the same for both the measurements. If the measurement results are equal, the input state must have been a superposition of $\\ket{00}$ and $\\ket{11}$, while different measurement outcomes will imply that the input state must have been a superposition of $\\ket{01}$ and $\\ket{10}$. However, in these measurements we will lose the information about the original superposition states: a state $\\alpha \\ket{00} + \\beta \\ket{11}$ will collapse to either $\\ket{00}$ or $\\ket{11}$, and we won't be able to recover the information about the coefficients $\\alpha$ and $\\beta$.</p>\n<p>We need to measure the <em>parity</em> of the state without collapsing it all the way to the basis states. Pauli measurements can be used for joint measurements involving multiple qubits. For this task we need to do the $Z \\otimes Z$ measurement on both qubits.</p>\n<p>A joint measurement using $Z \\otimes Z$ operator can be thought of as projecting the measured state to one of the two eigenspaces of $Z \\otimes Z$ with $+1$ and $-1$ as the corresponding eigenvalues. The measurement returns <code>Zero</code> if the measured state is projected to the space with an eigenvalue of $+1$, and a result of <code>One</code> if projected to the space with an eigenvalue of $-1$.</p>\n<p>As we've seen in the tutorial, the state $\\alpha \\ket{00} + \\beta \\ket{11}$ is an eigenstate of the $Z \\otimes Z$ operator with the eigenvalue $+1$, and the state $\\alpha \\ket{01} + \\beta \\ket{10}$ is an eigenstate with the eigenvalue $-1$.\nHence, we can use this joint measurement to recognize which of the superposition states we were given while preserving the initial superposition state.</p>\n<p>In Q#, the operation <code>Measure</code> can be used to measure multiple qubits using an array of <code>Pauli</code> constants (<code>PauliI</code>, <code>PauliX</code>, <code>PauliY</code>, or <code>PauliZ</code>) that define the basis for measurement.</p>\n"
3629
+ "content": "<p>If you weren't asked to maintain the state of the qubits, one approach would be to measure both the qubits separately in the computational basis, and check if the result is the same for both the measurements. If the measurement results are equal, the input state must have been a superposition of $\\ket{00}$ and $\\ket{11}$, while different measurement outcomes will imply that the input state must have been a superposition of $\\ket{01}$ and $\\ket{10}$. However, in these measurements you'll lose the information about the original superposition states: a state $\\alpha \\ket{00} + \\beta \\ket{11}$ will collapse to either $\\ket{00}$ or $\\ket{11}$, and you won't be able to recover the information about the coefficients $\\alpha$ and $\\beta$.</p>\n<p>You need to measure the <em>parity</em> of the state without collapsing it all the way to the basis states. Pauli measurements can be used for joint measurements involving multiple qubits. For this task we need to do the $Z \\otimes Z$ measurement on both qubits.</p>\n<p>A joint measurement using $Z \\otimes Z$ operator can be thought of as projecting the measured state to one of the two eigenspaces of $Z \\otimes Z$ with $+1$ and $-1$ as the corresponding eigenvalues. The measurement returns <code>Zero</code> if the measured state is projected to the space with an eigenvalue of $+1$, and a result of <code>One</code> if projected to the space with an eigenvalue of $-1$.</p>\n<p>As you've seen in the tutorial, the state $\\alpha \\ket{00} + \\beta \\ket{11}$ is an eigenstate of the $Z \\otimes Z$ operator with the eigenvalue $+1$, and the state $\\alpha \\ket{01} + \\beta \\ket{10}$ is an eigenstate with the eigenvalue $-1$.\nHence, you can use this joint measurement to recognize which of the superposition states you were given while preserving the initial superposition state.</p>\n<p>In Q#, the operation <code>Measure</code> can be used to measure multiple qubits using an array of <code>Pauli</code> constants (<code>PauliI</code>, <code>PauliX</code>, <code>PauliY</code>, or <code>PauliZ</code>) that define the basis for measurement.</p>\n"
3630
3630
  },
3631
3631
  {
3632
3632
  "type": "solution",
@@ -3643,7 +3643,7 @@ export default {
3643
3643
  "items": [
3644
3644
  {
3645
3645
  "type": "text-content",
3646
- "content": "<p>Joint measurement is a generalization of the measurement in the computational basis.\nPauli measurements can also be generalized to a larger number of qubits. A multi-qubit Pauli measurement corresponds to an operator $M_1 \\otimes \\dotsc \\otimes M_n$, with each $M_i$ being from the set of gates $\\{X,Y,Z,I\\}$. If at least one of the operators is not the identity matrix, then the measurement can result in two outcomes: a <code>Result</code> of <code>Zero</code> corresponding to eigenvalue $+1$ and a <code>Result</code> of <code>One</code> corresponding to the eigenvalue $-1$. The corresponding projection operators are the projections onto the corresponding eigenspaces.</p>\n<p>For example, a Pauli/joint measurement corresponding to the $X\\otimes Z$ operator can be characterized as follows:</p>\n<table>\n <tr>\n <th>Eigenvalue</th>\n <th>Measurement Result in Q#</th>\n <th>Eigenbasis</th>\n <th>Measurement Projector</th>\n </tr>\n <tr>\n <td>$+1$</td>\n <td>Zero</td>\n <td>$\\{ \\ket{0,+}, \\ket{1,-} \\}$</td>\n <td>$P_{+1} = \\ket{0,+}\\bra{0,+} + \\ket{1,-} \\bra{1,-}$</td>\n </tr>\n <tr>\n <td>$-1$</td>\n <td>One</td>\n <td>$\\{ \\ket{0,-}, \\ket{1,+} \\}$</td>\n <td>$P_{-1} = \\ket{0,-}\\bra{0,-} + \\ket{1,+} \\bra{1,+}$</td>\n </tr>\n</table>\n<p>The rules for measurements are then the same as those outlined in the Partial Measurements section, with the projection operators in the table.</p>\n<h2>🔎 Analyze</h2>\n<h3>Parity measurement in a different basis</h3>\n<p>Consider a system which is in a state $\\alpha \\ket{00} + \\beta \\ket{01} + \\beta \\ket{10} + \\alpha \\ket{11}$.</p>\n<p>What are the possible outcomes and their associated probabilities, if a measurement in an $XX$ Pauli measurement is done?</p>\n<details>\n<summary><b>Solution</b></summary>\nThe first step towards identifying the outcomes and their probabilities for joint measurements is to identify the eigenvectors corresponding to eigenvalues $\\pm1$ of the Pauli operator. We note that since $X\\ket{\\pm}= \\pm\\ket{\\pm}$, we have\n<p>$$XX \\ket{++} = \\ket{++}$$\n$$XX \\ket{--} = \\ket{--}$$\n$$XX \\ket{+-} = -\\ket{+-}$$\n$$XX \\ket{-+} = -\\ket{-+}$$</p>\n<p>Thus, the $XX$ operator measures the parity in the Hadamard, or the $\\ket{\\pm}$ basis. That is, it distinguishes basis states with an even number of $+$'s from basis states which have an odd number of $+$'s.</p>\n<p>The projector corresponding to a result of <code>Zero</code> is given by $P_{+1} = \\ket{++}\\bra{++} + \\ket{--}\\bra{--}$, while the projector corresponding to a result of <code>One</code> is given by $P_{-1} = \\ket{+-}\\bra{+-} + \\ket{-+}\\bra{-+}$. Then, we note that $P_{+1}$ annihilates states with odd parity, while leaving states with even parity unaffected. That is, for any values of the constants\n$$P_{+1} ( \\gamma \\ket{++} + \\delta \\ket{--} ) = ( \\gamma \\ket{++} + \\delta \\ket{--} )$$\n$$P_{+1} ( \\mu \\ket{-+} + \\nu \\ket{+-} ) = 0$$</p>\n<p>Similarly, $P_{-1}$ annihilates states with even parity, while leaving states with odd parity unaffected.</p>\n<p>Now we express the given state in the Hadamard basis. We note that it is possible to go from the computational basis to the Hadamard basis using the following relations:\n$$\\ket{0} = \\frac{1}{\\sqrt{2}} \\left( \\ket{+} + \\ket{-} \\right)$$\n$$\\ket{1} = \\frac{1}{\\sqrt{2}} \\left( \\ket{+} - \\ket{-} \\right)$$</p>\n<p>Using these, we obtain\n$$ \\alpha \\ket{00} + \\beta \\ket{01} + \\beta \\ket{10} + \\alpha \\ket{11} = (\\alpha + \\beta) \\ket{++} + (\\alpha - \\beta) \\ket{--}$$\nThus, this state has an even parity in the Hadamard basis. It follows that an $XX$ Pauli measurement will result in the outcome <code>Zero</code> with probability 1, leaving the state unchanged after the measurement.</p>\n</details>"
3646
+ "content": "<p>Joint measurement is a generalization of the measurement in the computational basis.\nPauli measurements can also be generalized to a larger number of qubits. A multi-qubit Pauli measurement corresponds to an operator $M_1 \\otimes \\dotsc \\otimes M_n$, with each $M_i$ being from the set of gates $\\{X,Y,Z,I\\}$. If at least one of the operators isn't the identity matrix, then the measurement can result in two outcomes: a <code>Result</code> of <code>Zero</code> corresponding to eigenvalue $+1$ and a <code>Result</code> of <code>One</code> corresponding to the eigenvalue $-1$. The corresponding projection operators are the projections onto the corresponding eigenspaces.</p>\n<p>For example, a Pauli/joint measurement corresponding to the $X\\otimes Z$ operator can be characterized as follows:</p>\n<table>\n <tr>\n <th>Eigenvalue</th>\n <th>Measurement Result in Q#</th>\n <th>Eigenbasis</th>\n <th>Measurement Projector</th>\n </tr>\n <tr>\n <td>$+1$</td>\n <td>Zero</td>\n <td>$\\{ \\ket{0,+}, \\ket{1,-} \\}$</td>\n <td>$P_{+1} = \\ket{0,+}\\bra{0,+} + \\ket{1,-} \\bra{1,-}$</td>\n </tr>\n <tr>\n <td>$-1$</td>\n <td>One</td>\n <td>$\\{ \\ket{0,-}, \\ket{1,+} \\}$</td>\n <td>$P_{-1} = \\ket{0,-}\\bra{0,-} + \\ket{1,+} \\bra{1,+}$</td>\n </tr>\n</table>\n<p>The rules for measurements are then the same as those outlined in the Partial Measurements section, with the projection operators in the table.</p>\n<h2>🔎 Analyze</h2>\n<h3>Parity measurement in a different basis</h3>\n<p>Consider a system which is in a state $\\alpha \\ket{00} + \\beta \\ket{01} + \\beta \\ket{10} + \\alpha \\ket{11}$.</p>\n<p>What are the possible outcomes and their associated probabilities, if a measurement in an $XX$ Pauli measurement is done?</p>\n<details>\n<summary><b>Solution</b></summary>\nThe first step towards identifying the outcomes and their probabilities for joint measurements is to identify the eigenvectors corresponding to eigenvalues $\\pm1$ of the Pauli operator. Note that since $X\\ket{\\pm}= \\pm\\ket{\\pm}$, you have\n<p>$$XX \\ket{++} = \\ket{++}$$\n$$XX \\ket{--} = \\ket{--}$$\n$$XX \\ket{+-} = -\\ket{+-}$$\n$$XX \\ket{-+} = -\\ket{-+}$$</p>\n<p>Thus, the $XX$ operator measures the parity in the Hadamard, or the $\\ket{\\pm}$ basis. That is, it distinguishes basis states with an even number of $+$'s from basis states which have an odd number of $+$'s.</p>\n<p>The projector corresponding to a result of <code>Zero</code> is given by $P_{+1} = \\ket{++}\\bra{++} + \\ket{--}\\bra{--}$, while the projector corresponding to a result of <code>One</code> is given by $P_{-1} = \\ket{+-}\\bra{+-} + \\ket{-+}\\bra{-+}$. Then, note that $P_{+1}$ annihilates states with odd parity, while leaving states with even parity unaffected. That is, for any values of the constants\n$$P_{+1} ( \\gamma \\ket{++} + \\delta \\ket{--} ) = ( \\gamma \\ket{++} + \\delta \\ket{--} )$$\n$$P_{+1} ( \\mu \\ket{-+} + \\nu \\ket{+-} ) = 0$$</p>\n<p>Similarly, $P_{-1}$ annihilates states with even parity, while leaving states with odd parity unaffected.</p>\n<p>Now you express the given state in the Hadamard basis. Note that it's possible to go from the computational basis to the Hadamard basis using the following relations:\n$$\\ket{0} = \\frac{1}{\\sqrt{2}} \\left( \\ket{+} + \\ket{-} \\right)$$\n$$\\ket{1} = \\frac{1}{\\sqrt{2}} \\left( \\ket{+} - \\ket{-} \\right)$$</p>\n<p>Using these, you obtain\n$$ \\alpha \\ket{00} + \\beta \\ket{01} + \\beta \\ket{10} + \\alpha \\ket{11} = (\\alpha + \\beta) \\ket{++} + (\\alpha - \\beta) \\ket{--}$$\nThus, this state has an even parity in the Hadamard basis. It follows that an $XX$ Pauli measurement will result in the outcome <code>Zero</code> with probability 1, leaving the state unchanged after the measurement.</p>\n</details>"
3647
3647
  }
3648
3648
  ]
3649
3649
  },
@@ -3654,7 +3654,7 @@ export default {
3654
3654
  "items": [
3655
3655
  {
3656
3656
  "type": "text-content",
3657
- "content": "<p>Congratulations! In this kata you learned how to apply measurements on multi-qubit systems. Here are a few key concepts to keep in mind:</p>\n<ul>\n<li>Full measurements: you measure all the qubits simultaneously in an orthogonal basis ($2^n$ possible outcomes).</li>\n<li>Partial measurements: you measure $m$ qubits out of $n$, for $m&lt; n$ ($2^m$ possible outcomes).</li>\n<li>Joint measurement: Pauli measurement of all $n$ qubits ($2$ possible outcomes).</li>\n</ul>\n<p>Next, you will implement a quantum algorithm to generate random numbers in &quot;Quantum Random Number Generation&quot; kata.</p>\n"
3657
+ "content": "<p>Congratulations! In this kata you learned how to apply measurements on multi-qubit systems. Here are a few key concepts to keep in mind:</p>\n<ul>\n<li>Full measurements: you measure all the qubits simultaneously in an orthogonal basis ($2^n$ possible outcomes).</li>\n<li>Partial measurements: you measure $m$ qubits out of $n$, for $m&lt; n$ ($2^m$ possible outcomes).</li>\n<li>Joint measurement: Pauli measurement of all $n$ qubits ($2$ possible outcomes).</li>\n</ul>\n<p>Next, you'll implement a quantum algorithm to generate random numbers in &quot;Quantum Random Number Generation&quot; kata.</p>\n"
3658
3658
  }
3659
3659
  ]
3660
3660
  }
@@ -4876,7 +4876,7 @@ export default {
4876
4876
  "items": [
4877
4877
  {
4878
4878
  "type": "text-content",
4879
- "content": "<p>Quantum key distribution is a type of quantum communication protocol that allows two parties to generate shared secret keys - random strings of bits known only to those two parties. These shared keys can then be used for a variety of different classical cryptographic protocols like encryption or authentication.</p>\n<p>Quantum key distribution protocols include two parties, commonly referred to as Alice and Bob, that have two communication channels between them, one quantum channel that allows Alice to send qubits to Bob and one bidirectional classical channel.\nThe quantum channel in such protocols is usually implemented with photons acting as qubits.\nNote that the classical communication channel has to be authenticated, so that both parties can verify that the classical messages they receive indeed come from the party they are communicating with and are not tampered with in transit.</p>\n"
4879
+ "content": "<p>Quantum key distribution is a type of quantum communication protocol that allows two parties to generate shared secret keys - random strings of bits known only to those two parties. These shared keys can then be used for a variety of different classical cryptographic protocols like encryption or authentication.</p>\n<p>Quantum key distribution protocols include two parties, commonly referred to as Alice and Bob, that have two communication channels between them, one quantum channel that allows Alice to send qubits to Bob and one bidirectional classical channel.\nThe quantum channel in such protocols is usually implemented with photons acting as qubits.\nNote that the classical communication channel has to be authenticated, so that both parties can verify that the classical messages they receive indeed come from the party they are communicating with and aren't tampered with in transit.</p>\n"
4880
4880
  }
4881
4881
  ]
4882
4882
  },
@@ -4887,7 +4887,7 @@ export default {
4887
4887
  "items": [
4888
4888
  {
4889
4889
  "type": "text-content",
4890
- "content": "<p>BB84 protocol, named after its inventors Charles H. Bennett and Gilles Brassard and year of publication, is one of the first proposed quantum key distribution protocols and probably the most famous one.</p>\n<p>BB84 protocol consists of the two main phases:</p>\n<ol>\n<li>\n<p>During the first phase, Alice prepares individual qubits following a certain procedure and then sends them to Bob via the quantum channel to be measured. Alice takes notes of the classical decisions she made when preparing the qubits, and Bob - of his decisions and the measurement results.</p>\n</li>\n<li>\n<p>The second phase is entirely classical post-processing and communication: Alice and Bob discuss their data from the first phase and extract a classical, random bit string they can use as a shared key.</p>\n</li>\n</ol>\n<p>Let's start by looking at how Alice prepares her qubits for sending them to Bob.</p>\n<p>Alice has two choices for each qubit, which basis to prepare it in, and what bit value she wants to encode.\nIn the first basis, the computational basis, Alice prepares the states $\\ket{0}$ and $\\ket{1}$ where $\\ket{0}$ represents the key bit value <code>0</code> and $\\ket{1}$ represents the key bit value <code>1</code>.\nThe second basis, Hadamard basis (sometimes also called the diagonal basis), uses the states $\\ket{+} = \\frac{1}{\\sqrt2}(\\ket{0} + \\ket{1})$ to represent the key bit value <code>0</code>, and $\\ket{-} = \\frac{1}{\\sqrt2}(\\ket{0} - \\ket{1})$ to represent the key bit value <code>1</code>.</p>\n<table>\n <tr>\n <th style=\"text-align:center\">Basis</th>\n <th style=\"text-align:center\">Bit 0</th>\n <th style=\"text-align:center\">Bit 1</th> \n </tr>\n <tr>\n <td style=\"text-align:center\">Computational basis</td>\n <td style=\"text-align:center\">$\\ket{0}$</td>\n <td style=\"text-align:center\">$\\ket{1}$</td>\n </tr>\n <tr>\n <td style=\"text-align:center\">Hadamard basis</td>\n <td style=\"text-align:center\">$\\ket{+}$</td>\n <td style=\"text-align:center\">$\\ket{-}$</td>\n </tr>\n</table>\n<p>The bases used in the protocol are selected such that if an eavesdropper tries to measure a qubit in transit and chooses the wrong basis, then they just get a 0 or 1 measurement result with equal probability.</p>\n<p>Alice has to make two random choices for each qubit she prepares, one for which basis to prepare in, and the other for what bit value she wants to send, choosing each option with $50\\%$ probability.\nIf Alice decides to send $N$ qubits, she needs to make $2N$ random choices, usually implemented as two arrays of $N$ choices each.</p>\n<p>Once Bob receives the qubits from Alice, he needs to decide in which basis, computational or Hadamard, to measure each of them, and these decisions are also random, with each basis chosen with $50\\%$ probability.</p>\n<p>Finally, at the end of the first phase of the protocol Alice has a list of the bit values she sent as well as what basis she prepared each qubit in, and Bob has a list of bases he used to measure each qubit.</p>\n<p>To extract the shared key, they need to figure out when they both used the same basis, and toss the data from qubits where they used different bases. If Alice and Bob did not use the same basis to prepare and measure the qubits in, the measurement results Bob got will be just random bits with $50\\%$ probability for both the <code>Zero</code> and <code>One</code> outcomes. But if they used the same basis, Bob's measurement result will match the bit Alice sent.</p>\n<p>This means that by exchanging information about the bases Alice and Bob used for preparation and measurements via a public classical communication channel, they can deduce which parts of their lists of bits they kept private are identical, and use them as their shared key!</p>\n<p>Now that we've learned the theory behind the BB84 protocol, let's implement its steps to see it in action!</p>\n"
4890
+ "content": "<p>BB84 protocol, named after its inventors Charles H. Bennett and Gilles Brassard and year of publication, is one of the first proposed quantum key distribution protocols and probably the most famous one.</p>\n<p>BB84 protocol consists of the two main phases:</p>\n<ol>\n<li>\n<p>During the first phase, Alice prepares individual qubits following a certain procedure and then sends them to Bob via the quantum channel to be measured. Alice takes notes of the classical decisions she made when preparing the qubits, and Bob takes notes of his decisions when measuring the qubits and the measurement results.</p>\n</li>\n<li>\n<p>The second phase is entirely classical post-processing and communication: Alice and Bob discuss their data from the first phase and extract a classical, random bit string they can use as a shared key.</p>\n</li>\n</ol>\n<p>Let's start by looking at how Alice prepares her qubits for sending them to Bob.</p>\n<p>Alice has two choices for each qubit, which basis to prepare it in, and what bit value she wants to encode.\nIn the first basis, the computational basis, Alice prepares the states $\\ket{0}$ and $\\ket{1}$ where $\\ket{0}$ represents the key bit value <code>0</code> and $\\ket{1}$ represents the key bit value <code>1</code>.\nThe second basis, Hadamard basis (sometimes also called the diagonal basis), uses the states $\\ket{+} = \\frac{1}{\\sqrt2}(\\ket{0} + \\ket{1})$ to represent the key bit value <code>0</code>, and $\\ket{-} = \\frac{1}{\\sqrt2}(\\ket{0} - \\ket{1})$ to represent the key bit value <code>1</code>.</p>\n<table>\n <tr>\n <th style=\"text-align:center\">Basis</th>\n <th style=\"text-align:center\">Bit 0</th>\n <th style=\"text-align:center\">Bit 1</th> \n </tr>\n <tr>\n <td style=\"text-align:center\">Computational basis</td>\n <td style=\"text-align:center\">$\\ket{0}$</td>\n <td style=\"text-align:center\">$\\ket{1}$</td>\n </tr>\n <tr>\n <td style=\"text-align:center\">Hadamard basis</td>\n <td style=\"text-align:center\">$\\ket{+}$</td>\n <td style=\"text-align:center\">$\\ket{-}$</td>\n </tr>\n</table>\n<p>The bases used in the protocol are selected such that if an eavesdropper tries to measure a qubit in transit and chooses the wrong basis, then they just get a 0 or 1 measurement result with equal probability.</p>\n<p>Alice has to make two random choices for each qubit she prepares, one for which basis to prepare in, and the other for what bit value she wants to send, choosing each option with $50\\%$ probability.\nIf Alice decides to send $N$ qubits, she needs to make $2N$ random choices, usually implemented as two arrays of $N$ choices each.</p>\n<p>Once Bob receives the qubits from Alice, he needs to decide in which basis, computational or Hadamard, to measure each of them, and these decisions are also random, with each basis chosen with $50\\%$ probability.</p>\n<p>Finally, at the end of the first phase of the protocol, Alice has a list of the bit values she sent as well as what basis she prepared each qubit in, and Bob has a list of bases he used to measure each qubit.</p>\n<p>To extract the shared key, they need to figure out when they both used the same basis, and toss the data from qubits where they used different bases. If Alice and Bob didn't use the same basis to prepare and measure the qubits in, the measurement results Bob got will be just random bits with $50\\%$ probability for both the 0 and 1 outcomes. But if they used the same basis, Bob's measurement result will match the bit Alice sent.</p>\n<p>This means that by exchanging information about the bases Alice and Bob used for preparation and measurements via a public classical communication channel, they can deduce which parts of their lists of bits they kept private are identical, and use them as their shared key!</p>\n<p>Now that you've learned the theory behind the BB84 protocol, let's implement its steps to see it in action!</p>\n"
4891
4891
  }
4892
4892
  ]
4893
4893
  },
@@ -4897,7 +4897,7 @@ export default {
4897
4897
  "title": "Generate Random Array",
4898
4898
  "description": {
4899
4899
  "type": "text-content",
4900
- "content": "<p><strong>Input:</strong> An integer $N$.</p>\n<p><strong>Output</strong> : A <code>Bool</code> array of length N, where each element is chosen at random as <code>true</code> or <code>false</code> with $50\\%$ probability.</p>\n<blockquote>\n<p>This will be used by both Alice and Bob to choose either the sequence of bits to send or the sequence of bases\nto use when encoding/measuring the bits.</p>\n</blockquote>\n"
4900
+ "content": "<p><strong>Input:</strong> An integer $N$.</p>\n<p><strong>Output</strong> : A <code>Bool</code> array of length $N$, where each element is chosen at random as <code>true</code> or <code>false</code> with $50\\%$ probability.</p>\n<blockquote>\n<p>This will be used by both Alice and Bob to choose either the sequence of bits to send or the sequence of bases\nto use when encoding/measuring the bits.</p>\n</blockquote>\n"
4901
4901
  },
4902
4902
  "sourceIds": [
4903
4903
  "key_distribution__random_array__Verification.qs",
@@ -4910,7 +4910,7 @@ export default {
4910
4910
  "items": [
4911
4911
  {
4912
4912
  "type": "text-content",
4913
- "content": "<p>We need to do three steps to generate an array of random values:</p>\n<ol>\n<li>Create a mutable array of size $N$ - it will need a default value that can be <code>false</code>.</li>\n<li>For each index from $0$ to $N-1$, choose one of the two values <code>true</code> or <code>false</code> at random, and assign that value to the array element at that index. We could choose a random bit by allocating a qubit, preparing it in the $\\ket{+}$ state, and measuring it. However, we don't need those bits to have quantum origin, so we can use a Q# library operation <code>DrawRandomInt</code> instead.</li>\n<li>Finally, return the generated array.</li>\n</ol>\n"
4913
+ "content": "<p>You need to do three steps to generate an array of random values:</p>\n<ol>\n<li>Create a mutable array of size $N$ - it will need a default value that can be <code>false</code>.</li>\n<li>For each index from $0$ to $N-1$, choose one of the two values <code>true</code> or <code>false</code> at random, and assign that value to the array element at that index. You could choose a random bit by allocating a qubit, preparing it in the $\\ket{+}$ state, and measuring it. However, you don't need those bits to have quantum origin, so you can use a Q# library operation <code>DrawRandomInt</code> instead.</li>\n<li>Finally, return the generated array.</li>\n</ol>\n"
4914
4914
  },
4915
4915
  {
4916
4916
  "type": "solution",
@@ -4939,7 +4939,7 @@ export default {
4939
4939
  "items": [
4940
4940
  {
4941
4941
  "type": "text-content",
4942
- "content": "<p>There are a total of 4 types of states that Alice can prepare before sending to Bob, each corresponds to the unique combination of bits and bases bool array.</p>\n<ol>\n<li>State $\\ket{0}$ corresponds to <code>bases[i]</code> be in computational basis, i.e., <code>false</code>, and <code>bits[i]</code> equal to 0, i.e., <code>false</code>.</li>\n<li>State $\\ket{1}$ corresponds to <code>bases[i]</code> in computational basis, i.e., <code>false</code>, and <code>bits[i]</code> equal to 1, i.e., <code>true</code>.</li>\n<li>State $\\ket{+}$ corresponds to <code>bases[i]</code> in Hadamard basis, i.e., <code>true</code>, and <code>bits[i]</code> equal to 0, i.e., <code>false</code>.</li>\n<li>State $\\ket{-}$ corresponds to <code>bases[i]</code> in Hadamard basis, i.e., <code>true</code> and <code>bits[i]</code> equal to 1, i.e., <code>true</code>.</li>\n</ol>\n<p>So, in case <code>bits[i]</code> is set to <code>true</code>, we need to apply the $X$ gate to the i-th qubit, and then if <code>bases[i]</code> is set to <code>true</code>, the $H$ gate needs to be applied to the i-th qubit.</p>\n"
4942
+ "content": "<p>There are a total of 4 types of states that Alice can prepare before sending to Bob, each corresponds to the unique combination of bits and bases bool array.</p>\n<ol>\n<li>State $\\ket{0}$ corresponds to <code>bases[i]</code> being in the computational basis (that is, <code>false</code>) and <code>bits[i]</code> being equal to 0 (that is, <code>false</code>).</li>\n<li>State $\\ket{1}$ corresponds to <code>bases[i]</code> being in the computational basis (that is, <code>false</code>) and <code>bits[i]</code> being equal to 1 (that is, <code>true</code>).</li>\n<li>State $\\ket{+}$ corresponds to <code>bases[i]</code> being in the Hadamard basis (that is, <code>true</code>) and <code>bits[i]</code> being equal to 0 (that is, <code>false</code>).</li>\n<li>State $\\ket{-}$ corresponds to <code>bases[i]</code> being in the Hadamard basis (that is, <code>true</code>) and <code>bits[i]</code> being equal to 1 (that is, <code>true</code>).</li>\n</ol>\n<p>So, in case <code>bits[i]</code> is set to <code>true</code>, you need to apply the $X$ gate to the i-th qubit, and then if <code>bases[i]</code> is set to <code>true</code>, the $H$ gate needs to be applied to the i-th qubit.</p>\n"
4943
4943
  },
4944
4944
  {
4945
4945
  "type": "solution",
@@ -4955,7 +4955,7 @@ export default {
4955
4955
  "title": "Measure Qubits (Bob's Task)",
4956
4956
  "description": {
4957
4957
  "type": "text-content",
4958
- "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li><code>qs</code>: an array of $N$ qubits;<br />\neach qubit is in one of the following states: $\\ket{0}$, $\\ket{1}$, $\\ket{+}$, $\\ket{-}$.</li>\n<li><code>bases</code>: a <code>Bool</code> array of length $N$;\n<code>bases[i]</code> indicates the basis that should be used to measure the qubit <code>i</code>:\n<ul>\n<li><code>false</code>: use the basis $\\ket{0}$ / $\\ket{1}$ (computational),</li>\n<li><code>true</code>: use the basis $\\ket{+}$ / $\\ket{-}$ (Hadamard).</li>\n</ul>\n</li>\n</ol>\n<p><strong>Goal:</strong> Measure each qubit in the corresponding basis and return an array of results as Boolean values, encoding measurement result <code>Zero</code> as <code>false</code> and <code>One</code> as <code>true</code>.\nThe state of the qubits at the end of the operation does not matter.</p>\n"
4958
+ "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li><code>qs</code>: an array of $N$ qubits;<br />\neach qubit is in one of the following states: $\\ket{0}$, $\\ket{1}$, $\\ket{+}$, $\\ket{-}$.</li>\n<li><code>bases</code>: a <code>Bool</code> array of length $N$;\n<code>bases[i]</code> indicates the basis that should be used to measure the qubit <code>i</code>:\n<ul>\n<li><code>false</code>: use the basis $\\ket{0}$ / $\\ket{1}$ (computational),</li>\n<li><code>true</code>: use the basis $\\ket{+}$ / $\\ket{-}$ (Hadamard).</li>\n</ul>\n</li>\n</ol>\n<p><strong>Goal:</strong> Measure each qubit in the corresponding basis and return an array of results as Boolean values, encoding measurement result <code>Zero</code> as <code>false</code> and <code>One</code> as <code>true</code>.\nThe state of the qubits at the end of the operation doesn't matter.</p>\n"
4959
4959
  },
4960
4960
  "sourceIds": [
4961
4961
  "key_distribution__measure_qubits__Verification.qs",
@@ -4968,7 +4968,7 @@ export default {
4968
4968
  "items": [
4969
4969
  {
4970
4970
  "type": "text-content",
4971
- "content": "<p>If the <code>bases[i]</code> array element is <code>true</code>, it means that we are choosing the Hadamard basis for this qubit, and thus an $H$ gate needs to be applied. Otherwise, we choose computational basis and don't need to apply the $H$ gate before measuring the qubit.</p>\n<p>Now, the output is expected to be a Boolean array, and thus we need to measure the each qubit and convert this measurement to a <code>Bool</code>.</p>\n<ol>\n<li>To measure each of the qubits in one operation call, we can use Q# library operation <code>MeasureEachZ</code>.</li>\n<li>To convert these measurement results into a Boolean array, we can use the function <code>ResultArrayAsBoolArray</code> that takes an array of <code>Result</code> type as an input and returns the required array of <code>Bool</code> type.</li>\n</ol>\n"
4971
+ "content": "<p>If the <code>bases[i]</code> array element is <code>true</code>, it means that you're choosing the Hadamard basis for this qubit, and thus an $H$ gate needs to be applied. Otherwise, you choose the computational basis and don't need to apply the $H$ gate before measuring the qubit.</p>\n<p>Now, the output is expected to be a Boolean array, and thus you need to measure the each qubit and convert this measurement to a <code>Bool</code>.</p>\n<ol>\n<li>To measure each of the qubits in one operation call, you can use Q# library operation <code>MeasureEachZ</code>.</li>\n<li>To convert these measurement results into a Boolean array, you can use the function <code>ResultArrayAsBoolArray</code> that takes an array of <code>Result</code> type as an input and returns the required array of <code>Bool</code> type.</li>\n</ol>\n"
4972
4972
  },
4973
4973
  {
4974
4974
  "type": "solution",
@@ -4997,7 +4997,7 @@ export default {
4997
4997
  "items": [
4998
4998
  {
4999
4999
  "type": "text-content",
5000
- "content": "<p>If Alice and Bob exchanged a qubit and used the same bases for preparing and measuring it, the bit produced by Bob's measurement would be the same as the one Alice encoded. Thus, they do not need to share the bits they chose or obtained over the classical communication channel. Sharing the bases used for each of the qubit is sufficient to understand if their bits match or not.</p>\n<p>To complete this task, we need to perform the following steps:</p>\n<ol>\n<li>Declare an empty mutable array, let's name it <code>key</code>.</li>\n<li>Decide which bits we can add to our key based on the comparison between bases used by Alice and Bob. You can iterate using an index in the range from $0$ to $N - 1$ and compare the bases in the corresponding positions.</li>\n<li>Return the required <code>key</code>.</li>\n</ol>\n"
5000
+ "content": "<p>If Alice and Bob exchanged a qubit and used the same bases for preparing and measuring it, the bit produced by Bob's measurement would be the same as the one Alice encoded. Thus, they don't need to share the bits they chose or obtained over the classical communication channel. Sharing the bases used for each of the qubit is sufficient to understand if their bits match or not.</p>\n<p>To complete this task, you need to perform the following steps:</p>\n<ol>\n<li>Declare an empty mutable array, let's name it <code>key</code>.</li>\n<li>Decide which bits you can add to the key based on the comparison between bases used by Alice and Bob. You can iterate using an index in the range from $0$ to $N - 1$ and compare the bases in the corresponding positions.</li>\n<li>Return the required <code>key</code>.</li>\n</ol>\n"
5001
5001
  },
5002
5002
  {
5003
5003
  "type": "solution",
@@ -5014,7 +5014,7 @@ export default {
5014
5014
  "items": [
5015
5015
  {
5016
5016
  "type": "text-content",
5017
- "content": "<p>In this lesson, your goal is to put together the code from the previous exercises to simulate the complete BB84 protocol, from Alice choosing her bits and sending qubits to Bob to them figuring out the shared key.</p>\n<blockquote>\n<p>This is an open-ended task that is not tested automatically, unlike the previous exercises. Follow the suggestions in the comments to write your code and test it!</p>\n</blockquote>\n"
5017
+ "content": "<p>In this lesson, your goal is to put together the code from the previous exercises to simulate the complete BB84 protocol, from Alice choosing her bits and sending qubits to Bob to them figuring out the shared key.</p>\n<blockquote>\n<p>This is an open-ended task that isn't tested automatically, unlike the previous exercises. Follow the suggestions in the comments to write your code and test it!</p>\n</blockquote>\n"
5018
5018
  },
5019
5019
  {
5020
5020
  "type": "example",
@@ -5030,7 +5030,7 @@ export default {
5030
5030
  "items": [
5031
5031
  {
5032
5032
  "type": "text-content",
5033
- "content": "<p>Now, let's consider adding an eavesdropper Eve in the protocol.</p>\n<p>Eve can intercept a qubit from the quantum channel that Alice and Bob are using.\nShe can try to get some information from it by measuring it. Then she prepares a new qubit and sends it back to the channel for Bob to receive.\nEve hopes that if she got lucky with her measurement, that when Bob measures the qubit he doesn't get an error so she won't be caught!</p>\n<p>How can Alice and Bob detect an eavesdropper?</p>\n<p>To do this, they need to reveal a part of their shared key publicly to check that they both got the same bits on the qubits for which they used the same bases. If Eve doesn't guess which basis to use for measurement, she'll introduce an error in the protocol by sending $\\ket{+}$ or $\\ket{-}$ when the computational basis was used or $\\ket{0}$ or $\\ket{1}$ when the Hadamard basis was used, thus sometimes causing Bob's measurement result differ from the bit Alice encoded even when their bases matched. By comparing their results on a random subset of bits, Alice and Bob will be able to find such discrepancies and detect Eve's presence.</p>\n<blockquote>\n<p>Feel free to experiment with the code above to introduce an eavesdropper into it and to model the information they can get about the key and the way they can be detected.</p>\n</blockquote>\n"
5033
+ "content": "<p>Now, let's consider adding an eavesdropper, known as Eve, in the protocol.</p>\n<p>Eve can intercept a qubit from the quantum channel that Alice and Bob are using.\nShe can try to get some information from it by measuring it. Then she prepares a new qubit and sends it back to the channel for Bob to receive.\nEve hopes that if she got lucky with her measurement, that when Bob measures the qubit he doesn't get an error so she won't be caught!</p>\n<p>How can Alice and Bob detect an eavesdropper?</p>\n<p>To do this, they need to reveal a part of their shared key publicly to check that they both got the same bits on the qubits for which they used the same bases. If Eve doesn't guess which basis to use for measurement, she'll introduce an error in the protocol by sending $\\ket{+}$ or $\\ket{-}$ when the computational basis was used or $\\ket{0}$ or $\\ket{1}$ when the Hadamard basis was used, thus sometimes causing Bob's measurement result differ from the bit Alice encoded even when their bases matched. By comparing their results on a random subset of bits, Alice and Bob will be able to find such discrepancies and detect Eve's presence.</p>\n<blockquote>\n<p>Feel free to experiment with the code above to introduce an eavesdropper into it and to model the information they can get about the key and the way they can be detected.</p>\n</blockquote>\n"
5034
5034
  }
5035
5035
  ]
5036
5036
  },