qsharp-lang 1.3.5-dev → 1.3.6-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +273 -77
  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 +1 -1
  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 +1 -1
  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 +1 -1
  65. package/docs/Microsoft.Quantum.Canon/CZ.md +1 -1
  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 +1 -1
  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 +1 -1
  77. package/docs/Microsoft.Quantum.Convert/IntAsBoolArray.md +1 -1
  78. package/docs/Microsoft.Quantum.Convert/IntAsDouble.md +1 -1
  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 +1 -1
  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 +1 -1
  87. package/docs/Microsoft.Quantum.Core/RangeStep.md +1 -1
  88. package/docs/Microsoft.Quantum.Core/Repeated.md +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -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 +1 -1
  220. package/docs/Microsoft.Quantum.Measurement/MeasureEachZ.md +1 -1
  221. package/docs/Microsoft.Quantum.Measurement/MeasureInteger.md +1 -1
  222. package/docs/Microsoft.Quantum.Random/DrawRandomDouble.md +1 -1
  223. package/docs/Microsoft.Quantum.Random/DrawRandomInt.md +1 -1
  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 -1
  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 -1
  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 -1
  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 +1 -1
  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 +1 -1
  255. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLUsingIncByLE.md +1 -1
  256. package/docs/Microsoft.Quantum.Unstable.Arithmetic/LookAheadDKRSAddLE.md +1 -1
  257. package/docs/Microsoft.Quantum.Unstable.Arithmetic/MAJ.md +1 -1
  258. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ReflectAboutInteger.md +1 -1
  259. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGAddLE.md +1 -1
  260. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGIncByLE.md +1 -1
  261. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryTTKIncByLE.md +1 -1
  262. package/docs/Microsoft.Quantum.Unstable.StatePreparation/ApproximatelyPreparePureStateCP.md +1 -1
  263. package/docs/Microsoft.Quantum.Unstable.StatePreparation/PreparePureStateD.md +1 -1
  264. package/docs/Microsoft.Quantum.Unstable.TableLookup/Select.md +1 -1
  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",
@@ -2144,8 +2334,7 @@ export default {
2144
2334
  },
2145
2335
  "sourceIds": [
2146
2336
  "single_qubit_measurements__distinguish_0_and_1__Verification.qs",
2147
- "KatasLibrary.qs",
2148
- "single_qubit_measurements__Common.qs"
2337
+ "KatasLibrary.qs"
2149
2338
  ],
2150
2339
  "placeholderCode": "namespace Kata {\n operation IsQubitZero(q : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
2151
2340
  "explainedSolution": {
@@ -2187,8 +2376,7 @@ export default {
2187
2376
  },
2188
2377
  "sourceIds": [
2189
2378
  "single_qubit_measurements__distinguish_plus_and_minus__Verification.qs",
2190
- "KatasLibrary.qs",
2191
- "single_qubit_measurements__Common.qs"
2379
+ "KatasLibrary.qs"
2192
2380
  ],
2193
2381
  "placeholderCode": "namespace Kata {\n operation IsQubitMinus(q : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
2194
2382
  "explainedSolution": {
@@ -2230,8 +2418,7 @@ export default {
2230
2418
  },
2231
2419
  "sourceIds": [
2232
2420
  "single_qubit_measurements__distinguish_orthogonal_states_1__Verification.qs",
2233
- "KatasLibrary.qs",
2234
- "single_qubit_measurements__Common.qs"
2421
+ "KatasLibrary.qs"
2235
2422
  ],
2236
2423
  "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
2424
  "explainedSolution": {
@@ -2261,8 +2448,7 @@ export default {
2261
2448
  },
2262
2449
  "sourceIds": [
2263
2450
  "single_qubit_measurements__distinguish_orthogonal_states_2__Verification.qs",
2264
- "KatasLibrary.qs",
2265
- "single_qubit_measurements__Common.qs"
2451
+ "KatasLibrary.qs"
2266
2452
  ],
2267
2453
  "placeholderCode": "namespace Kata {\n operation IsQubitA(alpha : Double, q : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
2268
2454
  "explainedSolution": {
@@ -2292,8 +2478,7 @@ export default {
2292
2478
  },
2293
2479
  "sourceIds": [
2294
2480
  "single_qubit_measurements__a_b_basis_measurements__Verification.qs",
2295
- "KatasLibrary.qs",
2296
- "single_qubit_measurements__Common.qs"
2481
+ "KatasLibrary.qs"
2297
2482
  ],
2298
2483
  "placeholderCode": "namespace Kata {\n operation MeasureInABBasis(alpha : Double, q : Qubit) : Result {\n // Implement your solution here...\n\n return Zero;\n }\n}\n",
2299
2484
  "explainedSolution": {
@@ -2397,7 +2582,6 @@ export default {
2397
2582
  },
2398
2583
  "sourceIds": [
2399
2584
  "multi_qubit_measurements__full_measurements__Verification.qs",
2400
- "multi_qubit_measurements__Common.qs",
2401
2585
  "KatasLibrary.qs"
2402
2586
  ],
2403
2587
  "placeholderCode": "namespace Kata {\n operation BasisStateMeasurement(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n}\n",
@@ -2472,7 +2656,6 @@ export default {
2472
2656
  },
2473
2657
  "sourceIds": [
2474
2658
  "multi_qubit_measurements__partial_measurements_for_system__Verification.qs",
2475
- "multi_qubit_measurements__Common.qs",
2476
2659
  "KatasLibrary.qs"
2477
2660
  ],
2478
2661
  "placeholderCode": "namespace Kata {\n operation IsPlusPlusMinus(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n}\n",
@@ -2515,7 +2698,6 @@ export default {
2515
2698
  },
2516
2699
  "sourceIds": [
2517
2700
  "multi_qubit_measurements__state_modification__Verification.qs",
2518
- "multi_qubit_measurements__Common.qs",
2519
2701
  "KatasLibrary.qs"
2520
2702
  ],
2521
2703
  "placeholderCode": "namespace Kata {\n operation StateSelection(qs : Qubit[], ind : Int) : Unit {\n // Implement your solution here...\n\n }\n}\n",
@@ -2558,7 +2740,6 @@ export default {
2558
2740
  },
2559
2741
  "sourceIds": [
2560
2742
  "multi_qubit_measurements__state_preparation__Verification.qs",
2561
- "multi_qubit_measurements__Common.qs",
2562
2743
  "KatasLibrary.qs"
2563
2744
  ],
2564
2745
  "placeholderCode": "namespace Kata {\n operation PostSelection(qs : Qubit[]) : Unit {\n // Implement your solution here...\n\n }\n}\n",
@@ -2601,7 +2782,6 @@ export default {
2601
2782
  },
2602
2783
  "sourceIds": [
2603
2784
  "multi_qubit_measurements__joint_measurements__Verification.qs",
2604
- "multi_qubit_measurements__Common.qs",
2605
2785
  "KatasLibrary.qs"
2606
2786
  ],
2607
2787
  "placeholderCode": "namespace Kata {\n operation ParityMeasurement(qs : Qubit[]) : Int {\n // Implement your solution here...\n\n return -1;\n }\n}\n",
@@ -3721,11 +3901,11 @@ export default {
3721
3901
  "globalCodeSources": [
3722
3902
  {
3723
3903
  "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"
3904
+ "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
3905
  },
3726
3906
  {
3727
3907
  "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"
3908
+ "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
3909
  },
3730
3910
  {
3731
3911
  "id": "complex_arithmetic__powers_of_i__Verification.qs",
@@ -3829,35 +4009,59 @@ export default {
3829
4009
  },
3830
4010
  {
3831
4011
  "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}"
4012
+ "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}"
4013
+ },
4014
+ {
4015
+ "id": "single_qubit_gates__sign_flip__Verification.qs",
4016
+ "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
4017
  },
3834
4018
  {
3835
4019
  "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"
4020
+ "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"
4021
+ },
4022
+ {
4023
+ "id": "single_qubit_gates__sign_flip_on_zero__Verification.qs",
4024
+ "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"
4025
+ },
4026
+ {
4027
+ "id": "single_qubit_gates__global_phase_minusone__Verification.qs",
4028
+ "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
4029
  },
3838
4030
  {
3839
4031
  "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"
4032
+ "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
4033
  },
3842
4034
  {
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"
4035
+ "id": "single_qubit_gates__basis_change__Verification.qs",
4036
+ "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
4037
  },
3846
4038
  {
3847
4039
  "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"
4040
+ "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"
4041
+ },
4042
+ {
4043
+ "id": "single_qubit_gates__phase_i__Verification.qs",
4044
+ "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
4045
  },
3850
4046
  {
3851
4047
  "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"
4048
+ "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"
4049
+ },
4050
+ {
4051
+ "id": "single_qubit_gates__complex_phase__Verification.qs",
4052
+ "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}"
4053
+ },
4054
+ {
4055
+ "id": "single_qubit_gates__amplitude_change__Verification.qs",
4056
+ "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
4057
  },
3854
4058
  {
3855
4059
  "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"
4060
+ "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
4061
  },
3858
4062
  {
3859
4063
  "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"
4064
+ "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
4065
  },
3862
4066
  {
3863
4067
  "id": "multi_qubit_systems__learn_basis_state_amplitudes__Verification.qs",
@@ -3881,11 +4085,11 @@ export default {
3881
4085
  },
3882
4086
  {
3883
4087
  "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}"
4088
+ "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}"
3885
4089
  },
3886
4090
  {
3887
4091
  "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}"
4092
+ "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}"
3889
4093
  },
3890
4094
  {
3891
4095
  "id": "multi_qubit_gates__qubit_swap__Verification.qs",
@@ -3901,39 +4105,31 @@ export default {
3901
4105
  },
3902
4106
  {
3903
4107
  "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"
4108
+ "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
4109
  },
3910
4110
  {
3911
4111
  "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"
4112
+ "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
4113
  },
3914
4114
  {
3915
4115
  "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"
4116
+ "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
4117
  },
3918
4118
  {
3919
4119
  "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"
4120
+ "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
4121
  },
3922
4122
  {
3923
4123
  "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"
4124
+ "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
4125
  },
3926
4126
  {
3927
4127
  "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"
4128
+ "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
4129
  },
3934
4130
  {
3935
4131
  "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"
4132
+ "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
4133
  },
3938
4134
  {
3939
4135
  "id": "multi_qubit_measurements__state_modification__Verification.qs",
@@ -3941,11 +4137,11 @@ export default {
3941
4137
  },
3942
4138
  {
3943
4139
  "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"
4140
+ "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
4141
  },
3946
4142
  {
3947
4143
  "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"
4144
+ "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
4145
  },
3950
4146
  {
3951
4147
  "id": "random_numbers__random_bit__Verification.qs",
@@ -3981,35 +4177,35 @@ export default {
3981
4177
  },
3982
4178
  {
3983
4179
  "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"
4180
+ "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
4181
  },
3986
4182
  {
3987
4183
  "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"
4184
+ "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
4185
  },
3990
4186
  {
3991
4187
  "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"
4188
+ "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
4189
  },
3994
4190
  {
3995
4191
  "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"
4192
+ "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
4193
  },
3998
4194
  {
3999
4195
  "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"
4196
+ "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
4197
  },
4002
4198
  {
4003
4199
  "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"
4200
+ "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
4201
  },
4006
4202
  {
4007
4203
  "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"
4204
+ "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
4205
  },
4010
4206
  {
4011
4207
  "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"
4208
+ "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
4209
  },
4014
4210
  {
4015
4211
  "id": "oracles__meeting_oracle__Verification.qs",
@@ -4017,7 +4213,7 @@ export default {
4017
4213
  },
4018
4214
  {
4019
4215
  "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"
4216
+ "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
4217
  },
4022
4218
  {
4023
4219
  "id": "deutsch_algo__implement_algo__Verification.qs",
@@ -4025,11 +4221,11 @@ export default {
4025
4221
  },
4026
4222
  {
4027
4223
  "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"
4224
+ "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
4225
  },
4030
4226
  {
4031
4227
  "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"
4228
+ "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
4229
  },
4034
4230
  {
4035
4231
  "id": "deutsch_jozsa__implement_dj__Verification.qs",