qsharp-lang 1.3.5-dev → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. package/dist/browser.d.ts +2 -2
  2. package/dist/compiler/compiler.d.ts +10 -4
  3. package/dist/compiler/compiler.js +15 -6
  4. package/dist/katas-content.generated.js +479 -79
  5. package/docs/Microsoft.Quantum.Arrays/All.md +1 -1
  6. package/docs/Microsoft.Quantum.Arrays/Any.md +1 -1
  7. package/docs/Microsoft.Quantum.Arrays/Chunks.md +1 -1
  8. package/docs/Microsoft.Quantum.Arrays/CircularlyShifted.md +1 -1
  9. package/docs/Microsoft.Quantum.Arrays/ColumnAt.md +1 -1
  10. package/docs/Microsoft.Quantum.Arrays/Count.md +2 -2
  11. package/docs/Microsoft.Quantum.Arrays/Diagonal.md +1 -1
  12. package/docs/Microsoft.Quantum.Arrays/DrawMany.md +1 -1
  13. package/docs/Microsoft.Quantum.Arrays/Enumerated.md +1 -1
  14. package/docs/Microsoft.Quantum.Arrays/Excluding.md +1 -1
  15. package/docs/Microsoft.Quantum.Arrays/Filtered.md +1 -1
  16. package/docs/Microsoft.Quantum.Arrays/FlatMapped.md +1 -1
  17. package/docs/Microsoft.Quantum.Arrays/Flattened.md +1 -1
  18. package/docs/Microsoft.Quantum.Arrays/Fold.md +1 -1
  19. package/docs/Microsoft.Quantum.Arrays/ForEach.md +1 -1
  20. package/docs/Microsoft.Quantum.Arrays/Head.md +1 -1
  21. package/docs/Microsoft.Quantum.Arrays/HeadAndRest.md +1 -1
  22. package/docs/Microsoft.Quantum.Arrays/IndexOf.md +1 -1
  23. package/docs/Microsoft.Quantum.Arrays/IndexRange.md +1 -1
  24. package/docs/Microsoft.Quantum.Arrays/Interleaved.md +1 -1
  25. package/docs/Microsoft.Quantum.Arrays/IsEmpty.md +1 -1
  26. package/docs/Microsoft.Quantum.Arrays/IsRectangularArray.md +1 -1
  27. package/docs/Microsoft.Quantum.Arrays/IsSorted.md +1 -1
  28. package/docs/Microsoft.Quantum.Arrays/IsSquareArray.md +1 -1
  29. package/docs/Microsoft.Quantum.Arrays/Mapped.md +1 -1
  30. package/docs/Microsoft.Quantum.Arrays/MappedByIndex.md +1 -1
  31. package/docs/Microsoft.Quantum.Arrays/MappedOverRange.md +1 -1
  32. package/docs/Microsoft.Quantum.Arrays/Most.md +1 -1
  33. package/docs/Microsoft.Quantum.Arrays/MostAndTail.md +1 -1
  34. package/docs/Microsoft.Quantum.Arrays/Padded.md +1 -1
  35. package/docs/Microsoft.Quantum.Arrays/Partitioned.md +1 -1
  36. package/docs/Microsoft.Quantum.Arrays/Rest.md +1 -1
  37. package/docs/Microsoft.Quantum.Arrays/Reversed.md +1 -1
  38. package/docs/Microsoft.Quantum.Arrays/SequenceI.md +1 -1
  39. package/docs/Microsoft.Quantum.Arrays/SequenceL.md +1 -1
  40. package/docs/Microsoft.Quantum.Arrays/Sorted.md +1 -1
  41. package/docs/Microsoft.Quantum.Arrays/Subarray.md +1 -1
  42. package/docs/Microsoft.Quantum.Arrays/Swapped.md +1 -1
  43. package/docs/Microsoft.Quantum.Arrays/Tail.md +1 -1
  44. package/docs/Microsoft.Quantum.Arrays/Transposed.md +1 -1
  45. package/docs/Microsoft.Quantum.Arrays/Unzipped.md +1 -1
  46. package/docs/Microsoft.Quantum.Arrays/Where.md +1 -1
  47. package/docs/Microsoft.Quantum.Arrays/Windows.md +1 -1
  48. package/docs/Microsoft.Quantum.Arrays/Zipped.md +1 -1
  49. package/docs/Microsoft.Quantum.Canon/ApplyCNOTChain.md +1 -1
  50. package/docs/Microsoft.Quantum.Canon/ApplyControlledOnBitString.md +23 -12
  51. package/docs/Microsoft.Quantum.Canon/ApplyControlledOnInt.md +1 -1
  52. package/docs/Microsoft.Quantum.Canon/ApplyP.md +1 -1
  53. package/docs/Microsoft.Quantum.Canon/ApplyPauli.md +1 -1
  54. package/docs/Microsoft.Quantum.Canon/ApplyPauliFromBitString.md +1 -1
  55. package/docs/Microsoft.Quantum.Canon/ApplyPauliFromInt.md +1 -1
  56. package/docs/Microsoft.Quantum.Canon/ApplyQFT.md +1 -1
  57. package/docs/Microsoft.Quantum.Canon/ApplyToEach.md +1 -1
  58. package/docs/Microsoft.Quantum.Canon/ApplyToEachA.md +1 -1
  59. package/docs/Microsoft.Quantum.Canon/ApplyToEachC.md +1 -1
  60. package/docs/Microsoft.Quantum.Canon/ApplyToEachCA.md +1 -1
  61. package/docs/Microsoft.Quantum.Canon/ApplyXorInPlace.md +1 -1
  62. package/docs/Microsoft.Quantum.Canon/ApplyXorInPlaceL.md +1 -1
  63. package/docs/Microsoft.Quantum.Canon/CX.md +1 -1
  64. package/docs/Microsoft.Quantum.Canon/CY.md +7 -5
  65. package/docs/Microsoft.Quantum.Canon/CZ.md +7 -5
  66. package/docs/Microsoft.Quantum.Canon/Fst.md +1 -1
  67. package/docs/Microsoft.Quantum.Canon/Snd.md +1 -1
  68. package/docs/Microsoft.Quantum.Canon/SwapReverseRegister.md +1 -1
  69. package/docs/Microsoft.Quantum.Convert/BigIntAsBoolArray.md +1 -1
  70. package/docs/Microsoft.Quantum.Convert/BoolArrayAsBigInt.md +1 -1
  71. package/docs/Microsoft.Quantum.Convert/BoolArrayAsInt.md +4 -3
  72. package/docs/Microsoft.Quantum.Convert/BoolArrayAsResultArray.md +1 -1
  73. package/docs/Microsoft.Quantum.Convert/BoolAsResult.md +1 -1
  74. package/docs/Microsoft.Quantum.Convert/ComplexAsComplexPolar.md +1 -1
  75. package/docs/Microsoft.Quantum.Convert/ComplexPolarAsComplex.md +1 -1
  76. package/docs/Microsoft.Quantum.Convert/IntAsBigInt.md +3 -3
  77. package/docs/Microsoft.Quantum.Convert/IntAsBoolArray.md +1 -1
  78. package/docs/Microsoft.Quantum.Convert/IntAsDouble.md +17 -3
  79. package/docs/Microsoft.Quantum.Convert/ResultArrayAsBoolArray.md +1 -1
  80. package/docs/Microsoft.Quantum.Convert/ResultArrayAsInt.md +1 -1
  81. package/docs/Microsoft.Quantum.Convert/ResultAsBool.md +1 -1
  82. package/docs/Microsoft.Quantum.Core/IsRangeEmpty.md +1 -1
  83. package/docs/Microsoft.Quantum.Core/Length.md +9 -4
  84. package/docs/Microsoft.Quantum.Core/RangeEnd.md +1 -1
  85. package/docs/Microsoft.Quantum.Core/RangeReverse.md +1 -1
  86. package/docs/Microsoft.Quantum.Core/RangeStart.md +6 -1
  87. package/docs/Microsoft.Quantum.Core/RangeStep.md +1 -1
  88. package/docs/Microsoft.Quantum.Core/Repeated.md +11 -4
  89. package/docs/Microsoft.Quantum.Diagnostics/CheckAllZero.md +1 -1
  90. package/docs/Microsoft.Quantum.Diagnostics/CheckOperationsAreEqual.md +1 -1
  91. package/docs/Microsoft.Quantum.Diagnostics/CheckZero.md +1 -1
  92. package/docs/Microsoft.Quantum.Diagnostics/DumpMachine.md +1 -1
  93. package/docs/Microsoft.Quantum.Diagnostics/DumpRegister.md +1 -1
  94. package/docs/Microsoft.Quantum.Diagnostics/Fact.md +1 -1
  95. package/docs/Microsoft.Quantum.Intrinsic/CCNOT.md +1 -1
  96. package/docs/Microsoft.Quantum.Intrinsic/CNOT.md +1 -1
  97. package/docs/Microsoft.Quantum.Intrinsic/Exp.md +1 -1
  98. package/docs/Microsoft.Quantum.Intrinsic/H.md +1 -1
  99. package/docs/Microsoft.Quantum.Intrinsic/I.md +1 -1
  100. package/docs/Microsoft.Quantum.Intrinsic/M.md +1 -1
  101. package/docs/Microsoft.Quantum.Intrinsic/Measure.md +1 -1
  102. package/docs/Microsoft.Quantum.Intrinsic/Message.md +1 -1
  103. package/docs/Microsoft.Quantum.Intrinsic/R.md +1 -1
  104. package/docs/Microsoft.Quantum.Intrinsic/R1.md +1 -1
  105. package/docs/Microsoft.Quantum.Intrinsic/R1Frac.md +1 -1
  106. package/docs/Microsoft.Quantum.Intrinsic/RFrac.md +1 -1
  107. package/docs/Microsoft.Quantum.Intrinsic/Reset.md +1 -1
  108. package/docs/Microsoft.Quantum.Intrinsic/ResetAll.md +1 -1
  109. package/docs/Microsoft.Quantum.Intrinsic/Rx.md +1 -1
  110. package/docs/Microsoft.Quantum.Intrinsic/Rxx.md +1 -1
  111. package/docs/Microsoft.Quantum.Intrinsic/Ry.md +1 -1
  112. package/docs/Microsoft.Quantum.Intrinsic/Ryy.md +1 -1
  113. package/docs/Microsoft.Quantum.Intrinsic/Rz.md +1 -1
  114. package/docs/Microsoft.Quantum.Intrinsic/Rzz.md +1 -1
  115. package/docs/Microsoft.Quantum.Intrinsic/S.md +1 -1
  116. package/docs/Microsoft.Quantum.Intrinsic/SWAP.md +1 -1
  117. package/docs/Microsoft.Quantum.Intrinsic/T.md +1 -1
  118. package/docs/Microsoft.Quantum.Intrinsic/X.md +1 -1
  119. package/docs/Microsoft.Quantum.Intrinsic/Y.md +1 -1
  120. package/docs/Microsoft.Quantum.Intrinsic/Z.md +1 -1
  121. package/docs/Microsoft.Quantum.Logical/Xor.md +7 -4
  122. package/docs/Microsoft.Quantum.Math/AbsComplex.md +1 -1
  123. package/docs/Microsoft.Quantum.Math/AbsComplexPolar.md +1 -1
  124. package/docs/Microsoft.Quantum.Math/AbsD.md +1 -1
  125. package/docs/Microsoft.Quantum.Math/AbsI.md +1 -1
  126. package/docs/Microsoft.Quantum.Math/AbsL.md +1 -1
  127. package/docs/Microsoft.Quantum.Math/AbsSquaredComplex.md +1 -1
  128. package/docs/Microsoft.Quantum.Math/AbsSquaredComplexPolar.md +1 -1
  129. package/docs/Microsoft.Quantum.Math/ApproximateFactorial.md +1 -1
  130. package/docs/Microsoft.Quantum.Math/ArcCos.md +1 -1
  131. package/docs/Microsoft.Quantum.Math/ArcCosh.md +1 -1
  132. package/docs/Microsoft.Quantum.Math/ArcSin.md +1 -1
  133. package/docs/Microsoft.Quantum.Math/ArcSinh.md +1 -1
  134. package/docs/Microsoft.Quantum.Math/ArcTan.md +1 -1
  135. package/docs/Microsoft.Quantum.Math/ArcTan2.md +1 -1
  136. package/docs/Microsoft.Quantum.Math/ArcTanh.md +1 -1
  137. package/docs/Microsoft.Quantum.Math/ArgComplex.md +1 -1
  138. package/docs/Microsoft.Quantum.Math/ArgComplexPolar.md +1 -1
  139. package/docs/Microsoft.Quantum.Math/Binom.md +1 -1
  140. package/docs/Microsoft.Quantum.Math/BitSizeI.md +1 -1
  141. package/docs/Microsoft.Quantum.Math/BitSizeL.md +1 -1
  142. package/docs/Microsoft.Quantum.Math/Ceiling.md +1 -1
  143. package/docs/Microsoft.Quantum.Math/Complex.md +1 -1
  144. package/docs/Microsoft.Quantum.Math/ComplexPolar.md +1 -1
  145. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentI.md +1 -1
  146. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentL.md +1 -1
  147. package/docs/Microsoft.Quantum.Math/Cos.md +1 -1
  148. package/docs/Microsoft.Quantum.Math/Cosh.md +1 -1
  149. package/docs/Microsoft.Quantum.Math/DivRemI.md +1 -1
  150. package/docs/Microsoft.Quantum.Math/DivRemL.md +1 -1
  151. package/docs/Microsoft.Quantum.Math/DividedByC.md +1 -1
  152. package/docs/Microsoft.Quantum.Math/DividedByCP.md +1 -1
  153. package/docs/Microsoft.Quantum.Math/E.md +10 -6
  154. package/docs/Microsoft.Quantum.Math/ExpModI.md +1 -1
  155. package/docs/Microsoft.Quantum.Math/ExpModL.md +1 -1
  156. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorI.md +1 -1
  157. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorL.md +1 -1
  158. package/docs/Microsoft.Quantum.Math/FactorialI.md +1 -1
  159. package/docs/Microsoft.Quantum.Math/FactorialL.md +1 -1
  160. package/docs/Microsoft.Quantum.Math/Floor.md +1 -1
  161. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorI.md +1 -1
  162. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorL.md +1 -1
  163. package/docs/Microsoft.Quantum.Math/HammingWeightI.md +1 -1
  164. package/docs/Microsoft.Quantum.Math/InverseModI.md +1 -1
  165. package/docs/Microsoft.Quantum.Math/InverseModL.md +1 -1
  166. package/docs/Microsoft.Quantum.Math/IsCoprimeI.md +1 -1
  167. package/docs/Microsoft.Quantum.Math/IsCoprimeL.md +1 -1
  168. package/docs/Microsoft.Quantum.Math/IsInfinite.md +1 -1
  169. package/docs/Microsoft.Quantum.Math/IsNaN.md +1 -1
  170. package/docs/Microsoft.Quantum.Math/LargestFixedPoint.md +1 -1
  171. package/docs/Microsoft.Quantum.Math/Lg.md +1 -1
  172. package/docs/Microsoft.Quantum.Math/Log.md +1 -1
  173. package/docs/Microsoft.Quantum.Math/Log10.md +1 -1
  174. package/docs/Microsoft.Quantum.Math/LogFactorialD.md +1 -1
  175. package/docs/Microsoft.Quantum.Math/LogGammaD.md +1 -1
  176. package/docs/Microsoft.Quantum.Math/LogOf2.md +9 -5
  177. package/docs/Microsoft.Quantum.Math/Max.md +1 -1
  178. package/docs/Microsoft.Quantum.Math/MaxD.md +1 -1
  179. package/docs/Microsoft.Quantum.Math/MaxI.md +1 -1
  180. package/docs/Microsoft.Quantum.Math/MaxL.md +1 -1
  181. package/docs/Microsoft.Quantum.Math/Min.md +1 -1
  182. package/docs/Microsoft.Quantum.Math/MinD.md +1 -1
  183. package/docs/Microsoft.Quantum.Math/MinI.md +1 -1
  184. package/docs/Microsoft.Quantum.Math/MinL.md +1 -1
  185. package/docs/Microsoft.Quantum.Math/MinusC.md +1 -1
  186. package/docs/Microsoft.Quantum.Math/MinusCP.md +1 -1
  187. package/docs/Microsoft.Quantum.Math/ModulusI.md +1 -1
  188. package/docs/Microsoft.Quantum.Math/ModulusL.md +1 -1
  189. package/docs/Microsoft.Quantum.Math/NegationC.md +1 -1
  190. package/docs/Microsoft.Quantum.Math/NegationCP.md +1 -1
  191. package/docs/Microsoft.Quantum.Math/PI.md +11 -6
  192. package/docs/Microsoft.Quantum.Math/PNorm.md +1 -1
  193. package/docs/Microsoft.Quantum.Math/PNormalized.md +1 -1
  194. package/docs/Microsoft.Quantum.Math/PlusC.md +1 -1
  195. package/docs/Microsoft.Quantum.Math/PlusCP.md +1 -1
  196. package/docs/Microsoft.Quantum.Math/PowC.md +1 -1
  197. package/docs/Microsoft.Quantum.Math/PowCP.md +1 -1
  198. package/docs/Microsoft.Quantum.Math/RealMod.md +1 -1
  199. package/docs/Microsoft.Quantum.Math/Round.md +3 -3
  200. package/docs/Microsoft.Quantum.Math/SignD.md +1 -1
  201. package/docs/Microsoft.Quantum.Math/SignI.md +1 -1
  202. package/docs/Microsoft.Quantum.Math/SignL.md +1 -1
  203. package/docs/Microsoft.Quantum.Math/Sin.md +1 -1
  204. package/docs/Microsoft.Quantum.Math/Sinh.md +1 -1
  205. package/docs/Microsoft.Quantum.Math/SmallestFixedPoint.md +1 -1
  206. package/docs/Microsoft.Quantum.Math/Sqrt.md +1 -1
  207. package/docs/Microsoft.Quantum.Math/SquaredNorm.md +1 -1
  208. package/docs/Microsoft.Quantum.Math/Tan.md +1 -1
  209. package/docs/Microsoft.Quantum.Math/Tanh.md +1 -1
  210. package/docs/Microsoft.Quantum.Math/TimesC.md +1 -1
  211. package/docs/Microsoft.Quantum.Math/TimesCP.md +1 -1
  212. package/docs/Microsoft.Quantum.Math/TrailingZeroCountI.md +1 -1
  213. package/docs/Microsoft.Quantum.Math/TrailingZeroCountL.md +1 -1
  214. package/docs/Microsoft.Quantum.Math/Truncate.md +1 -1
  215. package/docs/Microsoft.Quantum.Measurement/MResetEachZ.md +6 -1
  216. package/docs/Microsoft.Quantum.Measurement/MResetX.md +1 -1
  217. package/docs/Microsoft.Quantum.Measurement/MResetY.md +1 -1
  218. package/docs/Microsoft.Quantum.Measurement/MResetZ.md +1 -1
  219. package/docs/Microsoft.Quantum.Measurement/MeasureAllZ.md +7 -6
  220. package/docs/Microsoft.Quantum.Measurement/MeasureEachZ.md +19 -3
  221. package/docs/Microsoft.Quantum.Measurement/MeasureInteger.md +1 -1
  222. package/docs/Microsoft.Quantum.Random/DrawRandomDouble.md +4 -6
  223. package/docs/Microsoft.Quantum.Random/DrawRandomInt.md +4 -6
  224. package/docs/Microsoft.Quantum.ResourceEstimation/AccountForEstimates.md +1 -1
  225. package/docs/Microsoft.Quantum.ResourceEstimation/AuxQubitCount.md +1 -1
  226. package/docs/Microsoft.Quantum.ResourceEstimation/BeginEstimateCaching.md +1 -1
  227. package/docs/Microsoft.Quantum.ResourceEstimation/BeginRepeatEstimates.md +1 -2
  228. package/docs/Microsoft.Quantum.ResourceEstimation/CczCount.md +1 -1
  229. package/docs/Microsoft.Quantum.ResourceEstimation/EndEstimateCaching.md +1 -1
  230. package/docs/Microsoft.Quantum.ResourceEstimation/EndRepeatEstimates.md +1 -2
  231. package/docs/Microsoft.Quantum.ResourceEstimation/MeasurementCount.md +1 -1
  232. package/docs/Microsoft.Quantum.ResourceEstimation/PSSPCLayout.md +1 -1
  233. package/docs/Microsoft.Quantum.ResourceEstimation/RepeatEstimates.md +1 -2
  234. package/docs/Microsoft.Quantum.ResourceEstimation/RotationCount.md +1 -1
  235. package/docs/Microsoft.Quantum.ResourceEstimation/RotationDepth.md +1 -1
  236. package/docs/Microsoft.Quantum.ResourceEstimation/SingleVariant.md +1 -1
  237. package/docs/Microsoft.Quantum.ResourceEstimation/TCount.md +1 -1
  238. package/docs/Microsoft.Quantum.Unstable.Arithmetic/AddLE.md +1 -1
  239. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualL.md +1 -1
  240. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualLE.md +1 -1
  241. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterL.md +1 -1
  242. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterLE.md +1 -1
  243. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualL.md +1 -1
  244. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualLE.md +1 -1
  245. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessL.md +1 -1
  246. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessLE.md +1 -1
  247. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualL.md +1 -1
  248. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualLE.md +1 -1
  249. package/docs/Microsoft.Quantum.Unstable.Arithmetic/FourierTDIncByLE.md +3 -3
  250. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByI.md +1 -1
  251. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByIUsingIncByLE.md +1 -1
  252. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByL.md +1 -1
  253. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLE.md +1 -1
  254. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLEUsingAddLE.md +4 -4
  255. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLUsingIncByLE.md +1 -1
  256. package/docs/Microsoft.Quantum.Unstable.Arithmetic/LookAheadDKRSAddLE.md +4 -4
  257. package/docs/Microsoft.Quantum.Unstable.Arithmetic/MAJ.md +1 -1
  258. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ReflectAboutInteger.md +3 -5
  259. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGAddLE.md +3 -3
  260. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGIncByLE.md +3 -3
  261. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryTTKIncByLE.md +4 -5
  262. package/docs/Microsoft.Quantum.Unstable.StatePreparation/ApproximatelyPreparePureStateCP.md +3 -3
  263. package/docs/Microsoft.Quantum.Unstable.StatePreparation/PreparePureStateD.md +3 -3
  264. package/docs/Microsoft.Quantum.Unstable.TableLookup/Select.md +8 -8
  265. package/lib/node/qsc_wasm.cjs +60 -21
  266. package/lib/node/qsc_wasm.d.cts +21 -7
  267. package/lib/node/qsc_wasm_bg.wasm +0 -0
  268. package/lib/web/qsc_wasm.d.ts +25 -10
  269. package/lib/web/qsc_wasm.js +60 -21
  270. package/lib/web/qsc_wasm_bg.wasm +0 -0
  271. package/package.json +3 -3
  272. package/ux/circuit.tsx +157 -59
  273. package/ux/data.ts +4 -1
  274. package/ux/estimatesPanel.tsx +2 -10
  275. package/ux/qsharp-ux.css +8 -0
  276. package/ux/spinner.tsx +17 -0
  277. package/ux/tsconfig.json +2 -1
@@ -1226,60 +1226,60 @@ export default {
1226
1226
  },
1227
1227
  {
1228
1228
  "type": "exercise",
1229
- "id": "single_qubit_gates__y_gate",
1230
- "title": "The Y Gate",
1229
+ "id": "single_qubit_gates__sign_flip",
1230
+ "title": "Sign Flip",
1231
1231
  "description": {
1232
1232
  "type": "text-content",
1233
- "asHtml": "<p><strong>Input:</strong> A qubit in an arbitrary state $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$.</p>\n<p><strong>Goal:</strong> Apply the Y gate to the qubit, i.e., transform the given state into $i\\alpha|1\\rangle - i\\beta|0\\rangle$.</p>\n",
1234
- "asMarkdown": "**Input:** A qubit in an arbitrary state $|\\\\psi\\\\rangle = \\\\alpha|0\\\\rangle + \\\\beta|1\\\\rangle$.\n\n**Goal:** Apply the Y gate to the qubit, i.e., transform the given state into $i\\\\alpha|1\\\\rangle - i\\\\beta|0\\\\rangle$."
1233
+ "asHtml": "<p><strong>Input</strong>: A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.</p>\n<p><strong>Goal</strong> : Change the qubit state to $\\alpha |0\\rangle - \\beta |1\\rangle$ (i.e., flip the sign of the $|1\\rangle$ component of the superposition).</p>\n",
1234
+ "asMarkdown": "**Input**: A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n\n**Goal** : Change the qubit state to $\\alpha |0\\rangle - \\beta |1\\rangle$ (i.e., flip the sign of the $|1\\rangle$ component of the superposition).\n"
1235
1235
  },
1236
1236
  "sourceIds": [
1237
- "single_qubit_gates__y_gate__Verification.qs",
1237
+ "single_qubit_gates__sign_flip__Verification.qs",
1238
1238
  "KatasLibrary.qs"
1239
1239
  ],
1240
- "placeholderCode": "namespace Kata {\n operation ApplyY(q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}",
1240
+ "placeholderCode": "namespace Kata {\n operation SignFlip (q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}\n\n",
1241
1241
  "explainedSolution": {
1242
1242
  "type": "explained-solution",
1243
1243
  "items": [
1244
1244
  {
1245
1245
  "type": "text-content",
1246
- "asHtml": "<p>We have to do exactly what the task asks us to do: apply the Pauli gate $Y=\\begin{bmatrix} 0 &amp; -i \\\\ i &amp; 0 \\end{bmatrix}$.</p>\n<p>This has the effect of turning $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$ into $Y|\\psi\\rangle = i\\alpha|1\\rangle - i\\beta|0\\rangle$, which in matrix form looks as follows:\n$$\n\\begin{bmatrix} 0 &amp; -i \\\\ i &amp; 0 \\end{bmatrix} \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} = \n\\begin{bmatrix} -i\\beta \\\\ i\\alpha \\end{bmatrix}\n$$</p>\n",
1247
- "asMarkdown": "\nWe have to do exactly what the task asks us to do: apply the Pauli gate $Y=\\\\begin{bmatrix} 0 & -i \\\\\\\\ i & 0 \\\\end{bmatrix}$.\n\nThis has the effect of turning $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$ into $Y|\\psi\\rangle = i\\alpha|1\\rangle - i\\beta|0\\rangle$, which in matrix form looks as follows:\n$$\n\\begin{bmatrix} 0 & -i \\\\\\ i & 0 \\end{bmatrix} \\begin{bmatrix} \\alpha \\\\\\ \\beta \\end{bmatrix} = \n\\begin{bmatrix} -i\\beta \\\\\\ i\\alpha \\end{bmatrix}\n$$"
1246
+ "asHtml": "<p>The action of the Pauli Z gate is exactly what is required by this question.\nThis gate leaves the sign of the $|0\\rangle$ component of the superposition unchanged but flips the sign of the $|1\\rangle$ component of the superposition.</p>\n<p>As a reminder, the Pauli Z gate is defined by the following matrix:</p>\n<p>$$\nZ =\n \\begin{bmatrix}1 &amp; 0\\\\0 &amp; -1 \\end{bmatrix}\n$$</p>\n<p>Let&#39;s see its effect on the only computational basis state that it changes, $|1\\rangle$:</p>\n<p>$$\nZ|1\\rangle =\n \\begin{bmatrix} 1 &amp; 0\\\\0 &amp; -1 \\end{bmatrix}\n \\begin{bmatrix}0\\\\ 1\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1 \\cdot 0 + 0 \\cdot1\\\\0 \\cdot 1 + (-1) \\cdot 1\\\\ \\end{bmatrix}=\n\\begin{bmatrix}0\\\\ -1\\\\ \\end{bmatrix}=\n -\\begin{bmatrix}0\\\\ 1\\\\ \\end{bmatrix}=\n-|1\\rangle\n$$</p>\n<p>In general applying the Z gate to a single qubit superposition state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$ gives</p>\n<p>$$\nZ|\\psi\\rangle =\n \\begin{bmatrix}1 &amp; 0 \\\\0 &amp; -1\\end{bmatrix}\n \\begin{bmatrix}\\alpha\\\\ \\beta\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1\\cdot\\alpha + 0\\cdot\\beta\\\\0\\cdot\\alpha + (-1)\\cdot\\beta\\\\ \\end{bmatrix}=\n \\begin{bmatrix}\\alpha\\\\ -\\beta\\\\ \\end{bmatrix}=\n \\alpha |0\\rangle -\\beta |1\\rangle\n$$</p>\n",
1247
+ "asMarkdown": "\nThe action of the Pauli Z gate is exactly what is required by this question.\nThis gate leaves the sign of the $|0\\rangle$ component of the superposition unchanged but flips the sign of the $|1\\rangle$ component of the superposition.\n\nAs a reminder, the Pauli Z gate is defined by the following matrix:\n\n$$\nZ =\n \\begin{bmatrix}1 & 0\\\\\\0 & -1 \\end{bmatrix}\n$$\n\nLet's see its effect on the only computational basis state that it changes, $|1\\rangle$:\n\n$$\nZ|1\\rangle =\n \\begin{bmatrix} 1 & 0\\\\\\0 & -1 \\end{bmatrix}\n \\begin{bmatrix}0\\\\\\ 1\\\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1 \\cdot 0 + 0 \\cdot1\\\\\\0 \\cdot 1 + (-1) \\cdot 1\\\\\\ \\end{bmatrix}=\n\\begin{bmatrix}0\\\\\\ -1\\\\\\ \\end{bmatrix}=\n -\\begin{bmatrix}0\\\\\\ 1\\\\\\ \\end{bmatrix}=\n-|1\\rangle\n$$\n\nIn general applying the Z gate to a single qubit superposition state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$ gives\n\n$$\nZ|\\psi\\rangle =\n \\begin{bmatrix}1 & 0 \\\\\\0 & -1\\end{bmatrix}\n \\begin{bmatrix}\\alpha\\\\\\ \\beta\\\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1\\cdot\\alpha + 0\\cdot\\beta\\\\\\0\\cdot\\alpha + (-1)\\cdot\\beta\\\\\\ \\end{bmatrix}=\n \\begin{bmatrix}\\alpha\\\\\\ -\\beta\\\\\\ \\end{bmatrix}=\n \\alpha |0\\rangle -\\beta |1\\rangle\n$$"
1248
1248
  },
1249
1249
  {
1250
1250
  "type": "solution",
1251
- "id": "single_qubit_gates__y_gate_solution",
1252
- "code": "namespace Kata {\n operation ApplyY(q : Qubit) : Unit is Adj + Ctl {\n Y(q); // As simple as this.\n }\n}"
1251
+ "id": "single_qubit_gates__sign_flip_solution",
1252
+ "code": "namespace Kata {\n operation SignFlip (q : Qubit) : Unit is Adj + Ctl {\n Z(q);\n }\n}"
1253
1253
  }
1254
1254
  ]
1255
1255
  }
1256
1256
  },
1257
1257
  {
1258
1258
  "type": "exercise",
1259
- "id": "single_qubit_gates__global_phase_i",
1260
- "title": "Applying a Global Phase",
1259
+ "id": "single_qubit_gates__y_gate",
1260
+ "title": "The Y Gate",
1261
1261
  "description": {
1262
1262
  "type": "text-content",
1263
- "asHtml": "<p><strong>Input:</strong> A qubit in an arbitrary state $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$.</p>\n<p><strong>Goal:</strong> Use several Pauli gates to change the qubit state to $i|\\psi\\rangle = i\\alpha|0\\rangle + i\\beta|1\\rangle$.</p>\n",
1264
- "asMarkdown": "**Input:** A qubit in an arbitrary state $|\\\\psi\\\\rangle = \\\\alpha|0\\\\rangle + \\\\beta|1\\\\rangle$.\n\n**Goal:** Use several Pauli gates to change the qubit state to $i|\\\\psi\\\\rangle = i\\\\alpha|0\\\\rangle + i\\\\beta|1\\\\rangle$."
1263
+ "asHtml": "<p><strong>Input:</strong> A qubit in an arbitrary state $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$.</p>\n<p><strong>Goal:</strong> Apply the Y gate to the qubit, i.e., transform the given state into $i\\alpha|1\\rangle - i\\beta|0\\rangle$.</p>\n",
1264
+ "asMarkdown": "**Input:** A qubit in an arbitrary state $|\\\\psi\\\\rangle = \\\\alpha|0\\\\rangle + \\\\beta|1\\\\rangle$.\n\n**Goal:** Apply the Y gate to the qubit, i.e., transform the given state into $i\\\\alpha|1\\\\rangle - i\\\\beta|0\\\\rangle$."
1265
1265
  },
1266
1266
  "sourceIds": [
1267
- "single_qubit_gates__global_phase_i__Verification.qs",
1267
+ "single_qubit_gates__y_gate__Verification.qs",
1268
1268
  "KatasLibrary.qs"
1269
1269
  ],
1270
- "placeholderCode": "namespace Kata {\n operation GlobalPhaseI(q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}",
1270
+ "placeholderCode": "namespace Kata {\n operation ApplyY(q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}",
1271
1271
  "explainedSolution": {
1272
1272
  "type": "explained-solution",
1273
1273
  "items": [
1274
1274
  {
1275
1275
  "type": "text-content",
1276
- "asHtml": "<p>We need to apply a gate which applies a global phase of $i$, i.e. $|\\psi\\rangle \\rightarrow i|\\psi\\rangle$.\nThe matrix representation of such a gate is $\\begin{bmatrix} i &amp; 0 \\\\ 0 &amp; i \\end{bmatrix} = i\\begin{bmatrix} 1 &amp; 0 \\\\ 0 &amp; 1 \\end{bmatrix} = iI$.\nSince we are restricted to the Pauli gates, we use the property that a product of any two distinct Pauli gates equals the third gate with a $+i$ or a $-i$ global phase, therefore the product of all three Pauli gates is $XYZ = iI$.\n$$\n\\begin{bmatrix} 0 &amp; 1 \\\\ 1 &amp; 0 \\end{bmatrix}\\begin{bmatrix} 0 &amp; -i \\\\ i &amp; 0 \\end{bmatrix}\\begin{bmatrix} 1 &amp; 0 \\\\ 0 &amp; -1 \\end{bmatrix} = \n\\begin{bmatrix} i &amp; 0 \\\\ 0 &amp; i \\end{bmatrix}\n$$</p>\n<blockquote>\n<p>Remember the rightmost gates in mathematical notation are applied first in Q# code. Hence we first apply the $Z$ gate, followed by the $Y$ gate, and finally the $X$ gate.</p>\n</blockquote>\n",
1277
- "asMarkdown": "\nWe need to apply a gate which applies a global phase of $i$, i.e. $|\\psi\\rangle \\rightarrow i|\\psi\\rangle$.\nThe matrix representation of such a gate is $\\begin{bmatrix} i & 0 \\\\\\ 0 & i \\end{bmatrix} = i\\begin{bmatrix} 1 & 0 \\\\\\ 0 & 1 \\end{bmatrix} = iI$.\nSince we are restricted to the Pauli gates, we use the property that a product of any two distinct Pauli gates equals the third gate with a $+i$ or a $-i$ global phase, therefore the product of all three Pauli gates is $XYZ = iI$.\n$$\n\\begin{bmatrix} 0 & 1 \\\\\\ 1 & 0 \\end{bmatrix}\\begin{bmatrix} 0 & -i \\\\\\ i & 0 \\end{bmatrix}\\begin{bmatrix} 1 & 0 \\\\\\ 0 & -1 \\end{bmatrix} = \n\\begin{bmatrix} i & 0 \\\\\\ 0 & i \\end{bmatrix}\n$$\n\n> Remember the rightmost gates in mathematical notation are applied first in Q# code. Hence we first apply the $Z$ gate, followed by the $Y$ gate, and finally the $X$ gate."
1276
+ "asHtml": "<p>We have to do exactly what the task asks us to do: apply the Pauli gate $Y=\\begin{bmatrix} 0 &amp; -i \\\\ i &amp; 0 \\end{bmatrix}$.</p>\n<p>This has the effect of turning $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$ into $Y|\\psi\\rangle = i\\alpha|1\\rangle - i\\beta|0\\rangle$, which in matrix form looks as follows:\n$$\n\\begin{bmatrix} 0 &amp; -i \\\\ i &amp; 0 \\end{bmatrix} \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} = \n\\begin{bmatrix} -i\\beta \\\\ i\\alpha \\end{bmatrix}\n$$</p>\n",
1277
+ "asMarkdown": "\nWe have to do exactly what the task asks us to do: apply the Pauli gate $Y=\\\\begin{bmatrix} 0 & -i \\\\\\\\ i & 0 \\\\end{bmatrix}$.\n\nThis has the effect of turning $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$ into $Y|\\psi\\rangle = i\\alpha|1\\rangle - i\\beta|0\\rangle$, which in matrix form looks as follows:\n$$\n\\begin{bmatrix} 0 & -i \\\\\\ i & 0 \\end{bmatrix} \\begin{bmatrix} \\alpha \\\\\\ \\beta \\end{bmatrix} = \n\\begin{bmatrix} -i\\beta \\\\\\ i\\alpha \\end{bmatrix}\n$$"
1278
1278
  },
1279
1279
  {
1280
1280
  "type": "solution",
1281
- "id": "single_qubit_gates__global_phase_i_solution",
1282
- "code": "namespace Kata {\n operation GlobalPhaseI(q : Qubit) : Unit is Adj + Ctl {\n Z(q);\n Y(q);\n X(q);\n }\n}"
1281
+ "id": "single_qubit_gates__y_gate_solution",
1282
+ "code": "namespace Kata {\n operation ApplyY(q : Qubit) : Unit is Adj + Ctl {\n Y(q); // As simple as this.\n }\n}"
1283
1283
  }
1284
1284
  ]
1285
1285
  }
@@ -1314,6 +1314,66 @@ export default {
1314
1314
  ]
1315
1315
  }
1316
1316
  },
1317
+ {
1318
+ "type": "exercise",
1319
+ "id": "single_qubit_gates__global_phase_minusone",
1320
+ "title": "Global Phase -1",
1321
+ "description": {
1322
+ "type": "text-content",
1323
+ "asHtml": "<p><strong>Input:</strong> A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.</p>\n<p><strong>Goal</strong>: Change the state of the qubit to $- \\beta |0\\rangle - \\gamma |1\\rangle$.</p>\n<blockquote>\n<p>This change on its own is not observable - there is no experiment you can do on a standalone qubit to figure out whether it acquired the global phase or not.\nHowever, you can use a controlled version of this operation to observe the global phase it introduces.\nThis is used in later katas as part of more complicated tasks.</p>\n</blockquote>\n",
1324
+ "asMarkdown": "**Input:** A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.\n\n**Goal**: Change the state of the qubit to $- \\beta |0\\rangle - \\gamma |1\\rangle$.\n\n> This change on its own is not observable - there is no experiment you can do on a standalone qubit to figure out whether it acquired the global phase or not.\n> However, you can use a controlled version of this operation to observe the global phase it introduces.\n> This is used in later katas as part of more complicated tasks.\n"
1325
+ },
1326
+ "sourceIds": [
1327
+ "single_qubit_gates__global_phase_minusone__Verification.qs",
1328
+ "KatasLibrary.qs"
1329
+ ],
1330
+ "placeholderCode": "namespace Kata {\n operation GlobalPhaseChange (q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n\n",
1331
+ "explainedSolution": {
1332
+ "type": "explained-solution",
1333
+ "items": [
1334
+ {
1335
+ "type": "text-content",
1336
+ "asHtml": "<p>A global phase is a phase factor that multiplies the entire quantum state. It is not observable when measuring the qubit&#39;s state, as the probabilities remain unchanged. However, it is significant when considering quantum state transformations.</p>\n<p>Our task is to implement an operation that transforms the given qubit state from $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$ to $- \\beta |0\\rangle - \\gamma |1\\rangle$.</p>\n<p>To do that, we utilize a sequence of gates. The Pauli Z gate followed by the Pauli X gate can be used to achieve this effect when applied in succession twice.</p>\n<ol>\n<li><p><strong>Apply the Pauli Z gate</strong>: The Z gate multiplies the $|1\\rangle$ state by $-1$ but does not change the $|0\\rangle$ state, converting our state $\\beta |0\\rangle + \\gamma |1\\rangle$ to $\\beta |0\\rangle - \\gamma |1\\rangle$.</p>\n<p>The matrix representation of the Z gate is:</p>\n<p>$$\nZ =\n\\begin{bmatrix}1 &amp; 0 \\\\ 0 &amp; -1 \\end{bmatrix}\n$$</p>\n</li>\n<li><p><strong>Apply the Pauli X gate</strong>: The X gate flips the $|0\\rangle$ and $|1\\rangle$ basis states, converting our $\\beta |0\\rangle - \\gamma |1\\rangle$ state to $\\beta |1\\rangle - \\gamma |0\\rangle$.</p>\n<p>The matrix representation of the X gate is:</p>\n<p>$$\nX =\n\\begin{bmatrix}0 &amp; 1 \\\\1 &amp; 0\\end{bmatrix}\n$$</p>\n</li>\n<li><p><strong>Repeat the Z and X gates</strong>: Applying the Z gate again will multiply the $|1\\rangle$ state (that used to be $|0\\rangle$), converting our state $\\beta |1\\rangle - \\gamma |0\\rangle$ to $- \\beta |1\\rangle - \\gamma |0\\rangle$. Finally, the second X gate will restore the original basis states, but now with both amplitudes having acquired an additional phase of $-1$. This means our state has been multiplied by $-1$, achieving the required global phase change.</p>\n</li>\n</ol>\n",
1337
+ "asMarkdown": "\nA global phase is a phase factor that multiplies the entire quantum state. It is not observable when measuring the qubit's state, as the probabilities remain unchanged. However, it is significant when considering quantum state transformations.\n\nOur task is to implement an operation that transforms the given qubit state from $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$ to $- \\beta |0\\rangle - \\gamma |1\\rangle$.\n\nTo do that, we utilize a sequence of gates. The Pauli Z gate followed by the Pauli X gate can be used to achieve this effect when applied in succession twice.\n\n1. **Apply the Pauli Z gate**: The Z gate multiplies the $|1\\rangle$ state by $-1$ but does not change the $|0\\rangle$ state, converting our state $\\beta |0\\rangle + \\gamma |1\\rangle$ to $\\beta |0\\rangle - \\gamma |1\\rangle$.\n\n The matrix representation of the Z gate is:\n\n $$\n Z =\n \\begin{bmatrix}1 & 0 \\\\\\ 0 & -1 \\end{bmatrix}\n $$\n\n2. **Apply the Pauli X gate**: The X gate flips the $|0\\rangle$ and $|1\\rangle$ basis states, converting our $\\beta |0\\rangle - \\gamma |1\\rangle$ state to $\\beta |1\\rangle - \\gamma |0\\rangle$.\n\n The matrix representation of the X gate is:\n\n $$\n X =\n \\begin{bmatrix}0 & 1 \\\\\\1 & 0\\end{bmatrix}\n $$\n\n3. **Repeat the Z and X gates**: Applying the Z gate again will multiply the $|1\\rangle$ state (that used to be $|0\\rangle$), converting our state $\\beta |1\\rangle - \\gamma |0\\rangle$ to $- \\beta |1\\rangle - \\gamma |0\\rangle$. Finally, the second X gate will restore the original basis states, but now with both amplitudes having acquired an additional phase of $-1$. This means our state has been multiplied by $-1$, achieving the required global phase change."
1338
+ },
1339
+ {
1340
+ "type": "solution",
1341
+ "id": "single_qubit_gates__global_phase_minusone_solution",
1342
+ "code": "namespace Kata {\n operation GlobalPhaseChange (q : Qubit) : Unit is Adj + Ctl {\n Z(q);\n X(q);\n Z(q);\n X(q);\n }\n}\n"
1343
+ }
1344
+ ]
1345
+ }
1346
+ },
1347
+ {
1348
+ "type": "exercise",
1349
+ "id": "single_qubit_gates__global_phase_i",
1350
+ "title": "Global Phase i",
1351
+ "description": {
1352
+ "type": "text-content",
1353
+ "asHtml": "<p><strong>Input:</strong> A qubit in an arbitrary state $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$.</p>\n<p><strong>Goal:</strong> Use several Pauli gates to change the qubit state to $i|\\psi\\rangle = i\\alpha|0\\rangle + i\\beta|1\\rangle$.</p>\n",
1354
+ "asMarkdown": "**Input:** A qubit in an arbitrary state $|\\\\psi\\\\rangle = \\\\alpha|0\\\\rangle + \\\\beta|1\\\\rangle$.\n\n**Goal:** Use several Pauli gates to change the qubit state to $i|\\\\psi\\\\rangle = i\\\\alpha|0\\\\rangle + i\\\\beta|1\\\\rangle$."
1355
+ },
1356
+ "sourceIds": [
1357
+ "single_qubit_gates__global_phase_i__Verification.qs",
1358
+ "KatasLibrary.qs"
1359
+ ],
1360
+ "placeholderCode": "namespace Kata {\n operation GlobalPhaseI(q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}",
1361
+ "explainedSolution": {
1362
+ "type": "explained-solution",
1363
+ "items": [
1364
+ {
1365
+ "type": "text-content",
1366
+ "asHtml": "<p>We need to apply a gate which applies a global phase of $i$, i.e. $|\\psi\\rangle \\rightarrow i|\\psi\\rangle$.\nThe matrix representation of such a gate is $\\begin{bmatrix} i &amp; 0 \\\\ 0 &amp; i \\end{bmatrix} = i\\begin{bmatrix} 1 &amp; 0 \\\\ 0 &amp; 1 \\end{bmatrix} = iI$.\nSince we are restricted to the Pauli gates, we use the property that a product of any two distinct Pauli gates equals the third gate with a $+i$ or a $-i$ global phase, therefore the product of all three Pauli gates is $XYZ = iI$.\n$$\n\\begin{bmatrix} 0 &amp; 1 \\\\ 1 &amp; 0 \\end{bmatrix}\\begin{bmatrix} 0 &amp; -i \\\\ i &amp; 0 \\end{bmatrix}\\begin{bmatrix} 1 &amp; 0 \\\\ 0 &amp; -1 \\end{bmatrix} = \n\\begin{bmatrix} i &amp; 0 \\\\ 0 &amp; i \\end{bmatrix}\n$$</p>\n<blockquote>\n<p>Remember the rightmost gates in mathematical notation are applied first in Q# code. Hence we first apply the $Z$ gate, followed by the $Y$ gate, and finally the $X$ gate.</p>\n</blockquote>\n",
1367
+ "asMarkdown": "\nWe need to apply a gate which applies a global phase of $i$, i.e. $|\\psi\\rangle \\rightarrow i|\\psi\\rangle$.\nThe matrix representation of such a gate is $\\begin{bmatrix} i & 0 \\\\\\ 0 & i \\end{bmatrix} = i\\begin{bmatrix} 1 & 0 \\\\\\ 0 & 1 \\end{bmatrix} = iI$.\nSince we are restricted to the Pauli gates, we use the property that a product of any two distinct Pauli gates equals the third gate with a $+i$ or a $-i$ global phase, therefore the product of all three Pauli gates is $XYZ = iI$.\n$$\n\\begin{bmatrix} 0 & 1 \\\\\\ 1 & 0 \\end{bmatrix}\\begin{bmatrix} 0 & -i \\\\\\ i & 0 \\end{bmatrix}\\begin{bmatrix} 1 & 0 \\\\\\ 0 & -1 \\end{bmatrix} = \n\\begin{bmatrix} i & 0 \\\\\\ 0 & i \\end{bmatrix}\n$$\n\n> Remember the rightmost gates in mathematical notation are applied first in Q# code. Hence we first apply the $Z$ gate, followed by the $Y$ gate, and finally the $X$ gate."
1368
+ },
1369
+ {
1370
+ "type": "solution",
1371
+ "id": "single_qubit_gates__global_phase_i_solution",
1372
+ "code": "namespace Kata {\n operation GlobalPhaseI(q : Qubit) : Unit is Adj + Ctl {\n Z(q);\n Y(q);\n X(q);\n }\n}"
1373
+ }
1374
+ ]
1375
+ }
1376
+ },
1317
1377
  {
1318
1378
  "type": "lesson",
1319
1379
  "id": "identity_gate",
@@ -1322,7 +1382,7 @@ export default {
1322
1382
  {
1323
1383
  "type": "text-content",
1324
1384
  "asHtml": "<p>The identity gate is mostly here for completeness, at least for now. It will come in handy when dealing with multi-qubit systems and multi-qubit gates. It is represented by the identity matrix, and does not affect the state of the qubit.</p>\n<table>\n<tr>\n<th>Gate</th>\n<th>Matrix</th>\n<th>Ket-Bra</th>\n<th>Applying to $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$</th>\n</tr>\n<tr>\n<td>$I$</td>\n<td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}$</td>\n<td>$|0\\rangle\\langle0| + |1\\rangle\\langle1|$</td>\n<td>$I|\\psi\\rangle = |\\psi\\rangle$</td>\n</tr>\n</table>",
1325
- "asMarkdown": "\nThe identity gate is mostly here for completeness, at least for now. It will come in handy when dealing with multi-qubit systems and multi-qubit gates. It is represented by the identity matrix, and does not affect the state of the qubit.\n \n<table>\n<tr>\n<th>Gate</th>\n<th>Matrix</th>\n<th>Ket-Bra</th>\n<th>Applying to $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$</th>\n</tr>\n<tr>\n<td>$I$</td>\n<td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}$</td>\n<td>$|0\\rangle\\langle0| + |1\\rangle\\langle1|$</td>\n<td>$I|\\psi\\rangle = |\\psi\\rangle$</td>\n</tr>\n</table>"
1385
+ "asMarkdown": "\nThe identity gate is mostly here for completeness, at least for now. It will come in handy when dealing with multi-qubit systems and multi-qubit gates. It is represented by the identity matrix, and does not affect the state of the qubit.\n\n<table>\n<tr>\n<th>Gate</th>\n<th>Matrix</th>\n<th>Ket-Bra</th>\n<th>Applying to $|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$</th>\n</tr>\n<tr>\n<td>$I$</td>\n<td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}$</td>\n<td>$|0\\rangle\\langle0| + |1\\rangle\\langle1|$</td>\n<td>$I|\\psi\\rangle = |\\psi\\rangle$</td>\n</tr>\n</table>"
1326
1386
  }
1327
1387
  ]
1328
1388
  },
@@ -1338,6 +1398,36 @@ export default {
1338
1398
  }
1339
1399
  ]
1340
1400
  },
1401
+ {
1402
+ "type": "exercise",
1403
+ "id": "single_qubit_gates__basis_change",
1404
+ "title": "Basis Change",
1405
+ "description": {
1406
+ "type": "text-content",
1407
+ "asHtml": "<p><strong>Input</strong>: A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.</p>\n<p><strong>Goal</strong>: Change the state of the qubit as follows:</p>\n<ul>\n<li>If the qubit is in state $|0\\rangle$, change its state to $|+\\rangle = \\frac{1}{\\sqrt{2}} \\big(|0\\rangle + |1\\rangle\\big)$.</li>\n<li>If the qubit is in state $|1\\rangle$, change its state to $|-\\rangle = \\frac{1}{\\sqrt{2}} \\big(|0\\rangle - |1\\rangle\\big)$.</li>\n<li>If the qubit is in superposition, change its state according to the effect on basis vectors.</li>\n</ul>\n",
1408
+ "asMarkdown": "**Input**: A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n\n**Goal**: Change the state of the qubit as follows:\n\n- If the qubit is in state $|0\\rangle$, change its state to $|+\\rangle = \\frac{1}{\\sqrt{2}} \\big(|0\\rangle + |1\\rangle\\big)$.\n- If the qubit is in state $|1\\rangle$, change its state to $|-\\rangle = \\frac{1}{\\sqrt{2}} \\big(|0\\rangle - |1\\rangle\\big)$.\n- If the qubit is in superposition, change its state according to the effect on basis vectors.\n"
1409
+ },
1410
+ "sourceIds": [
1411
+ "single_qubit_gates__basis_change__Verification.qs",
1412
+ "KatasLibrary.qs"
1413
+ ],
1414
+ "placeholderCode": "namespace Kata {\n operation BasisChange (q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n\n",
1415
+ "explainedSolution": {
1416
+ "type": "explained-solution",
1417
+ "items": [
1418
+ {
1419
+ "type": "text-content",
1420
+ "asHtml": "<p>We can recognize that the Hadamard gate changes states $|0\\rangle$ and $|1\\rangle$ to $|+\\rangle$ and $|-\\rangle$, respectively, and vice versa.</p>\n<p>As a reminder, the Hadamard gate is defined by the following matrix:</p>\n<p>$$\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1 &amp; 1 \\\\1 &amp; -1\\end{bmatrix}\n$$</p>\n<p>For example, we can work out $H|1\\rangle$ as follows:</p>\n<p>$$\nH|1\\rangle=\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 &amp; 1 \\\\1 &amp; -1\\end{bmatrix}\n\\begin{bmatrix} 0\\\\ 1\\end{bmatrix}=\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1 \\cdot 0 + 1 \\cdot 1 \\\\1 \\cdot 0 + (-1) \\cdot 1\\end{bmatrix}=\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1\\\\ -1\\\\ \\end{bmatrix}=\n\\frac{1}{\\sqrt{2}} \\big(|0\\rangle - |1\\rangle\\big) = |-\\rangle\n$$</p>\n<p>Similarly, we can consider the effect of the Hadamard gate on the superposition state $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle$ (rounding the numbers to 4 decimal places):</p>\n<p>$$\nH|\\psi⟩ =\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 &amp; 1 \\\\ 1 &amp; -1 \\end{bmatrix}\n \\begin{bmatrix} \\alpha\\\\ \\beta\\\\ \\end{bmatrix} =\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} \\alpha + \\beta\\\\ \\alpha - \\beta\\\\ \\end{bmatrix}=\n0.7071\\begin{bmatrix} 1.4\\\\ -0.2\\\\ \\end{bmatrix} =\n\\begin{bmatrix}\n 0.98994\\\\ -0.14142\\\\ \\end{bmatrix} =\n 0.9899|0\\rangle - 0.1414|1\\rangle\n$$</p>\n",
1421
+ "asMarkdown": "\nWe can recognize that the Hadamard gate changes states $|0\\rangle$ and $|1\\rangle$ to $|+\\rangle$ and $|-\\rangle$, respectively, and vice versa.\n\nAs a reminder, the Hadamard gate is defined by the following matrix:\n\n$$\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1 & 1 \\\\\\1 & -1\\end{bmatrix}\n$$\n\nFor example, we can work out $H|1\\rangle$ as follows:\n\n$$\nH|1\\rangle=\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 & 1 \\\\\\1 & -1\\end{bmatrix}\n\\begin{bmatrix} 0\\\\\\ 1\\end{bmatrix}=\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1 \\cdot 0 + 1 \\cdot 1 \\\\\\1 \\cdot 0 + (-1) \\cdot 1\\end{bmatrix}=\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix}1\\\\\\ -1\\\\\\ \\end{bmatrix}=\n\\frac{1}{\\sqrt{2}} \\big(|0\\rangle - |1\\rangle\\big) = |-\\rangle\n$$\n\nSimilarly, we can consider the effect of the Hadamard gate on the superposition state $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle$ (rounding the numbers to 4 decimal places):\n\n$$\nH|\\psi⟩ =\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 & 1 \\\\\\ 1 & -1 \\end{bmatrix}\n \\begin{bmatrix} \\alpha\\\\\\ \\beta\\\\\\ \\end{bmatrix} =\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} \\alpha + \\beta\\\\\\ \\alpha - \\beta\\\\\\ \\end{bmatrix}=\n0.7071\\begin{bmatrix} 1.4\\\\\\ -0.2\\\\\\ \\end{bmatrix} =\n\\begin{bmatrix}\n 0.98994\\\\\\ -0.14142\\\\\\ \\end{bmatrix} =\n 0.9899|0\\rangle - 0.1414|1\\rangle\n$$"
1422
+ },
1423
+ {
1424
+ "type": "solution",
1425
+ "id": "single_qubit_gates__basis_change_solution",
1426
+ "code": "namespace Kata {\n operation BasisChange (q : Qubit) : Unit is Adj + Ctl {\n H(q);\n }\n}"
1427
+ }
1428
+ ]
1429
+ }
1430
+ },
1341
1431
  {
1342
1432
  "type": "exercise",
1343
1433
  "id": "single_qubit_gates__prepare_minus",
@@ -1380,6 +1470,46 @@ export default {
1380
1470
  }
1381
1471
  ]
1382
1472
  },
1473
+ {
1474
+ "type": "exercise",
1475
+ "id": "single_qubit_gates__phase_i",
1476
+ "title": "Relative Phase i",
1477
+ "description": {
1478
+ "type": "text-content",
1479
+ "asHtml": "<p><strong>Input:</strong> A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.</p>\n<p><strong>Goal:</strong> Change the qubit state to $\\alpha |0\\rangle + {\\color{red}i}\\beta |1\\rangle$ (add a relative phase $i$ to $|1\\rangle$ component of the superposition).</p>\n",
1480
+ "asMarkdown": "**Input:** A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n\n**Goal:** Change the qubit state to $\\alpha |0\\rangle + {\\color{red}i}\\beta |1\\rangle$ (add a relative phase $i$ to $|1\\rangle$ component of the superposition).\n"
1481
+ },
1482
+ "sourceIds": [
1483
+ "single_qubit_gates__phase_i__Verification.qs",
1484
+ "KatasLibrary.qs"
1485
+ ],
1486
+ "placeholderCode": "namespace Kata {\n operation PhaseFlip (q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n\n",
1487
+ "explainedSolution": {
1488
+ "type": "explained-solution",
1489
+ "items": [
1490
+ {
1491
+ "type": "text-content",
1492
+ "asHtml": "<h4>Solution 1</h4>\n<p>We can recognize that the $S$ gate performs this particular relative phase addition to the $|1\\rangle$ basis state. As a reminder,</p>\n<p>$$\nS =\n\\begin{bmatrix}1 &amp; 0\\\\ 0 &amp; i\\end{bmatrix}\n$$</p>\n<p>Let&#39;s see the effect of this gate on the general superposition $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.</p>\n<p>$$\n \\begin{bmatrix}1 &amp; 0 \\\\ 0 &amp; i \\end{bmatrix}\n \\begin{bmatrix}\\alpha\\\\ \\beta\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1\\cdot\\alpha + 0\\cdot\\beta\\\\ 0\\cdot\\alpha + i\\cdot\\beta \\end{bmatrix}=\n \\begin{bmatrix}\\alpha\\\\ i\\beta\\\\ \\end{bmatrix}\n$$</p>\n<p>It is therefore easy to see that when $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle, S|\\psi\\rangle = 0.6|0\\rangle + 0.8i|1\\rangle$.</p>\n",
1493
+ "asMarkdown": "\n#### Solution 1\n\nWe can recognize that the $S$ gate performs this particular relative phase addition to the $|1\\rangle$ basis state. As a reminder,\n\n$$\nS =\n\\begin{bmatrix}1 & 0\\\\\\ 0 & i\\end{bmatrix}\n$$\n\nLet's see the effect of this gate on the general superposition $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n\n$$\n \\begin{bmatrix}1 & 0 \\\\\\ 0 & i \\end{bmatrix}\n \\begin{bmatrix}\\alpha\\\\\\ \\beta\\\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1\\cdot\\alpha + 0\\cdot\\beta\\\\\\ 0\\cdot\\alpha + i\\cdot\\beta \\end{bmatrix}=\n \\begin{bmatrix}\\alpha\\\\\\ i\\beta\\\\\\ \\end{bmatrix}\n$$\n\nIt is therefore easy to see that when $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle, S|\\psi\\rangle = 0.6|0\\rangle + 0.8i|1\\rangle$."
1494
+ },
1495
+ {
1496
+ "type": "solution",
1497
+ "id": "single_qubit_gates__phase_i_solution_a",
1498
+ "code": "namespace Kata {\n operation PhaseFlip (q : Qubit) : Unit is Adj + Ctl {\n S(q);\n }\n}"
1499
+ },
1500
+ {
1501
+ "type": "text-content",
1502
+ "asHtml": "<h4>Solution 2</h4>\n<p>Alternatively, see the Complex Relative Phase task later in the kata for an explanation of using $R1$ gate to implement the same transformation.</p>\n",
1503
+ "asMarkdown": "\n#### Solution 2\n\nAlternatively, see the Complex Relative Phase task later in the kata for an explanation of using $R1$ gate to implement the same transformation."
1504
+ },
1505
+ {
1506
+ "type": "solution",
1507
+ "id": "single_qubit_gates_phase_i_solution_b",
1508
+ "code": "namespace Kata {\n operation PhaseFlip (q : Qubit) : Unit is Adj + Ctl {\n open Microsoft.Quantum.Math;\n R1(0.5 * PI(), q);\n }\n}"
1509
+ }
1510
+ ]
1511
+ }
1512
+ },
1383
1513
  {
1384
1514
  "type": "exercise",
1385
1515
  "id": "single_qubit_gates__three_quarters_pi_phase",
@@ -1422,6 +1552,66 @@ export default {
1422
1552
  }
1423
1553
  ]
1424
1554
  },
1555
+ {
1556
+ "type": "exercise",
1557
+ "id": "single_qubit_gates__complex_phase",
1558
+ "title": "Complex Relative Phase",
1559
+ "description": {
1560
+ "type": "text-content",
1561
+ "asHtml": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>Angle $\\alpha$, in radians, represented as Double.</li>\n<li>A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.</li>\n</ol>\n<p><strong>Goal:</strong> Change the state of the qubit as follows:</p>\n<ul>\n<li>If the qubit is in state $|0\\rangle$, don&#39;t change its state.</li>\n<li>If the qubit is in state $|1\\rangle$, change its state to $e^{i\\alpha} |1\\rangle$.</li>\n<li>If the qubit is in superposition, change its state according to the effect on basis vectors: $\\beta |0\\rangle + {\\color{red}{e^{i\\alpha}}} \\gamma |1\\rangle$.</li>\n</ul>\n",
1562
+ "asMarkdown": "**Inputs:**\n\n1. Angle $\\alpha$, in radians, represented as Double.\n2. A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.\n\n**Goal:** Change the state of the qubit as follows:\n\n- If the qubit is in state $|0\\rangle$, don't change its state.\n- If the qubit is in state $|1\\rangle$, change its state to $e^{i\\alpha} |1\\rangle$.\n- If the qubit is in superposition, change its state according to the effect on basis vectors: $\\beta |0\\rangle + {\\color{red}{e^{i\\alpha}}} \\gamma |1\\rangle$.\n"
1563
+ },
1564
+ "sourceIds": [
1565
+ "single_qubit_gates__complex_phase__Verification.qs",
1566
+ "KatasLibrary.qs"
1567
+ ],
1568
+ "placeholderCode": "namespace Kata {\n operation PhaseChange (alpha : Double, q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n\n",
1569
+ "explainedSolution": {
1570
+ "type": "explained-solution",
1571
+ "items": [
1572
+ {
1573
+ "type": "text-content",
1574
+ "asHtml": "<p>We know that:</p>\n<p>$$\nR1(\\alpha)=\n \\begin{bmatrix}1 &amp; 0\\\\0 &amp; \\color{red}{e^{i\\alpha}}\\end{bmatrix}\n$$</p>\n<p>So we have:</p>\n<p>$$\nR1(\\beta |0\\rangle + \\gamma |1\\rangle) =\n \\begin{bmatrix}1 &amp; 0 \\\\0 &amp; \\color{red}{e^{i\\alpha}} \\end{bmatrix}\n \\begin{bmatrix}\\beta\\\\ \\gamma\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1 \\cdot \\beta + 0 \\cdot \\gamma\\\\ 0 \\cdot \\beta + {\\color{red}{e^{i\\alpha}}} \\cdot \\gamma\\end{bmatrix}=\n \\begin{bmatrix}\\beta\\\\ {\\color{red}{e^{i\\alpha}}}\\gamma\\end{bmatrix}=\n \\beta |0\\rangle + {\\color{red}{e^{i\\alpha}}} \\gamma |1\\rangle\n$$</p>\n<blockquote>\n<p>Suppose now that $\\alpha = \\frac{\\pi}{2}$.\nThen $e^{i\\alpha}= \\cos\\frac{\\pi}{2} + i\\sin\\frac{\\pi}{2}$.\nAnd, since $\\cos\\frac{\\pi}{2}= 0$ and $\\sin\\frac{\\pi}{2} = 1$, then we have that $\\cos\\frac{\\pi}{2} + i \\sin\\frac{\\pi}{2} = i$, and<br>$R1(\\frac{\\pi}{2}) = S$, which we used in the second solution to the task &quot;Relative Phase i&quot;.</p>\n</blockquote>\n",
1575
+ "asMarkdown": "\nWe know that:\n\n$$\nR1(\\alpha)=\n \\begin{bmatrix}1 & 0\\\\\\0 & \\color{red}{e^{i\\alpha}}\\end{bmatrix}\n$$\n\nSo we have:\n\n$$\nR1(\\beta |0\\rangle + \\gamma |1\\rangle) =\n \\begin{bmatrix}1 & 0 \\\\\\0 & \\color{red}{e^{i\\alpha}} \\end{bmatrix}\n \\begin{bmatrix}\\beta\\\\\\ \\gamma\\\\\\ \\end{bmatrix}=\n\\begin{bmatrix}1 \\cdot \\beta + 0 \\cdot \\gamma\\\\\\ 0 \\cdot \\beta + {\\color{red}{e^{i\\alpha}}} \\cdot \\gamma\\end{bmatrix}=\n \\begin{bmatrix}\\beta\\\\\\ {\\color{red}{e^{i\\alpha}}}\\gamma\\end{bmatrix}=\n \\beta |0\\rangle + {\\color{red}{e^{i\\alpha}}} \\gamma |1\\rangle\n$$\n\n> Suppose now that $\\alpha = \\frac{\\pi}{2}$.\n> Then $e^{i\\alpha}= \\cos\\frac{\\pi}{2} + i\\sin\\frac{\\pi}{2}$.\n> And, since $\\cos\\frac{\\pi}{2}= 0$ and $\\sin\\frac{\\pi}{2} = 1$, then we have that $\\cos\\frac{\\pi}{2} + i \\sin\\frac{\\pi}{2} = i$, and \n> $R1(\\frac{\\pi}{2}) = S$, which we used in the second solution to the task \"Relative Phase i\"."
1576
+ },
1577
+ {
1578
+ "type": "solution",
1579
+ "id": "single_qubit_gates__complex_phase_solution",
1580
+ "code": "namespace Kata {\n operation PhaseChange (alpha : Double, q : Qubit) : Unit is Adj + Ctl {\n R1(alpha, q); \n }\n}\n\n"
1581
+ }
1582
+ ]
1583
+ }
1584
+ },
1585
+ {
1586
+ "type": "exercise",
1587
+ "id": "single_qubit_gates__amplitude_change",
1588
+ "title": "Amplitude Change",
1589
+ "description": {
1590
+ "type": "text-content",
1591
+ "asHtml": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>Angle $\\alpha$, in radians, represented as Double.</li>\n<li>A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.</li>\n</ol>\n<p><strong>Goal:</strong> Change the state of the qubit as follows:</p>\n<ul>\n<li>If the qubit is in state $|0\\rangle$, change its state to $\\cos \\alpha |0\\rangle + \\sin \\alpha |1\\rangle$.</li>\n<li>If the qubit is in state $|1\\rangle$, change its state to $-\\sin \\alpha |0\\rangle + \\cos \\alpha |1\\rangle$.</li>\n<li>If the qubit is in superposition, change its state according to the effect on basis vectors.</li>\n</ul>\n",
1592
+ "asMarkdown": "**Inputs:**\n\n1. Angle $\\alpha$, in radians, represented as Double.\n2. A qubit in state $|\\psi\\rangle = \\beta |0\\rangle + \\gamma |1\\rangle$.\n\n**Goal:** Change the state of the qubit as follows:\n\n- If the qubit is in state $|0\\rangle$, change its state to $\\cos \\alpha |0\\rangle + \\sin \\alpha |1\\rangle$.\n- If the qubit is in state $|1\\rangle$, change its state to $-\\sin \\alpha |0\\rangle + \\cos \\alpha |1\\rangle$.\n- If the qubit is in superposition, change its state according to the effect on basis vectors.\n"
1593
+ },
1594
+ "sourceIds": [
1595
+ "single_qubit_gates__amplitude_change__Verification.qs",
1596
+ "KatasLibrary.qs"
1597
+ ],
1598
+ "placeholderCode": "namespace Kata {\n operation AmplitudeChange (alpha : Double, q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n\n",
1599
+ "explainedSolution": {
1600
+ "type": "explained-solution",
1601
+ "items": [
1602
+ {
1603
+ "type": "text-content",
1604
+ "asHtml": "<p>We can recognize that we need to use one of the rotation gates Rx, Ry, and Rz (named because they &quot;rotate&quot; the qubit state in the three dimensional space visualized as the Bloch sphere about the x, y, and z axes, respectively), since they involve angle parameters. Of these three gates, only Ry rotates the basis states $|0\\rangle$ and $|1\\rangle$ to have real amplitudes (the other two gates introduce complex coefficients).</p>\n<p>As a reminder,</p>\n<p>$$\nR_{y}(\\theta) =\n\\begin{bmatrix}\\cos \\frac{\\theta}{2} &amp; -\\sin \\frac{\\theta}{2}\\\\ \\sin \\frac{\\theta}{2} &amp; \\cos \\frac{\\theta}{2}\\end{bmatrix}\n$$</p>\n<p>Let&#39;s see its effect on the $|0\\rangle$ state:</p>\n<p>$$\nR_y(\\theta)|0\\rangle =\n\\begin{bmatrix}\\cos \\frac{\\theta}{2} &amp; -\\sin \\frac{\\theta}{2}\\\\ \\sin \\frac{\\theta}{2} &amp; \\cos \\frac{\\theta}{2} \\end{bmatrix}\n\\begin{bmatrix}1\\\\ 0\\\\ \\end{bmatrix}=\n\\begin{bmatrix}\\cos \\frac{\\theta}{2}\\cdot1 - \\sin \\frac{\\theta}{2}\\cdot0\\\\ \\sin \\frac{\\theta}{2}\\cdot1 + \\cos \\frac{\\theta}{2}\\cdot0\n\\end{bmatrix}=\n\\begin{bmatrix}\\cos \\frac{\\theta}{2}\\\\ \\sin \\frac{\\theta}{2}\\end{bmatrix}=\n\\cos\\frac{\\theta}{2} |0\\rangle + \\sin\\frac{\\theta}{2} |1\\rangle\n$$</p>\n<p>Recall that when applying a gate, you can tell what its matrix does to the basis states by looking at its columns: the first column of the matrix is the state into which it will transform the $|0\\rangle$ state, and the second column is the state into which it will transform the $|1\\rangle$ state.\nOne of the examples used by the testing harness has $\\beta = 0.6, \\gamma = 0.8$ and $\\alpha = 1.0471975511965976 = \\frac{\\pi}{3}$.\nSince $\\cos \\frac{\\pi}{3} = 0.5$ and $\\sin \\frac{\\pi}{3} = 0.8660$, working to 4 decimal places, we can use $\\frac{\\theta}{2} = \\alpha$ to compute:</p>\n<p>$$\nR_{y}(\\theta) |\\psi\\rangle=\n \\begin{bmatrix}\\cos \\frac{\\theta}{2} &amp; -\\sin \\frac{\\theta}{2}\\\\ \\sin \\frac{\\theta}{2} &amp; \\cos \\frac{\\theta}{2} \\end{bmatrix}\n \\begin{bmatrix}\\beta\\\\ \\gamma\\\\ \\end{bmatrix}=\n \\begin{bmatrix}\\cos \\frac{\\theta}{2}\\cdot\\beta - \\sin \\frac{\\theta}{2}\\cdot\\gamma\\\\ \\sin \\frac{\\theta}{2}\\cdot\\beta +\\cos \\frac{\\theta}{2}\\cdot\\gamma \\end{bmatrix}=\n \\begin{bmatrix} 0.6\\cdot\\cos \\frac{\\pi}{3} -0.8\\cdot\\sin \\frac{\\pi}{3}\\\\0.6\\cdot\\sin \\frac{\\pi}{3} +0.8\\cdot\\cos \\frac{\\pi}{3}\\end{bmatrix}=\n \\begin{bmatrix}0.3 - 0.6928\\\\ 0.5196 + 0.4\\end{bmatrix}=\n\\begin{bmatrix}-0.3928\\\\ 0.9196\\\\ \\end{bmatrix}\n$$</p>\n<p>Notice that we used $\\frac{\\theta}{2} = \\alpha$; this means that in the Q# code we need to pass the angle $\\theta = 2\\alpha$.</p>\n",
1605
+ "asMarkdown": "\nWe can recognize that we need to use one of the rotation gates Rx, Ry, and Rz (named because they \"rotate\" the qubit state in the three dimensional space visualized as the Bloch sphere about the x, y, and z axes, respectively), since they involve angle parameters. Of these three gates, only Ry rotates the basis states $|0\\rangle$ and $|1\\rangle$ to have real amplitudes (the other two gates introduce complex coefficients).\n\nAs a reminder,\n\n$$\nR_{y}(\\theta) =\n\\begin{bmatrix}\\cos \\frac{\\theta}{2} & -\\sin \\frac{\\theta}{2}\\\\\\ \\sin \\frac{\\theta}{2} & \\cos \\frac{\\theta}{2}\\end{bmatrix}\n$$\n\nLet's see its effect on the $|0\\rangle$ state:\n\n$$\nR_y(\\theta)|0\\rangle =\n\\begin{bmatrix}\\cos \\frac{\\theta}{2} & -\\sin \\frac{\\theta}{2}\\\\\\ \\sin \\frac{\\theta}{2} & \\cos \\frac{\\theta}{2} \\end{bmatrix}\n\\begin{bmatrix}1\\\\\\ 0\\\\\\ \\end{bmatrix}=\n\\begin{bmatrix}\\cos \\frac{\\theta}{2}\\cdot1 - \\sin \\frac{\\theta}{2}\\cdot0\\\\\\ \\sin \\frac{\\theta}{2}\\cdot1 + \\cos \\frac{\\theta}{2}\\cdot0\n\\end{bmatrix}=\n\\begin{bmatrix}\\cos \\frac{\\theta}{2}\\\\\\ \\sin \\frac{\\theta}{2}\\end{bmatrix}=\n\\cos\\frac{\\theta}{2} |0\\rangle + \\sin\\frac{\\theta}{2} |1\\rangle\n$$\n\nRecall that when applying a gate, you can tell what its matrix does to the basis states by looking at its columns: the first column of the matrix is the state into which it will transform the $|0\\rangle$ state, and the second column is the state into which it will transform the $|1\\rangle$ state.\nOne of the examples used by the testing harness has $\\beta = 0.6, \\gamma = 0.8$ and $\\alpha = 1.0471975511965976 = \\frac{\\pi}{3}$.\nSince $\\cos \\frac{\\pi}{3} = 0.5$ and $\\sin \\frac{\\pi}{3} = 0.8660$, working to 4 decimal places, we can use $\\frac{\\theta}{2} = \\alpha$ to compute:\n\n$$\nR_{y}(\\theta) |\\psi\\rangle=\n \\begin{bmatrix}\\cos \\frac{\\theta}{2} & -\\sin \\frac{\\theta}{2}\\\\\\ \\sin \\frac{\\theta}{2} & \\cos \\frac{\\theta}{2} \\end{bmatrix}\n \\begin{bmatrix}\\beta\\\\\\ \\gamma\\\\\\ \\end{bmatrix}=\n \\begin{bmatrix}\\cos \\frac{\\theta}{2}\\cdot\\beta - \\sin \\frac{\\theta}{2}\\cdot\\gamma\\\\\\ \\sin \\frac{\\theta}{2}\\cdot\\beta +\\cos \\frac{\\theta}{2}\\cdot\\gamma \\end{bmatrix}=\n \\begin{bmatrix} 0.6\\cdot\\cos \\frac{\\pi}{3} -0.8\\cdot\\sin \\frac{\\pi}{3}\\\\\\0.6\\cdot\\sin \\frac{\\pi}{3} +0.8\\cdot\\cos \\frac{\\pi}{3}\\end{bmatrix}=\n \\begin{bmatrix}0.3 - 0.6928\\\\\\ 0.5196 + 0.4\\end{bmatrix}=\n\\begin{bmatrix}-0.3928\\\\\\ 0.9196\\\\\\ \\end{bmatrix}\n$$\n\nNotice that we used $\\frac{\\theta}{2} = \\alpha$; this means that in the Q# code we need to pass the angle $\\theta = 2\\alpha$."
1606
+ },
1607
+ {
1608
+ "type": "solution",
1609
+ "id": "single_qubit_gates__amplitude_change_solution",
1610
+ "code": "namespace Kata {\n operation AmplitudeChange (alpha : Double, q : Qubit) : Unit is Adj + Ctl {\n Ry(2.0 * alpha, q);\n }\n}"
1611
+ }
1612
+ ]
1613
+ }
1614
+ },
1425
1615
  {
1426
1616
  "type": "exercise",
1427
1617
  "id": "single_qubit_gates__prepare_rotated_state",
@@ -1555,8 +1745,8 @@ export default {
1555
1745
  "items": [
1556
1746
  {
1557
1747
  "type": "text-content",
1558
- "asHtml": "<p>Just like with single qubits, Dirac notation provides a useful shorthand for writing down states of multi-qubit systems.</p>\n<p>As we&#39;ve seen earlier, multi-qubit systems have their own canonical bases, and the basis states can be represented as tensor products of single-qubit basis states. Any multi-qubit system can be represented as a linear combination of these basis states:</p>\n<p>$$\n\\begin{bmatrix} x_0 \\\\ x_1 \\\\ x_2 \\\\ x_3 \\end{bmatrix} =\nx_0\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} +\nx_1\\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} +\nx_2\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} +\nx_3\\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} =\nx_0|0\\rangle \\otimes |0\\rangle +\nx_1|0\\rangle \\otimes |1\\rangle +\nx_2|1\\rangle \\otimes |0\\rangle +\nx_3|1\\rangle \\otimes |1\\rangle\n$$</p>\n<p>To simplify this, tensor products of basis states have their own notation:</p>\n<p>$$|0\\rangle \\otimes |0\\rangle = |00\\rangle$$\n$$|0\\rangle \\otimes |1\\rangle = |01\\rangle$$\n$$|1\\rangle \\otimes |0\\rangle = |10\\rangle$$\n$$|1\\rangle \\otimes |1\\rangle = |11\\rangle$$</p>\n<p>$$|0\\rangle \\otimes |0\\rangle \\otimes |0\\rangle = |000\\rangle$$</p>\n<p>And so on.</p>\n<p>Or, more generally:</p>\n<p>$$|i_0\\rangle \\otimes |i_1\\rangle \\otimes \\dotsb \\otimes |i_n\\rangle = |i_0i_1...i_n\\rangle$$</p>\n<p>Using this notation simplifies our example:</p>\n<p>$$\n\\begin{bmatrix} x_0 \\\\ x_1 \\\\ x_2 \\\\ x_3 \\end{bmatrix} =\nx_0|00\\rangle + x_1|01\\rangle + x_2|10\\rangle + x_3|11\\rangle\n$$</p>\n<p>Just like with single qubits, we can put arbitrary symbols within the kets the same way variables are used in algebra.\nWhether a ket represents a single qubit or an entire system depends on the context.\nSome ket symbols have a commonly accepted usage, such as the symbols for the Bell basis:</p>\n<p>$$|\\phi^+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|00\\rangle + |11\\rangle\\big)$$\n$$|\\phi^-\\rangle = \\frac{1}{\\sqrt{2}}\\big(|00\\rangle - |11\\rangle\\big)$$\n$$|\\psi^+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|01\\rangle + |10\\rangle\\big)$$\n$$|\\psi^-\\rangle = \\frac{1}{\\sqrt{2}}\\big(|01\\rangle - |10\\rangle\\big)$$</p>\n<blockquote>\n<h2>Endianness</h2>\n<p>In classical computing, endianness refers to the order of bits (or bytes) when representing numbers in binary. You&#39;re probably familiar with the typical way of writing numbers in binary: $0 = 0_2$, $1 = 1_2$, $2 = 10_2$, $3 = 11_2$, $4 = 100_2$, $5 = 101_2$, $6 = 110_2$, etc. This is known as <strong>big-endian format</strong>. In big-endian format, the <em>most significant</em> bits come first. For example: $110_2 = 1 \\cdot 4 + 1 \\cdot 2 + 0 \\cdot 1 = 4 + 2 = 6$.</p>\n<p>There is an alternate way of writing binary numbers - <strong>little-endian format</strong>. In little-endian format, the <em>least significant</em> bits come first. For example, $2$ would be written as $01$, $4$ as $001$, and $6$ as $011$. To put it another way, in little endian format, the number is written backwards compared to the big-endian format.</p>\n<p>In Dirac notation for multi-qubit systems, it&#39;s common to see integer numbers within the kets instead of bit sequences. What those numbers mean depends on the context - whether the notation used is big-endian or little-endian.</p>\n<p>Examples with a 3 qubit system:</p>\n<table>\n <tr>\n <th>Integer Ket</th>\n <td>$|0\\rangle$</td>\n <td>$|1\\rangle$</td>\n <td>$|2\\rangle$</td>\n <td>$|3\\rangle$</td>\n <td>$|4\\rangle$</td>\n <td>$|5\\rangle$</td>\n <td>$|6\\rangle$</td>\n <td>$|7\\rangle$</td>\n </tr>\n <tr>\n <th>Big-endian</th>\n <td>$|000\\rangle$</td>\n <td>$|001\\rangle$</td>\n <td>$|010\\rangle$</td>\n <td>$|011\\rangle$</td>\n <td>$|100\\rangle$</td>\n <td>$|101\\rangle$</td>\n <td>$|110\\rangle$</td>\n <td>$|111\\rangle$</td>\n </tr>\n <tr>\n <th>Little-endian</th>\n <td>$|000\\rangle$</td>\n <td>$|100\\rangle$</td>\n <td>$|010\\rangle$</td>\n <td>$|110\\rangle$</td>\n <td>$|001\\rangle$</td>\n <td>$|101\\rangle$</td>\n <td>$|011\\rangle$</td>\n <td>$|111\\rangle$</td>\n </tr>\n</table>\n\n<p>Multi-qubit quantum systems that store superpositions of numbers are often referred to as <strong>quantum registers</strong>.</p>\n</blockquote>\n",
1559
- "asMarkdown": "\nJust like with single qubits, Dirac notation provides a useful shorthand for writing down states of multi-qubit systems.\n\nAs we've seen earlier, multi-qubit systems have their own canonical bases, and the basis states can be represented as tensor products of single-qubit basis states. Any multi-qubit system can be represented as a linear combination of these basis states:\n\n$$\n\\begin{bmatrix} x_0 \\\\\\ x_1 \\\\\\ x_2 \\\\\\ x_3 \\end{bmatrix} =\nx_0\\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix} +\nx_1\\begin{bmatrix} 0 \\\\\\ 1 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix} +\nx_2\\begin{bmatrix} 0 \\\\\\ 0 \\\\\\ 1 \\\\\\ 0 \\end{bmatrix} +\nx_3\\begin{bmatrix} 0 \\\\\\ 0 \\\\\\ 0 \\\\\\ 1 \\end{bmatrix} =\nx_0|0\\rangle \\otimes |0\\rangle +\nx_1|0\\rangle \\otimes |1\\rangle +\nx_2|1\\rangle \\otimes |0\\rangle +\nx_3|1\\rangle \\otimes |1\\rangle\n$$\n\nTo simplify this, tensor products of basis states have their own notation:\n\n$$|0\\rangle \\otimes |0\\rangle = |00\\rangle$$\n$$|0\\rangle \\otimes |1\\rangle = |01\\rangle$$\n$$|1\\rangle \\otimes |0\\rangle = |10\\rangle$$\n$$|1\\rangle \\otimes |1\\rangle = |11\\rangle$$\n\n$$|0\\rangle \\otimes |0\\rangle \\otimes |0\\rangle = |000\\rangle$$\n\nAnd so on.\n\nOr, more generally:\n\n$$|i_0\\rangle \\otimes |i_1\\rangle \\otimes \\dotsb \\otimes |i_n\\rangle = |i_0i_1...i_n\\rangle$$\n\nUsing this notation simplifies our example:\n\n$$\n\\begin{bmatrix} x_0 \\\\\\ x_1 \\\\\\ x_2 \\\\\\ x_3 \\end{bmatrix} =\nx_0|00\\rangle + x_1|01\\rangle + x_2|10\\rangle + x_3|11\\rangle\n$$\n\nJust like with single qubits, we can put arbitrary symbols within the kets the same way variables are used in algebra.\nWhether a ket represents a single qubit or an entire system depends on the context.\nSome ket symbols have a commonly accepted usage, such as the symbols for the Bell basis:\n\n$$|\\phi^+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|00\\rangle + |11\\rangle\\big)$$\n$$|\\phi^-\\rangle = \\frac{1}{\\sqrt{2}}\\big(|00\\rangle - |11\\rangle\\big)$$\n$$|\\psi^+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|01\\rangle + |10\\rangle\\big)$$\n$$|\\psi^-\\rangle = \\frac{1}{\\sqrt{2}}\\big(|01\\rangle - |10\\rangle\\big)$$\n\n>## Endianness\n>\n> In classical computing, endianness refers to the order of bits (or bytes) when representing numbers in binary. You're probably familiar with the typical way of writing numbers in binary: $0 = 0_2$, $1 = 1_2$, $2 = 10_2$, $3 = 11_2$, $4 = 100_2$, $5 = 101_2$, $6 = 110_2$, etc. This is known as **big-endian format**. In big-endian format, the *most significant* bits come first. For example: $110_2 = 1 \\cdot 4 + 1 \\cdot 2 + 0 \\cdot 1 = 4 + 2 = 6$.\n>\n> There is an alternate way of writing binary numbers - **little-endian format**. In little-endian format, the *least significant* bits come first. For example, $2$ would be written as $01$, $4$ as $001$, and $6$ as $011$. To put it another way, in little endian format, the number is written backwards compared to the big-endian format.\n>\n> In Dirac notation for multi-qubit systems, it's common to see integer numbers within the kets instead of bit sequences. What those numbers mean depends on the context - whether the notation used is big-endian or little-endian.\n>\n> Examples with a 3 qubit system:\n>\n> <table>\n> <tr>\n> <th>Integer Ket</th>\n> <td>$|0\\rangle$</td>\n> <td>$|1\\rangle$</td>\n> <td>$|2\\rangle$</td>\n> <td>$|3\\rangle$</td>\n> <td>$|4\\rangle$</td>\n> <td>$|5\\rangle$</td>\n> <td>$|6\\rangle$</td>\n> <td>$|7\\rangle$</td>\n> </tr>\n> <tr>\n> <th>Big-endian</th>\n> <td>$|000\\rangle$</td>\n> <td>$|001\\rangle$</td>\n> <td>$|010\\rangle$</td>\n> <td>$|011\\rangle$</td>\n> <td>$|100\\rangle$</td>\n> <td>$|101\\rangle$</td>\n> <td>$|110\\rangle$</td>\n> <td>$|111\\rangle$</td>\n> </tr>\n> <tr>\n> <th>Little-endian</th>\n> <td>$|000\\rangle$</td>\n> <td>$|100\\rangle$</td>\n> <td>$|010\\rangle$</td>\n> <td>$|110\\rangle$</td>\n> <td>$|001\\rangle$</td>\n> <td>$|101\\rangle$</td>\n> <td>$|011\\rangle$</td>\n> <td>$|111\\rangle$</td>\n> </tr>\n></table>\n>\n> Multi-qubit quantum systems that store superpositions of numbers are often referred to as **quantum registers**."
1748
+ "asHtml": "<p>Just like with single qubits, Dirac notation provides a useful shorthand for writing down states of multi-qubit systems.</p>\n<p>As we&#39;ve seen earlier, multi-qubit systems have their own canonical bases, and the basis states can be represented as tensor products of single-qubit basis states. Any multi-qubit system can be represented as a linear combination of these basis states:</p>\n<p>$$\n\\begin{bmatrix} x_0 \\\\ x_1 \\\\ x_2 \\\\ x_3 \\end{bmatrix} =\nx_0\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} +\nx_1\\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} +\nx_2\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} +\nx_3\\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} =\nx_0|0\\rangle \\otimes |0\\rangle +\nx_1|0\\rangle \\otimes |1\\rangle +\nx_2|1\\rangle \\otimes |0\\rangle +\nx_3|1\\rangle \\otimes |1\\rangle\n$$</p>\n<p>To simplify this, tensor products of basis states have their own notation:</p>\n<p>$$|0\\rangle \\otimes |0\\rangle = |00\\rangle$$\n$$|0\\rangle \\otimes |1\\rangle = |01\\rangle$$\n$$|1\\rangle \\otimes |0\\rangle = |10\\rangle$$\n$$|1\\rangle \\otimes |1\\rangle = |11\\rangle$$</p>\n<p>$$|0\\rangle \\otimes |0\\rangle \\otimes |0\\rangle = |000\\rangle$$</p>\n<p>And so on.</p>\n<p>Or, more generally:</p>\n<p>$$|i_0\\rangle \\otimes |i_1\\rangle \\otimes \\dotsb \\otimes |i_n\\rangle = |i_0i_1...i_n\\rangle$$</p>\n<p>Using this notation simplifies our example:</p>\n<p>$$\n\\begin{bmatrix} x_0 \\\\ x_1 \\\\ x_2 \\\\ x_3 \\end{bmatrix} =\nx_0|00\\rangle + x_1|01\\rangle + x_2|10\\rangle + x_3|11\\rangle\n$$</p>\n<p>Just like with single qubits, we can put arbitrary symbols within the kets the same way variables are used in algebra.\nWhether a ket represents a single qubit or an entire system depends on the context.\nSome ket symbols have a commonly accepted usage, such as the symbols for the Bell basis:</p>\n<p>$$|\\Phi^+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|00\\rangle + |11\\rangle\\big)$$\n$$|\\Phi^-\\rangle = \\frac{1}{\\sqrt{2}}\\big(|00\\rangle - |11\\rangle\\big)$$\n$$|\\Psi^+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|01\\rangle + |10\\rangle\\big)$$\n$$|\\Psi^-\\rangle = \\frac{1}{\\sqrt{2}}\\big(|01\\rangle - |10\\rangle\\big)$$</p>\n<blockquote>\n<h2>Endianness</h2>\n<p>In classical computing, endianness refers to the order of bits (or bytes) when representing numbers in binary. You&#39;re probably familiar with the typical way of writing numbers in binary: $0 = 0_2$, $1 = 1_2$, $2 = 10_2$, $3 = 11_2$, $4 = 100_2$, $5 = 101_2$, $6 = 110_2$, etc. This is known as <strong>big-endian format</strong>. In big-endian format, the <em>most significant</em> bits come first. For example: $110_2 = 1 \\cdot 4 + 1 \\cdot 2 + 0 \\cdot 1 = 4 + 2 = 6$.</p>\n<p>There is an alternate way of writing binary numbers - <strong>little-endian format</strong>. In little-endian format, the <em>least significant</em> bits come first. For example, $2$ would be written as $01$, $4$ as $001$, and $6$ as $011$. To put it another way, in little endian format, the number is written backwards compared to the big-endian format.</p>\n<p>In Dirac notation for multi-qubit systems, it&#39;s common to see integer numbers within the kets instead of bit sequences. What those numbers mean depends on the context - whether the notation used is big-endian or little-endian.</p>\n<p>Examples with a 3 qubit system:</p>\n<table>\n <tr>\n <th>Integer Ket</th>\n <td>$|0\\rangle$</td>\n <td>$|1\\rangle$</td>\n <td>$|2\\rangle$</td>\n <td>$|3\\rangle$</td>\n <td>$|4\\rangle$</td>\n <td>$|5\\rangle$</td>\n <td>$|6\\rangle$</td>\n <td>$|7\\rangle$</td>\n </tr>\n <tr>\n <th>Big-endian</th>\n <td>$|000\\rangle$</td>\n <td>$|001\\rangle$</td>\n <td>$|010\\rangle$</td>\n <td>$|011\\rangle$</td>\n <td>$|100\\rangle$</td>\n <td>$|101\\rangle$</td>\n <td>$|110\\rangle$</td>\n <td>$|111\\rangle$</td>\n </tr>\n <tr>\n <th>Little-endian</th>\n <td>$|000\\rangle$</td>\n <td>$|100\\rangle$</td>\n <td>$|010\\rangle$</td>\n <td>$|110\\rangle$</td>\n <td>$|001\\rangle$</td>\n <td>$|101\\rangle$</td>\n <td>$|011\\rangle$</td>\n <td>$|111\\rangle$</td>\n </tr>\n</table>\n\n<p>Multi-qubit quantum systems that store superpositions of numbers are often referred to as <strong>quantum registers</strong>.</p>\n</blockquote>\n",
1749
+ "asMarkdown": "\nJust like with single qubits, Dirac notation provides a useful shorthand for writing down states of multi-qubit systems.\n\nAs we've seen earlier, multi-qubit systems have their own canonical bases, and the basis states can be represented as tensor products of single-qubit basis states. Any multi-qubit system can be represented as a linear combination of these basis states:\n\n$$\n\\begin{bmatrix} x_0 \\\\\\ x_1 \\\\\\ x_2 \\\\\\ x_3 \\end{bmatrix} =\nx_0\\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix} +\nx_1\\begin{bmatrix} 0 \\\\\\ 1 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix} +\nx_2\\begin{bmatrix} 0 \\\\\\ 0 \\\\\\ 1 \\\\\\ 0 \\end{bmatrix} +\nx_3\\begin{bmatrix} 0 \\\\\\ 0 \\\\\\ 0 \\\\\\ 1 \\end{bmatrix} =\nx_0|0\\rangle \\otimes |0\\rangle +\nx_1|0\\rangle \\otimes |1\\rangle +\nx_2|1\\rangle \\otimes |0\\rangle +\nx_3|1\\rangle \\otimes |1\\rangle\n$$\n\nTo simplify this, tensor products of basis states have their own notation:\n\n$$|0\\rangle \\otimes |0\\rangle = |00\\rangle$$\n$$|0\\rangle \\otimes |1\\rangle = |01\\rangle$$\n$$|1\\rangle \\otimes |0\\rangle = |10\\rangle$$\n$$|1\\rangle \\otimes |1\\rangle = |11\\rangle$$\n\n$$|0\\rangle \\otimes |0\\rangle \\otimes |0\\rangle = |000\\rangle$$\n\nAnd so on.\n\nOr, more generally:\n\n$$|i_0\\rangle \\otimes |i_1\\rangle \\otimes \\dotsb \\otimes |i_n\\rangle = |i_0i_1...i_n\\rangle$$\n\nUsing this notation simplifies our example:\n\n$$\n\\begin{bmatrix} x_0 \\\\\\ x_1 \\\\\\ x_2 \\\\\\ x_3 \\end{bmatrix} =\nx_0|00\\rangle + x_1|01\\rangle + x_2|10\\rangle + x_3|11\\rangle\n$$\n\nJust like with single qubits, we can put arbitrary symbols within the kets the same way variables are used in algebra.\nWhether a ket represents a single qubit or an entire system depends on the context.\nSome ket symbols have a commonly accepted usage, such as the symbols for the Bell basis:\n\n$$|\\Phi^+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|00\\rangle + |11\\rangle\\big)$$\n$$|\\Phi^-\\rangle = \\frac{1}{\\sqrt{2}}\\big(|00\\rangle - |11\\rangle\\big)$$\n$$|\\Psi^+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|01\\rangle + |10\\rangle\\big)$$\n$$|\\Psi^-\\rangle = \\frac{1}{\\sqrt{2}}\\big(|01\\rangle - |10\\rangle\\big)$$\n\n>## Endianness\n>\n> In classical computing, endianness refers to the order of bits (or bytes) when representing numbers in binary. You're probably familiar with the typical way of writing numbers in binary: $0 = 0_2$, $1 = 1_2$, $2 = 10_2$, $3 = 11_2$, $4 = 100_2$, $5 = 101_2$, $6 = 110_2$, etc. This is known as **big-endian format**. In big-endian format, the *most significant* bits come first. For example: $110_2 = 1 \\cdot 4 + 1 \\cdot 2 + 0 \\cdot 1 = 4 + 2 = 6$.\n>\n> There is an alternate way of writing binary numbers - **little-endian format**. In little-endian format, the *least significant* bits come first. For example, $2$ would be written as $01$, $4$ as $001$, and $6$ as $011$. To put it another way, in little endian format, the number is written backwards compared to the big-endian format.\n>\n> In Dirac notation for multi-qubit systems, it's common to see integer numbers within the kets instead of bit sequences. What those numbers mean depends on the context - whether the notation used is big-endian or little-endian.\n>\n> Examples with a 3 qubit system:\n>\n> <table>\n> <tr>\n> <th>Integer Ket</th>\n> <td>$|0\\rangle$</td>\n> <td>$|1\\rangle$</td>\n> <td>$|2\\rangle$</td>\n> <td>$|3\\rangle$</td>\n> <td>$|4\\rangle$</td>\n> <td>$|5\\rangle$</td>\n> <td>$|6\\rangle$</td>\n> <td>$|7\\rangle$</td>\n> </tr>\n> <tr>\n> <th>Big-endian</th>\n> <td>$|000\\rangle$</td>\n> <td>$|001\\rangle$</td>\n> <td>$|010\\rangle$</td>\n> <td>$|011\\rangle$</td>\n> <td>$|100\\rangle$</td>\n> <td>$|101\\rangle$</td>\n> <td>$|110\\rangle$</td>\n> <td>$|111\\rangle$</td>\n> </tr>\n> <tr>\n> <th>Little-endian</th>\n> <td>$|000\\rangle$</td>\n> <td>$|100\\rangle$</td>\n> <td>$|010\\rangle$</td>\n> <td>$|110\\rangle$</td>\n> <td>$|001\\rangle$</td>\n> <td>$|101\\rangle$</td>\n> <td>$|011\\rangle$</td>\n> <td>$|111\\rangle$</td>\n> </tr>\n></table>\n>\n> Multi-qubit quantum systems that store superpositions of numbers are often referred to as **quantum registers**."
1560
1750
  }
1561
1751
  ]
1562
1752
  },
@@ -1744,6 +1934,108 @@ export default {
1744
1934
  ]
1745
1935
  }
1746
1936
  },
1937
+ {
1938
+ "type": "lesson",
1939
+ "id": "multi_qubit_systems__modifying_entangled_states",
1940
+ "title": "Modifying Entangled States",
1941
+ "items": [
1942
+ {
1943
+ "type": "text-content",
1944
+ "asHtml": "<p>Entangled quantum states can be manipulated using single-qubit gates. For example, each state in the Bell basis is entangled and can be transformed into another Bell state through the application of single-qubit gates. In this lesson, you&#39;ll learn how to do that. (And we will learn more about applying single-qubit gates to multi-qubit states in the next kata.)</p>\n",
1945
+ "asMarkdown": "\nEntangled quantum states can be manipulated using single-qubit gates. For example, each state in the Bell basis is entangled and can be transformed into another Bell state through the application of single-qubit gates. In this lesson, you'll learn how to do that. (And we will learn more about applying single-qubit gates to multi-qubit states in the next kata.)"
1946
+ }
1947
+ ]
1948
+ },
1949
+ {
1950
+ "type": "exercise",
1951
+ "id": "multi_qubit_systems__bell_state_change_1 ",
1952
+ "title": "Bell State Change 1",
1953
+ "description": {
1954
+ "type": "text-content",
1955
+ "asHtml": "<p><strong>Input:</strong> Two entangled qubits in Bell state $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|00\\rangle + |11\\rangle\\big)$.</p>\n<p><strong>Goal:</strong> Change the two-qubit state to $|\\Phi^{-}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|00\\rangle - |11\\rangle\\big)$.</p>\n",
1956
+ "asMarkdown": "**Input:** Two entangled qubits in Bell state $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|00\\rangle + |11\\rangle\\big)$.\n\n**Goal:** Change the two-qubit state to $|\\Phi^{-}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|00\\rangle - |11\\rangle\\big)$.\n"
1957
+ },
1958
+ "sourceIds": [
1959
+ "multi_qubit_systems__bell_state_change_1__Verification.qs",
1960
+ "KatasLibrary.qs"
1961
+ ],
1962
+ "placeholderCode": "namespace Kata {\n operation BellStateChange1 (qs : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}",
1963
+ "explainedSolution": {
1964
+ "type": "explained-solution",
1965
+ "items": [
1966
+ {
1967
+ "type": "text-content",
1968
+ "asHtml": "<p>We recognize that the goal is another Bell state. In fact, it is one of the four Bell states.</p>\n<p>We remember from the Single-Qubit Gates kata that the Pauli Z gate will change the state of the $|1\\rangle$ basis state of a single qubit, so this gate seems like a good candidate for what we want to achieve. This gate leaves the sign of the $|0\\rangle$ basis state of a superposition unchanged, but flips the sign of the $|1\\rangle$ basis state of the superposition.</p>\n<p>Don&#39;t forget that the Z gate acts on only a single qubit, and we have two here.\nLet&#39;s also remember how the Bell state is made up from its individual qubits.</p>\n<p>If the two qubits are A and B, where A is <code>qs[0]</code> and B is <code>qs[1]</code>, we can write that\n$|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|0_{A}0_{B}\\rangle + |1_{A}1_{B}\\rangle\\big)$.\nIf we apply the Z gate to the qubit A, it will flip the phase of the basis state $|1_A\\rangle$. As this phase is in a sense spread across the entangled state, with $|1_A\\rangle$ basis state being part of the second half of the superposition, this application has the effect of flipping the sign of the whole basis state $|1_A1_B\\rangle$, as you can see by running the solution below.</p>\n<p>The exact same calculations can be done if we apply Z to the qubit B, so that&#39;s another possible solution.</p>\n",
1969
+ "asMarkdown": "\nWe recognize that the goal is another Bell state. In fact, it is one of the four Bell states.\n\nWe remember from the Single-Qubit Gates kata that the Pauli Z gate will change the state of the $|1\\rangle$ basis state of a single qubit, so this gate seems like a good candidate for what we want to achieve. This gate leaves the sign of the $|0\\rangle$ basis state of a superposition unchanged, but flips the sign of the $|1\\rangle$ basis state of the superposition.\n\nDon't forget that the Z gate acts on only a single qubit, and we have two here.\nLet's also remember how the Bell state is made up from its individual qubits.\n\nIf the two qubits are A and B, where A is `qs[0]` and B is `qs[1]`, we can write that\n$|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|0_{A}0_{B}\\rangle + |1_{A}1_{B}\\rangle\\big)$.\nIf we apply the Z gate to the qubit A, it will flip the phase of the basis state $|1_A\\rangle$. As this phase is in a sense spread across the entangled state, with $|1_A\\rangle$ basis state being part of the second half of the superposition, this application has the effect of flipping the sign of the whole basis state $|1_A1_B\\rangle$, as you can see by running the solution below.\n\nThe exact same calculations can be done if we apply Z to the qubit B, so that's another possible solution."
1970
+ },
1971
+ {
1972
+ "type": "solution",
1973
+ "id": "multi_qubit_systems__bell_state_change_1_solution",
1974
+ "code": "namespace Kata {\n operation BellStateChange1 (qs : Qubit[]) : Unit is Adj + Ctl {\n Z(qs[0]);\n }\n}"
1975
+ }
1976
+ ]
1977
+ }
1978
+ },
1979
+ {
1980
+ "type": "exercise",
1981
+ "id": "multi_qubit_systems__bell_state_change_2 ",
1982
+ "title": "Bell State Change 2",
1983
+ "description": {
1984
+ "type": "text-content",
1985
+ "asHtml": "<p><strong>Input:</strong> Two entangled qubits in Bell state $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|00\\rangle + |11\\rangle\\big)$.</p>\n<p><strong>Goal:</strong> Change the two-qubit state to $|\\Psi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|01\\rangle + |10\\rangle\\big)$.</p>\n",
1986
+ "asMarkdown": "**Input:** Two entangled qubits in Bell state $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|00\\rangle + |11\\rangle\\big)$.\n\n**Goal:** Change the two-qubit state to $|\\Psi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|01\\rangle + |10\\rangle\\big)$."
1987
+ },
1988
+ "sourceIds": [
1989
+ "multi_qubit_systems__bell_state_change_2__Verification.qs",
1990
+ "KatasLibrary.qs"
1991
+ ],
1992
+ "placeholderCode": "namespace Kata {\n operation BellStateChange2 (qs : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}",
1993
+ "explainedSolution": {
1994
+ "type": "explained-solution",
1995
+ "items": [
1996
+ {
1997
+ "type": "text-content",
1998
+ "asHtml": "<p>We have seen in the Single-Qubit Gates kata that the Pauli X gate flips $|0\\rangle$ to $|1\\rangle$ and vice versa, and as we seem to need some flipping of states, perhaps this gate may be of use. (Bearing in mind, of course, that the X gate operates on a single qubit).</p>\n<p>Let&#39;s compare the starting state $\\frac{1}{\\sqrt{2}} \\big(|0_A0_B\\rangle + |1_A1_B\\rangle\\big)$ with the goal state $\\frac{1}{\\sqrt{2}} \\big(1_A0_B\\rangle + |0_A1_B\\rangle\\big)$ term by term and see how we need to transform it to reach the goal.</p>\n<p>Using our nomenclature from &quot;Bell state change 1&quot;, we can now see by comparing terms that $|0_{A}\\rangle$ has flipped to $|1_A\\rangle$ to get the first term, and $|1_{A}\\rangle$ has flipped to $|0_A\\rangle$ to get the second term. This allows us to say that the correct gate to use is Pauli X, applied to <code>qs[0]</code>.</p>\n",
1999
+ "asMarkdown": "\nWe have seen in the Single-Qubit Gates kata that the Pauli X gate flips $|0\\rangle$ to $|1\\rangle$ and vice versa, and as we seem to need some flipping of states, perhaps this gate may be of use. (Bearing in mind, of course, that the X gate operates on a single qubit).\n\nLet's compare the starting state $\\frac{1}{\\sqrt{2}} \\big(|0_A0_B\\rangle + |1_A1_B\\rangle\\big)$ with the goal state $\\frac{1}{\\sqrt{2}} \\big(1_A0_B\\rangle + |0_A1_B\\rangle\\big)$ term by term and see how we need to transform it to reach the goal.\n\nUsing our nomenclature from \"Bell state change 1\", we can now see by comparing terms that $|0_{A}\\rangle$ has flipped to $|1_A\\rangle$ to get the first term, and $|1_{A}\\rangle$ has flipped to $|0_A\\rangle$ to get the second term. This allows us to say that the correct gate to use is Pauli X, applied to `qs[0]`."
2000
+ },
2001
+ {
2002
+ "type": "solution",
2003
+ "id": "multi_qubit_systems__bell_state_change_2_solution",
2004
+ "code": "namespace Kata {\n operation BellStateChange2 (qs : Qubit[]) : Unit is Adj + Ctl {\n X(qs[0]);\n }\n}"
2005
+ }
2006
+ ]
2007
+ }
2008
+ },
2009
+ {
2010
+ "type": "exercise",
2011
+ "id": "multi_qubit_systems__bell_state_change_3 ",
2012
+ "title": "Bell State Change 3",
2013
+ "description": {
2014
+ "type": "text-content",
2015
+ "asHtml": "<p><strong>Input:</strong> Two entangled qubits in Bell state $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|00\\rangle + |11\\rangle\\big)$.</p>\n<p><strong>Goal:</strong> Change the two-qubit state, without adding a global phase, to $|\\Psi^{-}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|01\\rangle - |10\\rangle\\big)$.</p>\n",
2016
+ "asMarkdown": "**Input:** Two entangled qubits in Bell state $|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|00\\rangle + |11\\rangle\\big)$.\n\n**Goal:** Change the two-qubit state, without adding a global phase, to $|\\Psi^{-}\\rangle = \\frac{1}{\\sqrt{2}} \\big(|01\\rangle - |10\\rangle\\big)$."
2017
+ },
2018
+ "sourceIds": [
2019
+ "multi_qubit_systems__bell_state_change_3__Verification.qs",
2020
+ "KatasLibrary.qs"
2021
+ ],
2022
+ "placeholderCode": "namespace Kata {\n operation BellStateChange3(qs : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}",
2023
+ "explainedSolution": {
2024
+ "type": "explained-solution",
2025
+ "items": [
2026
+ {
2027
+ "type": "text-content",
2028
+ "asHtml": "<p>We remember from the Single-Qubit Gates kata that the Pauli Z gate leaves the sign of the $|0\\rangle$ component of the single qubit superposition unchanged but flips the sign of the $|1\\rangle$ component of the superposition. We have also just seen in &quot;Bell State Change 2&quot; how to change our input state to the state $\\frac{1}{\\sqrt{2}} \\big(|01\\rangle + |10\\rangle\\big)$, which is almost our goal state (disregarding the phase change for the moment). So it would seem that a combination of these two gates will be what we need here. The remaining question is in what order to apply them, and to which qubit.</p>\n<p>First of all, which qubit? Looking back at the task &quot;Bell state change 2&quot;, it seems clear that we need to use qubit <code>qs[0]</code>, like we did there.</p>\n<p>Second, in what order should we apply the gates? Remember that the Pauli Z gate flips the phase of the $|1\\rangle$ component of the superposition and leaves the $|0\\rangle$ component alone.\nLet&#39;s experiment with applying X to <code>qs[0]</code> first. Looking at our &quot;halfway answer&quot; state $\\frac{1}{\\sqrt{2}} \\big(|01\\rangle + |10\\rangle\\big)$, we can see that if we apply the Z gate to <code>qs[0]</code>, it will leave the $|0_{A}\\rangle$ alone but flip the phase of $|1_{A}\\rangle$ to $-|1_{A}\\rangle$, thus flipping the phase of the $|11\\rangle$ component of our Bell state.</p>\n",
2029
+ "asMarkdown": "\nWe remember from the Single-Qubit Gates kata that the Pauli Z gate leaves the sign of the $|0\\rangle$ component of the single qubit superposition unchanged but flips the sign of the $|1\\rangle$ component of the superposition. We have also just seen in \"Bell State Change 2\" how to change our input state to the state $\\frac{1}{\\sqrt{2}} \\big(|01\\rangle + |10\\rangle\\big)$, which is almost our goal state (disregarding the phase change for the moment). So it would seem that a combination of these two gates will be what we need here. The remaining question is in what order to apply them, and to which qubit.\n\nFirst of all, which qubit? Looking back at the task \"Bell state change 2\", it seems clear that we need to use qubit `qs[0]`, like we did there.\n\nSecond, in what order should we apply the gates? Remember that the Pauli Z gate flips the phase of the $|1\\rangle$ component of the superposition and leaves the $|0\\rangle$ component alone.\nLet's experiment with applying X to `qs[0]` first. Looking at our \"halfway answer\" state $\\frac{1}{\\sqrt{2}} \\big(|01\\rangle + |10\\rangle\\big)$, we can see that if we apply the Z gate to `qs[0]`, it will leave the $|0_{A}\\rangle$ alone but flip the phase of $|1_{A}\\rangle$ to $-|1_{A}\\rangle$, thus flipping the phase of the $|11\\rangle$ component of our Bell state."
2030
+ },
2031
+ {
2032
+ "type": "solution",
2033
+ "id": "multi_qubit_systems__bell_state_change_3_solution",
2034
+ "code": "namespace Kata {\n operation BellStateChange3(qs : Qubit[]) : Unit is Adj + Ctl {\n X(qs[0]);\n Z(qs[0]);\n }\n}"
2035
+ }
2036
+ ]
2037
+ }
2038
+ },
1747
2039
  {
1748
2040
  "type": "lesson",
1749
2041
  "id": "multi_qubit_systems__conclusion",
@@ -1828,6 +2120,36 @@ export default {
1828
2120
  }
1829
2121
  ]
1830
2122
  },
2123
+ {
2124
+ "type": "exercise",
2125
+ "id": "multi_qubit_gates__entangle_qubits",
2126
+ "title": "Entangle Qubits",
2127
+ "description": {
2128
+ "type": "text-content",
2129
+ "asHtml": "<p><strong>Input:</strong> Two unentangled qubits (stored in an array of length 2).\nThe first qubit will be in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$, the second - in state $|0\\rangle$\n(this can be written as two-qubit state $\\big(\\alpha |0\\rangle + \\beta |1\\rangle \\big) \\otimes |0\\rangle = \\alpha |00\\rangle + \\beta |10\\rangle$).</p>\n<p><strong>Goal:</strong> Change the two-qubit state to $\\alpha |00\\rangle + \\beta |11\\rangle$.</p>\n",
2130
+ "asMarkdown": "**Input:** Two unentangled qubits (stored in an array of length 2).\nThe first qubit will be in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$, the second - in state $|0\\rangle$\n(this can be written as two-qubit state $\\big(\\alpha |0\\rangle + \\beta |1\\rangle \\big) \\otimes |0\\rangle = \\alpha |00\\rangle + \\beta |10\\rangle$).\n\n**Goal:** Change the two-qubit state to $\\alpha |00\\rangle + \\beta |11\\rangle$.\n"
2131
+ },
2132
+ "sourceIds": [
2133
+ "multi_qubit_gates__entangle_qubits__Verification.qs",
2134
+ "KatasLibrary.qs"
2135
+ ],
2136
+ "placeholderCode": "namespace Kata {\n operation EntangleQubits (qs : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}",
2137
+ "explainedSolution": {
2138
+ "type": "explained-solution",
2139
+ "items": [
2140
+ {
2141
+ "type": "text-content",
2142
+ "asHtml": "<p>Let&#39;s denote the first qubit in state $\\alpha |0\\rangle + \\beta |1\\rangle$ as A and the second qubit in state $|0\\rangle$ as B.</p>\n<p>Compare our input state $\\alpha |0_A0_B\\rangle + \\beta |1_A0_B\\rangle$ with the goal state $\\alpha |0_A0_B\\rangle + \\beta |1_A1_B\\rangle$. \nWe want to pass our input qubit through a gate or gates (to be decided) that do the following. If qubit A is in the $|0\\rangle$ state, then we want to leave qubit B alone (the first term of the superposition). \nHowever, if A is in the $|1\\rangle$ state, we want to flip qubit B from $|0\\rangle$ into $|1\\rangle$ state. In other words, the state of B is to be made contingent upon the state of A. \nThis is exactly the effect of the $CNOT$ gate. Depending upon the state of the <strong>control</strong> qubit (A in our case), the value of the controlled or <strong>target</strong> qubit (B in our case) is inverted or unchanged. Thus, we get the goal state $\\alpha |00\\rangle + \\beta |11\\rangle$.</p>\n",
2143
+ "asMarkdown": "\nLet's denote the first qubit in state $\\alpha |0\\rangle + \\beta |1\\rangle$ as A and the second qubit in state $|0\\rangle$ as B.\n\nCompare our input state $\\alpha |0_A0_B\\rangle + \\beta |1_A0_B\\rangle$ with the goal state $\\alpha |0_A0_B\\rangle + \\beta |1_A1_B\\rangle$. \nWe want to pass our input qubit through a gate or gates (to be decided) that do the following. If qubit A is in the $|0\\rangle$ state, then we want to leave qubit B alone (the first term of the superposition). \nHowever, if A is in the $|1\\rangle$ state, we want to flip qubit B from $|0\\rangle$ into $|1\\rangle$ state. In other words, the state of B is to be made contingent upon the state of A. \nThis is exactly the effect of the $CNOT$ gate. Depending upon the state of the **control** qubit (A in our case), the value of the controlled or **target** qubit (B in our case) is inverted or unchanged. Thus, we get the goal state $\\alpha |00\\rangle + \\beta |11\\rangle$."
2144
+ },
2145
+ {
2146
+ "type": "solution",
2147
+ "id": "multi_qubit_gates__entangle_qubits_solution",
2148
+ "code": "namespace Kata {\n operation EntangleQubits (qs : Qubit[]) : Unit is Adj + Ctl {\n CNOT(qs[0], qs[1]);\n }\n}"
2149
+ }
2150
+ ]
2151
+ }
2152
+ },
1831
2153
  {
1832
2154
  "type": "exercise",
1833
2155
  "id": "multi_qubit_gates__preparing_bell_state",
@@ -1858,6 +2180,58 @@ export default {
1858
2180
  ]
1859
2181
  }
1860
2182
  },
2183
+ {
2184
+ "type": "lesson",
2185
+ "id": "multi_qubit_gates__cz_gate",
2186
+ "title": "CZ Gate",
2187
+ "items": [
2188
+ {
2189
+ "type": "text-content",
2190
+ "asHtml": "<p>The $CZ$ (&quot;controlled-Z&quot;) gate is a two-qubit gate, with one qubit referred to as the <strong>control</strong> qubit, and the other as the <strong>target</strong> qubit. Interestingly, for the $CZ$ gate it doesn&#39;t matter which qubit is control and which is target - the effect of the gate is the same either way!</p>\n<p>The $CZ$ gate acts as a conditional gate: if the control qubit is in state $|1\\rangle$, it applies the $Z$ gate to the target qubit, otherwise it does nothing.</p>\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Applying to $|\\psi\\rangle = \\alpha|00\\rangle + \\beta|01\\rangle + \\gamma|10\\rangle + \\delta|11\\rangle$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$CZ$</td>\n <td>\n $$\\begin{bmatrix}\n 1 & 0 & 0 & 0 \\\\\n 0 & 1 & 0 & 0 \\\\\n 0 & 0 & 1 & 0 \\\\\n 0 & 0 & 0 & -1\n \\end{bmatrix}$$\n </td>\n <td>$CZ|\\psi\\rangle = \\alpha|00\\rangle + \\beta|01\\rangle + \\gamma|10\\rangle - \\delta|11\\rangle$</td>\n <td>\n $$CZ|00\\rangle = |00\\rangle$$\n $$CZ|01\\rangle = |01\\rangle$$\n $$CZ|10\\rangle = |10\\rangle$$\n $$CZ|11\\rangle = -|11\\rangle$$\n </td>\n </tr>\n</table>\n\n<p>The $CZ$ gate is particularly useful for creating and manipulating entangled states where the phase of the quantum state is crucial. Consider the following separable state:</p>\n<p>$$\\big(\\alpha|0\\rangle + \\beta|1\\rangle\\big) \\otimes \\big(\\gamma|0\\rangle + \\delta|1\\rangle\\big) = \\alpha\\gamma|00\\rangle + \\alpha\\delta|01\\rangle + \\beta\\gamma|10\\rangle + \\beta\\delta|11\\rangle$$</p>\n<p>If we apply the $CZ$ gate to it, with the first qubit as the control and the second as the target (or vice versa), we get the following state, which can no longer be separated:</p>\n<p>$$\\alpha\\gamma|00\\rangle + \\alpha\\delta|01\\rangle + \\beta\\gamma|10\\rangle - \\beta\\delta|11\\rangle$$</p>\n<p>The $CZ$ gate is also self-adjoint: applying it a second time reverses its effect, similar to the $CNOT$ gate.</p>\n",
2191
+ "asMarkdown": "\nThe $CZ$ (\"controlled-Z\") gate is a two-qubit gate, with one qubit referred to as the **control** qubit, and the other as the **target** qubit. Interestingly, for the $CZ$ gate it doesn't matter which qubit is control and which is target - the effect of the gate is the same either way!\n\nThe $CZ$ gate acts as a conditional gate: if the control qubit is in state $|1\\rangle$, it applies the $Z$ gate to the target qubit, otherwise it does nothing.\n\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Applying to $|\\psi\\rangle = \\alpha|00\\rangle + \\beta|01\\rangle + \\gamma|10\\rangle + \\delta|11\\rangle$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$CZ$</td>\n <td>\n $$\\begin{bmatrix}\n 1 & 0 & 0 & 0 \\\\\n 0 & 1 & 0 & 0 \\\\\n 0 & 0 & 1 & 0 \\\\\n 0 & 0 & 0 & -1\n \\end{bmatrix}$$\n </td>\n <td>$CZ|\\psi\\rangle = \\alpha|00\\rangle + \\beta|01\\rangle + \\gamma|10\\rangle - \\delta|11\\rangle$</td>\n <td>\n $$CZ|00\\rangle = |00\\rangle$$\n $$CZ|01\\rangle = |01\\rangle$$\n $$CZ|10\\rangle = |10\\rangle$$\n $$CZ|11\\rangle = -|11\\rangle$$\n </td>\n </tr>\n</table>\n\nThe $CZ$ gate is particularly useful for creating and manipulating entangled states where the phase of the quantum state is crucial. Consider the following separable state:\n\n$$\\big(\\alpha|0\\rangle + \\beta|1\\rangle\\big) \\otimes \\big(\\gamma|0\\rangle + \\delta|1\\rangle\\big) = \\alpha\\gamma|00\\rangle + \\alpha\\delta|01\\rangle + \\beta\\gamma|10\\rangle + \\beta\\delta|11\\rangle$$\n\nIf we apply the $CZ$ gate to it, with the first qubit as the control and the second as the target (or vice versa), we get the following state, which can no longer be separated:\n\n$$\\alpha\\gamma|00\\rangle + \\alpha\\delta|01\\rangle + \\beta\\gamma|10\\rangle - \\beta\\delta|11\\rangle$$\n\nThe $CZ$ gate is also self-adjoint: applying it a second time reverses its effect, similar to the $CNOT$ gate."
2192
+ }
2193
+ ]
2194
+ },
2195
+ {
2196
+ "type": "exercise",
2197
+ "id": "multi_qubit_gates__relative_phase_minusone",
2198
+ "title": "Relative Phase -1",
2199
+ "description": {
2200
+ "type": "text-content",
2201
+ "asHtml": "<p><strong>Input:</strong> Two unentangled qubits (stored in an array of length 2) in state $|+\\rangle \\otimes |+\\rangle = \\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle {\\color{blue}+} |11\\rangle \\big)$.</p>\n<p><strong>Goal:</strong> Change the two-qubit state to $\\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle {\\color{red}-} |11\\rangle \\big)$.</p>\n",
2202
+ "asMarkdown": "**Input:** Two unentangled qubits (stored in an array of length 2) in state $|+\\rangle \\otimes |+\\rangle = \\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle {\\color{blue}+} |11\\rangle \\big)$.\n\n**Goal:** Change the two-qubit state to $\\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle {\\color{red}-} |11\\rangle \\big)$.\n"
2203
+ },
2204
+ "sourceIds": [
2205
+ "multi_qubit_gates__relative_phase_minusone__Verification.qs",
2206
+ "KatasLibrary.qs"
2207
+ ],
2208
+ "placeholderCode": "namespace Kata {\n operation RelativePhaseMinusOne (qs : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}",
2209
+ "explainedSolution": {
2210
+ "type": "explained-solution",
2211
+ "items": [
2212
+ {
2213
+ "type": "text-content",
2214
+ "asHtml": "<p>Firstly we notice that we are dealing with an unentangled pair of qubits.\nIn vector form the transformation we need is \n$$\n\\frac{1}{2}\\begin{bmatrix}1\\\\ 1\\\\ 1\\\\ 1\\\\ \\end{bmatrix} \n\\rightarrow \n\\frac{1}{2}\\begin{bmatrix}1\\\\ 1\\\\ 1\\\\ -1\\\\ \\end{bmatrix}\n$$</p>\n<p>All that needs to happen to change the input into the goal is that the $|11\\rangle$ basis state needs to have its sign flipped.</p>\n<p>We remember that the Pauli $Z$ gate flips signs in the single qubit case, and that $CZ$ is the 2-qubit version of this gate. And indeed, the effect of the $CZ$ gate is exactly the transformation we&#39;re looking for here.</p>\n",
2215
+ "asMarkdown": "\nFirstly we notice that we are dealing with an unentangled pair of qubits.\nIn vector form the transformation we need is \n$$\n\\frac{1}{2}\\begin{bmatrix}1\\\\\\ 1\\\\\\ 1\\\\\\ 1\\\\\\ \\end{bmatrix} \n\\rightarrow \n\\frac{1}{2}\\begin{bmatrix}1\\\\\\ 1\\\\\\ 1\\\\\\ -1\\\\\\ \\end{bmatrix}\n$$\n\nAll that needs to happen to change the input into the goal is that the $|11\\rangle$ basis state needs to have its sign flipped.\n\nWe remember that the Pauli $Z$ gate flips signs in the single qubit case, and that $CZ$ is the 2-qubit version of this gate. And indeed, the effect of the $CZ$ gate is exactly the transformation we're looking for here."
2216
+ },
2217
+ {
2218
+ "type": "solution",
2219
+ "id": "multi_qubit_gates__two_qubit_gate_2_solution_a",
2220
+ "code": "namespace Kata {\n operation RelativePhaseMinusOne (qs : Qubit[]) : Unit is Adj + Ctl {\n CZ(qs[0], qs[1]);\n }\n}"
2221
+ },
2222
+ {
2223
+ "type": "text-content",
2224
+ "asHtml": "<p>Alternatively, we can express this gate using the intrinsic gate Z and its controlled variant using the Controlled functor:</p>\n",
2225
+ "asMarkdown": "\nAlternatively, we can express this gate using the intrinsic gate Z and its controlled variant using the Controlled functor:"
2226
+ },
2227
+ {
2228
+ "type": "solution",
2229
+ "id": "multi_qubit_gates__two_qubit_gate_2_solution_b",
2230
+ "code": "namespace Kata {\n operation RelativePhaseMinusOne (qs : Qubit[]) : Unit is Adj + Ctl {\n Controlled Z([qs[0]], qs[1]);\n }\n}"
2231
+ }
2232
+ ]
2233
+ }
2234
+ },
1861
2235
  {
1862
2236
  "type": "lesson",
1863
2237
  "id": "multi_qubit_gates__ket_bra_representation",
@@ -2144,8 +2518,7 @@ export default {
2144
2518
  },
2145
2519
  "sourceIds": [
2146
2520
  "single_qubit_measurements__distinguish_0_and_1__Verification.qs",
2147
- "KatasLibrary.qs",
2148
- "single_qubit_measurements__Common.qs"
2521
+ "KatasLibrary.qs"
2149
2522
  ],
2150
2523
  "placeholderCode": "namespace Kata {\n operation IsQubitZero(q : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
2151
2524
  "explainedSolution": {
@@ -2187,8 +2560,7 @@ export default {
2187
2560
  },
2188
2561
  "sourceIds": [
2189
2562
  "single_qubit_measurements__distinguish_plus_and_minus__Verification.qs",
2190
- "KatasLibrary.qs",
2191
- "single_qubit_measurements__Common.qs"
2563
+ "KatasLibrary.qs"
2192
2564
  ],
2193
2565
  "placeholderCode": "namespace Kata {\n operation IsQubitMinus(q : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
2194
2566
  "explainedSolution": {
@@ -2230,8 +2602,7 @@ export default {
2230
2602
  },
2231
2603
  "sourceIds": [
2232
2604
  "single_qubit_measurements__distinguish_orthogonal_states_1__Verification.qs",
2233
- "KatasLibrary.qs",
2234
- "single_qubit_measurements__Common.qs"
2605
+ "KatasLibrary.qs"
2235
2606
  ],
2236
2607
  "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n operation IsQubitPsiPlus(q : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
2237
2608
  "explainedSolution": {
@@ -2261,8 +2632,7 @@ export default {
2261
2632
  },
2262
2633
  "sourceIds": [
2263
2634
  "single_qubit_measurements__distinguish_orthogonal_states_2__Verification.qs",
2264
- "KatasLibrary.qs",
2265
- "single_qubit_measurements__Common.qs"
2635
+ "KatasLibrary.qs"
2266
2636
  ],
2267
2637
  "placeholderCode": "namespace Kata {\n operation IsQubitA(alpha : Double, q : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
2268
2638
  "explainedSolution": {
@@ -2292,8 +2662,7 @@ export default {
2292
2662
  },
2293
2663
  "sourceIds": [
2294
2664
  "single_qubit_measurements__a_b_basis_measurements__Verification.qs",
2295
- "KatasLibrary.qs",
2296
- "single_qubit_measurements__Common.qs"
2665
+ "KatasLibrary.qs"
2297
2666
  ],
2298
2667
  "placeholderCode": "namespace Kata {\n operation MeasureInABBasis(alpha : Double, q : Qubit) : Result {\n // Implement your solution here...\n\n return Zero;\n }\n}\n",
2299
2668
  "explainedSolution": {
@@ -2397,7 +2766,6 @@ export default {
2397
2766
  },
2398
2767
  "sourceIds": [
2399
2768
  "multi_qubit_measurements__full_measurements__Verification.qs",
2400
- "multi_qubit_measurements__Common.qs",
2401
2769
  "KatasLibrary.qs"
2402
2770
  ],
2403
2771
  "placeholderCode": "namespace Kata {\n operation BasisStateMeasurement(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n}\n",
@@ -2472,7 +2840,6 @@ export default {
2472
2840
  },
2473
2841
  "sourceIds": [
2474
2842
  "multi_qubit_measurements__partial_measurements_for_system__Verification.qs",
2475
- "multi_qubit_measurements__Common.qs",
2476
2843
  "KatasLibrary.qs"
2477
2844
  ],
2478
2845
  "placeholderCode": "namespace Kata {\n operation IsPlusPlusMinus(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n}\n",
@@ -2515,7 +2882,6 @@ export default {
2515
2882
  },
2516
2883
  "sourceIds": [
2517
2884
  "multi_qubit_measurements__state_modification__Verification.qs",
2518
- "multi_qubit_measurements__Common.qs",
2519
2885
  "KatasLibrary.qs"
2520
2886
  ],
2521
2887
  "placeholderCode": "namespace Kata {\n operation StateSelection(qs : Qubit[], ind : Int) : Unit {\n // Implement your solution here...\n\n }\n}\n",
@@ -2558,7 +2924,6 @@ export default {
2558
2924
  },
2559
2925
  "sourceIds": [
2560
2926
  "multi_qubit_measurements__state_preparation__Verification.qs",
2561
- "multi_qubit_measurements__Common.qs",
2562
2927
  "KatasLibrary.qs"
2563
2928
  ],
2564
2929
  "placeholderCode": "namespace Kata {\n operation PostSelection(qs : Qubit[]) : Unit {\n // Implement your solution here...\n\n }\n}\n",
@@ -2601,7 +2966,6 @@ export default {
2601
2966
  },
2602
2967
  "sourceIds": [
2603
2968
  "multi_qubit_measurements__joint_measurements__Verification.qs",
2604
- "multi_qubit_measurements__Common.qs",
2605
2969
  "KatasLibrary.qs"
2606
2970
  ],
2607
2971
  "placeholderCode": "namespace Kata {\n operation ParityMeasurement(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n}\n",
@@ -3721,11 +4085,11 @@ export default {
3721
4085
  "globalCodeSources": [
3722
4086
  {
3723
4087
  "id": "getting_started__flip_qubit__Verification.qs",
3724
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n\n operation FlipQubit(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.FlipQubit(register[0]);\n let reference = register => FlipQubit(register[0]);\n let isCorrect = CheckOperationsEquivalence(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n Message(\"Congratulations! You have solved your first exercise.\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Look out for hints when your solution is incorrect.\");\n Message(\"Hint: examine the effect your solution has on the |0〉 state and compare it with the effect it \" +\n \"is expected to have.\");\n use target = Qubit[1]; // |0〉\n ShowQuantumStateComparison(target, solution, reference);\n ResetAll(target);\n }\n isCorrect\n }\n}\n"
4088
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n\n operation FlipQubit(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.FlipQubit(register[0]);\n let reference = register => FlipQubit(register[0]);\n let isCorrect = CheckOperationsEquivalence(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n Message(\"Congratulations! You have solved your first exercise.\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Look out for hints when your solution is incorrect.\");\n Message(\"Hint: examine the effect your solution has on the |0〉 state and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, (qs => ()), solution, reference);\n }\n isCorrect\n }\n}\n"
3725
4089
  },
3726
4090
  {
3727
4091
  "id": "KatasLibrary.qs",
3728
- "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.Random;\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\n /// # Summary\n /// Prepare a random uneven superposition state on the given qubit array.\n operation PrepRandomState(qs : Qubit[]) : Unit {\n for q in qs {\n Ry(DrawRandomDouble(0.01, 0.99) * 2.0, q);\n }\n }\n}\n"
4092
+ "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.Math;\n open Microsoft.Quantum.Random;\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\n /// # Summary\n /// Shows the comparison of the quantum state between a specific operation and a reference operation.\n operation ShowQuantumStateComparison(\n registerSize : Int,\n initialState : Qubit[] => Unit,\n op : Qubit[] => Unit,\n reference : Qubit[] => Unit)\n : Unit {\n {\n use register = Qubit[registerSize];\n initialState(register);\n\n Message(\"Initial quantum state:\");\n DumpMachine();\n\n // Apply the reference operation and dump the simulator state\n reference(register);\n Message(\"Expected quantum state after applying the operation:\");\n DumpMachine();\n ResetAll(register);\n }\n\n {\n use register = Qubit[registerSize];\n initialState(register);\n // Apply the comparison operation and dump the simulator state\n op(register);\n Message(\"Actual quantum state after applying the operation:\");\n DumpMachine();\n ResetAll(register);\n }\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),\n refImpl : (Qubit[] => Unit is Adj),\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 ShowQuantumStateComparison(inputSize, (qs => ()), testImpl, refImpl);\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\n /// # Summary\n /// Prepare a random uneven superposition state on the given qubit array.\n operation PrepRandomState(qs : Qubit[]) : Unit {\n for q in qs {\n Ry(DrawRandomDouble(0.01, 0.99) * 2.0, q);\n }\n }\n\n\n // \"Framework\" operation for testing single-qubit tasks for distinguishing states of one qubit\n // with Bool return\n operation DistinguishTwoStates_SingleQubit(\n statePrep : ((Qubit, Int) => Unit is Adj),\n testImpl : (Qubit => Bool),\n stateNames : String[],\n preserveState : Bool) : Bool {\n\n let nTotal = 100;\n let nStates = 2;\n mutable misclassifications = [0, size=nStates];\n\n use q = Qubit();\n for _ in 1 .. nTotal {\n // get a random bit to define whether qubit will be in a state corresponding to true return (1) or to false one (0)\n // state = 0 false return\n // state = 1 true return\n let state = DrawRandomInt(0, 1);\n\n // do state prep: convert |0⟩ to outcome with false return or to outcome with true return depending on state\n statePrep(q, state);\n\n // get the solution's answer and verify if NOT a match, then differentiate what kind of mismatch\n let ans = testImpl(q);\n if ans != (state == 1) {\n set misclassifications w/= state <- misclassifications[state] + 1;\n }\n\n // If the final state is to be preserved, check if it was not modified\n if preserveState {\n Adjoint statePrep(q, state);\n if not CheckZero(q) {\n Message($\"Input quantum state {stateNames[state]} was not preserved during the measurement.\");\n Reset(q);\n return false;\n }\n } else {\n Reset(q);\n }\n }\n\n mutable totalMisclassifications = 0;\n for i in 0 .. nStates - 1 {\n if misclassifications[i] != 0 {\n set totalMisclassifications += misclassifications[i];\n Message($\"Misclassified {stateNames[i]} as {stateNames[1 - i]} in {misclassifications[i]} test runs.\");\n }\n }\n\n totalMisclassifications == 0\n }\n\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 _ 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\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}\n"
3729
4093
  },
3730
4094
  {
3731
4095
  "id": "complex_arithmetic__powers_of_i__Verification.qs",
@@ -3829,35 +4193,59 @@ export default {
3829
4193
  },
3830
4194
  {
3831
4195
  "id": "single_qubit_gates__state_flip__Verification.qs",
3832
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation StateFlip(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.StateFlip(register[0]);\n let reference = register => StateFlip(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n use initial = Qubit(); // |0〉\n Ry(ArcTan2(0.8, 0.6) * 2.0, initial);\n ShowQuantumStateComparison([initial], solution, reference);\n Reset(initial);\n }\n isCorrect\n }\n}"
4196
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation StateFlip(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.StateFlip(register[0]);\n let reference = register => StateFlip(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}"
4197
+ },
4198
+ {
4199
+ "id": "single_qubit_gates__sign_flip__Verification.qs",
4200
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation SignFlip(q : Qubit) : Unit is Adj + Ctl {\n Z(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.SignFlip(register[0]);\n let reference = register => SignFlip(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
3833
4201
  },
3834
4202
  {
3835
4203
  "id": "single_qubit_gates__y_gate__Verification.qs",
3836
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation ApplyY(q : Qubit) : Unit is Adj + Ctl {\n Y(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.ApplyY(register[0]);\n let reference = register => ApplyY(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n use initial = Qubit(); // |0〉\n Ry(ArcTan2(0.8, 0.6) * 2.0, initial); // 0.6|0〉 + 0.8|1〉\n ShowQuantumStateComparison([initial], solution, reference);\n Reset(initial);\n }\n isCorrect\n }\n}\n"
4204
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation ApplyY(q : Qubit) : Unit is Adj + Ctl {\n Y(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.ApplyY(register[0]);\n let reference = register => ApplyY(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
4205
+ },
4206
+ {
4207
+ "id": "single_qubit_gates__sign_flip_on_zero__Verification.qs",
4208
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation SignFlipOnZero(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n Z(q);\n X(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.SignFlipOnZero(register[0]);\n let reference = register => SignFlipOnZero(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\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 Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
4209
+ },
4210
+ {
4211
+ "id": "single_qubit_gates__global_phase_minusone__Verification.qs",
4212
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Canon;\n open Microsoft.Quantum.Intrinsic;\n\n\n operation GlobalPhaseChange (q : Qubit) : Unit is Adj + Ctl {\n Z(q);\n X(q);\n Z(q);\n X(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.GlobalPhaseChange(register[0]);\n let reference = register => GlobalPhaseChange(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
3837
4213
  },
3838
4214
  {
3839
4215
  "id": "single_qubit_gates__global_phase_i__Verification.qs",
3840
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation GlobalPhaseI(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n Z(q);\n Y(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.GlobalPhaseI(register[0]);\n let reference = register => GlobalPhaseI(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n use initial = Qubit(); // |0〉\n Ry(ArcTan2(0.8, 0.6) * 2.0, initial); // 0.6|0〉 + 0.8|1〉\n ShowQuantumStateComparison([initial], solution, reference);\n Reset(initial);\n }\n isCorrect\n }\n}\n"
4216
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation GlobalPhaseI(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n Z(q);\n Y(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.GlobalPhaseI(register[0]);\n let reference = register => GlobalPhaseI(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
3841
4217
  },
3842
4218
  {
3843
- "id": "single_qubit_gates__sign_flip_on_zero__Verification.qs",
3844
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation SignFlipOnZero(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n Z(q);\n X(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.SignFlipOnZero(register[0]);\n let reference = register => SignFlipOnZero(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\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 Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n use initial = Qubit(); // |0〉\n Ry(ArcTan2(0.8, 0.6) * 2.0, initial); // 0.6|0〉 + 0.8|1〉\n ShowQuantumStateComparison([initial], solution, reference);\n Reset(initial);\n }\n isCorrect\n }\n}\n"
4219
+ "id": "single_qubit_gates__basis_change__Verification.qs",
4220
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation BasisChange(q : Qubit) : Unit is Adj + Ctl {\n H(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.BasisChange(register[0]);\n let reference = register => BasisChange(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
3845
4221
  },
3846
4222
  {
3847
4223
  "id": "single_qubit_gates__prepare_minus__Verification.qs",
3848
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation PrepareMinus(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n H(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.PrepareMinus(register[0]);\n let reference = register => PrepareMinus(register[0]);\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(solution, reference, 1);\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 Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n use initial = Qubit(); // |0〉\n ShowQuantumStateComparison([initial], solution, reference);\n Reset(initial);\n }\n isCorrect\n }\n}\n"
4224
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation PrepareMinus(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n H(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.PrepareMinus(register[0]);\n let reference = register => PrepareMinus(register[0]);\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(solution, reference, 1);\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 Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n ShowQuantumStateComparison(1, qs => (), solution, reference);\n }\n isCorrect\n }\n}\n"
4225
+ },
4226
+ {
4227
+ "id": "single_qubit_gates__phase_i__Verification.qs",
4228
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Convert;\n\n operation PhaseFlip (q : Qubit) : Unit is Adj + Ctl {\n S(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.PhaseFlip(register[0]);\n let reference = register => PhaseFlip(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
3849
4229
  },
3850
4230
  {
3851
4231
  "id": "single_qubit_gates__three_quarters_pi_phase__Verification.qs",
3852
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation ThreeQuartersPiPhase(q : Qubit) : Unit is Adj + Ctl {\n S(q);\n T(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.ThreeQuartersPiPhase(register[0]);\n let reference = register => ThreeQuartersPiPhase(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\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 Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n use initial = Qubit(); // |0〉\n Ry(ArcTan2(0.8, 0.6) * 2.0, initial); // 0.6|0〉 + 0.8|1〉\n ShowQuantumStateComparison([initial], solution, reference);\n Reset(initial);\n }\n isCorrect\n }\n}\n"
4232
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation ThreeQuartersPiPhase(q : Qubit) : Unit is Adj + Ctl {\n S(q);\n T(q);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.ThreeQuartersPiPhase(register[0]);\n let reference = register => ThreeQuartersPiPhase(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\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 Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n }\n isCorrect\n }\n}\n"
4233
+ },
4234
+ {
4235
+ "id": "single_qubit_gates__complex_phase__Verification.qs",
4236
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Convert;\n\n operation PhaseChange (alpha : Double, q : Qubit) : Unit is Adj+Ctl {\n R1(alpha, q); \n }\n\n operation CheckSolution() : Bool {\n for i in 0 .. 36 {\n let alpha = ((2.0 * PI()) * IntAsDouble(i)) / 36.0;\n let solution = register => Kata.PhaseChange(alpha, register[0]);\n let reference = register => PhaseChange(alpha, register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n if not isCorrect {\n Message(\"Incorrect.\");\n Message($\"The solution was incorrect for the test case alpha = {alpha}.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}"
4237
+ },
4238
+ {
4239
+ "id": "single_qubit_gates__amplitude_change__Verification.qs",
4240
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Convert;\n\n operation AmplitudeChange (alpha : Double, q : Qubit) : Unit is Adj+Ctl {\n Ry(2.0 * alpha, q);\n }\n\n operation CheckSolution() : Bool {\n for i in 0 .. 36 {\n let alpha = ((2.0 * PI()) * IntAsDouble(i)) / 36.0;\n let solution = register => Kata.AmplitudeChange(alpha, register[0]);\n let reference = register => AmplitudeChange(alpha, register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n if not isCorrect {\n Message(\"Incorrect.\");\n Message($\"The solution was incorrect for the test case alpha = {alpha}.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have.\");\n ShowQuantumStateComparison(1, qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0]), solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
3853
4241
  },
3854
4242
  {
3855
4243
  "id": "single_qubit_gates__prepare_rotated_state__Verification.qs",
3856
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PrepareRotatedState (alpha : Double, beta : Double, q : Qubit) : Unit is Adj+Ctl {\n let phi = ArcTan2(beta, alpha);\n Rx(2.0 * phi, q);\n }\n\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let i = IntAsDouble(i);\n let alpha = Cos(i);\n let beta = Sin(i);\n let solution = register => Kata.PrepareRotatedState(alpha, beta, register[0]);\n let reference = register => PrepareRotatedState(alpha, beta, register[0]);\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(solution, reference, 1);\n if not isCorrect {\n Message(\"Incorrect.\");\n Message($\"The solution was incorrect for the test case alpha = {alpha}, beta = {beta}.\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n use initial = Qubit(); // |0〉\n ShowQuantumStateComparison([initial], solution, reference);\n Reset(initial);\n return false;\n }\n }\n\n Message(\"Correct!\");\n Message(\"The solution was correct for all test cases.\");\n true\n }\n}\n"
4244
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PrepareRotatedState (alpha : Double, beta : Double, q : Qubit) : Unit is Adj+Ctl {\n let phi = ArcTan2(beta, alpha);\n Rx(2.0 * phi, q);\n }\n\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let i = IntAsDouble(i);\n let alpha = Cos(i);\n let beta = Sin(i);\n let solution = register => Kata.PrepareRotatedState(alpha, beta, register[0]);\n let reference = register => PrepareRotatedState(alpha, beta, register[0]);\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(solution, reference, 1);\n if not isCorrect {\n Message(\"Incorrect.\");\n Message($\"The solution was incorrect for the test case alpha = {alpha}, beta = {beta}.\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n ShowQuantumStateComparison(1, qs => (), solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n Message(\"The solution was correct for all test cases.\");\n true\n }\n}\n"
3857
4245
  },
3858
4246
  {
3859
4247
  "id": "single_qubit_gates__prepare_arbitrary_state__Verification.qs",
3860
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PrepareArbitraryState (alpha : Double, beta : Double, theta : Double, q : Qubit) : Unit is Adj+Ctl {\n let phi = ArcTan2(beta, alpha);\n Ry(2.0 * phi, q);\n R1(theta, q);\n }\n\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let i = IntAsDouble(i);\n let alpha = Cos(i);\n let beta = Sin(i);\n let theta = Sin(i);\n let solution = register => Kata.PrepareArbitraryState(alpha, beta, theta, register[0]);\n let reference = register => PrepareArbitraryState(alpha, beta, theta, register[0]);\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(solution, reference, 1);\n if not isCorrect {\n Message(\"Incorrect.\");\n Message($\"The solution was incorrect for the test case alpha = {alpha}, beta = {beta}, theta = {theta}.\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n use initial = Qubit(); // |0〉\n ShowQuantumStateComparison([initial], solution, reference);\n Reset(initial);\n return false;\n }\n }\n\n Message(\"Correct!\");\n Message(\"The solution was correct for all test cases.\");\n true\n }\n}\n"
4248
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PrepareArbitraryState (alpha : Double, beta : Double, theta : Double, q : Qubit) : Unit is Adj+Ctl {\n let phi = ArcTan2(beta, alpha);\n Ry(2.0 * phi, q);\n R1(theta, q);\n }\n\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let i = IntAsDouble(i);\n let alpha = Cos(i);\n let beta = Sin(i);\n let theta = Sin(i);\n let solution = register => Kata.PrepareArbitraryState(alpha, beta, theta, register[0]);\n let reference = register => PrepareArbitraryState(alpha, beta, theta, register[0]);\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(solution, reference, 1);\n if not isCorrect {\n Message(\"Incorrect.\");\n Message($\"The solution was incorrect for the test case alpha = {alpha}, beta = {beta}, theta = {theta}.\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n ShowQuantumStateComparison(1, qs => (), solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n Message(\"The solution was correct for all test cases.\");\n true\n }\n}\n"
3861
4249
  },
3862
4250
  {
3863
4251
  "id": "multi_qubit_systems__learn_basis_state_amplitudes__Verification.qs",
@@ -3879,13 +4267,33 @@ export default {
3879
4267
  "id": "multi_qubit_systems__prepare_with_complex__Verification.qs",
3880
4268
  "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation PrepareWithComplex_Reference(qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n H(qs[1]);\n S(qs[0]);\n T(qs[1]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n CheckOperationsEquivalenceOnZeroStateWithFeedback(Kata.PrepareWithComplex, \n PrepareWithComplex_Reference, 2)\n }\n}\n"
3881
4269
  },
4270
+ {
4271
+ "id": "multi_qubit_systems__bell_state_change_1__Verification.qs",
4272
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Canon;\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Katas;\n\n operation PrepareBellState(qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n CNOT(qs[0], qs[1]);\n }\n\n\n operation BellStateChange1_Reference(qs : Qubit[]) : Unit is Adj + Ctl {\n Z(qs[0]);\n }\n\n\n operation CheckOperationsEquivalenceOnInitialStateStrict(\n initialState : Qubit[] => Unit is Adj,\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int\n ) : Bool {\n use (control, target) = (Qubit(), Qubit[inputSize]);\n within {\n H(control);\n initialState(target);\n }\n apply {\n Controlled op([control], target);\n Adjoint Controlled reference([control], target);\n }\n\n\n let isCorrect = CheckAllZero([control] + target);\n ResetAll([control] + target);\n isCorrect\n }\n\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = CheckOperationsEquivalenceOnInitialStateStrict(\n PrepareBellState,\n Kata.BellStateChange1, \n BellStateChange1_Reference, \n 2);\n\n\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect\");\n ShowQuantumStateComparison(2, PrepareBellState, Kata.BellStateChange1, BellStateChange1_Reference);\n }\n\n\n return isCorrect;\n }\n\n \n}\n"
4273
+ },
4274
+ {
4275
+ "id": "multi_qubit_systems__bell_state_change_2__Verification.qs",
4276
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Canon;\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Katas;\n\n operation PrepareBellState(qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n CNOT(qs[0], qs[1]);\n }\n\n\n operation BellStateChange2_Reference(qs : Qubit[]) : Unit is Adj + Ctl {\n X(qs[0]);\n }\n\n\n operation CheckOperationsEquivalenceOnInitialStateStrict(\n initialState : Qubit[] => Unit is Adj,\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int\n ) : Bool {\n use (control, target) = (Qubit(), Qubit[inputSize]);\n within {\n H(control);\n initialState(target);\n }\n apply {\n Controlled op([control], target);\n Adjoint Controlled reference([control], target);\n }\n\n\n let isCorrect = CheckAllZero([control] + target);\n ResetAll([control] + target);\n isCorrect\n }\n\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = CheckOperationsEquivalenceOnInitialStateStrict(\n PrepareBellState,\n Kata.BellStateChange2, \n BellStateChange2_Reference, \n 2);\n\n\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect\");\n ShowQuantumStateComparison(2, PrepareBellState, Kata.BellStateChange2, BellStateChange2_Reference);\n }\n\n\n return isCorrect;\n }\n\n \n}\n"
4277
+ },
4278
+ {
4279
+ "id": "multi_qubit_systems__bell_state_change_3__Verification.qs",
4280
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Canon;\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Katas;\n\n operation PrepareBellState(qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n CNOT(qs[0], qs[1]);\n }\n\n\n operation BellStateChange3_Reference(qs : Qubit[]) : Unit is Adj + Ctl {\n X(qs[0]);\n Z(qs[0]);\n }\n\n\n operation CheckOperationsEquivalenceOnInitialStateStrict(\n initialState : Qubit[] => Unit is Adj,\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int\n ) : Bool {\n use (control, target) = (Qubit(), Qubit[inputSize]);\n within {\n H(control);\n initialState(target);\n }\n apply {\n Controlled op([control], target);\n Adjoint Controlled reference([control], target);\n }\n\n\n let isCorrect = CheckAllZero([control] + target);\n ResetAll([control] + target);\n isCorrect\n }\n\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = CheckOperationsEquivalenceOnInitialStateStrict(\n PrepareBellState,\n Kata.BellStateChange3, \n BellStateChange3_Reference, \n 2);\n\n\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect\");\n ShowQuantumStateComparison(2, PrepareBellState, Kata.BellStateChange3, BellStateChange3_Reference);\n }\n\n\n return isCorrect;\n }\n\n \n}\n"
4281
+ },
3882
4282
  {
3883
4283
  "id": "multi_qubit_gates__compound_gate__Verification.qs",
3884
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation CompoundGate (qs : Qubit[]) : Unit is Adj + Ctl {\n S(qs[0]);\n I(qs[1]); // this line can be omitted, since it doesn't change the qubit state\n Y(qs[2]);\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.CompoundGate;\n let reference = CompoundGate;\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 3);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n \"transformation\");\n use initial = Qubit[3]; // |000〉\n Ry(ArcTan2(0.8, 0.6) * 2.0, initial[0]);\n Ry(ArcTan2(0.7, 0.4) * 2.0, initial[1]);\n Ry(ArcTan2(0.6, 0.5) * 2.0, initial[2]);\n ShowQuantumStateComparison(initial, solution, reference);\n ResetAll(initial);\n }\n\n isCorrect\n }\n}"
4284
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation CompoundGate (qs : Qubit[]) : Unit is Adj + Ctl {\n S(qs[0]);\n I(qs[1]); // this line can be omitted, since it doesn't change the qubit state\n Y(qs[2]);\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.CompoundGate;\n let reference = CompoundGate;\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 3);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n \"transformation\");\n ShowQuantumStateComparison(3, PrepRandomState, solution, reference);\n }\n\n isCorrect\n }\n}"
4285
+ },
4286
+ {
4287
+ "id": "multi_qubit_gates__entangle_qubits__Verification.qs",
4288
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Convert;\n\n operation EntangleQubits (qs : Qubit[]) : Unit is Adj + Ctl {\n CNOT(qs[0], qs[1]);\n }\n\n operation CheckOperationsEquivalenceOnInitialStateStrict(\n initialState : Qubit[] => Unit is Adj,\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int\n ) : Bool {\n use (control, target) = (Qubit(), Qubit[inputSize]);\n within {\n H(control);\n initialState(target);\n }\n apply {\n Controlled op([control], target);\n Adjoint Controlled reference([control], target);\n }\n let isCorrect = CheckAllZero([control] + target);\n ResetAll([control] + target);\n isCorrect\n }\n \n operation CheckSolution() : Bool {\n let range = 10;\n for i in 0 .. range - 1 {\n let angle = 2.0 * PI() * IntAsDouble(i) / IntAsDouble(range);\n let initialState = qs => Ry(2.0 * angle, qs[0]);\n let isCorrect = CheckOperationsEquivalenceOnInitialStateStrict(\n initialState,\n Kata.EntangleQubits, \n EntangleQubits, \n 2);\n if not isCorrect {\n Message(\"Incorrect\");\n Message($\"Test fails for alpha = {Cos(angle)}, beta = {Sin(angle)}.\");\n ShowQuantumStateComparison(2, initialState, Kata.EntangleQubits, EntangleQubits);\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}"
3885
4289
  },
3886
4290
  {
3887
4291
  "id": "multi_qubit_gates__preparing_bell_state__Verification.qs",
3888
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation BellState (qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n CNOT(qs[0], qs[1]);\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.BellState;\n let reference = BellState;\n let isCorrect = CheckOperationsEquivalenceOnZeroState(solution, reference, 2);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect :(\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n use initial = Qubit[2]; // |00〉\n ShowQuantumStateComparison(initial, solution, reference);\n ResetAll(initial);\n }\n\n isCorrect\n }\n}"
4292
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation BellState (qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n CNOT(qs[0], qs[1]);\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.BellState;\n let reference = BellState;\n let isCorrect = CheckOperationsEquivalenceOnZeroState(solution, reference, 2);\n\n // Output different feedback to the user depending on whether the solution was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the state prepared by your solution and compare it with the state it \" +\n \"is expected to prepare.\");\n ShowQuantumStateComparison(2, (qs => ()), solution, reference);\n }\n\n isCorrect\n }\n}"
4293
+ },
4294
+ {
4295
+ "id": "multi_qubit_gates__relative_phase_minusone__Verification.qs",
4296
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Diagnostics;\n\n operation PrepareState(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyToEachCA(H, qs);\n }\n operation RelativePhaseMinusOne (qs : Qubit[]) : Unit is Adj + Ctl {\n CZ(qs[0], qs[1]);\n }\n\n operation CheckOperationsEquivalenceOnInitialStateStrict(\n initialState : Qubit[] => Unit is Adj,\n op : (Qubit[] => Unit is Adj + Ctl),\n reference : (Qubit[] => Unit is Adj + Ctl),\n inputSize : Int\n ) : Bool {\n use (control, target) = (Qubit(), Qubit[inputSize]);\n within {\n H(control);\n initialState(target);\n }\n apply {\n Controlled op([control], target);\n Adjoint Controlled reference([control], target);\n }\n let isCorrect = CheckAllZero([control] + target);\n ResetAll([control] + target);\n isCorrect\n }\n\n operation CheckSolution() : Bool {\n let isCorrect = CheckOperationsEquivalenceOnInitialStateStrict(\n PrepareState,\n Kata.RelativePhaseMinusOne, \n RelativePhaseMinusOne, \n 2);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect\");\n ShowQuantumStateComparison(2, PrepareState, Kata.RelativePhaseMinusOne, RelativePhaseMinusOne);\n }\n\n return isCorrect;\n }\n}"
3889
4297
  },
3890
4298
  {
3891
4299
  "id": "multi_qubit_gates__qubit_swap__Verification.qs",
@@ -3901,39 +4309,31 @@ export default {
3901
4309
  },
3902
4310
  {
3903
4311
  "id": "single_qubit_measurements__distinguish_0_and_1__Verification.qs",
3904
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Intrinsic;\n\n operation StatePrep_IsQubitZero (q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |1⟩\n X(q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishTwoStates(\n StatePrep_IsQubitZero,\n Kata.IsQubitZero,\n [\"|1⟩\", \"|0⟩\"],\n false);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n isCorrect\n }\n\n}\n"
3905
- },
3906
- {
3907
- "id": "single_qubit_measurements__Common.qs",
3908
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Random;\n\n // \"Framework\" operation for testing single-qubit tasks for distinguishing states of one qubit\n // with Bool return\n operation DistinguishTwoStates(\n statePrep : ((Qubit, Int) => Unit is Adj),\n testImpl : (Qubit => Bool),\n stateName : String[],\n checkFinalState : Bool) : Bool {\n\n let nTotal = 100;\n let nStates = 2;\n mutable misclassifications = Repeated(0, nStates);\n\n use q = Qubit();\n for i in 1 .. nTotal {\n // get a random bit to define whether qubit will be in a state corresponding to true return (1) or to false one (0)\n // state = 0 false return\n // state = 1 true return\n let state = DrawRandomInt(0, 1);\n\n // do state prep: convert |0⟩ to outcome with false return or to outcome with true return depending on state\n statePrep(q, state);\n\n // get the solution's answer and verify if NOT a match, then differentiate what kind of mismatch\n let ans = testImpl(q);\n if ans != (state == 1) {\n set misclassifications w/= state <- misclassifications[state] + 1;\n }\n\n // If the final state is to be verified, check if it matches the measurement outcome\n if checkFinalState {\n Adjoint statePrep(q, state);\n Fact(CheckZero(q), \"Returned Bool value does not match the expected qubit state.\");\n } else {\n Reset(q);\n }\n }\n\n mutable totalMisclassifications = 0;\n for i in 0 .. nStates - 1 {\n if misclassifications[i] != 0 {\n set totalMisclassifications += misclassifications[i];\n Message($\"Misclassified {stateName[i]} as {stateName[1 - i]} in {misclassifications[i]} test runs.\");\n }\n }\n\n return totalMisclassifications == 0;\n }\n\n}\n"
4312
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Katas;\n\n operation StatePrep_IsQubitZero (q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |1⟩\n X(q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishTwoStates_SingleQubit(\n StatePrep_IsQubitZero,\n Kata.IsQubitZero,\n [\"|1⟩\", \"|0⟩\"],\n false);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n isCorrect\n }\n\n}\n"
3909
4313
  },
3910
4314
  {
3911
4315
  "id": "single_qubit_measurements__distinguish_plus_and_minus__Verification.qs",
3912
- "code": "namespace Kata.Verification {\n\n // Distinguish |+❭ and |-❭ using Measure operation\n operation StatePrep_IsQubitMinus (q : Qubit, state : Int) : Unit is Adj {\n if state == 1 {\n // convert |0⟩ to |-⟩\n X(q);\n H(q);\n } else {\n // convert |0⟩ to |+⟩\n H(q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishTwoStates(\n StatePrep_IsQubitMinus,\n Kata.IsQubitMinus,\n [\"|+⟩\", \"|-⟩\"],\n false);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n isCorrect\n }\n\n}\n"
4316
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n // Distinguish |+❭ and |-❭ using Measure operation\n operation StatePrep_IsQubitMinus (q : Qubit, state : Int) : Unit is Adj {\n if state == 1 {\n // convert |0⟩ to |-⟩\n X(q);\n H(q);\n } else {\n // convert |0⟩ to |+⟩\n H(q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishTwoStates_SingleQubit(\n StatePrep_IsQubitMinus,\n Kata.IsQubitMinus,\n [\"|+⟩\", \"|-⟩\"],\n false);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n isCorrect\n }\n\n}\n"
3913
4317
  },
3914
4318
  {
3915
4319
  "id": "single_qubit_measurements__distinguish_orthogonal_states_1__Verification.qs",
3916
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n\n // Distinguish specific orthogonal states\n // |ψ₊⟩ = 0.6 * |0⟩ + 0.8 * |1⟩,\n // |ψ₋⟩ = -0.8 * |0⟩ + 0.6 * |1⟩.\n operation StatePrep_IsQubitPsiPlus(q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |ψ₋⟩\n X(q);\n Ry(2.0 * ArcTan2(0.8, 0.6), q);\n } else {\n // convert |0⟩ to |ψ₊⟩\n Ry(2.0 * ArcTan2(0.8, 0.6), q);\n }\n }\n\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishTwoStates(\n StatePrep_IsQubitPsiPlus,\n Kata.IsQubitPsiPlus,\n [\"|ψ₋⟩\", \"|ψ₊⟩\"],\n false);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n isCorrect\n }\n\n}\n"
4320
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Katas;\n\n // Distinguish specific orthogonal states\n // |ψ₊⟩ = 0.6 * |0⟩ + 0.8 * |1⟩,\n // |ψ₋⟩ = -0.8 * |0⟩ + 0.6 * |1⟩.\n operation StatePrep_IsQubitPsiPlus(q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |ψ₋⟩\n X(q);\n Ry(2.0 * ArcTan2(0.8, 0.6), q);\n } else {\n // convert |0⟩ to |ψ₊⟩\n Ry(2.0 * ArcTan2(0.8, 0.6), q);\n }\n }\n\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishTwoStates_SingleQubit(\n StatePrep_IsQubitPsiPlus,\n Kata.IsQubitPsiPlus,\n [\"|ψ₋⟩\", \"|ψ₊⟩\"],\n false);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n }\n isCorrect\n }\n\n}\n"
3917
4321
  },
3918
4322
  {
3919
4323
  "id": "single_qubit_measurements__distinguish_orthogonal_states_2__Verification.qs",
3920
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n\n // Distinguish states |A❭ and |B❭\n // |A⟩ = cos(alpha) * |0⟩ - i sin(alpha) * |1⟩,\n // |B⟩ = - i sin(alpha) * |0⟩ + cos(alpha) * |1⟩.\n operation StatePrep_IsQubitA(alpha : Double, q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |B⟩\n X(q);\n Rx(2.0 * alpha, q);\n } else {\n // convert |0⟩ to |A⟩\n Rx(2.0 * alpha, q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let alpha = (PI() * IntAsDouble(i)) / 10.0;\n let isCorrect = DistinguishTwoStates(\n StatePrep_IsQubitA(alpha, _, _),\n Kata.IsQubitA(alpha, _),\n [$\"|B⟩ = -i sin({i}π/10)|0⟩ + cos({i}π/10)|1⟩\", $\"|A⟩ = cos({i}π/10)|0⟩ + i sin({i}π/10)|1⟩\"],\n false);\n if not isCorrect {\n Message(\"Incorrect.\");\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
4324
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Katas;\n\n // Distinguish states |A❭ and |B❭\n // |A⟩ = cos(alpha) * |0⟩ - i sin(alpha) * |1⟩,\n // |B⟩ = - i sin(alpha) * |0⟩ + cos(alpha) * |1⟩.\n operation StatePrep_IsQubitA(alpha : Double, q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |B⟩\n X(q);\n Rx(2.0 * alpha, q);\n } else {\n // convert |0⟩ to |A⟩\n Rx(2.0 * alpha, q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let alpha = (PI() * IntAsDouble(i)) / 10.0;\n let isCorrect = DistinguishTwoStates_SingleQubit(\n StatePrep_IsQubitA(alpha, _, _),\n Kata.IsQubitA(alpha, _),\n [$\"|B⟩ = -i sin({i}π/10)|0⟩ + cos({i}π/10)|1⟩\", $\"|A⟩ = cos({i}π/10)|0⟩ + i sin({i}π/10)|1⟩\"],\n false);\n if not isCorrect {\n Message(\"Incorrect.\");\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
3921
4325
  },
3922
4326
  {
3923
4327
  "id": "single_qubit_measurements__a_b_basis_measurements__Verification.qs",
3924
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n\n // Measure state in {|A❭, |B❭} basis\n // |A⟩ = cos(alpha) * |0⟩ - i sin(alpha) * |1⟩,\n // |B⟩ = - i sin(alpha) * |0⟩ + cos(alpha) * |1⟩.\n operation StatePrep_IsQubitA (alpha : Double, q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |B⟩\n X(q);\n Rx(2.0 * alpha, q);\n } else {\n // convert |0⟩ to |A⟩\n Rx(2.0 * alpha, q);\n }\n }\n\n // We can use the StatePrep_IsQubitA operation for the testing\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let alpha = (PI() * IntAsDouble(i)) / 10.0;\n let isCorrect = DistinguishTwoStates(\n StatePrep_IsQubitA(alpha, _, _),\n q => Kata.MeasureInABBasis(alpha, q) == Zero,\n [$\"|B⟩=(-i sin({i}π/10)|0⟩ + cos({i}π/10)|1⟩)\", $\"|A⟩=(cos({i}π/10)|0⟩ + i sin({i}π/10)|1⟩)\"],\n true);\n if not isCorrect {\n Message($\"Test fails for alpha={alpha}\");\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
4328
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Katas;\n\n // Measure state in {|A❭, |B❭} basis\n // |A⟩ = cos(alpha) * |0⟩ - i sin(alpha) * |1⟩,\n // |B⟩ = - i sin(alpha) * |0⟩ + cos(alpha) * |1⟩.\n operation StatePrep_IsQubitA (alpha : Double, q : Qubit, state : Int) : Unit is Adj {\n if state == 0 {\n // convert |0⟩ to |B⟩\n X(q);\n Rx(2.0 * alpha, q);\n } else {\n // convert |0⟩ to |A⟩\n Rx(2.0 * alpha, q);\n }\n }\n\n // We can use the StatePrep_IsQubitA operation for the testing\n operation CheckSolution() : Bool {\n for i in 0 .. 10 {\n let alpha = (PI() * IntAsDouble(i)) / 10.0;\n let isCorrect = DistinguishTwoStates_SingleQubit(\n StatePrep_IsQubitA(alpha, _, _),\n q => Kata.MeasureInABBasis(alpha, q) == Zero,\n [$\"|B⟩=(-i sin({i}π/10)|0⟩ + cos({i}π/10)|1⟩)\", $\"|A⟩=(cos({i}π/10)|0⟩ + i sin({i}π/10)|1⟩)\"],\n true);\n if not isCorrect {\n Message($\"Test fails for alpha={alpha}\");\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
3925
4329
  },
3926
4330
  {
3927
4331
  "id": "multi_qubit_measurements__full_measurements__Verification.qs",
3928
- "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"
3929
- },
3930
- {
3931
- "id": "multi_qubit_measurements__Common.qs",
3932
- "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"
4332
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\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"
3933
4333
  },
3934
4334
  {
3935
4335
  "id": "multi_qubit_measurements__partial_measurements_for_system__Verification.qs",
3936
- "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"
4336
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\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"
3937
4337
  },
3938
4338
  {
3939
4339
  "id": "multi_qubit_measurements__state_modification__Verification.qs",
@@ -3941,11 +4341,11 @@ export default {
3941
4341
  },
3942
4342
  {
3943
4343
  "id": "multi_qubit_measurements__state_preparation__Verification.qs",
3944
- "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"
4344
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n // Reference solution that does not use measurements (to be adjointable)\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 CheckOperationsEquivalenceOnZeroStateWithFeedback(Kata.PostSelection, StatePrep_Rotations, 2)\n }\n}\n"
3945
4345
  },
3946
4346
  {
3947
4347
  "id": "multi_qubit_measurements__joint_measurements__Verification.qs",
3948
- "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"
4348
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\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"
3949
4349
  },
3950
4350
  {
3951
4351
  "id": "random_numbers__random_bit__Verification.qs",
@@ -3981,35 +4381,35 @@ export default {
3981
4381
  },
3982
4382
  {
3983
4383
  "id": "oracles__phase_oracle_seven__Verification.qs",
3984
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation IsSeven_PhaseOracle_Reference(x : Qubit[]) : Unit is Adj + Ctl {\n Controlled Z(Most(x), Tail(x));\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let N = 3;\n let isCorrect = CheckOperationsEquivalenceStrict(\n Kata.IsSeven_PhaseOracle,\n IsSeven_PhaseOracle_Reference,\n 3);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n \"transformation\");\n use initial = Qubit[3]; // |000〉\n PrepRandomState(initial);\n ShowQuantumStateComparison(initial, Kata.IsSeven_PhaseOracle, IsSeven_PhaseOracle_Reference);\n ResetAll(initial);\n }\n isCorrect\n }\n}\n"
4384
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation IsSeven_PhaseOracle_Reference(x : Qubit[]) : Unit is Adj + Ctl {\n Controlled Z(Most(x), Tail(x));\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let N = 3;\n let isCorrect = CheckOperationsEquivalenceStrict(\n Kata.IsSeven_PhaseOracle,\n IsSeven_PhaseOracle_Reference,\n 3);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n \"transformation\");\n ShowQuantumStateComparison(3, PrepRandomState, Kata.IsSeven_PhaseOracle, IsSeven_PhaseOracle_Reference);\n }\n isCorrect\n }\n}\n"
3985
4385
  },
3986
4386
  {
3987
4387
  "id": "oracles__marking_oracle_seven__Verification.qs",
3988
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation IsSeven_MarkingOracle_Reference(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n Controlled X(x, y);\n }\n\n // ------------------------------------------------------\n @EntryPoint()\n operation CheckSolution () : Bool {\n let N = 3;\n let sol = ApplyOracle(_, Kata.IsSeven_MarkingOracle);\n let ref = ApplyOracle(_, IsSeven_MarkingOracle_Reference);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n \"transformation\");\n use initial = Qubit[4]; // |000〉\n PrepRandomState(initial[...2]);\n ShowQuantumStateComparison(initial, sol, ref);\n ResetAll(initial);\n }\n isCorrect\n }\n}\n"
4388
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation IsSeven_MarkingOracle_Reference(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n Controlled X(x, y);\n }\n\n // ------------------------------------------------------\n @EntryPoint()\n operation CheckSolution () : Bool {\n let N = 3;\n let sol = ApplyOracle(_, Kata.IsSeven_MarkingOracle);\n let ref = ApplyOracle(_, IsSeven_MarkingOracle_Reference);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n \"transformation\");\n ShowQuantumStateComparison(4, qs => PrepRandomState(qs[...2]), sol, ref);\n }\n isCorrect\n }\n}\n"
3989
4389
  },
3990
4390
  {
3991
4391
  "id": "oracles__marking_oracle_as_phase__Verification.qs",
3992
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Random;\n\n operation ApplyMarkingOracleAsPhaseOracle_Reference(\n markingOracle : ((Qubit[], Qubit) => Unit is Adj + Ctl),\n qubits : Qubit[]) : Unit is Adj + Ctl {\n\n use minus = Qubit();\n within {\n X(minus);\n H(minus);\n } apply {\n markingOracle(qubits, minus);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N - 1 {\n let pattern = IntAsBoolArray(k, N);\n let marking = ApplyControlledOnBitString(pattern, X, _, _);\n let sol = Kata.ApplyMarkingOracleAsPhaseOracle(marking, _);\n let ref = ApplyMarkingOracleAsPhaseOracle_Reference(marking, _);\n\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle that marks the bit string {pattern}\");\n use initial = Qubit[N];\n PrepRandomState(initial);\n ShowQuantumStateComparison(initial, sol, ref);\n ResetAll(initial);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
4392
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Random;\n\n operation ApplyMarkingOracleAsPhaseOracle_Reference(\n markingOracle : ((Qubit[], Qubit) => Unit is Adj + Ctl),\n qubits : Qubit[]) : Unit is Adj + Ctl {\n\n use minus = Qubit();\n within {\n X(minus);\n H(minus);\n } apply {\n markingOracle(qubits, minus);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N - 1 {\n let pattern = IntAsBoolArray(k, N);\n let marking = ApplyControlledOnBitString(pattern, X, _, _);\n let sol = Kata.ApplyMarkingOracleAsPhaseOracle(marking, _);\n let ref = ApplyMarkingOracleAsPhaseOracle_Reference(marking, _);\n\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle that marks the bit string {pattern}\");\n ShowQuantumStateComparison(N, PrepRandomState, sol, ref);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
3993
4393
  },
3994
4394
  {
3995
4395
  "id": "oracles__or_oracle__Verification.qs",
3996
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Random;\n\n operation Or_Oracle_Reference(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n X(y);\n ApplyControlledOnInt(0, X, x, y);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n let sol = ApplyOracle(_, Kata.Or_Oracle);\n let ref = ApplyOracle(_, Or_Oracle_Reference);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle\");\n use initial = Qubit[N + 1];\n PrepRandomState(initial[...N - 1]);\n ShowQuantumStateComparison(initial, sol, ref);\n ResetAll(initial);\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
4396
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Random;\n\n operation Or_Oracle_Reference(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n X(y);\n ApplyControlledOnInt(0, X, x, y);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n let sol = ApplyOracle(_, Kata.Or_Oracle);\n let ref = ApplyOracle(_, Or_Oracle_Reference);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle\");\n ShowQuantumStateComparison(N + 1, qs => PrepRandomState(qs[...N - 1]), sol, ref);\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
3997
4397
  },
3998
4398
  {
3999
4399
  "id": "oracles__kth_bit_oracle__Verification.qs",
4000
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation KthBit_Oracle_Reference(x : Qubit[], k : Int) : Unit is Adj + Ctl {\n Z(x[k]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. N - 1 {\n let sol = Kata.KthBit_Oracle(_, k);\n let ref = KthBit_Oracle_Reference(_, k);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for k = {k}\");\n use initial = Qubit[N];\n PrepRandomState(initial);\n ShowQuantumStateComparison(initial, sol, ref);\n ResetAll(initial);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
4400
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation KthBit_Oracle_Reference(x : Qubit[], k : Int) : Unit is Adj + Ctl {\n Z(x[k]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. N - 1 {\n let sol = Kata.KthBit_Oracle(_, k);\n let ref = KthBit_Oracle_Reference(_, k);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for k = {k}\");\n ShowQuantumStateComparison(N, PrepRandomState, sol, ref);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
4001
4401
  },
4002
4402
  {
4003
4403
  "id": "oracles__or_but_kth_oracle__Verification.qs",
4004
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation Or_Oracle_Reference(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n X(y);\n ApplyControlledOnInt(0, X, x, y);\n }\n\n operation OrOfBitsExceptKth_Oracle_Reference(x : Qubit[], k : Int) : Unit is Adj + Ctl {\n use minus = Qubit();\n within {\n X(minus);\n H(minus);\n } apply {\n Or_Oracle_Reference(x[...k-1] + x[k+1...], minus);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 2 .. 4 {\n for k in 0 .. N - 1 {\n let sol = Kata.OrOfBitsExceptKth_Oracle(_, k);\n let ref = OrOfBitsExceptKth_Oracle_Reference(_, k);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for k = {k}\");\n use initial = Qubit[N];\n PrepRandomState(initial);\n ShowQuantumStateComparison(initial, sol, ref);\n ResetAll(initial);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
4404
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation Or_Oracle_Reference(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n X(y);\n ApplyControlledOnInt(0, X, x, y);\n }\n\n operation OrOfBitsExceptKth_Oracle_Reference(x : Qubit[], k : Int) : Unit is Adj + Ctl {\n use minus = Qubit();\n within {\n X(minus);\n H(minus);\n } apply {\n Or_Oracle_Reference(x[...k-1] + x[k+1...], minus);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 2 .. 4 {\n for k in 0 .. N - 1 {\n let sol = Kata.OrOfBitsExceptKth_Oracle(_, k);\n let ref = OrOfBitsExceptKth_Oracle_Reference(_, k);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for k = {k}\");\n ShowQuantumStateComparison(N, PrepRandomState, sol, ref);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
4005
4405
  },
4006
4406
  {
4007
4407
  "id": "oracles__bit_pattern_oracle__Verification.qs",
4008
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n\n operation ArbitraryBitPattern_Oracle_Reference(x : Qubit[], y : Qubit, pattern : Bool[]) : Unit is Adj + Ctl {\n ApplyControlledOnBitString(pattern, X, x, y);\n }\n\n // ------------------------------------------------------\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N - 1 {\n let pattern = IntAsBoolArray(k, N);\n\n let sol = ApplyOracle(_, Kata.ArbitraryBitPattern_Oracle(_, _, pattern));\n let ref = ApplyOracle(_, ArbitraryBitPattern_Oracle_Reference(_, _, pattern));\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for the pattern {pattern}\");\n use initial = Qubit[N + 1];\n PrepRandomState(initial[...N - 1]);\n ShowQuantumStateComparison(initial, sol, ref);\n ResetAll(initial);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
4408
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n\n operation ArbitraryBitPattern_Oracle_Reference(x : Qubit[], y : Qubit, pattern : Bool[]) : Unit is Adj + Ctl {\n ApplyControlledOnBitString(pattern, X, x, y);\n }\n\n // ------------------------------------------------------\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N - 1 {\n let pattern = IntAsBoolArray(k, N);\n\n let sol = ApplyOracle(_, Kata.ArbitraryBitPattern_Oracle(_, _, pattern));\n let ref = ApplyOracle(_, ArbitraryBitPattern_Oracle_Reference(_, _, pattern));\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for the pattern {pattern}\");\n ShowQuantumStateComparison(N + 1, qs => PrepRandomState(qs[...N - 1]), sol, ref);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
4009
4409
  },
4010
4410
  {
4011
4411
  "id": "oracles__bit_pattern_challenge__Verification.qs",
4012
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n\n operation ArbitraryBitPattern_Oracle_Challenge_Reference(x : Qubit[], pattern : Bool[]) : Unit is Adj + Ctl {\n within {\n for i in IndexRange(x) {\n if not pattern[i] {\n X(x[i]);\n }\n }\n } apply {\n Controlled Z(Most(x), Tail(x));\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N -1 {\n let pattern = IntAsBoolArray(k, N);\n\n let sol = Kata.ArbitraryBitPattern_Oracle_Challenge(_, pattern);\n let ref = ArbitraryBitPattern_Oracle_Challenge_Reference(_, pattern);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for pattern = {pattern}\");\n use initial = Qubit[N];\n PrepRandomState(initial);\n ShowQuantumStateComparison(initial, sol, ref);\n ResetAll(initial);\n return false;\n }\n }\n }\n Message(\"All tests passed.\");\n true\n }\n}\n"
4412
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n\n operation ArbitraryBitPattern_Oracle_Challenge_Reference(x : Qubit[], pattern : Bool[]) : Unit is Adj + Ctl {\n within {\n for i in IndexRange(x) {\n if not pattern[i] {\n X(x[i]);\n }\n }\n } apply {\n Controlled Z(Most(x), Tail(x));\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N -1 {\n let pattern = IntAsBoolArray(k, N);\n\n let sol = Kata.ArbitraryBitPattern_Oracle_Challenge(_, pattern);\n let ref = ArbitraryBitPattern_Oracle_Challenge_Reference(_, pattern);\n let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle for pattern = {pattern}\");\n ShowQuantumStateComparison(N, PrepRandomState, sol, ref);\n return false;\n }\n }\n }\n Message(\"All tests passed.\");\n true\n }\n}\n"
4013
4413
  },
4014
4414
  {
4015
4415
  "id": "oracles__meeting_oracle__Verification.qs",
@@ -4017,7 +4417,7 @@ export default {
4017
4417
  },
4018
4418
  {
4019
4419
  "id": "deutsch_algo__one_minus_x_oracle__Verification.qs",
4020
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PhaseOracle_OneMinusX_Reference(x : Qubit) : Unit is Adj + Ctl {\n Z(x);\n R(PauliI, 2.0 * PI(), x);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.PhaseOracle_OneMinusX(register[0]);\n let reference = register => PhaseOracle_OneMinusX_Reference(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have. Note that the simulator might drop the global phase -1, so if you're getting \" +\n \"verdict \\\"Incorrect\\\" but the actual state matches the expected one, check that you're handling the global phase correctly.\");\n use initial = Qubit(); // |0〉\n Ry(ArcTan2(0.8, 0.6) * 2.0, initial); // 0.6|0〉 + 0.8|1〉\n ShowQuantumStateComparison([initial], solution, reference);\n Reset(initial);\n }\n isCorrect\n }\n}\n"
4420
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PhaseOracle_OneMinusX_Reference(x : Qubit) : Unit is Adj + Ctl {\n Z(x);\n R(PauliI, 2.0 * PI(), x);\n }\n\n operation CheckSolution() : Bool {\n let solution = register => Kata.PhaseOracle_OneMinusX(register[0]);\n let reference = register => PhaseOracle_OneMinusX_Reference(register[0]);\n let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 1);\n\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n Message(\"Hint: examine the effect your solution has on the state 0.6|0〉 + 0.8|1〉 and compare it with the effect it \" +\n \"is expected to have. Note that the simulator might drop the global phase -1, so if you're getting \" +\n \"verdict \\\"Incorrect\\\" but the actual state matches the expected one, check that you're handling the global phase correctly.\");\n ShowQuantumStateComparison(1, (qs => Ry(ArcTan2(0.8, 0.6) * 2.0, qs[0])), solution, reference);\n }\n isCorrect\n }\n}\n"
4021
4421
  },
4022
4422
  {
4023
4423
  "id": "deutsch_algo__implement_algo__Verification.qs",
@@ -4025,11 +4425,11 @@ export default {
4025
4425
  },
4026
4426
  {
4027
4427
  "id": "deutsch_jozsa__msb_oracle__Verification.qs",
4028
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PhaseOracle_MostSignificantBit_Reference(x : Qubit[]) : Unit is Adj + Ctl {\n Z(x[0]);\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.PhaseOracle_MostSignificantBit;\n let reference = PhaseOracle_MostSignificantBit_Reference;\n for N in 1 .. 4 {\n if not CheckOperationsEquivalenceStrict(solution, reference, N) {\n Message(\"Incorrect.\");\n Message($\"Hint: examine the effect your solution has on the {N}-qubit and compare it with the effect it \" +\n \"is expected to have. Note that the simulator might drop the global phase -1, so if you're getting \" +\n \"verdict \\\"Incorrect\\\" but the actual state matches the expected one, check that you're handling the global phase correctly.\");\n use initial = Qubit[N];\n PrepRandomState(initial);\n ShowQuantumStateComparison(initial, solution, reference);\n ResetAll(initial);\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
4428
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PhaseOracle_MostSignificantBit_Reference(x : Qubit[]) : Unit is Adj + Ctl {\n Z(x[0]);\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.PhaseOracle_MostSignificantBit;\n let reference = PhaseOracle_MostSignificantBit_Reference;\n for N in 1 .. 4 {\n if not CheckOperationsEquivalenceStrict(solution, reference, N) {\n Message(\"Incorrect.\");\n Message($\"Hint: examine the effect your solution has on the {N}-qubit and compare it with the effect it \" +\n \"is expected to have. Note that the simulator might drop the global phase -1, so if you're getting \" +\n \"verdict \\\"Incorrect\\\" but the actual state matches the expected one, check that you're handling the global phase correctly.\");\n ShowQuantumStateComparison(N, PrepRandomState, solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
4029
4429
  },
4030
4430
  {
4031
4431
  "id": "deutsch_jozsa__parity_oracle__Verification.qs",
4032
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PhaseOracle_Parity_Reference(x : Qubit[]) : Unit is Adj + Ctl {\n for xi in x {\n Z(xi);\n }\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.PhaseOracle_Parity;\n let reference = PhaseOracle_Parity_Reference;\n for N in 1 .. 4 {\n if not CheckOperationsEquivalenceStrict(solution, reference, N) {\n Message(\"Incorrect.\");\n Message($\"Hint: examine the effect your solution has on the {N}-qubit and compare it with the effect it \" +\n \"is expected to have. Note that the simulator might drop the global phase -1, so if you're getting \" +\n \"verdict \\\"Incorrect\\\" but the actual state matches the expected one, check that you're handling the global phase correctly.\");\n use initial = Qubit[N];\n PrepRandomState(initial);\n ShowQuantumStateComparison(initial, solution, reference);\n ResetAll(initial);\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
4432
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation PhaseOracle_Parity_Reference(x : Qubit[]) : Unit is Adj + Ctl {\n for xi in x {\n Z(xi);\n }\n }\n\n operation CheckSolution() : Bool {\n let solution = Kata.PhaseOracle_Parity;\n let reference = PhaseOracle_Parity_Reference;\n for N in 1 .. 4 {\n if not CheckOperationsEquivalenceStrict(solution, reference, N) {\n Message(\"Incorrect.\");\n Message($\"Hint: examine the effect your solution has on the {N}-qubit and compare it with the effect it \" +\n \"is expected to have. Note that the simulator might drop the global phase -1, so if you're getting \" +\n \"verdict \\\"Incorrect\\\" but the actual state matches the expected one, check that you're handling the global phase correctly.\");\n ShowQuantumStateComparison(N, PrepRandomState, solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
4033
4433
  },
4034
4434
  {
4035
4435
  "id": "deutsch_jozsa__implement_dj__Verification.qs",