qsharp-lang 1.1.5-dev → 1.1.6-dev

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 (273) hide show
  1. package/dist/compiler/compiler.d.ts +25 -7
  2. package/dist/compiler/compiler.js +28 -8
  3. package/dist/debug-service/debug-service.d.ts +2 -2
  4. package/dist/debug-service/debug-service.js +2 -2
  5. package/dist/katas-content.generated.js +59 -59
  6. package/docs/Microsoft.Quantum.Arrays/All.md +2 -2
  7. package/docs/Microsoft.Quantum.Arrays/Any.md +2 -2
  8. package/docs/Microsoft.Quantum.Arrays/Chunks.md +2 -2
  9. package/docs/Microsoft.Quantum.Arrays/CircularlyShifted.md +2 -2
  10. package/docs/Microsoft.Quantum.Arrays/ColumnAt.md +2 -2
  11. package/docs/Microsoft.Quantum.Arrays/Count.md +2 -2
  12. package/docs/Microsoft.Quantum.Arrays/Diagonal.md +2 -2
  13. package/docs/Microsoft.Quantum.Arrays/DrawMany.md +2 -2
  14. package/docs/Microsoft.Quantum.Arrays/Enumerated.md +2 -2
  15. package/docs/Microsoft.Quantum.Arrays/Excluding.md +2 -2
  16. package/docs/Microsoft.Quantum.Arrays/Filtered.md +2 -2
  17. package/docs/Microsoft.Quantum.Arrays/FlatMapped.md +2 -2
  18. package/docs/Microsoft.Quantum.Arrays/Flattened.md +2 -2
  19. package/docs/Microsoft.Quantum.Arrays/Fold.md +2 -2
  20. package/docs/Microsoft.Quantum.Arrays/ForEach.md +2 -2
  21. package/docs/Microsoft.Quantum.Arrays/Head.md +2 -2
  22. package/docs/Microsoft.Quantum.Arrays/HeadAndRest.md +2 -2
  23. package/docs/Microsoft.Quantum.Arrays/IndexOf.md +2 -2
  24. package/docs/Microsoft.Quantum.Arrays/IndexRange.md +2 -2
  25. package/docs/Microsoft.Quantum.Arrays/Interleaved.md +2 -2
  26. package/docs/Microsoft.Quantum.Arrays/IsEmpty.md +2 -2
  27. package/docs/Microsoft.Quantum.Arrays/IsRectangularArray.md +2 -2
  28. package/docs/Microsoft.Quantum.Arrays/IsSorted.md +2 -2
  29. package/docs/Microsoft.Quantum.Arrays/IsSquareArray.md +2 -2
  30. package/docs/Microsoft.Quantum.Arrays/Mapped.md +2 -2
  31. package/docs/Microsoft.Quantum.Arrays/MappedByIndex.md +2 -2
  32. package/docs/Microsoft.Quantum.Arrays/MappedOverRange.md +2 -2
  33. package/docs/Microsoft.Quantum.Arrays/Most.md +2 -2
  34. package/docs/Microsoft.Quantum.Arrays/MostAndTail.md +2 -2
  35. package/docs/Microsoft.Quantum.Arrays/Padded.md +2 -2
  36. package/docs/Microsoft.Quantum.Arrays/Partitioned.md +2 -2
  37. package/docs/Microsoft.Quantum.Arrays/Rest.md +2 -2
  38. package/docs/Microsoft.Quantum.Arrays/Reversed.md +2 -2
  39. package/docs/Microsoft.Quantum.Arrays/SequenceI.md +2 -2
  40. package/docs/Microsoft.Quantum.Arrays/SequenceL.md +2 -2
  41. package/docs/Microsoft.Quantum.Arrays/Sorted.md +2 -2
  42. package/docs/Microsoft.Quantum.Arrays/Subarray.md +2 -2
  43. package/docs/Microsoft.Quantum.Arrays/Swapped.md +2 -2
  44. package/docs/Microsoft.Quantum.Arrays/Tail.md +2 -2
  45. package/docs/Microsoft.Quantum.Arrays/Transposed.md +2 -2
  46. package/docs/Microsoft.Quantum.Arrays/Unzipped.md +2 -2
  47. package/docs/Microsoft.Quantum.Arrays/Where.md +2 -2
  48. package/docs/Microsoft.Quantum.Arrays/Windows.md +2 -2
  49. package/docs/Microsoft.Quantum.Arrays/Zipped.md +2 -2
  50. package/docs/Microsoft.Quantum.Canon/ApplyCNOTChain.md +2 -2
  51. package/docs/Microsoft.Quantum.Canon/ApplyControlledOnBitString.md +2 -2
  52. package/docs/Microsoft.Quantum.Canon/ApplyControlledOnInt.md +2 -2
  53. package/docs/Microsoft.Quantum.Canon/ApplyP.md +2 -2
  54. package/docs/Microsoft.Quantum.Canon/ApplyPauli.md +2 -2
  55. package/docs/Microsoft.Quantum.Canon/ApplyPauliFromBitString.md +2 -2
  56. package/docs/Microsoft.Quantum.Canon/ApplyPauliFromInt.md +2 -2
  57. package/docs/Microsoft.Quantum.Canon/ApplyQFT.md +2 -2
  58. package/docs/Microsoft.Quantum.Canon/ApplyToEach.md +2 -2
  59. package/docs/Microsoft.Quantum.Canon/ApplyToEachA.md +2 -2
  60. package/docs/Microsoft.Quantum.Canon/ApplyToEachC.md +2 -2
  61. package/docs/Microsoft.Quantum.Canon/ApplyToEachCA.md +2 -2
  62. package/docs/Microsoft.Quantum.Canon/ApplyXorInPlace.md +2 -2
  63. package/docs/Microsoft.Quantum.Canon/ApplyXorInPlaceL.md +2 -2
  64. package/docs/Microsoft.Quantum.Canon/CX.md +2 -2
  65. package/docs/Microsoft.Quantum.Canon/CY.md +2 -2
  66. package/docs/Microsoft.Quantum.Canon/CZ.md +2 -2
  67. package/docs/Microsoft.Quantum.Canon/Fst.md +2 -2
  68. package/docs/Microsoft.Quantum.Canon/Snd.md +2 -2
  69. package/docs/Microsoft.Quantum.Canon/SwapReverseRegister.md +2 -2
  70. package/docs/Microsoft.Quantum.Convert/BigIntAsBoolArray.md +2 -2
  71. package/docs/Microsoft.Quantum.Convert/BoolArrayAsBigInt.md +2 -2
  72. package/docs/Microsoft.Quantum.Convert/BoolArrayAsInt.md +2 -2
  73. package/docs/Microsoft.Quantum.Convert/BoolArrayAsResultArray.md +2 -2
  74. package/docs/Microsoft.Quantum.Convert/BoolAsResult.md +2 -2
  75. package/docs/Microsoft.Quantum.Convert/ComplexAsComplexPolar.md +2 -2
  76. package/docs/Microsoft.Quantum.Convert/ComplexPolarAsComplex.md +2 -2
  77. package/docs/Microsoft.Quantum.Convert/IntAsBigInt.md +2 -2
  78. package/docs/Microsoft.Quantum.Convert/IntAsBoolArray.md +2 -2
  79. package/docs/Microsoft.Quantum.Convert/IntAsDouble.md +2 -2
  80. package/docs/Microsoft.Quantum.Convert/ResultArrayAsBoolArray.md +2 -2
  81. package/docs/Microsoft.Quantum.Convert/ResultArrayAsInt.md +2 -2
  82. package/docs/Microsoft.Quantum.Convert/ResultAsBool.md +2 -2
  83. package/docs/Microsoft.Quantum.Core/IsRangeEmpty.md +2 -2
  84. package/docs/Microsoft.Quantum.Core/Length.md +2 -2
  85. package/docs/Microsoft.Quantum.Core/RangeEnd.md +2 -2
  86. package/docs/Microsoft.Quantum.Core/RangeReverse.md +2 -2
  87. package/docs/Microsoft.Quantum.Core/RangeStart.md +2 -2
  88. package/docs/Microsoft.Quantum.Core/RangeStep.md +2 -2
  89. package/docs/Microsoft.Quantum.Core/Repeated.md +2 -2
  90. package/docs/Microsoft.Quantum.Diagnostics/CheckAllZero.md +2 -2
  91. package/docs/Microsoft.Quantum.Diagnostics/CheckOperationsAreEqual.md +2 -2
  92. package/docs/Microsoft.Quantum.Diagnostics/CheckZero.md +2 -2
  93. package/docs/Microsoft.Quantum.Diagnostics/DumpMachine.md +2 -2
  94. package/docs/Microsoft.Quantum.Diagnostics/Fact.md +2 -2
  95. package/docs/Microsoft.Quantum.Intrinsic/CCNOT.md +2 -2
  96. package/docs/Microsoft.Quantum.Intrinsic/CNOT.md +2 -2
  97. package/docs/Microsoft.Quantum.Intrinsic/Exp.md +2 -2
  98. package/docs/Microsoft.Quantum.Intrinsic/H.md +8 -5
  99. package/docs/Microsoft.Quantum.Intrinsic/I.md +2 -2
  100. package/docs/Microsoft.Quantum.Intrinsic/M.md +2 -2
  101. package/docs/Microsoft.Quantum.Intrinsic/Measure.md +2 -2
  102. package/docs/Microsoft.Quantum.Intrinsic/Message.md +2 -2
  103. package/docs/Microsoft.Quantum.Intrinsic/R.md +2 -2
  104. package/docs/Microsoft.Quantum.Intrinsic/R1.md +2 -2
  105. package/docs/Microsoft.Quantum.Intrinsic/R1Frac.md +2 -2
  106. package/docs/Microsoft.Quantum.Intrinsic/RFrac.md +2 -2
  107. package/docs/Microsoft.Quantum.Intrinsic/Reset.md +2 -2
  108. package/docs/Microsoft.Quantum.Intrinsic/ResetAll.md +2 -2
  109. package/docs/Microsoft.Quantum.Intrinsic/Rx.md +2 -2
  110. package/docs/Microsoft.Quantum.Intrinsic/Rxx.md +2 -2
  111. package/docs/Microsoft.Quantum.Intrinsic/Ry.md +2 -2
  112. package/docs/Microsoft.Quantum.Intrinsic/Ryy.md +2 -2
  113. package/docs/Microsoft.Quantum.Intrinsic/Rz.md +2 -2
  114. package/docs/Microsoft.Quantum.Intrinsic/Rzz.md +2 -2
  115. package/docs/Microsoft.Quantum.Intrinsic/S.md +2 -2
  116. package/docs/Microsoft.Quantum.Intrinsic/SWAP.md +2 -2
  117. package/docs/Microsoft.Quantum.Intrinsic/T.md +2 -2
  118. package/docs/Microsoft.Quantum.Intrinsic/X.md +2 -2
  119. package/docs/Microsoft.Quantum.Intrinsic/Y.md +2 -2
  120. package/docs/Microsoft.Quantum.Intrinsic/Z.md +2 -2
  121. package/docs/Microsoft.Quantum.Logical/Xor.md +2 -2
  122. package/docs/Microsoft.Quantum.Math/AbsComplex.md +2 -2
  123. package/docs/Microsoft.Quantum.Math/AbsComplexPolar.md +2 -2
  124. package/docs/Microsoft.Quantum.Math/AbsD.md +2 -2
  125. package/docs/Microsoft.Quantum.Math/AbsI.md +2 -2
  126. package/docs/Microsoft.Quantum.Math/AbsL.md +2 -2
  127. package/docs/Microsoft.Quantum.Math/AbsSquaredComplex.md +2 -2
  128. package/docs/Microsoft.Quantum.Math/AbsSquaredComplexPolar.md +2 -2
  129. package/docs/Microsoft.Quantum.Math/ApproximateFactorial.md +2 -2
  130. package/docs/Microsoft.Quantum.Math/ArcCos.md +2 -2
  131. package/docs/Microsoft.Quantum.Math/ArcCosh.md +2 -2
  132. package/docs/Microsoft.Quantum.Math/ArcSin.md +2 -2
  133. package/docs/Microsoft.Quantum.Math/ArcSinh.md +2 -2
  134. package/docs/Microsoft.Quantum.Math/ArcTan.md +2 -2
  135. package/docs/Microsoft.Quantum.Math/ArcTan2.md +2 -2
  136. package/docs/Microsoft.Quantum.Math/ArcTanh.md +2 -2
  137. package/docs/Microsoft.Quantum.Math/ArgComplex.md +2 -2
  138. package/docs/Microsoft.Quantum.Math/ArgComplexPolar.md +2 -2
  139. package/docs/Microsoft.Quantum.Math/Binom.md +2 -2
  140. package/docs/Microsoft.Quantum.Math/BitSizeI.md +2 -2
  141. package/docs/Microsoft.Quantum.Math/BitSizeL.md +2 -2
  142. package/docs/Microsoft.Quantum.Math/Ceiling.md +2 -2
  143. package/docs/Microsoft.Quantum.Math/Complex.md +2 -2
  144. package/docs/Microsoft.Quantum.Math/ComplexPolar.md +2 -2
  145. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentI.md +2 -2
  146. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentL.md +2 -2
  147. package/docs/Microsoft.Quantum.Math/Cos.md +2 -2
  148. package/docs/Microsoft.Quantum.Math/Cosh.md +2 -2
  149. package/docs/Microsoft.Quantum.Math/DivRemI.md +2 -2
  150. package/docs/Microsoft.Quantum.Math/DivRemL.md +2 -2
  151. package/docs/Microsoft.Quantum.Math/DividedByC.md +2 -2
  152. package/docs/Microsoft.Quantum.Math/DividedByCP.md +2 -2
  153. package/docs/Microsoft.Quantum.Math/E.md +2 -2
  154. package/docs/Microsoft.Quantum.Math/ExpModI.md +2 -2
  155. package/docs/Microsoft.Quantum.Math/ExpModL.md +2 -2
  156. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorI.md +2 -2
  157. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorL.md +2 -2
  158. package/docs/Microsoft.Quantum.Math/FactorialI.md +2 -2
  159. package/docs/Microsoft.Quantum.Math/FactorialL.md +2 -2
  160. package/docs/Microsoft.Quantum.Math/Floor.md +2 -2
  161. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorI.md +2 -2
  162. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorL.md +2 -2
  163. package/docs/Microsoft.Quantum.Math/HammingWeightI.md +2 -2
  164. package/docs/Microsoft.Quantum.Math/InverseModI.md +2 -2
  165. package/docs/Microsoft.Quantum.Math/InverseModL.md +2 -2
  166. package/docs/Microsoft.Quantum.Math/IsCoprimeI.md +2 -2
  167. package/docs/Microsoft.Quantum.Math/IsCoprimeL.md +2 -2
  168. package/docs/Microsoft.Quantum.Math/IsInfinite.md +2 -2
  169. package/docs/Microsoft.Quantum.Math/IsNaN.md +2 -2
  170. package/docs/Microsoft.Quantum.Math/LargestFixedPoint.md +2 -2
  171. package/docs/Microsoft.Quantum.Math/Lg.md +2 -2
  172. package/docs/Microsoft.Quantum.Math/Log.md +2 -2
  173. package/docs/Microsoft.Quantum.Math/Log10.md +2 -2
  174. package/docs/Microsoft.Quantum.Math/LogFactorialD.md +2 -2
  175. package/docs/Microsoft.Quantum.Math/LogGammaD.md +2 -2
  176. package/docs/Microsoft.Quantum.Math/LogOf2.md +2 -2
  177. package/docs/Microsoft.Quantum.Math/Max.md +2 -2
  178. package/docs/Microsoft.Quantum.Math/MaxD.md +2 -2
  179. package/docs/Microsoft.Quantum.Math/MaxI.md +2 -2
  180. package/docs/Microsoft.Quantum.Math/MaxL.md +2 -2
  181. package/docs/Microsoft.Quantum.Math/Min.md +2 -2
  182. package/docs/Microsoft.Quantum.Math/MinD.md +2 -2
  183. package/docs/Microsoft.Quantum.Math/MinI.md +2 -2
  184. package/docs/Microsoft.Quantum.Math/MinL.md +2 -2
  185. package/docs/Microsoft.Quantum.Math/MinusC.md +2 -2
  186. package/docs/Microsoft.Quantum.Math/MinusCP.md +2 -2
  187. package/docs/Microsoft.Quantum.Math/ModulusI.md +2 -2
  188. package/docs/Microsoft.Quantum.Math/ModulusL.md +2 -2
  189. package/docs/Microsoft.Quantum.Math/NegationC.md +2 -2
  190. package/docs/Microsoft.Quantum.Math/NegationCP.md +2 -2
  191. package/docs/Microsoft.Quantum.Math/PI.md +2 -2
  192. package/docs/Microsoft.Quantum.Math/PNorm.md +2 -2
  193. package/docs/Microsoft.Quantum.Math/PNormalized.md +2 -2
  194. package/docs/Microsoft.Quantum.Math/PlusC.md +2 -2
  195. package/docs/Microsoft.Quantum.Math/PlusCP.md +2 -2
  196. package/docs/Microsoft.Quantum.Math/PowC.md +2 -2
  197. package/docs/Microsoft.Quantum.Math/PowCP.md +2 -2
  198. package/docs/Microsoft.Quantum.Math/RealMod.md +2 -2
  199. package/docs/Microsoft.Quantum.Math/Round.md +2 -2
  200. package/docs/Microsoft.Quantum.Math/SignD.md +2 -2
  201. package/docs/Microsoft.Quantum.Math/SignI.md +2 -2
  202. package/docs/Microsoft.Quantum.Math/SignL.md +2 -2
  203. package/docs/Microsoft.Quantum.Math/Sin.md +2 -2
  204. package/docs/Microsoft.Quantum.Math/Sinh.md +2 -2
  205. package/docs/Microsoft.Quantum.Math/SmallestFixedPoint.md +2 -2
  206. package/docs/Microsoft.Quantum.Math/Sqrt.md +2 -2
  207. package/docs/Microsoft.Quantum.Math/SquaredNorm.md +2 -2
  208. package/docs/Microsoft.Quantum.Math/Tan.md +2 -2
  209. package/docs/Microsoft.Quantum.Math/Tanh.md +2 -2
  210. package/docs/Microsoft.Quantum.Math/TimesC.md +2 -2
  211. package/docs/Microsoft.Quantum.Math/TimesCP.md +2 -2
  212. package/docs/Microsoft.Quantum.Math/TrailingZeroCountI.md +2 -2
  213. package/docs/Microsoft.Quantum.Math/TrailingZeroCountL.md +2 -2
  214. package/docs/Microsoft.Quantum.Math/Truncate.md +2 -2
  215. package/docs/Microsoft.Quantum.Measurement/MResetEachZ.md +2 -2
  216. package/docs/Microsoft.Quantum.Measurement/MResetX.md +2 -2
  217. package/docs/Microsoft.Quantum.Measurement/MResetY.md +2 -2
  218. package/docs/Microsoft.Quantum.Measurement/MResetZ.md +2 -2
  219. package/docs/Microsoft.Quantum.Measurement/MeasureAllZ.md +2 -2
  220. package/docs/Microsoft.Quantum.Measurement/MeasureEachZ.md +2 -2
  221. package/docs/Microsoft.Quantum.Measurement/MeasureInteger.md +2 -2
  222. package/docs/Microsoft.Quantum.Random/DrawRandomDouble.md +2 -2
  223. package/docs/Microsoft.Quantum.Random/DrawRandomInt.md +2 -2
  224. package/docs/Microsoft.Quantum.ResourceEstimation/AccountForEstimates.md +2 -2
  225. package/docs/Microsoft.Quantum.ResourceEstimation/AuxQubitCount.md +2 -2
  226. package/docs/Microsoft.Quantum.ResourceEstimation/BeginEstimateCaching.md +2 -2
  227. package/docs/Microsoft.Quantum.ResourceEstimation/BeginRepeatEstimates.md +2 -2
  228. package/docs/Microsoft.Quantum.ResourceEstimation/CczCount.md +2 -2
  229. package/docs/Microsoft.Quantum.ResourceEstimation/EndEstimateCaching.md +2 -2
  230. package/docs/Microsoft.Quantum.ResourceEstimation/EndRepeatEstimates.md +2 -2
  231. package/docs/Microsoft.Quantum.ResourceEstimation/MeasurementCount.md +2 -2
  232. package/docs/Microsoft.Quantum.ResourceEstimation/PSSPCLayout.md +2 -2
  233. package/docs/Microsoft.Quantum.ResourceEstimation/RepeatEstimates.md +2 -2
  234. package/docs/Microsoft.Quantum.ResourceEstimation/RotationCount.md +2 -2
  235. package/docs/Microsoft.Quantum.ResourceEstimation/RotationDepth.md +2 -2
  236. package/docs/Microsoft.Quantum.ResourceEstimation/SingleVariant.md +2 -2
  237. package/docs/Microsoft.Quantum.ResourceEstimation/TCount.md +2 -2
  238. package/docs/Microsoft.Quantum.Unstable.Arithmetic/AddLE.md +2 -2
  239. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualL.md +2 -2
  240. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualLE.md +2 -2
  241. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterL.md +2 -2
  242. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterLE.md +2 -2
  243. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualL.md +2 -2
  244. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualLE.md +2 -2
  245. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessL.md +2 -2
  246. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessLE.md +2 -2
  247. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualL.md +2 -2
  248. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualLE.md +2 -2
  249. package/docs/Microsoft.Quantum.Unstable.Arithmetic/FourierTDIncByLE.md +2 -2
  250. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByI.md +2 -2
  251. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByIUsingIncByLE.md +2 -2
  252. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByL.md +2 -2
  253. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLE.md +2 -2
  254. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLEUsingAddLE.md +2 -2
  255. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLUsingIncByLE.md +2 -2
  256. package/docs/Microsoft.Quantum.Unstable.Arithmetic/LookAheadDKRSAddLE.md +2 -2
  257. package/docs/Microsoft.Quantum.Unstable.Arithmetic/MAJ.md +2 -2
  258. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ReflectAboutInteger.md +2 -2
  259. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGAddLE.md +2 -2
  260. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGIncByLE.md +2 -2
  261. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryTTKIncByLE.md +2 -2
  262. package/docs/Microsoft.Quantum.Unstable.StatePreparation/ApproximatelyPreparePureStateCP.md +2 -2
  263. package/docs/Microsoft.Quantum.Unstable.StatePreparation/PreparePureStateD.md +2 -2
  264. package/docs/Microsoft.Quantum.Unstable.TableLookup/Select.md +2 -2
  265. package/lib/node/qsc_wasm.cjs +74 -51
  266. package/lib/node/qsc_wasm.d.cts +12 -6
  267. package/lib/node/qsc_wasm_bg.wasm +0 -0
  268. package/lib/web/qsc_wasm.d.ts +17 -11
  269. package/lib/web/qsc_wasm.js +72 -49
  270. package/lib/web/qsc_wasm_bg.wasm +0 -0
  271. package/package.json +1 -1
  272. package/ux/estimatesOverview.tsx +6 -2
  273. package/ux/scatterChart.tsx +31 -10
@@ -1360,30 +1360,30 @@ export default {
1360
1360
  "items": [
1361
1361
  {
1362
1362
  "type": "text-content",
1363
- "asHtml": "<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>How to implement such 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<p>$\\renewcommand{\\ket}[1]{\\left\\lvert#1\\right\\rangle}$\n$\\renewcommand{\\bra}[1]{\\left\\langle#1\\right\\rvert}$</p>\n",
1364
- "asMarkdown": "\nIn 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.\n\n**This kata covers the following topics:**\n\n- Measuring a single qubit in a multi-qubit system\n- Measuring multiple qubits simultaneously\n- How to implement such measurements in Q#\n\n**What you should know to start working on this kata:**\n\n- Basic linear algebra\n- Single and multi-qubit systems\n- Single and multi-qubit gates\n- Single-qubit system measurements\n\n$\\renewcommand{\\ket}[1]{\\left\\lvert#1\\right\\rangle}$\n$\\renewcommand{\\bra}[1]{\\left\\langle#1\\right\\rvert}$"
1363
+ "asHtml": "<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<p>$\\renewcommand{\\ket}[1]{\\left\\lvert#1\\right\\rangle}$\n$\\renewcommand{\\bra}[1]{\\left\\langle#1\\right\\rvert}$</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 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&#39;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",
1364
+ "asMarkdown": "\nIn 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.\n\n**This kata covers the following topics:**\n\n- Measuring a single qubit in a multi-qubit system\n- Measuring multiple qubits simultaneously\n- Implementing different kinds of measurements in Q#\n\n**What you should know to start working on this kata:**\n\n- Basic linear algebra\n- Single and multi-qubit systems\n- Single and multi-qubit gates\n- Single-qubit system measurements\n\n$\\renewcommand{\\ket}[1]{\\left\\lvert#1\\right\\rangle}$\n$\\renewcommand{\\bra}[1]{\\left\\langle#1\\right\\rvert}$\n\n## Types of Measurements\n\nThere are several types of measurements you can perform on an $n$-qubit system ($n>1$):\n\n- 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.\n- Partial measurement: measuring $m$ qubits out of $n$, for $m<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.\n- Joint measurement: measuring a joint property of all $n$ qubits ($2$ possible outcomes).\n\nWe will discuss these concepts in the same order as in the list above."
1365
1365
  }
1366
1366
  ]
1367
1367
  },
1368
1368
  {
1369
1369
  "type": "lesson",
1370
- "id": "multi_qubit_measurements__types_of_measurements",
1371
- "title": "Types of Measurements",
1370
+ "id": "multi_qubit_measurements__full_measurements_lesson",
1371
+ "title": "Full Measurements: Measurements in Multi-Qubit Bases",
1372
1372
  "items": [
1373
1373
  {
1374
1374
  "type": "text-content",
1375
- "asHtml": "<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&#39;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<h2>Full Measurements: Measurements in Multi-Qubit Bases</h2>\n<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 $|0\\dotsc0\\rangle, \\dotsc, |1\\dotsc 1\\rangle$. For generality, we consider an arbitrary orthonormal basis, which we denote by ${ |b_0\\rangle, |b_1\\rangle, \\dotsc, |b_{2^n-1}\\rangle }$.</p>\n<p>Then, the state $|\\psi\\rangle$ of the multi-qubit system can be expressed as a linear combination of the $2^n$ basis vectors $|b_i\\rangle$. That is, there exist complex numbers $c_0,c_1,\\dotsc, c_{2^n-1}$ such that</p>\n<p>$$\n|\\psi\\rangle = \\sum_{i=0}^{2^n-1} c_i|b_i\\rangle \\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 ${ |b_0\\rangle, |b_1\\rangle, \\dotsc, |b_{2^n-1}\\rangle }$ basis 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 $|b_i\\rangle$. That is, the post-measurement state of the system is equal to $|b_i\\rangle$.</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\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>Multi-Qubit Measurement Outcome Probabilities I</h2>\n<p>Suppose that a two-qubit system is known to be in the following state:\n$$\\ket \\psi = \\frac{1}{3}\\ket {00} + \\frac{2}{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<p>The wave function $|\\psi\\rangle$ is normalized, since $\\left(\\frac{1}{3}\\right)^2 + \\left(\\frac{2}{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{1}{9}$, $\\frac{4}{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{1}{3}\\right)^2 = \\frac{1}{9}$</td>\n </tr>\n <tr>\n <td>$01$</td>\n <td>$\\left( \\frac{2}{3}\\right)^2 = \\frac{4}{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\n<h2>Multi-Qubit Measurement Outcome Probabilities II</h2>\n<p>Suppose that a two-qubit system is known to be 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 Pauli X basis, that is, in the ${ \\ket{++}, \\ket{+-}, \\ket{-+}, \\ket{--}}$ basis, what are the outcome probabilities?</p>\n<h3>Analytical Solution</h3>\n<p>Using the expressions $|0\\rangle = \\frac{1}{\\sqrt{2}} \\big( |+\\rangle + |-\\rangle \\big)$ and $|1\\rangle = \\frac{1}{\\sqrt{2}} \\big( |+\\rangle - |-\\rangle \\big)$, we first express $|\\psi\\rangle$ 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\n<h3>Code-Based Solution</h3>\n<p>We can also use Q# to solve this problem. It can be achieved in three steps:</p>\n<ol>\n<li>Prepare the state $\\ket \\psi$.</li>\n<li>Apply a transformation that maps the 2-qubit Pauli X basis into the 2-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\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<blockquote>\n<p>To implement the first step, we can represent $\\ket \\psi$ as<br>$$\\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.</p>\n<p>Notice that we start by rotating the second qubit, as this gives a simpler implementation. If we started by rotating the first qubit, we would need to use a CNOT gate and a controlled $R_y$ gate to achieve the same result.</p>\n</blockquote>\n",
1376
- "asMarkdown": "\nThere are several types of measurements you can perform on an $n$-qubit system ($n>1$):\n\n- 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.\n- Partial measurement: measuring $m$ qubits out of $n$, for $m<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.\n- Joint measurement: measuring a joint property of all $n$ qubits ($2$ possible outcomes).\n\nWe will discuss these concepts in the same order as in the list above.\n\n## Full Measurements: Measurements in Multi-Qubit Bases\n\nConsider 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 $|0\\dotsc0\\rangle, \\dotsc, |1\\dotsc 1\\rangle$. For generality, we consider an arbitrary orthonormal basis, which we denote by $\\{ |b_0\\rangle, |b_1\\rangle, \\dotsc, |b_{2^n-1}\\rangle \\}$.\n\nThen, the state $|\\psi\\rangle$ of the multi-qubit system can be expressed as a linear combination of the $2^n$ basis vectors $|b_i\\rangle$. That is, there exist complex numbers $c_0,c_1,\\dotsc, c_{2^n-1}$ such that\n\n$$\n|\\psi\\rangle = \\sum_{i=0}^{2^n-1} c_i|b_i\\rangle \\equiv \\begin{pmatrix} c_0 \\\\\\ c_1 \\\\\\ \\vdots \\\\\\ c_{2^n-1} \\end{pmatrix}\n$$\n\nIn 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 $\\{ |b_0\\rangle, |b_1\\rangle, \\dotsc, |b_{2^n-1}\\rangle \\}$ basis satisfies the following rules:\n\n- The measurement outcome $b_i$ occurs with probability $|c_i|^2$.\n- Whenever the measurement outcome is $b_i$, the wave function collapses to the state $|b_i\\rangle$. That is, the post-measurement state of the system is equal to $|b_i\\rangle$.\n\nThis can be summarized in the following table:\n\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\n> 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.\n\n## Multi-Qubit Measurement Outcome Probabilities I\n\nSuppose that a two-qubit system is known to be in the following state:\n$$\\ket \\psi = \\frac{1}{3}\\ket {00} + \\frac{2}{3} \\ket {01} + \\frac{2}{3}\\ket {11}$$\n\nIf all the qubits are measured simultaneously in the computational basis, what are the outcome probabilities?\n\nThe wave function $|\\psi\\rangle$ is normalized, since $\\left(\\frac{1}{3}\\right)^2 + \\left(\\frac{2}{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{1}{9}$, $\\frac{4}{9}$ and $\\frac{4}{9}$, respectively, and the probability of measuring the basis state $10$ that is not part of the superposition is $0$:\n\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{1}{3}\\right)^2 = \\frac{1}{9}$</td>\n </tr>\n <tr>\n <td>$01$</td>\n <td>$\\left( \\frac{2}{3}\\right)^2 = \\frac{4}{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\n## Multi-Qubit Measurement Outcome Probabilities II\n\nSuppose that a two-qubit system is known to be in the following state:\n$$\\ket \\psi = \\frac{2}{3}\\ket {00} + \\frac{1}{3} \\ket {01} + \\frac{2}{3}\\ket {11}$$\n\nIf 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?\n\n### Analytical Solution\n\nUsing the expressions $|0\\rangle = \\frac{1}{\\sqrt{2}} \\big( |+\\rangle + |-\\rangle \\big)$ and $|1\\rangle = \\frac{1}{\\sqrt{2}} \\big( |+\\rangle - |-\\rangle \\big)$, we first express $|\\psi\\rangle$ 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}$$\n\n$$= \\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]$$\n\n$$= \\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]$$\n\n$$= \\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]$$\n\n$$= (\\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{--}$$\n\n$$= \\frac{5}{6}\\ket{++} - \\frac{1}{6}\\ket{+-} + \\frac{1}{6}\\ket{-+} + \\frac{1}{2}\\ket{--}$$\n\nAfter 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:\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\n### Code-Based Solution\n\nWe can also use Q# to solve this problem. It can be achieved in three steps:\n\n1. Prepare the state $\\ket \\psi$.\n2. Apply a transformation that maps the 2-qubit Pauli X basis into the 2-qubit computational basis. This transformation just applies a Hadamard gate to each of the qubits.\n3. View probabilities of each basis state with the `DumpMachine` function. Thanks to the previous step, the following state equivalence holds:\n\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\nThe 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!\n\n>To implement the first step, we can represent $\\ket \\psi$ as \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}$$\n>This representation tells us how we should rotate individual qubits.\n>\n>Notice that we start by rotating the second qubit, as this gives a simpler implementation. If we started by rotating the first qubit, we would need to use a CNOT gate and a controlled $R_y$ gate to achieve the same result."
1375
+ "asHtml": "<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 $|0\\dotsc0\\rangle, \\dotsc, |1\\dotsc 1\\rangle$. For generality, we consider an arbitrary orthonormal basis, which we denote by $\\{ |b_0\\rangle, |b_1\\rangle, \\dotsc, |b_{2^n-1}\\rangle \\}$.</p>\n<p>Then, the state $|\\psi\\rangle$ of the multi-qubit system can be expressed as a linear combination of the $2^n$ basis vectors $|b_i\\rangle$. That is, there exist complex numbers $c_0,c_1,\\dotsc, c_{2^n-1}$ such that</p>\n<p>$$\n|\\psi\\rangle = \\sum_{i=0}^{2^n-1} c_i|b_i\\rangle \\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 $\\{ |b_0\\rangle, |b_1\\rangle, \\dotsc, |b_{2^n-1}\\rangle \\}$ 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 $|b_i\\rangle$. That is, the post-measurement state of the system is equal to $|b_i\\rangle$.</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\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{1}{3}\\ket {00} + \\frac{2}{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\n<p>The wave function $|\\psi\\rangle$ is normalized, since $\\left(\\frac{1}{3}\\right)^2 + \\left(\\frac{2}{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{1}{9}$, $\\frac{4}{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{1}{3}\\right)^2 = \\frac{1}{9}$</td>\n </tr>\n <tr>\n <td>$01$</td>\n <td>$\\left( \\frac{2}{3}\\right)^2 = \\frac{4}{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\n<h3>Multi-Qubit Measurement Outcome Probabilities II</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 Pauli X basis, that is, in the $\\{ \\ket{++}, \\ket{+-}, \\ket{-+}, \\ket{--}\\}$ basis, what are the outcome probabilities?</p>\n<details>\n<summary><b>Analytical Solution</b></summary>\n\n<p>Using the expressions $|0\\rangle = \\frac{1}{\\sqrt{2}} \\big( |+\\rangle + |-\\rangle \\big)$ and $|1\\rangle = \\frac{1}{\\sqrt{2}} \\big( |+\\rangle - |-\\rangle \\big)$, we first express $|\\psi\\rangle$ 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\n</details>\n\n<details>\n<summary><b>Code-Based Solution</b></summary>\n\n<p>We can also use Q# to solve this problem. It can be achieved in three steps:</p>\n<ol>\n<li>Prepare the state $\\ket \\psi$.</li>\n<li>Apply a transformation that maps the 2-qubit Pauli X basis into the 2-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\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<blockquote>\n<p>To implement the first step, we can represent $\\ket \\psi$ as<br>$$\\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.</p>\n<p>Notice that we start by rotating the second qubit, as this gives a simpler implementation. If we started by rotating the first qubit, we would need to use a $CNOT$ gate and a controlled $R_y$ gate to achieve the same result.</p>\n</blockquote>\n",
1376
+ "asMarkdown": "\nConsider 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 $|0\\dotsc0\\rangle, \\dotsc, |1\\dotsc 1\\rangle$. For generality, we consider an arbitrary orthonormal basis, which we denote by $\\\\{ |b_0\\rangle, |b_1\\rangle, \\dotsc, |b_{2^n-1}\\rangle \\\\}$.\n\nThen, the state $|\\psi\\rangle$ of the multi-qubit system can be expressed as a linear combination of the $2^n$ basis vectors $|b_i\\rangle$. That is, there exist complex numbers $c_0,c_1,\\dotsc, c_{2^n-1}$ such that\n\n$$\n|\\psi\\rangle = \\sum_{i=0}^{2^n-1} c_i|b_i\\rangle \\equiv \\begin{pmatrix} c_0 \\\\\\ c_1 \\\\\\ \\vdots \\\\\\ c_{2^n-1} \\end{pmatrix}\n$$\n\nIn 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 $\\\\{ |b_0\\rangle, |b_1\\rangle, \\dotsc, |b_{2^n-1}\\rangle \\\\}$ satisfies the following rules:\n\n- The measurement outcome $b_i$ occurs with probability $|c_i|^2$.\n- Whenever the measurement outcome is $b_i$, the wave function collapses to the state $|b_i\\rangle$. That is, the post-measurement state of the system is equal to $|b_i\\rangle$.\n\nThis can be summarized in the following table:\n\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\n> 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.\n\n## 🔎 Analyze\n\n### Multi-Qubit Measurement Outcome Probabilities I\n\nYou are given a two-qubit system in the following state:\n$$\\ket \\psi = \\frac{1}{3}\\ket {00} + \\frac{2}{3} \\ket {01} + \\frac{2}{3}\\ket {11}$$\n\nIf all the qubits are measured simultaneously in the computational basis, what are the outcome probabilities?\n\n<details>\n<summary><b>Solution</b></summary>\n\nThe wave function $|\\psi\\rangle$ is normalized, since $\\left(\\frac{1}{3}\\right)^2 + \\left(\\frac{2}{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{1}{9}$, $\\frac{4}{9}$ and $\\frac{4}{9}$, respectively, and the probability of measuring the basis state $10$ that is not part of the superposition is $0$:\n\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{1}{3}\\right)^2 = \\frac{1}{9}$</td>\n </tr>\n <tr>\n <td>$01$</td>\n <td>$\\left( \\frac{2}{3}\\right)^2 = \\frac{4}{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\n### Multi-Qubit Measurement Outcome Probabilities II\n\nYou 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}$$\n\nIf 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?\n\n<details>\n<summary><b>Analytical Solution</b></summary>\n\nUsing the expressions $|0\\rangle = \\frac{1}{\\sqrt{2}} \\big( |+\\rangle + |-\\rangle \\big)$ and $|1\\rangle = \\frac{1}{\\sqrt{2}} \\big( |+\\rangle - |-\\rangle \\big)$, we first express $|\\psi\\rangle$ 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} =$$\n\n$$= \\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] =$$\n\n$$= \\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] =$$\n\n$$= \\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] =$$\n\n$$= (\\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{--} =$$\n\n$$= \\frac{5}{6}\\ket{++} - \\frac{1}{6}\\ket{+-} + \\frac{1}{6}\\ket{-+} + \\frac{1}{2}\\ket{--}$$\n\nAfter 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:\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\n</details>\n\n<details>\n<summary><b>Code-Based Solution</b></summary>\n\nWe can also use Q# to solve this problem. It can be achieved in three steps:\n\n1. Prepare the state $\\ket \\psi$.\n2. Apply a transformation that maps the 2-qubit Pauli X basis into the 2-qubit computational basis. This transformation just applies a Hadamard gate to each of the qubits.\n3. View probabilities of each basis state with the `DumpMachine` function. Thanks to the previous step, the following state equivalence holds:\n\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\nThe 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!\n\n>To implement the first step, we can represent $\\ket \\psi$ as \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}$$\n>This representation tells us how we should rotate individual qubits.\n>\n>Notice that we start by rotating the second qubit, as this gives a simpler implementation. If we started by rotating the first qubit, we would need to use a $CNOT$ gate and a controlled $R_y$ gate to achieve the same result."
1377
1377
  },
1378
1378
  {
1379
1379
  "type": "example",
1380
1380
  "id": "multi_qubit_measurements__multi_qubit_probabilities_2_example",
1381
- "code": "namespace Kata {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n\n operation SetInitialState(qs : Qubit[]) : Unit is Adj + Ctl {\n // Next two lines set the second qubit into the desired state\n let second_bit_angle = 2.0 * ArcCos(2.0 / 3.0);\n Ry(second_bit_angle, qs[1]);\n\n // Next two lines set the first qubit into the desired state\n let first_bit_angle = 2.0 * ArcCos(1.0 / Sqrt(5.0));\n Controlled Ry([qs[1]], (first_bit_angle, qs[0]));\n }\n\n operation ChangeBasis(qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n H(qs[1]);\n }\n\n @EntryPoint()\n operation CalculateProbabilities() : Unit {\n // This allocates qubits for us to work with\n use qs = Qubit[2];\n\n SetInitialState(qs);\n\n // Check that we've prepared the state |𝜓⟩\n Message(\"The state of the system before the transformation:\");\n DumpMachine();\n\n ChangeBasis(qs);\n\n Message(\"Final state of the two-qubit system:\");\n DumpMachine();\n\n // This returns the qubit array into state |00❭\n ResetAll(qs);\n }\n\n}\n"
1381
+ "code": "namespace Kata {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation CalculateProbabilities() : Unit {\n use qs = Qubit[2];\n\n Ry(2. * ArcCos(2. / 3.), qs[1]);\n Controlled Ry([qs[1]], (2. * ArcCos(1. / Sqrt(5.)), qs[0]));\n\n Message(\"The initial state of the system:\");\n DumpMachine();\n\n // Change the basis\n H(qs[0]);\n H(qs[1]);\n\n Message(\"Final state of the two-qubit system:\");\n DumpMachine();\n\n // Return the qubit array into state |00❭.\n ResetAll(qs);\n }\n}\n"
1382
1382
  },
1383
1383
  {
1384
1384
  "type": "text-content",
1385
- "asHtml": "<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 tensor product state. 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 2-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",
1386
- "asMarkdown": "\n## Measuring Each Qubit in a System Sequentially\n\nAs 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.\n\nIn 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$.\n\nThis 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.\n\n> 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 tensor product state. 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 2-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.\n>\n> 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.\n> We will not discuss such measurements in this kata.\n>\n> 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."
1385
+ "asHtml": "</details>\n\n\n<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",
1386
+ "asMarkdown": "\n</details>\n\n\n## Measuring Each Qubit in a System Sequentially\n\nAs 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.\n\nIn 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$.\n\nThis 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.\n\n> 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 **tensor product state**. 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.\n>\n> 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.\n> We will not discuss such measurements in this kata.\n>\n> 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."
1387
1387
  }
1388
1388
  ]
1389
1389
  },
@@ -1394,18 +1394,18 @@ export default {
1394
1394
  "items": [
1395
1395
  {
1396
1396
  "type": "text-content",
1397
- "asHtml": "<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. Using the wave function from exercise 1 above as an example, we show that the measurement probabilities obtained using the <code>M</code> operation in Q# are the same as those expected theoretically for exercise 1.</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",
1398
- "asMarkdown": "\nThis 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. Using the wave function from exercise 1 above as an example, we show that the measurement probabilities obtained using the `M` operation in Q# are the same as those expected theoretically for exercise 1.\n\nThe simulated probabilities will be different for each run of `DemoBasisMeasurement`. 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 `numRuns` is increased."
1397
+ "asHtml": "<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",
1398
+ "asMarkdown": "\nThis 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 `M` operation in Q# are the same as those expected theoretically, using the two-qubit state from the first exercise as an example:\n\n$$\\ket \\psi = \\frac{1}{3}\\ket {00} + \\frac{2}{3} \\ket {01} + \\frac{2}{3}\\ket {11}$$\n\nThe simulated probabilities will be different for each run of `DemoBasisMeasurement`. 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 `numRuns` is increased."
1399
1399
  },
1400
1400
  {
1401
1401
  "type": "example",
1402
1402
  "id": "multi_qubit_measurements__measuring_one_at_a_time",
1403
- "code": "namespace Kata {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Measurement;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation DemoBasisMeasurement() : Unit {\n let numRuns = 1000;\n\n // Define coefficients and obtain measurement probabilities for the\n // state |psi❭ = 0.33 |00❭ + 0.67 |01❭ + 0.67 |11❭\n // Use little endian format to encode basis states as integer indices.\n let coefficients = [0.333, 0.0, 0.667, 0.667];\n let expected_probabilities = [0.111, 0.0, 0.445, 0.445];\n\n // Set up counter array for measurements.\n mutable countArray = [0, 0, 0, 0];\n\n use qs = Qubit[2];\n for i in 1 .. numRuns {\n // Prepare the state from Exercise 1:\n PrepareEx1State(qs);\n if i == 1 {\n Message(\"The state |psi❭ of the system before measurement is:\");\n DumpMachine();\n }\n\n // Measure the first qubit, followed by the second qubit, and\n // convert the result to little endian integer\n let result = MeasureInteger(qs);\n\n // Update countArray\n set countArray w/= result <- countArray[result] + 1;\n }\n\n // Obtain simulated probability of measurement for each outcome\n mutable simulated_probabilities = [];\n for i in 0 .. 3 {\n set simulated_probabilities +=\n [IntAsDouble(countArray[i]) / IntAsDouble(numRuns)];\n }\n\n Message($\"Theoretical measurement probabilities are {expected_probabilities}\");\n Message($\"Simulated measurement probabilities are {simulated_probabilities}\");\n }\n\n operation PrepareEx1State(q : Qubit[]) : Unit {\n Ry(-ArcCos(1.0/9.0), q[0]);\n within {\n S(q[1]);\n H(q[1]);\n } apply {\n Rz(ArcTan(0.5), q[1]);\n CNOT(q[0], q[1]);\n Rz(ArcTan(0.5)-PI(), q[1]);\n CNOT(q[0], q[1]);\n }\n }\n}\n"
1403
+ "code": "namespace Kata {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation DemoBasisMeasurement() : Unit {\n let expected_probabilities = [1. / 9., 4. / 9., 0., 4. / 9.];\n\n // Set up counter array for tracking measurement outcomes.\n mutable countArray = [0, 0, 0, 0];\n\n use qs = Qubit[2];\n let numRuns = 1000;\n for i in 1 .. numRuns {\n // Prepare the starting state.\n Ry(2. * ArcCos(1. / 3.), qs[1]);\n Controlled H([qs[1]], qs[0]);\n if i == 1 {\n Message(\"The state of the system before measurement is:\");\n DumpMachine();\n }\n\n // Measure the first (most significant) qubit, then measure the second (least significant) qubit,\n // and convert the result to an integer, interpreting it as big endian binary notation.\n let result = (MResetZ(qs[0]) == One ? 1 | 0) * 2 + (MResetZ(qs[1]) == One ? 1 | 0);\n\n set countArray w/= result <- countArray[result] + 1;\n }\n\n // Obtain simulated probability of measurement for each outcome.\n mutable simulated_probabilities = [];\n for i in 0 .. 3 {\n set simulated_probabilities +=\n [IntAsDouble(countArray[i]) / IntAsDouble(numRuns)];\n }\n\n Message($\"Theoretical measurement probabilities are {expected_probabilities}\");\n Message($\"Simulated measurement probabilities are {simulated_probabilities}\");\n }\n}\n"
1404
1404
  },
1405
1405
  {
1406
1406
  "type": "text-content",
1407
- "asHtml": "<h2>Using Full Measurements to Identify the State of the System</h2>\n<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",
1408
- "asMarkdown": "\n## Using Full Measurements to Identify the State of the System\n\nFull 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."
1407
+ "asHtml": "<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",
1408
+ "asMarkdown": "\nFull 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."
1409
1409
  }
1410
1410
  ]
1411
1411
  },
@@ -1423,29 +1423,29 @@ export default {
1423
1423
  "multi_qubit_measurements__Common.qs",
1424
1424
  "KatasLibrary.qs"
1425
1425
  ],
1426
- "placeholderCode": "namespace Kata {\n operation BasisStateMeasurement(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n\n}\n",
1426
+ "placeholderCode": "namespace Kata {\n operation BasisStateMeasurement(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n}\n",
1427
1427
  "explainedSolution": {
1428
1428
  "type": "explained-solution",
1429
1429
  "items": [
1430
1430
  {
1431
1431
  "type": "text-content",
1432
- "asHtml": "<p>First, we measure both qubits in the input array and store the result in <code>m1</code> and <code>m2</code>. We can decode these results like this: </p>\n<ul>\n<li><code>m1</code> is $|0\\rangle$ and <code>m2</code> is $|0\\rangle$: we return $0\\cdot2+0 = 0$</li>\n<li><code>m1</code> is $|0\\rangle$ and <code>m2</code> is $|1\\rangle$: we return $0\\cdot2+1 = 1$</li>\n<li><code>m1</code> is $|1\\rangle$ and <code>m2</code> is $|0\\rangle$: we return $1\\cdot2+0 = 2$</li>\n<li><code>m1</code> is $|1\\rangle$ and <code>m2</code> is $|1\\rangle$: 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",
1433
- "asMarkdown": "\nFirst, we measure both qubits in the input array and store the result in `m1` and `m2`. We can decode these results like this: \n\n- `m1` is $|0\\rangle$ and `m2` is $|0\\rangle$: we return $0\\cdot2+0 = 0$\n- `m1` is $|0\\rangle$ and `m2` is $|1\\rangle$: we return $0\\cdot2+1 = 1$\n- `m1` is $|1\\rangle$ and `m2` is $|0\\rangle$: we return $1\\cdot2+0 = 2$\n- `m1` is $|1\\rangle$ and `m2` is $|1\\rangle$: we return $1\\cdot2+1 = 3$\n\nIn other words, we treat the measurement results as the binary notation of the return value in big endian notation."
1432
+ "asHtml": "<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 $|0\\rangle$ and <code>m2</code> is $|0\\rangle$: we return $0\\cdot2+0 = 0$</li>\n<li><code>m1</code> is $|0\\rangle$ and <code>m2</code> is $|1\\rangle$: we return $0\\cdot2+1 = 1$</li>\n<li><code>m1</code> is $|1\\rangle$ and <code>m2</code> is $|0\\rangle$: we return $1\\cdot2+0 = 2$</li>\n<li><code>m1</code> is $|1\\rangle$ and <code>m2</code> is $|1\\rangle$: 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",
1433
+ "asMarkdown": "\nFirst, we measure each of the qubits in the input array, convert the measurement results into integers\nand store them in variables `m1` and `m2`. We can decode these results like this: \n\n- `m1` is $|0\\rangle$ and `m2` is $|0\\rangle$: we return $0\\cdot2+0 = 0$\n- `m1` is $|0\\rangle$ and `m2` is $|1\\rangle$: we return $0\\cdot2+1 = 1$\n- `m1` is $|1\\rangle$ and `m2` is $|0\\rangle$: we return $1\\cdot2+0 = 2$\n- `m1` is $|1\\rangle$ and `m2` is $|1\\rangle$: we return $1\\cdot2+1 = 3$\n\nIn other words, we treat the measurement results as the binary notation of the return value in big-endian notation."
1434
1434
  },
1435
1435
  {
1436
1436
  "type": "solution",
1437
1437
  "id": "multi_qubit_measurements__full_measurements_solution",
1438
- "code": "namespace Kata {\n\n operation BasisStateMeasurement(qs : Qubit[]) : Int {\n // Measurement on the first qubit gives the higher bit of the answer, on the second - the lower\n let m1 = M(qs[0]) == Zero ? 0 | 1;\n let m2 = M(qs[1]) == Zero ? 0 | 1;\n return m1 * 2 + m2;\n }\n\n}\n"
1438
+ "code": "namespace Kata {\n operation BasisStateMeasurement(qs : Qubit[]) : Int {\n // Measurement on the first qubit gives the most significant bit of the answer, \n // on the second - the least significant bit.\n let m1 = M(qs[0]) == Zero ? 0 | 1;\n let m2 = M(qs[1]) == Zero ? 0 | 1;\n return m1 * 2 + m2;\n }\n}\n"
1439
1439
  },
1440
1440
  {
1441
1441
  "type": "text-content",
1442
- "asHtml": "<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&#39;s why we have to reverse the array before converting it).</li>\n</ul>\n",
1443
- "asMarkdown": "\nWe 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:\n\n- `MeasureEachZ` measures each of the qubits in the array in the computational basis and returns an array of `Result` data type.\n- `Reversed` reverses the given array.\n- `ResultArrayAsInt` converts an array of bits given as `Result` to an integer, assuming little-endian notation (that's why we have to reverse the array before converting it)."
1442
+ "asHtml": "<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&#39;s why we have to reverse the array before converting it).</li>\n</ul>\n",
1443
+ "asMarkdown": "\nWe 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:\n\n- `MeasureEachZ` measures each of the qubits in the array in the computational basis and returns an array of `Result` data type.\n- `Reversed` reverses the given array.\n- `ResultArrayAsInt` converts an array of bits given as `Result` to an integer, assuming little-endian notation (that's why we have to reverse the array before converting it)."
1444
1444
  },
1445
1445
  {
1446
1446
  "type": "solution",
1447
1447
  "id": "multi_qubit_measurements__full_measurements_solution_alt",
1448
- "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Measurement;\n\n operation BasisStateMeasurement(qs : Qubit[]) : Int {\n return ResultArrayAsInt(Reversed(MeasureEachZ(qs)));\n }\n \n}\n"
1448
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Measurement;\n\n operation BasisStateMeasurement(qs : Qubit[]) : Int {\n return ResultArrayAsInt(Reversed(MeasureEachZ(qs)));\n }\n}\n"
1449
1449
  }
1450
1450
  ]
1451
1451
  }
@@ -1457,8 +1457,8 @@ export default {
1457
1457
  "items": [
1458
1458
  {
1459
1459
  "type": "text-content",
1460
- "asHtml": "<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 single-qubit systems measurements 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 $|\\psi\\rangle$, for which the first $m&lt;n$ qubits are measured in an orthogonal basis ${ |b_0\\rangle , |b_1\\rangle, \\dotsc, |b_{2^m-1}\\rangle}$ corresponding to the $m$ qubits being measured. Then we define $2^m$ projectors corresponding to each of the $|b_i\\rangle$ states as</p>\n<p>$$P_i = |b_i\\rangle \\langle 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<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, $|b_i\\rangle \\langle b_i| \\otimes \\mathbb{1}_{n-m}$ simply means that</p>\n<ul>\n<li>The operator $|b_i\\rangle \\langle 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<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|\\psi\\rangle\\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 |\\psi\\rangle}{\\big|P_i |\\psi\\rangle\\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$$</p>\n<p>$$= \\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\\bra 0 0\\rangle \\otimes \\mathbb{1} \\ket{1} - \\ket 0 \\bra 0 1\\rangle \\otimes \\mathbb{1} \\ket 0 \\big)$$</p>\n<p>$$= \\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<p><strong>Partial measurement probabilities for the Hardy state</strong></p>\n<p>Consider a 2-qubit system in the state $\\ket \\psi = \\frac{1}{\\sqrt{12}} \\big(3|00\\rangle + |01\\rangle + |10\\rangle + |11\\rangle\\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 = |0\\rangle\\langle 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\n<p>Similarly, $P_1 = |1\\rangle \\langle 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>",
1461
- "asMarkdown": "\nFor a system with $n>1$ qubits, it is possible to measure $m<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.\n\nFirst, we recall the concept of projection operators introduced in the single-qubit systems measurements 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 $|\\psi\\rangle$, for which the first $m<n$ qubits are measured in an orthogonal basis $\\{ |b_0\\rangle , |b_1\\rangle, \\dotsc, |b_{2^m-1}\\rangle\\}$ corresponding to the $m$ qubits being measured. Then we define $2^m$ projectors corresponding to each of the $|b_i\\rangle$ states as\n\n$$P_i = |b_i\\rangle \\langle b_i| \\otimes \\mathbb{1}_{n-m} $$\n\nwhere $\\mathbb{1}_{n-m}$ is the identity operator over the remaining $(n-m)$ qubits.\n\nThe 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, $|b_i\\rangle \\langle b_i| \\otimes \\mathbb{1}_{n-m}$ simply means that\n\n- The operator $|b_i\\rangle \\langle b_i|$ acts only on the $m$ qubits being measured.\n- The effect of $P_i$ on the remaining qubits is $\\mathbb{1}_{n-m} $, i.e., the identity operator.\n\nAnalogous to the case for measurements for single-qubit systems, the rules for partial measurement probabilities and outcomes can be summarized as follows:\n\n- When a measurement is done, one of these projectors is chosen randomly. The probability of choosing projector $P_i$ is $\\big|P_i|\\psi\\rangle\\big|^2$.\n- 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\n\n$$\n\\frac{P_i |\\psi\\rangle}{\\big|P_i |\\psi\\rangle\\big|}.\n$$\n\nFor 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}$$\n\nThe action of $P_0$ on $\\ket \\psi$ is\n\n$$P_0 \\ket \\psi$$\n\n$$= \\left(\\ket 0\\bra 0 \\otimes \\mathbb{1}\\right) \\frac{1}{\\sqrt 2}\\big(\\ket{01} - \\ket{10}\\big)$$\n\n$$= \\frac{1}{\\sqrt 2} \\big( \\ket 0\\bra 0 0\\rangle \\otimes \\mathbb{1} \\ket{1} - \\ket 0 \\bra 0 1\\rangle \\otimes \\mathbb{1} \\ket 0 \\big)$$\n\n$$= \\frac{1}{\\sqrt 2} \\ket{01}$$\n\nSimilarly, we obtain\n$$P_1 \\ket\\psi = -\\frac{1}{\\sqrt 2} \\ket{10}$$\n\nClearly, 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.\n\n> 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.\n\n## 🔎 Analyze\n\n**Partial measurement probabilities for the Hardy state**\n\nConsider a 2-qubit system in the state $\\ket \\psi = \\frac{1}{\\sqrt{12}} \\big(3|00\\rangle + |01\\rangle + |10\\rangle + |11\\rangle\\big)$.\n\nIf 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?\n\n<details>\n<summary><b>Solution</b></summary>\nA measurement outcome of $0$ on the first qubit corresponds to the projection operator $P_0 = |0\\rangle\\langle 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\nSimilarly, $P_1 = |1\\rangle \\langle 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\n\n$$\\frac{P_1 \\ket{\\psi}}{\\big|P_1 \\ket{\\psi}\\big|} = \\frac{1}{\\sqrt{2}} \\left(\\ket{10} + \\ket{11}\\right)$$\n\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>"
1460
+ "asHtml": "<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 $|\\psi\\rangle$, for which the first $m&lt;n$ qubits are measured in an orthogonal basis $\\{ |b_0\\rangle , |b_1\\rangle, \\dotsc, |b_{2^m-1}\\rangle\\}$ corresponding to the $m$ qubits being measured. Then we define $2^m$ projectors corresponding to each of the $|b_i\\rangle$ states as</p>\n<p>$$P_i = |b_i\\rangle \\langle 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, $|b_i\\rangle \\langle b_i| \\otimes \\mathbb{1}_{n-m}$ simply means that</p>\n<ul>\n<li>The operator $|b_i\\rangle \\langle 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|\\psi\\rangle\\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 |\\psi\\rangle}{\\big|P_i |\\psi\\rangle\\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\\bra 0 0\\rangle \\otimes \\mathbb{1} \\ket{1} - \\ket 0 \\bra 0 1\\rangle \\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|00\\rangle + |01\\rangle + |10\\rangle + |11\\rangle\\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 = |0\\rangle\\langle 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\n<p>Similarly, $P_1 = |1\\rangle \\langle 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>",
1461
+ "asMarkdown": "\nFor a system with $n>1$ qubits, it is possible to measure $m<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.\n\nFirst, 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 $|\\psi\\rangle$, for which the first $m<n$ qubits are measured in an orthogonal basis $\\\\{ |b_0\\rangle , |b_1\\rangle, \\dotsc, |b_{2^m-1}\\rangle\\\\}$ corresponding to the $m$ qubits being measured. Then we define $2^m$ projectors corresponding to each of the $|b_i\\rangle$ states as\n\n$$P_i = |b_i\\rangle \\langle b_i| \\otimes \\mathbb{1}_{n-m} $$\n\nwhere $\\mathbb{1}_{n-m}$ is the identity operator over the remaining $(n-m)$ qubits.\n\n> The symbol $\\otimes$ represents the tensor product or the Kronecker product of two matrices. It is different from the usual matrix multiplication.\n> In the current context, $|b_i\\rangle \\langle b_i| \\otimes \\mathbb{1}_{n-m}$ simply means that\n>\n> - The operator $|b_i\\rangle \\langle b_i|$ acts only on the $m$ qubits being measured.\n> - The effect of $P_i$ on the remaining qubits is $\\mathbb{1}_{n-m} $, i.e., the identity operator.\n\nAnalogous to the case for measurements for single-qubit systems, the rules for partial measurement probabilities and outcomes can be summarized as follows:\n\n- When a measurement is done, one of these projectors is chosen randomly. The probability of choosing projector $P_i$ is $\\big|P_i|\\psi\\rangle\\big|^2$.\n- 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\n\n$$\n\\frac{P_i |\\psi\\rangle}{\\big|P_i |\\psi\\rangle\\big|}.\n$$\n\nFor 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}$$\n\nThe action of $P_0$ on $\\ket \\psi$ is\n\n$$P_0 \\ket \\psi = \\left(\\ket 0\\bra 0 \\otimes \\mathbb{1}\\right) \\frac{1}{\\sqrt 2}\\big(\\ket{01} - \\ket{10}\\big) =$$\n\n$$= \\frac{1}{\\sqrt 2} \\big( \\ket 0\\bra 0 0\\rangle \\otimes \\mathbb{1} \\ket{1} - \\ket 0 \\bra 0 1\\rangle \\otimes \\mathbb{1} \\ket 0 \\big) = \\frac{1}{\\sqrt 2} \\ket{01}$$\n\nSimilarly, we obtain\n$$P_1 \\ket\\psi = -\\frac{1}{\\sqrt 2} \\ket{10}$$\n\nClearly, 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.\n\n> 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.\n\n## 🔎 Analyze\n\n### Partial measurement probabilities for the Hardy state\n\nConsider a 2-qubit system in the state $\\ket \\psi = \\frac{1}{\\sqrt{12}} \\big(3|00\\rangle + |01\\rangle + |10\\rangle + |11\\rangle\\big)$.\n\nIf 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?\n\n<details>\n<summary><b>Solution</b></summary>\nA measurement outcome of $0$ on the first qubit corresponds to the projection operator $P_0 = |0\\rangle\\langle 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\nSimilarly, $P_1 = |1\\rangle \\langle 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\n\n$$\\frac{P_1 \\ket{\\psi}}{\\big|P_1 \\ket{\\psi}\\big|} = \\frac{1}{\\sqrt{2}} \\left(\\ket{10} + \\ket{11}\\right)$$\n\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>"
1462
1462
  }
1463
1463
  ]
1464
1464
  },
@@ -1469,18 +1469,18 @@ export default {
1469
1469
  "items": [
1470
1470
  {
1471
1471
  "type": "text-content",
1472
- "asHtml": "<p>Using the <code>M</code> operation in Q#, we demonstrate that the simulated outcome probabilities and post-measurement outcomes match the theoretical values obtained using the projection operators as described above. We use the Hardy state from Exercise 4 with 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 for Exercise 4 precisely, since partial state collapse is not a probabilistic process.</p>\n",
1473
- "asMarkdown": "\nUsing the `M` operation in Q#, we demonstrate that the simulated outcome probabilities and post-measurement outcomes match the theoretical values obtained using the projection operators as described above. We use the Hardy state from Exercise 4 with a computational basis measurement on the first qubit for this purpose.\n\nThe 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 for Exercise 4 precisely, since partial state collapse is not a probabilistic process."
1472
+ "asHtml": "<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|00\\rangle + |01\\rangle + |10\\rangle + |11\\rangle\\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",
1473
+ "asMarkdown": "\nIn 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|00\\rangle + |01\\rangle + |10\\rangle + |11\\rangle\\big)$ from the previous exercise and do a computational basis measurement on the first qubit for this purpose.\n\nThe 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."
1474
1474
  },
1475
1475
  {
1476
1476
  "type": "example",
1477
1477
  "id": "multi_qubit_measurements__partial_measurements_demo",
1478
- "code": "namespace Kata {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation DemoPartialMeasurement() : Unit {\n let numRuns = 1000;\n let divider = \"--------------------------------------------------------------------------------------------------\";\n //\n // We can use coefficients without normalization in PrepareArbitraryStateD,\n // the operation will normalize them automatically.\n let coefficients = [3., 1., 1., 1.];\n let expected_probabilities = [0.833, 0.167];\n\n // Set up the counter array for measurements.\n mutable countArray = [0, 0];\n\n use qs = Qubit[2];\n for i in 1 .. numRuns {\n // Prepare the state from Exercise 4:\n // |𝜓❭ = (1/√12)(3|00⟩+|01⟩+|10⟩+|11⟩)\n PrepareHardyState(qs);\n\n // Display the state of the qubits.\n if i == 1 {\n Message(\"The state |𝜓❭ of the system before measurement is:\");\n DumpMachine();\n Message(divider);\n }\n\n // Measure the first qubit.\n let outcome = M(qs[0]) == Zero ? 0 | 1;\n set countArray w/= outcome <- countArray[outcome] + 1;\n\n if countArray[outcome] == 1 {\n // The first time the outcome is 0/1, print the system state afterwards.\n Message(\"For outcome {outcome}, the post-measurement state of the system is:\");\n DumpMachine();\n }\n ResetAll(qs);\n }\n\n // Obtain simulated probability of measurement for each outcome\n mutable simulated_probabilities = [];\n for i in 0 .. 1 {\n set simulated_probabilities += [IntAsDouble(countArray[i]) / IntAsDouble(numRuns)];\n }\n\n Message($\"Theoretical measurement probabilities are {expected_probabilities}\");\n Message($\"Simulated measurement probabilities are {simulated_probabilities}\");\n }\n\n operation PrepareHardyState(q : Qubit[]) : Unit {\n Ry(ArcCos(2.0/3.0), q[1]);\n within {\n S(q[0]);\n H(q[0]);\n } apply {\n CNOT(q[1], q[0]);\n Rz(ArcTan(1.0/2.0), q[0]);\n CNOT(q[1], q[0]);\n Rz(-ArcTan(2.0), q[0]);\n }\n }\n\n}\n"
1478
+ "code": "namespace Kata {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation DemoPartialMeasurement() : Unit {\n let expected_probabilities = [0.833, 0.167];\n\n let numRuns = 1000;\n mutable countArray = [0, 0];\n use qs = Qubit[2];\n for i in 1 .. numRuns {\n // Prepare the Hardy state |𝜓❭ = (1/√12)(3|00⟩ + |01⟩ + |10⟩ + |11⟩)\n Ry(2. * ArcCos(Sqrt(5. / 6.)), qs[0]);\n ApplyControlledOnInt(0, Ry, [qs[0]], (2. * ArcCos(3. / Sqrt(10.)), qs[1]));\n Controlled H([qs[0]], qs[1]);\n\n if i == 1 {\n Message(\"The state |𝜓❭ of the system before measurement is:\");\n DumpMachine();\n }\n\n // Measure the first qubit.\n let outcome = M(qs[0]) == Zero ? 0 | 1;\n set countArray w/= outcome <- countArray[outcome] + 1;\n\n if countArray[outcome] == 1 {\n // The first time the outcome is 0/1, print the system state afterwards.\n Message($\"For outcome {outcome}, the post-measurement state of the system is:\");\n DumpMachine();\n }\n ResetAll(qs);\n }\n\n // Obtain simulated probability of measurement for each outcome.\n mutable simulated_probabilities = [];\n for i in 0 .. 1 {\n set simulated_probabilities += [IntAsDouble(countArray[i]) / IntAsDouble(numRuns)];\n }\n\n Message($\"Theoretical measurement probabilities are {expected_probabilities}\");\n Message($\"Simulated measurement probabilities are {simulated_probabilities}\");\n }\n}\n"
1479
1479
  },
1480
1480
  {
1481
1481
  "type": "text-content",
1482
- "asHtml": "<h2>Using Partial Measurements to Identify the State of the System</h2>\n<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",
1483
- "asMarkdown": "\n## Using Partial Measurements to Identify the State of the System\n\nIn certain situations, it is possible to distinguish between orthogonal states of multi-qubit systems using partial measurements, as illustrated in the next exercise."
1482
+ "asHtml": "<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",
1483
+ "asMarkdown": "\nIn certain situations, it is possible to distinguish between orthogonal states of multi-qubit systems using partial measurements, as illustrated in the next exercise."
1484
1484
  }
1485
1485
  ]
1486
1486
  },
@@ -1498,7 +1498,7 @@ export default {
1498
1498
  "multi_qubit_measurements__Common.qs",
1499
1499
  "KatasLibrary.qs"
1500
1500
  ],
1501
- "placeholderCode": "namespace Kata {\n operation IsPlusPlusMinus(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n\n}\n",
1501
+ "placeholderCode": "namespace Kata {\n operation IsPlusPlusMinus(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n}\n",
1502
1502
  "explainedSolution": {
1503
1503
  "type": "explained-solution",
1504
1504
  "items": [
@@ -1510,7 +1510,7 @@ export default {
1510
1510
  {
1511
1511
  "type": "solution",
1512
1512
  "id": "multi_qubit_measurements__partial_measurements_for_system_solution",
1513
- "code": "namespace Kata {\n\n operation IsPlusPlusMinus(qs : Qubit[]) : Int {\n return Measure([PauliX], [qs[0]]) == Zero ? 0 | 1;\n }\n\n}\n"
1513
+ "code": "namespace Kata {\n operation IsPlusPlusMinus(qs : Qubit[]) : Int {\n return Measure([PauliX], [qs[0]]) == Zero ? 0 | 1;\n }\n}\n"
1514
1514
  }
1515
1515
  ]
1516
1516
  }
@@ -1522,8 +1522,8 @@ export default {
1522
1522
  "items": [
1523
1523
  {
1524
1524
  "type": "text-content",
1525
- "asHtml": "<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 kata on multi-qubit systems. Consider a system of $n&gt;1$ number of 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$$\n\\ket \\psi = \\ket {\\phi_A} \\otimes \\ket{\\phi_B}\n$$\nwhere $\\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|}$$</p>\n<p>$$= \\frac{\\ket{b_i}\\bra{b_i}\\phi_A\\rangle \\otimes \\ket {\\phi_B}}{\\big|\\ket{b_i}\\bra{b_i}\\phi_A\\rangle \\otimes \\ket {\\phi_B}\\big|}$$</p>\n<p>$$= \\frac{\\bra{b_i}\\phi_A\\rangle \\cdot \\ket{b_i} \\otimes \\ket {\\phi_B}}{\\big|\\ket{b_i}\\big| \\cdot \\bra{b_i}\\phi_A\\rangle \\cdot \\big| \\ket {\\phi_B}\\big|}$$</p>\n<p>$$= \\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<p><strong>Sequential measurements on an entangled state and a separable state</strong></p>\n<p>Consider two two-qubit states:</p>\n<ul>\n<li>The Bell state $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big (|00\\rangle + |11\\rangle\\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 *always* 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 *correlated*.</p>\n\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\n<p>This aligns with the fact that the Bell state is entangled, while the $\\ket{\\theta}$ is separable and can be expressed as $\\ket \\theta = \\ket + \\otimes \\ket +$.</p>\n</details>\n\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",
1526
- "asMarkdown": "\nEntanglement 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.\n\n> It is useful to revisit the concepts of entanglement and separable states, which were introduced in the kata on multi-qubit systems. Consider a system of $n>1$ number of 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$$\n\\ket \\psi = \\ket {\\phi_A} \\otimes \\ket{\\phi_B}\n$$\nwhere $\\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.\n\nConsider 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\n\n$$\\ket{\\psi}_{i} \\equiv \\frac{P_i \\ket{\\psi}}{\\big|P_i \\ket{\\psi}\\big|}$$\n\n$$= \\frac{\\ket{b_i}\\bra{b_i}\\phi_A\\rangle \\otimes \\ket {\\phi_B}}{\\big|\\ket{b_i}\\bra{b_i}\\phi_A\\rangle \\otimes \\ket {\\phi_B}\\big|}$$\n\n$$= \\frac{\\bra{b_i}\\phi_A\\rangle \\cdot \\ket{b_i} \\otimes \\ket {\\phi_B}}{\\big|\\ket{b_i}\\big| \\cdot \\bra{b_i}\\phi_A\\rangle \\cdot \\big| \\ket {\\phi_B}\\big|}$$\n\n$$= \\ket{b_i} \\otimes \\ket{\\phi_B}$$\n\nThus, 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.\n\nOn 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.\n\n## 🔎 Analyze\n\n**Sequential measurements on an entangled state and a separable state**\n\nConsider two two-qubit states:\n\n- The Bell state $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big (|00\\rangle + |11\\rangle\\big)$.\n- A state $\\ket \\Theta = \\frac{1}{2} \\big( \\ket{00} + \\ket{01} + \\ket{10} + \\ket{11} \\big)$.\n\nFor 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.\n\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 *always* 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 *correlated*.</p>\n\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\n<p>This aligns with the fact that the Bell state is entangled, while the $\\ket{\\theta}$ is separable and can be expressed as $\\ket \\theta = \\ket + \\otimes \\ket +$.</p>\n</details>\n\n## State Modification Using Partial Measurements\n\nFor 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."
1525
+ "asHtml": "<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$$\n\\ket \\psi = \\ket {\\phi_A} \\otimes \\ket{\\phi_B}\n$$\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}\\bra{b_i}\\phi_A\\rangle \\otimes \\ket {\\phi_B}}{\\big|\\ket{b_i}\\bra{b_i}\\phi_A\\rangle \\otimes \\ket {\\phi_B}\\big|}=$$</p>\n<p>$$= \\frac{\\bra{b_i}\\phi_A\\rangle \\cdot \\ket{b_i} \\otimes \\ket {\\phi_B}}{\\big|\\ket{b_i}\\big| \\cdot \\bra{b_i}\\phi_A\\rangle \\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 $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big (|00\\rangle + |11\\rangle\\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\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\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\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",
1526
+ "asMarkdown": "\nEntanglement 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.\n\n> 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>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> $$\n\\ket \\psi = \\ket {\\phi_A} \\otimes \\ket{\\phi_B}\n$$\n> Here $\\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.\n\nConsider 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\n\n$$\\ket{\\psi}_{i} \\equiv \\frac{P_i \\ket{\\psi}}{\\big|P_i \\ket{\\psi}\\big|}\n= \\frac{\\ket{b_i}\\bra{b_i}\\phi_A\\rangle \\otimes \\ket {\\phi_B}}{\\big|\\ket{b_i}\\bra{b_i}\\phi_A\\rangle \\otimes \\ket {\\phi_B}\\big|}=$$\n\n$$= \\frac{\\bra{b_i}\\phi_A\\rangle \\cdot \\ket{b_i} \\otimes \\ket {\\phi_B}}{\\big|\\ket{b_i}\\big| \\cdot \\bra{b_i}\\phi_A\\rangle \\cdot \\big| \\ket {\\phi_B}\\big|}\n= \\ket{b_i} \\otimes \\ket{\\phi_B}$$\n\nThus, 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.\n\nOn 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.\n\n## 🔎 Analyze\n\n### Sequential measurements on an entangled state and a separable state\n\nConsider two two-qubit states:\n\n- The Bell state $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big (|00\\rangle + |11\\rangle\\big)$.\n- A state $\\ket \\Theta = \\frac{1}{2} \\big( \\ket{00} + \\ket{01} + \\ket{10} + \\ket{11} \\big)$.\n\nFor 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.\n\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\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\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\n## State Modification Using Partial Measurements\n\nFor 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."
1527
1527
  }
1528
1528
  ]
1529
1529
  },
@@ -1533,15 +1533,15 @@ export default {
1533
1533
  "title": "State Selection Using Partial Measurements",
1534
1534
  "description": {
1535
1535
  "type": "text-content",
1536
- "asHtml": "<p><strong>Input</strong>: </p>\n<ol>\n<li>A 2-qubit system in the state\n$$\n|\\psi\\rangle = \\frac{1}{\\sqrt{2}} |0\\rangle \\otimes ( a |0\\rangle + b|1\\rangle) + \\frac{1}{\\sqrt{2}} |1\\rangle \\otimes (b|0\\rangle + a |1\\rangle),\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, the state of the second qubit should be $a|0\\rangle + b|1\\rangle$</li>\n<li>If $ind$ equals 1, the state of the second qubit should be $b|0\\rangle + a |1\\rangle$.</li>\n</ul>\n<p>The state of the first qubit at the end does not matter.</p>\n",
1537
- "asMarkdown": "**Input**: \n1. A 2-qubit system in the state\n$$\n|\\psi\\rangle = \\frac{1}{\\sqrt{2}} |0\\rangle \\otimes ( a |0\\rangle + b|1\\rangle) + \\frac{1}{\\sqrt{2}} |1\\rangle \\otimes (b|0\\rangle + a |1\\rangle),\n$$\nwhere the constants $a$ and $b$ satisfying $|a|^2 + |b|^2 = 1$ are unknown.\n2. An integer $ind$ which is either $0$ or $1$.\n\n**Goal**: \n- If $ind$ equals 0, the state of the second qubit should be $a|0\\rangle + b|1\\rangle$\n- If $ind$ equals 1, the state of the second qubit should be $b|0\\rangle + a |1\\rangle$. \n\nThe state of the first qubit at the end does not matter.\n"
1536
+ "asHtml": "<p><strong>Input</strong>: </p>\n<ol>\n<li>A 2-qubit system in the state\n$$\n|\\psi\\rangle = \\frac{1}{\\sqrt{2}} |0\\rangle \\otimes ( a |0\\rangle + b|1\\rangle) + \\frac{1}{\\sqrt{2}} |1\\rangle \\otimes (b|0\\rangle + a |1\\rangle),\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|0\\rangle + b|1\\rangle$</li>\n<li>If $ind$ equals 1, convert the state of the second qubit into $b|0\\rangle + a|1\\rangle$.</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",
1537
+ "asMarkdown": "**Input**: \n1. A 2-qubit system in the state\n$$\n|\\psi\\rangle = \\frac{1}{\\sqrt{2}} |0\\rangle \\otimes ( a |0\\rangle + b|1\\rangle) + \\frac{1}{\\sqrt{2}} |1\\rangle \\otimes (b|0\\rangle + a |1\\rangle),\n$$\nwhere the constants $a$ and $b$ satisfying $|a|^2 + |b|^2 = 1$ are unknown.\n2. An integer $ind$ which is either $0$ or $1$.\n\n**Goal**: \n- If $ind$ equals 0, convert the state of the second qubit into $a|0\\rangle + b|1\\rangle$\n- If $ind$ equals 1, convert the state of the second qubit into $b|0\\rangle + a|1\\rangle$. \n\nThe state of the first qubit at the end does not matter (it has to be not entangled with the second qubit).\n"
1538
1538
  },
1539
1539
  "sourceIds": [
1540
1540
  "multi_qubit_measurements__state_modification__Verification.qs",
1541
1541
  "multi_qubit_measurements__Common.qs",
1542
1542
  "KatasLibrary.qs"
1543
1543
  ],
1544
- "placeholderCode": "namespace Kata {\n operation StateSelction(qs : Qubit[], ind : Int) : Unit {\n // Implement your solution here...\n\n }\n}\n",
1544
+ "placeholderCode": "namespace Kata {\n operation StateSelection(qs : Qubit[], ind : Int) : Unit {\n // Implement your solution here...\n\n }\n}\n",
1545
1545
  "explainedSolution": {
1546
1546
  "type": "explained-solution",
1547
1547
  "items": [
@@ -1553,7 +1553,7 @@ export default {
1553
1553
  {
1554
1554
  "type": "solution",
1555
1555
  "id": "multi_qubit_measurements__state_modification_solution",
1556
- "code": "namespace Kata {\n\n operation StateSelction(qs : Qubit[], ind : Int) : Unit {\n // It is convenient to convert measurement outcome to an integer\n let outcome = M(qs[0]) == Zero ? 0 | 1;\n if outcome != ind {\n X(qs[1]);\n }\n }\n\n}\n"
1556
+ "code": "namespace Kata {\n operation StateSelection(qs : Qubit[], ind : Int) : Unit {\n // It is convenient to convert measurement outcome to an integer\n let outcome = M(qs[0]) == Zero ? 0 | 1;\n if outcome != ind {\n X(qs[1]);\n }\n }\n}\n"
1557
1557
  }
1558
1558
  ]
1559
1559
  }
@@ -1561,7 +1561,7 @@ export default {
1561
1561
  {
1562
1562
  "type": "lesson",
1563
1563
  "id": "multi_qubit_measurements__state_preparation",
1564
- "title": "State Preparation",
1564
+ "title": "State Preparation Using Post-Selection",
1565
1565
  "items": [
1566
1566
  {
1567
1567
  "type": "text-content",
@@ -1576,8 +1576,8 @@ export default {
1576
1576
  "title": "State Preparation Using Partial Measurements",
1577
1577
  "description": {
1578
1578
  "type": "text-content",
1579
- "asHtml": "<p><strong>Input:</strong> Two qubits (in an array) which are in the state $\\ket{00}$.</p>\n<p><strong>Goal:</strong> Modify the qubits to the state $\\frac{1}{\\sqrt{3}} \\big(|00\\rangle + |01\\rangle + |10\\rangle\\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}(|00\\rangle + |01\\rangle + |11\\rangle) \\otimes |0\\rangle + \\frac{1}{2} |11\\rangle \\otimes |1\\rangle$.\n What happens when one measures the third qubit?\n</details>\n",
1580
- "asMarkdown": "**Input:** Two qubits (in an array) which are in the state $\\ket{00}$.\n\n**Goal:** Modify the qubits to the state $\\frac{1}{\\sqrt{3}} \\big(|00\\rangle + |01\\rangle + |10\\rangle\\big)$ using post-selection.\n\n<br/>\n<details>\n <summary><b>Need a hint?</b></summary>\n Consider a 3-qubit state $\\frac{1}{2}(|00\\rangle + |01\\rangle + |11\\rangle) \\otimes |0\\rangle + \\frac{1}{2} |11\\rangle \\otimes |1\\rangle$.\n What happens when one measures the third qubit?\n</details>\n"
1579
+ "asHtml": "<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(|00\\rangle + |01\\rangle + |10\\rangle\\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}(|00\\rangle + |01\\rangle + |11\\rangle) \\otimes |0\\rangle + \\frac{1}{2} |11\\rangle \\otimes |1\\rangle$.\n What happens when one measures the third qubit?\n</details>\n",
1580
+ "asMarkdown": "**Input:** Two qubits in the state $\\ket{00}$.\n\n**Goal:** Modify the qubits to the state $\\frac{1}{\\sqrt{3}} \\big(|00\\rangle + |01\\rangle + |10\\rangle\\big)$ using post-selection.\n\n<br/>\n<details>\n <summary><b>Need a hint?</b></summary>\n Consider a 3-qubit state $\\frac{1}{2}(|00\\rangle + |01\\rangle + |11\\rangle) \\otimes |0\\rangle + \\frac{1}{2} |11\\rangle \\otimes |1\\rangle$.\n What happens when one measures the third qubit?\n</details>\n"
1581
1581
  },
1582
1582
  "sourceIds": [
1583
1583
  "multi_qubit_measurements__state_preparation__Verification.qs",
@@ -1590,13 +1590,13 @@ export default {
1590
1590
  "items": [
1591
1591
  {
1592
1592
  "type": "text-content",
1593
- "asHtml": "<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. Here, we describe the procedure in more detail below.</p>\n<p>Initially we will prepare an equal superposition of all basis states corresponding to the first two qubits by applying the <strong>H</strong> gate to each of them:\n$$\\frac{1}{2} \\big(|00\\rangle + |01\\rangle + |10\\rangle + |11\\rangle\\big) \\otimes \\ket 0$$</p>\n<p>This state is a superposition of the state we want to prepare, and the $|11\\rangle$ 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 $|0\\rangle$ for the basis states that we want to keep, and switch it to $|1\\rangle$ for the basis states that we would like to discard.\nA <strong>CCNOT</strong> gate can be used to accomplish 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 $|1\\rangle$ if both control qubits are in the $|11\\rangle$ state, which marks exactly the state that we want to discard:</p>\n<p>$$\\text{CCNOT}\\frac{1}{2} \\big(|00\\textbf{0}\\rangle + |01\\textbf{0}\\rangle + |10\\textbf{0}\\rangle + |11\\textbf{0}\\rangle\\big) =\n\\frac{1}{2}\\big(|00\\rangle + |01\\rangle + |10\\rangle \\big) \\otimes |\\textbf{0}\\rangle + \\frac{1}{2}|11\\rangle \\otimes |\\textbf{1}\\rangle $$</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 $|0\\rangle$, the system collapses to a state that is a linear combination of basis states which had the extra qubit in state $|0\\rangle$, i.e., the two qubits end up in the target state $\\frac{1}{\\sqrt3}\\big(|00\\rangle + |01\\rangle + |10\\rangle\\big)$.</li>\n<li>If the result is $|1\\rangle$, the system collapses to a state $|11\\rangle$, 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 $|00\\rangle$ state and try again.</li>\n</ul>\n<blockquote>\n<p>Q# has a built-in <a href=\"https://docs.microsoft.com/en-us/quantum/user-guide/using-qsharp/control-flow#repeat-until-success-loop\" 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 <strong>H</strong> and <strong>CCNOT</strong> 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 $|00\\rangle$ state.</li>\n</ul>\n</blockquote>\n<p>This technique is sometimes called post-selection.</p>\n",
1594
- "asMarkdown": "\nWhile it is possible to prepare the state $\\ket \\psi$ directly using unitary rotations, it is simpler to use post-selection for preparing it. Here, we describe the procedure in more detail below.\n\nInitially we will prepare an equal superposition of all basis states corresponding to the first two qubits by applying the **H** gate to each of them:\n$$\\frac{1}{2} \\big(|00\\rangle + |01\\rangle + |10\\rangle + |11\\rangle\\big) \\otimes \\ket 0$$\n\nThis state is a superposition of the state we want to prepare, and the $|11\\rangle$ state that we would like to discard.\n\nNow, 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 $|0\\rangle$ for the basis states that we want to keep, and switch it to $|1\\rangle$ for the basis states that we would like to discard.\nA **CCNOT** gate can be used to accomplish 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 $|1\\rangle$ if both control qubits are in the $|11\\rangle$ state, which marks exactly the state that we want to discard:\n\n$$\\text{CCNOT}\\frac{1}{2} \\big(|00\\textbf{0}\\rangle + |01\\textbf{0}\\rangle + |10\\textbf{0}\\rangle + |11\\textbf{0}\\rangle\\big) =\n\\frac{1}{2}\\big(|00\\rangle + |01\\rangle + |10\\rangle \\big) \\otimes |\\textbf{0}\\rangle + \\frac{1}{2}|11\\rangle \\otimes |\\textbf{1}\\rangle $$\n\nFinally we measure just the extra qubit; this causes a partial collapse of the system to the state defined by the measurement result:\n* If the result is $|0\\rangle$, the system collapses to a state that is a linear combination of basis states which had the extra qubit in state $|0\\rangle$, i.e., the two qubits end up in the target state $\\frac{1}{\\sqrt3}\\big(|00\\rangle + |01\\rangle + |10\\rangle\\big)$.\n* If the result is $|1\\rangle$, the system collapses to a state $|11\\rangle$, 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 $|00\\rangle$ state and try again.\n\n> Q# has a built-in <a href=\"https://docs.microsoft.com/en-us/quantum/user-guide/using-qsharp/control-flow#repeat-until-success-loop\" target=\"_blank\">repeat-until-success (RUS) loop</a>, which comes in handy in this case.\n> * We will describe the main operations (applying **H** and **CCNOT** gates and the measurement) in the `repeat` part of the loop, which specifies its body. \n> * `until` section specifies the condition which will break the loop. In this case the result of the measurement needs to be `Zero` to indicate our success. \n> * Finally, the `fixup` 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 $|00\\rangle$ state.\n\nThis technique is sometimes called post-selection."
1593
+ "asHtml": "<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(|00\\rangle + |01\\rangle + |10\\rangle + |11\\rangle\\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 $|11\\rangle$ 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 $|0\\rangle$ for the basis states that we want to keep, and switch it to $|1\\rangle$ 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 $|1\\rangle$ if both control qubits are in the $|11\\rangle$ state, which marks exactly the state that we want to discard:</p>\n<p>$$CCNOT\\frac{1}{2} \\big(|00\\textbf{0}\\rangle + |01\\textbf{0}\\rangle + |10\\textbf{0}\\rangle + |11\\textbf{0}\\rangle\\big) =\n\\frac{1}{2}\\big(|00\\rangle + |01\\rangle + |10\\rangle \\big) \\otimes |\\textbf{0}\\rangle + \\frac{1}{2}|11\\rangle \\otimes |\\textbf{1}\\rangle $$</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 $|0\\rangle$, the first two qubits collapse to a state that is a linear combination of basis states which had the extra qubit in state $|0\\rangle$, i.e., they end up in the target state $\\frac{1}{\\sqrt3}\\big(|00\\rangle + |01\\rangle + |10\\rangle\\big)$.</li>\n<li>If the result is $|1\\rangle$, the first two qubits collapse to a state $|11\\rangle$, 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 $|00\\rangle$ 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-statement\" 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 $|00\\rangle$ state.</li>\n</ul>\n</blockquote>\n",
1594
+ "asMarkdown": "\nWhile it is possible to prepare the state $\\ket \\psi$ directly using unitary rotations, it is simpler to use post-selection for preparing it.\n\nInitially we will 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(|00\\rangle + |01\\rangle + |10\\rangle + |11\\rangle\\big) \\otimes \\ket 0$$\n\nThe state of the first two qubits is a superposition of the state we want to prepare and the $|11\\rangle$ state that we would like to discard.\n\nNow, 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 $|0\\rangle$ for the basis states that we want to keep, and switch it to $|1\\rangle$ 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 $|1\\rangle$ if both control qubits are in the $|11\\rangle$ state, which marks exactly the state that we want to discard:\n\n$$CCNOT\\frac{1}{2} \\big(|00\\textbf{0}\\rangle + |01\\textbf{0}\\rangle + |10\\textbf{0}\\rangle + |11\\textbf{0}\\rangle\\big) =\n\\frac{1}{2}\\big(|00\\rangle + |01\\rangle + |10\\rangle \\big) \\otimes |\\textbf{0}\\rangle + \\frac{1}{2}|11\\rangle \\otimes |\\textbf{1}\\rangle $$\n\nFinally, we measure just the extra qubit; this causes a partial collapse of the system to the state defined by the measurement result:\n* If the result is $|0\\rangle$, the first two qubits collapse to a state that is a linear combination of basis states which had the extra qubit in state $|0\\rangle$, i.e., they end up in the target state $\\frac{1}{\\sqrt3}\\big(|00\\rangle + |01\\rangle + |10\\rangle\\big)$.\n* If the result is $|1\\rangle$, the first two qubits collapse to a state $|11\\rangle$, 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 $|00\\rangle$ state and try again.\n\n> Q# has a built-in <a href=\"https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/conditionalloops#repeat-statement\" target=\"_blank\">repeat-until-success (RUS) loop</a>, which comes in handy in this case.\n> * We will describe the main operations (applying $H$ and $CCNOT$ gates and the measurement) in the `repeat` part of the loop, which specifies its body. \n> * `until` section specifies the condition which will break the loop. In this case the result of the measurement needs to be `Zero` to indicate our success. \n> * Finally, the `fixup` 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 $|00\\rangle$ state."
1595
1595
  },
1596
1596
  {
1597
1597
  "type": "solution",
1598
1598
  "id": "multi_qubit_measurements__state_preparation_solution",
1599
- "code": "namespace Kata {\n open Microsoft.Quantum.Measurement;\n\n operation PostSelection(qs : Qubit[]) : Unit {\n // Initialize the extra qubit\n use anc = Qubit();\n // Using the repeat-until-success pattern to prepare the right state\n mutable res = Zero;\n repeat {\n ApplyToEach(H, qs);\n Controlled X(qs, anc);\n set res = MResetZ(anc);\n }\n until (res == Zero)\n fixup {\n ResetAll(qs);\n }\n }\n\n}\n"
1599
+ "code": "namespace Kata {\n open Microsoft.Quantum.Measurement;\n\n operation PostSelection(qs : Qubit[]) : Unit {\n use anc = Qubit();\n mutable res = Zero;\n repeat {\n ApplyToEach(H, qs);\n Controlled X(qs, anc);\n set res = MResetZ(anc);\n }\n until (res == Zero)\n fixup {\n ResetAll(qs);\n }\n }\n}\n"
1600
1600
  }
1601
1601
  ]
1602
1602
  }
@@ -1608,8 +1608,8 @@ export default {
1608
1608
  "items": [
1609
1609
  {
1610
1610
  "type": "text-content",
1611
- "asHtml": "<p>Joint measurements, also known as Pauli measurements, are a generalization of 2-outcome measurements to multiple qubits and other bases. In Q#, joint measurements in Pauli bases are implemented using the <a href=\"https://docs.microsoft.com/en-us/qsharp/api/qsharp/microsoft.quantum.intrinsic.measure\" target=\"_blank\"><code>Measure</code></a> operation. Let&#39;s review single-qubit measurements in a different light before discussing joint measurements.</p>\n<h2>Single-Qubit Pauli Measurement</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{pmatrix} 1 &amp; 0 \\\\ 0 &amp; -1\\end{pmatrix} = \\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\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 1&#39;s 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 ${ |00\\rangle, |11\\rangle }$ and ${ |01\\rangle, |10\\rangle }$, 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 $1$&#39;s. On the other hand, a result of <code>One</code> corresponds to a post-measurement state with only odd parity computational basis vectors.</p>\n<p>Let&#39;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 $|00\\rangle$, 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 |\\psi\\rangle = \\lambda |\\psi\\rangle$,\nit is easy to see that $|00\\rangle$ 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 $|11\\rangle$ also belongs to $+1$ eigenspace, while $|01\\rangle$ and $|10\\rangle$ belong to the $-1$ eigenspace.</p>\n<p>Now, what happens if we apply a $Z \\otimes Z$ measurement to a superposition state $\\alpha |00\\rangle + \\beta |11\\rangle$? 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 |01\\rangle + \\beta |10\\rangle$ state belongs to the $-1$ eigenspace, and measuring it will return <code>One</code> without changing the state.</p>\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",
1612
- "asMarkdown": "\nJoint measurements, also known as Pauli measurements, are a generalization of 2-outcome measurements to multiple qubits and other bases. In Q#, joint measurements in Pauli bases are implemented using the <a href=\"https://docs.microsoft.com/en-us/qsharp/api/qsharp/microsoft.quantum.intrinsic.measure\" target=\"_blank\">`Measure`</a> operation. Let's review single-qubit measurements in a different light before discussing joint measurements.\n\n## Single-Qubit Pauli Measurement\n\nFor 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 `Result` in Q#) are the eigenvalues of the Hermitian matrix, and the corresponding projection matrices for the measurement are the projection operators onto the *eigenspaces* corresponding to the eigenvalues.\n\nFor example, consider the computational basis measurement, which can result in outcomes `Zero` or `One` corresponding to states $\\ket 0$ and $\\ket 1$. This measurement is associated with the Pauli Z operator, which is given by\n\n$$Z = \\begin{pmatrix} 1 & 0 \\\\\\ 0 & -1\\end{pmatrix} = \\ket{0}\\bra{0} - \\ket{1}\\bra{1}$$\n\nThe $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 `Result` of `Zero`, while an eigenvalue of $-1$ corresponds to a `Result` of `One`.\n\nSimilarly, one can implement measurements corresponding to the Pauli X and Y operators. We summarize the various properties below:\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\nIn 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$.\n\nJoint measurements are a generalization of this principle for multi-qubit matrices.\n\n## Parity Measurements\n\nThe simplest joint measurement is a parity measurement. A parity measurement treats computational basis vectors differently depending on whether the number of 1's in the basis vector is even or odd.\n\nFor 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 $\\{ |00\\rangle, |11\\rangle \\}$ and $\\{ |01\\rangle, |10\\rangle \\}$, respectively. That is, when a $ZZ$ measurement results in a `Zero` (i.e. the eigenvalue $+1$), the post-measurement state is a superposition of only those computational basis vectors which have an even number of $1$'s. On the other hand, a result of `One` corresponds to a post-measurement state with only odd parity computational basis vectors.\n\nLet's see what happens to various two-qubit states after the parity measurement. The $Z \\otimes Z$ matrix for two qubits is:\n\n$$\nZ \\otimes Z =\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$$\n\nWhen this transformation is applied to a basis state $|00\\rangle$, we get\n\n$$\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\\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix}\n$$\n\nComparing this to the characteristic equation for eigenvectors of $Z \\otimes Z$ given by\n$ Z \\otimes Z |\\psi\\rangle = \\lambda |\\psi\\rangle$,\nit is easy to see that $|00\\rangle$ belongs to the $+1$ eigenspace, hence the $Z \\otimes Z$ measurement will return `Zero` and leave the state unchanged.\n\nSimilarly, it can easily be verified that $|11\\rangle$ also belongs to $+1$ eigenspace, while $|01\\rangle$ and $|10\\rangle$ belong to the $-1$ eigenspace.\n\nNow, what happens if we apply a $Z \\otimes Z$ measurement to a superposition state $\\alpha |00\\rangle + \\beta |11\\rangle$? We can see that\n\n$$\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\\begin{bmatrix} \\alpha \\\\\\ 0 \\\\\\ 0 \\\\\\ \\beta \\end{bmatrix} =\n\\begin{bmatrix} \\alpha \\\\\\ 0 \\\\\\ 0 \\\\\\ \\beta \\end{bmatrix}\n$$\n\nSo this state also belongs to the $+1$ eigenspace, and measuring it will return `Zero` and leave the state unchanged. Similarly, we can verify that an $\\alpha |01\\rangle + \\beta |10\\rangle$ state belongs to the $-1$ eigenspace, and measuring it will return `One` without changing the state.\n\nSimilarly, a parity measurement on a higher number of qubits can be implemented using a $Z \\otimes \\dotsc \\otimes Z$ measurement."
1611
+ "asHtml": "<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&#39;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{pmatrix} 1 &amp; 0 \\\\ 0 &amp; -1\\end{pmatrix} = \\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\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 $\\{ |00\\rangle, |11\\rangle \\}$ and $\\{ |01\\rangle, |10\\rangle \\}$, 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&#39;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 $|00\\rangle$, 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 |\\psi\\rangle = \\lambda |\\psi\\rangle$,\nit is easy to see that $|00\\rangle$ 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 $|11\\rangle$ also belongs to $+1$ eigenspace, while $|01\\rangle$ and $|10\\rangle$ belong to the $-1$ eigenspace.</p>\n<p>Now, what happens if we apply a $Z \\otimes Z$ measurement to a superposition state $\\alpha |00\\rangle + \\beta |11\\rangle$? 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 |01\\rangle + \\beta |10\\rangle$ 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",
1612
+ "asMarkdown": "\nJoint 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 `Measure` operation. Let's review single-qubit measurements in a different light before discussing joint measurements.\n\n## Single-Qubit Pauli Measurements\n\nFor 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 `Result` in Q#) are the eigenvalues of the Hermitian matrix, and the corresponding projection matrices for the measurement are the projection operators onto the *eigenspaces* corresponding to the eigenvalues.\n\nFor example, consider the computational basis measurement, which can result in outcomes `Zero` or `One` corresponding to states $\\ket 0$ and $\\ket 1$. This measurement is associated with the Pauli Z operator, which is given by\n\n$$Z = \\begin{pmatrix} 1 & 0 \\\\\\ 0 & -1\\end{pmatrix} = \\ket{0}\\bra{0} - \\ket{1}\\bra{1}$$\n\nThe $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 `Result` of `Zero`, while an eigenvalue of $-1$ corresponds to a `Result` of `One`.\n\nSimilarly, one can implement measurements corresponding to the Pauli X and Y operators. We summarize the various properties below:\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\nIn 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$.\n\nJoint measurements are a generalization of this principle for multi-qubit matrices.\n\n## Parity Measurements\n\nThe 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.\n\nFor 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 $\\\\{ |00\\rangle, |11\\rangle \\\\}$ and $\\\\{ |01\\rangle, |10\\rangle \\\\}$, respectively. That is, when a $ZZ$ measurement results in a `Zero` (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 `One` corresponds to a post-measurement state with only computational basis vectors which have an odd number of 1s.\n\n> Let's see what happens to various two-qubit states after the parity measurement. The $Z \\otimes Z$ matrix for two qubits is:\n>\n>$$\nZ \\otimes Z =\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$$\n>\n>When this transformation is applied to a basis state $|00\\rangle$, we get\n>\n>$$\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\\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix}\n$$\n>\n>Comparing this to the characteristic equation for eigenvectors of $Z \\otimes Z$ given by\n$ Z \\otimes Z |\\psi\\rangle = \\lambda |\\psi\\rangle$,\nit is easy to see that $|00\\rangle$ belongs to the $+1$ eigenspace, hence the $Z \\otimes Z$ measurement will return `Zero` and leave the state unchanged.\n>\n>Similarly, it can easily be verified that $|11\\rangle$ also belongs to $+1$ eigenspace, while $|01\\rangle$ and $|10\\rangle$ belong to the $-1$ eigenspace.\n>\n>Now, what happens if we apply a $Z \\otimes Z$ measurement to a superposition state $\\alpha |00\\rangle + \\beta |11\\rangle$? We can see that\n>\n>$$\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\\begin{bmatrix} \\alpha \\\\\\ 0 \\\\\\ 0 \\\\\\ \\beta \\end{bmatrix} =\n\\begin{bmatrix} \\alpha \\\\\\ 0 \\\\\\ 0 \\\\\\ \\beta \\end{bmatrix}\n$$\n>\n>So this state also belongs to the $+1$ eigenspace, and measuring it will return `Zero` and leave the state unchanged. Similarly, we can verify that an $\\alpha |01\\rangle + \\beta |10\\rangle$ state belongs to the $-1$ eigenspace, and measuring it will return `One` without changing the state.\n\nSimilarly, a parity measurement on a higher number of qubits can be implemented using a $Z \\otimes \\dotsc \\otimes Z$ measurement."
1613
1613
  }
1614
1614
  ]
1615
1615
  },
@@ -1619,27 +1619,27 @@ export default {
1619
1619
  "title": "Two-Qubit Parity Measurement",
1620
1620
  "description": {
1621
1621
  "type": "text-content",
1622
- "asHtml": "<p><strong>Inputs</strong>: Two qubits stored in an array which are guaranteed to be either in a superposition of the states $|00\\rangle$ and $|11\\rangle$ or in a superposition of states $|01\\rangle$ and $|10\\rangle$.</p>\n<p><strong>Output</strong>: 0 if qubits were in the first superposition, 1 if they were in the second superposition.<br><em>The state of the qubits at the end of the operation should be the same as the starting state.</em></p>\n",
1623
- "asMarkdown": "**Inputs**: Two qubits stored in an array which are guaranteed to be either in a superposition of the states $|00\\rangle$ and $|11\\rangle$ or in a superposition of states $|01\\rangle$ and $|10\\rangle$.\n\n**Output**: 0 if qubits were in the first superposition, 1 if they were in the second superposition. \n*The state of the qubits at the end of the operation should be the same as the starting state.*\n"
1622
+ "asHtml": "<p><strong>Input</strong>: Two qubits stored in an array which are guaranteed to be either in a superposition of the states $|00\\rangle$ and $|11\\rangle$ or in a superposition of states $|01\\rangle$ and $|10\\rangle$.</p>\n<p><strong>Output</strong>: 0 if qubits were in the first superposition, 1 if they were in the second superposition.<br>The state of the qubits at the end of the operation should be the same as the starting state.</p>\n",
1623
+ "asMarkdown": "**Input**: Two qubits stored in an array which are guaranteed to be either in a superposition of the states $|00\\rangle$ and $|11\\rangle$ or in a superposition of states $|01\\rangle$ and $|10\\rangle$.\n\n**Output**: 0 if qubits were in the first superposition, 1 if they were in the second superposition. \nThe state of the qubits at the end of the operation should be the same as the starting state.\n"
1624
1624
  },
1625
1625
  "sourceIds": [
1626
1626
  "multi_qubit_measurements__joint_measurements__Verification.qs",
1627
1627
  "multi_qubit_measurements__Common.qs",
1628
1628
  "KatasLibrary.qs"
1629
1629
  ],
1630
- "placeholderCode": "namespace Kata {\n operation ParityMeasurement(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n\n}\n",
1630
+ "placeholderCode": "namespace Kata {\n operation ParityMeasurement(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n}\n",
1631
1631
  "explainedSolution": {
1632
1632
  "type": "explained-solution",
1633
1633
  "items": [
1634
1634
  {
1635
1635
  "type": "text-content",
1636
- "asHtml": "<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 |00\\rangle + \\beta |11\\rangle$ will collapse to either $|00\\rangle$ or $|11\\rangle$, and we won&#39;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. <a href=\"https://docs.microsoft.com/en-us/quantum/concepts/pauli-measurements\" target=\"_blank\">Pauli measurements</a> can be used for joint measurements involving multiple qubits. For this task we apply the $Z \\otimes Z$ measurement on both qubits.</p>\n<p>A joint measurement using $Z \\otimes Z$ operator can be thought 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&#39;ve seen in the tutorial, the state $\\alpha |00\\rangle + \\beta |11\\rangle$ is an eigenstate of the $Z \\otimes Z$ operator with the eigenvalue $+1$, and the state $\\alpha |01\\rangle + \\beta |10\\rangle$ 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 <a href=\"https://docs.microsoft.com/en-us/qsharp/api/qsharp/microsoft.quantum.intrinsic.measure\" target=\"_blank\"><code>Measure</code></a> can be used to measure multiple qubits using an array of <a href=\"https://docs.microsoft.com/en-us/quantum/user-guide/language/types?#primitive-types\" target=\"_blank\"><code>Pauli</code></a> constants that define the basis for measurement.</p>\n",
1637
- "asMarkdown": "\nIf 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 |00\\rangle + \\beta |11\\rangle$ will collapse to either $|00\\rangle$ or $|11\\rangle$, and we won't be able to recover the information about the coefficients $\\alpha$ and $\\beta$.\n\nWe need to measure the *parity* of the state without collapsing it all the way to the basis states. <a href=\"https://docs.microsoft.com/en-us/quantum/concepts/pauli-measurements\" target=\"_blank\">Pauli measurements</a> can be used for joint measurements involving multiple qubits. For this task we apply the $Z \\otimes Z$ measurement on both qubits.\n\nA joint measurement using $Z \\otimes Z$ operator can be thought 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 `Zero` if the measured state is projected to the space with an eigenvalue of $+1$, and a result of `One` if projected to the space with an eigenvalue of $-1$.\n\nAs we've seen in the tutorial, the state $\\alpha |00\\rangle + \\beta |11\\rangle$ is an eigenstate of the $Z \\otimes Z$ operator with the eigenvalue $+1$, and the state $\\alpha |01\\rangle + \\beta |10\\rangle$ 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.\n\nIn Q#, the operation <a href=\"https://docs.microsoft.com/en-us/qsharp/api/qsharp/microsoft.quantum.intrinsic.measure\" target=\"_blank\">`Measure`</a> can be used to measure multiple qubits using an array of <a href=\"https://docs.microsoft.com/en-us/quantum/user-guide/language/types?#primitive-types\" target=\"_blank\">`Pauli`</a> constants that define the basis for measurement."
1636
+ "asHtml": "<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 |00\\rangle + \\beta |11\\rangle$ will collapse to either $|00\\rangle$ or $|11\\rangle$, and we won&#39;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&#39;ve seen in the tutorial, the state $\\alpha |00\\rangle + \\beta |11\\rangle$ is an eigenstate of the $Z \\otimes Z$ operator with the eigenvalue $+1$, and the state $\\alpha |01\\rangle + \\beta |10\\rangle$ 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",
1637
+ "asMarkdown": "\nIf 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 |00\\rangle + \\beta |11\\rangle$ will collapse to either $|00\\rangle$ or $|11\\rangle$, and we won't be able to recover the information about the coefficients $\\alpha$ and $\\beta$.\n\nWe need to measure the *parity* 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.\n\nA 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 `Zero` if the measured state is projected to the space with an eigenvalue of $+1$, and a result of `One` if projected to the space with an eigenvalue of $-1$.\n\nAs we've seen in the tutorial, the state $\\alpha |00\\rangle + \\beta |11\\rangle$ is an eigenstate of the $Z \\otimes Z$ operator with the eigenvalue $+1$, and the state $\\alpha |01\\rangle + \\beta |10\\rangle$ 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.\n\nIn Q#, the operation `Measure` can be used to measure multiple qubits using an array of `Pauli` constants (`PauliI`, `PauliX`, `PauliY`, or `PauliZ`) that define the basis for measurement."
1638
1638
  },
1639
1639
  {
1640
1640
  "type": "solution",
1641
1641
  "id": "multi_qubit_measurements__joint_measurements_solution",
1642
- "code": "namespace Kata {\n\n operation ParityMeasurement(qs : Qubit[]) : Int {\n return Measure([PauliZ, PauliZ], qs) == Zero ? 0 | 1;\n }\n\n}\n"
1642
+ "code": "namespace Kata {\n operation ParityMeasurement(qs : Qubit[]) : Int {\n return Measure([PauliZ, PauliZ], qs) == Zero ? 0 | 1;\n }\n}\n"
1643
1643
  }
1644
1644
  ]
1645
1645
  }
@@ -1651,8 +1651,8 @@ export default {
1651
1651
  "items": [
1652
1652
  {
1653
1653
  "type": "text-content",
1654
- "asHtml": "<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\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<p><strong>Parity measurement in different basis</strong></p>\n<p>Consider a system which is in a state $\\alpha |00\\rangle + \\beta |01\\rangle + \\beta |10\\rangle + \\alpha |11\\rangle$.</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\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 $+$&#39;s from basis states which have an odd number of $+$&#39;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{--} ) =$$\n$$( \\gamma \\ket{++} + \\delta \\ket{--} )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 |00\\rangle + \\beta |01\\rangle + \\beta |10\\rangle + \\alpha |11\\rangle = (\\alpha + \\beta) |++\\rangle + (\\alpha - \\beta) |--\\rangle$$\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>",
1655
- "asMarkdown": "\nJoint 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 `Result` of `Zero` corresponding to eigenvalue $+1$ and a `Result` of `One` corresponding to the eigenvalue $-1$. The corresponding projection operators are the projections onto the corresponding eigenspaces.\n\nFor example, a Pauli/joint measurement corresponding to the $X\\otimes Z$ operator can be characterized as follows:\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\n The rules for measurements are then the same as those outlined in the partial measurements section, with the projection operators in the table.\n\n## 🔎 Analyze\n\n**Parity measurement in different basis**\n\nConsider a system which is in a state $\\alpha |00\\rangle + \\beta |01\\rangle + \\beta |10\\rangle + \\alpha |11\\rangle$.\n\nWhat are the possible outcomes and their associated probabilities, if a measurement in an $XX$ Pauli measurement is done?\n\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\n$$XX \\ket{++} = \\ket{++}$$\n$$XX \\ket{--} = \\ket{--}$$\n$$XX \\ket{+-} = -\\ket{+-}$$\n$$XX \\ket{-+} = -\\ket{-+}$$\n\nThus, 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.\n\nThe projector corresponding to a result of `Zero` is given by $P_{+1} = \\ket{++}\\bra{++} + \\ket{--}\\bra{--}$, while the projector corresponding to a result of `One` 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{--} ) =$$\n$$( \\gamma \\ket{++} + \\delta \\ket{--} )P_{+1} ( \\mu \\ket{-+} + \\nu \\ket{+-} ) = 0$$\n\nSimilarly, $P_{-1}$ annihilates states with even parity, while leaving states with odd parity unaffected.\n\nNow 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)$$\n\nUsing these, we obtain\n$$ \\alpha |00\\rangle + \\beta |01\\rangle + \\beta |10\\rangle + \\alpha |11\\rangle = (\\alpha + \\beta) |++\\rangle + (\\alpha - \\beta) |--\\rangle$$\nThus, this state has an even parity in the Hadamard basis. It follows that an $XX$ Pauli measurement will result in the outcome `Zero` with probability 1, leaving the state unchanged after the measurement.\n</details>"
1654
+ "asHtml": "<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\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 |00\\rangle + \\beta |01\\rangle + \\beta |10\\rangle + \\alpha |11\\rangle$.</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\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 $+$&#39;s from basis states which have an odd number of $+$&#39;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 |00\\rangle + \\beta |01\\rangle + \\beta |10\\rangle + \\alpha |11\\rangle = (\\alpha + \\beta) |++\\rangle + (\\alpha - \\beta) |--\\rangle$$\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>",
1655
+ "asMarkdown": "\nJoint 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 `Result` of `Zero` corresponding to eigenvalue $+1$ and a `Result` of `One` corresponding to the eigenvalue $-1$. The corresponding projection operators are the projections onto the corresponding eigenspaces.\n\nFor example, a Pauli/joint measurement corresponding to the $X\\otimes Z$ operator can be characterized as follows:\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\nThe rules for measurements are then the same as those outlined in the Partial Measurements section, with the projection operators in the table.\n\n## 🔎 Analyze\n\n### Parity measurement in a different basis\n\nConsider a system which is in a state $\\alpha |00\\rangle + \\beta |01\\rangle + \\beta |10\\rangle + \\alpha |11\\rangle$.\n\nWhat are the possible outcomes and their associated probabilities, if a measurement in an $XX$ Pauli measurement is done?\n\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\n$$XX \\ket{++} = \\ket{++}$$\n$$XX \\ket{--} = \\ket{--}$$\n$$XX \\ket{+-} = -\\ket{+-}$$\n$$XX \\ket{-+} = -\\ket{-+}$$\n\nThus, 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.\n\nThe projector corresponding to a result of `Zero` is given by $P_{+1} = \\ket{++}\\bra{++} + \\ket{--}\\bra{--}$, while the projector corresponding to a result of `One` 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$$\n\nSimilarly, $P_{-1}$ annihilates states with even parity, while leaving states with odd parity unaffected.\n\nNow 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)$$\n\nUsing these, we obtain\n$$ \\alpha |00\\rangle + \\beta |01\\rangle + \\beta |10\\rangle + \\alpha |11\\rangle = (\\alpha + \\beta) |++\\rangle + (\\alpha - \\beta) |--\\rangle$$\nThus, this state has an even parity in the Hadamard basis. It follows that an $XX$ Pauli measurement will result in the outcome `Zero` with probability 1, leaving the state unchanged after the measurement.\n</details>"
1656
1656
  }
1657
1657
  ]
1658
1658
  },
@@ -2316,7 +2316,7 @@ export default {
2316
2316
  },
2317
2317
  {
2318
2318
  "id": "KatasLibrary.qs",
2319
- "code": "// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nnamespace Microsoft.Quantum.Katas {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Intrinsic;\n\n /// # Summary\n /// Given two operations, checks whether they act identically for all input states.\n /// This operation is implemented by using the Choi–Jamiołkowski isomorphism.\n operation CheckOperationsEquivalence(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n use (control, target) = (Qubit[inputSize], Qubit[inputSize]);\n within {\n EntangleRegisters(control, target);\n }\n apply {\n op(target);\n Adjoint reference(target);\n }\n\n let areEquivalent = CheckAllZero(control + target);\n ResetAll(control + target);\n areEquivalent\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically (including global phase) for all input states.\n /// This is done through controlled versions of the operations instead of plain ones which convert the global phase\n /// into a relative phase that can be detected.\n operation CheckOperationsEquivalenceStrict(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n let controlledOp = register => Controlled op(register[...0], register[1...]);\n let controlledReference = register => Controlled reference(register[...0], register[1...]);\n let areEquivalent = CheckOperationsEquivalence(controlledOp, controlledReference, inputSize + 1);\n areEquivalent\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically on the zero state |0〉 ⊗ |0〉 ⊗ ... ⊗ |0〉 composed of\n /// `inputSize` qubits.\n operation CheckOperationsEquivalenceOnZeroState(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n use target = Qubit[inputSize];\n op(target);\n Adjoint reference(target);\n let isCorrect = CheckAllZero(target);\n ResetAll(target);\n isCorrect\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically on the zero state |0〉 ⊗ |0〉 ⊗ ... ⊗ |0〉 composed of\n /// `inputSize` qubits.\n /// This operation introduces a control qubit to convert a global phase into a relative phase to be able to detect\n /// it.\n operation CheckOperationsEquivalenceOnZeroStateStrict(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n use control = Qubit();\n use target = Qubit[inputSize];\n within {\n H(control);\n }\n apply {\n Controlled op([control], target);\n Adjoint Controlled reference([control], target);\n }\n\n let isCorrect = CheckAllZero([control] + target);\n ResetAll([control] + target);\n isCorrect\n }\n\n /// # Summary\n /// Shows the effect a quantum operation has on the quantum state.\n operation ShowEffectOnQuantumState(targetRegister : Qubit[], op : (Qubit[] => Unit is Adj + Ctl)) : Unit {\n Message(\"Quantum state before applying the operation:\");\n DumpMachine();\n\n // Apply the operation, dump the simulator state and \"undo\" the operation by applying the adjoint.\n Message(\"Quantum state after applying the operation:\");\n op(targetRegister);\n DumpMachine();\n Adjoint op(targetRegister);\n }\n\n /// # Summary\n /// Shows the comparison of the quantum state between a specific operation and a reference operation.\n operation ShowQuantumStateComparison(\n targetRegister : Qubit[],\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl))\n : Unit {\n Message(\"Initial quantum state:\");\n DumpMachine();\n\n // Apply the reference operation, dump the simulator state and \"undo\" the operation by applying the adjoint.\n reference(targetRegister);\n Message(\"Expected quantum state after applying the operation:\");\n DumpMachine();\n Adjoint reference(targetRegister);\n\n // Apply the specific operation, dump the simulator state and \"undo\" the operation by applying the adjoint.\n op(targetRegister);\n Message(\"Actual quantum state after applying the operation:\");\n DumpMachine();\n Adjoint op(targetRegister);\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically on the zero state |0〉 ⊗ |0〉 ⊗ ... ⊗ |0〉 composed of\n /// `inputSize` qubits. If they don't, prints user feedback.\n operation CheckOperationsEquivalenceOnZeroStateWithFeedback(\n testImpl : (Qubit[] => Unit is Adj + Ctl),\n refImpl : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int\n ) : Bool {\n\n let isCorrect = CheckOperationsEquivalenceOnZeroState(testImpl, refImpl, inputSize);\n\n // Output different feedback to the user depending on whether the exercise was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n use target = Qubit[inputSize];\n ShowQuantumStateComparison(target, testImpl, refImpl);\n ResetAll(target);\n }\n isCorrect\n }\n\n\n internal operation EntangleRegisters(\n control : Qubit[],\n target : Qubit[]) : Unit is Adj + Ctl {\n Fact(\n Length(control) == Length(target),\n $\"The length of qubit registers must be the same.\");\n\n for index in IndexRange(control) {\n H(control[index]);\n CNOT(control[index], target[index]);\n }\n }\n}\n"
2319
+ "code": "// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nnamespace Microsoft.Quantum.Katas {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Intrinsic;\n\n /// # Summary\n /// Given two operations, checks whether they act identically for all input states.\n /// This operation is implemented by using the Choi–Jamiołkowski isomorphism.\n operation CheckOperationsEquivalence(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n use (control, target) = (Qubit[inputSize], Qubit[inputSize]);\n within {\n EntangleRegisters(control, target);\n }\n apply {\n op(target);\n Adjoint reference(target);\n }\n\n let areEquivalent = CheckAllZero(control + target);\n ResetAll(control + target);\n areEquivalent\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically (including global phase) for all input states.\n /// This is done through controlled versions of the operations instead of plain ones which convert the global phase\n /// into a relative phase that can be detected.\n operation CheckOperationsEquivalenceStrict(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n let controlledOp = register => Controlled op(register[...0], register[1...]);\n let controlledReference = register => Controlled reference(register[...0], register[1...]);\n let areEquivalent = CheckOperationsEquivalence(controlledOp, controlledReference, inputSize + 1);\n areEquivalent\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically on the zero state |0〉 ⊗ |0〉 ⊗ ... ⊗ |0〉 composed of\n /// `inputSize` qubits.\n operation CheckOperationsEquivalenceOnZeroState(\n op : (Qubit[] => Unit),\n reference : (Qubit[] => Unit is Adj),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n use target = Qubit[inputSize];\n op(target);\n Adjoint reference(target);\n let isCorrect = CheckAllZero(target);\n ResetAll(target);\n isCorrect\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically on the zero state |0〉 ⊗ |0〉 ⊗ ... ⊗ |0〉 composed of\n /// `inputSize` qubits.\n /// This operation introduces a control qubit to convert a global phase into a relative phase to be able to detect\n /// it.\n operation CheckOperationsEquivalenceOnZeroStateStrict(\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int)\n : Bool {\n Fact(inputSize > 0, \"`inputSize` must be positive\");\n use control = Qubit();\n use target = Qubit[inputSize];\n within {\n H(control);\n }\n apply {\n Controlled op([control], target);\n Adjoint Controlled reference([control], target);\n }\n\n let isCorrect = CheckAllZero([control] + target);\n ResetAll([control] + target);\n isCorrect\n }\n\n /// # Summary\n /// Shows the effect a quantum operation has on the quantum state.\n operation ShowEffectOnQuantumState(targetRegister : Qubit[], op : (Qubit[] => Unit is Adj + Ctl)) : Unit {\n Message(\"Quantum state before applying the operation:\");\n DumpMachine();\n\n // Apply the operation, dump the simulator state and \"undo\" the operation by applying the adjoint.\n Message(\"Quantum state after applying the operation:\");\n op(targetRegister);\n DumpMachine();\n Adjoint op(targetRegister);\n }\n\n /// # Summary\n /// Shows the comparison of the quantum state between a specific operation and a reference operation.\n operation ShowQuantumStateComparison(\n targetRegister : Qubit[],\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl))\n : Unit {\n Message(\"Initial quantum state:\");\n DumpMachine();\n\n // Apply the reference operation, dump the simulator state and \"undo\" the operation by applying the adjoint.\n reference(targetRegister);\n Message(\"Expected quantum state after applying the operation:\");\n DumpMachine();\n Adjoint reference(targetRegister);\n\n // Apply the specific operation, dump the simulator state and \"undo\" the operation by applying the adjoint.\n op(targetRegister);\n Message(\"Actual quantum state after applying the operation:\");\n DumpMachine();\n Adjoint op(targetRegister);\n }\n\n /// # Summary\n /// Given two operations, checks whether they act identically on the zero state |0〉 ⊗ |0〉 ⊗ ... ⊗ |0〉 composed of\n /// `inputSize` qubits. If they don't, prints user feedback.\n operation CheckOperationsEquivalenceOnZeroStateWithFeedback(\n testImpl : (Qubit[] => Unit is Adj + Ctl),\n refImpl : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int\n ) : Bool {\n\n let isCorrect = CheckOperationsEquivalenceOnZeroState(testImpl, refImpl, inputSize);\n\n // Output different feedback to the user depending on whether the exercise was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n use target = Qubit[inputSize];\n ShowQuantumStateComparison(target, testImpl, refImpl);\n ResetAll(target);\n }\n isCorrect\n }\n\n\n internal operation EntangleRegisters(\n control : Qubit[],\n target : Qubit[]) : Unit is Adj + Ctl {\n Fact(\n Length(control) == Length(target),\n $\"The length of qubit registers must be the same.\");\n\n for index in IndexRange(control) {\n H(control[index]);\n CNOT(control[index], target[index]);\n }\n }\n}\n"
2320
2320
  },
2321
2321
  {
2322
2322
  "id": "qubit__learn_single_qubit_state__Verification.qs",
@@ -2416,27 +2416,27 @@ export default {
2416
2416
  },
2417
2417
  {
2418
2418
  "id": "multi_qubit_measurements__full_measurements__Verification.qs",
2419
- "code": "namespace Kata.Verification {\n\n // Distinguish four basis states\n operation StatePrep_BasisStateMeasurement(qs : Qubit[], state : Int, dummyVar : Double) : Unit is Adj {\n if state / 2 == 1 {\n // |10⟩ or |11⟩\n X(qs[0]);\n }\n if state % 2 == 1 {\n // |01⟩ or |11⟩\n X(qs[1]);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishStates_MultiQubit(\n 2,\n 4,\n StatePrep_BasisStateMeasurement,\n Kata.BasisStateMeasurement,\n false,\n [\"|00⟩\", \"|01⟩\", \"|10⟩\", \"|11⟩\"]);\n\n if (isCorrect) {\n Message(\"Correct!\");\n Message(\"All test cases passed.\");\n } else {\n Message(\"Incorrect!\");\n }\n\n isCorrect\n }\n}\n"
2419
+ "code": "namespace Kata.Verification {\n\n // Distinguish four basis states\n operation StatePrep_BasisStateMeasurement(qs : Qubit[], state : Int, dummyVar : Double) : Unit is Adj {\n if state / 2 == 1 {\n // |10⟩ or |11⟩\n X(qs[0]);\n }\n if state % 2 == 1 {\n // |01⟩ or |11⟩\n X(qs[1]);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishStates_MultiQubit(\n 2,\n 4,\n StatePrep_BasisStateMeasurement,\n Kata.BasisStateMeasurement,\n false,\n [\"|00⟩\", \"|01⟩\", \"|10⟩\", \"|11⟩\"]);\n\n if (isCorrect) {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n\n isCorrect\n }\n}\n"
2420
2420
  },
2421
2421
  {
2422
2422
  "id": "multi_qubit_measurements__Common.qs",
2423
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Canon;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Measurement;\n open Microsoft.Quantum.Random;\n\n // \"Framework\" operation for testing multi-qubit tasks for distinguishing states of an array of qubits\n // with Int return\n operation DistinguishStates_MultiQubit(\n nQubits : Int,\n nStates : Int,\n statePrep : ((Qubit[], Int, Double) => Unit is Adj),\n testImpl : (Qubit[] => Int),\n preserveState : Bool,\n stateNames : String[]) : Bool {\n\n let nTotal = 100;\n // misclassifications will store the number of times state i has been classified as state j (dimension nStates^2)\n mutable misclassifications = [0, size = nStates * nStates];\n // unknownClassifications will store the number of times state i has been classified as some invalid state (index < 0 or >= nStates)\n mutable unknownClassifications = [0, size = nStates];\n\n use qs = Qubit[nQubits];\n for i in 1 .. nTotal {\n // get a random integer to define the state of the qubits\n let state = DrawRandomInt(0, nStates - 1);\n // get a random rotation angle to define the exact state of the qubits\n // for some exercises, this value might be a dummy variable which does not matter\n let alpha = DrawRandomDouble(0.0, 1.0) * PI();\n\n // do state prep: convert |0...0⟩ to outcome with return equal to state\n statePrep(qs, state, alpha);\n\n // get the solution's answer and verify that it's a match, if not, increase the exact mismatch count\n let ans = testImpl(qs);\n if ((ans >= 0) and (ans < nStates)) {\n // classification result is a valid state index - check if is it correct\n if ans != state {\n set misclassifications w/= ((state * nStates) + ans) <- (misclassifications[(state * nStates) + ans] + 1);\n }\n }\n else {\n // classification result is an invalid state index - file it separately\n set unknownClassifications w/= state <- (unknownClassifications[state] + 1);\n }\n\n if preserveState {\n // check that the state of the qubit after the operation is unchanged\n Adjoint statePrep(qs, state, alpha);\n if not CheckAllZero(qs) {\n Message(\"Test should preseve qubit state.\");\n ResetAll(qs);\n return false;\n }\n } else {\n // we're not checking the state of the qubit after the operation\n ResetAll(qs);\n }\n }\n ResetAll(qs);\n\n mutable totalMisclassifications = 0;\n for i in 0 .. nStates - 1 {\n for j in 0 .. nStates - 1 {\n if misclassifications[(i * nStates) + j] != 0 {\n set totalMisclassifications += misclassifications[i * nStates + j];\n Message($\"Misclassified {stateNames[i]} as {stateNames[j]} in {misclassifications[(i * nStates) + j]} test runs.\");\n }\n }\n if unknownClassifications[i] != 0 {\n set totalMisclassifications += unknownClassifications[i];\n Message($\"Misclassified {stateNames[i]} as Unknown State in {unknownClassifications[i]} test runs.\");\n }\n }\n totalMisclassifications == 0\n }\n}\n"
2423
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Canon;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Measurement;\n open Microsoft.Quantum.Random;\n\n // \"Framework\" operation for testing multi-qubit tasks for distinguishing states of an array of qubits\n // with Int return\n operation DistinguishStates_MultiQubit(\n nQubits : Int,\n nStates : Int,\n statePrep : ((Qubit[], Int, Double) => Unit is Adj),\n testImpl : (Qubit[] => Int),\n preserveState : Bool,\n stateNames : String[]) : Bool {\n\n let nTotal = 100;\n // misclassifications will store the number of times state i has been classified as state j (dimension nStates^2)\n mutable misclassifications = [0, size = nStates * nStates];\n // unknownClassifications will store the number of times state i has been classified as some invalid state (index < 0 or >= nStates)\n mutable unknownClassifications = [0, size = nStates];\n\n use qs = Qubit[nQubits];\n for i in 1 .. nTotal {\n // get a random integer to define the state of the qubits\n let state = DrawRandomInt(0, nStates - 1);\n // get a random rotation angle to define the exact state of the qubits\n // for some exercises, this value might be a dummy variable which does not matter\n let alpha = DrawRandomDouble(0.0, 1.0) * PI();\n\n // do state prep: convert |0...0⟩ to outcome with return equal to state\n statePrep(qs, state, alpha);\n\n // get the solution's answer and verify that it's a match, if not, increase the exact mismatch count\n let ans = testImpl(qs);\n if ((ans >= 0) and (ans < nStates)) {\n // classification result is a valid state index - check if is it correct\n if ans != state {\n set misclassifications w/= ((state * nStates) + ans) <- (misclassifications[(state * nStates) + ans] + 1);\n }\n }\n else {\n // classification result is an invalid state index - file it separately\n set unknownClassifications w/= state <- (unknownClassifications[state] + 1);\n }\n\n if preserveState {\n // check that the state of the qubit after the operation is unchanged\n Adjoint statePrep(qs, state, alpha);\n if not CheckAllZero(qs) {\n Message($\"Input quantum state {stateNames[state]} was not preserved during the measurement.\");\n ResetAll(qs);\n return false;\n }\n } else {\n // we're not checking the state of the qubit after the operation\n ResetAll(qs);\n }\n }\n ResetAll(qs);\n\n mutable totalMisclassifications = 0;\n for i in 0 .. nStates - 1 {\n for j in 0 .. nStates - 1 {\n if misclassifications[(i * nStates) + j] != 0 {\n set totalMisclassifications += misclassifications[i * nStates + j];\n Message($\"Misclassified {stateNames[i]} as {stateNames[j]} in {misclassifications[(i * nStates) + j]} test runs.\");\n }\n }\n if unknownClassifications[i] != 0 {\n set totalMisclassifications += unknownClassifications[i];\n Message($\"Misclassified {stateNames[i]} as Unknown State in {unknownClassifications[i]} test runs.\");\n }\n }\n totalMisclassifications == 0\n }\n}\n"
2424
2424
  },
2425
2425
  {
2426
2426
  "id": "multi_qubit_measurements__partial_measurements_for_system__Verification.qs",
2427
- "code": "namespace Kata.Verification {\n\n // Distinguish orthogonal states using partial measurements\n operation StatePrep_IsPlusPlusMinus(qs : Qubit[], state : Int, dummyVar : Double) : Unit is Adj {\n if state == 0 {\n // prepare the state |++-⟩\n H(qs[0]);\n H(qs[1]);\n X(qs[2]);\n H(qs[2]);\n } else {\n // prepare the state |---⟩\n X(qs[0]);\n H(qs[0]);\n X(qs[1]);\n H(qs[1]);\n X(qs[2]);\n H(qs[2]);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n return DistinguishStates_MultiQubit(\n 3,\n 2,\n StatePrep_IsPlusPlusMinus,\n Kata.IsPlusPlusMinus,\n false,\n [\"|++-⟩\", \"|---⟩\"]);\n }\n\n}\n"
2427
+ "code": "namespace Kata.Verification {\n\n // Distinguish orthogonal states using partial measurements\n operation StatePrep_IsPlusPlusMinus(qs : Qubit[], state : Int, dummyVar : Double) : Unit is Adj {\n if state == 0 {\n // Prepare the state |++-⟩\n X(qs[2]);\n } else {\n // Prepare the state |---⟩\n ApplyToEachA(X, qs);\n }\n ApplyToEachA(H, qs);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishStates_MultiQubit(\n 3,\n 2,\n StatePrep_IsPlusPlusMinus,\n Kata.IsPlusPlusMinus,\n true,\n [\"|++-⟩\", \"|---⟩\"]);\n if (isCorrect) {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n\n isCorrect \n }\n}\n"
2428
2428
  },
2429
2429
  {
2430
2430
  "id": "multi_qubit_measurements__state_modification__Verification.qs",
2431
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n\n // State selection using partial measurements\n operation stateInitialize_StateSelction(alpha : Double, qs : Qubit[]) : Unit {\n // Prepare the state to be input to the testImplementation\n // set the second qubit in a superposition a |0⟩ + b|1⟩\n // with a = cos alpha, b = sin alpha\n Ry(2.0 * alpha, qs[1]);\n\n H(qs[0]);\n // Apply CX gate\n CX(qs[0], qs[1]);\n }\n\n operation statePrepare_StateSelction(alpha : Double, Choice : Int, qs : Qubit[]) : Unit is Adj {\n // The expected state of the second qubit for the exercise.\n\n // set the second qubit in a superposition a |0⟩ + b|1⟩\n // with a = cos alpha, b = sin alpha\n Ry(2.0 * alpha, qs[1]);\n if Choice == 1 {\n // if the Choice is 1, change the state to b|0⟩ + a|1⟩\n X(qs[1]);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n use qs = Qubit[2];\n for i in 0 .. 5 {\n let alpha = (PI() * IntAsDouble(i)) / 5.0;\n\n //for Choice = 0 and 1,\n for Choice in 0 .. 1 {\n // Prepare the state to be input to the testImplementation\n stateInitialize_StateSelction(alpha, qs);\n\n // operate testImplementation\n Kata.StateSelction(qs, Choice);\n // reset the first qubit, since its state does not matter\n Reset(qs[0]);\n\n // apply adjoint reference operation and check that the result is correct\n Adjoint statePrepare_StateSelction(alpha, Choice, qs);\n\n if not CheckAllZero(qs) {\n ResetAll(qs);\n return false;\n }\n ResetAll(qs);\n }\n }\n ResetAll(qs);\n true\n }\n\n}\n"
2431
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n\n // State selection using partial measurements\n operation StateInitialize_StateSelection(alpha : Double, qs : Qubit[]) : Unit {\n // Prepare the state to be input to the testImplementation\n // set the second qubit in a superposition a |0⟩ + b|1⟩\n // with a = cos alpha, b = sin alpha\n Ry(2.0 * alpha, qs[1]);\n\n H(qs[0]);\n // Apply CX gate\n CX(qs[0], qs[1]);\n }\n\n // Prepare the expected state of the second qubit for the exercise.\n operation StatePrepare_StateSelection(alpha : Double, ind : Int, q : Qubit) : Unit is Adj {\n // set the second qubit in a superposition a|0⟩ + b|1⟩\n // with a = cos alpha, b = sin alpha\n Ry(2.0 * alpha, q);\n if ind == 1 {\n // change the state to b|0⟩ + a|1⟩\n X(q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n use qs = Qubit[2];\n for i in 0 .. 5 {\n let alpha = (PI() * IntAsDouble(i)) / 5.0;\n let params = $\"a = {Cos(alpha)}, b = {Sin(alpha)}\";\n\n for ind in 0 .. 1 {\n // Prepare the state to be input to the testImplementation\n StateInitialize_StateSelection(alpha, qs);\n\n // operate testImplementation\n Kata.StateSelection(qs, ind);\n // reset the first qubit, since its state does not matter\n Reset(qs[0]);\n\n // apply adjoint reference operation and check that the result is correct\n Adjoint StatePrepare_StateSelection(alpha, ind, qs[1]);\n\n if not CheckAllZero(qs) {\n ResetAll(qs);\n Message(\"Incorrect.\");\n Message($\"The state of the second qubit for {params}, ind = {ind} does not match expectation.\");\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
2432
2432
  },
2433
2433
  {
2434
2434
  "id": "multi_qubit_measurements__state_preparation__Verification.qs",
2435
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n\n // State preparation using partial measurements\n operation RefImpl_T4(qs : Qubit[]) : Unit is Adj {\n // Rotate first qubit to (sqrt(2) |0⟩ + |1⟩) / sqrt(3)\n let theta = ArcSin(1.0 / Sqrt(3.0));\n Ry(2.0 * theta, qs[0]);\n\n // Split the state sqrt(2) |0⟩ ⊗ |0⟩ into |00⟩ + |01⟩\n ApplyControlledOnInt(0, H, [qs[0]], qs[1]);\n }\n\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n use qs = Qubit[2];\n\n // operate the test implementation\n Kata.PostSelection(qs);\n\n // apply adjoint reference operation and check that the result is |0⟩\n Adjoint RefImpl_T4(qs);\n let isCorrect = CheckAllZero(qs);\n ResetAll(qs);\n isCorrect\n }\n\n}\n"
2435
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n // State preparation using partial measurements\n operation StatePrep_Rotations(qs : Qubit[]) : Unit is Adj {\n // Rotate first qubit to (sqrt(2) |0⟩ + |1⟩) / sqrt(3)\n let theta = ArcSin(1.0 / Sqrt(3.0));\n Ry(2.0 * theta, qs[0]);\n\n // Split the state sqrt(2) |0⟩ ⊗ |0⟩ into |00⟩ + |01⟩\n ApplyControlledOnInt(0, H, [qs[0]], qs[1]);\n }\n\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = CheckOperationsEquivalenceOnZeroState(Kata.PostSelection, StatePrep_Rotations, 2);\n if (isCorrect) {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n // TODO #1207: refactor kata libraries ShowQuantumStateComparison to not require adjoint\n use qs = Qubit[2];\n Message(\"Expected quantum state after applying the operation:\");\n StatePrep_Rotations(qs);\n DumpMachine();\n ResetAll(qs);\n\n Kata.PostSelection(qs);\n Message(\"Actual quantum state after applying the operation:\");\n DumpMachine();\n ResetAll(qs);\n }\n isCorrect\n }\n}\n"
2436
2436
  },
2437
2437
  {
2438
2438
  "id": "multi_qubit_measurements__joint_measurements__Verification.qs",
2439
- "code": "namespace Kata.Verification {\n\n // Two qubit parity Measurement\n operation StatePrep_ParityMeasurement(qs : Qubit[], state : Int, alpha : Double) : Unit is Adj {\n // prep cos(alpha) * |0..0⟩ + sin(alpha) * |1..1⟩\n Ry(2.0 * alpha, qs[0]);\n for i in 1 .. Length(qs) - 1 {\n CNOT(qs[0], qs[i]);\n }\n\n if state == 1 {\n // flip the state of the first half of the qubits\n for i in 0 .. Length(qs) / 2 - 1 {\n X(qs[i]);\n }\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n return DistinguishStates_MultiQubit(\n 2,\n 2,\n StatePrep_ParityMeasurement,\n Kata.ParityMeasurement,\n true,\n [\"α|00⟩ + β|11⟩\", \"α|01⟩ + β|10⟩\"]);\n }\n}\n"
2439
+ "code": "namespace Kata.Verification {\n\n // Two qubit parity Measurement\n operation StatePrep_ParityMeasurement(qs : Qubit[], state : Int, alpha : Double) : Unit is Adj {\n // prep cos(alpha) * |0..0⟩ + sin(alpha) * |1..1⟩\n Ry(2.0 * alpha, qs[0]);\n CNOT(qs[0], qs[1]);\n\n if state == 1 {\n // flip the state of the first qubit\n X(qs[0]);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishStates_MultiQubit(\n 2,\n 2,\n StatePrep_ParityMeasurement,\n Kata.ParityMeasurement,\n true,\n [\"α|00⟩ + β|11⟩\", \"α|01⟩ + β|10⟩\"]);\n\n if (isCorrect) {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n\n isCorrect\n }\n}\n"
2440
2440
  },
2441
2441
  {
2442
2442
  "id": "random_numbers__random_bit__Verification.qs",