qsharp-lang 1.6.9-dev → 1.7.1-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 (297) hide show
  1. package/dist/katas-content.generated.js +1277 -95
  2. package/dist/katas-content.generated.md.js +1278 -96
  3. package/dist/samples.generated.js +1 -1
  4. package/docs/Microsoft.Quantum.Arrays/All.md +1 -1
  5. package/docs/Microsoft.Quantum.Arrays/Any.md +1 -1
  6. package/docs/Microsoft.Quantum.Arrays/Chunks.md +1 -1
  7. package/docs/Microsoft.Quantum.Arrays/CircularlyShifted.md +1 -1
  8. package/docs/Microsoft.Quantum.Arrays/ColumnAt.md +1 -1
  9. package/docs/Microsoft.Quantum.Arrays/Count.md +1 -1
  10. package/docs/Microsoft.Quantum.Arrays/Diagonal.md +1 -1
  11. package/docs/Microsoft.Quantum.Arrays/DrawMany.md +1 -1
  12. package/docs/Microsoft.Quantum.Arrays/Enumerated.md +1 -1
  13. package/docs/Microsoft.Quantum.Arrays/Excluding.md +1 -1
  14. package/docs/Microsoft.Quantum.Arrays/Filtered.md +1 -1
  15. package/docs/Microsoft.Quantum.Arrays/FlatMapped.md +1 -1
  16. package/docs/Microsoft.Quantum.Arrays/Flattened.md +1 -1
  17. package/docs/Microsoft.Quantum.Arrays/Fold.md +1 -1
  18. package/docs/Microsoft.Quantum.Arrays/ForEach.md +1 -1
  19. package/docs/Microsoft.Quantum.Arrays/Head.md +1 -1
  20. package/docs/Microsoft.Quantum.Arrays/HeadAndRest.md +1 -1
  21. package/docs/Microsoft.Quantum.Arrays/IndexOf.md +1 -1
  22. package/docs/Microsoft.Quantum.Arrays/IndexRange.md +1 -1
  23. package/docs/Microsoft.Quantum.Arrays/Interleaved.md +1 -1
  24. package/docs/Microsoft.Quantum.Arrays/IsEmpty.md +1 -1
  25. package/docs/Microsoft.Quantum.Arrays/IsRectangularArray.md +1 -1
  26. package/docs/Microsoft.Quantum.Arrays/IsSorted.md +1 -1
  27. package/docs/Microsoft.Quantum.Arrays/IsSquareArray.md +1 -1
  28. package/docs/Microsoft.Quantum.Arrays/Mapped.md +1 -1
  29. package/docs/Microsoft.Quantum.Arrays/MappedByIndex.md +1 -1
  30. package/docs/Microsoft.Quantum.Arrays/MappedOverRange.md +1 -1
  31. package/docs/Microsoft.Quantum.Arrays/Most.md +1 -1
  32. package/docs/Microsoft.Quantum.Arrays/MostAndTail.md +1 -1
  33. package/docs/Microsoft.Quantum.Arrays/Padded.md +1 -1
  34. package/docs/Microsoft.Quantum.Arrays/Partitioned.md +1 -1
  35. package/docs/Microsoft.Quantum.Arrays/Rest.md +1 -1
  36. package/docs/Microsoft.Quantum.Arrays/Reversed.md +1 -1
  37. package/docs/Microsoft.Quantum.Arrays/SequenceI.md +1 -1
  38. package/docs/Microsoft.Quantum.Arrays/SequenceL.md +1 -1
  39. package/docs/Microsoft.Quantum.Arrays/Sorted.md +1 -1
  40. package/docs/Microsoft.Quantum.Arrays/Subarray.md +1 -1
  41. package/docs/Microsoft.Quantum.Arrays/Swapped.md +1 -1
  42. package/docs/Microsoft.Quantum.Arrays/Tail.md +1 -1
  43. package/docs/Microsoft.Quantum.Arrays/Transposed.md +1 -1
  44. package/docs/Microsoft.Quantum.Arrays/Unzipped.md +1 -1
  45. package/docs/Microsoft.Quantum.Arrays/Where.md +1 -1
  46. package/docs/Microsoft.Quantum.Arrays/Windows.md +1 -1
  47. package/docs/Microsoft.Quantum.Arrays/Zipped.md +1 -1
  48. package/docs/Microsoft.Quantum.Canon/ApplyCNOTChain.md +1 -1
  49. package/docs/Microsoft.Quantum.Canon/ApplyControlledOnBitString.md +1 -1
  50. package/docs/Microsoft.Quantum.Canon/ApplyControlledOnInt.md +1 -1
  51. package/docs/Microsoft.Quantum.Canon/ApplyP.md +1 -1
  52. package/docs/Microsoft.Quantum.Canon/ApplyPauli.md +1 -1
  53. package/docs/Microsoft.Quantum.Canon/ApplyPauliFromBitString.md +1 -1
  54. package/docs/Microsoft.Quantum.Canon/ApplyPauliFromInt.md +1 -1
  55. package/docs/Microsoft.Quantum.Canon/ApplyQFT.md +11 -6
  56. package/docs/Microsoft.Quantum.Canon/ApplyToEach.md +1 -1
  57. package/docs/Microsoft.Quantum.Canon/ApplyToEachA.md +1 -1
  58. package/docs/Microsoft.Quantum.Canon/ApplyToEachC.md +1 -1
  59. package/docs/Microsoft.Quantum.Canon/ApplyToEachCA.md +1 -1
  60. package/docs/Microsoft.Quantum.Canon/ApplyXorInPlace.md +1 -1
  61. package/docs/Microsoft.Quantum.Canon/ApplyXorInPlaceL.md +1 -1
  62. package/docs/Microsoft.Quantum.Canon/CX.md +1 -1
  63. package/docs/Microsoft.Quantum.Canon/CY.md +1 -1
  64. package/docs/Microsoft.Quantum.Canon/CZ.md +1 -1
  65. package/docs/Microsoft.Quantum.Canon/Fst.md +1 -1
  66. package/docs/Microsoft.Quantum.Canon/Snd.md +1 -1
  67. package/docs/Microsoft.Quantum.Canon/SwapReverseRegister.md +1 -1
  68. package/docs/Microsoft.Quantum.Convert/BigIntAsBoolArray.md +1 -1
  69. package/docs/Microsoft.Quantum.Convert/BoolArrayAsBigInt.md +1 -1
  70. package/docs/Microsoft.Quantum.Convert/BoolArrayAsInt.md +1 -1
  71. package/docs/Microsoft.Quantum.Convert/BoolArrayAsResultArray.md +1 -1
  72. package/docs/Microsoft.Quantum.Convert/BoolAsResult.md +1 -1
  73. package/docs/Microsoft.Quantum.Convert/ComplexAsComplexPolar.md +1 -1
  74. package/docs/Microsoft.Quantum.Convert/ComplexPolarAsComplex.md +1 -1
  75. package/docs/Microsoft.Quantum.Convert/DoubleAsStringWithPrecision.md +35 -0
  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/DumpMachine.md +2 -2
  90. package/docs/Microsoft.Quantum.Diagnostics/DumpRegister.md +2 -2
  91. package/docs/Microsoft.Quantum.Diagnostics/Fact.md +14 -3
  92. package/docs/Microsoft.Quantum.Intrinsic/AND.md +33 -0
  93. package/docs/Microsoft.Quantum.Intrinsic/CCNOT.md +1 -1
  94. package/docs/Microsoft.Quantum.Intrinsic/CNOT.md +1 -1
  95. package/docs/Microsoft.Quantum.Intrinsic/Exp.md +1 -1
  96. package/docs/Microsoft.Quantum.Intrinsic/H.md +1 -1
  97. package/docs/Microsoft.Quantum.Intrinsic/I.md +1 -1
  98. package/docs/Microsoft.Quantum.Intrinsic/M.md +1 -1
  99. package/docs/Microsoft.Quantum.Intrinsic/Measure.md +9 -20
  100. package/docs/Microsoft.Quantum.Intrinsic/Message.md +1 -1
  101. package/docs/Microsoft.Quantum.Intrinsic/R.md +1 -1
  102. package/docs/Microsoft.Quantum.Intrinsic/R1.md +1 -1
  103. package/docs/Microsoft.Quantum.Intrinsic/R1Frac.md +4 -5
  104. package/docs/Microsoft.Quantum.Intrinsic/RFrac.md +2 -2
  105. package/docs/Microsoft.Quantum.Intrinsic/Reset.md +1 -1
  106. package/docs/Microsoft.Quantum.Intrinsic/ResetAll.md +1 -1
  107. package/docs/Microsoft.Quantum.Intrinsic/Rx.md +1 -1
  108. package/docs/Microsoft.Quantum.Intrinsic/Rxx.md +1 -1
  109. package/docs/Microsoft.Quantum.Intrinsic/Ry.md +1 -1
  110. package/docs/Microsoft.Quantum.Intrinsic/Ryy.md +1 -1
  111. package/docs/Microsoft.Quantum.Intrinsic/Rz.md +1 -1
  112. package/docs/Microsoft.Quantum.Intrinsic/Rzz.md +1 -1
  113. package/docs/Microsoft.Quantum.Intrinsic/S.md +1 -1
  114. package/docs/Microsoft.Quantum.Intrinsic/SWAP.md +1 -1
  115. package/docs/Microsoft.Quantum.Intrinsic/T.md +1 -1
  116. package/docs/Microsoft.Quantum.Intrinsic/X.md +1 -1
  117. package/docs/Microsoft.Quantum.Intrinsic/Y.md +1 -1
  118. package/docs/Microsoft.Quantum.Intrinsic/Z.md +1 -1
  119. package/docs/Microsoft.Quantum.Logical/Xor.md +1 -1
  120. package/docs/Microsoft.Quantum.Math/AbsComplex.md +1 -1
  121. package/docs/Microsoft.Quantum.Math/AbsComplexPolar.md +1 -1
  122. package/docs/Microsoft.Quantum.Math/AbsD.md +1 -1
  123. package/docs/Microsoft.Quantum.Math/AbsI.md +1 -1
  124. package/docs/Microsoft.Quantum.Math/AbsL.md +1 -1
  125. package/docs/Microsoft.Quantum.Math/AbsSquaredComplex.md +1 -1
  126. package/docs/Microsoft.Quantum.Math/AbsSquaredComplexPolar.md +1 -1
  127. package/docs/Microsoft.Quantum.Math/ApproximateFactorial.md +1 -1
  128. package/docs/Microsoft.Quantum.Math/ArcCos.md +1 -1
  129. package/docs/Microsoft.Quantum.Math/ArcCosh.md +1 -1
  130. package/docs/Microsoft.Quantum.Math/ArcSin.md +1 -1
  131. package/docs/Microsoft.Quantum.Math/ArcSinh.md +1 -1
  132. package/docs/Microsoft.Quantum.Math/ArcTan.md +1 -1
  133. package/docs/Microsoft.Quantum.Math/ArcTan2.md +1 -1
  134. package/docs/Microsoft.Quantum.Math/ArcTanh.md +1 -1
  135. package/docs/Microsoft.Quantum.Math/ArgComplex.md +1 -1
  136. package/docs/Microsoft.Quantum.Math/ArgComplexPolar.md +1 -1
  137. package/docs/Microsoft.Quantum.Math/Binom.md +1 -1
  138. package/docs/Microsoft.Quantum.Math/BitSizeI.md +1 -1
  139. package/docs/Microsoft.Quantum.Math/BitSizeL.md +1 -1
  140. package/docs/Microsoft.Quantum.Math/Ceiling.md +1 -1
  141. package/docs/Microsoft.Quantum.Math/Complex.md +1 -1
  142. package/docs/Microsoft.Quantum.Math/ComplexPolar.md +1 -1
  143. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentI.md +1 -1
  144. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentL.md +1 -1
  145. package/docs/Microsoft.Quantum.Math/Cos.md +1 -1
  146. package/docs/Microsoft.Quantum.Math/Cosh.md +1 -1
  147. package/docs/Microsoft.Quantum.Math/DivRemI.md +1 -1
  148. package/docs/Microsoft.Quantum.Math/DivRemL.md +1 -1
  149. package/docs/Microsoft.Quantum.Math/DividedByC.md +1 -1
  150. package/docs/Microsoft.Quantum.Math/DividedByCP.md +1 -1
  151. package/docs/Microsoft.Quantum.Math/E.md +1 -1
  152. package/docs/Microsoft.Quantum.Math/ExpModI.md +1 -1
  153. package/docs/Microsoft.Quantum.Math/ExpModL.md +1 -1
  154. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorI.md +1 -1
  155. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorL.md +1 -1
  156. package/docs/Microsoft.Quantum.Math/FactorialI.md +1 -1
  157. package/docs/Microsoft.Quantum.Math/FactorialL.md +1 -1
  158. package/docs/Microsoft.Quantum.Math/Floor.md +1 -1
  159. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorI.md +1 -1
  160. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorL.md +1 -1
  161. package/docs/Microsoft.Quantum.Math/HammingWeightI.md +1 -1
  162. package/docs/Microsoft.Quantum.Math/InverseModI.md +1 -1
  163. package/docs/Microsoft.Quantum.Math/InverseModL.md +1 -1
  164. package/docs/Microsoft.Quantum.Math/IsCoprimeI.md +1 -1
  165. package/docs/Microsoft.Quantum.Math/IsCoprimeL.md +1 -1
  166. package/docs/Microsoft.Quantum.Math/IsInfinite.md +1 -1
  167. package/docs/Microsoft.Quantum.Math/IsNaN.md +1 -1
  168. package/docs/Microsoft.Quantum.Math/LargestFixedPoint.md +1 -1
  169. package/docs/Microsoft.Quantum.Math/Lg.md +1 -1
  170. package/docs/Microsoft.Quantum.Math/Log.md +1 -1
  171. package/docs/Microsoft.Quantum.Math/Log10.md +1 -1
  172. package/docs/Microsoft.Quantum.Math/LogFactorialD.md +1 -1
  173. package/docs/Microsoft.Quantum.Math/LogGammaD.md +1 -1
  174. package/docs/Microsoft.Quantum.Math/LogOf2.md +1 -1
  175. package/docs/Microsoft.Quantum.Math/Max.md +1 -1
  176. package/docs/Microsoft.Quantum.Math/MaxD.md +1 -1
  177. package/docs/Microsoft.Quantum.Math/MaxI.md +1 -1
  178. package/docs/Microsoft.Quantum.Math/MaxL.md +1 -1
  179. package/docs/Microsoft.Quantum.Math/Min.md +1 -1
  180. package/docs/Microsoft.Quantum.Math/MinD.md +1 -1
  181. package/docs/Microsoft.Quantum.Math/MinI.md +1 -1
  182. package/docs/Microsoft.Quantum.Math/MinL.md +1 -1
  183. package/docs/Microsoft.Quantum.Math/MinusC.md +1 -1
  184. package/docs/Microsoft.Quantum.Math/MinusCP.md +1 -1
  185. package/docs/Microsoft.Quantum.Math/ModulusI.md +1 -1
  186. package/docs/Microsoft.Quantum.Math/ModulusL.md +1 -1
  187. package/docs/Microsoft.Quantum.Math/NegationC.md +1 -1
  188. package/docs/Microsoft.Quantum.Math/NegationCP.md +1 -1
  189. package/docs/Microsoft.Quantum.Math/PI.md +1 -1
  190. package/docs/Microsoft.Quantum.Math/PNorm.md +1 -1
  191. package/docs/Microsoft.Quantum.Math/PNormalized.md +1 -1
  192. package/docs/Microsoft.Quantum.Math/PlusC.md +1 -1
  193. package/docs/Microsoft.Quantum.Math/PlusCP.md +1 -1
  194. package/docs/Microsoft.Quantum.Math/PowC.md +1 -1
  195. package/docs/Microsoft.Quantum.Math/PowCP.md +1 -1
  196. package/docs/Microsoft.Quantum.Math/RealMod.md +1 -1
  197. package/docs/Microsoft.Quantum.Math/Round.md +1 -1
  198. package/docs/Microsoft.Quantum.Math/SignD.md +1 -1
  199. package/docs/Microsoft.Quantum.Math/SignI.md +1 -1
  200. package/docs/Microsoft.Quantum.Math/SignL.md +1 -1
  201. package/docs/Microsoft.Quantum.Math/Sin.md +1 -1
  202. package/docs/Microsoft.Quantum.Math/Sinh.md +1 -1
  203. package/docs/Microsoft.Quantum.Math/SmallestFixedPoint.md +1 -1
  204. package/docs/Microsoft.Quantum.Math/Sqrt.md +1 -1
  205. package/docs/Microsoft.Quantum.Math/SquaredNorm.md +1 -1
  206. package/docs/Microsoft.Quantum.Math/Tan.md +1 -1
  207. package/docs/Microsoft.Quantum.Math/Tanh.md +1 -1
  208. package/docs/Microsoft.Quantum.Math/TimesC.md +1 -1
  209. package/docs/Microsoft.Quantum.Math/TimesCP.md +1 -1
  210. package/docs/Microsoft.Quantum.Math/TrailingZeroCountI.md +1 -1
  211. package/docs/Microsoft.Quantum.Math/TrailingZeroCountL.md +1 -1
  212. package/docs/Microsoft.Quantum.Math/Truncate.md +1 -1
  213. package/docs/Microsoft.Quantum.Measurement/MResetEachZ.md +1 -1
  214. package/docs/Microsoft.Quantum.Measurement/MResetX.md +1 -1
  215. package/docs/Microsoft.Quantum.Measurement/MResetY.md +1 -1
  216. package/docs/Microsoft.Quantum.Measurement/MResetZ.md +1 -1
  217. package/docs/Microsoft.Quantum.Measurement/MeasureAllZ.md +1 -1
  218. package/docs/Microsoft.Quantum.Measurement/MeasureEachZ.md +1 -1
  219. package/docs/Microsoft.Quantum.Measurement/MeasureInteger.md +1 -1
  220. package/docs/Microsoft.Quantum.ResourceEstimation/AccountForEstimates.md +1 -1
  221. package/docs/Microsoft.Quantum.ResourceEstimation/AuxQubitCount.md +1 -1
  222. package/docs/Microsoft.Quantum.ResourceEstimation/BeginEstimateCaching.md +1 -1
  223. package/docs/Microsoft.Quantum.ResourceEstimation/BeginRepeatEstimates.md +1 -1
  224. package/docs/Microsoft.Quantum.ResourceEstimation/CczCount.md +1 -1
  225. package/docs/Microsoft.Quantum.ResourceEstimation/EndEstimateCaching.md +1 -1
  226. package/docs/Microsoft.Quantum.ResourceEstimation/EndRepeatEstimates.md +1 -1
  227. package/docs/Microsoft.Quantum.ResourceEstimation/MeasurementCount.md +1 -1
  228. package/docs/Microsoft.Quantum.ResourceEstimation/PSSPCLayout.md +1 -1
  229. package/docs/Microsoft.Quantum.ResourceEstimation/RepeatEstimates.md +1 -1
  230. package/docs/Microsoft.Quantum.ResourceEstimation/RotationCount.md +1 -1
  231. package/docs/Microsoft.Quantum.ResourceEstimation/RotationDepth.md +1 -1
  232. package/docs/Microsoft.Quantum.ResourceEstimation/SingleVariant.md +1 -1
  233. package/docs/Microsoft.Quantum.ResourceEstimation/TCount.md +1 -1
  234. package/docs/Microsoft.Quantum.Unstable.Arithmetic/AddLE.md +1 -1
  235. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualL.md +1 -1
  236. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualLE.md +1 -1
  237. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterL.md +1 -1
  238. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterLE.md +1 -1
  239. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualL.md +1 -1
  240. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualLE.md +1 -1
  241. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessL.md +1 -1
  242. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessLE.md +1 -1
  243. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualL.md +1 -1
  244. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualLE.md +1 -1
  245. package/docs/Microsoft.Quantum.Unstable.Arithmetic/FourierTDIncByLE.md +1 -1
  246. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByI.md +1 -1
  247. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByIUsingIncByLE.md +1 -1
  248. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByL.md +1 -1
  249. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLE.md +1 -1
  250. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLEUsingAddLE.md +1 -1
  251. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLUsingIncByLE.md +1 -1
  252. package/docs/Microsoft.Quantum.Unstable.Arithmetic/LookAheadDKRSAddLE.md +1 -1
  253. package/docs/Microsoft.Quantum.Unstable.Arithmetic/MAJ.md +1 -1
  254. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ReflectAboutInteger.md +1 -1
  255. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGAddLE.md +1 -1
  256. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGIncByLE.md +1 -1
  257. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryTTKIncByLE.md +1 -1
  258. package/docs/Microsoft.Quantum.Unstable.StatePreparation/ApproximatelyPreparePureStateCP.md +1 -1
  259. package/docs/Microsoft.Quantum.Unstable.StatePreparation/PreparePureStateD.md +1 -1
  260. package/docs/Microsoft.Quantum.Unstable.TableLookup/Select.md +1 -1
  261. package/docs/toc.yml +2 -31
  262. package/lib/node/qsc_wasm.cjs +43 -43
  263. package/lib/node/qsc_wasm_bg.wasm +0 -0
  264. package/lib/web/qsc_wasm.js +35 -35
  265. package/lib/web/qsc_wasm_bg.wasm +0 -0
  266. package/package.json +1 -1
  267. package/docs/Microsoft.Quantum.Intrinsic/AdjustForSingleControl.md +0 -21
  268. package/docs/Microsoft.Quantum.Intrinsic/ApplyGlobalPhase.md +0 -18
  269. package/docs/Microsoft.Quantum.Intrinsic/CCH.md +0 -18
  270. package/docs/Microsoft.Quantum.Intrinsic/CCY.md +0 -18
  271. package/docs/Microsoft.Quantum.Intrinsic/CCZ.md +0 -18
  272. package/docs/Microsoft.Quantum.Intrinsic/CH.md +0 -18
  273. package/docs/Microsoft.Quantum.Intrinsic/CRxx.md +0 -18
  274. package/docs/Microsoft.Quantum.Intrinsic/CRyy.md +0 -18
  275. package/docs/Microsoft.Quantum.Intrinsic/CRz.md +0 -18
  276. package/docs/Microsoft.Quantum.Intrinsic/CRzz.md +0 -18
  277. package/docs/Microsoft.Quantum.Intrinsic/CS.md +0 -18
  278. package/docs/Microsoft.Quantum.Intrinsic/CT.md +0 -18
  279. package/docs/Microsoft.Quantum.Intrinsic/CollectControls.md +0 -27
  280. package/docs/Microsoft.Quantum.Intrinsic/ControllableGlobalPhase.md +0 -18
  281. package/docs/Microsoft.Quantum.Intrinsic/EntangleForJointMeasure.md +0 -18
  282. package/docs/Microsoft.Quantum.Intrinsic/GlobalPhase.md +0 -18
  283. package/docs/Microsoft.Quantum.Intrinsic/IndicesOfNonIdentity.md +0 -18
  284. package/docs/Microsoft.Quantum.Intrinsic/MapPauli.md +0 -18
  285. package/docs/Microsoft.Quantum.Intrinsic/PhaseCCX.md +0 -18
  286. package/docs/Microsoft.Quantum.Intrinsic/RemovePauliI.md +0 -18
  287. package/docs/Microsoft.Quantum.Intrinsic/SpreadZ.md +0 -18
  288. package/docs/Microsoft.Quantum.Math/ExtendedTruncation.md +0 -18
  289. package/docs/Microsoft.Quantum.Math/PowCAsCP.md +0 -24
  290. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyActionIfGreaterThanOrEqualConstant.md +0 -23
  291. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyActionIfSumOverflows.md +0 -23
  292. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyAsSinglyControlled.md +0 -24
  293. package/docs/Microsoft.Quantum.Unstable.Arithmetic/PhaseGradient.md +0 -18
  294. package/docs/Microsoft.Quantum.Unstable.TableLookup/EncodeUnary.md +0 -18
  295. package/docs/Microsoft.Quantum.Unstable.TableLookup/MustBeFixed.md +0 -18
  296. package/docs/Microsoft.Quantum.Unstable.TableLookup/Unlookup.md +0 -22
  297. package/docs/Microsoft.Quantum.Unstable.TableLookup/WriteMemoryContents.md +0 -18
@@ -57,7 +57,7 @@ export default {
57
57
  "items": [
58
58
  {
59
59
  "type": "text-content",
60
- "content": "\nThis kata introduces you to complex arithmetic. This topic isn't particularly expansive, but it's important to understand it to be able to work with quantum computing.\n\n**This kata covers the following topics:**\n\n* Imaginary and complex numbers\n* Basic complex arithmetic\n* Complex plane\n* Modulus operator\n* Imaginary exponents\n* Polar representation\n\nIf you are curious to learn more, you can find more information at [Wikipedia](https://en.wikipedia.org/wiki/Complex_number).\n\nThis kata has several tasks that require you to write Q# code to test your understanding of the concepts. It will introduce the necessary Q# language constructs as it goes."
60
+ "content": "\nThis kata introduces you to complex arithmetic. This topic isn't particularly expansive, but it's important to understand it to be able to work with quantum computing.\n\n**This kata covers the following topics:**\n\n* Imaginary and complex numbers\n* Basic complex arithmetic\n* Complex plane\n* Modulus operator\n* Imaginary exponents\n* Polar representation\n\nIf you are curious to learn more, you can find more information at [Wikipedia](https://en.wikipedia.org/wiki/Complex_number).\n\nThis kata has several tasks that require you to write Q# code to test your understanding of the concepts. The kata will introduce the necessary Q# language constructs as it goes."
61
61
  }
62
62
  ]
63
63
  },
@@ -68,7 +68,7 @@ export default {
68
68
  "items": [
69
69
  {
70
70
  "type": "text-content",
71
- "content": "\nFor some purposes, real numbers aren't enough. Probably the most famous example is the equation:\n\n$$x^{2} = -1$$\n\nThis equation has no solution among real numbers. If, however, we abandon that constraint, we can do something interesting - we can define our own number. Let's say there exists some number that solves that equation. Let's call that number $i$.\n\n$$i^2 = -1$$\n\nAs we said before, $i$ can't be a real number. In that case, we'll call it an **imaginary unit**. However, there is no reason for us to define it as acting any different from any other number, other than the fact that $i^2 = -1$:\n\n$$i+i=2i$$\n\n$$i-i=0$$\n\n$$-1 \\cdot i=-i$$\n\n$$(-i)^{2} = -1$$\n\nWe'll call the number $i$ and its real multiples (numbers obtained by multiplying $i$ by a real number) **imaginary numbers**.\n\n> A good video introduction to imaginary numbers can be found [here](https://youtu.be/SP-YJe7Vldo)."
71
+ "content": "\nFor some purposes, real numbers aren't enough. Probably the most famous example is the equation:\n\n$$x^{2} = -1$$\n\nThis equation has no solution among real numbers. But if you abandon that constraint, you can do something interesting - you can define your own number. Let's say there exists some number that solves that equation. Let's call that number $i$.\n\n$$i^2 = -1$$\n\nAs said before, the number $i$ can't be a real number. In that case, let's call it an **imaginary number**. However, there's no reason to define it as acting any different from any other number, other than the fact that $i^2 = -1$. This means that you can do all the same operations on $i$ that you can do on any other number. For example:\n\n$$i+i=2i$$\n\n$$i-i=0$$\n\n$$-1 \\cdot i=-i$$\n\n$$(-i)^{2} = -1$$\n\nThe number $i$ and its real multiples (numbers obtained by multiplying $i$ by a real number) are called **imaginary numbers**.\n\n> A good video introduction to imaginary numbers can be found [here](https://youtu.be/SP-YJe7Vldo)."
72
72
  }
73
73
  ]
74
74
  },
@@ -91,7 +91,7 @@ export default {
91
91
  "items": [
92
92
  {
93
93
  "type": "text-content",
94
- "content": "\nWhen raising $i$ to an integer power, the answer will vary according to a certain pattern.\nTo figure it out, notice that raising $i$ to the power of $4$ gives: \n\n$$i^4 = i^2 \\cdot i^2 = (-1) \\cdot (-1) = 1$$\n\nThus, when the exponent $n$ is divisible by 4, $i^n$ will always be 1.\n\nWhen the exponent $n$ is not divisible by 4, you can use the previous observation to see that $i^n = i^{n \\mod 4}$.\nFor an even exponent $n$ that is not divisible by 4 you'll have $i^n = i^2 = -1.$\n\nHere is the complete pattern that arises when raising $i$ to non-negative powers. Note that it is periodic with period $4$.\n\n<table>\n <tr>\n <th>Power of $i$</th>\n <th> $i^0$ </th>\n <th> $i^1$ </th>\n <th> $i^2$ </th>\n <th> $i^3$ </th>\n <th> $i^4$ </th>\n <th> $i^5$ </th>\n <th> $i^6$ </th>\n <th> $i^7$ </th>\n <th> $i^8$ </th>\n <th> $\\dots$ </th>\n </tr>\n <tr>\n <td>Result</td>\n <td> $1$ </td>\n <td> $i$ </td>\n <td> $-1$ </td>\n <td> $-i$ </td>\n <td> $1$ </td>\n <td> $i$ </td>\n <td> $-1$ </td>\n <td> $-i$ </td>\n <td> $1$ </td>\n <td> $\\dots$ </td>\n </tr>\n</table>\n\n> `%` is the Q# modulo operator which returns the remainder of a division. For example, `7%2` gives $1$, because $1$ is the remainder of dividing $7$ by $2$. \n> We can use this operator to determine if the exponent $n$ is divisible by $4$."
94
+ "content": "\nWhen raising $i$ to an integer power, the answer will vary according to a certain pattern.\nTo figure it out, notice that raising $i$ to the power of $4$ gives: \n\n$$i^4 = i^2 \\cdot i^2 = (-1) \\cdot (-1) = 1$$\n\nThus, when the exponent $n$ is divisible by 4, $i^n$ will always be 1.\n\nWhen the exponent $n$ is not divisible by 4, you can use the previous observation to see that $i^n = i^{n \\mod 4}$.\nFor an even exponent $n$ that isn't divisible by 4 you'll have $i^n = i^2 = -1.$\n\nHere is the complete pattern that arises when raising $i$ to non-negative powers. Note that it is periodic with period $4$.\n\n<table>\n <tr>\n <th>Power of $i$</th>\n <th> $i^0$ </th>\n <th> $i^1$ </th>\n <th> $i^2$ </th>\n <th> $i^3$ </th>\n <th> $i^4$ </th>\n <th> $i^5$ </th>\n <th> $i^6$ </th>\n <th> $i^7$ </th>\n <th> $i^8$ </th>\n <th> $\\dots$ </th>\n </tr>\n <tr>\n <td>Result</td>\n <td> $1$ </td>\n <td> $i$ </td>\n <td> $-1$ </td>\n <td> $-i$ </td>\n <td> $1$ </td>\n <td> $i$ </td>\n <td> $-1$ </td>\n <td> $-i$ </td>\n <td> $1$ </td>\n <td> $\\dots$ </td>\n </tr>\n</table>\n\n> `%` is the Q# modulo operator which returns the remainder of a division. For example, `7%2` gives $1$, because $1$ is the remainder of dividing $7$ by $2$. \n> We can use this operator to determine if the exponent $n$ is divisible by $4$."
95
95
  },
96
96
  {
97
97
  "type": "solution",
@@ -108,7 +108,7 @@ export default {
108
108
  "items": [
109
109
  {
110
110
  "type": "text-content",
111
- "content": "\nAdding imaginary numbers to each other is quite simple, but what happens when we add a real number to an imaginary number? The result of that addition will be partly real and partly imaginary, otherwise known as a **complex number**. A complex number is simply the real part and the imaginary part being treated as a single number. Complex numbers are generally written as the sum of their two parts $a$ and $bi$, where both $a$ and $b$ are real numbers: \n\n$$a+bi$$\n\nFor example, $3+4i$ or $-5-7i$ are valid complex numbers. Note that purely real or purely imaginary numbers can also be written as complex numbers: $2$ is $2+0i$, and $-3i$ is $0-3i$.\n\nWhen performing operations on complex numbers, it is often helpful to treat them as polynomials in terms of $i$.\nLet's see how to do the main arithmetic operations on complex numbers.\n\n> In Q#, complex numbers are represented as user-defined type `Complex` from the `Microsoft.Quantum.Math` namespace. \n> \n> You can convert a complex number $x = a + bi$ into a tuple of two `Double` numbers using unwrap operator and tuple deconstruction: `let (a, b) = x!;`, \n> or access its real and imaginary parts using their names: `let (a, b) = (x::Real, x::Imag);`.\n> \n> You can construct a complex number from its real and imaginary parts as follows: `let x = Complex(a, b);`."
111
+ "content": "\nAdding imaginary numbers to each other is quite simple, but what happens when you add a real number to an imaginary number? The result of that addition will be partly real and partly imaginary, otherwise known as a **complex number**. A complex number is simply the real part and the imaginary part being treated as a single number. Complex numbers are generally written as the sum of their two parts $a$ and $bi$, where both $a$ and $b$ are real numbers: \n\n$$a+bi$$\n\nFor example, $3+4i$ or $-5-7i$ are valid complex numbers. Note that purely real or purely imaginary numbers can also be written as complex numbers: $2$ is $2+0i$, and $-3i$ is $0-3i$.\n\nWhen performing operations on complex numbers, it's often helpful to treat them as polynomials in terms of $i$.\nLet's see how to do the main arithmetic operations on complex numbers.\n\n> In Q#, complex numbers are represented as user-defined type `Complex` from the `Microsoft.Quantum.Math` namespace. \n> \n> You can convert a complex number $x = a + bi$ into a tuple of two `Double` numbers using unwrap operator and tuple deconstruction: `let (a, b) = x!;`, \n> or access its real and imaginary parts using their names: `let (a, b) = (x::Real, x::Imag);`.\n> \n> You can construct a complex number from its real and imaginary parts as follows: `let x = Complex(a, b);`."
112
112
  }
113
113
  ]
114
114
  },
@@ -177,7 +177,7 @@ export default {
177
177
  "items": [
178
178
  {
179
179
  "type": "text-content",
180
- "content": "\nBefore we discuss any other operations on complex numbers, we have to cover the **complex conjugate**. The conjugate is a simple operation: given a complex number $x = a + bi$, its complex conjugate is $\\overline{x} = a - bi$.\n\nThe conjugate allows us to do some interesting things. The first and probably most important is multiplying a complex number by its conjugate:\n\n$$x \\cdot \\overline{x} = (a + bi)(a - bi)$$\n\nNotice that the second expression is a difference of squares:\n\n$$(a + bi)(a - bi) = a^2 - (bi)^2 = a^2 - b^2i^2 = a^2 + b^2$$\n\nThis means that a complex number multiplied by its conjugate always produces a non-negative real number.\n\nAnother property of the conjugate is that it distributes over both complex addition and complex multiplication:\n\n$$\\overline{x + y} = \\overline{x} + \\overline{y}$$\n$$\\overline{x \\cdot y} = \\overline{x} \\cdot \\overline{y}$$"
180
+ "content": "\nBefore discussing any other operations on complex numbers, let's review the **complex conjugate**. The conjugate is a simple operation: given a complex number $x = a + bi$, its complex conjugate is $\\overline{x} = a - bi$.\n\nThe conjugate allows you to do some interesting things. The first and probably most important is multiplying a complex number by its conjugate:\n\n$$x \\cdot \\overline{x} = (a + bi)(a - bi)$$\n\nNotice that the second expression is a difference of squares:\n\n$$(a + bi)(a - bi) = a^2 - (bi)^2 = a^2 - b^2i^2 = a^2 + b^2$$\n\nThis means that a complex number multiplied by its conjugate always produces a non-negative real number.\n\nAnother property of the conjugate is that it distributes over both complex addition and complex multiplication:\n\n$$\\overline{x + y} = \\overline{x} + \\overline{y}$$\n$$\\overline{x \\cdot y} = \\overline{x} \\cdot \\overline{y}$$"
181
181
  }
182
182
  ]
183
183
  },
@@ -217,7 +217,7 @@ export default {
217
217
  "items": [
218
218
  {
219
219
  "type": "text-content",
220
- "content": "\nThe next use for the conjugate is complex division. Let's take two complex numbers: $x = a + bi$ and $y = c + di \\neq 0$ (not even complex numbers let you divide by $0$). What does $\\frac{x}{y}$ mean?\n\nLet's expand $x$ and $y$ into their component forms:\n\n$$\\frac{x}{y} = \\frac{a + bi}{c + di}$$\n\nUnfortunately, it isn't very clear what it means to divide by a complex number. We need some way to move either all real parts or all imaginary parts into the numerator. And thanks to the conjugate, we can do just that. Using the fact that any number (except $0$) divided by itself equals $1$, and any number multiplied by $1$ equals itself, we get:\n\n$$\\frac{x}{y} = \\frac{x}{y} \\cdot 1 = \\frac{x}{y} \\cdot \\frac{\\overline{y}}{\\overline{y}} = \\frac{x\\overline{y}}{y\\overline{y}} = \\frac{(a + bi)(c - di)}{(c + di)(c - di)} = \\frac{(a + bi)(c - di)}{c^2 + d^2}$$\n\nBy doing this, we re-wrote our division problem to have a complex multiplication expression in the numerator, and a real number in the denominator. We already know how to multiply complex numbers, and dividing a complex number by a real number is as simple as dividing both parts of the complex number separately:\n\n$$\\frac{a + bi}{r} = \\frac{a}{r} + \\frac{b}{r}i$$"
220
+ "content": "\nThe next use for the conjugate is complex division. Let's take two complex numbers: $x = a + bi$ and $y = c + di \\neq 0$ (not even complex numbers let you divide by $0$). What does $\\frac{x}{y}$ mean?\n\nLet's expand $x$ and $y$ into their component forms:\n\n$$\\frac{x}{y} = \\frac{a + bi}{c + di}$$\n\nUnfortunately, it isn't very clear what it means to divide by a complex number. You need some way to move either all real parts or all imaginary parts into the numerator. And thanks to the conjugate, you can do just that. Using the fact that any number (except $0$) divided by itself equals $1$, and any number multiplied by $1$ equals itself, you get:\n\n$$\\frac{x}{y} = \\frac{x}{y} \\cdot 1 = \\frac{x}{y} \\cdot \\frac{\\overline{y}}{\\overline{y}} = \\frac{x\\overline{y}}{y\\overline{y}} = \\frac{(a + bi)(c - di)}{(c + di)(c - di)} = \\frac{(a + bi)(c - di)}{c^2 + d^2}$$\n\nBy doing this, you re-wrote your division problem to have a complex multiplication expression in the numerator, and a real number in the denominator. You already know how to multiply complex numbers, and dividing a complex number by a real number is as simple as dividing both parts of the complex number separately:\n\n$$\\frac{a + bi}{r} = \\frac{a}{r} + \\frac{b}{r}i$$"
221
221
  }
222
222
  ]
223
223
  },
@@ -257,7 +257,7 @@ export default {
257
257
  "items": [
258
258
  {
259
259
  "type": "text-content",
260
- "content": "\nYou may recall that real numbers can be represented geometrically using the number line - a line on which each point represents a real number. We can extend this representation to include imaginary and complex numbers, which gives rise to an entirely different number line: the imaginary number line, which is orthogonal to the real number line and only intersects with it at $0$.\n\nA complex number has two components - a real component and an imaginary component. As you no doubt noticed from the exercises, these can be represented by two real numbers - the real component, and the real coefficient of the imaginary component. This allows us to map complex numbers onto a two-dimensional plane - the **complex plane**. The most common mapping is the obvious one: $a+bi$ can be represented by the point $(a,b)$ in the **Cartesian coordinate system**.\n\nThis mapping allows us to apply complex arithmetic to geometry, and, more importantly, apply geometric concepts to complex numbers. Many properties of complex numbers become easier to understand when viewed through a geometric lens.\n\n## Modulus\n\nOne such property is the **modulus operator**. This operator generalizes the **absolute value** operator on real numbers to the complex plane. Just like the absolute value of a number is its distance from $0$, the modulus of a complex number is its distance from $0+0i$. Using the distance formula, if $x=a+bi$, then:\n\n$$|x| = \\sqrt{a^2 + b^2}$$\n\nThere is also a slightly different, but algebraically equivalent definition: \n\n$$|x| = \\sqrt{x \\cdot \\overline{x}}$$\n\nLike the conjugate, the modulus distributes over multiplication.\n\n$$|x \\cdot y| = |x| \\cdot |y|$$\n\nUnlike the conjugate, however, the modulus doesn't distribute over addition. Instead, the interaction of the two comes from the triangle inequality:\n\n$$|x + y| \\leq |x| + |y|$$"
260
+ "content": "\nYou may recall that real numbers can be represented geometrically using the number line - a line on which each point represents a real number. You can extend this representation to include imaginary and complex numbers, which gives rise to an entirely different number line: the imaginary number line, which is orthogonal to the real number line and only intersects with it at $0$.\n\nA complex number has two components - a real component and an imaginary component. As you no doubt noticed from the exercises, these can be represented by two real numbers - the real component, and the real coefficient of the imaginary component. This allows you to map complex numbers onto a two-dimensional plane - the **complex plane**. The most common mapping is the obvious one: $a+bi$ can be represented by the point $(a,b)$ in the **Cartesian coordinate system**.\n\nThis mapping allows you to apply complex arithmetic to geometry, and, more importantly, apply geometric concepts to complex numbers. Many properties of complex numbers become easier to understand when viewed through a geometric lens.\n\n## Modulus\n\nOne such property is the **modulus operator**. This operator generalizes the **absolute value** operator on real numbers to the complex plane. Just like the absolute value of a number is its distance from $0$, the modulus of a complex number is its distance from $0+0i$. Using the distance formula, if $x=a+bi$, then:\n\n$$|x| = \\sqrt{a^2 + b^2}$$\n\nThere is also a slightly different, but algebraically equivalent definition: \n\n$$|x| = \\sqrt{x \\cdot \\overline{x}}$$\n\nLike the conjugate, the modulus distributes over multiplication.\n\n$$|x \\cdot y| = |x| \\cdot |y|$$\n\nUnlike the conjugate, however, the modulus doesn't distribute over addition. Instead, the interaction of the two comes from the triangle inequality:\n\n$$|x + y| \\leq |x| + |y|$$"
261
261
  }
262
262
  ]
263
263
  },
@@ -297,7 +297,7 @@ export default {
297
297
  "items": [
298
298
  {
299
299
  "type": "text-content",
300
- "content": "\nThe next complex operation we're going to need is exponentiation. Raising an imaginary number to an integer power is a fairly simple task, but raising a number to an imaginary power, or raising an imaginary (or complex) number to a real power isn't quite as simple.\n\nLet's start with raising real numbers to imaginary powers. Specifically, let's start with a rather special real number - Euler's constant, $e$:\n\n$$e^{i\\theta} = \\cos \\theta + i\\sin \\theta$$\n\nHere and later in this tutorial $\\theta$ is measured in radians.\n\n> Explaining why that happens is somewhat beyond the scope of this tutorial, as it requires some calculus, so we won't do that here. If you are curious, you can see [this video](https://youtu.be/v0YEaeIClKY) for a beautiful intuitive explanation, or [this Wikipedia article](https://en.wikipedia.org/wiki/Complex_number) for a more mathematically rigorous proof.\n\nHere are some examples of this formula in action:\n\n$$e^{i\\pi/4} = \\frac{1}{\\sqrt{2}} + \\frac{i}{\\sqrt{2}}$$\n$$e^{i\\pi/2} = i$$\n$$e^{i\\pi} = -1$$\n$$e^{2i\\pi} = 1$$\n\n> One interesting consequence of this is Euler's identity:\n> \n> $$e^{i\\pi} + 1 = 0$$\n> \n> While this doesn't have any notable uses, it is still an interesting identity to consider, as it combines five fundamental constants of algebra into one expression.\n\nWe can also calculate complex powers of $e$ as follows:\n\n$$e^{a + bi} = e^a \\cdot e^{bi}$$\n\nFinally, using logarithms to express the base of the exponent as $r = e^{\\ln r}$, we can use this to find complex powers of any positive real number."
300
+ "content": "\nThe next complex operation is **exponentiation**. Raising an imaginary number to an integer power is a fairly simple task, but raising a number to an imaginary power, or raising an imaginary (or complex) number to a real power isn't quite as simple.\n\nLet's start with raising real numbers to imaginary powers. Specifically, let's start with a rather special real number - Euler's constant, $e$:\n\n$$e^{i\\theta} = \\cos \\theta + i\\sin \\theta$$\n\nHere and later in this tutorial $\\theta$ is measured in radians.\n\n> Explaining why that happens is beyond the scope of this tutorial. If you are curious, you can see [this video](https://youtu.be/v0YEaeIClKY) for a beautiful intuitive explanation, or [this Wikipedia article](https://en.wikipedia.org/wiki/Complex_number) for a more mathematically rigorous proof.\n\nHere are some examples of this formula in action:\n\n$$e^{i\\pi/4} = \\frac{1}{\\sqrt{2}} + \\frac{i}{\\sqrt{2}}$$\n$$e^{i\\pi/2} = i$$\n$$e^{i\\pi} = -1$$\n$$e^{2i\\pi} = 1$$\n\n> One interesting consequence of this is Euler's identity:\n> \n> $$e^{i\\pi} + 1 = 0$$\n> \n> While this doesn't have any notable uses, it's still an interesting identity to consider, as it combines five fundamental constants of algebra into one expression.\n\nYou can also calculate complex powers of $e$ as follows:\n\n$$e^{a + bi} = e^a \\cdot e^{bi}$$\n\nFinally, using logarithms to express the base of the exponent as $r = e^{\\ln r}$, you can use this to find complex powers of any positive real number."
301
301
  }
302
302
  ]
303
303
  },
@@ -320,7 +320,7 @@ export default {
320
320
  "items": [
321
321
  {
322
322
  "type": "text-content",
323
- "content": "\nTo start, we will rewrite the expression $e^{a + bi}$ as a product of two simpler expressions: $ e^a \\cdot\\ e^{bi} $.\nThe first part is a real number.\nThe second part can be expressed using the formula $e^{i\\theta} = \\cos \\theta + i\\sin \\theta$.\nSubstituting this into our expression gives:\n$$ e^a(\\cos b + i\\sin b) = \\underset{real}{\\underbrace{e^a \\cos b}} + \\underset{imaginary}{\\underbrace{e^a \\sin b}}i $$"
323
+ "content": "\nTo start, you'll rewrite the expression $e^{a + bi}$ as a product of two simpler expressions: $ e^a \\cdot\\ e^{bi} $.\nThe first part is a real number.\nThe second part can be expressed using the formula $e^{i\\theta} = \\cos \\theta + i\\sin \\theta$.\nSubstituting this into our expression gives:\n$$ e^a(\\cos b + i\\sin b) = \\underset{real}{\\underbrace{e^a \\cos b}} + \\underset{imaginary}{\\underbrace{e^a \\sin b}}i $$"
324
324
  },
325
325
  {
326
326
  "type": "solution",
@@ -349,7 +349,7 @@ export default {
349
349
  "items": [
350
350
  {
351
351
  "type": "text-content",
352
- "content": "\nRewrite the expression $r^x$ to use Euler's constant, which will allow us to use an approach similar to the solution to the previous exercise.\n\nFirst, rewrite $r^x$ into a product of two powers: $$ r^{a+bi} = r^a \\cdot r^{bi} $$\n\nGiven that $r = e^{\\ln r} $ ($\\ln$ is the natural logarithm), we can rewrite the second part of the product as follows: \n $$ r^{bi} = e^{bi\\ln r} $$\n\nNow, given $e^{i\\theta} = \\cos \\theta + i\\sin \\theta$, we can rewrite it further as follows: \n $$ e^{bi\\ln r} = \\cos( b \\cdot \\ln r) + i \\sin(b \\cdot \\ln r) $$\n\nWhen substituting this into the original expression, we get:\n $$ \\underset{real}{\\underbrace{r^a \\cos(b \\cdot \\ln r)}} + \\underset{imaginary}{\\underbrace{r^a \\sin(b \\cdot \\ln r)}} i $$"
352
+ "content": "\nRewrite the expression $r^x$ to use Euler's constant, which will allow you to use an approach similar to the solution to the previous exercise.\n\nFirst, rewrite $r^x$ into a product of two powers: $$ r^{a+bi} = r^a \\cdot r^{bi} $$\n\nGiven that $r = e^{\\ln r} $ ($\\ln$ is the natural logarithm), you can rewrite the second part of the product as follows: \n $$ r^{bi} = e^{bi\\ln r} $$\n\nNow, given $e^{i\\theta} = \\cos \\theta + i\\sin \\theta$, you can rewrite it further as follows: \n $$ e^{bi\\ln r} = \\cos( b \\cdot \\ln r) + i \\sin(b \\cdot \\ln r) $$\n\nWhen substituting this into the original expression, you get:\n $$ \\underset{real}{\\underbrace{r^a \\cos(b \\cdot \\ln r)}} + \\underset{imaginary}{\\underbrace{r^a \\sin(b \\cdot \\ln r)}} i $$"
353
353
  },
354
354
  {
355
355
  "type": "solution",
@@ -366,7 +366,7 @@ export default {
366
366
  "items": [
367
367
  {
368
368
  "type": "text-content",
369
- "content": "\nConsider the expression $e^{i\\theta} = \\cos\\theta + i\\sin\\theta$. Notice that if we map this number onto the complex plane, it will land on a **unit circle** around $0 + 0i$. This means that its modulus is always $1$. You can also verify this algebraically: $\\cos^2\\theta + \\sin^2\\theta = 1$.\n\nUsing this fact we can represent complex numbers using **polar coordinates**. In a polar coordinate system, a point is represented by two numbers: its direction from origin, represented by an angle from the $x$ axis, and how far away it is in that direction.\n\nAnother way to think about this is that we're taking a point that is $1$ unit away (which is on the unit circle) in the specified direction, and multiplying it by the desired distance. And to get the point on the unit circle, we can use $e^{i\\theta}$.\n\nA complex number of the format $r \\cdot e^{i\\theta}$ will be represented by a point which is $r$ units away from the origin, in the direction specified by the angle $\\theta$.\nSometimes $\\theta$ will be referred to as the number's **argument** or **phase**.\n\n> In Q#, complex numbers in polar form are represented as user-defined type `ComplexPolar` from the `Microsoft.Quantum.Math` namespace. \n> \n> You can convert a complex number $x = r \\cdot e^{i\\theta}$ into a tuple of two `Double` numbers using unwrap operator and tuple deconstruction: `let (r, theta) = x!;`, \n> or access its magnitude and phase using their names: `let (r, theta) = (x::Magnitude, x::Argument);`.\n> \n> You can construct a complex number from its magnitude and phase as follows: `let x = ComplexPolar(r, theta);`."
369
+ "content": "\nConsider the expression $e^{i\\theta} = \\cos\\theta + i\\sin\\theta$. Notice that if you map this number onto the complex plane, it'll land on a **unit circle** around $0 + 0i$. This means that its modulus is always $1$. You can also verify this algebraically: $\\cos^2\\theta + \\sin^2\\theta = 1$.\n\nUsing this fact you can represent complex numbers using **polar coordinates**. In a polar coordinate system, a point is represented by two numbers: its direction from origin, represented by an angle from the $x$ axis, and how far away it is in that direction.\n\nAnother way to think about this is that you're taking a point that is $1$ unit away (which is on the unit circle) in the specified direction, and multiplying it by the desired distance. And to get the point on the unit circle, you can use $e^{i\\theta}$.\n\nA complex number of the format $r \\cdot e^{i\\theta}$ will be represented by a point which is $r$ units away from the origin, in the direction specified by the angle $\\theta$.\nSometimes $\\theta$ will be referred to as the number's **argument** or **phase**.\n\n> In Q#, complex numbers in polar form are represented as user-defined type `ComplexPolar` from the `Microsoft.Quantum.Math` namespace. \n> \n> You can convert a complex number $x = r \\cdot e^{i\\theta}$ into a tuple of two `Double` numbers using unwrap operator and tuple deconstruction: `let (r, theta) = x!;`, \n> or access its magnitude and phase using their names: `let (r, theta) = (x::Magnitude, x::Argument);`.\n> \n> You can construct a complex number from its magnitude and phase as follows: `let x = ComplexPolar(r, theta);`."
370
370
  }
371
371
  ]
372
372
  },
@@ -376,7 +376,7 @@ export default {
376
376
  "title": "Convert Cartesian to Polar",
377
377
  "description": {
378
378
  "type": "text-content",
379
- "content": "**Input:**\nA complex number $x = a + bi$.\n\n**Goal:**\nReturn the polar representation of $x = re^{i\\theta}$, i.e., the distance from origin $r$ and phase $\\theta$ as a `ComplexPolar`.\n\n* $r$ should be non-negative: $r \\geq 0$\n* $\\theta$ should be between $-\\pi$ and $\\pi$: $-\\pi < \\theta \\leq \\pi$\n\n<details>\n <summary><b>Need a hint?</b></summary>\n \nA video explanation of this conversion can be found [here](https://www.youtube.com/watch?v=8RasCV_Lggg).\n\n Q# namespace `Microsoft.Quantum.Math` includes a useful function `ArcTan2()`.\n\n</details>\n\n> Q# function `ComplexAsComplexPolar` from `Microsoft.Quantum.Math` namespace converts a complex number of type `Complex` to a complex number of type `ComplexPolar`. For educational purposes, try to do this task by hand.\n"
379
+ "content": "**Input:**\nA complex number $x = a + bi$.\n\n**Goal:**\nReturn the polar representation of $x = re^{i\\theta}$, that is, the distance from origin $r$ and phase $\\theta$ as a `ComplexPolar`.\n\n* $r$ should be non-negative: $r \\geq 0$\n* $\\theta$ should be between $-\\pi$ and $\\pi$: $-\\pi < \\theta \\leq \\pi$\n\n<details>\n <summary><b>Need a hint?</b></summary>\n \nA video explanation of this conversion can be found [here](https://www.youtube.com/watch?v=8RasCV_Lggg).\n\n Q# namespace `Microsoft.Quantum.Math` includes a useful function `ArcTan2()`.\n\n</details>\n\n> Q# function `ComplexAsComplexPolar` from `Microsoft.Quantum.Math` namespace converts a complex number of type `Complex` to a complex number of type `ComplexPolar`. For educational purposes, try to do this task by hand.\n"
380
380
  },
381
381
  "sourceIds": [
382
382
  "complex_arithmetic__cartesian_to_polar__Verification.qs",
@@ -389,7 +389,7 @@ export default {
389
389
  "items": [
390
390
  {
391
391
  "type": "text-content",
392
- "content": "\nWe need to calculate the $r$ and $\\theta$ values as seen in the complex plane. \n$r$ should be familiar to you already, since it is the modulus of a number (exercise 6):\n\n$$ r = \\sqrt{a^2 + b^2} $$\n\n$\\theta$ can be calculated using trigonometry: since we know that the polar and the Cartesian forms of the number represent the same value, we can write\n\n$$ re^{i \\theta} = a + bi $$\n\nEuler's formula allows us to express the left part of the equation as \n\n$$ re^{i \\theta} = r \\cos \\theta + i r \\sin \\theta $$\n\nFor two complex numbers to be equal, their real and imaginary parts have to be equal. This gives us the following system of equations:\n\n$$ \\begin{cases} a = r \\cos \\theta \\\\ b = r \\sin \\theta \\end{cases} $$\n\nTo calculate $\\theta$, we can divide the second equation by the first one to get\n\n$$ \\tan \\theta = \\frac{b}{a} $$\n\n$$ \\theta = \\arctan \\left(\\frac{b}{a}\\right) $$"
392
+ "content": "\nYou need to calculate the $r$ and $\\theta$ values as seen in the complex plane. \n$r$ should be familiar to you already, since it is the modulus of a number (exercise 6):\n\n$$ r = \\sqrt{a^2 + b^2} $$\n\n$\\theta$ can be calculated using trigonometry: since you know that the polar and the Cartesian forms of the number represent the same value, you can write\n\n$$ re^{i \\theta} = a + bi $$\n\nEuler's formula allows us to express the left part of the equation as \n\n$$ re^{i \\theta} = r \\cos \\theta + i r \\sin \\theta $$\n\nFor two complex numbers to be equal, their real and imaginary parts have to be equal. This gives you the following system of equations:\n\n$$ \\begin{cases} a = r \\cos \\theta \\\\ b = r \\sin \\theta \\end{cases} $$\n\nTo calculate $\\theta$, you can divide the second equation by the first one to get\n\n$$ \\tan \\theta = \\frac{b}{a} $$\n\n$$ \\theta = \\arctan \\left(\\frac{b}{a}\\right) $$"
393
393
  },
394
394
  {
395
395
  "type": "solution",
@@ -418,7 +418,7 @@ export default {
418
418
  "items": [
419
419
  {
420
420
  "type": "text-content",
421
- "content": "\nEuler's formula allows us to express the complex polar number as \n\n$$ re^{i \\theta} = \\underset{real}{\\underbrace{r \\cos \\theta}} + i \\underset{imaginary}{\\underbrace{r \\sin \\theta}}$$"
421
+ "content": "\nEuler's formula allows you to express the complex polar number as \n\n$$ re^{i \\theta} = \\underset{real}{\\underbrace{r \\cos \\theta}} + i \\underset{imaginary}{\\underbrace{r \\sin \\theta}}$$"
422
422
  },
423
423
  {
424
424
  "type": "solution",
@@ -447,7 +447,7 @@ export default {
447
447
  "items": [
448
448
  {
449
449
  "type": "text-content",
450
- "content": "\nMultiplying two complex numbers in polar form can be done efficiently in the following way:\n\n$$ z = x \\cdot y = r_{1}e^{\\theta_1 i} \\cdot r_{2}e^{\\theta_2 i} = r_{1}r_{2} \\cdot e^{(\\theta_1 + \\theta_2)i} $$ \n\n> Here is the longer approach of converting the numbers to the Cartesian from and doing multiplication in it: \n> $$ x = r_{1}e^{i\\theta_1} = r_{1}(\\cos \\theta_1 + i \\sin \\theta_1) $$\n> $$ y = r_{2}e^{i\\theta_2} = r_{2}(\\cos \\theta_2 + i \\sin \\theta_2) $$\n> $$ z = x \\cdot y = r_1r_2 \\cdot \\left( \\cos \\theta_1 \\cos \\theta_2 − \\sin \\theta_1 \\sin \\theta_2 + \ni (\\sin \\theta_1 \\cos \\theta_2 + \\sin \\theta_2 \\cos \\theta_1 ) \\right) $$\n>\n> We can simplify this using the following trigonometric identities:\n> * $\\cos a \\cos b \\mp \\sin a \\sin b = \\cos(a \\pm b)$\n> * $\\sin a \\cos b \\pm \\sin b \\cos a = \\sin(a \\pm b)$\n>\n> Finally, this solution gives the same answer as the short solution above:\n>$$r_{1}r_{2}(\\cos(\\theta_1 + \\theta_2) + i \\sin(\\theta_1 + \\theta_2)) = r_{1}r_{2} \\cdot e^{(\\theta_1 + \\theta_2)i} $$"
450
+ "content": "\nMultiplying two complex numbers in polar form can be done efficiently in the following way:\n\n$$ z = x \\cdot y = r_{1}e^{\\theta_1 i} \\cdot r_{2}e^{\\theta_2 i} = r_{1}r_{2} \\cdot e^{(\\theta_1 + \\theta_2)i} $$ \n\n> Here is the longer approach of converting the numbers to the Cartesian from and doing multiplication in it: \n> $$ x = r_{1}e^{i\\theta_1} = r_{1}(\\cos \\theta_1 + i \\sin \\theta_1) $$\n> $$ y = r_{2}e^{i\\theta_2} = r_{2}(\\cos \\theta_2 + i \\sin \\theta_2) $$\n> $$ z = x \\cdot y = r_1r_2 \\cdot \\left( \\cos \\theta_1 \\cos \\theta_2 − \\sin \\theta_1 \\sin \\theta_2 + \ni (\\sin \\theta_1 \\cos \\theta_2 + \\sin \\theta_2 \\cos \\theta_1 ) \\right) $$\n>\n> You can simplify this using the following trigonometric identities:\n> * $\\cos a \\cos b \\mp \\sin a \\sin b = \\cos(a \\pm b)$\n> * $\\sin a \\cos b \\pm \\sin b \\cos a = \\sin(a \\pm b)$\n>\n> Finally, this solution gives the same answer as the short solution above:\n>$$r_{1}r_{2}(\\cos(\\theta_1 + \\theta_2) + i \\sin(\\theta_1 + \\theta_2)) = r_{1}r_{2} \\cdot e^{(\\theta_1 + \\theta_2)i} $$"
451
451
  },
452
452
  {
453
453
  "type": "solution",
@@ -962,7 +962,7 @@ export default {
962
962
  "items": [
963
963
  {
964
964
  "type": "text-content",
965
- "content": "\nThis kata introduces you to one of the core concepts in quantum computing - the qubit, and its representation in mathematical notation and in Q# code.\n\n**This kata covers the following topics:**\n\n- The concept of a qubit\n- Superposition\n- Vector representation of qubit states\n- Dirac notation for single-qubit states\n- Relative and global phase\n- `Qubit` data type in Q#\n- Visualizing the quantum state using `DumpMachine`\n\n**What you should know to start working on this kata:**\n\n- Basic knowledge of complex arithmetic\n- Basic knowledge of linear algebra"
965
+ "content": "\nThis kata introduces you to one of the core concepts in quantum computing - the qubit, and its representation in mathematical notation and in Q# code.\n\n**This kata covers the following topics:**\n\n- The concept of a qubit\n- Superposition\n- Vector representation of qubit states\n- Dirac notation for single-qubit states\n- Relative and global phase\n- `Qubit` data type in Q#\n- Visualizing the quantum state using `DumpMachine`\n\n**What you should know to start working on this kata:**\n\n- Basic concepts of complex arithmetic\n- Basic concepts of linear algebra\n\nIf you need a refresher on these topics, you can check out the previous katas."
966
966
  }
967
967
  ]
968
968
  },
@@ -1072,7 +1072,7 @@ export default {
1072
1072
  "items": [
1073
1073
  {
1074
1074
  "type": "text-content",
1075
- "content": "\nThis kata introduces you to single-qubit gates. Quantum gates are the quantum counterpart to classical logic gates, acting as the building blocks of quantum algorithms. Quantum gates transform qubit states in various ways, and can be applied sequentially to perform complex quantum calculations. Single-qubit gates, as their name implies, act on individual qubits. You can learn more at <a href=\"https://en.wikipedia.org/wiki/Quantum_logic_gate\" target=\"_blank\">Wikipedia</a>.\n\n**This kata covers the following topics:**\n\n- Matrix representation\n- Ket-bra representation\n- The most important single-qubit gates\n\n**What you should know to start working on this kata:**\n\n- Basic linear algebra\n- The concept of qubit"
1075
+ "content": "\nThis kata introduces you to single-qubit gates. Quantum gates are the quantum counterpart to classical logic gates, acting as the building blocks of quantum algorithms. Quantum gates transform qubit states in various ways, and can be applied sequentially to perform complex quantum calculations. Single-qubit gates, as their name implies, act on individual qubits. You can learn more at <a href=\"https://en.wikipedia.org/wiki/Quantum_logic_gate\" target=\"_blank\">Wikipedia</a>.\n\n**This kata covers the following topics:**\n\n- Matrix representation\n- Ket-bra representation\n- The most important single-qubit gates\n\n**What you should know to start working on this kata:**\n\n- Basic knowledge of linear algebra\n- The concept of qubit\n\nIf you need a refresher on these topics, you can check out the previous katas."
1076
1076
  }
1077
1077
  ]
1078
1078
  },
@@ -1083,7 +1083,7 @@ export default {
1083
1083
  "items": [
1084
1084
  {
1085
1085
  "type": "text-content",
1086
- "content": "\nThere are certain properties common to all quantum gates. This section will introduce those properties, using the $X$ gate as an example.\n\n## Matrix Representation\n\nQuantum gates are represented as $2^N \\times 2^N$ unitary matrices, where $N$ is the number of qubits the gate operates on.\nAs a quick reminder, a unitary matrix is a square matrix whose inverse is its adjoint, thus $U^* U = UU^* = UU^{-1} = \\mathbb{I}$.\nSingle-qubit gates are represented by $2 \\times 2$ matrices.\nOur example for this section, the $X$ gate, is represented by the following matrix:\n\n$$\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$$\n\nYou may recall that the state of a qubit is represented by a vector of size $2$. You can apply a gate to a qubit by multiplying the gate's matrix by the qubit's state vector. The result will be another vector, representing the new state of the qubit. For example, applying the $X$ gate to the computational basis states looks like this:\n\n$$\nX\\ket{0} =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 \\cdot 1 + 1 \\cdot 0 \\\\ 1 \\cdot 1 + 0 \\cdot 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\n$$\n\n$$\nX\\ket{1} =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} =\n\\begin{bmatrix} 0 \\cdot 0 + 1 \\cdot 1 \\\\ 1 \\cdot 0 + 0 \\cdot 1 \\end{bmatrix} =\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}\n$$\n\nThe general case:\n\n$$\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$$\n\n$$\nX\\ket{\\psi} =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n\\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} =\n\\begin{bmatrix} 0 \\cdot \\alpha + 1 \\cdot \\beta \\\\ 1 \\cdot \\alpha + 0 \\cdot \\beta \\end{bmatrix} =\n\\begin{bmatrix} \\beta \\\\ \\alpha \\end{bmatrix}\n$$\n\n> If you need a reminder of what $\\ket{0}$, $\\ket{1}$, and $\\ket{\\psi}$ mean, you can review the section on Dirac notation in \"The Qubit\" kata.\n\nQuantum gates are represented by matrices, just like quantum states are represented by vectors. Because this is the most common way to represent quantum gates, the terms \"gate\" and \"gate matrix\" will be used interchangeably in this kata.\n\nApplying several quantum gates in sequence is equivalent to performing several of these multiplications.\nFor example, if you have gates $A$ and $B$ and a qubit in state $\\ket{\\psi}$, the result of applying $A$ followed by $B$ to that qubit would be $B\\big(A\\ket{\\psi}\\big)$ (the gate closest to the qubit state gets applied first).\nMatrix multiplication is associative, so this is equivalent to multiplying the $B$ matrix by the $A$ matrix, producing a compound gate of the two, and then applying that to the qubit: $\\big(BA\\big)\\ket{\\psi}$.\n\n>Note that matrix multiplication isn’t commutative, thus $(BA) \\neq (AB)$.\n\nAll quantum gates are reversible - there is another gate which will undo any given gate's transformation, returning the qubit to its original state.\nThis means that when dealing with quantum gates, information about qubit states is never lost, as opposed to classical logic gates, some of which destroy information.\nQuantum gates are represented by unitary matrices, so the inverse of a gate is its adjoint; these terms are also used interchangeably in quantum computing.\n\n## Effects on Basis States\n\nThere is a simple way to find out what a gate does to the two computational basis states $\\ket{0}$ and $\\ket{1}$. Consider an arbitrary gate:\n\n$$A = \\begin{bmatrix} \\epsilon & \\zeta \\\\ \\eta & \\mu \\end{bmatrix}$$\n\nWatch what happens when we apply it to these states:\n\n$$\nA\\ket{0} =\n\\begin{bmatrix} \\epsilon & \\zeta \\\\ \\eta & \\mu \\end{bmatrix}\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} \\epsilon \\cdot 1 + \\zeta \\cdot 0 \\\\ \\eta \\cdot 1 + \\mu \\cdot 0 \\end{bmatrix} =\n\\begin{bmatrix} \\epsilon \\\\ \\eta \\end{bmatrix} = \\epsilon\\ket{0} + \\eta\\ket{1}\n$$\n\n$$\nA\\ket{1} =\n\\begin{bmatrix} \\epsilon & \\zeta \\\\ \\eta & \\mu \\end{bmatrix}\n\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} =\n\\begin{bmatrix} \\epsilon \\cdot 0 + \\zeta \\cdot 1 \\\\ \\eta \\cdot 0 + \\mu \\cdot 1 \\end{bmatrix} =\n\\begin{bmatrix} \\zeta \\\\ \\mu \\end{bmatrix} = \\zeta\\ket{0} + \\mu\\ket{1}\n$$\n\nNotice that applying the gate to the $\\ket{0}$ state transforms it into the state written as the first column of the gate's matrix. Likewise, applying the gate to the $\\ket{1}$ state transforms it into the state written as the second column. This holds true for any quantum gate, including, of course, the $X$ gate:\n\n$$X = \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$$\n\n$$X\\ket{0} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} = \\ket{1}$$\n\n$$X\\ket{1} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = \\ket{0}$$\n\nOnce you understand how a gate affects the computational basis states, you can easily find how it affects any state.\nRecall that any qubit state vector can be written as a linear combination of the basis states:\n\n$$\\ket{\\psi} = \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} = \\alpha\\ket{0} + \\beta\\ket{1}$$\n\nBecause matrix multiplication distributes over addition, once you know how a gate affects those two basis states, you can calculate how it affects any state:\n\n$$X\\ket{\\psi} = X\\big(\\alpha\\ket{0} + \\beta\\ket{1}\\big) = X\\big(\\alpha\\ket{0}\\big) + X\\big(\\beta\\ket{1}\\big) = \\alpha X\\ket{0} + \\beta X\\ket{1} = \\alpha\\ket{1} + \\beta\\ket{0}$$\n\nThat is, applying a gate to a qubit in superposition is equivalent to applying that gate to the basis states that make up that superposition and adding the results with appropriate weights."
1086
+ "content": "\nThere are certain properties common to all quantum gates. This section introduces those properties, using the $X$ gate as an example.\n\n## Matrix Representation\n\nQuantum gates are represented as $2^N \\times 2^N$ unitary matrices, where $N$ is the number of qubits the gate operates on.\nAs a quick reminder, a unitary matrix is a square matrix whose inverse is its adjoint, thus $U^* U = UU^* = UU^{-1} = \\mathbb{I}$.\nSingle-qubit gates are represented by $2 \\times 2$ matrices.\nOur example for this section, the $X$ gate, is represented by the following matrix:\n\n$$\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$$\n\nYou may recall that the state of a qubit is represented by a vector of size $2$. You can apply a gate to a qubit by multiplying the gate's matrix by the qubit's state vector. The result will be another vector, representing the new state of the qubit. For example, applying the $X$ gate to the computational basis states looks like this:\n\n$$\nX\\ket{0} =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 \\cdot 1 + 1 \\cdot 0 \\\\ 1 \\cdot 1 + 0 \\cdot 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\n$$\n\n$$\nX\\ket{1} =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} =\n\\begin{bmatrix} 0 \\cdot 0 + 1 \\cdot 1 \\\\ 1 \\cdot 0 + 0 \\cdot 1 \\end{bmatrix} =\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}\n$$\n\nThe general case:\n\n$$\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$$\n\n$$\nX\\ket{\\psi} =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n\\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} =\n\\begin{bmatrix} 0 \\cdot \\alpha + 1 \\cdot \\beta \\\\ 1 \\cdot \\alpha + 0 \\cdot \\beta \\end{bmatrix} =\n\\begin{bmatrix} \\beta \\\\ \\alpha \\end{bmatrix}\n$$\n\n> If you need a reminder of what $\\ket{0}$, $\\ket{1}$, and $\\ket{\\psi}$ mean, you can review the section on Dirac notation in \"The Qubit\" kata.\n\nQuantum gates are represented by matrices, just like quantum states are represented by vectors. Because this is the most common way to represent quantum gates, the terms \"gate\" and \"gate matrix\" will be used interchangeably in this kata.\n\nApplying several quantum gates in sequence is equivalent to performing several of these multiplications.\nFor example, if you have gates $A$ and $B$ and a qubit in state $\\ket{\\psi}$, the result of applying $A$ followed by $B$ to that qubit would be $B\\big(A\\ket{\\psi}\\big)$ (the gate closest to the qubit state gets applied first).\nMatrix multiplication is associative, so this is equivalent to multiplying the $B$ matrix by the $A$ matrix, producing a compound gate of the two, and then applying that to the qubit: $\\big(BA\\big)\\ket{\\psi}$.\n\n>Note that matrix multiplication isn’t commutative, thus $(BA) \\neq (AB)$.\n\nAll quantum gates are reversible, that is, there exists another gate which will undo any given gate's transformation, returning the qubit to its original state.\nThis means that when dealing with quantum gates, information about qubit states is never lost, as opposed to classical logic gates, some of which destroy information.\nQuantum gates are represented by unitary matrices, so the inverse of a gate is its adjoint; these terms are also used interchangeably in quantum computing.\n\n## Effects on Basis States\n\nThere is a simple way to find out what a gate does to the two computational basis states $\\ket{0}$ and $\\ket{1}$. Consider an arbitrary gate:\n\n$$A = \\begin{bmatrix} \\epsilon & \\zeta \\\\ \\eta & \\mu \\end{bmatrix}$$\n\nWatch what happens when applying $A$ to these states:\n\n$$\nA\\ket{0} =\n\\begin{bmatrix} \\epsilon & \\zeta \\\\ \\eta & \\mu \\end{bmatrix}\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} \\epsilon \\cdot 1 + \\zeta \\cdot 0 \\\\ \\eta \\cdot 1 + \\mu \\cdot 0 \\end{bmatrix} =\n\\begin{bmatrix} \\epsilon \\\\ \\eta \\end{bmatrix} = \\epsilon\\ket{0} + \\eta\\ket{1}\n$$\n\n$$\nA\\ket{1} =\n\\begin{bmatrix} \\epsilon & \\zeta \\\\ \\eta & \\mu \\end{bmatrix}\n\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} =\n\\begin{bmatrix} \\epsilon \\cdot 0 + \\zeta \\cdot 1 \\\\ \\eta \\cdot 0 + \\mu \\cdot 1 \\end{bmatrix} =\n\\begin{bmatrix} \\zeta \\\\ \\mu \\end{bmatrix} = \\zeta\\ket{0} + \\mu\\ket{1}\n$$\n\nNotice that applying the $A$ gate to the $\\ket{0}$ state transforms it into the state written as the first column of the gate's matrix. Likewise, applying the $A$ gate to the $\\ket{1}$ state transforms it into the state written as the second column. This holds true for any quantum gate, including, of course, the $X$ gate:\n\n$$X = \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$$\n\n$$X\\ket{0} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} = \\ket{1}$$\n\n$$X\\ket{1} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = \\ket{0}$$\n\nOnce you understand how a gate affects the computational basis states, you can easily find how it affects any state.\nRecall that any qubit state vector can be written as a linear combination of the basis states:\n\n$$\\ket{\\psi} = \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} = \\alpha\\ket{0} + \\beta\\ket{1}$$\n\nBecause matrix multiplication distributes over addition, once you know how a gate affects those two basis states, you can calculate how it affects any state:\n\n$$X\\ket{\\psi} = X\\big(\\alpha\\ket{0} + \\beta\\ket{1}\\big) = X\\big(\\alpha\\ket{0}\\big) + X\\big(\\beta\\ket{1}\\big) = \\alpha X\\ket{0} + \\beta X\\ket{1} = \\alpha\\ket{1} + \\beta\\ket{0}$$\n\nThat is, applying a gate to a qubit in superposition is equivalent to applying that gate to the basis states that make up that superposition and adding the results with appropriate weights."
1087
1087
  }
1088
1088
  ]
1089
1089
  },
@@ -1094,7 +1094,7 @@ export default {
1094
1094
  "items": [
1095
1095
  {
1096
1096
  "type": "text-content",
1097
- "content": "\nThere is another way to represent quantum gates, this time using Dirac notation. However, the kets we've been using aren't enough to represent arbitrary matrices. We need to introduce another piece of notation: the **bra** (this is why Dirac notation is sometimes called **bra-ket notation**).\n\nRecall that kets represent column vectors; a bra is a ket's row vector counterpart. For any ket $\\ket{\\psi}$, the corresponding bra is its adjoint (conjugate transpose): $\\bra{\\psi} = \\ket{\\psi}^\\dagger$.\n\nSome examples:\n\n<table>\n <tr>\n <th>Ket</th>\n <th>Bra</th>\n </tr>\n <tr>\n <td>$\\ket{0} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}$</td>\n <td>$\\bra{0} = \\begin{bmatrix} 1 & 0 \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{1} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$</td>\n <td>$\\bra{1} = \\begin{bmatrix} 0 & 1 \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{i} = \\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ \\frac{i}{\\sqrt{2}} \\end{bmatrix}$</td>\n <td>$\\bra{ i} = \\begin{bmatrix} \\frac{1}{\\sqrt{2}} & -\\frac{i}{\\sqrt{2}} \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{\\psi} = \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix}$</td>\n <td>$\\bra{\\psi} = \\begin{bmatrix} \\overline{\\alpha} & \\overline{\\beta} \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</td>\n <td>$\\bra{\\psi} = \\overline{\\alpha}\\bra{0} + \\overline{\\beta}\\bra{1}$</td>\n </tr>\n</table>\n\nKets and bras give us a neat way to express inner and outer products. The inner product of $\\ket{\\phi}$ and $\\ket{\\psi}$ is the matrix product of $\\bra{\\phi}$ and $\\ket{\\psi}$, denoted as $\\braket{\\phi|\\psi}$, and their outer product is the matrix product of $\\ket{\\phi}$ and $\\bra{\\psi}$, denoted as $\\ket{\\phi}\\bra{\\psi}$. Notice that the norm of $\\ket{\\psi}$ is $\\sqrt{\\braket{\\psi|\\psi}}$.\n\nThis brings us to representing matrices. Recall that the outer product of two vectors of the same size produces a square matrix. We can use a linear combination of several outer products of simple vectors (such as basis vectors) to express any square matrix. For example, the $X$ gate can be expressed as follows:\n\n$$X = \\ket{0}\\bra{1} + \\ket{1}\\bra{0}$$\n\n$$\n\\ket{0}\\bra{1} + \\ket{1}\\bra{0} =\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 & 1 \\end{bmatrix} +\n\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\\begin{bmatrix} 1 & 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 & 1 \\\\ 0 & 0 \\end{bmatrix} + \\begin{bmatrix} 0 & 0 \\\\ 1 & 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n$$\n\nThis representation can be used to carry out calculations in Dirac notation without ever switching back to matrix representation:\n\n$$X\\ket{0} = \\big(\\ket{0}\\bra{1} + \\ket{1}\\bra{0}\\big)\\ket{0} = \\ket{0}\\braket{1|0} + \\ket{1}\\braket{0|0} = \\ket{0}\\big(\\braket{1|0}\\big) + \\ket{1}\\big(\\braket{0|0}\\big) = \\ket{0}(0) + \\ket{1}(1) = \\ket{1}$$\n\n> That last step may seem a bit confusing. Recall that $\\ket{0}$ and $\\ket{1}$ form an **orthonormal basis**. That is, they are both normalized, and they are orthogonal to each other.\n>\n> A vector is normalized if its norm is equal to $1$, which only happens if its inner product with itself is equal to $1$. This means that $\\braket{0|0} = \\braket{1|1} = 1$\n>\n> Two vectors are orthogonal to each other if their inner product equals $0$. This means that $\\braket{0|1} = \\braket{1|0} = 0$.\n\nIn general case, a matrix\n$$A = \\begin{bmatrix} a_{00} & a_{01} \\\\ a_{10} & a_{11} \\end{bmatrix}$$\nwill have the following ket-bra representation:\n$$A = a_{00} \\ket{0}\\bra{0} + a_{01} \\ket{0}\\bra{1} + a_{10} \\ket{1}\\bra{0} + a_{11} \\ket{1}\\bra{1}$$"
1097
+ "content": "\nThere is another way to represent quantum gates, this time using Dirac notation. However, kets aren't enough to represent arbitrary matrices. An additional notation is required: the **bra** (this is why Dirac notation is sometimes called **bra-ket notation**).\n\nRecall that kets represent column vectors; a bra is a ket's row vector counterpart. For any ket $\\ket{\\psi}$, the corresponding bra is its adjoint (conjugate transpose): $\\bra{\\psi} = \\ket{\\psi}^\\dagger$.\n\nSome examples:\n\n<table>\n <tr>\n <th>Ket</th>\n <th>Bra</th>\n </tr>\n <tr>\n <td>$\\ket{0} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}$</td>\n <td>$\\bra{0} = \\begin{bmatrix} 1 & 0 \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{1} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$</td>\n <td>$\\bra{1} = \\begin{bmatrix} 0 & 1 \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{i} = \\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ \\frac{i}{\\sqrt{2}} \\end{bmatrix}$</td>\n <td>$\\bra{ i} = \\begin{bmatrix} \\frac{1}{\\sqrt{2}} & -\\frac{i}{\\sqrt{2}} \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{\\psi} = \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix}$</td>\n <td>$\\bra{\\psi} = \\begin{bmatrix} \\overline{\\alpha} & \\overline{\\beta} \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</td>\n <td>$\\bra{\\psi} = \\overline{\\alpha}\\bra{0} + \\overline{\\beta}\\bra{1}$</td>\n </tr>\n</table>\n\nKets and bras give us a neat way to express inner and outer products. The inner product of $\\ket{\\phi}$ and $\\ket{\\psi}$ is the matrix product of $\\bra{\\phi}$ and $\\ket{\\psi}$, denoted as $\\braket{\\phi|\\psi}$, and their outer product is the matrix product of $\\ket{\\phi}$ and $\\bra{\\psi}$, denoted as $\\ket{\\phi}\\bra{\\psi}$. Notice that the norm of $\\ket{\\psi}$ is $\\sqrt{\\braket{\\psi|\\psi}}$.\n\nThis leads to the representation of matrices via outer products. Recall that the outer product of two vectors of the same size produces a square matrix. You can use a linear combination of several outer products of simple vectors (such as basis vectors) to express any square matrix. For example, the $X$ gate can be expressed as follows:\n\n$$X = \\ket{0}\\bra{1} + \\ket{1}\\bra{0}$$\n\n$$\n\\ket{0}\\bra{1} + \\ket{1}\\bra{0} =\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 & 1 \\end{bmatrix} +\n\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\\begin{bmatrix} 1 & 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 & 1 \\\\ 0 & 0 \\end{bmatrix} + \\begin{bmatrix} 0 & 0 \\\\ 1 & 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n$$\n\nThis representation can be used to carry out calculations in Dirac notation without ever switching back to matrix representation:\n\n$$X\\ket{0} = \\big(\\ket{0}\\bra{1} + \\ket{1}\\bra{0}\\big)\\ket{0} = \\ket{0}\\braket{1|0} + \\ket{1}\\braket{0|0} = \\ket{0}\\big(\\braket{1|0}\\big) + \\ket{1}\\big(\\braket{0|0}\\big) = \\ket{0}(0) + \\ket{1}(1) = \\ket{1}$$\n\n> That last step may seem a bit confusing. Recall that $\\ket{0}$ and $\\ket{1}$ form an **orthonormal basis**. That is, they're both normalized, and they're orthogonal to each other.\n>\n> A vector is normalized if its norm is equal to $1$, which only happens if its inner product with itself is equal to $1$. This means that $\\braket{0|0} = \\braket{1|1} = 1$\n>\n> Two vectors are orthogonal to each other if their inner product equals $0$. This means that $\\braket{0|1} = \\braket{1|0} = 0$.\n\nIn general case, a matrix\n$$A = \\begin{bmatrix} a_{00} & a_{01} \\\\ a_{10} & a_{11} \\end{bmatrix}$$\nwill have the following ket-bra representation:\n$$A = a_{00} \\ket{0}\\bra{0} + a_{01} \\ket{0}\\bra{1} + a_{10} \\ket{1}\\bra{0} + a_{11} \\ket{1}\\bra{1}$$"
1098
1098
  }
1099
1099
  ]
1100
1100
  },
@@ -1105,7 +1105,7 @@ export default {
1105
1105
  "items": [
1106
1106
  {
1107
1107
  "type": "text-content",
1108
- "content": "\nThis section describes a more formal process of finding the ket-bra decompositions of quantum gates. This section is not necessary to start working with quantum gates, so feel free to skip it for now, and come back to it later.\n\nYou can use the properties of _eigenvalues_ and _eigenvectors_ to find the ket-bra decomposition of any gate. Given a gate $A$ and the orthogonal vectors $\\ket{\\phi}$ and $\\ket{\\psi}$, if:\n\n$$A\\ket{\\phi} = x_\\phi\\ket{\\phi}$$\n$$A\\ket{\\psi} = x_\\psi\\ket{\\psi}$$\n\nReal numbers $x_\\phi$ and $x_\\psi$ are called eigenvalues and $\\ket{\\phi}$ and $\\ket{\\psi}$ are eigenvectors of $A$. Then:\n\n$$A = x_\\phi\\ket{\\phi}\\bra{\\phi} + x_\\psi\\ket{\\psi}\\bra{\\psi}$$\n\nLet's use our $X$ gate as a simple example. The $X$ gate has two eigenvectors: $\\ket{+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + \\ket{1}\\big)$ and $\\ket{-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - \\ket{1}\\big)$. Their eigenvalues are $1$ and $-1$ respectively:\n\n$$X\\ket{+} = \\ket{+}$$\n$$X\\ket{-} = -\\ket{-}$$\n\nHere's what the decomposition looks like:\n$$X = \\ket{+}\\bra{+} - \\ket{-}\\bra{-} =$$\n$$= \\frac{1}{2}\\big[\\big(\\ket{0} + \\ket{1}\\big)\\big(\\bra{0} + \\bra{1}\\big) - \\big(\\ket{0} - \\ket{1}\\big)\\big(\\bra{0} - \\bra{1}\\big)\\big] =$$\n$$= \\frac{1}{2}\\big(\\ket{0}\\bra{0} + \\ket{0}\\bra{1} + \\ket{1}\\bra{0} + \\ket{1}\\bra{1} - \\ket{0}\\bra{0} + \\ket{0}\\bra{1} + \\ket{1}\\bra{0} - \\ket{1}\\bra{1}\\big) =$$\n$$= \\frac{1}{2}\\big(2\\ket{0}\\bra{1} + 2\\ket{1}\\bra{0}\\big) =$$\n$$= \\ket{0}\\bra{1} + \\ket{1}\\bra{0}$$"
1108
+ "content": "\nThis section describes a more formal process of finding the ket-bra decompositions of quantum gates. This section isn't necessary to start working with quantum gates, so feel free to skip it for now, and come back to it later.\n\nYou can use the properties of _eigenvalues_ and _eigenvectors_ to find the ket-bra decomposition of any gate. Given a gate $A$ and the orthogonal vectors $\\ket{\\phi}$ and $\\ket{\\psi}$, if:\n\n$$A\\ket{\\phi} = x_\\phi\\ket{\\phi}$$\n$$A\\ket{\\psi} = x_\\psi\\ket{\\psi}$$\n\nReal numbers $x_\\phi$ and $x_\\psi$ are called eigenvalues and $\\ket{\\phi}$ and $\\ket{\\psi}$ are eigenvectors of $A$. Then:\n\n$$A = x_\\phi\\ket{\\phi}\\bra{\\phi} + x_\\psi\\ket{\\psi}\\bra{\\psi}$$\n\nLet's use our $X$ gate as a simple example. The $X$ gate has two eigenvectors: $\\ket{+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + \\ket{1}\\big)$ and $\\ket{-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - \\ket{1}\\big)$. Their eigenvalues are $1$ and $-1$ respectively:\n\n$$X\\ket{+} = \\ket{+}$$\n$$X\\ket{-} = -\\ket{-}$$\n\nHere's what the decomposition looks like:\n$$X = \\ket{+}\\bra{+} - \\ket{-}\\bra{-} =$$\n$$= \\frac{1}{2}\\big[\\big(\\ket{0} + \\ket{1}\\big)\\big(\\bra{0} + \\bra{1}\\big) - \\big(\\ket{0} - \\ket{1}\\big)\\big(\\bra{0} - \\bra{1}\\big)\\big] =$$\n$$= \\frac{1}{2}\\big(\\ket{0}\\bra{0} + \\ket{0}\\bra{1} + \\ket{1}\\bra{0} + \\ket{1}\\bra{1} - \\ket{0}\\bra{0} + \\ket{0}\\bra{1} + \\ket{1}\\bra{0} - \\ket{1}\\bra{1}\\big) =$$\n$$= \\frac{1}{2}\\big(2\\ket{0}\\bra{1} + 2\\ket{1}\\bra{0}\\big) =$$\n$$= \\ket{0}\\bra{1} + \\ket{1}\\bra{0}$$"
1109
1109
  }
1110
1110
  ]
1111
1111
  },
@@ -1116,7 +1116,7 @@ export default {
1116
1116
  "items": [
1117
1117
  {
1118
1118
  "type": "text-content",
1119
- "content": "\nThis section introduces some of the common single-qubit gates, including their matrix form, their ket-bra decomposition, and a brief \"cheatsheet\" listing their effect on some common qubit states.\n\nYou can use a tool called <a href=\"https://algassert.com/quirk\" target=\"_blank\">Quirk</a> to visualize how these gates interact with various qubit states.\n\nThis section relies on the following notation:\n\n<table>\n <tr>\n <td>$\\ket{+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + \\ket{1}\\big)$</td>\n <td>$\\ket{-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - \\ket{1}\\big)$</td>\n </tr>\n <tr>\n <td>$\\ket{i} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + i\\ket{1}\\big)$</td>\n <td>$\\ket{-i} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - i\\ket{1}\\big)$</td>\n </tr>\n</table>\n\nThe Pauli gates, named after <a href=\"https://en.wikipedia.org/wiki/Wolfgang_Pauli\" target=\"_blank\">Wolfgang Pauli</a>, are based on the so-called **Pauli matrices**, $X$, $Y$ and $Z$. All three Pauli gates are **self-adjoint**, meaning that each one is its own inverse, $XX = \\mathbb{I}$.\n\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$X$</td>\n <td>$\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{1} + \\ket{1}\\bra{0}$</td>\n <td>$X\\ket{\\psi} = \\alpha\\ket{1} + \\beta\\ket{0}$</td>\n <td>\n $X\\ket{0} = \\ket{1}$<br>\n $X\\ket{1} = \\ket{0}$<br>\n $X\\ket{+} = \\ket{+}$<br>\n $X\\ket{-} = -\\ket{-}$<br>\n $X\\ket{i} = i\\ket{-i}$<br>\n $X\\ket{-i} = -i\\ket{i}$\n </td>\n </tr>\n <tr>\n <td>$Y$</td>\n <td>$\\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}$</td>\n <td>$i(\\ket{1}\\bra{0} - \\ket{0}\\bra{1})$</td>\n <td>$Y\\ket{\\psi} = i\\big(\\alpha\\ket{1} - \\beta\\ket{0}\\big)$</td>\n <td>\n $Y\\ket{0} = i\\ket{1}$<br>\n $Y\\ket{1} = -i\\ket{0}$<br>\n $Y\\ket{+} = -i\\ket{-}$<br>\n $Y\\ket{-} = i\\ket{+}$<br>\n $Y\\ket{i} = \\ket{i}$<br>\n $Y\\ket{-i} = -\\ket{-i}$<br>\n </td>\n </tr>\n <tr>\n <td>$Z$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} - \\ket{1}\\bra{1}$</td>\n <td>$Z\\ket{\\psi} = \\alpha\\ket{0} - \\beta\\ket{1}$</td>\n <td>\n $Z\\ket{0} = \\ket{0}$<br>\n $Z\\ket{1} = -\\ket{1}$<br>\n $Z\\ket{+} = \\ket{-}$<br>\n $Z\\ket{-} = \\ket{+}$<br>\n $Z\\ket{i} = \\ket{-i}$<br>\n $Z\\ket{-i} = \\ket{i}$<br>\n </td>\n </tr>\n</table>\n\n> The $X$ gate is sometimes referred to as the **bit flip** gate, or the **NOT** gate, because it acts like the classical NOT gate on the computational basis.\n>\n> The $Z$ gate is sometimes referred to as the **phase flip** gate.\n\nHere are several properties of the Pauli gates that are easy to verify and convenient to remember:\n\n- Different Pauli gates _anti-commute_:\n $$XZ = -ZX, XY = -YX, YZ = -ZY$$\n- A product of any two Pauli gates equals the third gate, with an extra $i$ (or $-i$) phase:\n $$XY = iZ, YZ = iX, ZX = iY$$\n- A product of all three Pauli gates equals identity (with an extra $i$ phase):\n $$XYZ = iI$$"
1119
+ "content": "\nThis section introduces some of the common single-qubit gates, including their matrix form, their ket-bra decomposition, and a brief \"cheat sheet\" listing their effect on some common qubit states.\n\nYou can use a tool called <a href=\"https://algassert.com/quirk\" target=\"_blank\">Quirk</a> to visualize how these gates interact with various qubit states.\n\nThis section relies on the following notation:\n\n<table>\n <tr>\n <td>$\\ket{+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + \\ket{1}\\big)$</td>\n <td>$\\ket{-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - \\ket{1}\\big)$</td>\n </tr>\n <tr>\n <td>$\\ket{i} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + i\\ket{1}\\big)$</td>\n <td>$\\ket{-i} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - i\\ket{1}\\big)$</td>\n </tr>\n</table>\n\nThe Pauli gates, named after <a href=\"https://en.wikipedia.org/wiki/Wolfgang_Pauli\" target=\"_blank\">Wolfgang Pauli</a>, are based on the so-called **Pauli matrices**, $X$, $Y$ and $Z$. All three Pauli gates are **self-adjoint**, meaning that each one is its own inverse, $XX = \\mathbb{I}$.\n\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$X$</td>\n <td>$\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{1} + \\ket{1}\\bra{0}$</td>\n <td>$X\\ket{\\psi} = \\alpha\\ket{1} + \\beta\\ket{0}$</td>\n <td>\n $X\\ket{0} = \\ket{1}$<br>\n $X\\ket{1} = \\ket{0}$<br>\n $X\\ket{+} = \\ket{+}$<br>\n $X\\ket{-} = -\\ket{-}$<br>\n $X\\ket{i} = i\\ket{-i}$<br>\n $X\\ket{-i} = -i\\ket{i}$\n </td>\n </tr>\n <tr>\n <td>$Y$</td>\n <td>$\\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}$</td>\n <td>$i(\\ket{1}\\bra{0} - \\ket{0}\\bra{1})$</td>\n <td>$Y\\ket{\\psi} = i\\big(\\alpha\\ket{1} - \\beta\\ket{0}\\big)$</td>\n <td>\n $Y\\ket{0} = i\\ket{1}$<br>\n $Y\\ket{1} = -i\\ket{0}$<br>\n $Y\\ket{+} = -i\\ket{-}$<br>\n $Y\\ket{-} = i\\ket{+}$<br>\n $Y\\ket{i} = \\ket{i}$<br>\n $Y\\ket{-i} = -\\ket{-i}$<br>\n </td>\n </tr>\n <tr>\n <td>$Z$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} - \\ket{1}\\bra{1}$</td>\n <td>$Z\\ket{\\psi} = \\alpha\\ket{0} - \\beta\\ket{1}$</td>\n <td>\n $Z\\ket{0} = \\ket{0}$<br>\n $Z\\ket{1} = -\\ket{1}$<br>\n $Z\\ket{+} = \\ket{-}$<br>\n $Z\\ket{-} = \\ket{+}$<br>\n $Z\\ket{i} = \\ket{-i}$<br>\n $Z\\ket{-i} = \\ket{i}$<br>\n </td>\n </tr>\n</table>\n\n> The $X$ gate is sometimes referred to as the **bit flip** gate, or the **NOT** gate, because it acts like the classical NOT gate on the computational basis.\n>\n> The $Z$ gate is sometimes referred to as the **phase flip** gate.\n\nHere are several properties of the Pauli gates that are easy to verify and convenient to remember:\n\n- Different Pauli gates _anti-commute_:\n $$XZ = -ZX, XY = -YX, YZ = -ZY$$\n- A product of any two Pauli gates equals the third gate, with an extra $i$ (or $-i$) phase:\n $$XY = iZ, YZ = iX, ZX = iY$$\n- A product of all three Pauli gates equals identity (with an extra $i$ phase):\n $$XYZ = iI$$"
1120
1120
  }
1121
1121
  ]
1122
1122
  },
@@ -1127,7 +1127,7 @@ export default {
1127
1127
  "items": [
1128
1128
  {
1129
1129
  "type": "text-content",
1130
- "content": "\nThe following example contains code demonstrating how to apply gates in Q#. It sets up a series of quantum states, and then shows the result of applying the $X$ gate to each one.\n\nIn the previous kata we discussed that qubit state in Q# cannot be directly assigned or accessed. The same logic is extended to quantum gates: applying a gate to a qubit modifies the internal state of that qubit, but doesn't return the resulting state of the qubit. This is why we never assign the output of these gates to any variables in this demo - they don't produce any output.\n\nThe same principle applies to applying several gates in a row to a qubit. In the mathematical notation, applying an $X$ gate followed by a $Z$ gate to a state $\\ket{\\psi}$ is denoted as $Z(X(\\ket{\\psi}))$, because the result of applying a gate to a state is another state. In Q#, applying a gate doesn't return anything, so you can't use its output as an input to another gate - something like `Z(X(q))` will not produce the expected result. Instead, to apply several gates to the same qubit, you need to call them separately in the order in which they are applied:\n\n```qsharp\nX(q);\nZ(q);\n```\n\nAll the basic gates we will be covering in this kata are part of the Intrinsic namespace. We're also using the function DumpMachine to print the state of the quantum simulator."
1130
+ "content": "\nThe following example contains code demonstrating how to apply gates in Q#. It sets up a series of quantum states, and then shows the result of applying the $X$ gate to each one.\n\nThe previous kata mentioned that qubit state in Q# cannot be directly assigned or accessed. The same logic is extended to quantum gates: applying a gate to a qubit modifies the internal state of that qubit but doesn't return the resulting state of the qubit. That's the reason why you never assign the output of these gates to any variables in this demo - they don't produce any output.\n\nThe same principle applies to applying several gates in a row to a qubit. In the mathematical notation, applying an $X$ gate followed by a $Z$ gate to a state $\\ket{\\psi}$ is denoted as $Z(X(\\ket{\\psi}))$, because the result of applying a gate to a state is another state. In Q#, applying a gate doesn't return anything, so you can't use its output as an input to another gate - something like `Z(X(q))` won't produce the expected result. Instead, to apply several gates to the same qubit, you need to call them separately in the order in which they're applied:\n\n```qsharp\nX(q);\nZ(q);\n```\n\nAll the basic gates covered in this kata are part of the Intrinsic namespace. Additionally, the function `DumpMachine` from the Diagnostics namespace is used to print the state of the quantum simulator."
1131
1131
  },
1132
1132
  {
1133
1133
  "type": "example",
@@ -1154,7 +1154,7 @@ export default {
1154
1154
  "items": [
1155
1155
  {
1156
1156
  "type": "text-content",
1157
- "content": "\nWe can recognize that the Pauli $X$ gate will change the state $\\ket{0}$ to $\\ket{1}$ and vice versa, and $\\alpha\\ket{0} + \\beta\\ket{1}$ to $\\alpha\\ket{1} + \\beta\\ket{0}$.\n\nAs a reminder, the Pauli $X$ gate is defined by the following matrix:\n\n$$\nX =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n$$\n\nWe can see how it affects, for example, the basis state $\\ket{0}$:\n\n$$\nX\\ket{0} =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 \\cdot 1 + 1 \\cdot 0 \\\\ 1 \\cdot 1 + 0 \\cdot 0 \\end{bmatrix}=\n\\begin{bmatrix} 0 \\\\1 \\end{bmatrix}=\n\\ket{1}\n$$\n\nSimilarly, we can consider the effect of the $X$ gate on the superposition state $\\ket{\\psi} = 0.6\\ket{0} + 0.8\\ket{1}$:\n\n$$\nX\\ket{\\psi} =\n\\begin{bmatrix} 0 & 1 \\\\1 & 0\\end{bmatrix}\n\\begin{bmatrix}0.6 \\\\ 0.8 \\end{bmatrix}=\n\\begin{bmatrix} 0 \\cdot 0.6 + 1 \\cdot 0.8 \\\\ 1 \\cdot 0.6 + 0 \\cdot 0.8 \\end{bmatrix}=\n\\begin{bmatrix}0.8 \\\\ 0.6 \\end{bmatrix}=\n0.8\\ket{0} + 0.6\\ket{1}\n$$"
1157
+ "content": "\nYou can recognize that the Pauli $X$ gate will change the state $\\ket{0}$ to $\\ket{1}$ and vice versa, and $\\alpha\\ket{0} + \\beta\\ket{1}$ to $\\alpha\\ket{1} + \\beta\\ket{0}$.\n\nAs a reminder, the Pauli $X$ gate is defined by the following matrix:\n\n$$\nX =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n$$\n\nYou can see how it affects, for example, the basis state $\\ket{0}$:\n\n$$\nX\\ket{0} =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 \\cdot 1 + 1 \\cdot 0 \\\\ 1 \\cdot 1 + 0 \\cdot 0 \\end{bmatrix}=\n\\begin{bmatrix} 0 \\\\1 \\end{bmatrix}=\n\\ket{1}\n$$\n\nSimilarly, you can consider the effect of the $X$ gate on the superposition state $\\ket{\\psi} = 0.6\\ket{0} + 0.8\\ket{1}$:\n\n$$\nX\\ket{\\psi} =\n\\begin{bmatrix} 0 & 1 \\\\1 & 0\\end{bmatrix}\n\\begin{bmatrix}0.6 \\\\ 0.8 \\end{bmatrix}=\n\\begin{bmatrix} 0 \\cdot 0.6 + 1 \\cdot 0.8 \\\\ 1 \\cdot 0.6 + 0 \\cdot 0.8 \\end{bmatrix}=\n\\begin{bmatrix}0.8 \\\\ 0.6 \\end{bmatrix}=\n0.8\\ket{0} + 0.6\\ket{1}\n$$"
1158
1158
  },
1159
1159
  {
1160
1160
  "type": "solution",
@@ -1170,7 +1170,7 @@ export default {
1170
1170
  "title": "Sign Flip",
1171
1171
  "description": {
1172
1172
  "type": "text-content",
1173
- "content": "**Input**: A qubit in state $\\ket{\\psi} = \\alpha \\ket{0} + \\beta \\ket{1}$.\n\n**Goal** : Change the qubit state to $\\alpha \\ket{0} - \\beta \\ket{1}$ (i.e., flip the sign of the $\\ket{1}$ component of the superposition).\n"
1173
+ "content": "**Input**: A qubit in state $\\ket{\\psi} = \\alpha \\ket{0} + \\beta \\ket{1}$.\n\n**Goal** : Change the qubit state to $\\alpha \\ket{0} - \\beta \\ket{1}$, that is, flip the sign of the $\\ket{1}$ component of the superposition.\n"
1174
1174
  },
1175
1175
  "sourceIds": [
1176
1176
  "single_qubit_gates__sign_flip__Verification.qs",
@@ -1198,7 +1198,7 @@ export default {
1198
1198
  "title": "The Y Gate",
1199
1199
  "description": {
1200
1200
  "type": "text-content",
1201
- "content": "**Input:** A qubit in an arbitrary state $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$.\n\n**Goal:** Apply the Y gate to the qubit, i.e., transform the given state into $i\\alpha\\ket{1} - i\\beta\\ket{0}$.\n"
1201
+ "content": "**Input:** A qubit in an arbitrary state $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$.\n\n**Goal:** Apply the Y gate to the qubit, that is, transform the given state into $i\\alpha\\ket{1} - i\\beta\\ket{0}$.\n"
1202
1202
  },
1203
1203
  "sourceIds": [
1204
1204
  "single_qubit_gates__y_gate__Verification.qs",
@@ -1210,7 +1210,7 @@ export default {
1210
1210
  "items": [
1211
1211
  {
1212
1212
  "type": "text-content",
1213
- "content": "\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 $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$ into $Y\\ket{\\psi} = i\\alpha\\ket{1} - i\\beta\\ket{0}$, 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$$"
1213
+ "content": "\nYou 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 $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$ into $Y\\ket{\\psi} = i\\alpha\\ket{1} - i\\beta\\ket{0}$, 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$$"
1214
1214
  },
1215
1215
  {
1216
1216
  "type": "solution",
@@ -1226,7 +1226,7 @@ export default {
1226
1226
  "title": "Sign Flip on Zero",
1227
1227
  "description": {
1228
1228
  "type": "text-content",
1229
- "content": "**Input:** A qubit in an arbitrary state $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$.\n\n**Goal:** Use several Pauli gates to change the qubit state to $- \\alpha\\ket{0} + \\beta\\ket{1}$, i.e., apply the transformation represented by the following matrix:\n\n$$\\begin{bmatrix} -1 & 0 \\\\ 0 & 1 \\end{bmatrix}$$\n"
1229
+ "content": "**Input:** A qubit in an arbitrary state $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$.\n\n**Goal:** Use several Pauli gates to change the qubit state to $- \\alpha\\ket{0} + \\beta\\ket{1}$, that is, apply the transformation represented by the following matrix:\n\n$$\\begin{bmatrix} -1 & 0 \\\\ 0 & 1 \\end{bmatrix}$$\n"
1230
1230
  },
1231
1231
  "sourceIds": [
1232
1232
  "single_qubit_gates__sign_flip_on_zero__Verification.qs",
@@ -1238,7 +1238,7 @@ export default {
1238
1238
  "items": [
1239
1239
  {
1240
1240
  "type": "text-content",
1241
- "content": "\nThe first thing to notice is that the gate $\\begin{bmatrix} -1 & 0 \\\\ 0 & 1 \\end{bmatrix}$ is quite similar to the Pauli $Z$ gate $\\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}$.\nThe only difference being that the negative phase is applied on the $\\ket{0}$ instead of $\\ket{1}$. Hence we can simulate this gate by switching $\\ket{0}$ and $\\ket{1}$ states, applying the Pauli $Z$ gate and switching them back. The Pauli $X$ gate is the perfect gate to flip the state of the qubit and to undo the action afterwards.\n\nHence we can express the $Z_0 = \\begin{bmatrix} -1 & 0 \\\\ 0 & 1 \\end{bmatrix}$ matrix as\n\n$$\nZ_0 =\n\\begin{bmatrix} -1 & 0 \\\\ 0 & 1 \\end{bmatrix} = \n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix} \\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix} \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix} = \nXZX\n$$"
1241
+ "content": "\nThe first thing to notice is that the gate $\\begin{bmatrix} -1 & 0 \\\\ 0 & 1 \\end{bmatrix}$ is quite similar to the Pauli $Z$ gate $\\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}$.\nThe only difference being that the negative phase is applied on the $\\ket{0}$ instead of $\\ket{1}$. Hence you can simulate this gate by switching $\\ket{0}$ and $\\ket{1}$ states, applying the Pauli $Z$ gate and switching them back. The Pauli $X$ gate is the perfect gate to flip the state of the qubit and to undo the action afterwards.\n\nHence you can express the $Z_0 = \\begin{bmatrix} -1 & 0 \\\\ 0 & 1 \\end{bmatrix}$ matrix as\n\n$$\nZ_0 =\n\\begin{bmatrix} -1 & 0 \\\\ 0 & 1 \\end{bmatrix} = \n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix} \\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix} \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix} = \nXZX\n$$"
1242
1242
  },
1243
1243
  {
1244
1244
  "type": "solution",
@@ -1254,7 +1254,7 @@ export default {
1254
1254
  "title": "Global Phase -1",
1255
1255
  "description": {
1256
1256
  "type": "text-content",
1257
- "content": "**Input:** A qubit in state $\\ket{\\psi} = \\beta \\ket{0} + \\gamma \\ket{1}$.\n\n**Goal**: Change the state of the qubit to $- \\beta \\ket{0} - \\gamma \\ket{1}$.\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"
1257
+ "content": "**Input:** A qubit in state $\\ket{\\psi} = \\beta \\ket{0} + \\gamma \\ket{1}$.\n\n**Goal**: Change the state of the qubit to $- \\beta \\ket{0} - \\gamma \\ket{1}$.\n\n> This change on its own is not observable - there's 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"
1258
1258
  },
1259
1259
  "sourceIds": [
1260
1260
  "single_qubit_gates__global_phase_minusone__Verification.qs",
@@ -1266,7 +1266,7 @@ export default {
1266
1266
  "items": [
1267
1267
  {
1268
1268
  "type": "text-content",
1269
- "content": "\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 $\\ket{\\psi} = \\beta \\ket{0} + \\gamma \\ket{1}$ to $- \\beta \\ket{0} - \\gamma \\ket{1}$.\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 $\\ket{1}$ state by $-1$ but does not change the $\\ket{0}$ state, converting our state $\\beta \\ket{0} + \\gamma \\ket{1}$ to $\\beta \\ket{0} - \\gamma \\ket{1}$.\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 $\\ket{0}$ and $\\ket{1}$ basis states, converting our $\\beta \\ket{0} - \\gamma \\ket{1}$ state to $\\beta \\ket{1} - \\gamma \\ket{0}$.\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 $\\ket{1}$ state (that used to be $\\ket{0}$), converting our state $\\beta \\ket{1} - \\gamma \\ket{0}$ to $- \\beta \\ket{1} - \\gamma \\ket{0}$. 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."
1269
+ "content": "\nA global phase is a phase factor that multiplies the entire quantum state. It isn't observable when measuring the qubit's state, as the probabilities remain unchanged. However, it's significant when considering quantum state transformations.\n\nOur task is to implement an operation that transforms the given qubit state from $\\ket{\\psi} = \\beta \\ket{0} + \\gamma \\ket{1}$ to $- \\beta \\ket{0} - \\gamma \\ket{1}$.\n\nTo do that, you use 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 $\\ket{1}$ state by $-1$ but doen't change the $\\ket{0}$ state, converting our state $\\beta \\ket{0} + \\gamma \\ket{1}$ to $\\beta \\ket{0} - \\gamma \\ket{1}$.\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 $\\ket{0}$ and $\\ket{1}$ basis states, converting $\\beta \\ket{0} - \\gamma \\ket{1}$ state to $\\beta \\ket{1} - \\gamma \\ket{0}$.\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 $\\ket{1}$ state (that used to be $\\ket{0}$), converting the state $\\beta \\ket{1} - \\gamma \\ket{0}$ to $- \\beta \\ket{1} - \\gamma \\ket{0}$. 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 the state has been multiplied by $-1$, achieving the required global phase change."
1270
1270
  },
1271
1271
  {
1272
1272
  "type": "solution",
@@ -1294,7 +1294,7 @@ export default {
1294
1294
  "items": [
1295
1295
  {
1296
1296
  "type": "text-content",
1297
- "content": "\nWe need to apply a gate which applies a global phase of $i$, i.e. $\\ket{\\psi} \\rightarrow i\\ket{\\psi}$.\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."
1297
+ "content": "\nYou need to apply a gate which applies a global phase of $i$, that is, $\\ket{\\psi} \\rightarrow i\\ket{\\psi}$.\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 you're restricted to the Pauli gates, you can 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 you first apply the $Z$ gate, followed by the $Y$ gate, and finally the $X$ gate."
1298
1298
  },
1299
1299
  {
1300
1300
  "type": "solution",
@@ -1311,7 +1311,7 @@ export default {
1311
1311
  "items": [
1312
1312
  {
1313
1313
  "type": "text-content",
1314
- "content": "\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 $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n</tr>\n<tr>\n<td>$I$</td>\n<td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}$</td>\n<td>$\\ket{0}\\bra{0} + \\ket{1}\\bra{1}$</td>\n<td>$I\\ket{\\psi} = \\ket{\\psi}$</td>\n</tr>\n</table>"
1314
+ "content": "\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's represented by the identity matrix, and doesn't 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 $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n</tr>\n<tr>\n<td>$I$</td>\n<td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}$</td>\n<td>$\\ket{0}\\bra{0} + \\ket{1}\\bra{1}$</td>\n<td>$I\\ket{\\psi} = \\ket{\\psi}$</td>\n</tr>\n</table>"
1315
1315
  }
1316
1316
  ]
1317
1317
  },
@@ -1344,7 +1344,7 @@ export default {
1344
1344
  "items": [
1345
1345
  {
1346
1346
  "type": "text-content",
1347
- "content": "\nWe can recognize that the Hadamard gate changes states $\\ket{0}$ and $\\ket{1}$ to $\\ket{+}$ and $\\ket{-}$, 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\\ket{1}$ as follows:\n\n$$\nH\\ket{1}=\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(\\ket{0} - \\ket{1}\\big) = \\ket{-}\n$$\n\nSimilarly, we can consider the effect of the Hadamard gate on the superposition state $\\ket{\\psi} = 0.6\\ket{0} + 0.8\\ket{1}$ (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\\ket{0} - 0.1414\\ket{1}\n$$"
1347
+ "content": "\nYou can recognize that the Hadamard gate changes states $\\ket{0}$ and $\\ket{1}$ to $\\ket{+}$ and $\\ket{-}$, 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, you can work out $H\\ket{1}$ as follows:\n\n$$\nH\\ket{1}=\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(\\ket{0} - \\ket{1}\\big) = \\ket{-}\n$$\n\nSimilarly, you can consider the effect of the Hadamard gate on the superposition state $\\ket{\\psi} = 0.6\\ket{0} + 0.8\\ket{1}$ (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\\ket{0} - 0.1414\\ket{1}\n$$"
1348
1348
  },
1349
1349
  {
1350
1350
  "type": "solution",
@@ -1372,7 +1372,7 @@ export default {
1372
1372
  "items": [
1373
1373
  {
1374
1374
  "type": "text-content",
1375
- "content": "\nWe know that applying the Hadamard gate $H$ on the computational basis states $\\ket{0}$ and $\\ket{1}$ results in Hadamard basis states $\\ket{+}$ and $\\ket{-}$, respectively.\nWe are given a qubit in the state $\\ket{0}$. We first apply the Pauli $X$ gate to turn it into $X\\ket{0}=\\ket{1}$, and then apply the $H$ gate, turning the qubit into the required $H\\ket{1}=\\ket{-}$ state."
1375
+ "content": "\nYou know that applying the Hadamard gate $H$ on the computational basis states $\\ket{0}$ and $\\ket{1}$ results in Hadamard basis states $\\ket{+}$ and $\\ket{-}$, respectively.\nYou're given a qubit in the state $\\ket{0}$. You first apply the Pauli $X$ gate to turn it into $X\\ket{0}=\\ket{1}$, and then apply the $H$ gate, turning the qubit into the required $H\\ket{1}=\\ket{-}$ state."
1376
1376
  },
1377
1377
  {
1378
1378
  "type": "solution",
@@ -1389,7 +1389,7 @@ export default {
1389
1389
  "items": [
1390
1390
  {
1391
1391
  "type": "text-content",
1392
- "content": "\nThe next two gates are known as phase shift gates. They apply a phase to the $\\ket{1}$ state, and leave the $\\ket{0}$ state unchanged.\n\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$S$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & i \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + i\\ket{1}\\bra{1}$</td>\n <td>$S\\ket{\\psi} = \\alpha\\ket{0} + i\\beta\\ket{1}$</td>\n <td>\n $S\\ket{0} = \\ket{0}$<br>\n $S\\ket{1} = i\\ket{1}$<br>\n $S\\ket{+} = \\ket{i}$<br>\n $S\\ket{-} = \\ket{-i}$<br>\n $S\\ket{i} = \\ket{-}$<br>\n $S\\ket{-i} = \\ket{+}$<br>\n </td>\n </tr>\n <tr>\n <td>$T$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\pi/4} \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + e^{i\\pi/4}\\ket{1}$$\\bra{1}$</td>\n <td>$T\\ket{\\psi} = \\alpha\\ket{0} + e^{i\\pi/4} \\beta \\ket{1}$</td>\n <td>\n $T\\ket{0} = \\ket{0}$<br>\n $T\\ket{1} = e^{i\\pi/4}\\ket{1}$\n </td>\n </tr>\n</table>\n\n> Notice that applying the $T$ gate twice is equivalent to applying the $S$ gate, and applying the $S$ gate twice is equivalent to applying the $Z$ gate:\n$$T^2 = S, S^2 = Z$$"
1392
+ "content": "\nThe next two gates are known as **phase shift gates**. They apply a phase to the $\\ket{1}$ state, and leave the $\\ket{0}$ state unchanged.\n\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$S$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & i \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + i\\ket{1}\\bra{1}$</td>\n <td>$S\\ket{\\psi} = \\alpha\\ket{0} + i\\beta\\ket{1}$</td>\n <td>\n $S\\ket{0} = \\ket{0}$<br>\n $S\\ket{1} = i\\ket{1}$<br>\n $S\\ket{+} = \\ket{i}$<br>\n $S\\ket{-} = \\ket{-i}$<br>\n $S\\ket{i} = \\ket{-}$<br>\n $S\\ket{-i} = \\ket{+}$<br>\n </td>\n </tr>\n <tr>\n <td>$T$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\pi/4} \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + e^{i\\pi/4}\\ket{1}$$\\bra{1}$</td>\n <td>$T\\ket{\\psi} = \\alpha\\ket{0} + e^{i\\pi/4} \\beta \\ket{1}$</td>\n <td>\n $T\\ket{0} = \\ket{0}$<br>\n $T\\ket{1} = e^{i\\pi/4}\\ket{1}$\n </td>\n </tr>\n</table>\n\n> Notice that applying the $T$ gate twice is equivalent to applying the $S$ gate, and applying the $S$ gate twice is equivalent to applying the $Z$ gate:\n$$T^2 = S, S^2 = Z$$"
1393
1393
  }
1394
1394
  ]
1395
1395
  },
@@ -1411,7 +1411,7 @@ export default {
1411
1411
  "items": [
1412
1412
  {
1413
1413
  "type": "text-content",
1414
- "content": "\n#### Solution 1\n\nWe can recognize that the $S$ gate performs this particular relative phase addition to the $\\ket{1}$ 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 $\\ket{\\psi} = \\alpha \\ket{0} + \\beta \\ket{1}$.\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 $\\ket{\\psi} = 0.6\\ket{0} + 0.8\\ket{1}, S\\ket{\\psi} = 0.6\\ket{0} + 0.8i\\ket{1}$."
1414
+ "content": "\n#### Solution 1\n\nYou can recognize that the $S$ gate performs this particular relative phase addition to the $\\ket{1}$ 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 $\\ket{\\psi} = \\alpha \\ket{0} + \\beta \\ket{1}$.\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 $\\ket{\\psi} = 0.6\\ket{0} + 0.8\\ket{1}, S\\ket{\\psi} = 0.6\\ket{0} + 0.8i\\ket{1}$."
1415
1415
  },
1416
1416
  {
1417
1417
  "type": "solution",
@@ -1465,7 +1465,7 @@ export default {
1465
1465
  "items": [
1466
1466
  {
1467
1467
  "type": "text-content",
1468
- "content": "\nThe next few gates are parametrized: their exact behavior depends on a numeric parameter - an angle $\\theta$, given in radians.\nThese gates are the $X$ rotation gate $R_x(\\theta)$, $Y$ rotation gate $R_y(\\theta)$, $Z$ rotation gate $R_z(\\theta)$, and the arbitrary phase gate $R_1(\\theta)$.\nNote that for the first three gates the parameter $\\theta$ is multiplied by $\\frac{1}{2}$ within the gate's matrix.\n\n> These gates are known as rotation gates, because they represent rotations around various axes on the Bloch sphere. The Bloch sphere is a way of representing the qubit states visually, mapping them onto the surface of a sphere.\n> Unfortunately, this visualization isn't very useful beyond single-qubit states, which is why we have opted not to go into details in this kata.\n> If you are curious about it, you can learn more in <a href=\"https://en.wikipedia.org/wiki/Bloch_sphere\" target=\"_blank\">this Wikipedia article</a>.\n\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$R_x(\\theta)$</td>\n <td>\n $$\n \\begin{bmatrix} \\cos\\frac{\\theta}{2} & -i\\sin\\frac{\\theta}{2} \\\\ -i\\sin\\frac{\\theta}{2} & \\cos\\frac{\\theta}{2} \\end{bmatrix}\n $$\n </td>\n <td>$R_x(\\theta)\\ket{\\psi} = (\\alpha\\cos\\frac{\\theta}{2} - i\\beta\\sin\\frac{\\theta}{2})\\ket{0} + (\\beta\\cos\\frac{\\theta}{2} - i\\alpha\\sin\\frac{\\theta}{2})\\ket{1}$</td>\n <td>\n $R_x(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} - i\\sin\\frac{\\theta}{2}\\ket{1}$<br>\n $R_x(\\theta)\\ket{1} = \\cos\\frac{\\theta}{2}\\ket{1} - i\\sin\\frac{\\theta}{2}\\ket{0}$\n </td>\n </tr>\n <tr>\n <td>$R_y(\\theta)$</td>\n <td>$\\begin{bmatrix} \\cos\\frac{\\theta}{2} & -\\sin\\frac{\\theta}{2} \\\\ \\sin\\frac{\\theta}{2} & \\cos\\frac{\\theta}{2} \\end{bmatrix}$</td>\n <td>$R_y(\\theta)\\ket{\\psi} = (\\alpha\\cos\\frac{\\theta}{2} - \\beta\\sin\\frac{\\theta}{2})\\ket{0} + (\\beta\\cos\\frac{\\theta}{2} + \\alpha\\sin\\frac{\\theta}{2})\\ket{1}$</td>\n <td>\n $R_y(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} + \\sin\\frac{\\theta}{2}\\ket{1}$<br>\n $R_y(\\theta)\\ket{1} = \\cos\\frac{\\theta}{2}\\ket{1} - \\sin\\frac{\\theta}{2}\\ket{0}$\n </td>\n </tr>\n <tr>\n <td>$R_z(\\theta)$</td>\n <td>$\\begin{bmatrix} e^{-i\\theta/2} & 0 \\\\ 0 & e^{i\\theta/2} \\end{bmatrix}$</td>\n <td>$R_z(\\theta)\\ket{\\psi} = \\alpha e^{-i\\theta/2}\\ket{0} + \\beta e^{i\\theta/2}\\ket{1}$</td>\n <td>\n $R_z(\\theta)\\ket{0} = e^{-i\\theta/2}\\ket{0}$<br>\n $R_z(\\theta)\\ket{1} = e^{i\\theta/2}\\ket{1}$\n </td>\n </tr>\n <tr>\n <td>$R_1(\\theta)$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\theta} \\end{bmatrix}$</td>\n <td>$R_1(\\theta)\\ket{\\psi} = \\alpha\\ket{0} + \\beta e^{i\\theta}\\ket{1}$</td>\n <td>\n $R_1(\\theta)\\ket{0} = \\ket{0}$<br>\n $R_1(\\theta)\\ket{1} = e^{i\\theta}\\ket{1}$\n </td> \n </tr>\n</table>\n\nYou have already encountered some special cases of the $R_1$ gate:\n\n$$T = R_1(\\frac{\\pi}{4}), S = R_1(\\frac{\\pi}{2}), Z = R_1(\\pi)$$\n\nIn addition, this gate is closely related to the $R_z$ gate: applying $R_1$ gate is equivalent to applying the $R_z$ gate, and then applying a global phase:\n\n$$R_1(\\theta) = e^{i\\theta/2}R_z(\\theta)$$\n\nIn addition, the rotation gates are very closely related to their respective Pauli gates:\n\n$$X = iR_x(\\pi), Y = iR_y(\\pi), Z = iR_z(\\pi)$$"
1468
+ "content": "\nThe next few gates are parametrized: their exact behavior depends on a numeric parameter - an angle $\\theta$, given in radians.\nThese gates are the $X$ rotation gate $R_x(\\theta)$, $Y$ rotation gate $R_y(\\theta)$, $Z$ rotation gate $R_z(\\theta)$, and the arbitrary phase gate $R_1(\\theta)$.\nNote that for the first three gates the parameter $\\theta$ is multiplied by $\\frac{1}{2}$ within the gate's matrix.\n\n> These gates are known as rotation gates, because they represent rotations around various axes on the Bloch sphere. The Bloch sphere is a way of representing the qubit states visually, mapping them onto the surface of a sphere.\n> Unfortunately, this visualization isn't very useful beyond single-qubit states, which is why this kata doesn't go into details.\n> If you're curious about it, you can learn more in <a href=\"https://en.wikipedia.org/wiki/Bloch_sphere\" target=\"_blank\">this Wikipedia article</a>.\n\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$R_x(\\theta)$</td>\n <td>\n $$\n \\begin{bmatrix} \\cos\\frac{\\theta}{2} & -i\\sin\\frac{\\theta}{2} \\\\ -i\\sin\\frac{\\theta}{2} & \\cos\\frac{\\theta}{2} \\end{bmatrix}\n $$\n </td>\n <td>$R_x(\\theta)\\ket{\\psi} = (\\alpha\\cos\\frac{\\theta}{2} - i\\beta\\sin\\frac{\\theta}{2})\\ket{0} + (\\beta\\cos\\frac{\\theta}{2} - i\\alpha\\sin\\frac{\\theta}{2})\\ket{1}$</td>\n <td>\n $R_x(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} - i\\sin\\frac{\\theta}{2}\\ket{1}$<br>\n $R_x(\\theta)\\ket{1} = \\cos\\frac{\\theta}{2}\\ket{1} - i\\sin\\frac{\\theta}{2}\\ket{0}$\n </td>\n </tr>\n <tr>\n <td>$R_y(\\theta)$</td>\n <td>$\\begin{bmatrix} \\cos\\frac{\\theta}{2} & -\\sin\\frac{\\theta}{2} \\\\ \\sin\\frac{\\theta}{2} & \\cos\\frac{\\theta}{2} \\end{bmatrix}$</td>\n <td>$R_y(\\theta)\\ket{\\psi} = (\\alpha\\cos\\frac{\\theta}{2} - \\beta\\sin\\frac{\\theta}{2})\\ket{0} + (\\beta\\cos\\frac{\\theta}{2} + \\alpha\\sin\\frac{\\theta}{2})\\ket{1}$</td>\n <td>\n $R_y(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} + \\sin\\frac{\\theta}{2}\\ket{1}$<br>\n $R_y(\\theta)\\ket{1} = \\cos\\frac{\\theta}{2}\\ket{1} - \\sin\\frac{\\theta}{2}\\ket{0}$\n </td>\n </tr>\n <tr>\n <td>$R_z(\\theta)$</td>\n <td>$\\begin{bmatrix} e^{-i\\theta/2} & 0 \\\\ 0 & e^{i\\theta/2} \\end{bmatrix}$</td>\n <td>$R_z(\\theta)\\ket{\\psi} = \\alpha e^{-i\\theta/2}\\ket{0} + \\beta e^{i\\theta/2}\\ket{1}$</td>\n <td>\n $R_z(\\theta)\\ket{0} = e^{-i\\theta/2}\\ket{0}$<br>\n $R_z(\\theta)\\ket{1} = e^{i\\theta/2}\\ket{1}$\n </td>\n </tr>\n <tr>\n <td>$R_1(\\theta)$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\theta} \\end{bmatrix}$</td>\n <td>$R_1(\\theta)\\ket{\\psi} = \\alpha\\ket{0} + \\beta e^{i\\theta}\\ket{1}$</td>\n <td>\n $R_1(\\theta)\\ket{0} = \\ket{0}$<br>\n $R_1(\\theta)\\ket{1} = e^{i\\theta}\\ket{1}$\n </td> \n </tr>\n</table>\n\nYou have already encountered some special cases of the $R_1$ gate:\n\n$$T = R_1(\\frac{\\pi}{4}), S = R_1(\\frac{\\pi}{2}), Z = R_1(\\pi)$$\n\nIn addition, this gate is closely related to the $R_z$ gate: applying $R_1$ gate is equivalent to applying the $R_z$ gate, and then applying a global phase:\n\n$$R_1(\\theta) = e^{i\\theta/2}R_z(\\theta)$$\n\nIn addition, the rotation gates are very closely related to their respective Pauli gates:\n\n$$X = iR_x(\\pi), Y = iR_y(\\pi), Z = iR_z(\\pi)$$"
1469
1469
  }
1470
1470
  ]
1471
1471
  },
@@ -1487,7 +1487,7 @@ export default {
1487
1487
  "items": [
1488
1488
  {
1489
1489
  "type": "text-content",
1490
- "content": "\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 \\ket{0} + \\gamma \\ket{1}) =\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 \\ket{0} + {\\color{red}{e^{i\\alpha}}} \\gamma \\ket{1}\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\"."
1490
+ "content": "\nYou know that:\n\n$$\nR1(\\alpha)=\n \\begin{bmatrix}1 & 0 \\\\ 0 & \\color{red}{e^{i\\alpha}}\\end{bmatrix}\n$$\n\nSo you have:\n\n$$\nR1(\\beta \\ket{0} + \\gamma \\ket{1}) =\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 \\ket{0} + {\\color{red}{e^{i\\alpha}}} \\gamma \\ket{1}\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 you have that $\\cos\\frac{\\pi}{2} + i \\sin\\frac{\\pi}{2} = i$, and \n> $R1(\\frac{\\pi}{2}) = S$, which you used in the second solution to the task \"Relative Phase i\"."
1491
1491
  },
1492
1492
  {
1493
1493
  "type": "solution",
@@ -1515,7 +1515,7 @@ export default {
1515
1515
  "items": [
1516
1516
  {
1517
1517
  "type": "text-content",
1518
- "content": "\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 $\\ket{0}$ and $\\ket{1}$ 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 $\\ket{0}$ state:\n\n$$\nR_y(\\theta)\\ket{0} =\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} \\ket{0} + \\sin\\frac{\\theta}{2} \\ket{1}\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 $\\ket{0}$ state, and the second column is the state into which it will transform the $\\ket{1}$ state.\nOne of the examples used by the testing harness has $\\beta = 0.6, \\gamma = 0.8$ and $\\alpha = \\frac{\\pi}{3} = 1.0472$.\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) \\ket{\\psi}=\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$."
1518
+ "content": "\nYou can recognize that you 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 $\\ket{0}$ and $\\ket{1}$ 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 $\\ket{0}$ state:\n\n$$\nR_y(\\theta)\\ket{0} =\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} \\ket{0} + \\sin\\frac{\\theta}{2} \\ket{1}\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 $\\ket{0}$ state, and the second column is the state into which it will transform the $\\ket{1}$ state.\nOne of the examples used by the testing harness has $\\beta = 0.6, \\gamma = 0.8$ and $\\alpha = \\frac{\\pi}{3} 1.0472$.\nSince $\\cos \\frac{\\pi}{3} = 0.5$ and $\\sin \\frac{\\pi}{3} = 0.8660$, working to 4 decimal places, you can use $\\frac{\\theta}{2} = \\alpha$ to compute:\n\n$$\nR_{y}(\\theta) \\ket{\\psi}=\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 $\\frac{\\theta}{2} = \\alpha$; this means that in the Q# code you need to pass the angle $\\theta = 2\\alpha$."
1519
1519
  },
1520
1520
  {
1521
1521
  "type": "solution",
@@ -1531,7 +1531,7 @@ export default {
1531
1531
  "title": "Prepare Rotated State",
1532
1532
  "description": {
1533
1533
  "type": "text-content",
1534
- "content": "**Inputs:**\n\n1. Real numbers $\\alpha$ and $\\beta$ such that $\\alpha^2 + \\beta^2 = 1$.\n2. A qubit in state $\\ket{0}$.\n\n**Goal:** Use a rotation gate to transform the qubit into state $\\alpha\\ket{0} -i\\beta\\ket{1}$.\n\n> You will probably need functions from the `Microsoft.Quantum.Math` namespace, specifically <a href=\"https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.math/arctan2\" target=\"_blank\">ArcTan2</a>.\n>\n> You can assign variables in Q# by using the `let` keyword: `let num = 3;` or `let result = Function(input);`\n"
1534
+ "content": "**Inputs:**\n\n1. Real numbers $\\alpha$ and $\\beta$ such that $\\alpha^2 + \\beta^2 = 1$.\n2. A qubit in state $\\ket{0}$.\n\n**Goal:** Use a rotation gate to transform the qubit into state $\\alpha\\ket{0} -i\\beta\\ket{1}$.\n\n> You'll probably need functions from the `Microsoft.Quantum.Math` namespace, specifically <a href=\"https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.math/arctan2\" target=\"_blank\">ArcTan2</a>.\n>\n> You can assign variables in Q# by using the `let` keyword: `let num = 3;` or `let result = Function(input);`\n"
1535
1535
  },
1536
1536
  "sourceIds": [
1537
1537
  "single_qubit_gates__prepare_rotated_state__Verification.qs",
@@ -1543,7 +1543,7 @@ export default {
1543
1543
  "items": [
1544
1544
  {
1545
1545
  "type": "text-content",
1546
- "content": "\nWe use the rotation gate $R_x(\\theta)$. This gate turns the state $\\ket{0}$ into $R_x(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} - i\\sin\\frac{\\theta}{2}\\ket{1}$.\nThis is similar to the state we need. We just need to find an angle $\\theta$ such that $\\cos\\frac{\\theta}{2}=\\alpha$ and $\\sin\\frac{\\theta}{2}=\\beta$. We can use these two equations to solve for $\\theta$: $\\theta = 2\\arctan\\frac{\\beta}{\\alpha}$. (*Note: It is given that $\\alpha^2 + \\beta^2=1$*).\nHence the required gate is $R_x(2\\arctan\\frac{\\beta}{\\alpha})$, which in matrix form is $\\begin{bmatrix} \\alpha & -i\\beta \\\\ -i\\beta & \\alpha \\end{bmatrix}$.\nThis gate turns $\\ket{0} = \\begin{bmatrix} 1 \\\\ 0\\end{bmatrix}$ into $\\begin{bmatrix} \\alpha & -i\\beta \\\\ -i\\beta & \\alpha \\end{bmatrix} \\begin{bmatrix} 1 \\\\ 0\\end{bmatrix} = \\begin{bmatrix} \\alpha \\\\ -i\\beta \\end{bmatrix} = \\alpha\\ket{0} -i\\beta\\ket{1}$.\n\n> Trigonometric functions are available in Q# via the `Microsoft.Quantum.Math` namespace. In this case we will need <a href=\"https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.math/arctan2\" target=\"_blank\">ArcTan2</a>."
1546
+ "content": "\nYou use the rotation gate $R_x(\\theta)$. This gate turns the state $\\ket{0}$ into $R_x(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} - i\\sin\\frac{\\theta}{2}\\ket{1}$.\nThis is similar to the state you need. You just need to find an angle $\\theta$ such that $\\cos\\frac{\\theta}{2}=\\alpha$ and $\\sin\\frac{\\theta}{2}=\\beta$. You can use these two equations to solve for $\\theta$: $\\theta = 2\\arctan\\frac{\\beta}{\\alpha}$. (*Note: It's given that $\\alpha^2 + \\beta^2=1$*).\nHence the required gate is $R_x(2\\arctan\\frac{\\beta}{\\alpha})$, which in matrix form is $\\begin{bmatrix} \\alpha & -i\\beta \\\\ -i\\beta & \\alpha \\end{bmatrix}$.\nThis gate turns $\\ket{0} = \\begin{bmatrix} 1 \\\\ 0\\end{bmatrix}$ into $\\begin{bmatrix} \\alpha & -i\\beta \\\\ -i\\beta & \\alpha \\end{bmatrix} \\begin{bmatrix} 1 \\\\ 0\\end{bmatrix} = \\begin{bmatrix} \\alpha \\\\ -i\\beta \\end{bmatrix} = \\alpha\\ket{0} -i\\beta\\ket{1}$.\n\n> Trigonometric functions are available in Q# via the `Microsoft.Quantum.Math` namespace. In this case, you'll need <a href=\"https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.math/arctan2\" target=\"_blank\">ArcTan2</a>."
1547
1547
  },
1548
1548
  {
1549
1549
  "type": "solution",
@@ -1559,7 +1559,7 @@ export default {
1559
1559
  "title": "Prepare Arbitrary State",
1560
1560
  "description": {
1561
1561
  "type": "text-content",
1562
- "content": "**Inputs:**\n\n1. A non-negative real number $\\alpha$.\n2. A non-negative real number $\\beta = \\sqrt{1 - \\alpha^2}$.\n3. A real number $\\theta$.\n4. A qubit in state $\\ket{0}$.\n\n**Goal:** Transform the qubit into state $\\alpha\\ket{0} + e^{i\\theta}\\beta\\ket{1}$.\n\n> Since only the relative amplitudes and relative phase have any physical meaning, this allows us to prepare any single-qubit quantum state we want to."
1562
+ "content": "**Inputs:**\n\n1. A non-negative real number $\\alpha$.\n2. A non-negative real number $\\beta = \\sqrt{1 - \\alpha^2}$.\n3. A real number $\\theta$.\n4. A qubit in state $\\ket{0}$.\n\n**Goal:** Transform the qubit into state $\\alpha\\ket{0} + e^{i\\theta}\\beta\\ket{1}$.\n\n> Since only the relative amplitudes and relative phase have any physical meaning, this allows you to prepare any single-qubit quantum state you want to.\n"
1563
1563
  },
1564
1564
  "sourceIds": [
1565
1565
  "single_qubit_gates__prepare_arbitrary_state__Verification.qs",
@@ -1571,7 +1571,7 @@ export default {
1571
1571
  "items": [
1572
1572
  {
1573
1573
  "type": "text-content",
1574
- "content": "\nThis exercise can be done in two steps.\n\n1. Convert the state from $\\ket{0}$ to $\\alpha\\ket{0} + \\beta\\ket{1}$.\n This can be done in a similar manner to the \"Preparing a Rotated State\" exercise, we first prepare an $\\alpha\\ket{0} -i\\beta\\ket{1}$ state using the $R_x$ gate, and then removing the relative phase of $-i$ by applying the $S$ gate, which would turn $\\alpha\\ket{0} -i\\beta\\ket{1}$ to $\\alpha\\ket{0} + \\beta\\ket{1}$.\n An alternative, simpler approach is to use the $R_y$ gate, which allows us to get the necessary state right away without introducing a relative phase:\n$$\nR_y(2\\arctan\\frac{\\beta}{\\alpha}) = \\begin{bmatrix} \\alpha & -\\beta \\\\ \\beta & \\alpha \\end{bmatrix}\n$$\n2. Add a phase of $e^{i\\theta}$ to the $\\ket{1}$ basis state using the $R_1(\\theta)$ gate. This would turn $\\alpha\\ket{0} +\\beta\\ket{1}$ to $\\alpha\\ket{0} + e^{i\\theta}\\beta\\ket{1}$.\n\nThe solution can be represented as $R_1(\\theta)R_y(2\\arctan\\frac{\\beta}{\\alpha})$ or in matrix form as:\n$$\n\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\theta} \\end{bmatrix}\\begin{bmatrix} \\alpha & -\\beta \\\\ \\beta & \\alpha \\end{bmatrix} = \n\\begin{bmatrix} \\alpha & -\\beta \\\\ e^{i\\theta}\\beta & e^{i\\theta}\\alpha \\end{bmatrix}\n$$\n\nThis turns $\\ket{0} = \\begin{bmatrix} 1 \\\\ 0\\end{bmatrix}$ into $\\begin{bmatrix} \\alpha & -\\beta \\\\ e^{i\\theta}\\beta & e^{i\\theta}\\alpha \\end{bmatrix} \\begin{bmatrix} 1 \\\\ 0\\end{bmatrix} = \\begin{bmatrix} \\alpha \\\\ e^{i\\theta}\\beta \\end{bmatrix} = \\alpha\\ket{0} +e^{i\\theta}\\beta\\ket{1}$."
1574
+ "content": "\nThis exercise can be done in two steps.\n\n1. Convert the state from $\\ket{0}$ to $\\alpha\\ket{0} + \\beta\\ket{1}$.\n This can be done in a similar manner to the \"Preparing a Rotated State\" exercise, we first prepare an $\\alpha\\ket{0} -i\\beta\\ket{1}$ state using the $R_x$ gate, and then removing the relative phase of $-i$ by applying the $S$ gate, which would turn $\\alpha\\ket{0} -i\\beta\\ket{1}$ to $\\alpha\\ket{0} + \\beta\\ket{1}$.\n An alternative, simpler approach is to use the $R_y$ gate, which allows you to get the necessary state right away without introducing a relative phase:\n$$\nR_y(2\\arctan\\frac{\\beta}{\\alpha}) = \\begin{bmatrix} \\alpha & -\\beta \\\\ \\beta & \\alpha \\end{bmatrix}\n$$\n2. Add a phase of $e^{i\\theta}$ to the $\\ket{1}$ basis state using the $R_1(\\theta)$ gate. This would turn $\\alpha\\ket{0} +\\beta\\ket{1}$ to $\\alpha\\ket{0} + e^{i\\theta}\\beta\\ket{1}$.\n\nThe solution can be represented as $R_1(\\theta)R_y(2\\arctan\\frac{\\beta}{\\alpha})$ or in matrix form as:\n$$\n\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\theta} \\end{bmatrix}\\begin{bmatrix} \\alpha & -\\beta \\\\ \\beta & \\alpha \\end{bmatrix} = \n\\begin{bmatrix} \\alpha & -\\beta \\\\ e^{i\\theta}\\beta & e^{i\\theta}\\alpha \\end{bmatrix}\n$$\n\nThis turns $\\ket{0} = \\begin{bmatrix} 1 \\\\ 0\\end{bmatrix}$ into $\\begin{bmatrix} \\alpha & -\\beta \\\\ e^{i\\theta}\\beta & e^{i\\theta}\\alpha \\end{bmatrix} \\begin{bmatrix} 1 \\\\ 0\\end{bmatrix} = \\begin{bmatrix} \\alpha \\\\ e^{i\\theta}\\beta \\end{bmatrix} = \\alpha\\ket{0} +e^{i\\theta}\\beta\\ket{1}$."
1575
1575
  },
1576
1576
  {
1577
1577
  "type": "solution",
@@ -1588,7 +1588,7 @@ export default {
1588
1588
  "items": [
1589
1589
  {
1590
1590
  "type": "text-content",
1591
- "content": "\nCongratulations! In this kata you learned the matrix and the ket-bra representation of quantum gates. Here are a few key concepts to keep in mind:\n\n- Single-qubit gates act on individual qubits and are represented by $2 \\times 2$ unitary matrices.\n- The effect of a gate applied to a qubit can be calculated by multiplying the corresponding matrix by the state vector of the qubit.\n- Applying several quantum gates in sequence is equivalent to performing several matrix multiplications.\n- Any square matrix can be represented as a linear combination of the outer products of vectors. The outer product is the matrix product of $\\ket{\\phi}$ and $\\bra{\\psi}$, denoted as $\\ket{\\phi}\\bra{\\psi}$.\n- Pauli gates, identity and Hadamard gates, phase shift gates, and rotation gates are examples of single-qubit gates. All of them are available in Q#.\n\nNext, you will learn about multi-qubit systems in the “Multi-Qubit Systems” kata."
1591
+ "content": "\nCongratulations! In this kata you learned the matrix and the ket-bra representation of quantum gates. Here are a few key concepts to keep in mind:\n\n- Single-qubit gates act on individual qubits and are represented by $2 \\times 2$ unitary matrices.\n- The effect of a gate applied to a qubit can be calculated by multiplying the corresponding matrix by the state vector of the qubit.\n- Applying several quantum gates in sequence is equivalent to performing several matrix multiplications.\n- Any square matrix can be represented as a linear combination of the outer products of vectors. The outer product is the matrix product of $\\ket{\\phi}$ and $\\bra{\\psi}$, denoted as $\\ket{\\phi}\\bra{\\psi}$.\n- Pauli gates, identity and Hadamard gates, phase shift gates, and rotation gates are examples of single-qubit gates. All of them are available in Q#.\n\nNext, you'll learn about multi-qubit systems in the “Multi-Qubit Systems” kata."
1592
1592
  }
1593
1593
  ]
1594
1594
  }
@@ -1606,7 +1606,7 @@ export default {
1606
1606
  "items": [
1607
1607
  {
1608
1608
  "type": "text-content",
1609
- "content": "\nThis kata introduces you to multi-qubit systems, their representation in mathematical notation and in Q# code, and the concept of entanglement.\n\nIf you are not familiar with single-qubit systems, we recommend that you complete \"The Qubit\" kata first.\n\n**This kata covers the following topics:**\n\n- Vector representation of multi-qubit systems\n- Entangled and separable states\n- Dirac notation for multi-qubit systems\n\n**What you should know to start working on this kata:**\n\n- Basic single-qubit gates\n- The concept of tensor product"
1609
+ "content": "\nThis kata introduces you to multi-qubit systems, their representation in mathematical notation and in Q# code, and the concept of entanglement.\n\nIf you are not familiar with single-qubit systems, we recommend that you complete \"The Qubit\" kata first.\n\n**This kata covers the following topics:**\n\n- Vector representation of multi-qubit systems\n- Entangled and separable states\n- Dirac notation for multi-qubit systems\n\n**What you should know to start working on this kata:**\n\n- Basic single-qubit gates\n- The concept of tensor product\n\nIf you need a refresher on these topics, you can check out the previous katas."
1610
1610
  }
1611
1611
  ]
1612
1612
  },
@@ -1617,7 +1617,7 @@ export default {
1617
1617
  "items": [
1618
1618
  {
1619
1619
  "type": "text-content",
1620
- "content": "\nIn The Qubit kata we discussed the concept of a qubit - the basic building block of a quantum computer.\nA multi-qubit system is a collection of multiple qubits, treated as a single system.\n\nLet's start by examining a system of two classical bits. Each bit can be in two states: $0$ and $1$. Therefore, a system of two bits can be in four different states: $00$, $01$, $10$, and $11$. Generally, a system of $N$ classical bits can be in any of the $2^N$ states.\n\nA system of $N$ qubits can also be in any of the $2^N$ classical states, but, unlike the classical bits, it can also be in a **superposition** of all these states.\n\nSimilarly to single-qubit systems, a state of an $N$-qubit system can be represented as a complex vector of size $2^N$:\n$$\\begin{bmatrix} x_0 \\\\ x_1 \\\\ \\vdots \\\\ x_{2^N-1}\\end{bmatrix}$$\n\n## Basis States\n\nSimilarly to single-qubit systems, multi-qubit systems have their own sets of basis states.\nThe computational basis for an $N$-qubit system is a set of $2^N$ vectors, in each of which with one element equals $1$, and the other elements equal $0$.\n\nFor example, this is the **computational basis** for a two-qubit system:\n\n$$\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix},\n\\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix},\n\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix},\n\\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}$$\n\nIt is easy to see that these vectors form an orthonormal basis. Note that each of these basis states can be represented as a tensor product of some combination of single-qubit basis states:\n\n<table>\n <tr>\n <td>$\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}$</td>\n <td>$\\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$</td>\n <td>$\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}$</td>\n <td>$\\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$</td>\n </tr>\n</table>\n\nAny two-qubit system can be expressed as some linear combination of those tensor products of single-qubit basis states.\n\nSimilar logic applies to systems of more than two qubits. In general case,\n\n$$\n\\begin{bmatrix} x_0 \\\\ x_1 \\\\ \\vdots \\\\ x_{2^N-1} \\end{bmatrix} =\nx_0 \\begin{bmatrix} 1 \\\\ 0 \\\\ \\vdots \\\\ 0 \\end{bmatrix} +\nx_1 \\begin{bmatrix} 0 \\\\ 1 \\\\ \\vdots \\\\ 0 \\end{bmatrix} + \\dotsb +\nx_{2^N-1} \\begin{bmatrix} 0 \\\\ 0 \\\\ \\vdots \\\\ 1 \\end{bmatrix}\n$$\n\nThe coefficients of the basis vectors define how \"close\" is the system state to the corresponding basis vector.\n\n> Just like with single-qubit systems, there exist other orthonormal bases states for multi-qubit systems. An example for a two-qubit system is the **Bell basis**:\n>\n> $$\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix},\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ -1 \\end{bmatrix},\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 0 \\\\ 1 \\\\ 1 \\\\ 0 \\end{bmatrix},\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 0 \\\\ 1 \\\\ -1 \\\\ 0 \\end{bmatrix}$$\n>\n> You can check that these vectors are normalized, and orthogonal to each other, and that any two-qubit state can be expressed as a linear combination of these vectors. The vectors of Bell basis, however, can not be represented as tensor products of single-qubit basis states."
1620
+ "content": "\nThe Qubit kata discussed the concept of a qubit - the basic building block of a quantum computer.\nA multi-qubit system is a collection of multiple qubits, treated as a single system.\n\nLet's start by examining a system of two classical bits. Each bit can be in two states: $0$ and $1$. Therefore, a system of two bits can be in four different states: $00$, $01$, $10$, and $11$. Generally, a system of $N$ classical bits can be in any of the $2^N$ states.\n\nA system of $N$ qubits can also be in any of the $2^N$ classical states, but, unlike the classical bits, it can also be in a **superposition** of all these states.\n\nSimilarly to single-qubit systems, a state of an $N$-qubit system can be represented as a complex vector of size $2^N$:\n$$\\begin{bmatrix} x_0 \\\\ x_1 \\\\ \\vdots \\\\ x_{2^N-1}\\end{bmatrix}$$\n\n## Basis States\n\nSimilarly to single-qubit systems, multi-qubit systems have their own sets of basis states.\nThe computational basis for an $N$-qubit system is a set of $2^N$ vectors, in each of which with one element equals $1$, and the other elements equal $0$.\n\nFor example, this is the **computational basis** for a two-qubit system:\n\n$$\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix},\n\\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix},\n\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix},\n\\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}$$\n\nIt's easy to see that these vectors form an orthonormal basis. Note that each of these basis states can be represented as a tensor product of some combination of single-qubit basis states:\n\n<table>\n <tr>\n <td>$\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}$</td>\n <td>$\\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$</td>\n <td>$\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}$</td>\n <td>$\\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$</td>\n </tr>\n</table>\n\nAny two-qubit system can be expressed as some linear combination of those tensor products of single-qubit basis states.\n\nSimilar logic applies to systems of more than two qubits. In general case,\n\n$$\n\\begin{bmatrix} x_0 \\\\ x_1 \\\\ \\vdots \\\\ x_{2^N-1} \\end{bmatrix} =\nx_0 \\begin{bmatrix} 1 \\\\ 0 \\\\ \\vdots \\\\ 0 \\end{bmatrix} +\nx_1 \\begin{bmatrix} 0 \\\\ 1 \\\\ \\vdots \\\\ 0 \\end{bmatrix} + \\dotsb +\nx_{2^N-1} \\begin{bmatrix} 0 \\\\ 0 \\\\ \\vdots \\\\ 1 \\end{bmatrix}\n$$\n\nThe coefficients of the basis vectors define how \"close\" is the system state to the corresponding basis vector.\n\n> Just like with single-qubit systems, there exist other orthonormal bases states for multi-qubit systems. An example for a two-qubit system is the **Bell basis**:\n>\n> $$\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix},\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ -1 \\end{bmatrix},\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 0 \\\\ 1 \\\\ 1 \\\\ 0 \\end{bmatrix},\n\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 0 \\\\ 1 \\\\ -1 \\\\ 0 \\end{bmatrix}$$\n>\n> You can check that these vectors are normalized, and orthogonal to each other, and that any two-qubit state can be expressed as a linear combination of these vectors. The vectors of Bell basis, however, can't be represented as tensor products of single-qubit basis states."
1621
1621
  }
1622
1622
  ]
1623
1623
  },
@@ -1628,7 +1628,7 @@ export default {
1628
1628
  "items": [
1629
1629
  {
1630
1630
  "type": "text-content",
1631
- "content": "\nSometimes the global state of a multi-qubit system can be separated into the states of individual qubits or subsystems. To do this, you would express the vector state of the global system as a tensor product of the vectors representing each individual qubit/subsystem. Here is an example of a two-qubit state:\n\n$$\n\\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ 0 \\\\ \\frac{1}{\\sqrt{2}} \\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}\n$$\n\nYou can see that the first qubit is in state $\\frac{1}{\\sqrt{2}}\\big(\\ket{0} + \\ket{1}\\big)$ and the second qubit is in state $\\ket{0}$. The multi-qubit states that allow such representation are known as **separable states**, or product states, because you can separate the global state into the tensor product of individual subsystems.\n\n## 🔎 Analyze\n\nShow that the state is separable:\n$$\n\\frac{1}{2} \\begin{bmatrix} 1 \\\\ i \\\\ -i \\\\ 1 \\end{bmatrix} =\n\\begin{bmatrix} ? \\\\ ? \\end{bmatrix} \\otimes \\begin{bmatrix} ? \\\\ ? \\end{bmatrix}\n$$\n\n<details>\n<summary><b>Solution</b></summary>\nTo separate the state into a tensor product of two single-qubit states, we need to represent it in the following way:\n\n$$\n\\begin{bmatrix} \\alpha \\gamma \\\\ \\alpha \\delta \\\\ \\beta \\gamma \\\\ \\beta \\delta \\end{bmatrix} =\n\\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} \\otimes \\begin{bmatrix} \\gamma \\\\ \\delta \\end{bmatrix}\n$$\n\nThis brings us to a system of equations:\n\n$$\n\\begin{cases}\n\\alpha\\gamma = \\frac{1}{2} \\\\ \\alpha\\delta = \\frac{i}{2} \\\\ \\beta \\gamma = \\frac{-i}{2} \\\\ \\beta \\delta = \\frac{1}{2}\n\\end{cases}\n$$\n\nSolving this system of equations gives us the answer:\n\n$$\\alpha = \\frac{1}{\\sqrt2}, \\beta = \\frac{-i}{\\sqrt2}, \\gamma = \\frac{1}{\\sqrt2}, \\delta = \\frac{i}{\\sqrt2}$$\n\n$$\n\\frac{1}{2} \\begin{bmatrix} 1 \\\\ i \\\\ -i \\\\ 1 \\end{bmatrix} =\n\\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ -i \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ i \\end{bmatrix}\n$$\n\nNote that finding such representation is not always possible, as you will see in the next exercise.\n</details>\n\n## 🔎 Analyze\n\nIs this state separable?\n\n$$\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}$$\n\n<details>\n<summary><b>Solution</b></summary>\nLet's assume that this state is separable and write down the system of equations to determine the coefficients of individual qubit states in the tensor product, similar to what we did in the previous exercise:\n\n$$\n\\begin{cases}\n\\alpha\\gamma = \\frac{1}{\\sqrt2} \\\\ \\alpha\\delta = 0 \\\\ \\beta \\gamma = 0 \\\\ \\beta \\delta = \\frac{1}{\\sqrt2}\n\\end{cases}\n$$\n\nNow let's multiply the first and the last equations, and the second and the third equations:\n\n$$\n\\begin{cases}\n\\alpha\\beta\\gamma\\delta = \\frac{1}{2} \\\\ \\alpha\\beta\\gamma\\delta = 0\n\\end{cases}\n$$\n\nWe can see that this system of equations doesn't have a solution, which means that this state is <b>not separable</b>.\n</details>"
1631
+ "content": "\nSometimes the global state of a multi-qubit system can be separated into the states of individual qubits or subsystems. To do this, you express the vector state of the global system as a tensor product of the vectors representing each individual qubit/subsystem. Here is an example of a two-qubit state:\n\n$$\n\\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ 0 \\\\ \\frac{1}{\\sqrt{2}} \\\\ 0 \\end{bmatrix} =\n\\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}\n$$\n\nYou can see that the first qubit is in state $\\frac{1}{\\sqrt{2}}\\big(\\ket{0} + \\ket{1}\\big)$ and the second qubit is in state $\\ket{0}$. The multi-qubit states that allow such representation are known as **separable states**, or product states, because you can separate the global state into the tensor product of individual subsystems.\n\n## 🔎 Analyze\n\nShow that the state is separable:\n$$\n\\frac{1}{2} \\begin{bmatrix} 1 \\\\ i \\\\ -i \\\\ 1 \\end{bmatrix} =\n\\begin{bmatrix} ? \\\\ ? \\end{bmatrix} \\otimes \\begin{bmatrix} ? \\\\ ? \\end{bmatrix}\n$$\n\n<details>\n<summary><b>Solution</b></summary>\nTo separate the state into a tensor product of two single-qubit states, you need to represent it in the following way:\n\n$$\n\\begin{bmatrix} \\alpha \\gamma \\\\ \\alpha \\delta \\\\ \\beta \\gamma \\\\ \\beta \\delta \\end{bmatrix} =\n\\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} \\otimes \\begin{bmatrix} \\gamma \\\\ \\delta \\end{bmatrix}\n$$\n\nThis brings you to a system of equations:\n\n$$\n\\begin{cases}\n\\alpha\\gamma = \\frac{1}{2} \\\\ \\alpha\\delta = \\frac{i}{2} \\\\ \\beta \\gamma = \\frac{-i}{2} \\\\ \\beta \\delta = \\frac{1}{2}\n\\end{cases}\n$$\n\nSolving this system of equations gives the answer:\n\n$$\\alpha = \\frac{1}{\\sqrt2}, \\beta = \\frac{-i}{\\sqrt2}, \\gamma = \\frac{1}{\\sqrt2}, \\delta = \\frac{i}{\\sqrt2}$$\n\n$$\n\\frac{1}{2} \\begin{bmatrix} 1 \\\\ i \\\\ -i \\\\ 1 \\end{bmatrix} =\n\\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ -i \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ i \\end{bmatrix}\n$$\n\nNote that finding such representation isn't always possible, as you'll see in the next exercise.\n</details>\n\n## 🔎 Analyze\n\nIs this state separable?\n\n$$\\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}$$\n\n<details>\n<summary><b>Solution</b></summary>\nLet's assume that this state is separable and write down the system of equations to determine the coefficients of individual qubit states in the tensor product, similar to what you did in the previous exercise:\n\n$$\n\\begin{cases}\n\\alpha\\gamma = \\frac{1}{\\sqrt2} \\\\ \\alpha\\delta = 0 \\\\ \\beta \\gamma = 0 \\\\ \\beta \\delta = \\frac{1}{\\sqrt2}\n\\end{cases}\n$$\n\nNow let's multiply the first and the last equations, and the second and the third equations:\n\n$$\n\\begin{cases}\n\\alpha\\beta\\gamma\\delta = \\frac{1}{2} \\\\ \\alpha\\beta\\gamma\\delta = 0\n\\end{cases}\n$$\n\nYou can see that this system of equations doesn't have a solution, which means that this state is <b>not separable</b>.\n</details>"
1632
1632
  }
1633
1633
  ]
1634
1634
  },
@@ -1639,7 +1639,7 @@ export default {
1639
1639
  "items": [
1640
1640
  {
1641
1641
  "type": "text-content",
1642
- "content": "\nSometimes, quantum states cannot be written as individual qubit states. Quantum systems that are not separable are called **entangled** systems. If a state can be written as the product state of the individual subsystems, that state is not entangled.\n\nEntanglement is a quantum correlation, which is very different from classical correlations. In entanglement, the state of the subsystems isn't determined, and you can talk only about the probabilities associated with the outcomes. The global system must be considered as one.\n\n> For example, every state in the Bell basis is an entangled state.\n\nEntanglement is a huge part of what makes quantum computing so powerful. It allows us to link the qubits so that they stop behaving like individuals and start behaving like a large, more complex system. In entangled systems, measuring one of the qubits modifies the state of the other qubits, and tells us something about their state.\n\nFor example, consider two qubits $A$ and $B$ in superposition such that the state of the global system is\n\n$$\\ket{\\psi}_{AB} = \\frac{1}{\\sqrt2}\\ket{00} + \\frac{1}{\\sqrt2}\\ket{11}$$\n\nIn such a state, only two outcomes are possible when you measure the state of both qubits in the standard basis: $\\ket{00}$ and $\\ket{11}$. Notice that each outcome has the same probability of $\\frac{1}{2}$. There's zero probability of obtaining $\\ket{01}$ and $\\ket{10}$. If you measure the first qubit and you get that it is in $\\ket{0}$ state, then you can be positive that the second qubit is also in $\\ket{0}$ state, even without measuring it. The measurement outcomes are correlated, and the qubits are entangled.\n\nThis property is used extensively in many quantum algorithms."
1642
+ "content": "\nSometimes, quantum states can't be written as individual qubit states. Quantum systems that aren't separable are called **entangled** systems. If a state can be written as the product state of the individual subsystems, that state isn't entangled.\n\nEntanglement is a quantum correlation, which is very different from classical correlations. In entanglement, the state of the subsystems isn't determined, and you can talk only about the probabilities associated with the outcomes. The global system must be considered as one.\n\n> For example, every state in the Bell basis is an entangled state.\n\nEntanglement is a huge part of what makes quantum computing so powerful. It allows us to link the qubits so that they stop behaving like individuals and start behaving like a large, more complex system. In entangled systems, measuring one of the qubits modifies the state of the other qubits, and tells us something about their state.\n\nFor example, consider two qubits $A$ and $B$ in superposition such that the state of the global system is\n\n$$\\ket{\\psi}_{AB} = \\frac{1}{\\sqrt2}\\ket{00} + \\frac{1}{\\sqrt2}\\ket{11}$$\n\nIn such a state, only two outcomes are possible when you measure the state of both qubits in the standard basis: $\\ket{00}$ and $\\ket{11}$. Notice that each outcome has the same probability of $\\frac{1}{2}$. There's zero probability of obtaining $\\ket{01}$ and $\\ket{10}$. If you measure the first qubit and you get that it is in $\\ket{0}$ state, then you can be positive that the second qubit is also in $\\ket{0}$ state, even without measuring it. The measurement outcomes are correlated, and the qubits are entangled.\n\nThis property is used extensively in many quantum algorithms."
1643
1643
  }
1644
1644
  ]
1645
1645
  },
@@ -1650,7 +1650,7 @@ export default {
1650
1650
  "items": [
1651
1651
  {
1652
1652
  "type": "text-content",
1653
- "content": "\nJust like with single qubits, Dirac notation provides a useful shorthand for writing down states of multi-qubit systems.\n\nAs we've seen earlier, multi-qubit systems have their own canonical bases, and the basis states can be represented as tensor products of single-qubit basis states. Any multi-qubit system can be represented as a linear combination of these basis states:\n\n$$\n\\begin{bmatrix} x_0 \\\\ x_1 \\\\ x_2 \\\\ x_3 \\end{bmatrix} =\nx_0\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} +\nx_1\\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} +\nx_2\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} +\nx_3\\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} =\nx_0\\ket{0} \\otimes \\ket{0} +\nx_1\\ket{0} \\otimes \\ket{1} +\nx_2\\ket{1} \\otimes \\ket{0} +\nx_3\\ket{1} \\otimes \\ket{1}\n$$\n\nTo simplify this, tensor products of basis states have their own notation:\n\n$$\\ket{0} \\otimes \\ket{0} = \\ket{00}$$\n$$\\ket{0} \\otimes \\ket{1} = \\ket{01}$$\n$$\\ket{1} \\otimes \\ket{0} = \\ket{10}$$\n$$\\ket{1} \\otimes \\ket{1} = \\ket{11}$$\n\n$$\\ket{0} \\otimes \\ket{0} \\otimes \\ket{0} = \\ket{000}$$\n\nAnd so on.\n\nOr, more generally:\n\n$$\\ket{i_0} \\otimes \\ket{i_1} \\otimes \\dotsb \\otimes \\ket{i_n} = \\ket{i_0i_1...i_n}$$\n\nUsing this notation simplifies our example:\n\n$$\n\\begin{bmatrix} x_0 \\\\ x_1 \\\\ x_2 \\\\ x_3 \\end{bmatrix} =\nx_0\\ket{00} + x_1\\ket{01} + x_2\\ket{10} + x_3\\ket{11}\n$$\n\nJust like with single qubits, we can put arbitrary symbols within the kets the same way variables are used in algebra.\nWhether a ket represents a single qubit or an entire system depends on the context.\nSome ket symbols have a commonly accepted usage, such as the symbols for the Bell basis:\n\n$$\\ket{\\Phi^+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{00} + \\ket{11}\\big)$$\n$$\\ket{\\Phi^-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{00} - \\ket{11}\\big)$$\n$$\\ket{\\Psi^+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{01} + \\ket{10}\\big)$$\n$$\\ket{\\Psi^-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{01} - \\ket{10}\\big)$$\n\n>## Endianness\n>\n> In classical computing, endianness refers to the order of bits (or bytes) when representing numbers in binary. You're probably familiar with the typical way of writing numbers in binary: $0 = 0_2$, $1 = 1_2$, $2 = 10_2$, $3 = 11_2$, $4 = 100_2$, $5 = 101_2$, $6 = 110_2$, etc. This is known as **big-endian format**. In big-endian format, the *most significant* bits come first. For example: $110_2 = 1 \\cdot 4 + 1 \\cdot 2 + 0 \\cdot 1 = 4 + 2 = 6$.\n>\n> There is an alternate way of writing binary numbers - **little-endian format**. In little-endian format, the *least significant* bits come first. For example, $2$ would be written as $01$, $4$ as $001$, and $6$ as $011$. To put it another way, in little endian format, the number is written backwards compared to the big-endian format.\n>\n> In Dirac notation for multi-qubit systems, it's common to see integer numbers within the kets instead of bit sequences. What those numbers mean depends on the context - whether the notation used is big-endian or little-endian.\n>\n> Examples with a 3 qubit system:\n>\n> <table>\n> <tr>\n> <th>Integer Ket</th>\n> <td>$\\ket{0}$</td>\n> <td>$\\ket{1}$</td>\n> <td>$\\ket{2}$</td>\n> <td>$\\ket{3}$</td>\n> <td>$\\ket{4}$</td>\n> <td>$\\ket{5}$</td>\n> <td>$\\ket{6}$</td>\n> <td>$\\ket{7}$</td>\n> </tr>\n> <tr>\n> <th>Big-endian</th>\n> <td>$\\ket{000}$</td>\n> <td>$\\ket{001}$</td>\n> <td>$\\ket{010}$</td>\n> <td>$\\ket{011}$</td>\n> <td>$\\ket{100}$</td>\n> <td>$\\ket{101}$</td>\n> <td>$\\ket{110}$</td>\n> <td>$\\ket{111}$</td>\n> </tr>\n> <tr>\n> <th>Little-endian</th>\n> <td>$\\ket{000}$</td>\n> <td>$\\ket{100}$</td>\n> <td>$\\ket{010}$</td>\n> <td>$\\ket{110}$</td>\n> <td>$\\ket{001}$</td>\n> <td>$\\ket{101}$</td>\n> <td>$\\ket{011}$</td>\n> <td>$\\ket{111}$</td>\n> </tr>\n></table>\n>\n> Multi-qubit quantum systems that store superpositions of numbers are often referred to as **quantum registers**."
1653
+ "content": "\nJust like with single qubits, Dirac notation provides a useful shorthand for writing down states of multi-qubit systems.\n\nAs you've seen earlier, multi-qubit systems have their own canonical bases, and the basis states can be represented as tensor products of single-qubit basis states. Any multi-qubit system can be represented as a linear combination of these basis states:\n\n$$\n\\begin{bmatrix} x_0 \\\\ x_1 \\\\ x_2 \\\\ x_3 \\end{bmatrix} =\nx_0\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} +\nx_1\\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} +\nx_2\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} +\nx_3\\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} =\nx_0\\ket{0} \\otimes \\ket{0} +\nx_1\\ket{0} \\otimes \\ket{1} +\nx_2\\ket{1} \\otimes \\ket{0} +\nx_3\\ket{1} \\otimes \\ket{1}\n$$\n\nTo simplify this, tensor products of basis states have their own notation:\n\n$$\\ket{0} \\otimes \\ket{0} = \\ket{00}$$\n$$\\ket{0} \\otimes \\ket{1} = \\ket{01}$$\n$$\\ket{1} \\otimes \\ket{0} = \\ket{10}$$\n$$\\ket{1} \\otimes \\ket{1} = \\ket{11}$$\n\n$$\\ket{0} \\otimes \\ket{0} \\otimes \\ket{0} = \\ket{000}$$\n\nAnd so on.\n\nOr, more generally:\n\n$$\\ket{i_0} \\otimes \\ket{i_1} \\otimes \\dotsb \\otimes \\ket{i_n} = \\ket{i_0i_1...i_n}$$\n\nUsing this notation simplifies the example:\n\n$$\n\\begin{bmatrix} x_0 \\\\ x_1 \\\\ x_2 \\\\ x_3 \\end{bmatrix} =\nx_0\\ket{00} + x_1\\ket{01} + x_2\\ket{10} + x_3\\ket{11}\n$$\n\nJust like with single qubits, you can put arbitrary symbols within the kets the same way variables are used in algebra.\nWhether a ket represents a single qubit or an entire system depends on the context.\nSome ket symbols have a commonly accepted usage, such as the symbols for the Bell basis:\n\n$$\\ket{\\Phi^+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{00} + \\ket{11}\\big)$$\n$$\\ket{\\Phi^-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{00} - \\ket{11}\\big)$$\n$$\\ket{\\Psi^+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{01} + \\ket{10}\\big)$$\n$$\\ket{\\Psi^-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{01} - \\ket{10}\\big)$$\n\n>## Endianness\n>\n> In classical computing, *endianness* refers to the order of bits (or bytes) when representing numbers in binary. You're probably familiar with the typical way of writing numbers in binary: $0 = 0_2$, $1 = 1_2$, $2 = 10_2$, $3 = 11_2$, $4 = 100_2$, $5 = 101_2$, $6 = 110_2$, etc. This is known as **big-endian format**. In big-endian format, the *most significant* bits come first. For example: $110_2 = 1 \\cdot 4 + 1 \\cdot 2 + 0 \\cdot 1 = 4 + 2 = 6$.\n>\n> There is an alternate way of writing binary numbers - **little-endian format**. In little-endian format, the *least significant* bits come first. For example, $2$ would be written as $01$, $4$ as $001$, and $6$ as $011$. To put it another way, in little endian format, the number is written backwards compared to the big-endian format.\n>\n> In Dirac notation for multi-qubit systems, it's common to see integer numbers within the kets instead of bit sequences. What those numbers mean depends on the context - whether the notation used is big-endian or little-endian.\n>\n> Examples with a 3 qubit system:\n>\n> <table>\n> <tr>\n> <th>Integer Ket</th>\n> <td>$\\ket{0}$</td>\n> <td>$\\ket{1}$</td>\n> <td>$\\ket{2}$</td>\n> <td>$\\ket{3}$</td>\n> <td>$\\ket{4}$</td>\n> <td>$\\ket{5}$</td>\n> <td>$\\ket{6}$</td>\n> <td>$\\ket{7}$</td>\n> </tr>\n> <tr>\n> <th>Big-endian</th>\n> <td>$\\ket{000}$</td>\n> <td>$\\ket{001}$</td>\n> <td>$\\ket{010}$</td>\n> <td>$\\ket{011}$</td>\n> <td>$\\ket{100}$</td>\n> <td>$\\ket{101}$</td>\n> <td>$\\ket{110}$</td>\n> <td>$\\ket{111}$</td>\n> </tr>\n> <tr>\n> <th>Little-endian</th>\n> <td>$\\ket{000}$</td>\n> <td>$\\ket{100}$</td>\n> <td>$\\ket{010}$</td>\n> <td>$\\ket{110}$</td>\n> <td>$\\ket{001}$</td>\n> <td>$\\ket{101}$</td>\n> <td>$\\ket{011}$</td>\n> <td>$\\ket{111}$</td>\n> </tr>\n></table>\n>\n> Multi-qubit quantum systems that store superpositions of numbers are often referred to as **quantum registers**."
1654
1654
  }
1655
1655
  ]
1656
1656
  },
@@ -1670,7 +1670,7 @@ export default {
1670
1670
  },
1671
1671
  {
1672
1672
  "type": "text-content",
1673
- "content": "\n> You might have noticed that we've been \"resetting\" the qubits at the end of our demos, that is, returning them to $\\ket{0}$ state. Q# requires you to return your qubits into the $\\ket{0}$ state before they are released at the end of their scope.\n> The reason for this is entanglement.\n>\n> Consider running a program on a quantum computer: the number of qubits is very limited, and you want to reuse the released qubits in other parts of the program.\nIf they are not in zero state by that time, they can potentially be still entangled with the qubits which are not yet released, thus operations you perform on them can affect the state of other parts of the program, causing erroneous and hard to debug behavior.\n>\n> Resetting the qubits to zero state automatically when they go outside the scope of the block they were allocated in is dangerous as well: if they were entangled with others, measuring them to reset them can affect the state of the unreleased qubits, and thus change the results of the program - without the developer noticing this.\n>\n> The requirement that the qubits should be in zero state before they can be released aims to remind the developer to double-check that all necessary information has been properly extracted from the qubits, and that they are not entangled with unreleased qubits any more."
1673
+ "content": "\n> You might have noticed that every demo has been \"resetting\" the qubits at the end of the code, that is, returning them to $\\ket{0}$ state. Q# requires you to return your qubits into the $\\ket{0}$ state before they are released at the end of their scope.\n> The reason for this is entanglement.\n>\n> Consider running a program on a quantum computer: the number of qubits is very limited, and you want to reuse the released qubits in other parts of the program.\nIf they aren't in zero state by that time, they can potentially be still entangled with the qubits which aren't yet released, thus operations you perform on them can affect the state of other parts of the program, causing erroneous and hard to debug behavior.\n>\n> Resetting the qubits to zero state automatically when they go outside the scope of the block they were allocated in is dangerous as well: if they were entangled with others, measuring them to reset them can affect the state of the unreleased qubits, and thus change the results of the program - without the developer noticing this.\n>\n> The requirement that the qubits should be in zero state before they can be released aims to remind the developer to double-check that all necessary information has been properly extracted from the qubits, and that they aren't entangled with unreleased qubits any more."
1674
1674
  }
1675
1675
  ]
1676
1676
  },
@@ -1680,7 +1680,7 @@ export default {
1680
1680
  "title": "Learn Basis State Amplitudes Using DumpMachine",
1681
1681
  "description": {
1682
1682
  "type": "text-content",
1683
- "content": "\n**Input:** 2 qubits in an unknown state $\\ket{\\psi} = \\sum_{k = 0}^{3} x_k \\ket{k}$. The amplitudes $x_k$ will be real and non-negative.\n\n**Output:** A tuple of two numbers $(x_1', x_2')$ - your estimates of the amplitudes of the state $\\ket{01}$ and $\\ket{10}$, respectively.\nThe absolute errors $|x_1 - x_1'|$ and $|x_2 - x_2'|$ should be less than or equal to 0.001.\n\nPlease note that the state parameter is guaranteed to be the same\nif you run the code several times. Your operation will be called\nonce for every run.\n\n<details>\n <summary><b>Need a hint?</b></summary>\n On a physical quantum system, there would be no way to obtain these values from a single observation. Since this program runs on a simulator, we can use <code>DumpMachine</code> to inspect the qubits and take a note of their state. Furthermore, the problem statement guarantees, that the state will be the same from invocation to invocation. So we can update the code to return the amplitudes that we've taken note of. Then run the code again.\n</details>\n"
1683
+ "content": "\n**Input:** 2 qubits in an unknown state $\\ket{\\psi} = \\sum_{k = 0}^{3} x_k \\ket{k}$. The amplitudes $x_k$ will be real and non-negative.\n\n**Output:** A tuple of two numbers $(x_1', x_2')$ - your estimates of the amplitudes of the state $\\ket{01}$ and $\\ket{10}$, respectively.\nThe absolute errors $|x_1 - x_1'|$ and $|x_2 - x_2'|$ should be less than or equal to 0.001.\n\nPlease note that the state parameter is guaranteed to be the same\nif you run the code several times. Your operation will be called\nonce for every run.\n\n<details>\n <summary><b>Need a hint?</b></summary>\n On a physical quantum system, there would be no way to obtain these values from a single observation. Since this program runs on a simulator, you can use <code>DumpMachine</code> to inspect the qubits and take a note of their state. Furthermore, the problem statement guarantees that the state will be the same from invocation to invocation. So, you can update the code to return the amplitudes that you've taken note of, then run the code again.\n</details>\n"
1684
1684
  },
1685
1685
  "sourceIds": [
1686
1686
  "multi_qubit_systems__learn_basis_state_amplitudes__Verification.qs",
@@ -1709,7 +1709,7 @@ export default {
1709
1709
  "items": [
1710
1710
  {
1711
1711
  "type": "text-content",
1712
- "content": "\nIn the following exercises you will learn to prepare separable quantum states by manipulating individual qubits.\nYou will only need knowledge from the Single-Qubit Gates kata for that.\n\n> In each exercise, you'll be given an array of qubits to manipulate; you can access $i$-th element of the array `qs` as `qs[i]`.\nArray elements are indexed starting with 0, the first array element corresponds to the leftmost qubit in Dirac notation."
1712
+ "content": "\nIn the following exercises you'll learn to prepare separable quantum states by manipulating individual qubits.\nYou'll only need knowledge from the Single-Qubit Gates kata for that.\n\n> In each exercise, you'll be given an array of qubits to manipulate; you can access the $i$-th element of the array `qs` as `qs[i]`.\nArray elements are indexed starting with 0, the first array element corresponds to the leftmost qubit in Dirac notation."
1713
1713
  }
1714
1714
  ]
1715
1715
  },
@@ -1731,7 +1731,7 @@ export default {
1731
1731
  "items": [
1732
1732
  {
1733
1733
  "type": "text-content",
1734
- "content": "\nThe starting state can be represented as follows:\n$$ \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\ket{0} \\otimes \\ket{0} $$\n\nThe goal state can be represented as follows:\n$$ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} = \\ket{1} \\otimes \\ket{1} $$\n\nApplying an **X** gate to a qubit in the $\\ket{0}$ state transforms the qubit state into the $\\ket{1}$ state. So, if we apply the **X** gate on the first qubit and the second qubit, we get the desired state."
1734
+ "content": "\nThe starting state can be represented as follows:\n$$ \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\ket{0} \\otimes \\ket{0} $$\n\nThe goal state can be represented as follows:\n$$ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} = \\ket{1} \\otimes \\ket{1} $$\n\nApplying an $X$ gate to a qubit in the $\\ket{0}$ state transforms the qubit state into the $\\ket{1}$ state. So, if you apply the $X$ gate on the first qubit and the second qubit, you get the desired state."
1735
1735
  },
1736
1736
  {
1737
1737
  "type": "solution",
@@ -1759,7 +1759,7 @@ export default {
1759
1759
  "items": [
1760
1760
  {
1761
1761
  "type": "text-content",
1762
- "content": "\nWe begin in the same state as the previous exercise:\n$$ \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = \\ket{0} \\otimes \\ket{0}$$\n\nThe goal state can be separated as follows:\n$$ \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ -1 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ -1 \\end{bmatrix} = \\ket{0} \\otimes \\frac{1}{\\sqrt2}\\big(\\ket{0} - \\ket{1}\\big)$$\n\nThis means that the first qubit is already in the state we want it to be, but the second qubit needs to be transformed from the $ \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} $ into $ \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 \\\\ -1\\end{bmatrix}$ state.\n\nFirst, we apply the **X** gate to the second qubit; this performs the following transformation:\n$$ X \\ket{0} = \\begin{bmatrix}0 & 1 \\\\ 1 & 0 \\end{bmatrix} \\cdot \\begin{bmatrix}1 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} = \\ket{1} $$\n\nSecond, we apply the **H** gate to the second qubit; this transforms its state into the desired one:\n$$ H\\ket{1} = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix} \\cdot \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ -1 \\end{bmatrix}$$"
1762
+ "content": "\nYou begin in the same state as the previous exercise:\n$$ \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = \\ket{0} \\otimes \\ket{0}$$\n\nThe goal state can be separated as follows:\n$$ \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ -1 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ -1 \\end{bmatrix} = \\ket{0} \\otimes \\frac{1}{\\sqrt2}\\big(\\ket{0} - \\ket{1}\\big)$$\n\nThis means that the first qubit is already in the state you want it to be, but the second qubit needs to be transformed from the $ \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} $ into $ \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 \\\\ -1\\end{bmatrix}$ state.\n\nFirst, you apply the $X$ gate to the second qubit; this performs the following transformation:\n$$ X \\ket{0} = \\begin{bmatrix}0 & 1 \\\\ 1 & 0 \\end{bmatrix} \\cdot \\begin{bmatrix}1 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} = \\ket{1} $$\n\nSecond, you apply the $H$ gate to the second qubit; this transforms its state into the desired one:\n$$ H\\ket{1} = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix} \\cdot \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ -1 \\end{bmatrix}$$"
1763
1763
  },
1764
1764
  {
1765
1765
  "type": "solution",
@@ -1787,7 +1787,7 @@ export default {
1787
1787
  "items": [
1788
1788
  {
1789
1789
  "type": "text-content",
1790
- "content": "\nAgain, to start we will represent the goal state as a tensor product of single-qubit states; this gives us the following representation:\n\n$$ \\frac{1}{2}\\big(\\ket{00} - \\ket{01} + \\ket{10} - \\ket{11}\\big) = \\frac{1}{2}\\begin{bmatrix} 1 \\\\ -1 \\\\ 1 \\\\ -1 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ -1 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\big(\\ket{0} + \\ket{1}\\big) \\otimes \\frac{1}{\\sqrt2}\\big(\\ket{0} - \\ket{1}\\big) $$\n\nThis time we need to transform both the first and the second qubits. Let's start with the first qubit. Applying the **H** gate transforms its state as follows:\n\n$$ H\\ket{0} = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix} \\cdot \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\big(\\ket{0} + \\ket{1}\\big)$$\n\nFor the second qubit we can use the same transformation we've seen in the \"Prepare a Superposition of Two Basis States\" exercise; this will give the desired end state."
1790
+ "content": "\nAgain, to start you'll represent the goal state as a tensor product of single-qubit states; this gives you the following representation:\n\n$$ \\frac{1}{2}\\big(\\ket{00} - \\ket{01} + \\ket{10} - \\ket{11}\\big) = \\frac{1}{2}\\begin{bmatrix} 1 \\\\ -1 \\\\ 1 \\\\ -1 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ -1 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\big(\\ket{0} + \\ket{1}\\big) \\otimes \\frac{1}{\\sqrt2}\\big(\\ket{0} - \\ket{1}\\big) $$\n\nThis time you need to transform both the first and the second qubits. Let's start with the first qubit. Applying the $H$ gate transforms its state as follows:\n\n$$ H\\ket{0} = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix} \\cdot \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\big(\\ket{0} + \\ket{1}\\big)$$\n\nFor the second qubit, you can use the same transformation you've seen in the \"Prepare a Superposition of Two Basis States\" exercise; this will give the desired end state."
1791
1791
  },
1792
1792
  {
1793
1793
  "type": "solution",
@@ -1815,7 +1815,7 @@ export default {
1815
1815
  "items": [
1816
1816
  {
1817
1817
  "type": "text-content",
1818
- "content": "\nThe start state is the same as the previous exercises:\n$$ \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = \\ket{0} \\otimes \\ket{0} $$\n\nThe goal state, factored as a tensor product, looks like this (remember that $e^{3i\\pi/4} = e^{i\\pi/4} e^{i\\pi/2}$):\n\n$$\n\\frac{1}{2}\\begin{bmatrix} 1 \\\\ e^{i\\pi/4} \\\\ e^{i\\pi/2} \\\\ e^{3i\\pi/4} \\end{bmatrix} =\n\\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ e^{i\\pi/2} \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ e^{i\\pi/4} \\end{bmatrix} =\n\\frac{1}{\\sqrt2}\\big(\\ket{0} + e^{i\\pi/2}\\ket{1}\\big) \\otimes \\frac{1}{\\sqrt2}\\big(\\ket{0} + e^{i\\pi/4}\\ket{1}\\big) $$\n\nWe will again need to adjust the states of both qubits independently.\n\nFor the first qubit, we'll start by applying the **H** gate, getting the state $\\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix}$, as we've seen in the previous task. Afterwards we'll apply the **S** gate with the following result:\n\n$$ \\begin{bmatrix} 1 & 0 \\\\ 0 & i \\end{bmatrix} \\cdot \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ i \\end{bmatrix}$$\n\nIf we recall that $i = e^{i\\pi/2}$, we can write the final state of the first qubit as:\n$$ \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ e^{i\\pi/2} \\end{bmatrix} $$\n\nFor the second qubit. we'll apply the **H** gate, followed by the **T** gate, with the following result:\n$$ \\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\pi/4} \\end{bmatrix} \\cdot \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ e^{i\\pi/4} \\end{bmatrix} $$"
1818
+ "content": "\nThe start state is the same as the previous exercises:\n$$ \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = \\ket{0} \\otimes \\ket{0} $$\n\nThe goal state, factored as a tensor product, looks like this (remember that $e^{3i\\pi/4} = e^{i\\pi/4} e^{i\\pi/2}$):\n\n$$\n\\frac{1}{2}\\begin{bmatrix} 1 \\\\ e^{i\\pi/4} \\\\ e^{i\\pi/2} \\\\ e^{3i\\pi/4} \\end{bmatrix} =\n\\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ e^{i\\pi/2} \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ e^{i\\pi/4} \\end{bmatrix} =\n\\frac{1}{\\sqrt2}\\big(\\ket{0} + e^{i\\pi/2}\\ket{1}\\big) \\otimes \\frac{1}{\\sqrt2}\\big(\\ket{0} + e^{i\\pi/4}\\ket{1}\\big) $$\n\nYou'll again need to adjust the states of both qubits independently.\n\nFor the first qubit, you'll start by applying the $H$ gate, getting the state $\\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix}$, as you've seen in the previous task. Afterwards you'll apply the $S$ gate with the following result:\n\n$$ \\begin{bmatrix} 1 & 0 \\\\ 0 & i \\end{bmatrix} \\cdot \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ i \\end{bmatrix}$$\n\nIf you recall that $i = e^{i\\pi/2}$, you can write the final state of the first qubit as:\n$$ \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ e^{i\\pi/2} \\end{bmatrix} $$\n\nFor the second qubit, you'll apply the $H$ gate, followed by the $T$ gate, with the following result:\n$$ \\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\pi/4} \\end{bmatrix} \\cdot \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ e^{i\\pi/4} \\end{bmatrix} $$"
1819
1819
  },
1820
1820
  {
1821
1821
  "type": "solution",
@@ -1832,7 +1832,7 @@ export default {
1832
1832
  "items": [
1833
1833
  {
1834
1834
  "type": "text-content",
1835
- "content": "\nEntangled quantum states can be manipulated using single-qubit gates. For example, each state in the Bell basis is entangled and can be transformed into another Bell state through the application of single-qubit gates. In this lesson, you'll learn how to do that. (And we will learn more about applying single-qubit gates to multi-qubit states in the next kata.)"
1835
+ "content": "\nEntangled quantum states can be manipulated using single-qubit gates. For example, each state in the Bell basis is entangled and can be transformed into another Bell state through the application of single-qubit gates. In this lesson, you'll learn how to do that (and you'll learn more about applying single-qubit gates to multi-qubit states in the next kata)."
1836
1836
  }
1837
1837
  ]
1838
1838
  },
@@ -1854,7 +1854,7 @@ export default {
1854
1854
  "items": [
1855
1855
  {
1856
1856
  "type": "text-content",
1857
- "content": "\nWe recognize that the goal is another Bell state. In fact, it is one of the four Bell states.\n\nWe remember from the Single-Qubit Gates kata that the Pauli Z gate will change the state of the $\\ket{1}$ basis state of a single qubit, so this gate seems like a good candidate for what we want to achieve. This gate leaves the sign of the $\\ket{0}$ basis state of a superposition unchanged, but flips the sign of the $\\ket{1}$ basis state of the superposition.\n\nDon't forget that the Z gate acts on only a single qubit, and we have two here.\nLet's also remember how the Bell state is made up from its individual qubits.\n\nIf the two qubits are A and B, where A is `qs[0]` and B is `qs[1]`, we can write that\n$\\ket{\\Phi^{+}} = \\frac{1}{\\sqrt{2}} \\big(\\ket{0_{A}0_{B}} + \\ket{1_{A}1_{B}}\\big)$.\nIf we apply the Z gate to the qubit A, it will flip the phase of the basis state $\\ket{1_A}$. As this phase is in a sense spread across the entangled state, with $\\ket{1_A}$ basis state being part of the second half of the superposition, this application has the effect of flipping the sign of the whole basis state $\\ket{1_A1_B}$, as you can see by running the solution below.\n\nThe exact same calculations can be done if we apply Z to the qubit B, so that's another possible solution."
1857
+ "content": "\nYou recognize that the goal is another Bell state. In fact, it is one of the four Bell states.\n\nYou have seen in the Single-Qubit Gates kata that the Pauli Z gate will change the state of the $\\ket{1}$ basis state of a single qubit, so this gate seems like a good candidate for what you want to achieve. This gate leaves the sign of the $\\ket{0}$ basis state of a superposition unchanged, but flips the sign of the $\\ket{1}$ basis state of the superposition.\n\nDon't forget that the $Z$ gate acts on only a single qubit, and you have two here.\nLet's also remember how the Bell state is made up from its individual qubits.\n\nIf the two qubits are A and B, where A is `qs[0]` and B is `qs[1]`, you can write that\n$\\ket{\\Phi^{+}} = \\frac{1}{\\sqrt{2}} \\big(\\ket{0_{A}0_{B}} + \\ket{1_{A}1_{B}}\\big)$.\nIf you apply the $Z$ gate to the qubit A, it will flip the phase of the basis state $\\ket{1_A}$. As this phase is in a sense spread across the entangled state, with $\\ket{1_A}$ basis state being part of the second half of the superposition, this application has the effect of flipping the sign of the whole basis state $\\ket{1_A1_B}$, as you can see by running the solution below.\n\nThe exact same calculations can be done if you apply $Z$ to the qubit B, so that's another possible solution."
1858
1858
  },
1859
1859
  {
1860
1860
  "type": "solution",
@@ -1882,7 +1882,7 @@ export default {
1882
1882
  "items": [
1883
1883
  {
1884
1884
  "type": "text-content",
1885
- "content": "\nWe have seen in the Single-Qubit Gates kata that the Pauli X gate flips $\\ket{0}$ to $\\ket{1}$ and vice versa, and as we seem to need some flipping of states, perhaps this gate may be of use. (Bearing in mind, of course, that the X gate operates on a single qubit).\n\nLet's compare the starting state $\\frac{1}{\\sqrt{2}} \\big(\\ket{0_A0_B} + \\ket{1_A1_B}\\big)$ with the goal state $\\frac{1}{\\sqrt{2}} \\big(\\ket{1_A0_B} + \\ket{0_A1_B}\\big)$ term by term and see how we need to transform it to reach the goal.\n\nUsing our nomenclature from \"Bell state change 1\", we can now see by comparing terms that $\\ket{0_{A}}$ has flipped to $\\ket{1_A}$ to get the first term, and $\\ket{1_{A}}$ has flipped to $\\ket{0_A}$ to get the second term. This allows us to say that the correct gate to use is Pauli X, applied to `qs[0]`."
1885
+ "content": "\nYou have seen in the Single-Qubit Gates kata that the Pauli X gate flips $\\ket{0}$ to $\\ket{1}$ and vice versa, and as you seem to need some flipping of states, perhaps this gate may be of use. (Bearing in mind, of course, that the $X$ gate operates on a single qubit).\n\nLet's compare the starting state $\\frac{1}{\\sqrt{2}} \\big(\\ket{0_A0_B} + \\ket{1_A1_B}\\big)$ with the goal state $\\frac{1}{\\sqrt{2}} \\big(\\ket{1_A0_B} + \\ket{0_A1_B}\\big)$ term by term and see how you need to transform it to reach the goal.\n\nUsing the nomenclature from \"Bell state change 1\", you can now see by comparing terms that $\\ket{0_{A}}$ has flipped to $\\ket{1_A}$ to get the first term, and $\\ket{1_{A}}$ has flipped to $\\ket{0_A}$ to get the second term. This allows you to say that the correct gate to use is Pauli X, applied to `qs[0]`."
1886
1886
  },
1887
1887
  {
1888
1888
  "type": "solution",
@@ -1910,7 +1910,7 @@ export default {
1910
1910
  "items": [
1911
1911
  {
1912
1912
  "type": "text-content",
1913
- "content": "\nWe remember from the Single-Qubit Gates kata that the Pauli Z gate leaves the sign of the $\\ket{0}$ component of the single qubit superposition unchanged but flips the sign of the $\\ket{1}$ component of the superposition. We have also just seen in \"Bell State Change 2\" how to change our input state to the state $\\frac{1}{\\sqrt{2}} \\big(\\ket{01} + \\ket{10}\\big)$, which is almost our goal state (disregarding the phase change for the moment). So it would seem that a combination of these two gates will be what we need here. The remaining question is in what order to apply them, and to which qubit.\n\nFirst of all, which qubit? Looking back at the task \"Bell state change 2\", it seems clear that we need to use qubit `qs[0]`, like we did there.\n\nSecond, in what order should we apply the gates? Remember that the Pauli Z gate flips the phase of the $\\ket{1}$ component of the superposition and leaves the $\\ket{0}$ component alone.\nLet's experiment with applying X to `qs[0]` first. Looking at our \"halfway answer\" state $\\frac{1}{\\sqrt{2}} \\big(\\ket{01} + \\ket{10}\\big)$, we can see that if we apply the Z gate to `qs[0]`, it will leave the $\\ket{0_{A}}$ alone but flip the phase of $\\ket{1_{A}}$ to $-\\ket{1_{A}}$, thus flipping the phase of the $\\ket{11}$ component of our Bell state."
1913
+ "content": "\nYou have seen in the Single-Qubit Gates kata that the Pauli Z gate leaves the sign of the $\\ket{0}$ component of the single qubit superposition unchanged but flips the sign of the $\\ket{1}$ component of the superposition. You have also just seen in \"Bell State Change 2\" how to change our input state to the state $\\frac{1}{\\sqrt{2}} \\big(\\ket{01} + \\ket{10}\\big)$, which is almost your goal state (disregarding the phase change for the moment). So it would seem that a combination of these two gates will be what you need here. The remaining question is in what order to apply them, and to which qubit.\n\nFirst of all, which qubit? Looking back at the task \"Bell state change 2\", it seems clear that you need to use qubit `qs[0]`, like you did there.\n\nSecond, in what order should you apply the gates? Remember that the Pauli Z gate flips the phase of the $\\ket{1}$ component of the superposition and leaves the $\\ket{0}$ component alone.\nLet's experiment with applying $X$ gate to `qs[0]` first. Looking at our \"halfway answer\" state $\\frac{1}{\\sqrt{2}} \\big(\\ket{01} + \\ket{10}\\big)$, you can see that if you apply the $Z$ gate to `qs[0]`, it'll leave the $\\ket{0_{A}}$ alone but flip the phase of $\\ket{1_{A}}$ to $-\\ket{1_{A}}$, thus flipping the phase of the $\\ket{11}$ component of our Bell state."
1914
1914
  },
1915
1915
  {
1916
1916
  "type": "solution",
@@ -1927,7 +1927,7 @@ export default {
1927
1927
  "items": [
1928
1928
  {
1929
1929
  "type": "text-content",
1930
- "content": "\nCongratulations! In this kata you learned to prepare separable multi-qubit states using only single-qubit gates. You also learned the difference between separable states and entangled states. Here are a few key concepts to keep in mind:\n\n- A system of $N$ qubits can be in a superposition of $2^N$ quantum states. The computational basis for an $N$-qubit system is a set of $2^N$ vectors.\n- Any two-qubit system can be expressed as some linear combination of the tensor products of single-qubit basis states.\n- Two qubits are entangled if their states are correlated and if they can't be described as two independent qubits.\n\nNext, you will learn about multi-qubit gates and how they can give you access to all states of multi-qubit systems in the \"Multi-Qubit Gates\" kata."
1930
+ "content": "\nCongratulations! In this kata you learned to prepare separable multi-qubit states using only single-qubit gates. You also learned the difference between separable states and entangled states. Here are a few key concepts to keep in mind:\n\n- A system of $N$ qubits can be in a superposition of $2^N$ quantum states. The computational basis for an $N$-qubit system is a set of $2^N$ vectors.\n- Any two-qubit system can be expressed as some linear combination of the tensor products of single-qubit basis states.\n- Two qubits are entangled if their states are correlated and if they can't be described as two independent qubits.\n\nNext, you'll learn about multi-qubit gates and how they can give you access to all states of multi-qubit systems in the \"Multi-Qubit Gates\" kata."
1931
1931
  }
1932
1932
  ]
1933
1933
  }
@@ -4691,7 +4691,7 @@ export default {
4691
4691
  "items": [
4692
4692
  {
4693
4693
  "type": "text-content",
4694
- "content": "\nTrue random number generation is a notoriously difficult problem. Many \"random\" generators today are actually pseudo-random, using a starting seed to spawn seemingly-random numbers that are actually a repeatable function of that seed. Most true random number generators are based on measurements of some natural phenomenon, such as atmospheric noise or atomic decay. You can read more about it <a href=\"https://en.wikipedia.org/wiki/Random_number_generation\" target=\"_blank\">here</a>.\n\nQuantum random number generators (QRNGs) are truly random. Of course, this only applies to the case when they run on a real quantum device, relying on the randomness of the quantum state collapse during measurement to produce the random numbers. When QRNGs run on a simulator, the source of randomness is the same as for other classical programs, so the generated numbers are pseudo-random.\n\nThe quantum algorithm for random number generation is one of the simplest applications of quantum computing principles, requiring very few qubits to run.\n\n**This kata covers the following topics:**\n\n- Quantum random number generation and the principles behind it\n- Implementation of a variety of QRNGs with equal probability of any given number\n- Implementation a single-bit QRNG with weighted probabilities of generated bits\n\n**What you should know to start working on this kata:**\n\n- The concept of qubit and measurement\n- Single-qubit gates"
4694
+ "content": "\nTrue random number generation is a notoriously difficult problem. Many \"random\" generators today are actually pseudo-random, using a starting seed to spawn seemingly-random numbers that are actually a repeatable function of that seed. Most true random number generators are based on measurements of some natural phenomenon, such as atmospheric noise or atomic decay. You can read more about it <a href=\"https://en.wikipedia.org/wiki/Random_number_generation\" target=\"_blank\">here</a>.\n\nQuantum random number generators (QRNGs) are truly random. Of course, this only applies to the case when they run on a real quantum device, relying on the randomness of the quantum state collapse during measurement to produce the random numbers. When QRNGs run on a simulator, the source of randomness is the same as for other classical programs, so the generated numbers are pseudo-random.\n\nThe quantum algorithm for random number generation is one of the simplest applications of quantum computing principles, requiring very few qubits to run.\n\n**This kata covers the following topics:**\n\n- Quantum random number generation and the principles behind it\n- Implementation of a variety of QRNGs with equal probability of any given number\n- Implementation a single-bit QRNG with weighted probabilities of generated bits\n\n**What you should know to start working on this kata:**\n\n- Quantum measurements\n- Basic single-qubit gates\n\nIf you need a refresher on these topics, you can check out the previous katas."
4695
4695
  }
4696
4696
  ]
4697
4697
  },
@@ -4702,7 +4702,7 @@ export default {
4702
4702
  "items": [
4703
4703
  {
4704
4704
  "type": "text-content",
4705
- "content": "\nRecall from the Qubit kata that a qubit state $\\ket{\\psi}$ is defined via the basis states $\\ket{0}$ and $\\ket{1}$ as $\\ket{\\psi} = \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} = \\alpha\\ket{0} + \\beta\\ket{1}$, where $|\\alpha|^2 + |\\beta|^2 = 1$.\n\nWe call $\\alpha$ and $\\beta$ the probability amplitudes of states $\\ket{0}$ and $\\ket{1}$, respectively. When $\\ket{\\psi}$ is measured in the $\\{\\ket{0}, \\ket{1}\\}$ basis (the computational basis), the probabilities of the outcomes are defined based on the state amplitudes: there is a $|\\alpha|^2$ probability that the measurement result will be $0$, and a $|\\beta|^2$ probability that the measurement result will be $1$.\n\n> For example, a qubit in state $\\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} \\end{bmatrix}$ will yield measurement results $0$ or $1$ with equal probability, while a qubit in state $\\begin{bmatrix} \\frac{1}{2} \\\\ \\frac{\\sqrt3}{2} \\end{bmatrix}$ will yield measurement result $0$ only 25% of the time, and $1$ 75% of the time.\n\nThis knowledge is sufficient to implement a simple random number generator!\n\n> Remember that you can refer to the Single-Qubit Gates kata if you need a refresher on the various quantum gates and their usage in Q#."
4705
+ "content": "\nRecall from the Qubit kata that a qubit state $\\ket{\\psi}$ is defined via the basis states $\\ket{0}$ and $\\ket{1}$ as $\\ket{\\psi} = \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} = \\alpha\\ket{0} + \\beta\\ket{1}$, where $|\\alpha|^2 + |\\beta|^2 = 1$.\n\n$\\alpha$ and $\\beta$ are the probability amplitudes of states $\\ket{0}$ and $\\ket{1}$, respectively. When $\\ket{\\psi}$ is measured in the $\\{\\ket{0}, \\ket{1}\\}$ basis (the computational basis), the probabilities of the outcomes are defined based on the state amplitudes: there is a $|\\alpha|^2$ probability that the measurement result will be $0$, and a $|\\beta|^2$ probability that the measurement result will be $1$.\n\n> For example, a qubit in state $\\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} \\end{bmatrix}$ will yield measurement results $0$ or $1$ with equal probability, while a qubit in state $\\begin{bmatrix} \\frac{1}{2} \\\\ \\frac{\\sqrt3}{2} \\end{bmatrix}$ will yield measurement result $0$ only 25% of the time, and $1$ 75% of the time.\n\nThis knowledge is sufficient to implement a simple random number generator!\n\n> Remember that you can refer to the Single-Qubit Gates kata if you need a refresher on the various quantum gates and their usage in Q#."
4706
4706
  }
4707
4707
  ]
4708
4708
  },
@@ -4725,7 +4725,7 @@ export default {
4725
4725
  "items": [
4726
4726
  {
4727
4727
  "type": "text-content",
4728
- "content": "\nThe state of single qubit can be represented as a two-dimensional column vector $\\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix}$, where $\\alpha$ and $\\beta$ are complex numbers that satisfy $|\\alpha|^2 + |\\beta|^2 = 1$. When we measure the qubit, we get either 0 with probability $|\\alpha|^2$ or 1 with probability $|\\beta|^2$. Essentially we can control probability of measurement outcome by setting the right amplitudes of basis states. \n\nWhen we allocate the qubit in Q#, amplitudes $\\alpha$ and $\\beta$ are 1 and 0, respectively. Now our goal is set equal amplitudes for $\\alpha$ and $\\beta$ for absolute randomness. We can achieve that by simply applying Hadamard gate to the initial state $\\ket{0}$:\n\n$$\nH\\ket{0} =\n\\frac{1}{\\sqrt{2}}\n\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix}\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} =\n\\frac{1}{\\sqrt{2}}\n\\begin{bmatrix} 1 \\cdot 1 + 1 \\cdot 0 \\\\ 1 \\cdot 1 + (-1) \\cdot 0 \\end{bmatrix} =\n\\frac{1}{\\sqrt{2}}\n\\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix}\n$$\n\nNow, both 0 and 1 measurement outcomes occur with equal probability of $|\\frac{1}{\\sqrt{2}}|^2 = \\frac{1}{2}$.\n\n> Since the outcome probability is the square of the absolute value of amplitude, we will get the same distribution of outcomes by measuring the $\\ket{-}$ state, which we can prepare by applying the Hadamard gate to the basis state $\\ket{1}$. Try it out to achieve the stretch goal!"
4728
+ "content": "\nThe state of single qubit can be represented as a two-dimensional column vector $\\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix}$, where $\\alpha$ and $\\beta$ are complex numbers that satisfy $|\\alpha|^2 + |\\beta|^2 = 1$. When you measure the qubit, you get either 0 with probability $|\\alpha|^2$ or 1 with probability $|\\beta|^2$. Essentially, you can control probability of measurement outcome by setting the right amplitudes of basis states. \n\nWhen you allocate the qubit in Q#, amplitudes $\\alpha$ and $\\beta$ are 1 and 0, respectively. Now your goal is to set equal amplitudes for $\\alpha$ and $\\beta$ for absolute randomness. You can achieve that by simply applying Hadamard gate to the initial state $\\ket{0}$:\n\n$$\nH\\ket{0} =\n\\frac{1}{\\sqrt{2}}\n\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix}\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} =\n\\frac{1}{\\sqrt{2}}\n\\begin{bmatrix} 1 \\cdot 1 + 1 \\cdot 0 \\\\ 1 \\cdot 1 + (-1) \\cdot 0 \\end{bmatrix} =\n\\frac{1}{\\sqrt{2}}\n\\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix}\n$$\n\nNow, both 0 and 1 measurement outcomes occur with equal probability of $|\\frac{1}{\\sqrt{2}}|^2 = \\frac{1}{2}$.\n\n> Since the outcome probability is the square of the absolute value of amplitude, you'll get the same distribution of outcomes by measuring the $\\ket{-}$ state, which you can prepare by applying the Hadamard gate to the basis state $\\ket{1}$. Try it out to achieve the stretch goal!"
4729
4729
  },
4730
4730
  {
4731
4731
  "type": "solution",
@@ -4754,7 +4754,7 @@ export default {
4754
4754
  "items": [
4755
4755
  {
4756
4756
  "type": "text-content",
4757
- "content": "\nLet's reuse the `RandomBit` operation from the \"Generate A Single Random Bit\" exercise.\nWe can generate two random bits by calling the `RandomBit` operation twice, multiply the most significant bit by 2 and add the least significant bit to generate a random two-bit number."
4757
+ "content": "\nLet's reuse the `RandomBit` operation from the \"Generate A Single Random Bit\" exercise.\nYou can generate two random bits by calling the `RandomBit` operation twice, multiply the most significant bit by 2 and add the least significant bit to generate a random two-bit number."
4758
4758
  },
4759
4759
  {
4760
4760
  "type": "solution",
@@ -4783,7 +4783,7 @@ export default {
4783
4783
  "items": [
4784
4784
  {
4785
4785
  "type": "text-content",
4786
- "content": "\nLet's reuse the `RandomBit` operation from the \"Generate A Single Random Bit\" exercise again.\nWe'll generate $N$ random bits by calling `RandomBit` operation $N$ times, and treat the result as a binary notation of the integer we're looking for.\nSince the maximum value of the number written with $N$ bits is $2^N - 1$, we don't need to do any extra checks to ensure that the result is within the given range."
4786
+ "content": "\nLet's reuse the `RandomBit` operation from the \"Generate A Single Random Bit\" exercise again.\nYou'll generate $N$ random bits by calling `RandomBit` operation $N$ times, and treat the result as a binary notation of the integer you're looking for.\nSince the maximum value of the number written with $N$ bits is $2^N - 1$, you don't need to do any extra checks to ensure that the result is within the given range."
4787
4787
  },
4788
4788
  {
4789
4789
  "type": "solution",
@@ -4799,7 +4799,7 @@ export default {
4799
4799
  "title": "Generate a Weighted Bit",
4800
4800
  "description": {
4801
4801
  "type": "text-content",
4802
- "content": "In each of the above exercises, all generated numbers were equally likely. Now let's create an operation that will return a random bit with different probabilities of outcomes. \n\n> Remember that by setting the amplitudes of basis states $\\alpha$ and $\\beta$, we can control the probability of getting measurement outcomes $0$ and $1$ when the qubit is measured.\n\n**Input:** \nA floating-point number $x$, $0 \\le x \\le 1$. \n\n**Goal:** Generate $0$ or $1$ with probability of $0$ equal to $x$ and probability of $1$ equal to $1 - x$.\n\n> Q# namespace `Microsoft.Quantum.Math` includes useful functions `Sqrt`, `ArcCos`, and `ArcSin`.\n"
4802
+ "content": "In each of the above exercises, all generated numbers were equally likely. Now let's create an operation that will return a random bit with different probabilities of outcomes. \n\n> Remember that by setting the amplitudes of basis states $\\alpha$ and $\\beta$, you can control the probability of getting measurement outcomes $0$ and $1$ when the qubit is measured.\n\n**Input:** \nA floating-point number $x$, $0 \\le x \\le 1$. \n\n**Goal:** Generate $0$ or $1$ with probability of $0$ equal to $x$ and probability of $1$ equal to $1 - x$.\n\n> Q# namespace `Microsoft.Quantum.Math` includes useful functions `Sqrt`, `ArcCos`, and `ArcSin`.\n"
4803
4803
  },
4804
4804
  "sourceIds": [
4805
4805
  "random_numbers__weighted_random_bit__Verification.qs",
@@ -4812,7 +4812,7 @@ export default {
4812
4812
  "items": [
4813
4813
  {
4814
4814
  "type": "text-content",
4815
- "content": "\nAn arbitrary single-qubit state can be written as:\n\n$$\n\\ket{\\psi} =\n \\cos \\frac{\\theta}{2} \\ket{0 } + e^{i\\phi} \\sin \\frac{\\theta}{2} \\ket{1}\n$$\n\nHere, $\\theta$ is the angle between the state vector and the $Z$-axis, and $\\phi$ is the longitude angle with respect to the $X$-axis on the Bloch sphere.\n\nOur goal is to generate $0$ or $1$ with the probability of generating a $0$ equal to $x$ and the probability of generating a $1$ equal to $1 - x$. This means that the qubit state should look like\n\n$$\n\\ket{\\psi} =\n \\sqrt x \\ket{0 } + \\sqrt{1 - x} \\ket{1}\n$$\n\nComparing the amplitudes of the state $\\ket{0 }$ in the two equations, we get\n\n$$\n\\sqrt x = \\cos \\frac{\\theta}{2} \\Rightarrow \\theta = 2 \\arccos\\sqrt x\n$$\n\nSince $\\theta$ is the angle between the state vector and the $Z$-axis, we need to apply the $Ry$ gate with the calculated $\\theta$ to the starting state $\\ket{0 }$ to get the desired qubit state.\n\nThe $Ry$ gate applies a given rotation about the $Y$-axis (i.e., in the $ZX$-plane). Hence, $\\phi$ (longitude angle with respect to $X$-axis) is always equal to $0^{\\circ}$, which means that the relative phase $e^{i\\phi}$ doesn't have any impact on the resulting qubit state.\n\n> We can also calculate ${\\theta}$ by comparing the amplitudes of the state $\\ket{1 }$ in the two equations, which is $2 \\arcsin\\sqrt{1.0 - x}$. The results will be equivalent."
4815
+ "content": "\nAn arbitrary single-qubit state can be written as:\n\n$$\n\\ket{\\psi} =\n \\cos \\frac{\\theta}{2} \\ket{0 } + e^{i\\phi} \\sin \\frac{\\theta}{2} \\ket{1}\n$$\n\nHere, $\\theta$ is the angle between the state vector and the $Z$-axis, and $\\phi$ is the longitude angle with respect to the $X$-axis on the Bloch sphere.\n\nYour goal is to generate $0$ or $1$ with the probability of generating a $0$ equal to $x$ and the probability of generating a $1$ equal to $1 - x$. This means that the qubit state should look like this:\n\n$$\n\\ket{\\psi} =\n \\sqrt x \\ket{0 } + \\sqrt{1 - x} \\ket{1}\n$$\n\nComparing the amplitudes of the state $\\ket{0 }$ in the two equations, you get\n\n$$\n\\sqrt x = \\cos \\frac{\\theta}{2} \\Rightarrow \\theta = 2 \\arccos\\sqrt x\n$$\n\nSince $\\theta$ is the angle between the state vector and the $Z$-axis, you need to apply the $Ry$ gate with the calculated $\\theta$ to the starting state $\\ket{0 }$ to get the desired qubit state.\n\nThe $Ry$ gate applies a given rotation about the $Y$-axis, that is, in the $ZX$-plane. Hence, $\\phi$ (longitude angle with respect to $X$-axis) is always equal to $0^{\\circ}$, which means that the relative phase $e^{i\\phi}$ doesn't have any impact on the resulting qubit state.\n\n> You can also calculate ${\\theta}$ by comparing the amplitudes of the state $\\ket{1 }$ in the two equations, which is $2 \\arcsin\\sqrt{1.0 - x}$. The results will be equivalent."
4816
4816
  },
4817
4817
  {
4818
4818
  "type": "solution",
@@ -4828,7 +4828,7 @@ export default {
4828
4828
  "title": "Generate a Random Number Between Min and Max",
4829
4829
  "description": {
4830
4830
  "type": "text-content",
4831
- "content": "In the \"Generate A Number Of Arbitrary Size\" exercise, we generated numbers in the range $[0, 2^N-1]$ $(1 \\leq N \\leq 10)$. Now let's create an operation that will return a random number in the range $[min, max]$. \n\n**Input:** \nTwo integers $min$ and $max$ ($0 \\leq min \\leq max \\leq 2^{10}-1$).\n\n**Goal:** Generate a random number in the range $[min, max]$ with an equal probability of getting each of the numbers in this range.\n\n> Q# namespace `Microsoft.Quantum.Math` includes useful function `BitSizeI` that calculates the number of bits in the binary representation of the given number.\n"
4831
+ "content": "In the \"Generate A Number Of Arbitrary Size\" exercise, you generated numbers in the range $[0, 2^N-1]$ $(1 \\leq N \\leq 10)$. Now let's create an operation that will return a random number in the range $[min, max]$. \n\n**Input:** \nTwo integers $min$ and $max$ ($0 \\leq min \\leq max \\leq 2^{10}-1$).\n\n**Goal:** Generate a random number in the range $[min, max]$ with an equal probability of getting each of the numbers in this range.\n\n> Q# namespace `Microsoft.Quantum.Math` includes useful function `BitSizeI` that calculates the number of bits in the binary representation of the given number.\n"
4832
4832
  },
4833
4833
  "sourceIds": [
4834
4834
  "random_numbers__random_number__Verification.qs",
@@ -4841,7 +4841,7 @@ export default {
4841
4841
  "items": [
4842
4842
  {
4843
4843
  "type": "text-content",
4844
- "content": "\nWe can reuse the `RandomBit` and `RandomNBits` operations from earlier exercises.\n\nWe'll generate an $N$-bit random number by calling the `RandomNBits` operation, where $N$ is the bitsize of $max - min$. We can repeat this process until the result is less than or equal than $max - min$, and return that number plus $min$."
4844
+ "content": "\nYou can reuse the `RandomBit` and `RandomNBits` operations from earlier exercises.\n\nYou'll generate an $N$-bit random number by calling the `RandomNBits` operation, where $N$ is the bitsize of $max - min$. You can repeat this process until the result is less than or equal than $max - min$, and return that number plus $min$."
4845
4845
  },
4846
4846
  {
4847
4847
  "type": "solution",
@@ -5670,7 +5670,7 @@ export default {
5670
5670
  "items": [
5671
5671
  {
5672
5672
  "type": "text-content",
5673
- "content": "\nQuantum oracles are a key part of many quantum algorithms that rely on quantum implementation of a classical function. The algorithms' discussions often assume that the quantum oracle that implements the function of interest is provided.  This kata dives deeper into the definition of different types of quantum oracles, their properties, and the basic ways to implement the oracles.\n\n**This kata covers the following topics:**\n\n- Quantum oracles and how they relate to classical oracles\n- Two types of quantum oracles - phase oracles and marking oracles\n- Phase kickback and its uses for oracles implementation\n- Implementation and testing of quantum oracles in Q#\n\n**What you should know to start working on this kata:**\n\n- Basic knowledge of fundamental quantum concepts\n- Basic knowledge of multi-qubit gates, especially controlled gates. If you're not familiar with these concepts, you can find them in the Multi-Qubit Gates kata."
5673
+ "content": "\nQuantum oracles are a key part of many quantum algorithms that rely on quantum implementation of a classical function. The algorithms' discussions often assume that the quantum oracle that implements the function of interest is provided.  This kata dives deeper into the definition of different types of quantum oracles, their properties, and the basic ways to implement the oracles.\n\n**This kata covers the following topics:**\n\n- Quantum oracles and how they relate to classical oracles\n- Two types of quantum oracles - phase oracles and marking oracles\n- Phase kickback and its uses for oracles implementation\n- Implementation and testing of quantum oracles in Q#\n\n**What you should know to start working on this kata:**\n\n- Fundamental quantum concepts\n- Basic multi-qubit gates, especially controlled gates\n\nIf you need a refresher on these topics, you can check out the previous katas."
5674
5674
  }
5675
5675
  ]
5676
5676
  },
@@ -6574,7 +6574,7 @@ export default {
6574
6574
  "items": [
6575
6575
  {
6576
6576
  "type": "text-content",
6577
- "content": "\nThis kata introduces you to Deutsch algorithm - the single-qubit variant of Deutsch–Jozsa algorithm, one of the most famous educational algorithms in quantum computing.\n\n**This kata covers the following topics:**\n\n- The problem solved by Deutsch algorithm and the classical solution to it\n- Single-qubit phase oracles (for a more detailed introduction to phase oracles, see Oracles kata)\n- Deutsch algorithm\n- Implementing oracles and end-to-end Deutsch algorithm in Q#\n\n**What you should know to start working on this kata:**\n\n- Basic knowledge of single-qubit gates\n- Basic knowledge of quantum measurements"
6577
+ "content": "\nThis kata introduces you to Deutsch algorithm - the single-qubit variant of Deutsch–Jozsa algorithm, one of the most famous educational algorithms in quantum computing.\n\n**This kata covers the following topics:**\n\n- The problem solved by Deutsch algorithm and the classical solution to it\n- Single-qubit phase oracles (for a more detailed introduction to phase oracles, see Oracles kata)\n- Deutsch algorithm\n- Implementing oracles and end-to-end Deutsch algorithm in Q#\n\n**What you should know to start working on this kata:**\n\n- Basic single-qubit gates\n- Quantum measurements\n\nIf you need a refresher on these topics, you can check out the previous katas."
6578
6578
  }
6579
6579
  ]
6580
6580
  },
@@ -6651,7 +6651,7 @@ export default {
6651
6651
  "items": [
6652
6652
  {
6653
6653
  "type": "text-content",
6654
- "content": "\nYou can follow the steps of the algorithm for the constant and the balanced scenarios using a neat visualization. Since Deutsch algorithm deals only with states with real amplitudes, you can map all states on the unit circle, and follow the state evolution through the steps.\n\n1. Start with a qubit in the $\\ket{0}$ state and apply the $H$ gate to the qubit.\n <br/>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"660\" height=\"334\" fill=\"none\" version=\"1.1\" viewBox=\"0 0 660 334\" xmlns=\"http://www.w3.org/2000/svg\">\n <style>\n :root {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n }\n @media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n }\n .kata_svg_path {\n stroke: var(--kata-svg-path);\n }\n .kata_svg_text {\n fill: var(--kata-svg-stroke);\n }\n .kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n }\n .kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n }\n .kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n }\n </style>\n <g clip-path=\"url(#clip0_4_498)\">\n <g clip-rule=\"evenodd\" fill-rule=\"evenodd\">\n <!-- Large circles -->\n <g class=\"kata_svg_path\">\n <path d=\"m7.1 146c0-76.8 62.3-139 139-139 76.8 0 139 62.3 139 139 0 76.8-62.3 139-139 139-76.8 0-139-62.3-139-139z\" stroke-miterlimit=\"8\" stroke-width=\"1.38\" />\n <path d=\"m358 146c0-76.8 62.2-139 139-139s139 62.3 139 139c0 76.8-62.2 139-139 139s-139-62.3-139-139z\" stroke-miterlimit=\"8\" stroke-width=\"1.38\" />\n </g>\n <!-- Normal points -->\n <g class=\"kata_svg_point\">\n <path d=\"m140 7.4c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n <path d=\"m1.3 147c0-3.26 2.64-5.9 5.9-5.9 3.26 0 5.9 2.64 5.9 5.9s-2.64 5.9-5.9 5.9c-3.26 0-5.9-2.64-5.9-5.9z\" />\n <path d=\"m140 286c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n <path d=\"m240 243c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m40.3 50.2c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9c0 3.26-2.69 5.9-6 5.9s-6-2.64-6-5.9z\" />\n <path d=\"m40.3 243c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m491 7.4c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m352 147c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m491 286c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m591 243c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n <path d=\"m391 50.2c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9c0 3.26-2.64 5.9-5.9 5.9s-5.9-2.64-5.9-5.9z\" />\n <path d=\"m391 243c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n </g>\n <!-- Arrows -->\n <g class=\"kata_svg_fill_accent\" >\n <path d=\"m291 146h16.5l-0.688 0.688v-96.5l0.688 0.687h-54.6v-1.38h55.3v97.9h-17.2v-1.38zm-33-90.7-6.13-5.11 6.13-5.11c0.292-0.243 0.726-0.204 0.968 0.088 0.244 0.292 0.204 0.725-0.088 0.968l-5.5 4.58v-1.06l5.5 4.58c0.292 0.243 0.332 0.677 0.088 0.968-0.242 0.292-0.676 0.331-0.968 0.088z\" />\n <path d=\"m642 146h16.5l-0.688 0.688v-96.5l0.688 0.687h-54.6v-1.38h55.3v97.9h-17.2v-1.38zm-33-90.7-6.13-5.11 6.13-5.11c0.292-0.243 0.726-0.204 0.968 0.088 0.244 0.292 0.204 0.725-0.088 0.968l-5.5 4.58v-1.06l5.5 4.58c0.292 0.243 0.332 0.677 0.088 0.968-0.242 0.292-0.676 0.331-0.968 0.088z\" />\n </g>\n <!-- From points -->\n <g class=\"kata_svg_point kata_svg_stroke_accent\">\n <path d=\"m279 147c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m630 147c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n </g>\n <!-- Target points -->\n <g class=\"kata_svg_fill_accent\">\n <path d=\"m240 50.1c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9c0 3.26-2.69 5.9-6 5.9s-6-2.64-6-5.9z\" />\n <path d=\"m591 50.1c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9c0 3.26-2.64 5.9-5.9 5.9s-5.9-2.64-5.9-5.9z\" />\n </g>\n </g>\n <g class=\"kata_svg_text\" clip-rule=\"evenodd\" fill-rule=\"evenodd\">\n <!-- Legend text -->\n <path d=\"m120 319c-0.941 0.455-2.17 0.683-3.68 0.683-1.98 0-3.53-0.581-4.66-1.74s-1.7-2.71-1.7-4.64c0-2.06 0.635-3.73 1.9-5.01 1.28-1.28 2.93-1.92 4.96-1.92 1.26 0 2.32 0.159 3.18 0.476v2.79c-0.863-0.515-1.84-0.773-2.95-0.773-1.21 0-2.19 0.381-2.93 1.14-0.743 0.761-1.11 1.79-1.11 3.09 0 1.25 0.35 2.24 1.05 2.98 0.701 0.737 1.64 1.1 2.83 1.1 1.13 0 2.17-0.276 3.11-0.827v2.65zm6.35 0.683c-1.53 0-2.74-0.429-3.62-1.28-0.875-0.863-1.31-2.03-1.31-3.5 0-1.52 0.455-2.71 1.37-3.57 0.91-0.862 2.14-1.29 3.69-1.29 1.53 0 2.73 0.432 3.59 1.29 0.869 0.857 1.3 1.99 1.3 3.4 0 1.53-0.449 2.73-1.35 3.62-0.892 0.886-2.12 1.33-3.67 1.33zm0.071-7.48c-0.67 0-1.19 0.23-1.56 0.691-0.371 0.462-0.557 1.11-0.557 1.96 0 1.77 0.713 2.65 2.14 2.65 1.36 0 2.04-0.907 2.04-2.72 0-1.72-0.686-2.58-2.06-2.58zm15.7 7.25h-2.83v-5.11c0-1.43-0.509-2.14-1.53-2.14-0.491 0-0.896 0.188-1.21 0.566-0.318 0.377-0.476 0.856-0.476 1.44v5.25h-2.84v-9.2h2.84v1.46h0.036c0.676-1.12 1.66-1.68 2.96-1.68 2.04 0 3.05 1.26 3.05 3.79v5.63zm1.65-0.243v-2.3c0.468 0.282 0.932 0.492 1.39 0.629 0.467 0.138 0.907 0.207 1.32 0.207 0.503 0 0.898-0.069 1.19-0.207 0.293-0.137 0.44-0.347 0.44-0.629 0-0.179-0.066-0.329-0.198-0.449s-0.302-0.224-0.512-0.314c-0.204-0.09-0.428-0.171-0.674-0.243-0.245-0.072-0.482-0.153-0.71-0.242-0.365-0.138-0.688-0.285-0.97-0.441-0.275-0.161-0.509-0.347-0.701-0.557-0.185-0.209-0.329-0.452-0.431-0.727-0.096-0.276-0.144-0.602-0.144-0.98 0-0.515 0.111-0.958 0.333-1.33 0.227-0.372 0.527-0.674 0.898-0.908 0.378-0.239 0.806-0.413 1.28-0.521 0.485-0.114 0.988-0.171 1.51-0.171 0.408 0 0.821 0.033 1.24 0.099 0.419 0.06 0.833 0.15 1.24 0.27v2.19c-0.359-0.21-0.746-0.365-1.16-0.467-0.407-0.108-0.809-0.162-1.2-0.162-0.186 0-0.362 0.018-0.53 0.054-0.162 0.03-0.305 0.078-0.431 0.144-0.126 0.06-0.225 0.14-0.297 0.242-0.072 0.096-0.107 0.207-0.107 0.333 0 0.167 0.053 0.311 0.161 0.431s0.249 0.225 0.422 0.314c0.174 0.084 0.366 0.162 0.575 0.234 0.216 0.066 0.429 0.135 0.638 0.207 0.378 0.131 0.719 0.275 1.02 0.431 0.305 0.156 0.566 0.338 0.781 0.548 0.222 0.21 0.39 0.455 0.503 0.737 0.12 0.281 0.18 0.617 0.18 1.01 0 0.545-0.12 1.01-0.359 1.4-0.234 0.384-0.548 0.698-0.944 0.944-0.389 0.239-0.841 0.413-1.36 0.521-0.509 0.114-1.04 0.171-1.59 0.171-1.01 0-1.95-0.156-2.81-0.468zm14.3 0.135c-0.42 0.222-1.05 0.333-1.9 0.333-2 0-3-1.04-3-3.12v-4.21h-1.49v-2.09h1.49v-1.99l2.83-0.808v2.79h2.07v2.09h-2.07v3.72c0 0.958 0.38 1.44 1.14 1.44 0.3 0 0.608-0.086 0.926-0.26v2.1zm9.26 0.108h-2.69v-1.32h-0.036c-0.617 1.03-1.53 1.55-2.74 1.55-0.893 0-1.6-0.252-2.11-0.755-0.51-0.509-0.764-1.19-0.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-0.333c0-1.01-0.545-1.51-1.64-1.51-1.1 0-2.14 0.326-3.13 0.979v-2.14c0.396-0.204 0.935-0.383 1.62-0.539 0.688-0.156 1.31-0.234 1.88-0.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-0.62l-1.67 0.215c-0.922 0.12-1.38 0.536-1.38 1.25 0 0.323 0.111 0.59 0.333 0.8 0.227 0.203 0.533 0.305 0.916 0.305 0.533 0 0.968-0.183 1.3-0.548 0.335-0.371 0.503-0.838 0.503-1.4zm13.8 3.74h-2.83v-5.11c0-1.43-0.509-2.14-1.53-2.14-0.492 0-0.896 0.188-1.21 0.566-0.318 0.377-0.476 0.856-0.476 1.44v5.25h-2.84v-9.2h2.84v1.46h0.036c0.676-1.12 1.66-1.68 2.96-1.68 2.04 0 3.06 1.26 3.06 3.79v5.63zm7.82-0.108c-0.419 0.222-1.05 0.333-1.9 0.333-2 0-3-1.04-3-3.12v-4.21h-1.49v-2.09h1.49v-1.99l2.83-0.808v2.79h2.07v2.09h-2.07v3.72c0 0.958 0.38 1.44 1.14 1.44 0.3 0 0.608-0.086 0.925-0.26v2.1z\" />\n <path d=\"m476 307-4.44 12.9h-3.29l-4.38-12.9h3.13l2.69 8.97c0.143 0.485 0.23 0.913 0.26 1.28h0.054c0.042-0.402 0.135-0.842 0.279-1.32l2.67-8.93h3.04zm7.54 12.9h-2.69v-1.32h-0.036c-0.617 1.03-1.53 1.55-2.74 1.55-0.892 0-1.6-0.252-2.11-0.755-0.509-0.509-0.764-1.19-0.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-0.333c0-1.01-0.545-1.51-1.64-1.51-1.1 0-2.14 0.326-3.13 0.979v-2.14c0.395-0.204 0.934-0.383 1.62-0.539 0.689-0.156 1.31-0.234 1.88-0.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-0.62l-1.67 0.215c-0.922 0.12-1.38 0.536-1.38 1.25 0 0.323 0.11 0.59 0.332 0.8 0.228 0.203 0.533 0.305 0.916 0.305 0.533 0 0.968-0.183 1.3-0.548 0.336-0.371 0.503-0.838 0.503-1.4zm10.9-2.9c-0.341-0.186-0.739-0.279-1.2-0.279-0.617 0-1.1 0.228-1.45 0.683-0.348 0.449-0.521 1.06-0.521 1.84v4.39h-2.84v-9.2h2.84v1.71h0.036c0.449-1.25 1.26-1.87 2.42-1.87 0.3 0 0.534 0.036 0.701 0.108v2.62zm2.84-4.02c-0.479 0-0.871-0.141-1.18-0.423-0.305-0.287-0.458-0.638-0.458-1.05 0-0.425 0.153-0.773 0.458-1.04 0.306-0.27 0.698-0.404 1.18-0.404 0.485 0 0.878 0.134 1.18 0.404 0.306 0.269 0.458 0.617 0.458 1.04 0 0.431-0.152 0.785-0.458 1.06-0.299 0.276-0.692 0.414-1.18 0.414zm1.4 10.7h-2.84v-9.2h2.84v9.2zm10 0h-2.69v-1.32h-0.036c-0.617 1.03-1.53 1.55-2.74 1.55-0.893 0-1.6-0.252-2.11-0.755-0.51-0.509-0.764-1.19-0.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-0.333c0-1.01-0.545-1.51-1.64-1.51-1.1 0-2.14 0.326-3.13 0.979v-2.14c0.396-0.204 0.935-0.383 1.62-0.539 0.688-0.156 1.31-0.234 1.88-0.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-0.62l-1.67 0.215c-0.922 0.12-1.38 0.536-1.38 1.25 0 0.323 0.111 0.59 0.333 0.8 0.227 0.203 0.533 0.305 0.916 0.305 0.533 0 0.968-0.183 1.3-0.548 0.335-0.371 0.503-0.838 0.503-1.4zm7.79 2.67h-0.036v1.07h-2.84v-13.6h2.84v5.8h0.036c0.7-1.07 1.7-1.61 2.99-1.61 1.19 0 2.1 0.408 2.74 1.22 0.64 0.815 0.961 1.93 0.961 3.34 0 1.53-0.374 2.76-1.12 3.69s-1.75 1.39-3 1.39c-1.13 0-1.99-0.432-2.57-1.29zm-0.081-3.88v0.943c0 0.593 0.17 1.08 0.512 1.47 0.341 0.39 0.778 0.584 1.31 0.584 0.647 0 1.15-0.248 1.5-0.745 0.359-0.503 0.539-1.21 0.539-2.13 0-0.76-0.165-1.35-0.494-1.78-0.324-0.431-0.788-0.646-1.39-0.646-0.569 0-1.04 0.212-1.42 0.638-0.372 0.425-0.557 0.979-0.557 1.66zm11.5 4.95h-2.84v-13.6h2.84v13.6zm10.7-3.79h-6c0.095 1.34 0.937 2 2.52 2 1.01 0 1.9-0.239 2.67-0.719v2.05c-0.851 0.455-1.96 0.683-3.32 0.683-1.48 0-2.64-0.411-3.46-1.23-0.82-0.827-1.23-1.98-1.23-3.45 0-1.53 0.443-2.74 1.33-3.63 0.887-0.892 1.98-1.34 3.27-1.34 1.34 0 2.38 0.399 3.11 1.2 0.737 0.797 1.1 1.88 1.1 3.24v1.2zm-2.63-1.74c0-1.32-0.533-1.98-1.6-1.98-0.456 0-0.851 0.189-1.19 0.566-0.33 0.377-0.53 0.848-0.602 1.41h3.39z\" />\n <!-- Ket text -->\n <path d=\"m242 141h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m250 142c-0.374 0-0.686 0.11-0.936 0.332-0.252 0.222-0.454 0.54-0.608 0.956-0.154 0.418-0.264 0.924-0.328 1.52-0.066 0.598-0.098 1.27-0.098 2.02 0 1.76 0.164 3.05 0.49 3.88 0.328 0.824 0.834 1.24 1.52 1.24 0.654 0 1.14-0.388 1.45-1.16 0.316-0.774 0.476-1.98 0.476-3.6 0-1.24-0.082-2.25-0.244-3.02s-0.388-1.32-0.676-1.66c-0.29-0.334-0.64-0.502-1.05-0.502zm0.04-0.688c1.18 0 2.06 0.456 2.64 1.37 0.578 0.912 0.868 2.29 0.868 4.14 0 1.91-0.31 3.36-0.928 4.34-0.62 0.98-1.52 1.47-2.71 1.47-1.17 0-2.04-0.458-2.61-1.38-0.57-0.918-0.854-2.31-0.854-4.18 0-0.994 0.088-1.85 0.262-2.58 0.176-0.724 0.422-1.32 0.738-1.79 0.316-0.474 0.696-0.824 1.14-1.05 0.442-0.228 0.926-0.34 1.45-0.34z\" />\n <path d=\"m256 140 3.23 7.28v0.6l-3.23 7.29-0.866-0.308 2.6-7.28-2.6-7.29 0.866-0.29z\" />\n <path d=\"m140 30.2h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m148 30.6h0.446c-0.033 0.519-0.049 1.24-0.049 2.16v6.92c0 0.313 0.018 0.55 0.053 0.709s0.097 0.289 0.186 0.389 0.218 0.178 0.385 0.235c0.168 0.0568 0.378 0.1 0.632 0.13 0.254 0.0296 0.589 0.05 1 0.0608v0.592h-5.99v-0.592c0.599-0.0272 1.03-0.0636 1.28-0.11 0.257-0.0458 0.453-0.115 0.588-0.207s0.234-0.222 0.296-0.389c0.062-0.168 0.093-0.44 0.093-0.819v-6.57c0-0.216-0.038-0.374-0.114-0.474-0.075-0.1-0.186-0.15-0.332-0.15-0.173 0-0.419 0.0892-0.737 0.268-0.319 0.178-0.714 0.424-1.18 0.738l-0.356-0.624 3.79-2.26z\" />\n <path d=\"m154 29.4 3.23 7.28v0.6l-3.23 7.29-0.867-0.308 2.6-7.28-2.6-7.29 0.867-0.292z\" />\n <path d=\"m208 73h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m217 74.6h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42v-4.67z\" />\n <path d=\"m226 72.3 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m208 206h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m213 212h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m226 205 3.23 7.28v0.598l-3.23 7.29-0.866-0.308 2.6-7.28-2.6-7.29 0.866-0.292z\" />\n <path d=\"m133 250h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m146 243h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m154 244h0.446c-0.033 0.518-0.049 1.24-0.049 2.16v6.92c0 0.312 0.018 0.55 0.053 0.708 0.035 0.16 0.097 0.29 0.186 0.39s0.218 0.178 0.385 0.234c0.168 0.058 0.378 0.1 0.632 0.13s0.59 0.05 1.01 0.062v0.59h-5.99v-0.59c0.599-0.028 1.03-0.064 1.28-0.11 0.257-0.046 0.453-0.114 0.588-0.206s0.234-0.222 0.296-0.39 0.093-0.44 0.093-0.818v-6.57c0-0.216-0.038-0.374-0.113-0.474-0.076-0.1-0.187-0.15-0.333-0.15-0.173 0-0.419 0.088-0.737 0.268-0.319 0.178-0.714 0.424-1.18 0.736l-0.356-0.624 3.79-2.26z\" />\n <path d=\"m160 243 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m28.4 147h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m41.6 141h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m49.5 142c-0.373 0-0.685 0.11-0.936 0.332s-0.454 0.54-0.608 0.956c-0.154 0.418-0.263 0.924-0.328 1.52-0.0648 0.598-0.0972 1.27-0.0972 2.02 0 1.76 0.163 3.05 0.49 3.88 0.327 0.824 0.833 1.24 1.52 1.24 0.654 0 1.14-0.388 1.45-1.16 0.316-0.774 0.474-1.98 0.474-3.6 0-1.24-0.081-2.25-0.243-3.02-0.162-0.77-0.388-1.32-0.677-1.66-0.289-0.334-0.639-0.502-1.05-0.502zm0.0406-0.688c1.18 0 2.06 0.456 2.64 1.37 0.578 0.912 0.867 2.29 0.867 4.14 0 1.91-0.309 3.36-0.928 4.34-0.619 0.98-1.52 1.47-2.71 1.47-1.17 0-2.04-0.458-2.61-1.38-0.57-0.918-0.855-2.31-0.855-4.18 0-0.994 0.0878-1.85 0.263-2.58s0.422-1.32 0.738-1.79c0.316-0.474 0.696-0.824 1.14-1.05 0.443-0.228 0.927-0.34 1.45-0.34z\" />\n <path d=\"m55.8 140 3.23 7.28v0.6l-3.23 7.29-0.867-0.308 2.6-7.28-2.6-7.29 0.867-0.29z\" />\n <path d=\"m57.9 212h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m71 206h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m79.9 207h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42v-4.67z\" />\n <path d=\"m88.4 205 3.23 7.28v0.6l-3.23 7.29-0.867-0.308 2.6-7.28-2.6-7.29 0.867-0.29z\" />\n <path d=\"m57.2 78.8h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m70.3 72.5h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m74.8 78.8h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m87.7 71.8 3.23 7.28v0.6l-3.23 7.29-0.867-0.308 2.6-7.28-2.6-7.29 0.867-0.292z\" />\n <path d=\"m592 141h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m600 142c-0.372 0-0.684 0.11-0.936 0.332-0.25 0.222-0.454 0.54-0.608 0.956-0.154 0.418-0.262 0.924-0.328 1.52-0.064 0.598-0.098 1.27-0.098 2.02 0 1.76 0.164 3.05 0.492 3.88 0.326 0.824 0.832 1.24 1.52 1.24 0.652 0 1.14-0.388 1.45-1.16 0.316-0.774 0.474-1.98 0.474-3.6 0-1.24-0.08-2.25-0.242-3.02-0.164-0.77-0.388-1.32-0.678-1.66-0.288-0.334-0.638-0.502-1.05-0.502zm0.042-0.688c1.18 0 2.06 0.456 2.64 1.37 0.578 0.912 0.866 2.29 0.866 4.14 0 1.91-0.308 3.36-0.928 4.34-0.618 0.98-1.52 1.47-2.71 1.47-1.17 0-2.04-0.458-2.61-1.38-0.57-0.918-0.856-2.31-0.856-4.18 0-0.994 0.088-1.85 0.264-2.58s0.422-1.32 0.738-1.79c0.316-0.474 0.696-0.824 1.14-1.05 0.444-0.228 0.926-0.34 1.45-0.34z\" />\n <path d=\"m606 140 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.29z\" />\n <path d=\"m489 30.2h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m498 30.6h0.446c-0.032 0.519-0.048 1.24-0.048 2.16v6.92c0 0.313 0.016 0.55 0.052 0.709 0.034 0.159 0.098 0.289 0.186 0.389 0.09 0.1 0.218 0.178 0.386 0.235 0.166 0.0568 0.378 0.1 0.632 0.13 0.254 0.0296 0.588 0.05 1 0.0608v0.592h-5.99v-0.592c0.6-0.0272 1.03-0.0636 1.29-0.11 0.256-0.0458 0.452-0.115 0.588-0.207 0.134-0.0918 0.232-0.222 0.294-0.389 0.064-0.168 0.094-0.44 0.094-0.819v-6.57c0-0.216-0.038-0.374-0.114-0.474s-0.186-0.15-0.332-0.15c-0.172 0-0.418 0.0892-0.738 0.268-0.318 0.178-0.712 0.424-1.18 0.738l-0.358-0.624 3.79-2.26z\" />\n <path d=\"m504 29.4 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m558 73h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m567 74.6h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42v-4.67z\" />\n <path d=\"m575 72.3 3.23 7.28v0.6l-3.23 7.29-0.866-0.308 2.6-7.28-2.6-7.29 0.866-0.292z\" />\n <path d=\"m558 206h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m563 212h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m575 205 3.23 7.28v0.598l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m483 250h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m496 243h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m504 244h0.446c-0.032 0.518-0.048 1.24-0.048 2.16v6.92c0 0.312 0.016 0.55 0.052 0.708 0.036 0.16 0.098 0.29 0.186 0.39 0.09 0.1 0.218 0.178 0.386 0.234 0.166 0.058 0.378 0.1 0.632 0.13s0.588 0.05 1 0.062v0.59h-5.99v-0.59c0.6-0.028 1.03-0.064 1.29-0.11 0.256-0.046 0.452-0.114 0.588-0.206 0.134-0.092 0.232-0.222 0.294-0.39 0.064-0.168 0.094-0.44 0.094-0.818v-6.57c0-0.216-0.038-0.374-0.114-0.474-0.074-0.1-0.186-0.15-0.332-0.15-0.172 0-0.418 0.088-0.738 0.268-0.318 0.178-0.712 0.424-1.18 0.736l-0.358-0.624 3.79-2.26z\" />\n <path d=\"m510 243 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m378 147h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m391 141h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m399 142c-0.372 0-0.684 0.11-0.936 0.332s-0.454 0.54-0.608 0.956c-0.154 0.418-0.264 0.924-0.328 1.52-0.064 0.598-0.098 1.27-0.098 2.02 0 1.76 0.164 3.05 0.492 3.88 0.326 0.824 0.832 1.24 1.52 1.24 0.654 0 1.14-0.388 1.46-1.16 0.316-0.774 0.474-1.98 0.474-3.6 0-1.24-0.082-2.25-0.244-3.02s-0.386-1.32-0.676-1.66c-0.29-0.334-0.638-0.502-1.05-0.502zm0.04-0.688c1.18 0 2.07 0.456 2.64 1.37 0.578 0.912 0.866 2.29 0.866 4.14 0 1.91-0.308 3.36-0.928 4.34-0.618 0.98-1.52 1.47-2.71 1.47-1.17 0-2.04-0.458-2.61-1.38-0.57-0.918-0.856-2.31-0.856-4.18 0-0.994 0.088-1.85 0.264-2.58s0.422-1.32 0.738-1.79c0.316-0.474 0.694-0.824 1.14-1.05 0.444-0.228 0.926-0.34 1.45-0.34z\" />\n <path d=\"m406 140 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.29z\" />\n <path d=\"m408 212h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m421 206h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m430 207h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42v-4.67z\" />\n <path d=\"m438 205 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.29z\" />\n <path d=\"m407 78.8h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m420 72.5h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m425 78.8h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m438 71.8 3.24 7.28v0.6l-3.24 7.29-0.866-0.308 2.6-7.28-2.6-7.29 0.866-0.292z\" />\n </g>\n </g>\n <defs>\n <clipPath id=\"clip0_4_498\">\n <rect transform=\"translate(.6 .8)\" width=\"659\" height=\"332\" />\n </clipPath>\n </defs>\n</svg>\n\n2. Apply the oracle. \n Here, the difference between the two scenarios becomes noticeable. In the constant scenario, $\\ket{0}$ and $\\ket{1}$ states get the same phase (either $1$ or $-1$), so the state remains the same or acquires a global phase of $-1$, which is physically the same state. In the variable scenario, zero and one states get different phases, so the state changes!\n <br/>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"738\" height=\"374\" fill=\"none\" version=\"1.1\" viewBox=\"0 0 738 374\" xmlns=\"http://www.w3.org/2000/svg\">\n <style>\n :root {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n }\n @media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n }\n .kata_svg_path {\n stroke: var(--kata-svg-path);\n }\n .kata_svg_text {\n fill: var(--kata-svg-stroke);\n }\n .kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n }\n .kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n }\n .kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n }\n </style>\n <g clip-path=\"url(#clip0_5_635)\">\n <!-- Large circles -->\n <g class=\"kata_svg_path\">\n <path d=\"m7.3 189c0-76.8 62.3-139 139-139 76.8 0 139 62.3 139 139 0 76.8-62.3 139-139 139-76.8 0-139-62.3-139-139z\" />\n <path d=\"m358 189c0-76.8 62.2-139 139-139s139 62.3 139 139c0 76.8-62.2 139-139 139s-139-62.3-139-139z\" />\n </g>\n <!-- Normal points -->\n <g class=\"kata_svg_point\">\n <path d=\"m392 285c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n <path d=\"m630 189c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m491 49.4c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9c0 3.26-2.69 5.9-6 5.9s-6-2.64-6-5.9z\" />\n <path d=\"m352 189c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n <path d=\"m491 328c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m240 285c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m40.5 92.4c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m279 189c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m140 49.4c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9c0 3.26-2.64 5.9-5.9 5.9s-5.9-2.64-5.9-5.9z\" />\n <path d=\"m1.3 189c0-3.26 2.69-5.9 6-5.9 3.31 0 6 2.64 6 5.9s-2.69 5.9-6 5.9c-3.31 0-6-2.64-6-5.9z\" />\n <path d=\"m140 328c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n </g>\n <!-- From points -->\n <g class=\"kata_svg_point kata_svg_stroke_accent\" >\n <path d=\"m591 92.4c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n </g>\n <g class=\"kata_svg_fill_accent\">\n <path d=\"m240 92.3c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9c0 3.26-2.69 5.9-6 5.9s-6-2.64-6-5.9z\" />\n <path d=\"m40.4 285c0-3.26 2.69-5.9 6-5.9 3.31 0 6 2.64 6 5.9s-2.69 5.9-6 5.9c-3.31 0-6-2.64-6-5.9z\" />\n <path d=\"m591 285c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n <path d=\"m391 92.3c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9c0 3.26-2.64 5.9-5.9 5.9s-5.9-2.64-5.9-5.9z\" />\n </g>\n <!-- Arrows -->\n <g class=\"kata_svg_fill_accent\" >\n <path d=\"m247 85.4v-15.1l-0.688 0.688h22.1l-0.687-0.688v22.1l0.687-0.688h-16.2v1.38h16.9v-23.5h-23.5v15.8h1.38zm-5.8-5.06 5.11 6.13 5.11-6.13c0.244-0.292 0.204-0.725-0.088-0.968-0.291-0.243-0.725-0.204-0.968 0.088l-4.58 5.5h1.06l-4.58-5.5c-0.243-0.292-0.677-0.331-0.968-0.088-0.292 0.243-0.332 0.677-0.088 0.968z\" />\n <path d=\"m199 136-105 102 0.96 0.985 105-102-0.96-0.984zm-104 95.6-0.826 7.94 7.96-0.619c0.378-0.03 0.661-0.361 0.632-0.739-0.03-0.379-0.36-0.662-0.739-0.632l-7.14 0.555 0.737 0.757 0.741-7.12c0.0392-0.378-0.235-0.716-0.613-0.755-0.378-0.04-0.716 0.235-0.755 0.612z\" />\n <path d=\"m603 91.6h58.4v194h-56.4v-1.37h55.8l-0.688 0.686v-193l0.688 0.688h-57.8v-1.38zm7.05 199-6.13-5.11 6.13-5.11c0.29-0.244 0.724-0.204 0.968 0.088 0.242 0.29 0.204 0.724-0.088 0.968l-5.5 4.58v-1.06l5.5 4.58c0.292 0.242 0.33 0.676 0.088 0.968-0.244 0.292-0.678 0.332-0.968 0.088z\" />\n <path d=\"m397 85.7v-56.4h201v56.6h-1.37v-55.9l0.686 0.688h-200l0.688-0.688v55.7h-1.38zm5.8-5.06-5.11 6.13-5.11-6.13c-0.242-0.292-0.204-0.725 0.088-0.968 0.292-0.243 0.726-0.204 0.968 0.0882l4.58 5.5h-1.06l4.58-5.5c0.242-0.292 0.676-0.331 0.968-0.0882 0.292 0.243 0.33 0.677 0.088 0.968z\" />\n </g>\n <!-- Equation text -->\n <g class=\"kata_svg_fill_accent\" clip-rule=\"evenodd\" fill-rule=\"evenodd\">\n <path d=\"m231 48.1c0.516 0 0.962 0.0422 1.34 0.126l-0.308 1.34h-0.696c-0.074-0.301-0.17-0.517-0.288-0.649-0.12-0.132-0.294-0.198-0.526-0.198-0.302 0-0.556 0.083-0.764 0.249s-0.386 0.413-0.534 0.74-0.284 0.767-0.412 1.32l-0.196 0.862h2.03l-0.174 0.799h-2.04l-1.47 6.9c-0.242 1.14-0.614 2-1.12 2.56-0.5 0.562-1.13 0.842-1.89 0.842-0.222 0-0.396-0.0132-0.522-0.0396l0.134-0.696c0.054 0.0158 0.178 0.0236 0.372 0.0236 0.238 0 0.44-0.0606 0.61-0.182 0.168-0.121 0.324-0.332 0.47-0.633 0.144-0.3 0.278-0.717 0.4-1.25l1.7-7.52h-1.34l0.118-0.546c0.354-0.0212 0.608-0.0502 0.764-0.087 0.154-0.037 0.276-0.0924 0.364-0.166 0.086-0.0738 0.16-0.17 0.22-0.289 0.062-0.119 0.138-0.336 0.234-0.653 0.28-0.949 0.71-1.66 1.29-2.14 0.582-0.477 1.32-0.716 2.23-0.716z\" />\n <path d=\"m250 47.3c1.54 0.406 2.72 1.28 3.55 2.63 0.826 1.35 1.24 2.97 1.24 4.88 0 1.91-0.41 3.53-1.23 4.88-0.822 1.34-2.01 2.22-3.55 2.62l-0.19-0.609c1.22-0.406 2.12-1.21 2.72-2.4 0.594-1.2 0.89-2.72 0.89-4.56 0-1.78-0.296-3.26-0.886-4.44s-1.51-1.97-2.74-2.38l0.214-0.609zm-10.1 0 0.214 0.609c-1.23 0.406-2.15 1.2-2.74 2.38-0.592 1.18-0.89 2.66-0.89 4.44 0 1.85 0.298 3.37 0.89 4.56 0.594 1.2 1.5 2 2.72 2.4l-0.19 0.609c-1.55-0.406-2.73-1.28-3.55-2.62-0.822-1.34-1.23-2.97-1.23-4.88 0-1.9 0.412-3.53 1.24-4.88s2.01-2.22 3.55-2.63z\" />\n <path d=\"m243 51.7c0.162 0 0.306 0.0184 0.43 0.0554 0.124 0.0368 0.234 0.0936 0.328 0.17 0.096 0.0764 0.18 0.175 0.254 0.297s0.144 0.286 0.214 0.494c0.068 0.208 0.132 0.467 0.194 0.775 0.06 0.308 0.114 0.629 0.162 0.961h0.078c0.506-0.712 0.89-1.23 1.15-1.56 0.26-0.33 0.48-0.575 0.66-0.736s0.352-0.274 0.518-0.34c0.166-0.0658 0.386-0.0988 0.66-0.0988 0.248 0 0.452 0.0316 0.61 0.0948l-0.316 1.43h-0.554c-0.032-0.221-0.124-0.332-0.278-0.332-0.046 0-0.098 0.0078-0.15 0.0238-0.052 0.0158-0.118 0.05-0.194 0.103-0.076 0.0526-0.188 0.156-0.336 0.308-0.148 0.153-0.314 0.34-0.498 0.562-0.184 0.222-0.374 0.454-0.57 0.696l-0.538 0.672c0.096 0.506 0.186 0.944 0.27 1.31s0.158 0.676 0.224 0.922 0.124 0.439 0.174 0.581c0.052 0.142 0.106 0.249 0.164 0.32 0.058 0.0712 0.116 0.121 0.178 0.15 0.06 0.029 0.13 0.0434 0.208 0.0434 0.144 0 0.282-0.0552 0.416-0.166s0.328-0.361 0.582-0.751l0.514 0.34c-0.37 0.548-0.704 0.935-1 1.16-0.298 0.224-0.652 0.336-1.06 0.336-0.226 0-0.418-0.0408-0.576-0.123-0.158-0.0816-0.296-0.212-0.412-0.391-0.116-0.179-0.218-0.459-0.308-0.839-0.164-0.675-0.264-1.19-0.3-1.55h-0.08c-0.558 0.786-0.974 1.35-1.25 1.69s-0.496 0.596-0.672 0.759-0.348 0.278-0.514 0.344c-0.166 0.066-0.386 0.099-0.66 0.099-0.248 0-0.452-0.0316-0.61-0.095l0.316-1.43h0.554c0.032 0.221 0.124 0.332 0.278 0.332 0.072 0 0.15-0.0198 0.232-0.0594s0.2-0.134 0.352-0.285c0.154-0.15 0.364-0.386 0.634-0.708 0.268-0.322 0.658-0.804 1.17-1.45-0.08-0.417-0.16-0.817-0.246-1.2-0.084-0.385-0.17-0.744-0.26-1.08s-0.164-0.55-0.222-0.653-0.12-0.174-0.186-0.214-0.148-0.0592-0.248-0.0592c-0.112 0-0.212 0.025-0.302 0.075-0.09 0.0502-0.186 0.137-0.292 0.261-0.106 0.124-0.246 0.318-0.42 0.581l-0.514-0.34c0.332-0.501 0.652-0.875 0.958-1.12 0.306-0.248 0.666-0.372 1.08-0.372z\" />\n <path d=\"m262 55.9h9.75v1.05h-9.75v-1.05zm0-3.28h9.75v1.05h-9.75v-1.05z\" />\n <path d=\"m281 49.2c-0.364 0-0.668 0.108-0.914 0.324-0.244 0.216-0.442 0.527-0.592 0.933-0.15 0.406-0.258 0.901-0.32 1.48-0.064 0.583-0.096 1.24-0.096 1.97 0 1.72 0.16 2.98 0.478 3.78 0.32 0.804 0.814 1.21 1.48 1.21 0.638 0 1.11-0.378 1.42-1.14s0.462-1.93 0.462-3.52c0-1.21-0.078-2.2-0.236-2.95-0.16-0.751-0.38-1.29-0.662-1.62s-0.622-0.49-1.02-0.49zm0.04-0.672c1.15 0 2.01 0.446 2.58 1.34s0.846 2.24 0.846 4.04c0 1.87-0.3 3.28-0.904 4.24s-1.49 1.44-2.65 1.44c-1.14 0-1.99-0.448-2.54-1.34-0.556-0.897-0.834-2.26-0.834-4.08 0-0.97 0.086-1.81 0.256-2.52 0.172-0.707 0.412-1.29 0.72-1.75 0.31-0.461 0.68-0.803 1.11-1.02s0.904-0.332 1.42-0.332z\" />\n <path d=\"m94.3 164c0.53 0 0.986 0.043 1.37 0.13l-0.316 1.38h-0.713c-0.0756-0.308-0.174-0.53-0.296-0.665s-0.301-0.203-0.539-0.203c-0.308 0-0.569 0.085-0.782 0.256-0.213 0.17-0.396 0.422-0.547 0.758-0.151 0.334-0.292 0.786-0.422 1.35l-0.203 0.882h2.08l-0.178 0.82h-2.09l-1.51 7.07c-0.249 1.17-0.63 2.05-1.14 2.62-0.513 0.574-1.16 0.862-1.94 0.862-0.227 0-0.405-0.012-0.535-0.04l0.138-0.714c0.054 0.016 0.181 0.026 0.381 0.026 0.243 0 0.451-0.064 0.624-0.188s0.334-0.34 0.482-0.648 0.285-0.734 0.409-1.28l1.74-7.71h-1.37l0.122-0.56c0.362-0.022 0.623-0.052 0.782-0.09s0.284-0.094 0.373-0.17c0.0892-0.076 0.165-0.174 0.227-0.296 0.0622-0.12 0.142-0.344 0.239-0.668 0.286-0.972 0.728-1.7 1.33-2.19 0.597-0.489 1.36-0.734 2.28-0.734z\" />\n <path d=\"m113 163c1.58 0.416 2.79 1.31 3.64 2.7 0.846 1.38 1.27 3.05 1.27 5 0 1.96-0.422 3.62-1.26 5-0.843 1.37-2.06 2.27-3.64 2.69l-0.195-0.624c1.25-0.416 2.18-1.24 2.78-2.46 0.608-1.23 0.911-2.79 0.911-4.68 0-1.83-0.302-3.34-0.907-4.55-0.606-1.21-1.54-2.02-2.81-2.44l0.219-0.624zm-10.3 0 0.219 0.624c-1.26 0.416-2.2 1.23-2.81 2.44-0.608 1.21-0.912 2.73-0.912 4.55 0 1.89 0.304 3.45 0.912 4.68 0.608 1.23 1.54 2.05 2.78 2.46l-0.194 0.624c-1.58-0.416-2.8-1.31-3.64-2.69-0.843-1.38-1.26-3.04-1.26-5 0-1.95 0.423-3.62 1.27-5 0.846-1.38 2.06-2.28 3.64-2.7z\" />\n <path d=\"m106 168c0.168 0 0.315 0.02 0.442 0.058s0.239 0.096 0.336 0.174c0.098 0.078 0.184 0.18 0.26 0.304 0.075 0.124 0.148 0.292 0.219 0.506 0.07 0.214 0.136 0.478 0.198 0.794s0.118 0.646 0.166 0.986h0.081c0.519-0.73 0.912-1.26 1.18-1.6 0.267-0.338 0.493-0.588 0.677-0.754 0.183-0.164 0.36-0.28 0.53-0.348 0.171-0.068 0.396-0.1 0.677-0.1 0.254 0 0.462 0.032 0.624 0.096l-0.324 1.47h-0.567c-0.033-0.228-0.127-0.342-0.284-0.342-0.049 0-0.1 0.01-0.154 0.026s-0.12 0.05-0.199 0.104c-0.078 0.054-0.193 0.16-0.344 0.316-0.151 0.158-0.322 0.35-0.511 0.576-0.189 0.228-0.383 0.464-0.583 0.714l-0.551 0.688c0.097 0.52 0.189 0.968 0.275 1.35 0.087 0.378 0.164 0.694 0.231 0.944 0.068 0.252 0.127 0.45 0.178 0.596 0.052 0.146 0.107 0.256 0.167 0.328 0.059 0.074 0.12 0.124 0.182 0.154s0.134 0.044 0.215 0.044c0.146 0 0.288-0.056 0.425-0.17 0.138-0.112 0.337-0.37 0.596-0.77l0.527 0.35c-0.378 0.562-0.72 0.956-1.02 1.19-0.306 0.23-0.669 0.346-1.09 0.346-0.232 0-0.429-0.042-0.591-0.126s-0.303-0.218-0.422-0.402-0.224-0.47-0.316-0.858c-0.167-0.692-0.27-1.22-0.308-1.59h-0.081c-0.573 0.806-0.998 1.38-1.28 1.73-0.278 0.352-0.507 0.612-0.689 0.78-0.181 0.166-0.356 0.284-0.526 0.352-0.171 0.068-0.396 0.102-0.677 0.102-0.254 0-0.462-0.034-0.624-0.098l0.324-1.47h0.567c0.033 0.228 0.127 0.342 0.284 0.342 0.076 0 0.155-0.022 0.239-0.062s0.204-0.138 0.361-0.292 0.373-0.396 0.648-0.724c0.276-0.33 0.676-0.824 1.2-1.48-0.081-0.428-0.165-0.838-0.251-1.23-0.087-0.394-0.176-0.762-0.268-1.1-0.092-0.342-0.167-0.564-0.227-0.67-0.059-0.104-0.123-0.178-0.19-0.218-0.068-0.04-0.153-0.06-0.256-0.06-0.113 0-0.216 0.024-0.308 0.076s-0.191 0.14-0.3 0.268c-0.108 0.126-0.251 0.326-0.429 0.596l-0.527-0.35c0.34-0.512 0.667-0.896 0.981-1.15 0.313-0.254 0.683-0.382 1.11-0.382z\" />\n <path d=\"m125 172h9.99v1.08h-9.99v-1.08zm0-3.36h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m146 164h0.446c-0.032 0.519-0.048 1.24-0.048 2.16v6.92c0 0.314 0.018 0.55 0.052 0.71 0.036 0.158 0.098 0.288 0.186 0.388 0.09 0.1 0.218 0.178 0.386 0.236 0.168 0.056 0.378 0.1 0.632 0.128 0.254 0.03 0.588 0.05 1 0.062v0.592h-5.99v-0.592c0.6-0.028 1.03-0.064 1.29-0.11s0.452-0.114 0.588-0.206c0.134-0.092 0.234-0.222 0.296-0.39 0.062-0.166 0.092-0.44 0.092-0.818v-6.57c0-0.216-0.038-0.374-0.114-0.474-0.074-0.1-0.186-0.15-0.332-0.15-0.172 0-0.418 0.09-0.736 0.268-0.32 0.178-0.714 0.424-1.18 0.738l-0.358-0.624 3.79-2.26z\" />\n <path d=\"m676 183c0.516 0 0.962 0.044 1.34 0.128l-0.308 1.34h-0.696c-0.074-0.3-0.17-0.516-0.288-0.648-0.12-0.132-0.294-0.198-0.528-0.198-0.3 0-0.554 0.082-0.762 0.248-0.208 0.168-0.386 0.414-0.534 0.74-0.148 0.328-0.286 0.768-0.412 1.32l-0.198 0.862h2.03l-0.174 0.798h-2.04l-1.47 6.9c-0.244 1.14-0.614 2-1.12 2.56-0.5 0.56-1.13 0.842-1.89 0.842-0.222 0-0.396-0.014-0.522-0.04l0.134-0.696c0.052 0.016 0.176 0.024 0.372 0.024 0.238 0 0.44-0.06 0.608-0.182 0.17-0.122 0.326-0.332 0.472-0.632 0.144-0.302 0.278-0.718 0.398-1.25l1.7-7.52h-1.34l0.12-0.546c0.352-0.02 0.608-0.05 0.762-0.086 0.156-0.038 0.278-0.092 0.364-0.166 0.088-0.074 0.162-0.17 0.222-0.288 0.06-0.12 0.138-0.338 0.234-0.654 0.278-0.948 0.71-1.66 1.29-2.14 0.584-0.476 1.33-0.716 2.23-0.716z\" />\n <path d=\"m694 182c1.54 0.406 2.72 1.28 3.55 2.63 0.826 1.35 1.24 2.97 1.24 4.88 0 1.91-0.412 3.53-1.23 4.88s-2.01 2.22-3.55 2.62l-0.19-0.608c1.22-0.406 2.12-1.21 2.72-2.41 0.594-1.2 0.89-2.72 0.89-4.56 0-1.78-0.296-3.26-0.886-4.44-0.59-1.18-1.51-1.97-2.74-2.38l0.212-0.608zm-10.1 0 0.212 0.608c-1.23 0.406-2.15 1.2-2.74 2.38-0.594 1.18-0.89 2.66-0.89 4.44 0 1.85 0.296 3.37 0.89 4.56 0.594 1.2 1.5 2 2.72 2.41l-0.19 0.608c-1.55-0.406-2.73-1.28-3.55-2.62-0.824-1.34-1.23-2.97-1.23-4.88 0-1.9 0.412-3.53 1.24-4.88 0.824-1.35 2.01-2.22 3.55-2.63z\" />\n <path d=\"m688 187c0.164 0 0.308 0.018 0.432 0.054 0.124 0.038 0.234 0.094 0.328 0.17 0.096 0.078 0.18 0.176 0.254 0.298 0.074 0.12 0.144 0.286 0.212 0.494 0.07 0.208 0.134 0.466 0.194 0.774 0.062 0.31 0.116 0.63 0.162 0.962h0.08c0.506-0.712 0.89-1.23 1.15-1.56 0.262-0.33 0.482-0.576 0.662-0.736 0.178-0.16 0.352-0.274 0.518-0.34s0.386-0.098 0.66-0.098c0.248 0 0.45 0.03 0.61 0.094l-0.318 1.43h-0.554c-0.03-0.222-0.122-0.332-0.276-0.332-0.048 0-0.098 8e-3 -0.15 0.024s-0.118 0.05-0.194 0.102-0.188 0.156-0.336 0.308c-0.148 0.154-0.314 0.34-0.498 0.562-0.186 0.222-0.374 0.454-0.57 0.696l-0.538 0.672c0.094 0.506 0.184 0.944 0.27 1.31 0.084 0.368 0.158 0.676 0.224 0.922 0.066 0.244 0.124 0.438 0.174 0.58 0.05 0.144 0.104 0.25 0.162 0.322 0.058 0.07 0.118 0.12 0.178 0.15 0.062 0.028 0.132 0.042 0.21 0.042 0.142 0 0.282-0.054 0.416-0.166 0.134-0.11 0.328-0.36 0.58-0.75l0.516 0.34c-0.37 0.548-0.704 0.934-1 1.16s-0.652 0.336-1.06 0.336c-0.226 0-0.418-0.04-0.576-0.122-0.16-0.082-0.296-0.212-0.412-0.392s-0.22-0.458-0.308-0.838c-0.164-0.676-0.264-1.19-0.302-1.55h-0.078c-0.56 0.786-0.974 1.35-1.25 1.69s-0.496 0.596-0.672 0.76c-0.178 0.164-0.348 0.278-0.514 0.344s-0.388 0.098-0.662 0.098c-0.248 0-0.45-0.032-0.608-0.094l0.316-1.43h0.554c0.032 0.222 0.124 0.332 0.276 0.332 0.074 0 0.152-0.02 0.234-0.06 0.082-0.038 0.2-0.134 0.352-0.284s0.364-0.386 0.632-0.708c0.27-0.322 0.66-0.804 1.17-1.45-0.08-0.416-0.162-0.816-0.246-1.2-0.084-0.384-0.172-0.744-0.26-1.08-0.09-0.332-0.164-0.55-0.222-0.652-0.058-0.104-0.12-0.174-0.186-0.214s-0.15-0.06-0.25-0.06c-0.11 0-0.21 0.026-0.3 0.076s-0.188 0.138-0.292 0.262c-0.106 0.122-0.246 0.316-0.42 0.58l-0.514-0.34c0.332-0.5 0.652-0.876 0.958-1.12 0.304-0.248 0.666-0.372 1.08-0.372z\" />\n <path d=\"m706 191h9.75v1.05h-9.75v-1.05zm0-3.28h9.75v1.05h-9.75v-1.05z\" />\n <path d=\"m725 187c0.162 0 0.306 0.018 0.43 0.054 0.124 0.038 0.234 0.094 0.328 0.17 0.096 0.078 0.18 0.176 0.254 0.298 0.074 0.12 0.144 0.286 0.214 0.494 0.068 0.208 0.132 0.466 0.194 0.774 0.06 0.31 0.114 0.63 0.162 0.962h0.078c0.506-0.712 0.89-1.23 1.15-1.56 0.26-0.33 0.48-0.576 0.66-0.736s0.352-0.274 0.518-0.34 0.386-0.098 0.66-0.098c0.248 0 0.452 0.03 0.61 0.094l-0.316 1.43h-0.554c-0.032-0.222-0.124-0.332-0.278-0.332-0.046 0-0.096 8e-3 -0.15 0.024-0.052 0.016-0.118 0.05-0.194 0.102s-0.188 0.156-0.336 0.308c-0.148 0.154-0.314 0.34-0.498 0.562s-0.374 0.454-0.57 0.696l-0.538 0.672c0.096 0.506 0.186 0.944 0.27 1.31 0.084 0.368 0.16 0.676 0.224 0.922 0.066 0.244 0.124 0.438 0.174 0.58 0.052 0.144 0.106 0.25 0.164 0.322 0.058 0.07 0.116 0.12 0.178 0.15 0.06 0.028 0.13 0.042 0.208 0.042 0.144 0 0.282-0.054 0.416-0.166 0.134-0.11 0.328-0.36 0.582-0.75l0.514 0.34c-0.37 0.548-0.704 0.934-1 1.16s-0.652 0.336-1.06 0.336c-0.228 0-0.42-0.04-0.578-0.122s-0.296-0.212-0.412-0.392-0.218-0.458-0.308-0.838c-0.164-0.676-0.264-1.19-0.3-1.55h-0.08c-0.558 0.786-0.974 1.35-1.25 1.69s-0.496 0.596-0.672 0.76-0.348 0.278-0.514 0.344-0.386 0.098-0.66 0.098c-0.248 0-0.452-0.032-0.61-0.094l0.316-1.43h0.554c0.032 0.222 0.124 0.332 0.278 0.332 0.072 0 0.15-0.02 0.232-0.06 0.082-0.038 0.2-0.134 0.352-0.284 0.154-0.15 0.364-0.386 0.634-0.708 0.268-0.322 0.658-0.804 1.17-1.45-0.08-0.416-0.16-0.816-0.246-1.2-0.084-0.384-0.17-0.744-0.26-1.08s-0.164-0.55-0.222-0.652c-0.058-0.104-0.12-0.174-0.186-0.214s-0.148-0.06-0.248-0.06c-0.112 0-0.212 0.026-0.302 0.076s-0.186 0.138-0.292 0.262c-0.106 0.122-0.246 0.316-0.42 0.58l-0.514-0.34c0.332-0.5 0.652-0.876 0.958-1.12 0.306-0.248 0.666-0.372 1.08-0.372z\" />\n <path d=\"m463 7.88c0.516 0 0.962 0.0422 1.34 0.127l-0.308 1.34h-0.696c-0.074-0.301-0.17-0.517-0.288-0.649-0.12-0.132-0.294-0.198-0.526-0.198-0.302 0-0.556 0.083-0.764 0.249-0.208 0.166-0.386 0.413-0.534 0.74-0.148 0.327-0.284 0.767-0.412 1.32l-0.198 0.862h2.03l-0.174 0.799h-2.04l-1.47 6.9c-0.244 1.14-0.614 2-1.12 2.56-0.5 0.562-1.13 0.842-1.89 0.842-0.222 0-0.396-0.0132-0.522-0.0394l0.134-0.696c0.052 0.0158 0.176 0.0238 0.372 0.0238 0.238 0 0.44-0.0606 0.608-0.182 0.17-0.121 0.326-0.332 0.472-0.633 0.144-0.301 0.278-0.717 0.4-1.25l1.7-7.52h-1.34l0.12-0.546c0.352-0.021 0.608-0.05 0.762-0.087 0.156-0.0368 0.278-0.0922 0.364-0.166 0.088-0.074 0.162-0.17 0.222-0.289s0.138-0.336 0.234-0.653c0.28-0.949 0.71-1.66 1.29-2.14 0.584-0.477 1.33-0.716 2.23-0.716z\" />\n <path d=\"m482 7.11c1.54 0.406 2.72 1.28 3.55 2.63 0.826 1.35 1.24 2.97 1.24 4.88 0 1.91-0.41 3.53-1.23 4.88-0.822 1.34-2.01 2.22-3.55 2.62l-0.19-0.609c1.22-0.406 2.12-1.21 2.72-2.4s0.89-2.72 0.89-4.56c0-1.78-0.296-3.26-0.886-4.44-0.59-1.18-1.51-1.97-2.74-2.38l0.212-0.609zm-10.1 0 0.212 0.609c-1.23 0.406-2.15 1.2-2.74 2.38-0.594 1.18-0.89 2.66-0.89 4.44 0 1.85 0.296 3.37 0.89 4.56s1.5 2 2.72 2.4l-0.19 0.609c-1.55-0.406-2.73-1.28-3.55-2.62-0.824-1.34-1.23-2.97-1.23-4.88 0-1.9 0.412-3.53 1.24-4.88 0.824-1.35 2.01-2.22 3.55-2.63z\" />\n <path d=\"m475 11.5c0.164 0 0.308 0.0184 0.432 0.0554s0.234 0.0936 0.328 0.17c0.096 0.0766 0.18 0.175 0.254 0.297 0.074 0.121 0.144 0.286 0.212 0.494 0.07 0.208 0.134 0.467 0.194 0.775 0.062 0.309 0.116 0.629 0.162 0.961h0.08c0.506-0.712 0.89-1.23 1.15-1.56 0.262-0.33 0.482-0.575 0.662-0.736 0.178-0.161 0.352-0.274 0.518-0.34 0.166-0.066 0.386-0.099 0.66-0.099 0.248 0 0.45 0.0318 0.61 0.095l-0.318 1.43h-0.552c-0.032-0.222-0.124-0.332-0.278-0.332-0.048 0-0.098 8e-3 -0.15 0.0238s-0.118 0.0502-0.194 0.103c-0.076 0.0528-0.188 0.156-0.336 0.309-0.148 0.153-0.314 0.34-0.498 0.562-0.186 0.221-0.374 0.453-0.57 0.696l-0.538 0.672c0.096 0.506 0.184 0.944 0.27 1.31 0.084 0.369 0.158 0.676 0.224 0.921s0.124 0.439 0.174 0.581 0.104 0.249 0.162 0.32 0.118 0.121 0.178 0.15c0.062 0.029 0.132 0.0434 0.21 0.0434 0.142 0 0.282-0.0554 0.416-0.166 0.134-0.111 0.328-0.361 0.58-0.751l0.516 0.34c-0.37 0.548-0.704 0.935-1 1.16s-0.652 0.336-1.06 0.336c-0.226 0-0.418-0.0408-0.576-0.123-0.16-0.0818-0.296-0.212-0.412-0.392-0.116-0.179-0.22-0.459-0.308-0.838-0.164-0.675-0.264-1.19-0.302-1.55h-0.078c-0.56 0.786-0.974 1.35-1.25 1.69s-0.496 0.596-0.672 0.759c-0.178 0.163-0.348 0.278-0.514 0.344s-0.388 0.0988-0.662 0.0988c-0.248 0-0.45-0.0316-0.608-0.0948l0.316-1.43h0.554c0.032 0.222 0.124 0.332 0.276 0.332 0.074 0 0.152-0.0198 0.234-0.0592 0.082-0.0396 0.2-0.135 0.352-0.285 0.152-0.15 0.364-0.386 0.632-0.708 0.27-0.322 0.66-0.804 1.17-1.45-0.08-0.417-0.162-0.817-0.246-1.2-0.084-0.385-0.172-0.743-0.26-1.08-0.09-0.332-0.164-0.55-0.222-0.653-0.058-0.103-0.12-0.174-0.186-0.214-0.066-0.0396-0.15-0.0594-0.25-0.0594-0.11 0-0.21 0.025-0.3 0.0752-0.09 0.05-0.188 0.137-0.292 0.261-0.106 0.124-0.246 0.318-0.42 0.581l-0.514-0.34c0.332-0.501 0.652-0.875 0.958-1.12s0.666-0.372 1.08-0.372z\" />\n <path d=\"m494 15.7h9.75v1.05h-9.75v-1.05zm0-3.28h9.75v1.05h-9.75v-1.05z\" />\n <path d=\"m510 14h9.74v5.58h-1.12v-4.54h-8.62v-1.04z\" />\n <path d=\"m524 11.5c0.164 0 0.308 0.0184 0.432 0.0554s0.234 0.0936 0.328 0.17c0.094 0.0766 0.18 0.175 0.254 0.297 0.072 0.121 0.144 0.286 0.212 0.494 0.07 0.208 0.134 0.467 0.194 0.775 0.062 0.309 0.116 0.629 0.162 0.961h0.08c0.506-0.712 0.89-1.23 1.15-1.56 0.262-0.33 0.482-0.575 0.662-0.736 0.178-0.161 0.352-0.274 0.518-0.34 0.166-0.066 0.386-0.099 0.66-0.099 0.248 0 0.45 0.0318 0.608 0.095l-0.316 1.43h-0.554c-0.03-0.222-0.124-0.332-0.276-0.332-0.048 0-0.098 8e-3 -0.15 0.0238-0.054 0.0158-0.118 0.0502-0.194 0.103-0.076 0.0528-0.188 0.156-0.336 0.309-0.148 0.153-0.314 0.34-0.498 0.562-0.186 0.221-0.376 0.453-0.57 0.696l-0.538 0.672c0.094 0.506 0.184 0.944 0.268 1.31 0.086 0.369 0.16 0.676 0.226 0.921s0.124 0.439 0.174 0.581 0.104 0.249 0.162 0.32 0.118 0.121 0.178 0.15c0.062 0.029 0.13 0.0434 0.21 0.0434 0.142 0 0.28-0.0554 0.416-0.166 0.134-0.111 0.328-0.361 0.58-0.751l0.514 0.34c-0.368 0.548-0.702 0.935-1 1.16s-0.652 0.336-1.06 0.336c-0.226 0-0.418-0.0408-0.578-0.123-0.158-0.0818-0.294-0.212-0.41-0.392-0.116-0.179-0.22-0.459-0.308-0.838-0.164-0.675-0.264-1.19-0.302-1.55h-0.078c-0.56 0.786-0.974 1.35-1.25 1.69s-0.496 0.596-0.672 0.759c-0.178 0.163-0.348 0.278-0.514 0.344-0.168 0.066-0.388 0.0988-0.662 0.0988-0.248 0-0.45-0.0316-0.608-0.0948l0.316-1.43h0.554c0.032 0.222 0.124 0.332 0.276 0.332 0.074 0 0.152-0.0198 0.234-0.0592 0.082-0.0396 0.198-0.135 0.352-0.285 0.152-0.15 0.364-0.386 0.632-0.708 0.27-0.322 0.66-0.804 1.17-1.45-0.08-0.417-0.162-0.817-0.246-1.2-0.084-0.385-0.172-0.743-0.26-1.08-0.09-0.332-0.164-0.55-0.222-0.653-0.058-0.103-0.12-0.174-0.186-0.214-0.066-0.0396-0.15-0.0594-0.25-0.0594-0.11 0-0.21 0.025-0.3 0.0752-0.09 0.05-0.188 0.137-0.292 0.261-0.106 0.124-0.246 0.318-0.42 0.581l-0.514-0.34c0.332-0.501 0.652-0.875 0.956-1.12 0.306-0.248 0.668-0.372 1.08-0.372z\" />\n </g>\n <g class=\"kata_svg_text\" clip-rule=\"evenodd\" fill-rule=\"evenodd\">\n <!-- Legend text -->\n <path d=\"m121 360c-0.941 0.455-2.17 0.683-3.68 0.683-1.98 0-3.53-0.581-4.66-1.74s-1.7-2.71-1.7-4.64c0-2.06 0.635-3.73 1.9-5.01 1.28-1.28 2.93-1.92 4.96-1.92 1.26 0 2.32 0.159 3.18 0.476v2.79c-0.863-0.515-1.84-0.773-2.95-0.773-1.21 0-2.19 0.381-2.93 1.14-0.743 0.761-1.11 1.79-1.11 3.09 0 1.25 0.35 2.24 1.05 2.98 0.701 0.737 1.64 1.1 2.83 1.1 1.13 0 2.17-0.276 3.11-0.827v2.65zm6.35 0.683c-1.53 0-2.74-0.429-3.62-1.28-0.875-0.863-1.31-2.03-1.31-3.5 0-1.52 0.455-2.71 1.37-3.57 0.91-0.862 2.14-1.29 3.69-1.29 1.53 0 2.73 0.432 3.59 1.29 0.869 0.857 1.3 1.99 1.3 3.4 0 1.53-0.449 2.73-1.35 3.62-0.892 0.886-2.12 1.33-3.67 1.33zm0.071-7.48c-0.67 0-1.19 0.23-1.56 0.691-0.371 0.462-0.557 1.11-0.557 1.96 0 1.77 0.713 2.65 2.14 2.65 1.36 0 2.04-0.907 2.04-2.72 0-1.72-0.686-2.58-2.06-2.58zm15.7 7.25h-2.83v-5.11c0-1.43-0.509-2.14-1.53-2.14-0.491 0-0.896 0.188-1.21 0.566-0.318 0.377-0.476 0.856-0.476 1.44v5.25h-2.84v-9.2h2.84v1.46h0.036c0.676-1.12 1.66-1.68 2.96-1.68 2.04 0 3.06 1.26 3.06 3.79v5.63zm1.65-0.243v-2.3c0.467 0.282 0.932 0.492 1.39 0.629 0.467 0.138 0.907 0.207 1.32 0.207 0.503 0 0.898-0.069 1.19-0.207 0.293-0.137 0.44-0.347 0.44-0.629 0-0.179-0.066-0.329-0.198-0.449s-0.302-0.224-0.512-0.314c-0.204-0.09-0.428-0.171-0.674-0.243-0.245-0.072-0.482-0.153-0.71-0.242-0.365-0.138-0.688-0.285-0.97-0.441-0.275-0.161-0.509-0.347-0.701-0.557-0.185-0.209-0.329-0.452-0.431-0.727-0.096-0.276-0.144-0.602-0.144-0.98 0-0.515 0.111-0.958 0.333-1.33 0.227-0.372 0.527-0.674 0.898-0.908 0.377-0.239 0.806-0.413 1.28-0.521 0.485-0.114 0.988-0.171 1.51-0.171 0.408 0 0.821 0.033 1.24 0.099 0.419 0.06 0.833 0.15 1.24 0.27v2.19c-0.359-0.21-0.746-0.365-1.16-0.467-0.407-0.108-0.809-0.162-1.2-0.162-0.186 0-0.362 0.018-0.53 0.054-0.162 0.03-0.305 0.078-0.431 0.144-0.126 0.06-0.225 0.14-0.297 0.242-0.072 0.096-0.108 0.207-0.108 0.333 0 0.167 0.054 0.311 0.162 0.431s0.249 0.225 0.422 0.314c0.174 0.084 0.366 0.162 0.575 0.234 0.216 0.066 0.429 0.135 0.638 0.207 0.378 0.131 0.719 0.275 1.02 0.431 0.305 0.156 0.566 0.338 0.781 0.548 0.222 0.21 0.39 0.455 0.503 0.737 0.12 0.281 0.18 0.617 0.18 1.01 0 0.545-0.12 1.01-0.359 1.4-0.234 0.384-0.548 0.698-0.944 0.944-0.389 0.239-0.841 0.413-1.36 0.521-0.509 0.114-1.04 0.171-1.59 0.171-1.01 0-1.95-0.156-2.81-0.468zm14.3 0.135c-0.419 0.222-1.05 0.333-1.9 0.333-2 0-3-1.04-3-3.12v-4.21h-1.49v-2.09h1.49v-1.99l2.83-0.808v2.79h2.07v2.09h-2.07v3.72c0 0.958 0.38 1.44 1.14 1.44 0.3 0 0.608-0.086 0.925-0.26v2.1zm9.26 0.108h-2.69v-1.32h-0.036c-0.617 1.03-1.53 1.55-2.74 1.55-0.893 0-1.6-0.252-2.11-0.755-0.51-0.509-0.764-1.19-0.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-0.333c0-1.01-0.545-1.51-1.64-1.51-1.1 0-2.14 0.326-3.13 0.979v-2.14c0.396-0.204 0.935-0.383 1.62-0.539 0.689-0.156 1.32-0.234 1.88-0.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-0.62l-1.67 0.215c-0.922 0.12-1.38 0.536-1.38 1.25 0 0.323 0.111 0.59 0.333 0.8 0.227 0.203 0.533 0.305 0.916 0.305 0.533 0 0.967-0.183 1.3-0.548 0.335-0.371 0.503-0.838 0.503-1.4zm13.8 3.74h-2.83v-5.11c0-1.43-0.509-2.14-1.53-2.14-0.492 0-0.896 0.188-1.21 0.566-0.318 0.377-0.476 0.856-0.476 1.44v5.25h-2.84v-9.2h2.84v1.46h0.035c0.677-1.12 1.66-1.68 2.96-1.68 2.04 0 3.06 1.26 3.06 3.79v5.63zm7.82-0.108c-0.419 0.222-1.05 0.333-1.9 0.333-2 0-3-1.04-3-3.12v-4.21h-1.49v-2.09h1.49v-1.99l2.83-0.808v2.79h2.07v2.09h-2.07v3.72c0 0.958 0.38 1.44 1.14 1.44 0.3 0 0.608-0.086 0.925-0.26v2.1z\" />\n <path d=\"m477 347-4.44 12.9h-3.29l-4.38-12.9h3.13l2.69 8.97c0.143 0.485 0.23 0.913 0.26 1.28h0.054c0.042-0.402 0.135-0.842 0.279-1.32l2.67-8.93h3.04zm7.54 12.9h-2.69v-1.32h-0.036c-0.617 1.03-1.53 1.55-2.74 1.55-0.892 0-1.6-0.252-2.11-0.755-0.509-0.509-0.764-1.19-0.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-0.333c0-1.01-0.545-1.51-1.64-1.51-1.1 0-2.14 0.326-3.13 0.979v-2.14c0.395-0.204 0.934-0.383 1.62-0.539 0.689-0.156 1.32-0.234 1.88-0.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-0.62l-1.67 0.215c-0.922 0.12-1.38 0.536-1.38 1.25 0 0.323 0.11 0.59 0.332 0.8 0.228 0.203 0.533 0.305 0.916 0.305 0.534 0 0.968-0.183 1.3-0.548 0.336-0.371 0.503-0.838 0.503-1.4zm10.9-2.9c-0.341-0.186-0.739-0.279-1.2-0.279-0.617 0-1.1 0.228-1.45 0.683-0.347 0.449-0.521 1.06-0.521 1.84v4.39h-2.84v-9.2h2.84v1.71h0.036c0.449-1.25 1.26-1.87 2.43-1.87 0.299 0 0.533 0.036 0.7 0.108v2.62zm2.84-4.02c-0.479 0-0.871-0.141-1.18-0.423-0.305-0.287-0.458-0.638-0.458-1.05 0-0.425 0.153-0.773 0.458-1.04 0.306-0.27 0.698-0.404 1.18-0.404 0.486 0 0.878 0.134 1.18 0.404 0.306 0.269 0.459 0.617 0.459 1.04 0 0.431-0.153 0.785-0.459 1.06-0.299 0.276-0.691 0.414-1.18 0.414zm1.4 10.7h-2.84v-9.2h2.84v9.2zm10 0h-2.69v-1.32h-0.036c-0.617 1.03-1.53 1.55-2.74 1.55-0.892 0-1.6-0.252-2.11-0.755-0.509-0.509-0.764-1.19-0.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-0.333c0-1.01-0.545-1.51-1.64-1.51-1.1 0-2.14 0.326-3.13 0.979v-2.14c0.396-0.204 0.935-0.383 1.62-0.539 0.688-0.156 1.31-0.234 1.88-0.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-0.62l-1.67 0.215c-0.922 0.12-1.38 0.536-1.38 1.25 0 0.323 0.111 0.59 0.333 0.8 0.227 0.203 0.533 0.305 0.916 0.305 0.533 0 0.968-0.183 1.3-0.548 0.335-0.371 0.503-0.838 0.503-1.4zm7.79 2.67h-0.036v1.07h-2.84v-13.6h2.84v5.8h0.036c0.7-1.07 1.7-1.61 2.99-1.61 1.19 0 2.1 0.408 2.74 1.22 0.641 0.815 0.961 1.93 0.961 3.34 0 1.53-0.374 2.76-1.12 3.69s-1.75 1.39-3 1.39c-1.13 0-1.99-0.432-2.57-1.29zm-0.081-3.88v0.943c0 0.593 0.17 1.08 0.512 1.47 0.341 0.39 0.778 0.584 1.31 0.584 0.646 0 1.15-0.248 1.5-0.745 0.359-0.503 0.539-1.21 0.539-2.13 0-0.76-0.165-1.35-0.494-1.78-0.324-0.431-0.788-0.646-1.39-0.646-0.569 0-1.04 0.212-1.42 0.638-0.372 0.425-0.557 0.979-0.557 1.66zm11.5 4.95h-2.84v-13.6h2.84v13.6zm10.7-3.79h-6c0.096 1.34 0.937 2 2.52 2 1.01 0 1.9-0.239 2.67-0.719v2.05c-0.851 0.455-1.96 0.683-3.32 0.683-1.48 0-2.64-0.411-3.46-1.23-0.82-0.827-1.23-1.98-1.23-3.45 0-1.53 0.443-2.74 1.33-3.63 0.887-0.892 1.98-1.34 3.27-1.34 1.34 0 2.38 0.399 3.11 1.2 0.737 0.797 1.1 1.88 1.1 3.24v1.2zm-2.63-1.74c0-1.32-0.533-1.98-1.6-1.98-0.456 0-0.851 0.189-1.19 0.566-0.33 0.377-0.53 0.848-0.602 1.41h3.39z\" />\n <!-- Ket text -->\n <path d=\"m242 183h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m250 184c-0.374 0-0.686 0.11-0.936 0.332-0.252 0.222-0.454 0.54-0.608 0.956s-0.264 0.924-0.328 1.52c-0.066 0.598-0.098 1.27-0.098 2.02 0 1.76 0.164 3.05 0.49 3.88 0.328 0.826 0.834 1.24 1.52 1.24 0.654 0 1.14-0.388 1.46-1.16 0.316-0.776 0.474-1.98 0.474-3.6 0-1.24-0.082-2.25-0.244-3.02s-0.388-1.32-0.676-1.66c-0.29-0.334-0.64-0.502-1.05-0.502zm0.04-0.69c1.18 0 2.06 0.458 2.64 1.37 0.578 0.914 0.868 2.29 0.868 4.14 0 1.91-0.31 3.36-0.928 4.34-0.618 0.982-1.52 1.47-2.71 1.47-1.17 0-2.04-0.46-2.61-1.38s-0.854-2.31-0.854-4.18c0-0.994 0.088-1.85 0.262-2.58 0.176-0.724 0.422-1.32 0.738-1.8 0.316-0.472 0.696-0.822 1.14-1.05 0.442-0.228 0.926-0.342 1.45-0.342z\" />\n <path d=\"m256 182 3.24 7.28v0.6l-3.24 7.29-0.866-0.308 2.6-7.28-2.6-7.29 0.866-0.292z\" />\n <path d=\"m139 72.2h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m148 72.6h0.444c-0.032 0.519-0.048 1.24-0.048 2.16v6.92c0 0.313 0.018 0.55 0.052 0.709 0.036 0.159 0.098 0.289 0.188 0.389 0.088 0.1 0.216 0.178 0.384 0.235 0.168 0.0566 0.378 0.0998 0.632 0.13s0.59 0.05 1.01 0.0608v0.592h-5.99v-0.592c0.6-0.027 1.03-0.0634 1.28-0.109 0.258-0.046 0.454-0.115 0.588-0.207 0.136-0.0918 0.234-0.221 0.296-0.389 0.062-0.167 0.094-0.44 0.094-0.819v-6.57c0-0.216-0.038-0.374-0.114-0.474-0.076-0.0998-0.186-0.15-0.332-0.15-0.174 0-0.42 0.089-0.738 0.267-0.32 0.178-0.714 0.424-1.18 0.738l-0.356-0.624 3.79-2.26z\" />\n <path d=\"m153 71.5 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m208 115h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m217 117h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42v-4.67z\" />\n <path d=\"m225 114 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m208 248h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m212 255h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m225 247 3.23 7.28v0.6l-3.23 7.29-0.866-0.308 2.6-7.28-2.6-7.29 0.866-0.292z\" />\n <path d=\"m132 292h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m145 285h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m154 286h0.444c-0.032 0.52-0.048 1.24-0.048 2.16v6.92c0 0.314 0.018 0.55 0.054 0.71 0.034 0.16 0.096 0.29 0.186 0.39 0.088 0.1 0.216 0.178 0.384 0.234 0.168 0.058 0.378 0.1 0.632 0.13s0.59 0.05 1.01 0.06v0.592h-5.99v-0.592c0.6-0.026 1.03-0.062 1.28-0.108 0.258-0.046 0.454-0.116 0.588-0.208 0.136-0.092 0.234-0.22 0.296-0.388s0.094-0.44 0.094-0.82v-6.57c0-0.216-0.038-0.374-0.114-0.474s-0.186-0.15-0.332-0.15c-0.174 0-0.42 0.088-0.738 0.266-0.318 0.18-0.714 0.424-1.18 0.738l-0.356-0.624 3.79-2.26z\" />\n <path d=\"m159 285 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m27.9 189h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m41 183h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m48.9 184c-0.373 0-0.685 0.11-0.936 0.332-0.251 0.222-0.454 0.54-0.608 0.956s-0.264 0.924-0.328 1.52c-0.0648 0.598-0.0972 1.27-0.0972 2.02 0 1.76 0.163 3.05 0.49 3.88 0.327 0.826 0.833 1.24 1.52 1.24 0.654 0 1.14-0.388 1.45-1.16 0.316-0.776 0.474-1.98 0.474-3.6 0-1.24-0.081-2.25-0.243-3.02-0.162-0.77-0.388-1.32-0.677-1.66-0.289-0.334-0.639-0.502-1.05-0.502zm0.0406-0.69c1.18 0 2.06 0.458 2.64 1.37 0.578 0.914 0.867 2.29 0.867 4.14 0 1.91-0.309 3.36-0.928 4.34-0.619 0.982-1.52 1.47-2.71 1.47-1.17 0-2.04-0.46-2.61-1.38-0.57-0.918-0.855-2.31-0.855-4.18 0-0.994 0.0878-1.85 0.263-2.58s0.422-1.32 0.738-1.8c0.316-0.472 0.696-0.822 1.14-1.05 0.443-0.228 0.927-0.342 1.45-0.342z\" />\n <path d=\"m55.2 182 3.23 7.28v0.6l-3.23 7.29-0.867-0.308 2.6-7.28-2.6-7.29 0.867-0.292z\" />\n <path d=\"m57.3 254h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m70.4 248h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m79.3 250h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42v-4.67z\" />\n <path d=\"m87.8 247 3.23 7.28v0.6l-3.23 7.29-0.867-0.308 2.6-7.28-2.6-7.29 0.867-0.292z\" />\n <path d=\"m56.6 121h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m69.8 115h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m74.3 121h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m87.1 114 3.23 7.28v0.599l-3.23 7.29-0.867-0.308 2.6-7.28-2.6-7.29 0.867-0.292z\" />\n <path d=\"m593 183h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m601 184c-0.372 0-0.684 0.11-0.936 0.332-0.25 0.222-0.454 0.54-0.608 0.956s-0.262 0.924-0.328 1.52c-0.064 0.598-0.096 1.27-0.096 2.02 0 1.76 0.162 3.05 0.49 3.88 0.326 0.826 0.834 1.24 1.52 1.24 0.654 0 1.14-0.388 1.45-1.16s0.474-1.98 0.474-3.6c0-1.24-0.08-2.25-0.242-3.02s-0.388-1.32-0.678-1.66c-0.288-0.334-0.638-0.502-1.05-0.502zm0.042-0.69c1.18 0 2.06 0.458 2.64 1.37 0.578 0.914 0.868 2.29 0.868 4.14 0 1.91-0.31 3.36-0.93 4.34-0.618 0.982-1.52 1.47-2.71 1.47-1.17 0-2.04-0.46-2.61-1.38s-0.856-2.31-0.856-4.18c0-0.994 0.088-1.85 0.264-2.58s0.422-1.32 0.738-1.8c0.316-0.472 0.696-0.822 1.14-1.05 0.444-0.228 0.928-0.342 1.45-0.342z\" />\n <path d=\"m607 182 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m490 72.2h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m499 72.6h0.446c-0.032 0.519-0.048 1.24-0.048 2.16v6.92c0 0.313 0.018 0.55 0.052 0.709 0.036 0.159 0.098 0.289 0.186 0.389 0.09 0.1 0.218 0.178 0.386 0.235 0.168 0.0566 0.378 0.0998 0.632 0.13s0.588 0.05 1 0.0608v0.592h-5.99v-0.592c0.6-0.027 1.03-0.0634 1.29-0.109 0.256-0.046 0.452-0.115 0.588-0.207 0.134-0.0918 0.234-0.221 0.296-0.389 0.062-0.167 0.092-0.44 0.092-0.819v-6.57c0-0.216-0.038-0.374-0.114-0.474-0.074-0.0998-0.186-0.15-0.332-0.15-0.172 0-0.418 0.089-0.736 0.267-0.32 0.178-0.714 0.424-1.18 0.738l-0.358-0.624 3.79-2.26z\" />\n <path d=\"m504 71.5 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m559 115h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m567 117h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42v-4.67z\" />\n <path d=\"m576 114 3.23 7.28v0.6l-3.23 7.29-0.866-0.308 2.6-7.28-2.6-7.29 0.866-0.292z\" />\n <path d=\"m559 248h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m563 255h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m576 247 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m483 292h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m496 285h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m505 286h0.446c-0.032 0.52-0.048 1.24-0.048 2.16v6.92c0 0.314 0.018 0.55 0.052 0.71 0.036 0.16 0.098 0.29 0.186 0.39 0.09 0.1 0.218 0.178 0.386 0.234 0.168 0.058 0.378 0.1 0.632 0.13s0.588 0.05 1 0.06v0.592h-5.99v-0.592c0.598-0.026 1.03-0.062 1.28-0.108s0.452-0.116 0.588-0.208c0.134-0.092 0.234-0.22 0.296-0.388s0.092-0.44 0.092-0.82v-6.57c0-0.216-0.038-0.374-0.114-0.474-0.074-0.1-0.186-0.15-0.332-0.15-0.172 0-0.418 0.088-0.736 0.266-0.32 0.18-0.714 0.424-1.18 0.738l-0.358-0.624 3.79-2.26z\" />\n <path d=\"m510 285 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m379 189h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m392 183h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m400 184c-0.372 0-0.684 0.11-0.936 0.332-0.25 0.222-0.454 0.54-0.608 0.956s-0.262 0.924-0.328 1.52c-0.064 0.598-0.098 1.27-0.098 2.02 0 1.76 0.164 3.05 0.492 3.88 0.326 0.826 0.832 1.24 1.52 1.24 0.652 0 1.14-0.388 1.45-1.16s0.474-1.98 0.474-3.6c0-1.24-0.08-2.25-0.242-3.02-0.164-0.77-0.388-1.32-0.678-1.66-0.288-0.334-0.638-0.502-1.05-0.502zm0.042-0.69c1.18 0 2.06 0.458 2.64 1.37 0.578 0.914 0.866 2.29 0.866 4.14 0 1.91-0.308 3.36-0.928 4.34-0.618 0.982-1.52 1.47-2.71 1.47-1.17 0-2.04-0.46-2.61-1.38s-0.856-2.31-0.856-4.18c0-0.994 0.088-1.85 0.264-2.58s0.422-1.32 0.738-1.8c0.316-0.472 0.696-0.822 1.14-1.05 0.444-0.228 0.926-0.342 1.45-0.342z\" />\n <path d=\"m406 182 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m408 254h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m421 248h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m430 250h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42v-4.67z\" />\n <path d=\"m439 247 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m408 121h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m421 115h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m425 121h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m438 114 3.23 7.28v0.599l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n </g>\n </g>\n <defs>\n <clipPath id=\"clip0_5_635\">\n <rect transform=\"translate(.6 .2)\" width=\"737\" height=\"374\" />\n </clipPath>\n </defs>\n</svg>\n\n3. Apply the $H$ gate to the qubit again.\n Now, you get the $\\ket{0}$ state for both constant scenarios and the $\\ket{1}$ state for both variable scenarios!\n <br/>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"679\" height=\"365\" fill=\"none\" version=\"1.1\" viewBox=\"0 0 679 365\" xmlns=\"http://www.w3.org/2000/svg\">\n <style>\n :root {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n }\n @media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n }\n .kata_svg_path {\n stroke: var(--kata-svg-path);\n }\n .kata_svg_text {\n fill: var(--kata-svg-stroke);\n }\n .kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n }\n .kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n }\n .kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n }\n </style>\n <g clip-path=\"url(#clip0_6_812)\" clip-rule=\"evenodd\" fill-rule=\"evenodd\">\n <!-- Large circles -->\n <g class=\"kata_svg_path\">\n <path d=\"m24.1 163c0-76.8 62.3-139 139-139 76.8 0 139 62.3 139 139 0 76.8-62.3 139-139 139-76.8 0-139-62.3-139-139z\" />\n <path d=\"m375 163c0-76.8 62.2-139 139-139s139 62.3 139 139c0 76.8-62.2 139-139 139s-139-62.3-139-139z\" />\n </g>\n <!-- Target points -->\n <g class=\"kata_svg_fill_accent\">\n <path d=\"m296 163c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n <path d=\"m18 163c0-3.26 2.69-5.9 6-5.9 3.31 0 6 2.64 6 5.9s-2.69 5.9-6 5.9c-3.31 0-6-2.64-6-5.9z\" />\n <path d=\"m508 23.7c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9c0 3.26-2.69 5.9-6 5.9s-6-2.64-6-5.9z\" />\n <path d=\"m508 302c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n </g>\n <!-- Normal points -->\n <g class=\"kata_svg_point\">\n <path d=\"m157 23.8c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9c0 3.26-2.64 5.9-5.9 5.9s-5.9-2.64-5.9-5.9z\" />\n <path d=\"m157 302c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n <path d=\"m257 260c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m57.3 66.6c0-3.26 2.69-5.9 6-5.9 3.31 0 6 2.64 6 5.9 0 3.26-2.69 5.9-6 5.9-3.31 0-6-2.64-6-5.9z\" />\n <path d=\"m647 163c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m369 163c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n <path d=\"m608 66.6c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9c0 3.26-2.69 5.9-6 5.9s-6-2.64-6-5.9z\" />\n <path d=\"m408 260c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\" />\n </g>\n <!-- From point -->\n <g class=\"kata_svg_point kata_svg_stroke_accent\">\n <path d=\"m257 66.6c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9c0 3.26-2.69 5.9-6 5.9s-6-2.64-6-5.9z\" />\n <path d=\"m57.3 260c0-3.26 2.69-5.9 6-5.9 3.31 0 6 2.64 6 5.9s-2.69 5.9-6 5.9c-3.31 0-6-2.64-6-5.9z\" />\n <path d=\"m608 260c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\" />\n <path d=\"m408 66.6c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9c0 3.26-2.64 5.9-5.9 5.9s-5.9-2.64-5.9-5.9z\" />\n </g>\n <!-- Arrows -->\n <g class=\"kata_svg_fill_accent\" >\n <path d=\"m309 162h15.1l-0.688 0.688v-96.5l0.688 0.688h-55.3v-1.38h56v97.9h-15.8v-1.38zm5.06 5.8-6.13-5.11 6.13-5.11c0.292-0.242 0.726-0.202 0.968 0.088 0.244 0.292 0.204 0.726-0.088 0.97l-5.5 4.58v-1.06l5.5 4.58c0.292 0.242 0.332 0.676 0.088 0.968-0.242 0.292-0.676 0.33-0.968 0.088z\" />\n <path d=\"m17 164h-15.4l0.688-0.688v96.5l-0.688-0.688h55.7v1.38h-56.3v-97.9h16.1v1.38zm-5.06-5.8 6.13 5.11-6.13 5.11c-0.292 0.242-0.725 0.204-0.968-0.088-0.243-0.292-0.204-0.726 0.088-0.968l5.5-4.58v1.06l-5.5-4.58c-0.292-0.242-0.331-0.676-0.088-0.968 0.243-0.292 0.677-0.33 0.968-0.088z\" />\n <path d=\"m620 259h57.4l-0.688 0.686v-258l0.688 0.687h-163l0.688-0.687v15.4h-1.38v-16.1h165v260h-58.1v-1.37zm-101-247-5.11 6.13-5.11-6.13c-0.242-0.292-0.204-0.725 0.088-0.968 0.292-0.243 0.726-0.204 0.968 0.088l4.58 5.5h-1.06l4.58-5.5c0.242-0.292 0.676-0.331 0.968-0.088 0.292 0.243 0.33 0.677 0.088 0.968z\" />\n <path d=\"m408 67.4h-51.1l0.686-0.688v258l-0.686-0.688h157l-0.686 0.688v-15.4h1.37v16.1h-158v-259h51.8v1.38zm101 247 5.11-6.13 5.11 6.13c0.244 0.292 0.204 0.726-0.088 0.97-0.292 0.242-0.724 0.202-0.968-0.088l-4.58-5.5h1.06l-4.58 5.5c-0.244 0.29-0.676 0.33-0.968 0.088-0.292-0.244-0.332-0.678-0.088-0.97z\" />\n </g>\n <g class=\"kata_svg_text\" clip-rule=\"evenodd\" fill-rule=\"evenodd\">\n <!-- Legend text -->\n <path d=\"m135 350c-0.94 0.455-2.17 0.683-3.68 0.683-1.98 0-3.53-0.581-4.66-1.74s-1.7-2.71-1.7-4.64c0-2.06 0.635-3.73 1.9-5.01 1.28-1.28 2.93-1.92 4.96-1.92 1.26 0 2.32 0.159 3.18 0.476v2.79c-0.862-0.515-1.84-0.773-2.95-0.773-1.21 0-2.19 0.381-2.93 1.14-0.743 0.761-1.11 1.79-1.11 3.09 0 1.25 0.35 2.24 1.05 2.98 0.7 0.737 1.64 1.1 2.83 1.1 1.13 0 2.17-0.276 3.11-0.827v2.65zm6.35 0.683c-1.53 0-2.74-0.429-3.62-1.28-0.875-0.863-1.31-2.03-1.31-3.5 0-1.52 0.455-2.71 1.37-3.57 0.91-0.862 2.14-1.29 3.69-1.29 1.53 0 2.72 0.432 3.59 1.29 0.868 0.857 1.3 1.99 1.3 3.4 0 1.53-0.45 2.73-1.35 3.62-0.893 0.886-2.12 1.33-3.68 1.33zm0.072-7.48c-0.671 0-1.19 0.23-1.56 0.691-0.371 0.462-0.557 1.11-0.557 1.96 0 1.77 0.713 2.65 2.14 2.65 1.36 0 2.04-0.907 2.04-2.72 0-1.72-0.686-2.58-2.06-2.58zm15.7 7.25h-2.83v-5.11c0-1.43-0.509-2.14-1.53-2.14-0.492 0-0.896 0.188-1.21 0.566-0.318 0.377-0.477 0.856-0.477 1.44v5.25h-2.84v-9.2h2.84v1.46h0.036c0.677-1.12 1.66-1.68 2.96-1.68 2.04 0 3.06 1.26 3.06 3.79v5.63zm1.65-0.243v-2.3c0.467 0.282 0.931 0.492 1.39 0.629 0.467 0.138 0.907 0.207 1.32 0.207 0.503 0 0.899-0.069 1.19-0.207 0.294-0.137 0.441-0.347 0.441-0.629 0-0.179-0.066-0.329-0.198-0.449s-0.303-0.224-0.512-0.314c-0.204-0.09-0.429-0.171-0.674-0.243-0.246-0.072-0.482-0.153-0.71-0.242-0.365-0.138-0.689-0.285-0.97-0.441-0.276-0.161-0.509-0.347-0.701-0.557-0.186-0.209-0.329-0.452-0.431-0.727-0.096-0.276-0.144-0.602-0.144-0.98 0-0.515 0.111-0.958 0.332-1.33 0.228-0.372 0.528-0.674 0.899-0.908 0.377-0.239 0.806-0.413 1.28-0.521 0.485-0.114 0.988-0.171 1.51-0.171 0.407 0 0.821 0.033 1.24 0.099 0.419 0.06 0.832 0.15 1.24 0.27v2.19c-0.36-0.21-0.746-0.365-1.16-0.467-0.408-0.108-0.809-0.162-1.2-0.162-0.186 0-0.363 0.018-0.53 0.054-0.162 0.03-0.306 0.078-0.431 0.144-0.126 0.06-0.225 0.14-0.297 0.242-0.072 0.096-0.108 0.207-0.108 0.333 0 0.167 0.054 0.311 0.162 0.431s0.249 0.225 0.422 0.314c0.174 0.084 0.366 0.162 0.575 0.234 0.216 0.066 0.428 0.135 0.638 0.207 0.377 0.131 0.719 0.275 1.02 0.431 0.306 0.156 0.566 0.338 0.782 0.548 0.222 0.21 0.389 0.455 0.503 0.737 0.12 0.281 0.18 0.617 0.18 1.01 0 0.545-0.12 1.01-0.36 1.4-0.233 0.384-0.548 0.698-0.943 0.944-0.389 0.239-0.841 0.413-1.36 0.521-0.509 0.114-1.04 0.171-1.59 0.171-1.01 0-1.95-0.156-2.81-0.468zm14.3 0.135c-0.419 0.222-1.05 0.333-1.9 0.333-2 0-3-1.04-3-3.12v-4.21h-1.49v-2.09h1.49v-1.99l2.83-0.808v2.79h2.07v2.09h-2.07v3.72c0 0.958 0.38 1.44 1.14 1.44 0.299 0 0.608-0.086 0.925-0.26v2.1zm9.26 0.108h-2.69v-1.32h-0.036c-0.617 1.03-1.53 1.55-2.74 1.55-0.893 0-1.6-0.252-2.11-0.755-0.509-0.509-0.763-1.19-0.763-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-0.333c0-1.01-0.545-1.51-1.64-1.51-1.1 0-2.14 0.326-3.13 0.979v-2.14c0.395-0.204 0.934-0.383 1.62-0.539 0.689-0.156 1.32-0.234 1.88-0.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-0.62l-1.67 0.215c-0.923 0.12-1.38 0.536-1.38 1.25 0 0.323 0.111 0.59 0.333 0.8 0.227 0.203 0.533 0.305 0.916 0.305 0.533 0 0.967-0.183 1.3-0.548 0.335-0.371 0.503-0.838 0.503-1.4zm13.8 3.74h-2.83v-5.11c0-1.43-0.509-2.14-1.53-2.14-0.491 0-0.895 0.188-1.21 0.566-0.317 0.377-0.476 0.856-0.476 1.44v5.25h-2.84v-9.2h2.84v1.46h0.036c0.677-1.12 1.66-1.68 2.96-1.68 2.04 0 3.06 1.26 3.06 3.79v5.63zm7.82-0.108c-0.419 0.222-1.05 0.333-1.9 0.333-2 0-3-1.04-3-3.12v-4.21h-1.49v-2.09h1.49v-1.99l2.83-0.808v2.79h2.07v2.09h-2.07v3.72c0 0.958 0.38 1.44 1.14 1.44 0.299 0 0.608-0.086 0.925-0.26v2.1z\" />\n <path d=\"m491 338-4.44 12.9h-3.29l-4.38-12.9h3.13l2.69 8.97c0.144 0.485 0.23 0.913 0.26 1.28h0.054c0.042-0.402 0.135-0.842 0.279-1.32l2.67-8.93h3.04zm7.54 12.9h-2.69v-1.32h-0.036c-0.616 1.03-1.53 1.55-2.74 1.55-0.892 0-1.6-0.252-2.11-0.755-0.509-0.509-0.764-1.19-0.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-0.333c0-1.01-0.545-1.51-1.64-1.51-1.1 0-2.14 0.326-3.13 0.979v-2.14c0.395-0.204 0.934-0.383 1.62-0.539 0.689-0.156 1.32-0.234 1.88-0.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-0.62l-1.67 0.215c-0.922 0.12-1.38 0.536-1.38 1.25 0 0.323 0.11 0.59 0.332 0.8 0.228 0.203 0.533 0.305 0.916 0.305 0.534 0 0.968-0.183 1.3-0.548 0.336-0.371 0.503-0.838 0.503-1.4zm10.9-2.9c-0.341-0.186-0.739-0.279-1.2-0.279-0.616 0-1.1 0.228-1.45 0.683-0.347 0.449-0.521 1.06-0.521 1.84v4.39h-2.84v-9.2h2.84v1.71h0.036c0.449-1.25 1.26-1.87 2.43-1.87 0.299 0 0.533 0.036 0.7 0.108v2.62zm2.84-4.02c-0.479 0-0.871-0.141-1.18-0.423-0.305-0.287-0.458-0.638-0.458-1.05 0-0.425 0.153-0.773 0.458-1.04 0.306-0.27 0.698-0.404 1.18-0.404 0.486 0 0.878 0.134 1.18 0.404 0.306 0.269 0.459 0.617 0.459 1.04 0 0.431-0.153 0.785-0.459 1.06-0.299 0.276-0.691 0.414-1.18 0.414zm1.4 10.7h-2.84v-9.2h2.84v9.2zm10 0h-2.69v-1.32h-0.036c-0.617 1.03-1.53 1.55-2.74 1.55-0.892 0-1.6-0.252-2.11-0.755-0.509-0.509-0.764-1.19-0.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-0.333c0-1.01-0.545-1.51-1.64-1.51-1.1 0-2.14 0.326-3.13 0.979v-2.14c0.396-0.204 0.935-0.383 1.62-0.539 0.688-0.156 1.31-0.234 1.88-0.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-0.62l-1.67 0.215c-0.922 0.12-1.38 0.536-1.38 1.25 0 0.323 0.111 0.59 0.333 0.8 0.227 0.203 0.533 0.305 0.916 0.305 0.533 0 0.968-0.183 1.3-0.548 0.335-0.371 0.503-0.838 0.503-1.4zm7.79 2.67h-0.036v1.07h-2.84v-13.6h2.84v5.8h0.036c0.7-1.07 1.7-1.61 2.99-1.61 1.19 0 2.1 0.408 2.74 1.22 0.641 0.815 0.961 1.93 0.961 3.34 0 1.53-0.374 2.76-1.12 3.69s-1.75 1.39-3 1.39c-1.13 0-1.99-0.432-2.57-1.29zm-0.081-3.88v0.943c0 0.593 0.17 1.08 0.512 1.47 0.341 0.39 0.779 0.584 1.31 0.584 0.646 0 1.15-0.248 1.5-0.745 0.359-0.503 0.539-1.21 0.539-2.13 0-0.76-0.165-1.35-0.494-1.78-0.324-0.431-0.788-0.646-1.39-0.646-0.569 0-1.04 0.212-1.42 0.638-0.372 0.425-0.557 0.979-0.557 1.66zm11.5 4.95h-2.84v-13.6h2.84v13.6zm10.7-3.79h-6c0.096 1.34 0.937 2 2.52 2 1.01 0 1.9-0.239 2.67-0.719v2.05c-0.851 0.455-1.96 0.683-3.32 0.683-1.48 0-2.64-0.411-3.46-1.23-0.82-0.827-1.23-1.98-1.23-3.45 0-1.53 0.443-2.74 1.33-3.63 0.887-0.892 1.98-1.34 3.27-1.34 1.34 0 2.38 0.399 3.11 1.2 0.737 0.797 1.1 1.88 1.1 3.24v1.2zm-2.63-1.74c0-1.32-0.533-1.98-1.6-1.98-0.456 0-0.851 0.189-1.19 0.566-0.33 0.377-0.53 0.848-0.602 1.41h3.39z\" />\n <!-- Ket text -->\n <path d=\"m259 156h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m266 157c-0.372 0-0.684 0.11-0.936 0.332s-0.454 0.54-0.608 0.956-0.264 0.924-0.328 1.52c-0.064 0.598-0.098 1.27-0.098 2.02 0 1.76 0.164 3.05 0.49 3.88 0.328 0.824 0.834 1.24 1.52 1.24 0.654 0 1.14-0.386 1.46-1.16s0.474-1.98 0.474-3.6c0-1.24-0.082-2.25-0.244-3.02s-0.388-1.32-0.676-1.66c-0.29-0.334-0.64-0.502-1.05-0.502zm0.04-0.69c1.18 0 2.06 0.458 2.64 1.37 0.578 0.914 0.866 2.29 0.866 4.14 0 1.91-0.308 3.36-0.928 4.34-0.618 0.982-1.52 1.47-2.71 1.47-1.17 0-2.04-0.46-2.61-1.38s-0.856-2.31-0.856-4.18c0-0.994 0.088-1.85 0.264-2.58s0.42-1.32 0.738-1.8c0.316-0.472 0.694-0.822 1.14-1.05 0.442-0.228 0.926-0.342 1.45-0.342z\" />\n <path d=\"m273 156 3.23 7.28v0.598l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m156 45.5h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m164 45.9h0.446c-0.032 0.519-0.05 1.24-0.05 2.16v6.92c0 0.313 0.018 0.55 0.054 0.709 0.034 0.159 0.096 0.289 0.186 0.389s0.218 0.178 0.384 0.235c0.168 0.0568 0.38 0.1 0.634 0.13 0.254 0.0298 0.588 0.05 1 0.0608v0.592h-5.99v-0.592c0.6-0.027 1.03-0.0634 1.29-0.109 0.256-0.0458 0.452-0.115 0.586-0.207 0.136-0.0918 0.234-0.222 0.296-0.389 0.062-0.168 0.094-0.44 0.094-0.819v-6.57c0-0.216-0.038-0.374-0.114-0.474s-0.186-0.15-0.332-0.15c-0.172 0-0.418 0.0892-0.738 0.267-0.318 0.178-0.712 0.424-1.18 0.738l-0.356-0.624 3.79-2.26z\" />\n <path d=\"m170 44.8 3.23 7.28v0.6l-3.23 7.29-0.866-0.308 2.6-7.28-2.6-7.29 0.866-0.292z\" />\n <path d=\"m224 88.4h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m233 90h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42v-4.67z\" />\n <path d=\"m242 87.6 3.23 7.28v0.6l-3.23 7.29-0.866-0.308 2.6-7.28-2.6-7.29 0.866-0.292z\" />\n <path d=\"m224 222h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m229 228h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m242 221 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m149 265h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m162 259h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m171 259h0.446c-0.032 0.52-0.05 1.24-0.05 2.16v6.92c0 0.314 0.018 0.55 0.054 0.71 0.034 0.16 0.096 0.29 0.186 0.39s0.218 0.178 0.386 0.234c0.166 0.056 0.378 0.1 0.632 0.13s0.588 0.05 1 0.06v0.592h-5.99v-0.592c0.6-0.026 1.03-0.062 1.29-0.108 0.256-0.046 0.452-0.116 0.586-0.208 0.136-0.092 0.234-0.222 0.296-0.388 0.062-0.168 0.094-0.44 0.094-0.82v-6.57c0-0.216-0.038-0.374-0.114-0.474s-0.186-0.15-0.332-0.15c-0.172 0-0.418 0.088-0.738 0.266-0.318 0.178-0.712 0.424-1.18 0.738l-0.358-0.624 3.79-2.26z\" />\n <path d=\"m176 258 3.23 7.28v0.6l-3.23 7.29-0.866-0.308 2.6-7.28-2.6-7.29 0.866-0.292z\" />\n <path d=\"m44.7 163h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m57.9 156h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m65.7 157c-0.373 0-0.685 0.11-0.936 0.332s-0.454 0.54-0.608 0.956-0.264 0.924-0.328 1.52c-0.0648 0.598-0.0972 1.27-0.0972 2.02 0 1.76 0.163 3.05 0.49 3.88 0.327 0.824 0.833 1.24 1.52 1.24 0.654 0 1.14-0.386 1.45-1.16 0.316-0.776 0.474-1.98 0.474-3.6 0-1.24-0.081-2.25-0.243-3.02-0.162-0.77-0.388-1.32-0.677-1.66-0.289-0.334-0.639-0.502-1.05-0.502zm0.0406-0.69c1.18 0 2.06 0.458 2.64 1.37 0.578 0.914 0.867 2.29 0.867 4.14 0 1.91-0.309 3.36-0.928 4.34-0.619 0.982-1.52 1.47-2.71 1.47-1.17 0-2.04-0.46-2.61-1.38-0.57-0.918-0.855-2.31-0.855-4.18 0-0.994 0.0878-1.85 0.263-2.58s0.422-1.32 0.738-1.8c0.316-0.472 0.696-0.822 1.14-1.05 0.443-0.228 0.927-0.342 1.45-0.342z\" />\n <path d=\"m72 156 3.23 7.28v0.598l-3.23 7.29-0.867-0.308 2.6-7.28-2.6-7.29 0.867-0.292z\" />\n <path d=\"m74.1 228h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m87.3 221h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m96.2 223h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42v-4.67z\" />\n <path d=\"m105 220 3.23 7.28v0.598l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m73.4 94.2h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m86.6 87.9h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m91.1 94.2h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m104 87.2 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m608 156h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m616 157c-0.374 0-0.686 0.11-0.936 0.332-0.252 0.222-0.454 0.54-0.608 0.956s-0.264 0.924-0.328 1.52c-0.066 0.598-0.098 1.27-0.098 2.02 0 1.76 0.164 3.05 0.49 3.88 0.328 0.824 0.834 1.24 1.52 1.24 0.654 0 1.14-0.386 1.46-1.16s0.474-1.98 0.474-3.6c0-1.24-0.082-2.25-0.244-3.02s-0.388-1.32-0.676-1.66c-0.29-0.334-0.64-0.502-1.05-0.502zm0.04-0.69c1.18 0 2.06 0.458 2.64 1.37 0.578 0.914 0.868 2.29 0.868 4.14 0 1.91-0.31 3.36-0.928 4.34-0.618 0.982-1.52 1.47-2.71 1.47-1.17 0-2.04-0.46-2.61-1.38s-0.854-2.31-0.854-4.18c0-0.994 0.088-1.85 0.262-2.58 0.176-0.724 0.422-1.32 0.738-1.8 0.316-0.472 0.696-0.822 1.14-1.05 0.442-0.228 0.926-0.342 1.45-0.342z\" />\n <path d=\"m622 156 3.23 7.28v0.598l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m505 45.5h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m514 45.9h0.444c-0.032 0.519-0.048 1.24-0.048 2.16v6.92c0 0.313 0.018 0.55 0.054 0.709 0.034 0.159 0.096 0.289 0.186 0.389 0.088 0.1 0.216 0.178 0.384 0.235s0.378 0.1 0.632 0.13c0.254 0.0298 0.59 0.05 1.01 0.0608v0.592h-5.99v-0.592c0.6-0.027 1.03-0.0634 1.28-0.109 0.258-0.0458 0.454-0.115 0.588-0.207 0.136-0.0918 0.234-0.222 0.296-0.389 0.062-0.168 0.094-0.44 0.094-0.819v-6.57c0-0.216-0.038-0.374-0.114-0.474s-0.186-0.15-0.332-0.15c-0.174 0-0.42 0.0892-0.738 0.267-0.318 0.178-0.714 0.424-1.18 0.738l-0.356-0.624 3.79-2.26z\" />\n <path d=\"m519 44.8 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m574 88.4h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m583 90h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42v-4.67z\" />\n <path d=\"m591 87.6 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m574 222h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m578 228h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m591 221 3.23 7.28v0.6l-3.23 7.29-0.866-0.308 2.6-7.28-2.6-7.29 0.866-0.292z\" />\n <path d=\"m498 265h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m511 259h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m520 259h0.446c-0.034 0.52-0.05 1.24-0.05 2.16v6.92c0 0.314 0.018 0.55 0.054 0.71 0.034 0.16 0.096 0.29 0.186 0.39 0.088 0.1 0.216 0.178 0.384 0.234s0.378 0.1 0.632 0.13 0.59 0.05 1.01 0.06v0.592h-5.99v-0.592c0.6-0.026 1.03-0.062 1.28-0.108 0.258-0.046 0.454-0.116 0.588-0.208 0.136-0.092 0.234-0.222 0.296-0.388 0.062-0.168 0.094-0.44 0.094-0.82v-6.57c0-0.216-0.038-0.374-0.114-0.474s-0.186-0.15-0.332-0.15c-0.174 0-0.42 0.088-0.738 0.266s-0.714 0.424-1.18 0.738l-0.356-0.624 3.79-2.26z\" />\n <path d=\"m525 258 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m394 163h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m407 156h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m415 157c-0.374 0-0.686 0.11-0.936 0.332-0.252 0.222-0.454 0.54-0.608 0.956s-0.264 0.924-0.328 1.52c-0.066 0.598-0.098 1.27-0.098 2.02 0 1.76 0.164 3.05 0.49 3.88 0.328 0.824 0.834 1.24 1.52 1.24 0.654 0 1.14-0.386 1.45-1.16 0.318-0.776 0.476-1.98 0.476-3.6 0-1.24-0.082-2.25-0.244-3.02s-0.388-1.32-0.676-1.66c-0.29-0.334-0.64-0.502-1.05-0.502zm0.04-0.69c1.18 0 2.06 0.458 2.64 1.37 0.578 0.914 0.868 2.29 0.868 4.14 0 1.91-0.31 3.36-0.928 4.34-0.62 0.982-1.52 1.47-2.71 1.47-1.17 0-2.04-0.46-2.61-1.38s-0.854-2.31-0.854-4.18c0-0.994 0.088-1.85 0.262-2.58 0.176-0.724 0.422-1.32 0.738-1.8 0.316-0.472 0.696-0.822 1.14-1.05 0.442-0.228 0.926-0.342 1.45-0.342z\" />\n <path d=\"m421 156 3.23 7.28v0.598l-3.23 7.29-0.866-0.308 2.6-7.28-2.6-7.29 0.866-0.292z\" />\n <path d=\"m423 228h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m436 221h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m445 223h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42v-4.67z\" />\n <path d=\"m454 220 3.23 7.28v0.598l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n <path d=\"m423 94.2h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m436 87.9h1.25v15.1h-1.25v-15.1z\" />\n <path d=\"m440 94.2h9.99v1.08h-9.99v-1.08z\" />\n <path d=\"m453 87.2 3.23 7.28v0.6l-3.23 7.29-0.868-0.308 2.6-7.28-2.6-7.29 0.868-0.292z\" />\n </g>\n </g>\n <defs>\n <clipPath id=\"clip0_6_812\">\n <rect transform=\"translate(.8 .6)\" width=\"677\" height=\"364\"/>\n </clipPath>\n </defs>\n</svg>\n"
6654
+ "content": "\nYou can follow the steps of the algorithm for the constant and the balanced scenarios using a neat visualization. Since Deutsch algorithm deals only with states with real amplitudes, you can map all states on the unit circle, and follow the state evolution through the steps.\n\n1. Start with a qubit in the $\\ket{0}$ state and apply the $H$ gate to the qubit.\n <br/>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"685\" height=\"380\" fill=\"none\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n<style>\n/* Default values, or theme set explicitly to light */\n:root, [data-theme=\"light\"] {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n}\n/* User has set OS preference for dark. (An explict light theme will override) */\n@media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n}\n/* Explicit dark theme set (should match above dark preference values) */\n[data-theme=\"dark\"] {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n}\n/*** Kata specific styles ***/\n.kata_svg_path {\n stroke: var(--kata-svg-path);\n stroke-width: 2;\n stroke-linecap: round;\n fill: none;\n}\n.kata_svg_text {\n fill: var(--kata-svg-stroke);\n}\n.kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n}\n.kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n}\n.kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n}\n</style>\n <!-- Large circles -->\n <g class=\"kata_svg_path\">\n <path d=\"m24.1 163c0-76.8 62.3-139 139-139 76.8 0 139 62.3 139 139 0 76.8-62.3 139-139 139-76.8 0-139-62.3-139-139z\"/>\n <path d=\"m375 163c0-76.8 62.2-139 139-139s139 62.3 139 139c0 76.8-62.2 139-139 139s-139-62.3-139-139z\"/>\n </g>\n <!-- Target points -->\n <g class=\"kata_svg_fill_accent\">\n <path d=\"m257 66.6c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m608 66.6c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n </g>\n <!-- Normal points -->\n <g class=\"kata_svg_point\">\n <path d=\"m18 163c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m508 23.7c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m508 302c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m157 23.8c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m157 302c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m257 260c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m57.3 66.6c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m369 163c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m408 260c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m57.3 260c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m408 66.6c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m608 260c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n </g>\n <!-- From point -->\n <g class=\"kata_svg_point kata_svg_stroke_accent\">\n <path d=\"m647 163c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m296 163c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n </g>\n <!-- Arrows -->\n <g class=\"kata_svg_path kata_svg_stroke_accent\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\n <path d=\"m308.12 163.05h16.128v-96.466h-54.244l5.6085-4.3192-5.6085 4.3192 5.6085 4.7704\" image-rendering=\"auto\"/>\n <path d=\"m659.97 162.9h16.128v-96.466h-55.326l5.6085-4.3192-5.6085 4.3192 5.6085 4.7704\" image-rendering=\"auto\"/>\n </g>\n <g class=\"kata_svg_text\">\n <!-- Legend text -->\n <path d=\"m135 350c-.94.455-2.17.683-3.68.683-1.98 0-3.53-.581-4.66-1.74s-1.7-2.71-1.7-4.64c0-2.06.635-3.73 1.9-5.01 1.28-1.28 2.93-1.92 4.96-1.92 1.26 0 2.32.159 3.18.476v2.79c-.862-.515-1.84-.773-2.95-.773-1.21 0-2.19.381-2.93 1.14-.743.761-1.11 1.79-1.11 3.09 0 1.25.35 2.24 1.05 2.98.7.737 1.64 1.1 2.83 1.1 1.13 0 2.17-.276 3.11-.827v2.65zm6.35.683c-1.53 0-2.74-.429-3.62-1.28-.875-.863-1.31-2.03-1.31-3.5 0-1.52.455-2.71 1.37-3.57.91-.862 2.14-1.29 3.69-1.29 1.53 0 2.72.432 3.59 1.29.868.857 1.3 1.99 1.3 3.4 0 1.53-.45 2.73-1.35 3.62-.893.886-2.12 1.33-3.68 1.33zm.072-7.48c-.671 0-1.19.23-1.56.691-.371.462-.557 1.11-.557 1.96 0 1.77.713 2.65 2.14 2.65 1.36 0 2.04-.907 2.04-2.72 0-1.72-.686-2.58-2.06-2.58zm15.7 7.25h-2.83v-5.11c0-1.43-.509-2.14-1.53-2.14-.492 0-.896.188-1.21.566-.318.377-.477.856-.477 1.44v5.25h-2.84v-9.2h2.84v1.46h.036c.677-1.12 1.66-1.68 2.96-1.68 2.04 0 3.06 1.26 3.06 3.79v5.63zm1.65-.243v-2.3c.467.282.931.492 1.39.629.467.138.907.207 1.32.207.503 0 .899-.069 1.19-.207.294-.137.441-.347.441-.629 0-.179-.066-.329-.198-.449s-.303-.224-.512-.314c-.204-.09-.429-.171-.674-.243-.246-.072-.482-.153-.71-.242-.365-.138-.689-.285-.97-.441-.276-.161-.509-.347-.701-.557-.186-.209-.329-.452-.431-.727-.096-.276-.144-.602-.144-.98 0-.515.111-.958.332-1.33.228-.372.528-.674.899-.908.377-.239.806-.413 1.28-.521.485-.114.988-.171 1.51-.171.407 0 .821.033 1.24.099.419.06.832.15 1.24.27v2.19c-.36-.21-.746-.365-1.16-.467-.408-.108-.809-.162-1.2-.162-.186 0-.363.018-.53.054-.162.03-.306.078-.431.144-.126.06-.225.14-.297.242-.072.096-.108.207-.108.333 0 .167.054.311.162.431s.249.225.422.314c.174.084.366.162.575.234.216.066.428.135.638.207.377.131.719.275 1.02.431.306.156.566.338.782.548.222.21.389.455.503.737.12.281.18.617.18 1.01 0 .545-.12 1.01-.36 1.4-.233.384-.548.698-.943.944-.389.239-.841.413-1.36.521-.509.114-1.04.171-1.59.171-1.01 0-1.95-.156-2.81-.468zm14.3.135c-.419.222-1.05.333-1.9.333-2 0-3-1.04-3-3.12v-4.21h-1.49v-2.09h1.49v-1.99l2.83-.808v2.79h2.07v2.09h-2.07v3.72c0 .958.38 1.44 1.14 1.44.299 0 .608-.086.925-.26v2.1zm9.26.108h-2.69v-1.32h-.036c-.617 1.03-1.53 1.55-2.74 1.55-.893 0-1.6-.252-2.11-.755-.509-.509-.763-1.19-.763-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-.333c0-1.01-.545-1.51-1.64-1.51-1.1 0-2.14.326-3.13.979v-2.14c.395-.204.934-.383 1.62-.539.689-.156 1.32-.234 1.88-.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-.62l-1.67.215c-.923.12-1.38.536-1.38 1.25 0 .323.111.59.333.8.227.203.533.305.916.305.533 0 .967-.183 1.3-.548.335-.371.503-.838.503-1.4zm13.8 3.74h-2.83v-5.11c0-1.43-.509-2.14-1.53-2.14-.491 0-.895.188-1.21.566-.317.377-.476.856-.476 1.44v5.25h-2.84v-9.2h2.84v1.46h.036c.677-1.12 1.66-1.68 2.96-1.68 2.04 0 3.06 1.26 3.06 3.79v5.63zm7.82-.108c-.419.222-1.05.333-1.9.333-2 0-3-1.04-3-3.12v-4.21h-1.49v-2.09h1.49v-1.99l2.83-.808v2.79h2.07v2.09h-2.07v3.72c0 .958.38 1.44 1.14 1.44.299 0 .608-.086.925-.26v2.1z\"/>\n <path d=\"m491 338-4.44 12.9h-3.29l-4.38-12.9h3.13l2.69 8.97c.144.485.23.913.26 1.28h.054c.042-.402.135-.842.279-1.32l2.67-8.93h3.04zm7.54 12.9h-2.69v-1.32h-.036c-.616 1.03-1.53 1.55-2.74 1.55-.892 0-1.6-.252-2.11-.755-.509-.509-.764-1.19-.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-.333c0-1.01-.545-1.51-1.64-1.51-1.1 0-2.14.326-3.13.979v-2.14c.395-.204.934-.383 1.62-.539.689-.156 1.32-.234 1.88-.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-.62l-1.67.215c-.922.12-1.38.536-1.38 1.25 0 .323.11.59.332.8.228.203.533.305.916.305.534 0 .968-.183 1.3-.548.336-.371.503-.838.503-1.4zm10.9-2.9c-.341-.186-.739-.279-1.2-.279-.616 0-1.1.228-1.45.683-.347.449-.521 1.06-.521 1.84v4.39h-2.84v-9.2h2.84v1.71h.036c.449-1.25 1.26-1.87 2.43-1.87.299 0 .533.036.7.108v2.62zm2.84-4.02c-.479 0-.871-.141-1.18-.423-.305-.287-.458-.638-.458-1.05 0-.425.153-.773.458-1.04.306-.27.698-.404 1.18-.404.486 0 .878.134 1.18.404.306.269.459.617.459 1.04 0 .431-.153.785-.459 1.06-.299.276-.691.414-1.18.414zm1.4 10.7h-2.84v-9.2h2.84zm10 0h-2.69v-1.32h-.036c-.617 1.03-1.53 1.55-2.74 1.55-.892 0-1.6-.252-2.11-.755-.509-.509-.764-1.19-.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-.333c0-1.01-.545-1.51-1.64-1.51-1.1 0-2.14.326-3.13.979v-2.14c.396-.204.935-.383 1.62-.539.688-.156 1.31-.234 1.88-.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-.62l-1.67.215c-.922.12-1.38.536-1.38 1.25 0 .323.111.59.333.8.227.203.533.305.916.305.533 0 .968-.183 1.3-.548.335-.371.503-.838.503-1.4zm7.79 2.67h-.036v1.07h-2.84v-13.6h2.84v5.8h.036c.7-1.07 1.7-1.61 2.99-1.61 1.19 0 2.1.408 2.74 1.22.641.815.961 1.93.961 3.34 0 1.53-.374 2.76-1.12 3.69s-1.75 1.39-3 1.39c-1.13 0-1.99-.432-2.57-1.29zm-.081-3.88v.943c0 .593.17 1.08.512 1.47.341.39.779.584 1.31.584.646 0 1.15-.248 1.5-.745.359-.503.539-1.21.539-2.13 0-.76-.165-1.35-.494-1.78-.324-.431-.788-.646-1.39-.646-.569 0-1.04.212-1.42.638-.372.425-.557.979-.557 1.66zm11.5 4.95h-2.84v-13.6h2.84zm10.7-3.79h-6c.096 1.34.937 2 2.52 2 1.01 0 1.9-.239 2.67-.719v2.05c-.851.455-1.96.683-3.32.683-1.48 0-2.64-.411-3.46-1.23-.82-.827-1.23-1.98-1.23-3.45 0-1.53.443-2.74 1.33-3.63.887-.892 1.98-1.34 3.27-1.34 1.34 0 2.38.399 3.11 1.2.737.797 1.1 1.88 1.1 3.24v1.2zm-2.63-1.74c0-1.32-.533-1.98-1.6-1.98-.456 0-.851.189-1.19.566-.33.377-.53.848-.602 1.41h3.39z\"/>\n <!-- Ket text -->\n <path d=\"m259 156h1.25v15.1h-1.25z\"/>\n <path d=\"m266 157c-.372 0-.684.11-.936.332s-.454.54-.608.956-.264.924-.328 1.52c-.064.598-.098 1.27-.098 2.02 0 1.76.164 3.05.49 3.88.328.824.834 1.24 1.52 1.24.654 0 1.14-.386 1.46-1.16s.474-1.98.474-3.6c0-1.24-.082-2.25-.244-3.02s-.388-1.32-.676-1.66c-.29-.334-.64-.502-1.05-.502zm.04-.69c1.18 0 2.06.458 2.64 1.37.578.914.866 2.29.866 4.14 0 1.91-.308 3.36-.928 4.34-.618.982-1.52 1.47-2.71 1.47-1.17 0-2.04-.46-2.61-1.38s-.856-2.31-.856-4.18c0-.994.088-1.85.264-2.58s.42-1.32.738-1.8c.316-.472.694-.822 1.14-1.05.442-.228.926-.342 1.45-.342z\"/>\n <path d=\"m273 156 3.23 7.28v.598l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29.868-.292z\"/>\n <path d=\"m156 45.5h1.25v15.1h-1.25z\"/>\n <path d=\"m164 45.9h.446c-.032.519-.05 1.24-.05 2.16v6.92c0 .313.018.55.054.709.034.159.096.289.186.389s.218.178.384.235c.168.0568.38.1.634.13.254.0298.588.05 1 .0608v.592h-5.99v-.592c.6-.027 1.03-.0634 1.29-.109.256-.0458.452-.115.586-.207.136-.0918.234-.222.296-.389.062-.168.094-.44.094-.819v-6.57c0-.216-.038-.374-.114-.474s-.186-.15-.332-.15c-.172 0-.418.0892-.738.267-.318.178-.712.424-1.18.738l-.356-.624 3.79-2.26z\"/>\n <path d=\"m170 44.8 3.23 7.28v.6l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m224 88.4h1.25v15.1h-1.25z\"/>\n <path d=\"m233 90h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42z\"/>\n <path d=\"m242 87.6 3.23 7.28v.6l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m224 222h1.25v15.1h-1.25z\"/>\n <path d=\"m229 228h9.99v1.08h-9.99z\"/>\n <path d=\"m242 221 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m149 265h9.99v1.08h-9.99z\"/>\n <path d=\"m162 259h1.25v15.1h-1.25z\"/>\n <path d=\"m171 259h.446c-.032.52-.05 1.24-.05 2.16v6.92c0 .314.018.55.054.71.034.16.096.29.186.39s.218.178.386.234c.166.056.378.1.632.13s.588.05 1 .06v.592h-5.99v-.592c.6-.026 1.03-.062 1.29-.108.256-.046.452-.116.586-.208.136-.092.234-.222.296-.388.062-.168.094-.44.094-.82v-6.57c0-.216-.038-.374-.114-.474s-.186-.15-.332-.15c-.172 0-.418.088-.738.266-.318.178-.712.424-1.18.738l-.358-.624 3.79-2.26z\"/>\n <path d=\"m176 258 3.23 7.28v.6l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m44.7 163h9.99v1.08h-9.99z\"/>\n <path d=\"m57.9 156h1.25v15.1h-1.25z\"/>\n <path d=\"m65.7 157c-.373 0-.685.11-.936.332s-.454.54-.608.956-.264.924-.328 1.52c-.0648.598-.0972 1.27-.0972 2.02 0 1.76.163 3.05.49 3.88.327.824.833 1.24 1.52 1.24.654 0 1.14-.386 1.45-1.16.316-.776.474-1.98.474-3.6 0-1.24-.081-2.25-.243-3.02s-.388-1.32-.677-1.66c-.289-.334-.639-.502-1.05-.502zm.0406-.69c1.18 0 2.06.458 2.64 1.37.578.914.867 2.29.867 4.14 0 1.91-.309 3.36-.928 4.34-.619.982-1.52 1.47-2.71 1.47-1.17 0-2.04-.46-2.61-1.38-.57-.918-.855-2.31-.855-4.18 0-.994.0878-1.85.263-2.58s.422-1.32.738-1.8c.316-.472.696-.822 1.14-1.05.443-.228.927-.342 1.45-.342z\"/>\n <path d=\"m72 156 3.23 7.28v.598l-3.23 7.29-.867-.308 2.6-7.28-2.6-7.29.867-.292z\"/>\n <path d=\"m74.1 228h9.99v1.08h-9.99z\"/>\n <path d=\"m87.3 221h1.25v15.1h-1.25z\"/>\n <path d=\"m96.2 223h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42z\"/>\n <path d=\"m105 220 3.23 7.28v.598l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29.868-.292z\"/>\n <path d=\"m73.4 94.2h9.99v1.08h-9.99z\"/>\n <path d=\"m86.6 87.9h1.25v15.1h-1.25z\"/>\n <path d=\"m91.1 94.2h9.99v1.08h-9.99z\"/>\n <path d=\"m104 87.2 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m608 156h1.25v15.1h-1.25z\"/>\n <path d=\"m616 157c-.374 0-.686.11-.936.332-.252.222-.454.54-.608.956s-.264.924-.328 1.52c-.066.598-.098 1.27-.098 2.02 0 1.76.164 3.05.49 3.88.328.824.834 1.24 1.52 1.24.654 0 1.14-.386 1.46-1.16s.474-1.98.474-3.6c0-1.24-.082-2.25-.244-3.02s-.388-1.32-.676-1.66c-.29-.334-.64-.502-1.05-.502zm.04-.69c1.18 0 2.06.458 2.64 1.37.578.914.868 2.29.868 4.14 0 1.91-.31 3.36-.928 4.34-.618.982-1.52 1.47-2.71 1.47-1.17 0-2.04-.46-2.61-1.38s-.854-2.31-.854-4.18c0-.994.088-1.85.262-2.58.176-.724.422-1.32.738-1.8.316-.472.696-.822 1.14-1.05.442-.228.926-.342 1.45-.342z\"/>\n <path d=\"m622 156 3.23 7.28v.598l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29.868-.292z\"/>\n <path d=\"m505 45.5h1.25v15.1h-1.25z\"/>\n <path d=\"m514 45.9h.444c-.032.519-.048 1.24-.048 2.16v6.92c0 .313.018.55.054.709.034.159.096.289.186.389.088.1.216.178.384.235s.378.1.632.13c.254.0298.59.05 1.01.0608v.592h-5.99v-.592c.6-.027 1.03-.0634 1.28-.109.258-.0458.454-.115.588-.207.136-.0918.234-.222.296-.389.062-.168.094-.44.094-.819v-6.57c0-.216-.038-.374-.114-.474s-.186-.15-.332-.15c-.174 0-.42.0892-.738.267-.318.178-.714.424-1.18.738l-.356-.624 3.79-2.26z\"/>\n <path d=\"m519 44.8 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m574 88.4h1.25v15.1h-1.25z\"/>\n <path d=\"m583 90h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42z\"/>\n <path d=\"m591 87.6 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m574 222h1.25v15.1h-1.25z\"/>\n <path d=\"m578 228h9.99v1.08h-9.99z\"/>\n <path d=\"m591 221 3.23 7.28v.6l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m498 265h9.99v1.08h-9.99z\"/>\n <path d=\"m511 259h1.25v15.1h-1.25z\"/>\n <path d=\"m520 259h.446c-.034.52-.05 1.24-.05 2.16v6.92c0 .314.018.55.054.71.034.16.096.29.186.39.088.1.216.178.384.234s.378.1.632.13.59.05 1.01.06v.592h-5.99v-.592c.6-.026 1.03-.062 1.28-.108.258-.046.454-.116.588-.208.136-.092.234-.222.296-.388.062-.168.094-.44.094-.82v-6.57c0-.216-.038-.374-.114-.474s-.186-.15-.332-.15c-.174 0-.42.088-.738.266s-.714.424-1.18.738l-.356-.624 3.79-2.26z\"/>\n <path d=\"m525 258 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m394 163h9.99v1.08h-9.99z\"/>\n <path d=\"m407 156h1.25v15.1h-1.25z\"/>\n <path d=\"m415 157c-.374 0-.686.11-.936.332-.252.222-.454.54-.608.956s-.264.924-.328 1.52c-.066.598-.098 1.27-.098 2.02 0 1.76.164 3.05.49 3.88.328.824.834 1.24 1.52 1.24.654 0 1.14-.386 1.45-1.16.318-.776.476-1.98.476-3.6 0-1.24-.082-2.25-.244-3.02s-.388-1.32-.676-1.66c-.29-.334-.64-.502-1.05-.502zm.04-.69c1.18 0 2.06.458 2.64 1.37.578.914.868 2.29.868 4.14 0 1.91-.31 3.36-.928 4.34-.62.982-1.52 1.47-2.71 1.47-1.17 0-2.04-.46-2.61-1.38s-.854-2.31-.854-4.18c0-.994.088-1.85.262-2.58.176-.724.422-1.32.738-1.8.316-.472.696-.822 1.14-1.05.442-.228.926-.342 1.45-.342z\"/>\n <path d=\"m421 156 3.23 7.28v.598l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29.866-.292z\"/>\n <path d=\"m423 228h9.99v1.08h-9.99z\"/>\n <path d=\"m436 221h1.25v15.1h-1.25z\"/>\n <path d=\"m445 223h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42z\"/>\n <path d=\"m454 220 3.23 7.28v.598l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29.868-.292z\"/>\n <path d=\"m423 94.2h9.99v1.08h-9.99z\"/>\n <path d=\"m436 87.9h1.25v15.1h-1.25z\"/>\n <path d=\"m440 94.2h9.99v1.08h-9.99z\"/>\n <path d=\"m453 87.2 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n </g>\n</svg>\n\n2. Apply the oracle. \n Here, the difference between the two scenarios becomes noticeable. In the constant scenario, $\\ket{0}$ and $\\ket{1}$ states get the same phase (either $1$ or $-1$), so the state remains the same or acquires a global phase of $-1$, which is physically the same state. In the variable scenario, zero and one states get different phases, so the state changes!\n <br/>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"685\" height=\"380\" fill=\"none\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n<style>\n/* Default values, or theme set explicitly to light */\n:root, [data-theme=\"light\"] {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n}\n/* User has set OS preference for dark. (An explict light theme will override) */\n@media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n}\n/* Explicit dark theme set (should match above dark preference values) */\n[data-theme=\"dark\"] {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n}\n/*** Kata specific styles ***/\n.kata_svg_path {\n stroke: var(--kata-svg-path);\n stroke-width: 2;\n stroke-linecap: round;\n fill: none;\n}\n.kata_svg_text {\n fill: var(--kata-svg-stroke);\n}\n.kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n}\n.kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n}\n.kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n}\n</style>\n <!-- Large circles -->\n <g class=\"kata_svg_path\">\n <path d=\"m24.1 163c0-76.8 62.3-139 139-139 76.8 0 139 62.3 139 139 0 76.8-62.3 139-139 139-76.8 0-139-62.3-139-139z\"/>\n <path d=\"m375 163c0-76.8 62.2-139 139-139s139 62.3 139 139c0 76.8-62.2 139-139 139s-139-62.3-139-139z\"/>\n </g>\n <!-- Normal points -->\n <g class=\"kata_svg_point\">\n <path d=\"m157 23.8c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m157 302c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m257 260c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m57.3 66.6c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m647 163c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m369 163c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m408 260c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m296 163c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m18 163c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m508 23.7c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m508 302c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n </g>\n <!-- Target points -->\n <g class=\"kata_svg_fill_accent\">\n <path d=\"m257 66.6c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m57.3 260c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m608 260c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m408 66.6c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n </g>\n <!-- From point -->\n <g class=\"kata_svg_point kata_svg_stroke_accent\">\n <path d=\"m608 66.6c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n </g>\n <!-- Arrows -->\n <g class=\"kata_svg_path kata_svg_stroke_accent\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\n <path d=\"m269.59 66.574h13.076v-21.506h-19.622v14.449l5.1379-6.8441-5.1379 6.8522-6.4917-6.8522\" image-rendering=\"auto\"/>\n <path d=\"m614.87 59.292.6231-55.409h-201.62v55.688l-4.9896-4.7393 4.9896 4.8536 5.062-4.8536\" image-rendering=\"auto\"/>\n <path d=\"m214.6 107.51-104.64 104.38 8.787-.26203-8.787.26203.0944-8.0595\" image-rendering=\"auto\"/>\n <path d=\"m620.69 66.395h51.003v193.29h-50.926l5.8-5.9628-5.8 5.9628 5.8 5.8634\" image-rendering=\"auto\"/>\n </g>\n <!-- Equation text -->\n <g class=\"kata_svg_fill_accent\" clip-rule=\"evenodd\" fill-rule=\"evenodd\">\n <path d=\"m253 18.1c.516 0 .962.0422 1.34.126l-.308 1.34h-.696c-.074-.301-.17-.517-.288-.649-.12-.132-.294-.198-.526-.198-.302 0-.556.083-.764.249s-.386.413-.534.74-.284.767-.412 1.32l-.196.862h2.03l-.174.799h-2.04l-1.47 6.9c-.242 1.14-.614 2-1.12 2.56-.5.562-1.13.842-1.89.842-.222 0-.396-.0132-.522-.0396l.134-.696c.054.0158.178.0236.372.0236.238 0 .44-.0606.61-.182.168-.121.324-.332.47-.633.144-.3.278-.717.4-1.25l1.7-7.52h-1.34l.118-.546c.354-.0212.608-.0502.764-.087.154-.037.276-.0924.364-.166.086-.0738.16-.17.22-.289.062-.119.138-.336.234-.653.28-.949.71-1.66 1.29-2.14.582-.477 1.32-.716 2.23-.716z\"/>\n <path d=\"m272 17.3c1.54.406 2.72 1.28 3.55 2.63.826 1.35 1.24 2.97 1.24 4.88s-.41 3.53-1.23 4.88c-.822 1.34-2.01 2.22-3.55 2.62l-.19-.609c1.22-.406 2.12-1.21 2.72-2.4.594-1.2.89-2.72.89-4.56 0-1.78-.296-3.26-.886-4.44s-1.51-1.97-2.74-2.38l.214-.609zm-10.1 0 .214.609c-1.23.406-2.15 1.2-2.74 2.38-.592 1.18-.89 2.66-.89 4.44 0 1.85.298 3.37.89 4.56.594 1.2 1.5 2 2.72 2.4l-.19.609c-1.55-.406-2.73-1.28-3.55-2.62-.822-1.34-1.23-2.97-1.23-4.88 0-1.9.412-3.53 1.24-4.88s2.01-2.22 3.55-2.63z\"/>\n <path d=\"m265 21.7c.162 0 .306.0184.43.0554.124.0368.234.0936.328.17.096.0764.18.175.254.297s.144.286.214.494c.068.208.132.467.194.775.06.308.114.629.162.961h.078c.506-.712.89-1.23 1.15-1.56s.48-.575.66-.736.352-.274.518-.34c.166-.0658.386-.0988.66-.0988.248 0 .452.0316.61.0948l-.316 1.43h-.554c-.032-.221-.124-.332-.278-.332-.046 0-.098.0078-.15.0238-.052.0158-.118.05-.194.103-.076.0526-.188.156-.336.308-.148.153-.314.34-.498.562s-.374.454-.57.696l-.538.672c.096.506.186.944.27 1.31s.158.676.224.922.124.439.174.581c.052.142.106.249.164.32.058.0712.116.121.178.15.06.029.13.0434.208.0434.144 0 .282-.0552.416-.166s.328-.361.582-.751l.514.34c-.37.548-.704.935-1 1.16-.298.224-.652.336-1.06.336-.226 0-.418-.0408-.576-.123-.158-.0816-.296-.212-.412-.391s-.218-.459-.308-.839c-.164-.675-.264-1.19-.3-1.55h-.08c-.558.786-.974 1.35-1.25 1.69s-.496.596-.672.759-.348.278-.514.344-.386.099-.66.099c-.248 0-.452-.0316-.61-.095l.316-1.43h.554c.032.221.124.332.278.332.072 0 .15-.0198.232-.0594s.2-.134.352-.285c.154-.15.364-.386.634-.708.268-.322.658-.804 1.17-1.45-.08-.417-.16-.817-.246-1.2-.084-.385-.17-.744-.26-1.08s-.164-.55-.222-.653-.12-.174-.186-.214-.148-.0592-.248-.0592c-.112 0-.212.025-.302.075-.09.0502-.186.137-.292.261s-.246.318-.42.581l-.514-.34c.332-.501.652-.875.958-1.12.306-.248.666-.372 1.08-.372z\"/>\n <path d=\"m284 25.9h9.75v1.05h-9.75zm0-3.28h9.75v1.05h-9.75z\"/>\n <path d=\"m303 19.2c-.364 0-.668.108-.914.324-.244.216-.442.527-.592.933s-.258.901-.32 1.48c-.064.583-.096 1.24-.096 1.97 0 1.72.16 2.98.478 3.78.32.804.814 1.21 1.48 1.21.638 0 1.11-.378 1.42-1.14s.462-1.93.462-3.52c0-1.21-.078-2.2-.236-2.95-.16-.751-.38-1.29-.662-1.62s-.622-.49-1.02-.49zm.04-.672c1.15 0 2.01.446 2.58 1.34s.846 2.24.846 4.04c0 1.87-.3 3.28-.904 4.24s-1.49 1.44-2.65 1.44c-1.14 0-1.99-.448-2.54-1.34-.556-.897-.834-2.26-.834-4.08 0-.97.086-1.81.256-2.52.172-.707.412-1.29.72-1.75.31-.461.68-.803 1.11-1.02s.904-.332 1.42-.332z\"/>\n <path d=\"m110.47 136.35c.53 0 .986.043 1.37.13l-.316 1.38h-.713c-.0756-.308-.174-.53-.296-.665s-.301-.203-.539-.203c-.308 0-.569.085-.782.256-.213.17-.396.422-.547.758-.151.334-.292.786-.422 1.35l-.203.882h2.08l-.178.82h-2.09l-1.51 7.07c-.249 1.17-.63 2.05-1.14 2.62-.513.574-1.16.862-1.94.862-.227 0-.405-.012-.535-.04l.138-.714c.054.016.181.026.381.026.243 0 .451-.064.624-.188s.334-.34.482-.648.285-.734.409-1.28l1.74-7.71h-1.37l.122-.56c.362-.022.623-.052.782-.09s.284-.094.373-.17c.0892-.076.165-.174.227-.296.0622-.12.142-.344.239-.668.286-.972.728-1.7 1.33-2.19.597-.489 1.36-.734 2.28-.734z\"/>\n <path d=\"m129.17 135.35c1.58.416 2.79 1.31 3.64 2.7.846 1.38 1.27 3.05 1.27 5 0 1.96-.422 3.62-1.26 5-.843 1.37-2.06 2.27-3.64 2.69l-.195-.624c1.25-.416 2.18-1.24 2.78-2.46.608-1.23.911-2.79.911-4.68 0-1.83-.302-3.34-.907-4.55-.606-1.21-1.54-2.02-2.81-2.44l.219-.624zm-10.3 0 .219.624c-1.26.416-2.2 1.23-2.81 2.44-.608 1.21-.912 2.73-.912 4.55 0 1.89.304 3.45.912 4.68s1.54 2.05 2.78 2.46l-.194.624c-1.58-.416-2.8-1.31-3.64-2.69-.843-1.38-1.26-3.04-1.26-5 0-1.95.423-3.62 1.27-5 .846-1.38 2.06-2.28 3.64-2.7z\"/>\n <path d=\"m122.17 140.35c.168 0 .315.02.442.058s.239.096.336.174c.098.078.184.18.26.304.075.124.148.292.219.506.07.214.136.478.198.794s.118.646.166.986h.081c.519-.73.912-1.26 1.18-1.6.267-.338.493-.588.677-.754.183-.164.36-.28.53-.348.171-.068.396-.1.677-.1.254 0 .462.032.624.096l-.324 1.47h-.567c-.033-.228-.127-.342-.284-.342-.049 0-.1.01-.154.026s-.12.05-.199.104c-.078.054-.193.16-.344.316-.151.158-.322.35-.511.576-.189.228-.383.464-.583.714l-.551.688c.097.52.189.968.275 1.35.087.378.164.694.231.944.068.252.127.45.178.596.052.146.107.256.167.328.059.074.12.124.182.154s.134.044.215.044c.146 0 .288-.056.425-.17.138-.112.337-.37.596-.77l.527.35c-.378.562-.72.956-1.02 1.19-.306.23-.669.346-1.09.346-.232 0-.429-.042-.591-.126s-.303-.218-.422-.402-.224-.47-.316-.858c-.167-.692-.27-1.22-.308-1.59h-.081c-.573.806-.998 1.38-1.28 1.73-.278.352-.507.612-.689.78-.181.166-.356.284-.526.352-.171.068-.396.102-.677.102-.254 0-.462-.034-.624-.098l.324-1.47h.567c.033.228.127.342.284.342.076 0 .155-.022.239-.062s.204-.138.361-.292.373-.396.648-.724c.276-.33.676-.824 1.2-1.48-.081-.428-.165-.838-.251-1.23-.087-.394-.176-.762-.268-1.1-.092-.342-.167-.564-.227-.67-.059-.104-.123-.178-.19-.218-.068-.04-.153-.06-.256-.06-.113 0-.216.024-.308.076s-.191.14-.3.268c-.108.126-.251.326-.429.596l-.527-.35c.34-.512.667-.896.981-1.15.313-.254.683-.382 1.11-.382z\"/>\n <path d=\"m141.17 144.35h9.99v1.08h-9.99zm0-3.36h9.99v1.08h-9.99z\"/>\n <path d=\"m162.17 136.35h.446c-.032.519-.048 1.24-.048 2.16v6.92c0 .314.018.55.052.71.036.158.098.288.186.388.09.1.218.178.386.236.168.056.378.1.632.128.254.03.588.05 1 .062v.592h-5.99v-.592c.6-.028 1.03-.064 1.29-.11s.452-.114.588-.206c.134-.092.234-.222.296-.39.062-.166.092-.44.092-.818v-6.57c0-.216-.038-.374-.114-.474-.074-.1-.186-.15-.332-.15-.172 0-.418.09-.736.268-.32.178-.714.424-1.18.738l-.358-.624 3.79-2.26z\"/>\n <path d=\"m616.79 271.85c.516 0 .962.044 1.34.128l-.308 1.34h-.696c-.074-.3-.17-.516-.288-.648-.12-.132-.294-.198-.528-.198-.3 0-.554.082-.762.248-.208.168-.386.414-.534.74-.148.328-.286.768-.412 1.32l-.198.862h2.03l-.174.798h-2.04l-1.47 6.9c-.244 1.14-.614 2-1.12 2.56-.5.56-1.13.842-1.89.842-.222 0-.396-.014-.522-.04l.134-.696c.052.016.176.024.372.024.238 0 .44-.06.608-.182.17-.122.326-.332.472-.632.144-.302.278-.718.398-1.25l1.7-7.52h-1.34l.12-.546c.352-.02.608-.05.762-.086.156-.038.278-.092.364-.166.088-.074.162-.17.222-.288.06-.12.138-.338.234-.654.278-.948.71-1.66 1.29-2.14.584-.476 1.33-.716 2.23-.716z\"/>\n <path d=\"m634.79 270.85c1.54.406 2.72 1.28 3.55 2.63.826 1.35 1.24 2.97 1.24 4.88s-.412 3.53-1.23 4.88-2.01 2.22-3.55 2.62l-.19-.608c1.22-.406 2.12-1.21 2.72-2.41.594-1.2.89-2.72.89-4.56 0-1.78-.296-3.26-.886-4.44s-1.51-1.97-2.74-2.38l.212-.608zm-10.1 0 .212.608c-1.23.406-2.15 1.2-2.74 2.38-.594 1.18-.89 2.66-.89 4.44 0 1.85.296 3.37.89 4.56.594 1.2 1.5 2 2.72 2.41l-.19.608c-1.55-.406-2.73-1.28-3.55-2.62-.824-1.34-1.23-2.97-1.23-4.88 0-1.9.412-3.53 1.24-4.88.824-1.35 2.01-2.22 3.55-2.63z\"/>\n <path d=\"m628.79 275.85c.164 0 .308.018.432.054.124.038.234.094.328.17.096.078.18.176.254.298.074.12.144.286.212.494.07.208.134.466.194.774.062.31.116.63.162.962h.08c.506-.712.89-1.23 1.15-1.56.262-.33.482-.576.662-.736.178-.16.352-.274.518-.34s.386-.098.66-.098c.248 0 .45.03.61.094l-.318 1.43h-.554c-.03-.222-.122-.332-.276-.332-.048 0-.098.008-.15.024s-.118.05-.194.102-.188.156-.336.308c-.148.154-.314.34-.498.562-.186.222-.374.454-.57.696l-.538.672c.094.506.184.944.27 1.31.084.368.158.676.224.922.066.244.124.438.174.58.05.144.104.25.162.322.058.07.118.12.178.15.062.028.132.042.21.042.142 0 .282-.054.416-.166.134-.11.328-.36.58-.75l.516.34c-.37.548-.704.934-1 1.16s-.652.336-1.06.336c-.226 0-.418-.04-.576-.122-.16-.082-.296-.212-.412-.392s-.22-.458-.308-.838c-.164-.676-.264-1.19-.302-1.55h-.078c-.56.786-.974 1.35-1.25 1.69s-.496.596-.672.76c-.178.164-.348.278-.514.344s-.388.098-.662.098c-.248 0-.45-.032-.608-.094l.316-1.43h.554c.032.222.124.332.276.332.074 0 .152-.02.234-.06.082-.038.2-.134.352-.284s.364-.386.632-.708c.27-.322.66-.804 1.17-1.45-.08-.416-.162-.816-.246-1.2s-.172-.744-.26-1.08c-.09-.332-.164-.55-.222-.652-.058-.104-.12-.174-.186-.214s-.15-.06-.25-.06c-.11 0-.21.026-.3.076s-.188.138-.292.262c-.106.122-.246.316-.42.58l-.514-.34c.332-.5.652-.876.958-1.12.304-.248.666-.372 1.08-.372z\"/>\n <path d=\"m646.79 279.85h9.75v1.05h-9.75zm0-3.28h9.75v1.05h-9.75z\"/>\n <path d=\"m665.79 275.85c.162 0 .306.018.43.054.124.038.234.094.328.17.096.078.18.176.254.298.074.12.144.286.214.494.068.208.132.466.194.774.06.31.114.63.162.962h.078c.506-.712.89-1.23 1.15-1.56s.48-.576.66-.736.352-.274.518-.34.386-.098.66-.098c.248 0 .452.03.61.094l-.316 1.43h-.554c-.032-.222-.124-.332-.278-.332-.046 0-.096.008-.15.024-.052.016-.118.05-.194.102s-.188.156-.336.308c-.148.154-.314.34-.498.562s-.374.454-.57.696l-.538.672c.096.506.186.944.27 1.31.084.368.16.676.224.922.066.244.124.438.174.58.052.144.106.25.164.322.058.07.116.12.178.15.06.028.13.042.208.042.144 0 .282-.054.416-.166.134-.11.328-.36.582-.75l.514.34c-.37.548-.704.934-1 1.16s-.652.336-1.06.336c-.228 0-.42-.04-.578-.122s-.296-.212-.412-.392-.218-.458-.308-.838c-.164-.676-.264-1.19-.3-1.55h-.08c-.558.786-.974 1.35-1.25 1.69s-.496.596-.672.76-.348.278-.514.344-.386.098-.66.098c-.248 0-.452-.032-.61-.094l.316-1.43h.554c.032.222.124.332.278.332.072 0 .15-.02.232-.06.082-.038.2-.134.352-.284.154-.15.364-.386.634-.708.268-.322.658-.804 1.17-1.45-.08-.416-.16-.816-.246-1.2-.084-.384-.17-.744-.26-1.08s-.164-.55-.222-.652c-.058-.104-.12-.174-.186-.214s-.148-.06-.248-.06c-.112 0-.212.026-.302.076s-.186.138-.292.262c-.106.122-.246.316-.42.58l-.514-.34c.332-.5.652-.876.958-1.12.306-.248.666-.372 1.08-.372z\"/>\n <path d=\"m484.16 7.6428c.516 0 .962.0422 1.34.127l-.308 1.34h-.696c-.074-.301-.17-.517-.288-.649-.12-.132-.294-.198-.526-.198-.302 0-.556.083-.764.249s-.386.413-.534.74-.284.767-.412 1.32l-.198.862h2.03l-.174.799h-2.04l-1.47 6.9c-.244 1.14-.614 2-1.12 2.56-.5.562-1.13.842-1.89.842-.222 0-.396-.0132-.522-.0394l.134-.696c.052.0158.176.0238.372.0238.238 0 .44-.0606.608-.182.17-.121.326-.332.472-.633.144-.301.278-.717.4-1.25l1.7-7.52h-1.34l.12-.546c.352-.021.608-.05.762-.087.156-.0368.278-.0922.364-.166.088-.074.162-.17.222-.289s.138-.336.234-.653c.28-.949.71-1.66 1.29-2.14.584-.477 1.33-.716 2.23-.716z\"/>\n <path d=\"m503.16 6.8728c1.54.406 2.72 1.28 3.55 2.63.826 1.35 1.24 2.97 1.24 4.88s-.41 3.53-1.23 4.88c-.822 1.34-2.01 2.22-3.55 2.62l-.19-.609c1.22-.406 2.12-1.21 2.72-2.4s.89-2.72.89-4.56c0-1.78-.296-3.26-.886-4.44-.59-1.18-1.51-1.97-2.74-2.38l.212-.609zm-10.1 0 .212.609c-1.23.406-2.15 1.2-2.74 2.38-.594 1.18-.89 2.66-.89 4.44 0 1.85.296 3.37.89 4.56s1.5 2 2.72 2.4l-.19.609c-1.55-.406-2.73-1.28-3.55-2.62-.824-1.34-1.23-2.97-1.23-4.88 0-1.9.412-3.53 1.24-4.88.824-1.35 2.01-2.22 3.55-2.63z\"/>\n <path d=\"m496.16 11.263c.164 0 .308.0184.432.0554s.234.0936.328.17c.096.0766.18.175.254.297.074.121.144.286.212.494.07.208.134.467.194.775.062.309.116.629.162.961h.08c.506-.712.89-1.23 1.15-1.56.262-.33.482-.575.662-.736.178-.161.352-.274.518-.34s.386-.099.66-.099c.248 0 .45.0318.61.095l-.318 1.43h-.552c-.032-.222-.124-.332-.278-.332-.048 0-.098.008-.15.0238s-.118.0502-.194.103-.188.156-.336.309-.314.34-.498.562c-.186.221-.374.453-.57.696l-.538.672c.096.506.184.944.27 1.31.084.369.158.676.224.921s.124.439.174.581.104.249.162.32.118.121.178.15c.062.029.132.0434.21.0434.142 0 .282-.0554.416-.166.134-.111.328-.361.58-.751l.516.34c-.37.548-.704.935-1 1.16s-.652.336-1.06.336c-.226 0-.418-.0408-.576-.123-.16-.0818-.296-.212-.412-.392-.116-.179-.22-.459-.308-.838-.164-.675-.264-1.19-.302-1.55h-.078c-.56.786-.974 1.35-1.25 1.69s-.496.596-.672.759c-.178.163-.348.278-.514.344s-.388.0988-.662.0988c-.248 0-.45-.0316-.608-.0948l.316-1.43h.554c.032.222.124.332.276.332.074 0 .152-.0198.234-.0592.082-.0396.2-.135.352-.285s.364-.386.632-.708c.27-.322.66-.804 1.17-1.45-.08-.417-.162-.817-.246-1.2-.084-.385-.172-.743-.26-1.08-.09-.332-.164-.55-.222-.653s-.12-.174-.186-.214c-.066-.0396-.15-.0594-.25-.0594-.11 0-.21.025-.3.0752-.09.05-.188.137-.292.261-.106.124-.246.318-.42.581l-.514-.34c.332-.501.652-.875.958-1.12s.666-.372 1.08-.372z\"/>\n <path d=\"m515.16 15.463h9.75v1.05h-9.75zm0-3.28h9.75v1.05h-9.75z\"/>\n <path d=\"m531.16 13.763h9.74v5.58h-1.12v-4.54h-8.62z\"/>\n <path d=\"m545.16 11.263c.164 0 .308.0184.432.0554s.234.0936.328.17c.094.0766.18.175.254.297.072.121.144.286.212.494.07.208.134.467.194.775.062.309.116.629.162.961h.08c.506-.712.89-1.23 1.15-1.56.262-.33.482-.575.662-.736.178-.161.352-.274.518-.34s.386-.099.66-.099c.248 0 .45.0318.608.095l-.316 1.43h-.554c-.03-.222-.124-.332-.276-.332-.048 0-.098.008-.15.0238-.054.0158-.118.0502-.194.103s-.188.156-.336.309-.314.34-.498.562c-.186.221-.376.453-.57.696l-.538.672c.094.506.184.944.268 1.31.086.369.16.676.226.921s.124.439.174.581.104.249.162.32.118.121.178.15c.062.029.13.0434.21.0434.142 0 .28-.0554.416-.166.134-.111.328-.361.58-.751l.514.34c-.368.548-.702.935-1 1.16s-.652.336-1.06.336c-.226 0-.418-.0408-.578-.123-.158-.0818-.294-.212-.41-.392-.116-.179-.22-.459-.308-.838-.164-.675-.264-1.19-.302-1.55h-.078c-.56.786-.974 1.35-1.25 1.69s-.496.596-.672.759c-.178.163-.348.278-.514.344-.168.066-.388.0988-.662.0988-.248 0-.45-.0316-.608-.0948l.316-1.43h.554c.032.222.124.332.276.332.074 0 .152-.0198.234-.0592.082-.0396.198-.135.352-.285.152-.15.364-.386.632-.708.27-.322.66-.804 1.17-1.45-.08-.417-.162-.817-.246-1.2-.084-.385-.172-.743-.26-1.08-.09-.332-.164-.55-.222-.653s-.12-.174-.186-.214c-.066-.0396-.15-.0594-.25-.0594-.11 0-.21.025-.3.0752-.09.05-.188.137-.292.261-.106.124-.246.318-.42.581l-.514-.34c.332-.501.652-.875.956-1.12.306-.248.668-.372 1.08-.372z\"/>\n </g>\n <g class=\"kata_svg_text\">\n <!-- Legend text -->\n <path d=\"m135 350c-.94.455-2.17.683-3.68.683-1.98 0-3.53-.581-4.66-1.74s-1.7-2.71-1.7-4.64c0-2.06.635-3.73 1.9-5.01 1.28-1.28 2.93-1.92 4.96-1.92 1.26 0 2.32.159 3.18.476v2.79c-.862-.515-1.84-.773-2.95-.773-1.21 0-2.19.381-2.93 1.14-.743.761-1.11 1.79-1.11 3.09 0 1.25.35 2.24 1.05 2.98.7.737 1.64 1.1 2.83 1.1 1.13 0 2.17-.276 3.11-.827v2.65zm6.35.683c-1.53 0-2.74-.429-3.62-1.28-.875-.863-1.31-2.03-1.31-3.5 0-1.52.455-2.71 1.37-3.57.91-.862 2.14-1.29 3.69-1.29 1.53 0 2.72.432 3.59 1.29.868.857 1.3 1.99 1.3 3.4 0 1.53-.45 2.73-1.35 3.62-.893.886-2.12 1.33-3.68 1.33zm.072-7.48c-.671 0-1.19.23-1.56.691-.371.462-.557 1.11-.557 1.96 0 1.77.713 2.65 2.14 2.65 1.36 0 2.04-.907 2.04-2.72 0-1.72-.686-2.58-2.06-2.58zm15.7 7.25h-2.83v-5.11c0-1.43-.509-2.14-1.53-2.14-.492 0-.896.188-1.21.566-.318.377-.477.856-.477 1.44v5.25h-2.84v-9.2h2.84v1.46h.036c.677-1.12 1.66-1.68 2.96-1.68 2.04 0 3.06 1.26 3.06 3.79v5.63zm1.65-.243v-2.3c.467.282.931.492 1.39.629.467.138.907.207 1.32.207.503 0 .899-.069 1.19-.207.294-.137.441-.347.441-.629 0-.179-.066-.329-.198-.449s-.303-.224-.512-.314c-.204-.09-.429-.171-.674-.243-.246-.072-.482-.153-.71-.242-.365-.138-.689-.285-.97-.441-.276-.161-.509-.347-.701-.557-.186-.209-.329-.452-.431-.727-.096-.276-.144-.602-.144-.98 0-.515.111-.958.332-1.33.228-.372.528-.674.899-.908.377-.239.806-.413 1.28-.521.485-.114.988-.171 1.51-.171.407 0 .821.033 1.24.099.419.06.832.15 1.24.27v2.19c-.36-.21-.746-.365-1.16-.467-.408-.108-.809-.162-1.2-.162-.186 0-.363.018-.53.054-.162.03-.306.078-.431.144-.126.06-.225.14-.297.242-.072.096-.108.207-.108.333 0 .167.054.311.162.431s.249.225.422.314c.174.084.366.162.575.234.216.066.428.135.638.207.377.131.719.275 1.02.431.306.156.566.338.782.548.222.21.389.455.503.737.12.281.18.617.18 1.01 0 .545-.12 1.01-.36 1.4-.233.384-.548.698-.943.944-.389.239-.841.413-1.36.521-.509.114-1.04.171-1.59.171-1.01 0-1.95-.156-2.81-.468zm14.3.135c-.419.222-1.05.333-1.9.333-2 0-3-1.04-3-3.12v-4.21h-1.49v-2.09h1.49v-1.99l2.83-.808v2.79h2.07v2.09h-2.07v3.72c0 .958.38 1.44 1.14 1.44.299 0 .608-.086.925-.26v2.1zm9.26.108h-2.69v-1.32h-.036c-.617 1.03-1.53 1.55-2.74 1.55-.893 0-1.6-.252-2.11-.755-.509-.509-.763-1.19-.763-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-.333c0-1.01-.545-1.51-1.64-1.51-1.1 0-2.14.326-3.13.979v-2.14c.395-.204.934-.383 1.62-.539.689-.156 1.32-.234 1.88-.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-.62l-1.67.215c-.923.12-1.38.536-1.38 1.25 0 .323.111.59.333.8.227.203.533.305.916.305.533 0 .967-.183 1.3-.548.335-.371.503-.838.503-1.4zm13.8 3.74h-2.83v-5.11c0-1.43-.509-2.14-1.53-2.14-.491 0-.895.188-1.21.566-.317.377-.476.856-.476 1.44v5.25h-2.84v-9.2h2.84v1.46h.036c.677-1.12 1.66-1.68 2.96-1.68 2.04 0 3.06 1.26 3.06 3.79v5.63zm7.82-.108c-.419.222-1.05.333-1.9.333-2 0-3-1.04-3-3.12v-4.21h-1.49v-2.09h1.49v-1.99l2.83-.808v2.79h2.07v2.09h-2.07v3.72c0 .958.38 1.44 1.14 1.44.299 0 .608-.086.925-.26v2.1z\"/>\n <path d=\"m491 338-4.44 12.9h-3.29l-4.38-12.9h3.13l2.69 8.97c.144.485.23.913.26 1.28h.054c.042-.402.135-.842.279-1.32l2.67-8.93h3.04zm7.54 12.9h-2.69v-1.32h-.036c-.616 1.03-1.53 1.55-2.74 1.55-.892 0-1.6-.252-2.11-.755-.509-.509-.764-1.19-.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-.333c0-1.01-.545-1.51-1.64-1.51-1.1 0-2.14.326-3.13.979v-2.14c.395-.204.934-.383 1.62-.539.689-.156 1.32-.234 1.88-.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-.62l-1.67.215c-.922.12-1.38.536-1.38 1.25 0 .323.11.59.332.8.228.203.533.305.916.305.534 0 .968-.183 1.3-.548.336-.371.503-.838.503-1.4zm10.9-2.9c-.341-.186-.739-.279-1.2-.279-.616 0-1.1.228-1.45.683-.347.449-.521 1.06-.521 1.84v4.39h-2.84v-9.2h2.84v1.71h.036c.449-1.25 1.26-1.87 2.43-1.87.299 0 .533.036.7.108v2.62zm2.84-4.02c-.479 0-.871-.141-1.18-.423-.305-.287-.458-.638-.458-1.05 0-.425.153-.773.458-1.04.306-.27.698-.404 1.18-.404.486 0 .878.134 1.18.404.306.269.459.617.459 1.04 0 .431-.153.785-.459 1.06-.299.276-.691.414-1.18.414zm1.4 10.7h-2.84v-9.2h2.84zm10 0h-2.69v-1.32h-.036c-.617 1.03-1.53 1.55-2.74 1.55-.892 0-1.6-.252-2.11-.755-.509-.509-.764-1.19-.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-.333c0-1.01-.545-1.51-1.64-1.51-1.1 0-2.14.326-3.13.979v-2.14c.396-.204.935-.383 1.62-.539.688-.156 1.31-.234 1.88-.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-.62l-1.67.215c-.922.12-1.38.536-1.38 1.25 0 .323.111.59.333.8.227.203.533.305.916.305.533 0 .968-.183 1.3-.548.335-.371.503-.838.503-1.4zm7.79 2.67h-.036v1.07h-2.84v-13.6h2.84v5.8h.036c.7-1.07 1.7-1.61 2.99-1.61 1.19 0 2.1.408 2.74 1.22.641.815.961 1.93.961 3.34 0 1.53-.374 2.76-1.12 3.69s-1.75 1.39-3 1.39c-1.13 0-1.99-.432-2.57-1.29zm-.081-3.88v.943c0 .593.17 1.08.512 1.47.341.39.779.584 1.31.584.646 0 1.15-.248 1.5-.745.359-.503.539-1.21.539-2.13 0-.76-.165-1.35-.494-1.78-.324-.431-.788-.646-1.39-.646-.569 0-1.04.212-1.42.638-.372.425-.557.979-.557 1.66zm11.5 4.95h-2.84v-13.6h2.84zm10.7-3.79h-6c.096 1.34.937 2 2.52 2 1.01 0 1.9-.239 2.67-.719v2.05c-.851.455-1.96.683-3.32.683-1.48 0-2.64-.411-3.46-1.23-.82-.827-1.23-1.98-1.23-3.45 0-1.53.443-2.74 1.33-3.63.887-.892 1.98-1.34 3.27-1.34 1.34 0 2.38.399 3.11 1.2.737.797 1.1 1.88 1.1 3.24v1.2zm-2.63-1.74c0-1.32-.533-1.98-1.6-1.98-.456 0-.851.189-1.19.566-.33.377-.53.848-.602 1.41h3.39z\"/>\n <!-- Ket text -->\n <path d=\"m259 156h1.25v15.1h-1.25z\"/>\n <path d=\"m266 157c-.372 0-.684.11-.936.332s-.454.54-.608.956-.264.924-.328 1.52c-.064.598-.098 1.27-.098 2.02 0 1.76.164 3.05.49 3.88.328.824.834 1.24 1.52 1.24.654 0 1.14-.386 1.46-1.16s.474-1.98.474-3.6c0-1.24-.082-2.25-.244-3.02s-.388-1.32-.676-1.66c-.29-.334-.64-.502-1.05-.502zm.04-.69c1.18 0 2.06.458 2.64 1.37.578.914.866 2.29.866 4.14 0 1.91-.308 3.36-.928 4.34-.618.982-1.52 1.47-2.71 1.47-1.17 0-2.04-.46-2.61-1.38s-.856-2.31-.856-4.18c0-.994.088-1.85.264-2.58s.42-1.32.738-1.8c.316-.472.694-.822 1.14-1.05.442-.228.926-.342 1.45-.342z\"/>\n <path d=\"m273 156 3.23 7.28v.598l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29.868-.292z\"/>\n <path d=\"m156 45.5h1.25v15.1h-1.25z\"/>\n <path d=\"m164 45.9h.446c-.032.519-.05 1.24-.05 2.16v6.92c0 .313.018.55.054.709.034.159.096.289.186.389s.218.178.384.235c.168.0568.38.1.634.13.254.0298.588.05 1 .0608v.592h-5.99v-.592c.6-.027 1.03-.0634 1.29-.109.256-.0458.452-.115.586-.207.136-.0918.234-.222.296-.389.062-.168.094-.44.094-.819v-6.57c0-.216-.038-.374-.114-.474s-.186-.15-.332-.15c-.172 0-.418.0892-.738.267-.318.178-.712.424-1.18.738l-.356-.624 3.79-2.26z\"/>\n <path d=\"m170 44.8 3.23 7.28v.6l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m224 88.4h1.25v15.1h-1.25z\"/>\n <path d=\"m233 90h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42z\"/>\n <path d=\"m242 87.6 3.23 7.28v.6l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m224 222h1.25v15.1h-1.25z\"/>\n <path d=\"m229 228h9.99v1.08h-9.99z\"/>\n <path d=\"m242 221 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m149 265h9.99v1.08h-9.99z\"/>\n <path d=\"m162 259h1.25v15.1h-1.25z\"/>\n <path d=\"m171 259h.446c-.032.52-.05 1.24-.05 2.16v6.92c0 .314.018.55.054.71.034.16.096.29.186.39s.218.178.386.234c.166.056.378.1.632.13s.588.05 1 .06v.592h-5.99v-.592c.6-.026 1.03-.062 1.29-.108.256-.046.452-.116.586-.208.136-.092.234-.222.296-.388.062-.168.094-.44.094-.82v-6.57c0-.216-.038-.374-.114-.474s-.186-.15-.332-.15c-.172 0-.418.088-.738.266-.318.178-.712.424-1.18.738l-.358-.624 3.79-2.26z\"/>\n <path d=\"m176 258 3.23 7.28v.6l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m44.7 163h9.99v1.08h-9.99z\"/>\n <path d=\"m57.9 156h1.25v15.1h-1.25z\"/>\n <path d=\"m65.7 157c-.373 0-.685.11-.936.332s-.454.54-.608.956-.264.924-.328 1.52c-.0648.598-.0972 1.27-.0972 2.02 0 1.76.163 3.05.49 3.88.327.824.833 1.24 1.52 1.24.654 0 1.14-.386 1.45-1.16.316-.776.474-1.98.474-3.6 0-1.24-.081-2.25-.243-3.02s-.388-1.32-.677-1.66c-.289-.334-.639-.502-1.05-.502zm.0406-.69c1.18 0 2.06.458 2.64 1.37.578.914.867 2.29.867 4.14 0 1.91-.309 3.36-.928 4.34-.619.982-1.52 1.47-2.71 1.47-1.17 0-2.04-.46-2.61-1.38-.57-.918-.855-2.31-.855-4.18 0-.994.0878-1.85.263-2.58s.422-1.32.738-1.8c.316-.472.696-.822 1.14-1.05.443-.228.927-.342 1.45-.342z\"/>\n <path d=\"m72 156 3.23 7.28v.598l-3.23 7.29-.867-.308 2.6-7.28-2.6-7.29.867-.292z\"/>\n <path d=\"m74.1 228h9.99v1.08h-9.99z\"/>\n <path d=\"m87.3 221h1.25v15.1h-1.25z\"/>\n <path d=\"m96.2 223h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42z\"/>\n <path d=\"m105 220 3.23 7.28v.598l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29.868-.292z\"/>\n <path d=\"m73.4 94.2h9.99v1.08h-9.99z\"/>\n <path d=\"m86.6 87.9h1.25v15.1h-1.25z\"/>\n <path d=\"m91.1 94.2h9.99v1.08h-9.99z\"/>\n <path d=\"m104 87.2 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m608 156h1.25v15.1h-1.25z\"/>\n <path d=\"m616 157c-.374 0-.686.11-.936.332-.252.222-.454.54-.608.956s-.264.924-.328 1.52c-.066.598-.098 1.27-.098 2.02 0 1.76.164 3.05.49 3.88.328.824.834 1.24 1.52 1.24.654 0 1.14-.386 1.46-1.16s.474-1.98.474-3.6c0-1.24-.082-2.25-.244-3.02s-.388-1.32-.676-1.66c-.29-.334-.64-.502-1.05-.502zm.04-.69c1.18 0 2.06.458 2.64 1.37.578.914.868 2.29.868 4.14 0 1.91-.31 3.36-.928 4.34-.618.982-1.52 1.47-2.71 1.47-1.17 0-2.04-.46-2.61-1.38s-.854-2.31-.854-4.18c0-.994.088-1.85.262-2.58.176-.724.422-1.32.738-1.8.316-.472.696-.822 1.14-1.05.442-.228.926-.342 1.45-.342z\"/>\n <path d=\"m622 156 3.23 7.28v.598l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29.868-.292z\"/>\n <path d=\"m505 45.5h1.25v15.1h-1.25z\"/>\n <path d=\"m514 45.9h.444c-.032.519-.048 1.24-.048 2.16v6.92c0 .313.018.55.054.709.034.159.096.289.186.389.088.1.216.178.384.235s.378.1.632.13c.254.0298.59.05 1.01.0608v.592h-5.99v-.592c.6-.027 1.03-.0634 1.28-.109.258-.0458.454-.115.588-.207.136-.0918.234-.222.296-.389.062-.168.094-.44.094-.819v-6.57c0-.216-.038-.374-.114-.474s-.186-.15-.332-.15c-.174 0-.42.0892-.738.267-.318.178-.714.424-1.18.738l-.356-.624 3.79-2.26z\"/>\n <path d=\"m519 44.8 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m574 88.4h1.25v15.1h-1.25z\"/>\n <path d=\"m583 90h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42z\"/>\n <path d=\"m591 87.6 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m574 222h1.25v15.1h-1.25z\"/>\n <path d=\"m578 228h9.99v1.08h-9.99z\"/>\n <path d=\"m591 221 3.23 7.28v.6l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m498 265h9.99v1.08h-9.99z\"/>\n <path d=\"m511 259h1.25v15.1h-1.25z\"/>\n <path d=\"m520 259h.446c-.034.52-.05 1.24-.05 2.16v6.92c0 .314.018.55.054.71.034.16.096.29.186.39.088.1.216.178.384.234s.378.1.632.13.59.05 1.01.06v.592h-5.99v-.592c.6-.026 1.03-.062 1.28-.108.258-.046.454-.116.588-.208.136-.092.234-.222.296-.388.062-.168.094-.44.094-.82v-6.57c0-.216-.038-.374-.114-.474s-.186-.15-.332-.15c-.174 0-.42.088-.738.266s-.714.424-1.18.738l-.356-.624 3.79-2.26z\"/>\n <path d=\"m525 258 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m394 163h9.99v1.08h-9.99z\"/>\n <path d=\"m407 156h1.25v15.1h-1.25z\"/>\n <path d=\"m415 157c-.374 0-.686.11-.936.332-.252.222-.454.54-.608.956s-.264.924-.328 1.52c-.066.598-.098 1.27-.098 2.02 0 1.76.164 3.05.49 3.88.328.824.834 1.24 1.52 1.24.654 0 1.14-.386 1.45-1.16.318-.776.476-1.98.476-3.6 0-1.24-.082-2.25-.244-3.02s-.388-1.32-.676-1.66c-.29-.334-.64-.502-1.05-.502zm.04-.69c1.18 0 2.06.458 2.64 1.37.578.914.868 2.29.868 4.14 0 1.91-.31 3.36-.928 4.34-.62.982-1.52 1.47-2.71 1.47-1.17 0-2.04-.46-2.61-1.38s-.854-2.31-.854-4.18c0-.994.088-1.85.262-2.58.176-.724.422-1.32.738-1.8.316-.472.696-.822 1.14-1.05.442-.228.926-.342 1.45-.342z\"/>\n <path d=\"m421 156 3.23 7.28v.598l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29.866-.292z\"/>\n <path d=\"m423 228h9.99v1.08h-9.99z\"/>\n <path d=\"m436 221h1.25v15.1h-1.25z\"/>\n <path d=\"m445 223h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42z\"/>\n <path d=\"m454 220 3.23 7.28v.598l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29.868-.292z\"/>\n <path d=\"m423 94.2h9.99v1.08h-9.99z\"/>\n <path d=\"m436 87.9h1.25v15.1h-1.25z\"/>\n <path d=\"m440 94.2h9.99v1.08h-9.99z\"/>\n <path d=\"m453 87.2 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n </g>\n</svg>\n\n3. Apply the $H$ gate to the qubit again.\n Now, you get the $\\ket{0}$ state for both constant scenarios and the $\\ket{1}$ state for both variable scenarios!\n <br/>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"685\" height=\"380\" fill=\"none\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n<style>\n/* Default values, or theme set explicitly to light */\n:root, [data-theme=\"light\"] {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n}\n/* User has set OS preference for dark. (An explict light theme will override) */\n@media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n}\n/* Explicit dark theme set (should match above dark preference values) */\n[data-theme=\"dark\"] {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n}\n/*** Kata specific styles ***/\n.kata_svg_path {\n stroke: var(--kata-svg-path);\n stroke-width: 2;\n stroke-linecap: round;\n fill: none;\n}\n.kata_svg_text {\n fill: var(--kata-svg-stroke);\n}\n.kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n}\n.kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n}\n.kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n}\n</style>\n <!-- Large circles -->\n <g class=\"kata_svg_path\" >\n <path d=\"m24.1 163c0-76.8 62.3-139 139-139 76.8 0 139 62.3 139 139 0 76.8-62.3 139-139 139-76.8 0-139-62.3-139-139z\"/>\n <path d=\"m375 163c0-76.8 62.2-139 139-139s139 62.3 139 139c0 76.8-62.2 139-139 139s-139-62.3-139-139z\"/>\n </g>\n <!-- Target points -->\n <g class=\"kata_svg_fill_accent\">\n <path d=\"m296 163c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m18 163c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m508 23.7c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m508 302c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n </g>\n <!-- Normal points -->\n <g class=\"kata_svg_point\">\n <path d=\"m157 23.8c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m157 302c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m257 260c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m57.3 66.6c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m647 163c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m369 163c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n <path d=\"m608 66.6c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m408 260c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n </g>\n <!-- From point -->\n <g class=\"kata_svg_point kata_svg_stroke_accent\">\n <path d=\"m257 66.6c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m57.3 260c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m608 260c0-3.26 2.69-5.9 6-5.9s6 2.64 6 5.9-2.69 5.9-6 5.9-6-2.64-6-5.9z\"/>\n <path d=\"m408 66.6c0-3.26 2.64-5.9 5.9-5.9s5.9 2.64 5.9 5.9-2.64 5.9-5.9 5.9-5.9-2.64-5.9-5.9z\"/>\n </g>\n <!-- Arrows -->\n <g class=\"kata_svg_path kata_svg_stroke_accent\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\n <path d=\"m269.59 66.574h54.658v96.133h-15.241l5.6085-4.3192-5.6085 4.3192 5.6085 4.7704\" image-rendering=\"auto\"/>\n <path d=\"m407 66.95h-50v257h157v-15.074l-4.3311 4.8322 4.3311-4.7179 4.5323 4.7179\" image-rendering=\"auto\"/>\n <path d=\"m56.477 259.94h-51.893v-96.99h12.254l-5.544 4.3192 5.544-4.3192-5.544-4.7704\" image-rendering=\"auto\"/>\n <path d=\"m619.97 259.89h50.641v-254.72h-156.63v11.463l4.3311-4.8322-4.3311 4.7179-4.5323-4.7179\" image-rendering=\"auto\"/>\n </g>\n <g class=\"kata_svg_text\">\n <!-- Legend text -->\n <path d=\"m135 350c-.94.455-2.17.683-3.68.683-1.98 0-3.53-.581-4.66-1.74s-1.7-2.71-1.7-4.64c0-2.06.635-3.73 1.9-5.01 1.28-1.28 2.93-1.92 4.96-1.92 1.26 0 2.32.159 3.18.476v2.79c-.862-.515-1.84-.773-2.95-.773-1.21 0-2.19.381-2.93 1.14-.743.761-1.11 1.79-1.11 3.09 0 1.25.35 2.24 1.05 2.98.7.737 1.64 1.1 2.83 1.1 1.13 0 2.17-.276 3.11-.827v2.65zm6.35.683c-1.53 0-2.74-.429-3.62-1.28-.875-.863-1.31-2.03-1.31-3.5 0-1.52.455-2.71 1.37-3.57.91-.862 2.14-1.29 3.69-1.29 1.53 0 2.72.432 3.59 1.29.868.857 1.3 1.99 1.3 3.4 0 1.53-.45 2.73-1.35 3.62-.893.886-2.12 1.33-3.68 1.33zm.072-7.48c-.671 0-1.19.23-1.56.691-.371.462-.557 1.11-.557 1.96 0 1.77.713 2.65 2.14 2.65 1.36 0 2.04-.907 2.04-2.72 0-1.72-.686-2.58-2.06-2.58zm15.7 7.25h-2.83v-5.11c0-1.43-.509-2.14-1.53-2.14-.492 0-.896.188-1.21.566-.318.377-.477.856-.477 1.44v5.25h-2.84v-9.2h2.84v1.46h.036c.677-1.12 1.66-1.68 2.96-1.68 2.04 0 3.06 1.26 3.06 3.79v5.63zm1.65-.243v-2.3c.467.282.931.492 1.39.629.467.138.907.207 1.32.207.503 0 .899-.069 1.19-.207.294-.137.441-.347.441-.629 0-.179-.066-.329-.198-.449s-.303-.224-.512-.314c-.204-.09-.429-.171-.674-.243-.246-.072-.482-.153-.71-.242-.365-.138-.689-.285-.97-.441-.276-.161-.509-.347-.701-.557-.186-.209-.329-.452-.431-.727-.096-.276-.144-.602-.144-.98 0-.515.111-.958.332-1.33.228-.372.528-.674.899-.908.377-.239.806-.413 1.28-.521.485-.114.988-.171 1.51-.171.407 0 .821.033 1.24.099.419.06.832.15 1.24.27v2.19c-.36-.21-.746-.365-1.16-.467-.408-.108-.809-.162-1.2-.162-.186 0-.363.018-.53.054-.162.03-.306.078-.431.144-.126.06-.225.14-.297.242-.072.096-.108.207-.108.333 0 .167.054.311.162.431s.249.225.422.314c.174.084.366.162.575.234.216.066.428.135.638.207.377.131.719.275 1.02.431.306.156.566.338.782.548.222.21.389.455.503.737.12.281.18.617.18 1.01 0 .545-.12 1.01-.36 1.4-.233.384-.548.698-.943.944-.389.239-.841.413-1.36.521-.509.114-1.04.171-1.59.171-1.01 0-1.95-.156-2.81-.468zm14.3.135c-.419.222-1.05.333-1.9.333-2 0-3-1.04-3-3.12v-4.21h-1.49v-2.09h1.49v-1.99l2.83-.808v2.79h2.07v2.09h-2.07v3.72c0 .958.38 1.44 1.14 1.44.299 0 .608-.086.925-.26v2.1zm9.26.108h-2.69v-1.32h-.036c-.617 1.03-1.53 1.55-2.74 1.55-.893 0-1.6-.252-2.11-.755-.509-.509-.763-1.19-.763-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-.333c0-1.01-.545-1.51-1.64-1.51-1.1 0-2.14.326-3.13.979v-2.14c.395-.204.934-.383 1.62-.539.689-.156 1.32-.234 1.88-.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-.62l-1.67.215c-.923.12-1.38.536-1.38 1.25 0 .323.111.59.333.8.227.203.533.305.916.305.533 0 .967-.183 1.3-.548.335-.371.503-.838.503-1.4zm13.8 3.74h-2.83v-5.11c0-1.43-.509-2.14-1.53-2.14-.491 0-.895.188-1.21.566-.317.377-.476.856-.476 1.44v5.25h-2.84v-9.2h2.84v1.46h.036c.677-1.12 1.66-1.68 2.96-1.68 2.04 0 3.06 1.26 3.06 3.79v5.63zm7.82-.108c-.419.222-1.05.333-1.9.333-2 0-3-1.04-3-3.12v-4.21h-1.49v-2.09h1.49v-1.99l2.83-.808v2.79h2.07v2.09h-2.07v3.72c0 .958.38 1.44 1.14 1.44.299 0 .608-.086.925-.26v2.1z\"/>\n <path d=\"m491 338-4.44 12.9h-3.29l-4.38-12.9h3.13l2.69 8.97c.144.485.23.913.26 1.28h.054c.042-.402.135-.842.279-1.32l2.67-8.93h3.04zm7.54 12.9h-2.69v-1.32h-.036c-.616 1.03-1.53 1.55-2.74 1.55-.892 0-1.6-.252-2.11-.755-.509-.509-.764-1.19-.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-.333c0-1.01-.545-1.51-1.64-1.51-1.1 0-2.14.326-3.13.979v-2.14c.395-.204.934-.383 1.62-.539.689-.156 1.32-.234 1.88-.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-.62l-1.67.215c-.922.12-1.38.536-1.38 1.25 0 .323.11.59.332.8.228.203.533.305.916.305.534 0 .968-.183 1.3-.548.336-.371.503-.838.503-1.4zm10.9-2.9c-.341-.186-.739-.279-1.2-.279-.616 0-1.1.228-1.45.683-.347.449-.521 1.06-.521 1.84v4.39h-2.84v-9.2h2.84v1.71h.036c.449-1.25 1.26-1.87 2.43-1.87.299 0 .533.036.7.108v2.62zm2.84-4.02c-.479 0-.871-.141-1.18-.423-.305-.287-.458-.638-.458-1.05 0-.425.153-.773.458-1.04.306-.27.698-.404 1.18-.404.486 0 .878.134 1.18.404.306.269.459.617.459 1.04 0 .431-.153.785-.459 1.06-.299.276-.691.414-1.18.414zm1.4 10.7h-2.84v-9.2h2.84zm10 0h-2.69v-1.32h-.036c-.617 1.03-1.53 1.55-2.74 1.55-.892 0-1.6-.252-2.11-.755-.509-.509-.764-1.19-.764-2.03 0-1.78 1.06-2.82 3.17-3.09l2.5-.333c0-1.01-.545-1.51-1.64-1.51-1.1 0-2.14.326-3.13.979v-2.14c.396-.204.935-.383 1.62-.539.688-.156 1.31-.234 1.88-.234 2.62 0 3.94 1.31 3.94 3.93v5.5zm-2.67-3.74v-.62l-1.67.215c-.922.12-1.38.536-1.38 1.25 0 .323.111.59.333.8.227.203.533.305.916.305.533 0 .968-.183 1.3-.548.335-.371.503-.838.503-1.4zm7.79 2.67h-.036v1.07h-2.84v-13.6h2.84v5.8h.036c.7-1.07 1.7-1.61 2.99-1.61 1.19 0 2.1.408 2.74 1.22.641.815.961 1.93.961 3.34 0 1.53-.374 2.76-1.12 3.69s-1.75 1.39-3 1.39c-1.13 0-1.99-.432-2.57-1.29zm-.081-3.88v.943c0 .593.17 1.08.512 1.47.341.39.779.584 1.31.584.646 0 1.15-.248 1.5-.745.359-.503.539-1.21.539-2.13 0-.76-.165-1.35-.494-1.78-.324-.431-.788-.646-1.39-.646-.569 0-1.04.212-1.42.638-.372.425-.557.979-.557 1.66zm11.5 4.95h-2.84v-13.6h2.84zm10.7-3.79h-6c.096 1.34.937 2 2.52 2 1.01 0 1.9-.239 2.67-.719v2.05c-.851.455-1.96.683-3.32.683-1.48 0-2.64-.411-3.46-1.23-.82-.827-1.23-1.98-1.23-3.45 0-1.53.443-2.74 1.33-3.63.887-.892 1.98-1.34 3.27-1.34 1.34 0 2.38.399 3.11 1.2.737.797 1.1 1.88 1.1 3.24v1.2zm-2.63-1.74c0-1.32-.533-1.98-1.6-1.98-.456 0-.851.189-1.19.566-.33.377-.53.848-.602 1.41h3.39z\"/>\n <!-- Ket text -->\n <path d=\"m259 156h1.25v15.1h-1.25z\"/>\n <path d=\"m266 157c-.372 0-.684.11-.936.332s-.454.54-.608.956-.264.924-.328 1.52c-.064.598-.098 1.27-.098 2.02 0 1.76.164 3.05.49 3.88.328.824.834 1.24 1.52 1.24.654 0 1.14-.386 1.46-1.16s.474-1.98.474-3.6c0-1.24-.082-2.25-.244-3.02s-.388-1.32-.676-1.66c-.29-.334-.64-.502-1.05-.502zm.04-.69c1.18 0 2.06.458 2.64 1.37.578.914.866 2.29.866 4.14 0 1.91-.308 3.36-.928 4.34-.618.982-1.52 1.47-2.71 1.47-1.17 0-2.04-.46-2.61-1.38s-.856-2.31-.856-4.18c0-.994.088-1.85.264-2.58s.42-1.32.738-1.8c.316-.472.694-.822 1.14-1.05.442-.228.926-.342 1.45-.342z\"/>\n <path d=\"m273 156 3.23 7.28v.598l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29.868-.292z\"/>\n <path d=\"m156 45.5h1.25v15.1h-1.25z\"/>\n <path d=\"m164 45.9h.446c-.032.519-.05 1.24-.05 2.16v6.92c0 .313.018.55.054.709.034.159.096.289.186.389s.218.178.384.235c.168.0568.38.1.634.13.254.0298.588.05 1 .0608v.592h-5.99v-.592c.6-.027 1.03-.0634 1.29-.109.256-.0458.452-.115.586-.207.136-.0918.234-.222.296-.389.062-.168.094-.44.094-.819v-6.57c0-.216-.038-.374-.114-.474s-.186-.15-.332-.15c-.172 0-.418.0892-.738.267-.318.178-.712.424-1.18.738l-.356-.624 3.79-2.26z\"/>\n <path d=\"m170 44.8 3.23 7.28v.6l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m224 88.4h1.25v15.1h-1.25z\"/>\n <path d=\"m233 90h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42z\"/>\n <path d=\"m242 87.6 3.23 7.28v.6l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m224 222h1.25v15.1h-1.25z\"/>\n <path d=\"m229 228h9.99v1.08h-9.99z\"/>\n <path d=\"m242 221 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m149 265h9.99v1.08h-9.99z\"/>\n <path d=\"m162 259h1.25v15.1h-1.25z\"/>\n <path d=\"m171 259h.446c-.032.52-.05 1.24-.05 2.16v6.92c0 .314.018.55.054.71.034.16.096.29.186.39s.218.178.386.234c.166.056.378.1.632.13s.588.05 1 .06v.592h-5.99v-.592c.6-.026 1.03-.062 1.29-.108.256-.046.452-.116.586-.208.136-.092.234-.222.296-.388.062-.168.094-.44.094-.82v-6.57c0-.216-.038-.374-.114-.474s-.186-.15-.332-.15c-.172 0-.418.088-.738.266-.318.178-.712.424-1.18.738l-.358-.624 3.79-2.26z\"/>\n <path d=\"m176 258 3.23 7.28v.6l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m44.7 163h9.99v1.08h-9.99z\"/>\n <path d=\"m57.9 156h1.25v15.1h-1.25z\"/>\n <path d=\"m65.7 157c-.373 0-.685.11-.936.332s-.454.54-.608.956-.264.924-.328 1.52c-.0648.598-.0972 1.27-.0972 2.02 0 1.76.163 3.05.49 3.88.327.824.833 1.24 1.52 1.24.654 0 1.14-.386 1.45-1.16.316-.776.474-1.98.474-3.6 0-1.24-.081-2.25-.243-3.02s-.388-1.32-.677-1.66c-.289-.334-.639-.502-1.05-.502zm.0406-.69c1.18 0 2.06.458 2.64 1.37.578.914.867 2.29.867 4.14 0 1.91-.309 3.36-.928 4.34-.619.982-1.52 1.47-2.71 1.47-1.17 0-2.04-.46-2.61-1.38-.57-.918-.855-2.31-.855-4.18 0-.994.0878-1.85.263-2.58s.422-1.32.738-1.8c.316-.472.696-.822 1.14-1.05.443-.228.927-.342 1.45-.342z\"/>\n <path d=\"m72 156 3.23 7.28v.598l-3.23 7.29-.867-.308 2.6-7.28-2.6-7.29.867-.292z\"/>\n <path d=\"m74.1 228h9.99v1.08h-9.99z\"/>\n <path d=\"m87.3 221h1.25v15.1h-1.25z\"/>\n <path d=\"m96.2 223h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42z\"/>\n <path d=\"m105 220 3.23 7.28v.598l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29.868-.292z\"/>\n <path d=\"m73.4 94.2h9.99v1.08h-9.99z\"/>\n <path d=\"m86.6 87.9h1.25v15.1h-1.25z\"/>\n <path d=\"m91.1 94.2h9.99v1.08h-9.99z\"/>\n <path d=\"m104 87.2 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m608 156h1.25v15.1h-1.25z\"/>\n <path d=\"m616 157c-.374 0-.686.11-.936.332-.252.222-.454.54-.608.956s-.264.924-.328 1.52c-.066.598-.098 1.27-.098 2.02 0 1.76.164 3.05.49 3.88.328.824.834 1.24 1.52 1.24.654 0 1.14-.386 1.46-1.16s.474-1.98.474-3.6c0-1.24-.082-2.25-.244-3.02s-.388-1.32-.676-1.66c-.29-.334-.64-.502-1.05-.502zm.04-.69c1.18 0 2.06.458 2.64 1.37.578.914.868 2.29.868 4.14 0 1.91-.31 3.36-.928 4.34-.618.982-1.52 1.47-2.71 1.47-1.17 0-2.04-.46-2.61-1.38s-.854-2.31-.854-4.18c0-.994.088-1.85.262-2.58.176-.724.422-1.32.738-1.8.316-.472.696-.822 1.14-1.05.442-.228.926-.342 1.45-.342z\"/>\n <path d=\"m622 156 3.23 7.28v.598l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29.868-.292z\"/>\n <path d=\"m505 45.5h1.25v15.1h-1.25z\"/>\n <path d=\"m514 45.9h.444c-.032.519-.048 1.24-.048 2.16v6.92c0 .313.018.55.054.709.034.159.096.289.186.389.088.1.216.178.384.235s.378.1.632.13c.254.0298.59.05 1.01.0608v.592h-5.99v-.592c.6-.027 1.03-.0634 1.28-.109.258-.0458.454-.115.588-.207.136-.0918.234-.222.296-.389.062-.168.094-.44.094-.819v-6.57c0-.216-.038-.374-.114-.474s-.186-.15-.332-.15c-.174 0-.42.0892-.738.267-.318.178-.714.424-1.18.738l-.356-.624 3.79-2.26z\"/>\n <path d=\"m519 44.8 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m574 88.4h1.25v15.1h-1.25z\"/>\n <path d=\"m583 90h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42z\"/>\n <path d=\"m591 87.6 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m574 222h1.25v15.1h-1.25z\"/>\n <path d=\"m578 228h9.99v1.08h-9.99z\"/>\n <path d=\"m591 221 3.23 7.28v.6l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m498 265h9.99v1.08h-9.99z\"/>\n <path d=\"m511 259h1.25v15.1h-1.25z\"/>\n <path d=\"m520 259h.446c-.034.52-.05 1.24-.05 2.16v6.92c0 .314.018.55.054.71.034.16.096.29.186.39.088.1.216.178.384.234s.378.1.632.13.59.05 1.01.06v.592h-5.99v-.592c.6-.026 1.03-.062 1.28-.108.258-.046.454-.116.588-.208.136-.092.234-.222.296-.388.062-.168.094-.44.094-.82v-6.57c0-.216-.038-.374-.114-.474s-.186-.15-.332-.15c-.174 0-.42.088-.738.266s-.714.424-1.18.738l-.356-.624 3.79-2.26z\"/>\n <path d=\"m525 258 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n <path d=\"m394 163h9.99v1.08h-9.99z\"/>\n <path d=\"m407 156h1.25v15.1h-1.25z\"/>\n <path d=\"m415 157c-.374 0-.686.11-.936.332-.252.222-.454.54-.608.956s-.264.924-.328 1.52c-.066.598-.098 1.27-.098 2.02 0 1.76.164 3.05.49 3.88.328.824.834 1.24 1.52 1.24.654 0 1.14-.386 1.45-1.16.318-.776.476-1.98.476-3.6 0-1.24-.082-2.25-.244-3.02s-.388-1.32-.676-1.66c-.29-.334-.64-.502-1.05-.502zm.04-.69c1.18 0 2.06.458 2.64 1.37.578.914.868 2.29.868 4.14 0 1.91-.31 3.36-.928 4.34-.62.982-1.52 1.47-2.71 1.47-1.17 0-2.04-.46-2.61-1.38s-.854-2.31-.854-4.18c0-.994.088-1.85.262-2.58.176-.724.422-1.32.738-1.8.316-.472.696-.822 1.14-1.05.442-.228.926-.342 1.45-.342z\"/>\n <path d=\"m421 156 3.23 7.28v.598l-3.23 7.29-.866-.308 2.6-7.28-2.6-7.29.866-.292z\"/>\n <path d=\"m423 228h9.99v1.08h-9.99z\"/>\n <path d=\"m436 221h1.25v15.1h-1.25z\"/>\n <path d=\"m445 223h1.15v4.67h4.42v1.08h-4.42v4.67h-1.15v-4.67h-4.42v-1.08h4.42z\"/>\n <path d=\"m454 220 3.23 7.28v.598l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29.868-.292z\"/>\n <path d=\"m423 94.2h9.99v1.08h-9.99z\"/>\n <path d=\"m436 87.9h1.25v15.1h-1.25z\"/>\n <path d=\"m440 94.2h9.99v1.08h-9.99z\"/>\n <path d=\"m453 87.2 3.23 7.28v.6l-3.23 7.29-.868-.308 2.6-7.28-2.6-7.29z\"/>\n </g>\n</svg>\n"
6655
6655
  }
6656
6656
  ]
6657
6657
  },
@@ -6724,7 +6724,7 @@ export default {
6724
6724
  "items": [
6725
6725
  {
6726
6726
  "type": "text-content",
6727
- "content": "\nThis kata introduces you to Deutsch-Jozsa algorithm - one of the most famous algorithms in quantum computing. The problem it solves has little practical value, but the algorithm itself is one of the earliest examples of a quantum algorithm that is exponentially faster than any possible deterministic algorithm for the same problem. It is also relatively simple to explain and illustrates several very important concepts (such as quantum oracles). As such, Deutsch–Jozsa algorithm is part of almost every introductory course on quantum computing.\n\n**This kata covers the following topics:**\n\n- The problem solved by Deutsch-Jozsa algorithm and the classical solution to it\n- Multi-qubit phase oracles (for a more detailed introduction to phase oracles, see Oracles kata)\n- Deutsch-Jozsa algorithm\n- Implementing oracles and end-to-end Deutsch-Jozsa algorithm in Q#\n- Bernstein-Vazirani algorithm and the problem solved by it\n\n**What you should know to start working on this kata:**\n\n- Basic knowledge of single-qubit gates\n- Basic knowledge of quantum measurements\n- Deutsch algorithm - the single-qubit variant of Deutsch-Jozsa algorithm. If you're not familiar with it, you can find it in the Deutsch algorithm kata."
6727
+ "content": "\nThis kata introduces you to Deutsch-Jozsa algorithm - one of the most famous algorithms in quantum computing. The problem it solves has little practical value, but the algorithm itself is one of the earliest examples of a quantum algorithm that is exponentially faster than any possible deterministic algorithm for the same problem. It is also relatively simple to explain and illustrates several very important concepts (such as quantum oracles). As such, Deutsch–Jozsa algorithm is part of almost every introductory course on quantum computing.\n\n**This kata covers the following topics:**\n\n- The problem solved by Deutsch-Jozsa algorithm and the classical solution to it\n- Multi-qubit phase oracles (for a more detailed introduction to phase oracles, see Oracles kata)\n- Deutsch-Jozsa algorithm\n- Implementing oracles and end-to-end Deutsch-Jozsa algorithm in Q#\n- Bernstein-Vazirani algorithm and the problem solved by it\n\n**What you should know to start working on this kata:**\n\n- Basic single-qubit gates\n- Quantum measurements\n- Deutsch algorithm - the single-qubit variant of Deutsch-Jozsa algorithm. \n\nIf you need a refresher on these topics, you can check out the previous katas."
6728
6728
  }
6729
6729
  ]
6730
6730
  },
@@ -6930,7 +6930,7 @@ export default {
6930
6930
  "items": [
6931
6931
  {
6932
6932
  "type": "text-content",
6933
- "content": "\nThis kata introduces you to Grover's search algorithm - one of the fundamental algorithms in quantum computing.\n\n**This kata covers the following topics:**\n\n- The general problem solved by Grover's search algorithm - the search problem\n- Implementing Grover's algorithm in Q# for a problem provided as a quantum oracle\n- Some of the practical aspects of this algorithm\n\nNote that this tutorial does not cover implementing specific classical functions as quantum oracles in detail. To get familiar with that topic, check out the earlier Oracles and Marking Oracles katas.\n\n**What you should know to start working on this kata:**\n\n- Basic knowledge of quantum gates and measurements\n- Basic understanding of quantum oracles"
6933
+ "content": "\nThis kata introduces you to Grover's search algorithm - one of the fundamental algorithms in quantum computing.\n\n**This kata covers the following topics:**\n\n- The general problem solved by Grover's search algorithm - the search problem\n- Implementing Grover's algorithm in Q# for a problem provided as a quantum oracle\n- Some of the practical aspects of this algorithm\n\nNote that this tutorial does not cover implementing specific classical functions as quantum oracles in detail. To get familiar with that topic, check out the earlier Oracles and Marking Oracles katas.\n\n**What you should know to start working on this kata:**\n\n- Basic knowledge of quantum gates and measurements\n- Basic understanding of quantum oracles\n\nIf you need a refresher on these topics, you can check out the previous katas."
6934
6934
  }
6935
6935
  ]
6936
6936
  },
@@ -6980,7 +6980,7 @@ export default {
6980
6980
  "items": [
6981
6981
  {
6982
6982
  "type": "text-content",
6983
- "content": "\n### Inputs\n\nYou are given the number of bits in the function input $n$ and the phase oracle for the problem we're solving - a \"black box\" quantum operation $U_f$ that implements a classical function $f(x)$. \n\nAs usual, the phase oracle $U_f$ is defined by its effect on the individual values $x$ (represented as basis states $\\ket{x}$). \nIf the value of the function on the input $x$ $f(x) = 1$, the corresponding basis state $\\ket{x}$ is multiplied by $-1$; otherwise, the basis state is not changed.\nFormally, this can be written as follows:\n\n$$U_f \\ket{x} = (-1)^{f(x)} \\ket{x}$$\n\n> Typically the oracle for Grover's search is implemented as a marking oracle and then converted into a phase oracle using the phase kickback trick.\n\n\n### Algorithm outline\n\nThe high-level outline of the algorithm is very simple:\n\n1. Initialize the quantum system to a well-known starting state.\n2. Apply a fixed sequence of \"Grover iterations\" several times. Each iteration is implemented as pair of operations that includes one call of the oracle \"black box\".\n3. Finally, measuring all qubits will produce the desired output with high probability.\n\nLet's take a closer look at the algorithm.\n\n> We will use a convenient visualization of the algorithm steps rather than mathematical derivation.\n> They are equivalent, but the visual representation is much easier to follow.\n\n\n### Initial state and definitions\n\nGrover's search algorithm begins with a uniform superposition of all the states in the search space.\nTypically, the search space is defined as all $n$-bit bit strings, so this superposition is just an even superposition \nof all $N = 2^n$ basis states on $n$ qubits:\n$$\\ket{\\text{all}} = \\frac{1}{\\sqrt{N}}\\sum_{x=0}^{N-1}{\\ket{x}} $$\n\nWhen this superposition is considered in the context of the equation $f(x) = 1$, \nall the basis states can be split in two groups: \"good\" (solutions) and \"bad\" (non-solutions).\nIf the number of states for which $f(x)=1$ (the number of equation solutions) is $M$, \ntwo uniform superpositions of \"good\" and \"bad\" states can be defined as follows:\n\n$$\\ket{\\text{good}} = \\frac{1}{\\sqrt{M}}\\sum_{x,f(x)=1}{\\ket{x}}$$\n$$\\ket{\\text{bad}} = \\frac{1}{\\sqrt{N-M}}\\sum_{x,f(x)=0}{\\ket{x}}$$\n\nNow, the even superposition of all basis states can be rewritten as follows:\n$$\\ket{\\text{all}} = \\sqrt{\\frac{M}{N}}\\ket{\\text{good}} + \\sqrt{\\frac{N-M}{N}}\\ket{\\text{bad}}$$\n\nThe amplutudes $\\sqrt{\\frac{M}{N}}$ and $\\sqrt{\\frac{N-M}{N}}$ can then be written in a trigonometric representation,\nas a sine and cosine of the angle $\\theta$:\n\n$$\\sin \\theta = \\sqrt{\\frac{M}{N}}, \\cos \\theta = \\sqrt{\\frac{N-M}{N}}$$\n\nWith this replacement, the initial state can be written as \n\n$$\\ket{\\text{all}} = \\sin \\theta \\ket{\\text{good}} + \\cos \\theta \\ket{\\text{bad}}$$\n\nThe states involved in the algorithm can be represented on a plane on which $\\ket{\\text{good}}$ and $\\ket{\\text{bad}}$ vectors correspond to vertical and horizontal axes, respectively.\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"447\" height=\"370\" overflow=\"hidden\" version=\"1.1\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\">\n <style>\n :root {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n }\n @media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n }\n .kata_svg_path {\n stroke: var(--kata-svg-path);\n stroke-width: 10;\n stroke-linecap: round;\n fill: none;\n }\n .kata_svg_text {\n fill: var(--kata-svg-stroke);\n }\n .kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n }\n .kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n }\n .kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n }\n </style>\n <g transform=\"matrix(.25 0 0 .25 -333 -132)\">\n <g class=\"kata_svg_path\">\n <!-- Main circle -->\n <circle cx=\"2020\" cy=\"1310\" r=\"670\" />\n <!-- x axis -->\n <path d=\"M2685 1310 h-1335 m1335 0 l-32 -32 m32 32 l-32 32\" />\n <!-- y axis -->\n <path d=\"m2020 645 v1323 m0 -1323 l-32 32 m32 -32 l32 32\" />\n <!-- Angle line -->\n <path d=\"m2665 1145 l-645 165 m645 -165 l-32 45 m32 -45 l -45 -25\" />\n <path d=\"m2357 1225c6.73 27 10.1 54.7 10.1 82.5\" fill-rule=\"evenodd\" />\n </g>\n <g class=\"kata_svg_text\">\n <!-- |all> ket -->\n <path d=\"m2735 1098h6.92v83.6h-6.92z\" />\n <path d=\"m2782 1122c-3.09 0-5.86 1.25-8.31 3.73-2.46 2.49-4.37 5.82-5.75 10s-2.07 8.35-2.07 12.5c0 3.11 0.43 5.44 1.28 6.98 0.86 1.55 2.29 2.32 4.29 2.32 1.98 0 3.92-0.86 5.82-2.56 1.9-1.71 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.81 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.31-0.49-4-1.48-5.08s-2.66-1.62-5.03-1.62zm-0.9-3.54c1.95 0 3.77 0.21 5.46 0.65 1.69 0.43 3.44 1.2 5.23 2.31l4.14-2.96 2.87 0.71-6.6 28.5c-0.66 2.85-0.99 5.07-0.99 6.65 0 1.2 0.19 2.07 0.58 2.61s1.01 0.81 1.84 0.81c0.9 0 1.86-0.37 2.88-1.1 1.02-0.74 2.45-2.14 4.31-4.2l2.56 2.51c-2.69 2.88-4.99 4.92-6.89 6.13-1.9 1.22-3.96 1.82-6.18 1.82-1.86 0-3.34-0.61-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.64 0.34-3.39 1.03-5.25l-0.58-0.18c-2.88 4.19-5.6 7.26-8.18 9.21-2.57 1.94-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73s-2.72-5.98-2.72-10.5c0-5.15 1.01-10.1 3.03-14.8 2.02-4.75 4.8-8.49 8.34-11.2 3.53-2.74 7.47-4.11 11.8-4.11zm75.2-20.5h2.65l-11 49.7c-0.66 2.97-0.99 5.19-0.99 6.65 0 1.2 0.2 2.07 0.58 2.61 0.39 0.54 1.01 0.81 1.85 0.81 0.89 0 1.85-0.37 2.87-1.1 1.02-0.74 2.46-2.14 4.31-4.2l2.56 2.51c-2.9 3.06-5.27 5.15-7.12 6.27-1.84 1.12-3.9 1.68-6.17 1.68-1.95 0-3.51-0.71-4.67-2.13-1.17-1.42-1.76-3.24-1.76-5.46 0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.62-2.85 0.77-3.79 0.15-0.95 0.22-1.82 0.22-2.63 0-0.9-0.16-1.58-0.49-2.04-0.33-0.47-0.8-0.81-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.34zm-29 0h2.65l-11 49.7c-0.66 2.97-0.99 5.19-0.99 6.65 0 1.2 0.2 2.07 0.58 2.61 0.39 0.54 1.01 0.81 1.85 0.81 0.89 0 1.85-0.37 2.87-1.1 1.02-0.74 2.46-2.14 4.31-4.2l2.56 2.51c-2.9 3.06-5.27 5.15-7.12 6.27-1.84 1.12-3.9 1.68-6.17 1.68-1.95 0-3.51-0.71-4.67-2.13-1.17-1.42-1.76-3.24-1.76-5.46 0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.62-2.85 0.77-3.79 0.15-0.95 0.22-1.82 0.22-2.63 0-0.9-0.16-1.58-0.49-2.04-0.33-0.47-0.8-0.81-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.34z\" />\n <path d=\"m2875 1098 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |good> ket -->\n <path d=\"m1889 530h6.91v83.6h-6.91z\" />\n <path d=\"m2040 554c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm-49 0c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm98.3-0.09c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.42 5.44 1.28 6.99 0.85 1.54 2.28 2.31 4.29 2.31 0.93 0 1.87-0.202 2.83-0.606 0.96-0.405 1.95-1.06 2.99-1.96 1.03-0.898 2.05-1.99 3.05-3.28s1.92-2.58 2.76-3.89c0.84-1.3 1.62-2.84 2.34-4.63 0.72-1.78 1.33-3.93 1.84-6.45l0.4-1.93c0.45-2.16 0.68-4.19 0.68-6.11 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm-148 0c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.45 5.44 1.35 6.99 0.89 1.54 2.3 2.31 4.22 2.31 1.53 0 3.05-0.524 4.56-1.57s3.13-2.71 4.85-4.99 3.06-4.45 4.02-6.51c0.96-2.07 1.77-4.64 2.45-7.73 0.67-3.08 1.01-5.76 1.01-8.04 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm100-3.5c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-49 0c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-51.7-0.045c1.88 0 3.66 0.225 5.34 0.674s3.37 1.21 5.08 2.29l4.13-2.96 2.88 0.719-4.63 20.9c-0.33 1.47-1.08 5.17-2.25 11.1-1.23 6.29-2.22 10.7-2.98 13.3-0.77 2.6-1.72 4.98-2.86 7.12s-2.6 4-4.4 5.59c-1.8 1.59-3.98 2.82-6.54 3.68-2.56 0.869-5.59 1.3-9.09 1.3-11.3 0-17-3.29-17-9.88 0-1.68 0.51-3.2 1.52-4.58 1.02-1.38 2.65-2.83 4.9-4.36l3.24 2.6c-0.57 0.689-1.05 1.37-1.44 2.04s-0.67 1.32-0.83 1.95c-0.17 0.629-0.25 1.38-0.25 2.25 0 2.25 0.81 3.89 2.43 4.92 1.61 1.03 4.05 1.55 7.32 1.55 3.68 0 6.64-0.831 8.87-2.49s4.14-4.34 5.73-8.02c1.58-3.68 3.13-9.25 4.62-16.7l-0.62-0.134c-2.91 3.98-5.6 6.89-8.09 8.72-2.49 1.83-5.17 2.74-8.04 2.74-3.27 0-5.8-1.23-7.62-3.68-1.81-2.46-2.71-5.96-2.71-10.5 0-5.12 1-10 3.01-14.8 2-4.72 4.79-8.47 8.35-11.3 3.57-2.78 7.53-4.18 11.9-4.18zm168-20.5h2.65l-11.2 49.7c-0.66 2.94-0.99 5.15-0.99 6.65 0 1.2 0.2 2.07 0.59 2.6s1 0.809 1.84 0.809c0.9 0 1.86-0.367 2.87-1.1 1.02-0.734 2.46-2.13 4.32-4.2l2.56 2.52c-2.76 2.9-5.08 4.96-6.97 6.15-1.88 1.2-3.92 1.8-6.1 1.8-1.86 0-3.34-0.614-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.65 0.34-3.4 1.03-5.26l-0.59-0.18c-2.87 4.19-5.6 7.26-8.17 9.21-2.58 1.95-5.3 2.92-8.18 2.92-3.29 0-5.84-1.24-7.66-3.73-1.81-2.48-2.71-5.97-2.71-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.33-11.2c3.54-2.74 7.47-4.11 11.8-4.11 1.82 0 3.51 0.187 5.05 0.562 1.54 0.374 3.12 1.02 4.74 1.95l2.33-10.4c0.24-0.989 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.899-0.16-1.58-0.49-2.04s-0.8-0.801-1.42-1.01c-0.61-0.209-1.71-0.359-3.3-0.449l0.54-2.34z\" />\n <path d=\"m2126 529 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |bad> ket -->\n <path d=\"m2766 1275h6.92v83.6h-6.92z\" />\n <path d=\"m2816 1301c-1.43 0-2.85 0.46-4.24 1.37s-2.94 2.43-4.65 4.54-3.1 4.27-4.18 6.49-1.99 5.05-2.74 8.49l-0.4 1.89c-0.45 2.09-0.68 4.13-0.68 6.11 0 2.36 0.52 4.07 1.55 5.12 1.04 1.05 2.75 1.57 5.15 1.57 1.22 0 2.39-0.2 3.5-0.61 1.11-0.4 2.24-1.07 3.39-2 1.15-0.92 2.25-2.14 3.28-3.66 1.03-1.51 1.99-3.37 2.85-5.59 0.87-2.22 1.55-4.59 2.03-7.12 0.47-2.53 0.71-4.95 0.71-7.25 0-3.12-0.44-5.46-1.32-7.01-0.88-1.56-2.3-2.34-4.25-2.34zm97.4-1.75c-3.06 0-5.8 1.23-8.22 3.71-2.43 2.47-4.34 5.8-5.73 9.99s-2.09 8.37-2.09 12.5c0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c0.93 0 1.87-0.2 2.83-0.6 0.96-0.41 1.96-1.06 2.99-1.96s2.05-1.99 3.05-3.28c1.01-1.29 1.93-2.58 2.77-3.88 0.83-1.31 1.61-2.85 2.33-4.63s1.33-3.93 1.84-6.45l0.41-1.93c0.45-2.15 0.67-4.19 0.67-6.11 0-2.33-0.49-4.03-1.48-5.1-0.99-1.06-2.64-1.59-4.94-1.59zm-50.9 0c-3.09 0-5.86 1.24-8.31 3.73-2.46 2.48-4.37 5.82-5.75 9.99-1.38 4.18-2.07 8.35-2.07 12.5 0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c1.98 0 3.92-0.85 5.82-2.56 1.9-1.7 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.8 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.3-0.49-4-1.48-5.07-0.99-1.08-2.67-1.62-5.03-1.62zm-0.9-3.55c1.95 0 3.77 0.22 5.46 0.65 1.69 0.44 3.43 1.21 5.23 2.32l4.13-2.97 2.88 0.72-6.6 28.5c-0.66 2.84-0.99 5.06-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.69 2.87-4.99 4.92-6.89 6.13-1.91 1.21-3.97 1.82-6.18 1.82-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11zm70.6-20.5h2.65l-11.2 49.7c-0.66 2.93-0.99 5.15-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.75 2.9-5.08 4.95-6.96 6.15-1.89 1.2-3.93 1.8-6.11 1.8-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11 1.83 0 3.51 0.19 5.05 0.56 1.55 0.38 3.13 1.03 4.74 1.96l2.34-10.4c0.24-0.99 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.9-0.17-1.58-0.5-2.05-0.33-0.46-0.8-0.8-1.41-1.01-0.62-0.21-1.72-0.36-3.3-0.45l0.54-2.33zm-124 0h2.61l-7.91 31.4 0.59 0.18c2.9-3.9 5.63-6.71 8.17-8.45 2.55-1.74 5.09-2.6 7.64-2.6 3.26 0 5.8 1.24 7.61 3.72 1.81 2.49 2.72 5.99 2.72 10.5 0 4.94-1 9.8-2.99 14.6-1.99 4.78-4.75 8.57-8.29 11.4-3.53 2.8-7.48 4.2-11.8 4.2-3.99 0-7.52-0.98-10.6-2.92l-4.13 2.92-2.87-0.72 11.6-51.4c0.69-3.05 1.03-5.27 1.03-6.64 0-1.26-0.38-2.15-1.14-2.66-0.77-0.5-2.14-0.79-4.11-0.85l0.54-2.33z\" />\n <path d=\"m2950 1275 17.9 40.3v3.33l-17.9 40.4-4.8-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- theta-->\n <path d=\"m2414 1260c-1.4 6.49-2.11 12-2.11 16.4 0 3.36 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.31 2.11-11.8 2.11-16.3 0-3.15-0.51-5.5-1.53-7.06-1.01-1.55-2.6-2.33-4.76-2.33zm0.54-3.64c8.69 0 13 5.51 13 16.5 0 3.12-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.5-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09-2.19-2.72-3.28-6.81-3.28-12.3 0-2.97 0.33-6.62 0.99-11 0.66-4.35 1.74-8.79 3.26-13.3 1.51-4.54 3.45-8.57 5.84-12.1 2.38-3.52 5.12-6.23 8.22-8.13s6.46-2.85 10.1-2.85z\" fill-rule=\"evenodd\" />\n </g>\n <g class=\"kata_svg_fill_accent kata_svg_stroke_accent\">\n <!-- Started state square braket -->\n <path d=\"m2722 1082v-49h89v-49 49h89v49\" fill=\"none\" stroke-width=\"6\" />\n <text transform=\"translate(2605 952)\" font-family=\"sans-serif\" font-size=\"64px\" font-weight=\"400\">The starting state</text>\n </g>\n </g>\n</svg>\n\n### Grover's iteration\n\nEach Grover's iteration consists of two operations.\n\n1. The phase oracle $U_f$.\n2. An operation called \"reflection about the mean\".\n\nApplying the phase oracle to the state will flip the sign of all basis states in $\\ket{\\text{good}}$ \nand leave all basis states in $\\ket{\\text{bad}}$ unchanged:\n\n$$U_f\\ket{\\text{good}} = -\\ket{\\text{good}}$$\n$$U_f\\ket{\\text{bad}} = \\ket{\\text{bad}}$$\n\nOn the circle plot, this transformation leaves the horizontal component of the state vector unchanged and reverses its vertical component. In other words, this operation is a reflection along the horizontal axis.\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"447\" height=\"370\" overflow=\"hidden\" version=\"1.1\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\">\n <style>\n :root {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n }\n @media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n }\n .kata_svg_path {\n stroke: var(--kata-svg-path);\n stroke-width: 10;\n stroke-linecap: round;\n fill: none;\n }\n .kata_svg_text {\n fill: var(--kata-svg-stroke);\n }\n .kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n }\n .kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n }\n .kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n }\n </style>\n <g transform=\"matrix(.25 0 0 .25 -333 -132)\">\n <g class=\"kata_svg_path\">\n <!-- Main circle -->\n <circle cx=\"2020\" cy=\"1310\" r=\"670\" />\n <!-- x axis -->\n <path d=\"M2685 1310 h-1335 m1335 0 l-32 -32 m32 32 l-32 32\" />\n <!-- y axis -->\n <path d=\"m2020 645 v1323 m0 -1323 l-32 32 m32 -32 l32 32\" />\n <!-- Angle line -->\n <path d=\"m2665 1145 l-645 165 m645 -165 l-32 45 m32 -45 l -45 -25\" />\n <path d=\"m2357 1225c6.73 27 10.1 54.7 10.1 82.5\" fill-rule=\"evenodd\" />\n <!-- lower angle line -->\n <path d=\"m2665 1475 l-645 -165 m645 165 l-32 -45 m32 45 l -45 25\" class=\"kata_svg_stroke_accent\"/>\n <!-- lower angle curve -->\n <path transform=\"matrix(1 0 0 -1 1677 1655)\" d=\"m679 259c7.22 28.1 10.9 56.9 10.9 85.9\" class=\"kata_svg_stroke_accent\"/>\n </g>\n <g class=\"kata_svg_text\">\n <!-- |all> ket -->\n <path d=\"m2735 1098h6.92v83.6h-6.92z\" />\n <path d=\"m2782 1122c-3.09 0-5.86 1.25-8.31 3.73-2.46 2.49-4.37 5.82-5.75 10s-2.07 8.35-2.07 12.5c0 3.11 0.43 5.44 1.28 6.98 0.86 1.55 2.29 2.32 4.29 2.32 1.98 0 3.92-0.86 5.82-2.56 1.9-1.71 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.81 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.31-0.49-4-1.48-5.08s-2.66-1.62-5.03-1.62zm-0.9-3.54c1.95 0 3.77 0.21 5.46 0.65 1.69 0.43 3.44 1.2 5.23 2.31l4.14-2.96 2.87 0.71-6.6 28.5c-0.66 2.85-0.99 5.07-0.99 6.65 0 1.2 0.19 2.07 0.58 2.61s1.01 0.81 1.84 0.81c0.9 0 1.86-0.37 2.88-1.1 1.02-0.74 2.45-2.14 4.31-4.2l2.56 2.51c-2.69 2.88-4.99 4.92-6.89 6.13-1.9 1.22-3.96 1.82-6.18 1.82-1.86 0-3.34-0.61-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.64 0.34-3.39 1.03-5.25l-0.58-0.18c-2.88 4.19-5.6 7.26-8.18 9.21-2.57 1.94-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73s-2.72-5.98-2.72-10.5c0-5.15 1.01-10.1 3.03-14.8 2.02-4.75 4.8-8.49 8.34-11.2 3.53-2.74 7.47-4.11 11.8-4.11zm75.2-20.5h2.65l-11 49.7c-0.66 2.97-0.99 5.19-0.99 6.65 0 1.2 0.2 2.07 0.58 2.61 0.39 0.54 1.01 0.81 1.85 0.81 0.89 0 1.85-0.37 2.87-1.1 1.02-0.74 2.46-2.14 4.31-4.2l2.56 2.51c-2.9 3.06-5.27 5.15-7.12 6.27-1.84 1.12-3.9 1.68-6.17 1.68-1.95 0-3.51-0.71-4.67-2.13-1.17-1.42-1.76-3.24-1.76-5.46 0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.62-2.85 0.77-3.79 0.15-0.95 0.22-1.82 0.22-2.63 0-0.9-0.16-1.58-0.49-2.04-0.33-0.47-0.8-0.81-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.34zm-29 0h2.65l-11 49.7c-0.66 2.97-0.99 5.19-0.99 6.65 0 1.2 0.2 2.07 0.58 2.61 0.39 0.54 1.01 0.81 1.85 0.81 0.89 0 1.85-0.37 2.87-1.1 1.02-0.74 2.46-2.14 4.31-4.2l2.56 2.51c-2.9 3.06-5.27 5.15-7.12 6.27-1.84 1.12-3.9 1.68-6.17 1.68-1.95 0-3.51-0.71-4.67-2.13-1.17-1.42-1.76-3.24-1.76-5.46 0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.62-2.85 0.77-3.79 0.15-0.95 0.22-1.82 0.22-2.63 0-0.9-0.16-1.58-0.49-2.04-0.33-0.47-0.8-0.81-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.34z\" />\n <path d=\"m2875 1098 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |good> ket -->\n <path d=\"m1889 530h6.91v83.6h-6.91z\" />\n <path d=\"m2040 554c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm-49 0c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm98.3-0.09c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.42 5.44 1.28 6.99 0.85 1.54 2.28 2.31 4.29 2.31 0.93 0 1.87-0.202 2.83-0.606 0.96-0.405 1.95-1.06 2.99-1.96 1.03-0.898 2.05-1.99 3.05-3.28s1.92-2.58 2.76-3.89c0.84-1.3 1.62-2.84 2.34-4.63 0.72-1.78 1.33-3.93 1.84-6.45l0.4-1.93c0.45-2.16 0.68-4.19 0.68-6.11 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm-148 0c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.45 5.44 1.35 6.99 0.89 1.54 2.3 2.31 4.22 2.31 1.53 0 3.05-0.524 4.56-1.57s3.13-2.71 4.85-4.99 3.06-4.45 4.02-6.51c0.96-2.07 1.77-4.64 2.45-7.73 0.67-3.08 1.01-5.76 1.01-8.04 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm100-3.5c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-49 0c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-51.7-0.045c1.88 0 3.66 0.225 5.34 0.674s3.37 1.21 5.08 2.29l4.13-2.96 2.88 0.719-4.63 20.9c-0.33 1.47-1.08 5.17-2.25 11.1-1.23 6.29-2.22 10.7-2.98 13.3-0.77 2.6-1.72 4.98-2.86 7.12s-2.6 4-4.4 5.59c-1.8 1.59-3.98 2.82-6.54 3.68-2.56 0.869-5.59 1.3-9.09 1.3-11.3 0-17-3.29-17-9.88 0-1.68 0.51-3.2 1.52-4.58 1.02-1.38 2.65-2.83 4.9-4.36l3.24 2.6c-0.57 0.689-1.05 1.37-1.44 2.04s-0.67 1.32-0.83 1.95c-0.17 0.629-0.25 1.38-0.25 2.25 0 2.25 0.81 3.89 2.43 4.92 1.61 1.03 4.05 1.55 7.32 1.55 3.68 0 6.64-0.831 8.87-2.49s4.14-4.34 5.73-8.02c1.58-3.68 3.13-9.25 4.62-16.7l-0.62-0.134c-2.91 3.98-5.6 6.89-8.09 8.72-2.49 1.83-5.17 2.74-8.04 2.74-3.27 0-5.8-1.23-7.62-3.68-1.81-2.46-2.71-5.96-2.71-10.5 0-5.12 1-10 3.01-14.8 2-4.72 4.79-8.47 8.35-11.3 3.57-2.78 7.53-4.18 11.9-4.18zm168-20.5h2.65l-11.2 49.7c-0.66 2.94-0.99 5.15-0.99 6.65 0 1.2 0.2 2.07 0.59 2.6s1 0.809 1.84 0.809c0.9 0 1.86-0.367 2.87-1.1 1.02-0.734 2.46-2.13 4.32-4.2l2.56 2.52c-2.76 2.9-5.08 4.96-6.97 6.15-1.88 1.2-3.92 1.8-6.1 1.8-1.86 0-3.34-0.614-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.65 0.34-3.4 1.03-5.26l-0.59-0.18c-2.87 4.19-5.6 7.26-8.17 9.21-2.58 1.95-5.3 2.92-8.18 2.92-3.29 0-5.84-1.24-7.66-3.73-1.81-2.48-2.71-5.97-2.71-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.33-11.2c3.54-2.74 7.47-4.11 11.8-4.11 1.82 0 3.51 0.187 5.05 0.562 1.54 0.374 3.12 1.02 4.74 1.95l2.33-10.4c0.24-0.989 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.899-0.16-1.58-0.49-2.04s-0.8-0.801-1.42-1.01c-0.61-0.209-1.71-0.359-3.3-0.449l0.54-2.34z\" />\n <path d=\"m2126 529 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |bad> ket -->\n <path d=\"m2766 1275h6.92v83.6h-6.92z\" />\n <path d=\"m2816 1301c-1.43 0-2.85 0.46-4.24 1.37s-2.94 2.43-4.65 4.54-3.1 4.27-4.18 6.49-1.99 5.05-2.74 8.49l-0.4 1.89c-0.45 2.09-0.68 4.13-0.68 6.11 0 2.36 0.52 4.07 1.55 5.12 1.04 1.05 2.75 1.57 5.15 1.57 1.22 0 2.39-0.2 3.5-0.61 1.11-0.4 2.24-1.07 3.39-2 1.15-0.92 2.25-2.14 3.28-3.66 1.03-1.51 1.99-3.37 2.85-5.59 0.87-2.22 1.55-4.59 2.03-7.12 0.47-2.53 0.71-4.95 0.71-7.25 0-3.12-0.44-5.46-1.32-7.01-0.88-1.56-2.3-2.34-4.25-2.34zm97.4-1.75c-3.06 0-5.8 1.23-8.22 3.71-2.43 2.47-4.34 5.8-5.73 9.99s-2.09 8.37-2.09 12.5c0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c0.93 0 1.87-0.2 2.83-0.6 0.96-0.41 1.96-1.06 2.99-1.96s2.05-1.99 3.05-3.28c1.01-1.29 1.93-2.58 2.77-3.88 0.83-1.31 1.61-2.85 2.33-4.63s1.33-3.93 1.84-6.45l0.41-1.93c0.45-2.15 0.67-4.19 0.67-6.11 0-2.33-0.49-4.03-1.48-5.1-0.99-1.06-2.64-1.59-4.94-1.59zm-50.9 0c-3.09 0-5.86 1.24-8.31 3.73-2.46 2.48-4.37 5.82-5.75 9.99-1.38 4.18-2.07 8.35-2.07 12.5 0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c1.98 0 3.92-0.85 5.82-2.56 1.9-1.7 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.8 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.3-0.49-4-1.48-5.07-0.99-1.08-2.67-1.62-5.03-1.62zm-0.9-3.55c1.95 0 3.77 0.22 5.46 0.65 1.69 0.44 3.43 1.21 5.23 2.32l4.13-2.97 2.88 0.72-6.6 28.5c-0.66 2.84-0.99 5.06-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.69 2.87-4.99 4.92-6.89 6.13-1.91 1.21-3.97 1.82-6.18 1.82-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11zm70.6-20.5h2.65l-11.2 49.7c-0.66 2.93-0.99 5.15-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.75 2.9-5.08 4.95-6.96 6.15-1.89 1.2-3.93 1.8-6.11 1.8-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11 1.83 0 3.51 0.19 5.05 0.56 1.55 0.38 3.13 1.03 4.74 1.96l2.34-10.4c0.24-0.99 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.9-0.17-1.58-0.5-2.05-0.33-0.46-0.8-0.8-1.41-1.01-0.62-0.21-1.72-0.36-3.3-0.45l0.54-2.33zm-124 0h2.61l-7.91 31.4 0.59 0.18c2.9-3.9 5.63-6.71 8.17-8.45 2.55-1.74 5.09-2.6 7.64-2.6 3.26 0 5.8 1.24 7.61 3.72 1.81 2.49 2.72 5.99 2.72 10.5 0 4.94-1 9.8-2.99 14.6-1.99 4.78-4.75 8.57-8.29 11.4-3.53 2.8-7.48 4.2-11.8 4.2-3.99 0-7.52-0.98-10.6-2.92l-4.13 2.92-2.87-0.72 11.6-51.4c0.69-3.05 1.03-5.27 1.03-6.64 0-1.26-0.38-2.15-1.14-2.66-0.77-0.5-2.14-0.79-4.11-0.85l0.54-2.33z\" />\n <path d=\"m2950 1275 17.9 40.3v3.33l-17.9 40.4-4.8-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- theta-->\n <path d=\"m2414 1260c-1.4 6.49-2.11 12-2.11 16.4 0 3.36 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.31 2.11-11.8 2.11-16.3 0-3.15-0.51-5.5-1.53-7.06-1.01-1.55-2.6-2.33-4.76-2.33zm0.54-3.64c8.69 0 13 5.51 13 16.5 0 3.12-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.5-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09-2.19-2.72-3.28-6.81-3.28-12.3 0-2.97 0.33-6.62 0.99-11 0.66-4.35 1.74-8.79 3.26-13.3 1.51-4.54 3.45-8.57 5.84-12.1 2.38-3.52 5.12-6.23 8.22-8.13s6.46-2.85 10.1-2.85z\" fill-rule=\"evenodd\" />\n </g>\n <g class=\"kata_svg_fill_accent kata_svg_stroke_accent\" font-family=\"sans-serif\" font-size=\"64px\" font-weight=\"400\">\n <!-- theta -->\n <path d=\"m2415 1364c-1.41 6.5-2.11 12-2.11 16.4 0 3.35 0.51 5.82 1.52 7.39 1.02 1.57 2.67 2.36 4.95 2.36 3.35 0 6.53-2.26 9.54-6.76 3.01-4.51 5.56-11 7.66-19.4zm18.4-30.3c-3.51 0-6.75 2.21-9.73 6.64-2.98 4.44-5.52 10.8-7.61 19h21.5c1.41-6.32 2.12-11.8 2.12-16.3 0-3.14-0.51-5.49-1.53-7.05s-2.61-2.33-4.76-2.33zm0.54-3.64c8.68 0 13 5.51 13 16.5 0 3.11-0.35 6.83-1.05 11.2-0.71 4.33-1.82 8.74-3.35 13.2s-3.46 8.47-5.79 11.9c-2.34 3.46-5.04 6.13-8.09 8.02-3.06 1.88-6.35 2.83-9.88 2.83-4.47 0-7.79-1.37-9.98-4.09-2.18-2.73-3.28-6.82-3.28-12.3 0-2.96 0.33-6.61 0.99-11 0.66-4.34 1.75-8.78 3.26-13.3 1.51-4.53 3.46-8.56 5.84-12.1s5.12-6.23 8.22-8.13 6.46-2.85 10.1-2.85z\" />\n <text transform=\"translate(2734 1521)\">State after</text>\n <text transform=\"translate(2734 1598)\">the first </text>\n <text transform=\"translate(2734 1676)\">reflection</text>\n </g>\n </g>\n</svg>\n\n\"Reflection about the mean\" is an operation for which the visual definition is much more intuitive than the mathematical one.\nIt is literally a reflection about the state $\\ket{\\text{all}}$ - the uniform superposition of all basis states in the search space. \n\nMathematically, this operation is described as $2\\ket{\\text{all}}\\bra{\\text{all}} - I$: it leaves the component of the input state parallel to the state $\\ket{\\text{all}}$ unchanged and multiplies the component orthogonal to it by $-1$.\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"447\" height=\"370\" overflow=\"hidden\" version=\"1.1\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\">\n <style>\n :root {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n }\n @media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n }\n .kata_svg_path {\n stroke: var(--kata-svg-path);\n stroke-width: 10;\n stroke-linecap: round;\n fill: none;\n }\n .kata_svg_text {\n fill: var(--kata-svg-stroke);\n }\n .kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n }\n .kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n }\n .kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n }\n </style>\n <g transform=\"matrix(.25 0 0 .25 -333 -132)\">\n <g class=\"kata_svg_path\">\n <!-- Main circle -->\n <circle cx=\"2020\" cy=\"1310\" r=\"670\" />\n <!-- x axis -->\n <path d=\"M2685 1310 h-1335 m1335 0 l-32 -32 m32 32 l-32 32\" />\n <!-- y axis -->\n <path d=\"m2020 645 v1323 m0 -1323 l-32 32 m32 -32 l32 32\" />\n <!-- Angle line -->\n <path d=\"m2665 1145 l-645 165 m645 -165 l-32 45 m32 -45 l -45 -25\" />\n <path d=\"m2357 1225c6.73 27 10.1 54.7 10.1 82.5\" fill-rule=\"evenodd\" />\n <!-- lower angle line -->\n <path d=\"m2665 1475 l-645 -165 m645 165 l-32 -45 m32 45 l -45 25\" stroke-width=\"10\" stroke-linecap=\"round\" />\n <!-- lower angle curve -->\n <path transform=\"matrix(1 0 0 -1 1677 1655)\" d=\"m679 259c7.22 28.1 10.9 56.9 10.9 85.9\" fill=\"none\" fill-rule=\"evenodd\" stroke-width=\"10\" />\n <path d=\"M2490 845 l-470 465 m470 -465 l-50 0 m50 0 l0 50\" class=\"kata_svg_stroke_accent\"/>\n <!-- Accented angle line -->\n <path d=\"m2270 1065c43.2 45.4 73.5 102 88 160\" class=\"kata_svg_stroke_accent\"/>\n </g>\n <g class=\"kata_svg_text\">\n <!-- |all> ket -->\n <path d=\"m2735 1098h6.92v83.6h-6.92z\" />\n <path d=\"m2782 1122c-3.09 0-5.86 1.25-8.31 3.73-2.46 2.49-4.37 5.82-5.75 10s-2.07 8.35-2.07 12.5c0 3.11 0.43 5.44 1.28 6.98 0.86 1.55 2.29 2.32 4.29 2.32 1.98 0 3.92-0.86 5.82-2.56 1.9-1.71 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.81 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.31-0.49-4-1.48-5.08s-2.66-1.62-5.03-1.62zm-0.9-3.54c1.95 0 3.77 0.21 5.46 0.65 1.69 0.43 3.44 1.2 5.23 2.31l4.14-2.96 2.87 0.71-6.6 28.5c-0.66 2.85-0.99 5.07-0.99 6.65 0 1.2 0.19 2.07 0.58 2.61s1.01 0.81 1.84 0.81c0.9 0 1.86-0.37 2.88-1.1 1.02-0.74 2.45-2.14 4.31-4.2l2.56 2.51c-2.69 2.88-4.99 4.92-6.89 6.13-1.9 1.22-3.96 1.82-6.18 1.82-1.86 0-3.34-0.61-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.64 0.34-3.39 1.03-5.25l-0.58-0.18c-2.88 4.19-5.6 7.26-8.18 9.21-2.57 1.94-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73s-2.72-5.98-2.72-10.5c0-5.15 1.01-10.1 3.03-14.8 2.02-4.75 4.8-8.49 8.34-11.2 3.53-2.74 7.47-4.11 11.8-4.11zm75.2-20.5h2.65l-11 49.7c-0.66 2.97-0.99 5.19-0.99 6.65 0 1.2 0.2 2.07 0.58 2.61 0.39 0.54 1.01 0.81 1.85 0.81 0.89 0 1.85-0.37 2.87-1.1 1.02-0.74 2.46-2.14 4.31-4.2l2.56 2.51c-2.9 3.06-5.27 5.15-7.12 6.27-1.84 1.12-3.9 1.68-6.17 1.68-1.95 0-3.51-0.71-4.67-2.13-1.17-1.42-1.76-3.24-1.76-5.46 0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.62-2.85 0.77-3.79 0.15-0.95 0.22-1.82 0.22-2.63 0-0.9-0.16-1.58-0.49-2.04-0.33-0.47-0.8-0.81-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.34zm-29 0h2.65l-11 49.7c-0.66 2.97-0.99 5.19-0.99 6.65 0 1.2 0.2 2.07 0.58 2.61 0.39 0.54 1.01 0.81 1.85 0.81 0.89 0 1.85-0.37 2.87-1.1 1.02-0.74 2.46-2.14 4.31-4.2l2.56 2.51c-2.9 3.06-5.27 5.15-7.12 6.27-1.84 1.12-3.9 1.68-6.17 1.68-1.95 0-3.51-0.71-4.67-2.13-1.17-1.42-1.76-3.24-1.76-5.46 0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.62-2.85 0.77-3.79 0.15-0.95 0.22-1.82 0.22-2.63 0-0.9-0.16-1.58-0.49-2.04-0.33-0.47-0.8-0.81-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.34z\" />\n <path d=\"m2875 1098 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |good> ket -->\n <path d=\"m1889 530h6.91v83.6h-6.91z\" />\n <path d=\"m2040 554c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm-49 0c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm98.3-0.09c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.42 5.44 1.28 6.99 0.85 1.54 2.28 2.31 4.29 2.31 0.93 0 1.87-0.202 2.83-0.606 0.96-0.405 1.95-1.06 2.99-1.96 1.03-0.898 2.05-1.99 3.05-3.28s1.92-2.58 2.76-3.89c0.84-1.3 1.62-2.84 2.34-4.63 0.72-1.78 1.33-3.93 1.84-6.45l0.4-1.93c0.45-2.16 0.68-4.19 0.68-6.11 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm-148 0c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.45 5.44 1.35 6.99 0.89 1.54 2.3 2.31 4.22 2.31 1.53 0 3.05-0.524 4.56-1.57s3.13-2.71 4.85-4.99 3.06-4.45 4.02-6.51c0.96-2.07 1.77-4.64 2.45-7.73 0.67-3.08 1.01-5.76 1.01-8.04 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm100-3.5c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-49 0c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-51.7-0.045c1.88 0 3.66 0.225 5.34 0.674s3.37 1.21 5.08 2.29l4.13-2.96 2.88 0.719-4.63 20.9c-0.33 1.47-1.08 5.17-2.25 11.1-1.23 6.29-2.22 10.7-2.98 13.3-0.77 2.6-1.72 4.98-2.86 7.12s-2.6 4-4.4 5.59c-1.8 1.59-3.98 2.82-6.54 3.68-2.56 0.869-5.59 1.3-9.09 1.3-11.3 0-17-3.29-17-9.88 0-1.68 0.51-3.2 1.52-4.58 1.02-1.38 2.65-2.83 4.9-4.36l3.24 2.6c-0.57 0.689-1.05 1.37-1.44 2.04s-0.67 1.32-0.83 1.95c-0.17 0.629-0.25 1.38-0.25 2.25 0 2.25 0.81 3.89 2.43 4.92 1.61 1.03 4.05 1.55 7.32 1.55 3.68 0 6.64-0.831 8.87-2.49s4.14-4.34 5.73-8.02c1.58-3.68 3.13-9.25 4.62-16.7l-0.62-0.134c-2.91 3.98-5.6 6.89-8.09 8.72-2.49 1.83-5.17 2.74-8.04 2.74-3.27 0-5.8-1.23-7.62-3.68-1.81-2.46-2.71-5.96-2.71-10.5 0-5.12 1-10 3.01-14.8 2-4.72 4.79-8.47 8.35-11.3 3.57-2.78 7.53-4.18 11.9-4.18zm168-20.5h2.65l-11.2 49.7c-0.66 2.94-0.99 5.15-0.99 6.65 0 1.2 0.2 2.07 0.59 2.6s1 0.809 1.84 0.809c0.9 0 1.86-0.367 2.87-1.1 1.02-0.734 2.46-2.13 4.32-4.2l2.56 2.52c-2.76 2.9-5.08 4.96-6.97 6.15-1.88 1.2-3.92 1.8-6.1 1.8-1.86 0-3.34-0.614-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.65 0.34-3.4 1.03-5.26l-0.59-0.18c-2.87 4.19-5.6 7.26-8.17 9.21-2.58 1.95-5.3 2.92-8.18 2.92-3.29 0-5.84-1.24-7.66-3.73-1.81-2.48-2.71-5.97-2.71-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.33-11.2c3.54-2.74 7.47-4.11 11.8-4.11 1.82 0 3.51 0.187 5.05 0.562 1.54 0.374 3.12 1.02 4.74 1.95l2.33-10.4c0.24-0.989 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.899-0.16-1.58-0.49-2.04s-0.8-0.801-1.42-1.01c-0.61-0.209-1.71-0.359-3.3-0.449l0.54-2.34z\" />\n <path d=\"m2126 529 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |bad> ket -->\n <path d=\"m2766 1275h6.92v83.6h-6.92z\" />\n <path d=\"m2816 1301c-1.43 0-2.85 0.46-4.24 1.37s-2.94 2.43-4.65 4.54-3.1 4.27-4.18 6.49-1.99 5.05-2.74 8.49l-0.4 1.89c-0.45 2.09-0.68 4.13-0.68 6.11 0 2.36 0.52 4.07 1.55 5.12 1.04 1.05 2.75 1.57 5.15 1.57 1.22 0 2.39-0.2 3.5-0.61 1.11-0.4 2.24-1.07 3.39-2 1.15-0.92 2.25-2.14 3.28-3.66 1.03-1.51 1.99-3.37 2.85-5.59 0.87-2.22 1.55-4.59 2.03-7.12 0.47-2.53 0.71-4.95 0.71-7.25 0-3.12-0.44-5.46-1.32-7.01-0.88-1.56-2.3-2.34-4.25-2.34zm97.4-1.75c-3.06 0-5.8 1.23-8.22 3.71-2.43 2.47-4.34 5.8-5.73 9.99s-2.09 8.37-2.09 12.5c0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c0.93 0 1.87-0.2 2.83-0.6 0.96-0.41 1.96-1.06 2.99-1.96s2.05-1.99 3.05-3.28c1.01-1.29 1.93-2.58 2.77-3.88 0.83-1.31 1.61-2.85 2.33-4.63s1.33-3.93 1.84-6.45l0.41-1.93c0.45-2.15 0.67-4.19 0.67-6.11 0-2.33-0.49-4.03-1.48-5.1-0.99-1.06-2.64-1.59-4.94-1.59zm-50.9 0c-3.09 0-5.86 1.24-8.31 3.73-2.46 2.48-4.37 5.82-5.75 9.99-1.38 4.18-2.07 8.35-2.07 12.5 0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c1.98 0 3.92-0.85 5.82-2.56 1.9-1.7 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.8 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.3-0.49-4-1.48-5.07-0.99-1.08-2.67-1.62-5.03-1.62zm-0.9-3.55c1.95 0 3.77 0.22 5.46 0.65 1.69 0.44 3.43 1.21 5.23 2.32l4.13-2.97 2.88 0.72-6.6 28.5c-0.66 2.84-0.99 5.06-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.69 2.87-4.99 4.92-6.89 6.13-1.91 1.21-3.97 1.82-6.18 1.82-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11zm70.6-20.5h2.65l-11.2 49.7c-0.66 2.93-0.99 5.15-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.75 2.9-5.08 4.95-6.96 6.15-1.89 1.2-3.93 1.8-6.11 1.8-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11 1.83 0 3.51 0.19 5.05 0.56 1.55 0.38 3.13 1.03 4.74 1.96l2.34-10.4c0.24-0.99 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.9-0.17-1.58-0.5-2.05-0.33-0.46-0.8-0.8-1.41-1.01-0.62-0.21-1.72-0.36-3.3-0.45l0.54-2.33zm-124 0h2.61l-7.91 31.4 0.59 0.18c2.9-3.9 5.63-6.71 8.17-8.45 2.55-1.74 5.09-2.6 7.64-2.6 3.26 0 5.8 1.24 7.61 3.72 1.81 2.49 2.72 5.99 2.72 10.5 0 4.94-1 9.8-2.99 14.6-1.99 4.78-4.75 8.57-8.29 11.4-3.53 2.8-7.48 4.2-11.8 4.2-3.99 0-7.52-0.98-10.6-2.92l-4.13 2.92-2.87-0.72 11.6-51.4c0.69-3.05 1.03-5.27 1.03-6.64 0-1.26-0.38-2.15-1.14-2.66-0.77-0.5-2.14-0.79-4.11-0.85l0.54-2.33z\" />\n <path d=\"m2950 1275 17.9 40.3v3.33l-17.9 40.4-4.8-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- theta-->\n <path d=\"m2414 1260c-1.4 6.49-2.11 12-2.11 16.4 0 3.36 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.31 2.11-11.8 2.11-16.3 0-3.15-0.51-5.5-1.53-7.06-1.01-1.55-2.6-2.33-4.76-2.33zm0.54-3.64c8.69 0 13 5.51 13 16.5 0 3.12-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.5-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09-2.19-2.72-3.28-6.81-3.28-12.3 0-2.97 0.33-6.62 0.99-11 0.66-4.35 1.74-8.79 3.26-13.3 1.51-4.54 3.45-8.57 5.84-12.1 2.38-3.52 5.12-6.23 8.22-8.13s6.46-2.85 10.1-2.85z\" fill-rule=\"evenodd\" />\n <!-- lower theta -->\n <path d=\"m2415 1364c-1.41 6.5-2.11 12-2.11 16.4 0 3.35 0.51 5.82 1.52 7.39 1.02 1.57 2.67 2.36 4.95 2.36 3.35 0 6.53-2.26 9.54-6.76 3.01-4.51 5.56-11 7.66-19.4zm18.4-30.3c-3.51 0-6.75 2.21-9.73 6.64-2.98 4.44-5.52 10.8-7.61 19h21.5c1.41-6.32 2.12-11.8 2.12-16.3 0-3.14-0.51-5.49-1.53-7.05s-2.61-2.33-4.76-2.33zm0.54-3.64c8.68 0 13 5.51 13 16.5 0 3.11-0.35 6.83-1.05 11.2-0.71 4.33-1.82 8.74-3.35 13.2s-3.46 8.47-5.79 11.9c-2.34 3.46-5.04 6.13-8.09 8.02-3.06 1.88-6.35 2.83-9.88 2.83-4.47 0-7.79-1.37-9.98-4.09-2.18-2.73-3.28-6.82-3.28-12.3 0-2.96 0.33-6.61 0.99-11 0.66-4.34 1.75-8.78 3.26-13.3 1.51-4.53 3.46-8.56 5.84-12.1s5.12-6.23 8.22-8.13 6.46-2.85 10.1-2.85z\" />\n </g>\n <g class=\"kata_svg_fill_accent kata_svg_stroke_accent\" font-family=\"sans-serif\" font-size=\"64px\" font-weight=\"400\">\n <text transform=\"translate(2490 780)\">State after</text>\n <text transform=\"translate(2550 840)\">the second</text>\n <text transform=\"translate(2610 900)\">reflection</text>\n <!--2 \\theta and angle -->\n <path d=\"m2410 1105c-1.41 6.5-2.12 12-2.12 16.4 0 3.35 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.32 2.11-11.8 2.11-16.3 0-3.14-0.51-5.5-1.52-7.05-1.02-1.56-2.61-2.34-4.77-2.34zm-58.2-2.7c5.57 0 9.77 1.22 12.6 3.66 2.84 2.44 4.27 5.98 4.27 10.6 0 1.59-0.16 3.05-0.48 4.38-0.31 1.33-0.8 2.65-1.48 3.95-0.67 1.3-1.58 2.7-2.72 4.2-1.13 1.5-2.39 3.02-3.77 4.56s-3.76 4.11-7.14 7.7c-5.69 6.02-9.87 11.3-12.5 15.8h16.9c1.47 0 2.65-0.09 3.55-0.27s1.62-0.479 2.16-0.898c0.54-0.42 0.96-0.966 1.28-1.64 0.31-0.674 0.71-1.72 1.19-3.12h3.82l-0.77 13.1h-37v-2.16c1.29-3.14 3.03-6.36 5.21-9.66 2.19-3.3 5.29-7.17 9.3-11.6 3.47-3.83 5.98-6.74 7.5-8.72 1.68-2.16 2.93-4.02 3.75-5.59 0.83-1.57 1.42-3.06 1.78-4.45s0.54-2.79 0.54-4.2c0-2.25-0.36-4.23-1.08-5.95s-1.82-3.08-3.3-4.07c-1.49-0.988-3.35-1.48-5.6-1.48-5.6 0-9.37 3.11-11.3 9.34h-5.43v-8.62c3.62-1.71 7.01-2.94 10.2-3.71 3.16-0.763 6-1.14 8.52-1.14zm58.7-0.943c8.69 0 13 5.51 13 16.5 0 3.11-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.49-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09s-3.28-6.81-3.28-12.3c0-2.96 0.33-6.62 0.99-11 0.66-4.34 1.74-8.78 3.26-13.3 1.51-4.54 3.46-8.56 5.84-12.1s5.12-6.23 8.22-8.13 6.46-2.85 10.1-2.85z\" fill=\"#0070c0\" fill-rule=\"evenodd\" />\n </g>\n </g>\n</svg>\n\nAs we can see, the pair of these reflections combined amount to a counterclockwise rotation by an angle $2\\theta$. \nIf we repeat the Grover's iteration, reflecting the new state first along the horizontal axis and then along the $\\ket{\\text{all}}$ vector, it performs a rotation by $2\\theta$ again. The angle of this rotation depends only on the angle between the reflection axes and not on the state we reflect!\n\nEach iteration of Grover's search adds $2\\theta$ to the current angle in the expression of the system state as a superposition of $\\ket{\\text{good}}$ and $\\ket{\\text{bad}}$.\nAfter applying $R$ iterations of Grover's search the state of the system will become\n\n$$\\sin{(2R+1)\\theta}\\ket{\\text{good}} + \\cos{(2R+1)\\theta}\\ket{\\text{bad}}$$\n\nAt firat, each iteration brings the state of the system closer to the vertical axis, increasing the probability of measuring one of the basis states that are part of $\\ket{\\text{good}}$ - the states that are solutions to the problem."
6983
+ "content": "\n### Inputs\n\nYou are given the number of bits in the function input $n$ and the phase oracle for the problem we're solving - a \"black box\" quantum operation $U_f$ that implements a classical function $f(x)$. \n\nAs usual, the phase oracle $U_f$ is defined by its effect on the individual values $x$ (represented as basis states $\\ket{x}$). \nIf the value of the function on the input $x$ $f(x) = 1$, the corresponding basis state $\\ket{x}$ is multiplied by $-1$; otherwise, the basis state is not changed.\nFormally, this can be written as follows:\n\n$$U_f \\ket{x} = (-1)^{f(x)} \\ket{x}$$\n\n> Typically the oracle for Grover's search is implemented as a marking oracle and then converted into a phase oracle using the phase kickback trick.\n\n\n### Algorithm outline\n\nThe high-level outline of the algorithm is very simple:\n\n1. Initialize the quantum system to a well-known starting state.\n2. Apply a fixed sequence of \"Grover iterations\" several times. Each iteration is implemented as pair of operations that includes one call of the oracle \"black box\".\n3. Finally, measuring all qubits will produce the desired output with high probability.\n\nLet's take a closer look at the algorithm.\n\n> We will use a convenient visualization of the algorithm steps rather than mathematical derivation.\n> They are equivalent, but the visual representation is much easier to follow.\n\n\n### Initial state and definitions\n\nGrover's search algorithm begins with a uniform superposition of all the states in the search space.\nTypically, the search space is defined as all $n$-bit bit strings, so this superposition is just an even superposition \nof all $N = 2^n$ basis states on $n$ qubits:\n$$\\ket{\\text{all}} = \\frac{1}{\\sqrt{N}}\\sum_{x=0}^{N-1}{\\ket{x}} $$\n\nWhen this superposition is considered in the context of the equation $f(x) = 1$, \nall the basis states can be split in two groups: \"good\" (solutions) and \"bad\" (non-solutions).\nIf the number of states for which $f(x)=1$ (the number of equation solutions) is $M$, \ntwo uniform superpositions of \"good\" and \"bad\" states can be defined as follows:\n\n$$\\ket{\\text{good}} = \\frac{1}{\\sqrt{M}}\\sum_{x,f(x)=1}{\\ket{x}}$$\n$$\\ket{\\text{bad}} = \\frac{1}{\\sqrt{N-M}}\\sum_{x,f(x)=0}{\\ket{x}}$$\n\nNow, the even superposition of all basis states can be rewritten as follows:\n$$\\ket{\\text{all}} = \\sqrt{\\frac{M}{N}}\\ket{\\text{good}} + \\sqrt{\\frac{N-M}{N}}\\ket{\\text{bad}}$$\n\nThe amplutudes $\\sqrt{\\frac{M}{N}}$ and $\\sqrt{\\frac{N-M}{N}}$ can then be written in a trigonometric representation,\nas a sine and cosine of the angle $\\theta$:\n\n$$\\sin \\theta = \\sqrt{\\frac{M}{N}}, \\cos \\theta = \\sqrt{\\frac{N-M}{N}}$$\n\nWith this replacement, the initial state can be written as \n\n$$\\ket{\\text{all}} = \\sin \\theta \\ket{\\text{good}} + \\cos \\theta \\ket{\\text{bad}}$$\n\nThe states involved in the algorithm can be represented on a plane on which $\\ket{\\text{good}}$ and $\\ket{\\text{bad}}$ vectors correspond to vertical and horizontal axes, respectively.\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"447\" height=\"370\" overflow=\"hidden\" version=\"1.1\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\">\n<style>\n/* Default values, or theme set explicitly to light */\n:root, [data-theme=\"light\"] {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n}\n/* User has set OS preference for dark. (An explict light theme will override) */\n@media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n}\n/* Explicit dark theme set (should match above dark preference values) */\n[data-theme=\"dark\"] {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n}\n/*** Kata specific styles ***/\n.kata_svg_path {\n stroke: var(--kata-svg-path);\n stroke-width: 2;\n stroke-linecap: round;\n fill: none;\n}\n.kata_svg_text {\n fill: var(--kata-svg-stroke);\n}\n.kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n}\n.kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n}\n.kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n}\n</style>\n <g transform=\"matrix(.25 0 0 .25 -333 -132)\">\n <g class=\"kata_svg_path\">\n <!-- Main circle -->\n <circle cx=\"2020\" cy=\"1310\" r=\"670\" />\n <!-- x axis -->\n <path d=\"M2685 1310 h-1335 m1335 0 l-32 -32 m32 32 l-32 32\" />\n <!-- y axis -->\n <path d=\"m2020 645 v1323 m0 -1323 l-32 32 m32 -32 l32 32\" />\n <!-- Angle line -->\n <path d=\"m2665 1145 l-645 165 m645 -165 l-32 45 m32 -45 l -45 -25\" />\n <path d=\"m2357 1225c6.73 27 10.1 54.7 10.1 82.5\" fill-rule=\"evenodd\" />\n </g>\n <g class=\"kata_svg_text\">\n <!-- |all> ket -->\n <path d=\"m2735 1098h6.92v83.6h-6.92z\" />\n <path d=\"m2782 1122c-3.09 0-5.86 1.25-8.31 3.73-2.46 2.49-4.37 5.82-5.75 10s-2.07 8.35-2.07 12.5c0 3.11 0.43 5.44 1.28 6.98 0.86 1.55 2.29 2.32 4.29 2.32 1.98 0 3.92-0.86 5.82-2.56 1.9-1.71 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.81 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.31-0.49-4-1.48-5.08s-2.66-1.62-5.03-1.62zm-0.9-3.54c1.95 0 3.77 0.21 5.46 0.65 1.69 0.43 3.44 1.2 5.23 2.31l4.14-2.96 2.87 0.71-6.6 28.5c-0.66 2.85-0.99 5.07-0.99 6.65 0 1.2 0.19 2.07 0.58 2.61s1.01 0.81 1.84 0.81c0.9 0 1.86-0.37 2.88-1.1 1.02-0.74 2.45-2.14 4.31-4.2l2.56 2.51c-2.69 2.88-4.99 4.92-6.89 6.13-1.9 1.22-3.96 1.82-6.18 1.82-1.86 0-3.34-0.61-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.64 0.34-3.39 1.03-5.25l-0.58-0.18c-2.88 4.19-5.6 7.26-8.18 9.21-2.57 1.94-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73s-2.72-5.98-2.72-10.5c0-5.15 1.01-10.1 3.03-14.8 2.02-4.75 4.8-8.49 8.34-11.2 3.53-2.74 7.47-4.11 11.8-4.11zm75.2-20.5h2.65l-11 49.7c-0.66 2.97-0.99 5.19-0.99 6.65 0 1.2 0.2 2.07 0.58 2.61 0.39 0.54 1.01 0.81 1.85 0.81 0.89 0 1.85-0.37 2.87-1.1 1.02-0.74 2.46-2.14 4.31-4.2l2.56 2.51c-2.9 3.06-5.27 5.15-7.12 6.27-1.84 1.12-3.9 1.68-6.17 1.68-1.95 0-3.51-0.71-4.67-2.13-1.17-1.42-1.76-3.24-1.76-5.46 0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.62-2.85 0.77-3.79 0.15-0.95 0.22-1.82 0.22-2.63 0-0.9-0.16-1.58-0.49-2.04-0.33-0.47-0.8-0.81-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.34zm-29 0h2.65l-11 49.7c-0.66 2.97-0.99 5.19-0.99 6.65 0 1.2 0.2 2.07 0.58 2.61 0.39 0.54 1.01 0.81 1.85 0.81 0.89 0 1.85-0.37 2.87-1.1 1.02-0.74 2.46-2.14 4.31-4.2l2.56 2.51c-2.9 3.06-5.27 5.15-7.12 6.27-1.84 1.12-3.9 1.68-6.17 1.68-1.95 0-3.51-0.71-4.67-2.13-1.17-1.42-1.76-3.24-1.76-5.46 0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.62-2.85 0.77-3.79 0.15-0.95 0.22-1.82 0.22-2.63 0-0.9-0.16-1.58-0.49-2.04-0.33-0.47-0.8-0.81-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.34z\" />\n <path d=\"m2875 1098 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |good> ket -->\n <path d=\"m1889 530h6.91v83.6h-6.91z\" />\n <path d=\"m2040 554c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm-49 0c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm98.3-0.09c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.42 5.44 1.28 6.99 0.85 1.54 2.28 2.31 4.29 2.31 0.93 0 1.87-0.202 2.83-0.606 0.96-0.405 1.95-1.06 2.99-1.96 1.03-0.898 2.05-1.99 3.05-3.28s1.92-2.58 2.76-3.89c0.84-1.3 1.62-2.84 2.34-4.63 0.72-1.78 1.33-3.93 1.84-6.45l0.4-1.93c0.45-2.16 0.68-4.19 0.68-6.11 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm-148 0c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.45 5.44 1.35 6.99 0.89 1.54 2.3 2.31 4.22 2.31 1.53 0 3.05-0.524 4.56-1.57s3.13-2.71 4.85-4.99 3.06-4.45 4.02-6.51c0.96-2.07 1.77-4.64 2.45-7.73 0.67-3.08 1.01-5.76 1.01-8.04 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm100-3.5c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-49 0c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-51.7-0.045c1.88 0 3.66 0.225 5.34 0.674s3.37 1.21 5.08 2.29l4.13-2.96 2.88 0.719-4.63 20.9c-0.33 1.47-1.08 5.17-2.25 11.1-1.23 6.29-2.22 10.7-2.98 13.3-0.77 2.6-1.72 4.98-2.86 7.12s-2.6 4-4.4 5.59c-1.8 1.59-3.98 2.82-6.54 3.68-2.56 0.869-5.59 1.3-9.09 1.3-11.3 0-17-3.29-17-9.88 0-1.68 0.51-3.2 1.52-4.58 1.02-1.38 2.65-2.83 4.9-4.36l3.24 2.6c-0.57 0.689-1.05 1.37-1.44 2.04s-0.67 1.32-0.83 1.95c-0.17 0.629-0.25 1.38-0.25 2.25 0 2.25 0.81 3.89 2.43 4.92 1.61 1.03 4.05 1.55 7.32 1.55 3.68 0 6.64-0.831 8.87-2.49s4.14-4.34 5.73-8.02c1.58-3.68 3.13-9.25 4.62-16.7l-0.62-0.134c-2.91 3.98-5.6 6.89-8.09 8.72-2.49 1.83-5.17 2.74-8.04 2.74-3.27 0-5.8-1.23-7.62-3.68-1.81-2.46-2.71-5.96-2.71-10.5 0-5.12 1-10 3.01-14.8 2-4.72 4.79-8.47 8.35-11.3 3.57-2.78 7.53-4.18 11.9-4.18zm168-20.5h2.65l-11.2 49.7c-0.66 2.94-0.99 5.15-0.99 6.65 0 1.2 0.2 2.07 0.59 2.6s1 0.809 1.84 0.809c0.9 0 1.86-0.367 2.87-1.1 1.02-0.734 2.46-2.13 4.32-4.2l2.56 2.52c-2.76 2.9-5.08 4.96-6.97 6.15-1.88 1.2-3.92 1.8-6.1 1.8-1.86 0-3.34-0.614-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.65 0.34-3.4 1.03-5.26l-0.59-0.18c-2.87 4.19-5.6 7.26-8.17 9.21-2.58 1.95-5.3 2.92-8.18 2.92-3.29 0-5.84-1.24-7.66-3.73-1.81-2.48-2.71-5.97-2.71-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.33-11.2c3.54-2.74 7.47-4.11 11.8-4.11 1.82 0 3.51 0.187 5.05 0.562 1.54 0.374 3.12 1.02 4.74 1.95l2.33-10.4c0.24-0.989 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.899-0.16-1.58-0.49-2.04s-0.8-0.801-1.42-1.01c-0.61-0.209-1.71-0.359-3.3-0.449l0.54-2.34z\" />\n <path d=\"m2126 529 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |bad> ket -->\n <path d=\"m2766 1275h6.92v83.6h-6.92z\" />\n <path d=\"m2816 1301c-1.43 0-2.85 0.46-4.24 1.37s-2.94 2.43-4.65 4.54-3.1 4.27-4.18 6.49-1.99 5.05-2.74 8.49l-0.4 1.89c-0.45 2.09-0.68 4.13-0.68 6.11 0 2.36 0.52 4.07 1.55 5.12 1.04 1.05 2.75 1.57 5.15 1.57 1.22 0 2.39-0.2 3.5-0.61 1.11-0.4 2.24-1.07 3.39-2 1.15-0.92 2.25-2.14 3.28-3.66 1.03-1.51 1.99-3.37 2.85-5.59 0.87-2.22 1.55-4.59 2.03-7.12 0.47-2.53 0.71-4.95 0.71-7.25 0-3.12-0.44-5.46-1.32-7.01-0.88-1.56-2.3-2.34-4.25-2.34zm97.4-1.75c-3.06 0-5.8 1.23-8.22 3.71-2.43 2.47-4.34 5.8-5.73 9.99s-2.09 8.37-2.09 12.5c0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c0.93 0 1.87-0.2 2.83-0.6 0.96-0.41 1.96-1.06 2.99-1.96s2.05-1.99 3.05-3.28c1.01-1.29 1.93-2.58 2.77-3.88 0.83-1.31 1.61-2.85 2.33-4.63s1.33-3.93 1.84-6.45l0.41-1.93c0.45-2.15 0.67-4.19 0.67-6.11 0-2.33-0.49-4.03-1.48-5.1-0.99-1.06-2.64-1.59-4.94-1.59zm-50.9 0c-3.09 0-5.86 1.24-8.31 3.73-2.46 2.48-4.37 5.82-5.75 9.99-1.38 4.18-2.07 8.35-2.07 12.5 0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c1.98 0 3.92-0.85 5.82-2.56 1.9-1.7 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.8 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.3-0.49-4-1.48-5.07-0.99-1.08-2.67-1.62-5.03-1.62zm-0.9-3.55c1.95 0 3.77 0.22 5.46 0.65 1.69 0.44 3.43 1.21 5.23 2.32l4.13-2.97 2.88 0.72-6.6 28.5c-0.66 2.84-0.99 5.06-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.69 2.87-4.99 4.92-6.89 6.13-1.91 1.21-3.97 1.82-6.18 1.82-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11zm70.6-20.5h2.65l-11.2 49.7c-0.66 2.93-0.99 5.15-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.75 2.9-5.08 4.95-6.96 6.15-1.89 1.2-3.93 1.8-6.11 1.8-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11 1.83 0 3.51 0.19 5.05 0.56 1.55 0.38 3.13 1.03 4.74 1.96l2.34-10.4c0.24-0.99 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.9-0.17-1.58-0.5-2.05-0.33-0.46-0.8-0.8-1.41-1.01-0.62-0.21-1.72-0.36-3.3-0.45l0.54-2.33zm-124 0h2.61l-7.91 31.4 0.59 0.18c2.9-3.9 5.63-6.71 8.17-8.45 2.55-1.74 5.09-2.6 7.64-2.6 3.26 0 5.8 1.24 7.61 3.72 1.81 2.49 2.72 5.99 2.72 10.5 0 4.94-1 9.8-2.99 14.6-1.99 4.78-4.75 8.57-8.29 11.4-3.53 2.8-7.48 4.2-11.8 4.2-3.99 0-7.52-0.98-10.6-2.92l-4.13 2.92-2.87-0.72 11.6-51.4c0.69-3.05 1.03-5.27 1.03-6.64 0-1.26-0.38-2.15-1.14-2.66-0.77-0.5-2.14-0.79-4.11-0.85l0.54-2.33z\" />\n <path d=\"m2950 1275 17.9 40.3v3.33l-17.9 40.4-4.8-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- theta-->\n <path d=\"m2414 1260c-1.4 6.49-2.11 12-2.11 16.4 0 3.36 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.31 2.11-11.8 2.11-16.3 0-3.15-0.51-5.5-1.53-7.06-1.01-1.55-2.6-2.33-4.76-2.33zm0.54-3.64c8.69 0 13 5.51 13 16.5 0 3.12-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.5-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09-2.19-2.72-3.28-6.81-3.28-12.3 0-2.97 0.33-6.62 0.99-11 0.66-4.35 1.74-8.79 3.26-13.3 1.51-4.54 3.45-8.57 5.84-12.1 2.38-3.52 5.12-6.23 8.22-8.13s6.46-2.85 10.1-2.85z\" fill-rule=\"evenodd\" />\n </g>\n <g class=\"kata_svg_fill_accent kata_svg_stroke_accent\">\n <!-- Started state square braket -->\n <path d=\"m2722 1082v-49h89v-49 49h89v49\" fill=\"none\" stroke-width=\"6\" />\n <text transform=\"translate(2605 952)\" font-family=\"sans-serif\" font-size=\"64px\" font-weight=\"400\">The starting state</text>\n </g>\n </g>\n</svg>\n\n### Grover's iteration\n\nEach Grover's iteration consists of two operations.\n\n1. The phase oracle $U_f$.\n2. An operation called \"reflection about the mean\".\n\nApplying the phase oracle to the state will flip the sign of all basis states in $\\ket{\\text{good}}$ \nand leave all basis states in $\\ket{\\text{bad}}$ unchanged:\n\n$$U_f\\ket{\\text{good}} = -\\ket{\\text{good}}$$\n$$U_f\\ket{\\text{bad}} = \\ket{\\text{bad}}$$\n\nOn the circle plot, this transformation leaves the horizontal component of the state vector unchanged and reverses its vertical component. In other words, this operation is a reflection along the horizontal axis.\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"447\" height=\"370\" overflow=\"hidden\" version=\"1.1\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\">\n<style>\n/* Default values, or theme set explicitly to light */\n:root, [data-theme=\"light\"] {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n}\n/* User has set OS preference for dark. (An explict light theme will override) */\n@media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n}\n/* Explicit dark theme set (should match above dark preference values) */\n[data-theme=\"dark\"] {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n}\n/*** Kata specific styles ***/\n.kata_svg_path {\n stroke: var(--kata-svg-path);\n stroke-width: 2;\n stroke-linecap: round;\n fill: none;\n}\n.kata_svg_text {\n fill: var(--kata-svg-stroke);\n}\n.kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n}\n.kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n}\n.kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n}\n</style>\n <g transform=\"matrix(.25 0 0 .25 -333 -132)\">\n <g class=\"kata_svg_path\">\n <!-- Main circle -->\n <circle cx=\"2020\" cy=\"1310\" r=\"670\" />\n <!-- x axis -->\n <path d=\"M2685 1310 h-1335 m1335 0 l-32 -32 m32 32 l-32 32\" />\n <!-- y axis -->\n <path d=\"m2020 645 v1323 m0 -1323 l-32 32 m32 -32 l32 32\" />\n <!-- Angle line -->\n <path d=\"m2665 1145 l-645 165 m645 -165 l-32 45 m32 -45 l -45 -25\" />\n <path d=\"m2357 1225c6.73 27 10.1 54.7 10.1 82.5\" fill-rule=\"evenodd\" />\n <!-- lower angle line -->\n <path d=\"m2665 1475 l-645 -165 m645 165 l-32 -45 m32 45 l -45 25\" class=\"kata_svg_stroke_accent\"/>\n <!-- lower angle curve -->\n <path transform=\"matrix(1 0 0 -1 1677 1655)\" d=\"m679 259c7.22 28.1 10.9 56.9 10.9 85.9\" class=\"kata_svg_stroke_accent\"/>\n </g>\n <g class=\"kata_svg_text\">\n <!-- |all> ket -->\n <path d=\"m2735 1098h6.92v83.6h-6.92z\" />\n <path d=\"m2782 1122c-3.09 0-5.86 1.25-8.31 3.73-2.46 2.49-4.37 5.82-5.75 10s-2.07 8.35-2.07 12.5c0 3.11 0.43 5.44 1.28 6.98 0.86 1.55 2.29 2.32 4.29 2.32 1.98 0 3.92-0.86 5.82-2.56 1.9-1.71 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.81 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.31-0.49-4-1.48-5.08s-2.66-1.62-5.03-1.62zm-0.9-3.54c1.95 0 3.77 0.21 5.46 0.65 1.69 0.43 3.44 1.2 5.23 2.31l4.14-2.96 2.87 0.71-6.6 28.5c-0.66 2.85-0.99 5.07-0.99 6.65 0 1.2 0.19 2.07 0.58 2.61s1.01 0.81 1.84 0.81c0.9 0 1.86-0.37 2.88-1.1 1.02-0.74 2.45-2.14 4.31-4.2l2.56 2.51c-2.69 2.88-4.99 4.92-6.89 6.13-1.9 1.22-3.96 1.82-6.18 1.82-1.86 0-3.34-0.61-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.64 0.34-3.39 1.03-5.25l-0.58-0.18c-2.88 4.19-5.6 7.26-8.18 9.21-2.57 1.94-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73s-2.72-5.98-2.72-10.5c0-5.15 1.01-10.1 3.03-14.8 2.02-4.75 4.8-8.49 8.34-11.2 3.53-2.74 7.47-4.11 11.8-4.11zm75.2-20.5h2.65l-11 49.7c-0.66 2.97-0.99 5.19-0.99 6.65 0 1.2 0.2 2.07 0.58 2.61 0.39 0.54 1.01 0.81 1.85 0.81 0.89 0 1.85-0.37 2.87-1.1 1.02-0.74 2.46-2.14 4.31-4.2l2.56 2.51c-2.9 3.06-5.27 5.15-7.12 6.27-1.84 1.12-3.9 1.68-6.17 1.68-1.95 0-3.51-0.71-4.67-2.13-1.17-1.42-1.76-3.24-1.76-5.46 0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.62-2.85 0.77-3.79 0.15-0.95 0.22-1.82 0.22-2.63 0-0.9-0.16-1.58-0.49-2.04-0.33-0.47-0.8-0.81-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.34zm-29 0h2.65l-11 49.7c-0.66 2.97-0.99 5.19-0.99 6.65 0 1.2 0.2 2.07 0.58 2.61 0.39 0.54 1.01 0.81 1.85 0.81 0.89 0 1.85-0.37 2.87-1.1 1.02-0.74 2.46-2.14 4.31-4.2l2.56 2.51c-2.9 3.06-5.27 5.15-7.12 6.27-1.84 1.12-3.9 1.68-6.17 1.68-1.95 0-3.51-0.71-4.67-2.13-1.17-1.42-1.76-3.24-1.76-5.46 0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.62-2.85 0.77-3.79 0.15-0.95 0.22-1.82 0.22-2.63 0-0.9-0.16-1.58-0.49-2.04-0.33-0.47-0.8-0.81-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.34z\" />\n <path d=\"m2875 1098 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |good> ket -->\n <path d=\"m1889 530h6.91v83.6h-6.91z\" />\n <path d=\"m2040 554c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm-49 0c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm98.3-0.09c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.42 5.44 1.28 6.99 0.85 1.54 2.28 2.31 4.29 2.31 0.93 0 1.87-0.202 2.83-0.606 0.96-0.405 1.95-1.06 2.99-1.96 1.03-0.898 2.05-1.99 3.05-3.28s1.92-2.58 2.76-3.89c0.84-1.3 1.62-2.84 2.34-4.63 0.72-1.78 1.33-3.93 1.84-6.45l0.4-1.93c0.45-2.16 0.68-4.19 0.68-6.11 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm-148 0c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.45 5.44 1.35 6.99 0.89 1.54 2.3 2.31 4.22 2.31 1.53 0 3.05-0.524 4.56-1.57s3.13-2.71 4.85-4.99 3.06-4.45 4.02-6.51c0.96-2.07 1.77-4.64 2.45-7.73 0.67-3.08 1.01-5.76 1.01-8.04 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm100-3.5c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-49 0c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-51.7-0.045c1.88 0 3.66 0.225 5.34 0.674s3.37 1.21 5.08 2.29l4.13-2.96 2.88 0.719-4.63 20.9c-0.33 1.47-1.08 5.17-2.25 11.1-1.23 6.29-2.22 10.7-2.98 13.3-0.77 2.6-1.72 4.98-2.86 7.12s-2.6 4-4.4 5.59c-1.8 1.59-3.98 2.82-6.54 3.68-2.56 0.869-5.59 1.3-9.09 1.3-11.3 0-17-3.29-17-9.88 0-1.68 0.51-3.2 1.52-4.58 1.02-1.38 2.65-2.83 4.9-4.36l3.24 2.6c-0.57 0.689-1.05 1.37-1.44 2.04s-0.67 1.32-0.83 1.95c-0.17 0.629-0.25 1.38-0.25 2.25 0 2.25 0.81 3.89 2.43 4.92 1.61 1.03 4.05 1.55 7.32 1.55 3.68 0 6.64-0.831 8.87-2.49s4.14-4.34 5.73-8.02c1.58-3.68 3.13-9.25 4.62-16.7l-0.62-0.134c-2.91 3.98-5.6 6.89-8.09 8.72-2.49 1.83-5.17 2.74-8.04 2.74-3.27 0-5.8-1.23-7.62-3.68-1.81-2.46-2.71-5.96-2.71-10.5 0-5.12 1-10 3.01-14.8 2-4.72 4.79-8.47 8.35-11.3 3.57-2.78 7.53-4.18 11.9-4.18zm168-20.5h2.65l-11.2 49.7c-0.66 2.94-0.99 5.15-0.99 6.65 0 1.2 0.2 2.07 0.59 2.6s1 0.809 1.84 0.809c0.9 0 1.86-0.367 2.87-1.1 1.02-0.734 2.46-2.13 4.32-4.2l2.56 2.52c-2.76 2.9-5.08 4.96-6.97 6.15-1.88 1.2-3.92 1.8-6.1 1.8-1.86 0-3.34-0.614-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.65 0.34-3.4 1.03-5.26l-0.59-0.18c-2.87 4.19-5.6 7.26-8.17 9.21-2.58 1.95-5.3 2.92-8.18 2.92-3.29 0-5.84-1.24-7.66-3.73-1.81-2.48-2.71-5.97-2.71-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.33-11.2c3.54-2.74 7.47-4.11 11.8-4.11 1.82 0 3.51 0.187 5.05 0.562 1.54 0.374 3.12 1.02 4.74 1.95l2.33-10.4c0.24-0.989 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.899-0.16-1.58-0.49-2.04s-0.8-0.801-1.42-1.01c-0.61-0.209-1.71-0.359-3.3-0.449l0.54-2.34z\" />\n <path d=\"m2126 529 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |bad> ket -->\n <path d=\"m2766 1275h6.92v83.6h-6.92z\" />\n <path d=\"m2816 1301c-1.43 0-2.85 0.46-4.24 1.37s-2.94 2.43-4.65 4.54-3.1 4.27-4.18 6.49-1.99 5.05-2.74 8.49l-0.4 1.89c-0.45 2.09-0.68 4.13-0.68 6.11 0 2.36 0.52 4.07 1.55 5.12 1.04 1.05 2.75 1.57 5.15 1.57 1.22 0 2.39-0.2 3.5-0.61 1.11-0.4 2.24-1.07 3.39-2 1.15-0.92 2.25-2.14 3.28-3.66 1.03-1.51 1.99-3.37 2.85-5.59 0.87-2.22 1.55-4.59 2.03-7.12 0.47-2.53 0.71-4.95 0.71-7.25 0-3.12-0.44-5.46-1.32-7.01-0.88-1.56-2.3-2.34-4.25-2.34zm97.4-1.75c-3.06 0-5.8 1.23-8.22 3.71-2.43 2.47-4.34 5.8-5.73 9.99s-2.09 8.37-2.09 12.5c0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c0.93 0 1.87-0.2 2.83-0.6 0.96-0.41 1.96-1.06 2.99-1.96s2.05-1.99 3.05-3.28c1.01-1.29 1.93-2.58 2.77-3.88 0.83-1.31 1.61-2.85 2.33-4.63s1.33-3.93 1.84-6.45l0.41-1.93c0.45-2.15 0.67-4.19 0.67-6.11 0-2.33-0.49-4.03-1.48-5.1-0.99-1.06-2.64-1.59-4.94-1.59zm-50.9 0c-3.09 0-5.86 1.24-8.31 3.73-2.46 2.48-4.37 5.82-5.75 9.99-1.38 4.18-2.07 8.35-2.07 12.5 0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c1.98 0 3.92-0.85 5.82-2.56 1.9-1.7 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.8 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.3-0.49-4-1.48-5.07-0.99-1.08-2.67-1.62-5.03-1.62zm-0.9-3.55c1.95 0 3.77 0.22 5.46 0.65 1.69 0.44 3.43 1.21 5.23 2.32l4.13-2.97 2.88 0.72-6.6 28.5c-0.66 2.84-0.99 5.06-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.69 2.87-4.99 4.92-6.89 6.13-1.91 1.21-3.97 1.82-6.18 1.82-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11zm70.6-20.5h2.65l-11.2 49.7c-0.66 2.93-0.99 5.15-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.75 2.9-5.08 4.95-6.96 6.15-1.89 1.2-3.93 1.8-6.11 1.8-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11 1.83 0 3.51 0.19 5.05 0.56 1.55 0.38 3.13 1.03 4.74 1.96l2.34-10.4c0.24-0.99 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.9-0.17-1.58-0.5-2.05-0.33-0.46-0.8-0.8-1.41-1.01-0.62-0.21-1.72-0.36-3.3-0.45l0.54-2.33zm-124 0h2.61l-7.91 31.4 0.59 0.18c2.9-3.9 5.63-6.71 8.17-8.45 2.55-1.74 5.09-2.6 7.64-2.6 3.26 0 5.8 1.24 7.61 3.72 1.81 2.49 2.72 5.99 2.72 10.5 0 4.94-1 9.8-2.99 14.6-1.99 4.78-4.75 8.57-8.29 11.4-3.53 2.8-7.48 4.2-11.8 4.2-3.99 0-7.52-0.98-10.6-2.92l-4.13 2.92-2.87-0.72 11.6-51.4c0.69-3.05 1.03-5.27 1.03-6.64 0-1.26-0.38-2.15-1.14-2.66-0.77-0.5-2.14-0.79-4.11-0.85l0.54-2.33z\" />\n <path d=\"m2950 1275 17.9 40.3v3.33l-17.9 40.4-4.8-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- theta-->\n <path d=\"m2414 1260c-1.4 6.49-2.11 12-2.11 16.4 0 3.36 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.31 2.11-11.8 2.11-16.3 0-3.15-0.51-5.5-1.53-7.06-1.01-1.55-2.6-2.33-4.76-2.33zm0.54-3.64c8.69 0 13 5.51 13 16.5 0 3.12-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.5-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09-2.19-2.72-3.28-6.81-3.28-12.3 0-2.97 0.33-6.62 0.99-11 0.66-4.35 1.74-8.79 3.26-13.3 1.51-4.54 3.45-8.57 5.84-12.1 2.38-3.52 5.12-6.23 8.22-8.13s6.46-2.85 10.1-2.85z\" fill-rule=\"evenodd\" />\n </g>\n <g class=\"kata_svg_fill_accent kata_svg_stroke_accent\" font-family=\"sans-serif\" font-size=\"64px\" font-weight=\"400\">\n <!-- theta -->\n <path d=\"m2415 1364c-1.41 6.5-2.11 12-2.11 16.4 0 3.35 0.51 5.82 1.52 7.39 1.02 1.57 2.67 2.36 4.95 2.36 3.35 0 6.53-2.26 9.54-6.76 3.01-4.51 5.56-11 7.66-19.4zm18.4-30.3c-3.51 0-6.75 2.21-9.73 6.64-2.98 4.44-5.52 10.8-7.61 19h21.5c1.41-6.32 2.12-11.8 2.12-16.3 0-3.14-0.51-5.49-1.53-7.05s-2.61-2.33-4.76-2.33zm0.54-3.64c8.68 0 13 5.51 13 16.5 0 3.11-0.35 6.83-1.05 11.2-0.71 4.33-1.82 8.74-3.35 13.2s-3.46 8.47-5.79 11.9c-2.34 3.46-5.04 6.13-8.09 8.02-3.06 1.88-6.35 2.83-9.88 2.83-4.47 0-7.79-1.37-9.98-4.09-2.18-2.73-3.28-6.82-3.28-12.3 0-2.96 0.33-6.61 0.99-11 0.66-4.34 1.75-8.78 3.26-13.3 1.51-4.53 3.46-8.56 5.84-12.1s5.12-6.23 8.22-8.13 6.46-2.85 10.1-2.85z\" />\n <text transform=\"translate(2734 1521)\">State after</text>\n <text transform=\"translate(2734 1598)\">the first </text>\n <text transform=\"translate(2734 1676)\">reflection</text>\n </g>\n </g>\n</svg>\n\n\"Reflection about the mean\" is an operation for which the visual definition is much more intuitive than the mathematical one.\nIt is literally a reflection about the state $\\ket{\\text{all}}$ - the uniform superposition of all basis states in the search space. \n\nMathematically, this operation is described as $2\\ket{\\text{all}}\\bra{\\text{all}} - I$: it leaves the component of the input state parallel to the state $\\ket{\\text{all}}$ unchanged and multiplies the component orthogonal to it by $-1$.\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"447\" height=\"370\" overflow=\"hidden\" version=\"1.1\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\">\n<style>\n/* Default values, or theme set explicitly to light */\n:root, [data-theme=\"light\"] {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n}\n/* User has set OS preference for dark. (An explict light theme will override) */\n@media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n}\n/* Explicit dark theme set (should match above dark preference values) */\n[data-theme=\"dark\"] {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n}\n/*** Kata specific styles ***/\n.kata_svg_path {\n stroke: var(--kata-svg-path);\n stroke-width: 2;\n stroke-linecap: round;\n fill: none;\n}\n.kata_svg_text {\n fill: var(--kata-svg-stroke);\n}\n.kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n}\n.kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n}\n.kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n}\n</style>\n <g transform=\"matrix(.25 0 0 .25 -333 -132)\">\n <g class=\"kata_svg_path\">\n <!-- Main circle -->\n <circle cx=\"2020\" cy=\"1310\" r=\"670\" />\n <!-- x axis -->\n <path d=\"M2685 1310 h-1335 m1335 0 l-32 -32 m32 32 l-32 32\" />\n <!-- y axis -->\n <path d=\"m2020 645 v1323 m0 -1323 l-32 32 m32 -32 l32 32\" />\n <!-- Angle line -->\n <path d=\"m2665 1145 l-645 165 m645 -165 l-32 45 m32 -45 l -45 -25\" />\n <path d=\"m2357 1225c6.73 27 10.1 54.7 10.1 82.5\" fill-rule=\"evenodd\" />\n <!-- lower angle line -->\n <path d=\"m2665 1475 l-645 -165 m645 165 l-32 -45 m32 45 l -45 25\" stroke-width=\"10\" stroke-linecap=\"round\" />\n <!-- lower angle curve -->\n <path transform=\"matrix(1 0 0 -1 1677 1655)\" d=\"m679 259c7.22 28.1 10.9 56.9 10.9 85.9\" fill=\"none\" fill-rule=\"evenodd\" stroke-width=\"10\" />\n <path d=\"M2490 845 l-470 465 m470 -465 l-50 0 m50 0 l0 50\" class=\"kata_svg_stroke_accent\"/>\n <!-- Accented angle line -->\n <path d=\"m2270 1065c43.2 45.4 73.5 102 88 160\" class=\"kata_svg_stroke_accent\"/>\n </g>\n <g class=\"kata_svg_text\">\n <!-- |all> ket -->\n <path d=\"m2735 1098h6.92v83.6h-6.92z\" />\n <path d=\"m2782 1122c-3.09 0-5.86 1.25-8.31 3.73-2.46 2.49-4.37 5.82-5.75 10s-2.07 8.35-2.07 12.5c0 3.11 0.43 5.44 1.28 6.98 0.86 1.55 2.29 2.32 4.29 2.32 1.98 0 3.92-0.86 5.82-2.56 1.9-1.71 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.81 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.31-0.49-4-1.48-5.08s-2.66-1.62-5.03-1.62zm-0.9-3.54c1.95 0 3.77 0.21 5.46 0.65 1.69 0.43 3.44 1.2 5.23 2.31l4.14-2.96 2.87 0.71-6.6 28.5c-0.66 2.85-0.99 5.07-0.99 6.65 0 1.2 0.19 2.07 0.58 2.61s1.01 0.81 1.84 0.81c0.9 0 1.86-0.37 2.88-1.1 1.02-0.74 2.45-2.14 4.31-4.2l2.56 2.51c-2.69 2.88-4.99 4.92-6.89 6.13-1.9 1.22-3.96 1.82-6.18 1.82-1.86 0-3.34-0.61-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.64 0.34-3.39 1.03-5.25l-0.58-0.18c-2.88 4.19-5.6 7.26-8.18 9.21-2.57 1.94-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73s-2.72-5.98-2.72-10.5c0-5.15 1.01-10.1 3.03-14.8 2.02-4.75 4.8-8.49 8.34-11.2 3.53-2.74 7.47-4.11 11.8-4.11zm75.2-20.5h2.65l-11 49.7c-0.66 2.97-0.99 5.19-0.99 6.65 0 1.2 0.2 2.07 0.58 2.61 0.39 0.54 1.01 0.81 1.85 0.81 0.89 0 1.85-0.37 2.87-1.1 1.02-0.74 2.46-2.14 4.31-4.2l2.56 2.51c-2.9 3.06-5.27 5.15-7.12 6.27-1.84 1.12-3.9 1.68-6.17 1.68-1.95 0-3.51-0.71-4.67-2.13-1.17-1.42-1.76-3.24-1.76-5.46 0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.62-2.85 0.77-3.79 0.15-0.95 0.22-1.82 0.22-2.63 0-0.9-0.16-1.58-0.49-2.04-0.33-0.47-0.8-0.81-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.34zm-29 0h2.65l-11 49.7c-0.66 2.97-0.99 5.19-0.99 6.65 0 1.2 0.2 2.07 0.58 2.61 0.39 0.54 1.01 0.81 1.85 0.81 0.89 0 1.85-0.37 2.87-1.1 1.02-0.74 2.46-2.14 4.31-4.2l2.56 2.51c-2.9 3.06-5.27 5.15-7.12 6.27-1.84 1.12-3.9 1.68-6.17 1.68-1.95 0-3.51-0.71-4.67-2.13-1.17-1.42-1.76-3.24-1.76-5.46 0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.62-2.85 0.77-3.79 0.15-0.95 0.22-1.82 0.22-2.63 0-0.9-0.16-1.58-0.49-2.04-0.33-0.47-0.8-0.81-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.34z\" />\n <path d=\"m2875 1098 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |good> ket -->\n <path d=\"m1889 530h6.91v83.6h-6.91z\" />\n <path d=\"m2040 554c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm-49 0c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm98.3-0.09c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.42 5.44 1.28 6.99 0.85 1.54 2.28 2.31 4.29 2.31 0.93 0 1.87-0.202 2.83-0.606 0.96-0.405 1.95-1.06 2.99-1.96 1.03-0.898 2.05-1.99 3.05-3.28s1.92-2.58 2.76-3.89c0.84-1.3 1.62-2.84 2.34-4.63 0.72-1.78 1.33-3.93 1.84-6.45l0.4-1.93c0.45-2.16 0.68-4.19 0.68-6.11 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm-148 0c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.45 5.44 1.35 6.99 0.89 1.54 2.3 2.31 4.22 2.31 1.53 0 3.05-0.524 4.56-1.57s3.13-2.71 4.85-4.99 3.06-4.45 4.02-6.51c0.96-2.07 1.77-4.64 2.45-7.73 0.67-3.08 1.01-5.76 1.01-8.04 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm100-3.5c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-49 0c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-51.7-0.045c1.88 0 3.66 0.225 5.34 0.674s3.37 1.21 5.08 2.29l4.13-2.96 2.88 0.719-4.63 20.9c-0.33 1.47-1.08 5.17-2.25 11.1-1.23 6.29-2.22 10.7-2.98 13.3-0.77 2.6-1.72 4.98-2.86 7.12s-2.6 4-4.4 5.59c-1.8 1.59-3.98 2.82-6.54 3.68-2.56 0.869-5.59 1.3-9.09 1.3-11.3 0-17-3.29-17-9.88 0-1.68 0.51-3.2 1.52-4.58 1.02-1.38 2.65-2.83 4.9-4.36l3.24 2.6c-0.57 0.689-1.05 1.37-1.44 2.04s-0.67 1.32-0.83 1.95c-0.17 0.629-0.25 1.38-0.25 2.25 0 2.25 0.81 3.89 2.43 4.92 1.61 1.03 4.05 1.55 7.32 1.55 3.68 0 6.64-0.831 8.87-2.49s4.14-4.34 5.73-8.02c1.58-3.68 3.13-9.25 4.62-16.7l-0.62-0.134c-2.91 3.98-5.6 6.89-8.09 8.72-2.49 1.83-5.17 2.74-8.04 2.74-3.27 0-5.8-1.23-7.62-3.68-1.81-2.46-2.71-5.96-2.71-10.5 0-5.12 1-10 3.01-14.8 2-4.72 4.79-8.47 8.35-11.3 3.57-2.78 7.53-4.18 11.9-4.18zm168-20.5h2.65l-11.2 49.7c-0.66 2.94-0.99 5.15-0.99 6.65 0 1.2 0.2 2.07 0.59 2.6s1 0.809 1.84 0.809c0.9 0 1.86-0.367 2.87-1.1 1.02-0.734 2.46-2.13 4.32-4.2l2.56 2.52c-2.76 2.9-5.08 4.96-6.97 6.15-1.88 1.2-3.92 1.8-6.1 1.8-1.86 0-3.34-0.614-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.65 0.34-3.4 1.03-5.26l-0.59-0.18c-2.87 4.19-5.6 7.26-8.17 9.21-2.58 1.95-5.3 2.92-8.18 2.92-3.29 0-5.84-1.24-7.66-3.73-1.81-2.48-2.71-5.97-2.71-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.33-11.2c3.54-2.74 7.47-4.11 11.8-4.11 1.82 0 3.51 0.187 5.05 0.562 1.54 0.374 3.12 1.02 4.74 1.95l2.33-10.4c0.24-0.989 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.899-0.16-1.58-0.49-2.04s-0.8-0.801-1.42-1.01c-0.61-0.209-1.71-0.359-3.3-0.449l0.54-2.34z\" />\n <path d=\"m2126 529 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |bad> ket -->\n <path d=\"m2766 1275h6.92v83.6h-6.92z\" />\n <path d=\"m2816 1301c-1.43 0-2.85 0.46-4.24 1.37s-2.94 2.43-4.65 4.54-3.1 4.27-4.18 6.49-1.99 5.05-2.74 8.49l-0.4 1.89c-0.45 2.09-0.68 4.13-0.68 6.11 0 2.36 0.52 4.07 1.55 5.12 1.04 1.05 2.75 1.57 5.15 1.57 1.22 0 2.39-0.2 3.5-0.61 1.11-0.4 2.24-1.07 3.39-2 1.15-0.92 2.25-2.14 3.28-3.66 1.03-1.51 1.99-3.37 2.85-5.59 0.87-2.22 1.55-4.59 2.03-7.12 0.47-2.53 0.71-4.95 0.71-7.25 0-3.12-0.44-5.46-1.32-7.01-0.88-1.56-2.3-2.34-4.25-2.34zm97.4-1.75c-3.06 0-5.8 1.23-8.22 3.71-2.43 2.47-4.34 5.8-5.73 9.99s-2.09 8.37-2.09 12.5c0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c0.93 0 1.87-0.2 2.83-0.6 0.96-0.41 1.96-1.06 2.99-1.96s2.05-1.99 3.05-3.28c1.01-1.29 1.93-2.58 2.77-3.88 0.83-1.31 1.61-2.85 2.33-4.63s1.33-3.93 1.84-6.45l0.41-1.93c0.45-2.15 0.67-4.19 0.67-6.11 0-2.33-0.49-4.03-1.48-5.1-0.99-1.06-2.64-1.59-4.94-1.59zm-50.9 0c-3.09 0-5.86 1.24-8.31 3.73-2.46 2.48-4.37 5.82-5.75 9.99-1.38 4.18-2.07 8.35-2.07 12.5 0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c1.98 0 3.92-0.85 5.82-2.56 1.9-1.7 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.8 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.3-0.49-4-1.48-5.07-0.99-1.08-2.67-1.62-5.03-1.62zm-0.9-3.55c1.95 0 3.77 0.22 5.46 0.65 1.69 0.44 3.43 1.21 5.23 2.32l4.13-2.97 2.88 0.72-6.6 28.5c-0.66 2.84-0.99 5.06-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.69 2.87-4.99 4.92-6.89 6.13-1.91 1.21-3.97 1.82-6.18 1.82-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11zm70.6-20.5h2.65l-11.2 49.7c-0.66 2.93-0.99 5.15-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.75 2.9-5.08 4.95-6.96 6.15-1.89 1.2-3.93 1.8-6.11 1.8-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11 1.83 0 3.51 0.19 5.05 0.56 1.55 0.38 3.13 1.03 4.74 1.96l2.34-10.4c0.24-0.99 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.9-0.17-1.58-0.5-2.05-0.33-0.46-0.8-0.8-1.41-1.01-0.62-0.21-1.72-0.36-3.3-0.45l0.54-2.33zm-124 0h2.61l-7.91 31.4 0.59 0.18c2.9-3.9 5.63-6.71 8.17-8.45 2.55-1.74 5.09-2.6 7.64-2.6 3.26 0 5.8 1.24 7.61 3.72 1.81 2.49 2.72 5.99 2.72 10.5 0 4.94-1 9.8-2.99 14.6-1.99 4.78-4.75 8.57-8.29 11.4-3.53 2.8-7.48 4.2-11.8 4.2-3.99 0-7.52-0.98-10.6-2.92l-4.13 2.92-2.87-0.72 11.6-51.4c0.69-3.05 1.03-5.27 1.03-6.64 0-1.26-0.38-2.15-1.14-2.66-0.77-0.5-2.14-0.79-4.11-0.85l0.54-2.33z\" />\n <path d=\"m2950 1275 17.9 40.3v3.33l-17.9 40.4-4.8-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- theta-->\n <path d=\"m2414 1260c-1.4 6.49-2.11 12-2.11 16.4 0 3.36 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.31 2.11-11.8 2.11-16.3 0-3.15-0.51-5.5-1.53-7.06-1.01-1.55-2.6-2.33-4.76-2.33zm0.54-3.64c8.69 0 13 5.51 13 16.5 0 3.12-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.5-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09-2.19-2.72-3.28-6.81-3.28-12.3 0-2.97 0.33-6.62 0.99-11 0.66-4.35 1.74-8.79 3.26-13.3 1.51-4.54 3.45-8.57 5.84-12.1 2.38-3.52 5.12-6.23 8.22-8.13s6.46-2.85 10.1-2.85z\" fill-rule=\"evenodd\" />\n <!-- lower theta -->\n <path d=\"m2415 1364c-1.41 6.5-2.11 12-2.11 16.4 0 3.35 0.51 5.82 1.52 7.39 1.02 1.57 2.67 2.36 4.95 2.36 3.35 0 6.53-2.26 9.54-6.76 3.01-4.51 5.56-11 7.66-19.4zm18.4-30.3c-3.51 0-6.75 2.21-9.73 6.64-2.98 4.44-5.52 10.8-7.61 19h21.5c1.41-6.32 2.12-11.8 2.12-16.3 0-3.14-0.51-5.49-1.53-7.05s-2.61-2.33-4.76-2.33zm0.54-3.64c8.68 0 13 5.51 13 16.5 0 3.11-0.35 6.83-1.05 11.2-0.71 4.33-1.82 8.74-3.35 13.2s-3.46 8.47-5.79 11.9c-2.34 3.46-5.04 6.13-8.09 8.02-3.06 1.88-6.35 2.83-9.88 2.83-4.47 0-7.79-1.37-9.98-4.09-2.18-2.73-3.28-6.82-3.28-12.3 0-2.96 0.33-6.61 0.99-11 0.66-4.34 1.75-8.78 3.26-13.3 1.51-4.53 3.46-8.56 5.84-12.1s5.12-6.23 8.22-8.13 6.46-2.85 10.1-2.85z\" />\n </g>\n <g class=\"kata_svg_fill_accent kata_svg_stroke_accent\" font-family=\"sans-serif\" font-size=\"64px\" font-weight=\"400\">\n <text transform=\"translate(2490 780)\">State after</text>\n <text transform=\"translate(2550 840)\">the second</text>\n <text transform=\"translate(2610 900)\">reflection</text>\n <!--2 \\theta and angle -->\n <path d=\"m2410 1105c-1.41 6.5-2.12 12-2.12 16.4 0 3.35 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.32 2.11-11.8 2.11-16.3 0-3.14-0.51-5.5-1.52-7.05-1.02-1.56-2.61-2.34-4.77-2.34zm-58.2-2.7c5.57 0 9.77 1.22 12.6 3.66 2.84 2.44 4.27 5.98 4.27 10.6 0 1.59-0.16 3.05-0.48 4.38-0.31 1.33-0.8 2.65-1.48 3.95-0.67 1.3-1.58 2.7-2.72 4.2-1.13 1.5-2.39 3.02-3.77 4.56s-3.76 4.11-7.14 7.7c-5.69 6.02-9.87 11.3-12.5 15.8h16.9c1.47 0 2.65-0.09 3.55-0.27s1.62-0.479 2.16-0.898c0.54-0.42 0.96-0.966 1.28-1.64 0.31-0.674 0.71-1.72 1.19-3.12h3.82l-0.77 13.1h-37v-2.16c1.29-3.14 3.03-6.36 5.21-9.66 2.19-3.3 5.29-7.17 9.3-11.6 3.47-3.83 5.98-6.74 7.5-8.72 1.68-2.16 2.93-4.02 3.75-5.59 0.83-1.57 1.42-3.06 1.78-4.45s0.54-2.79 0.54-4.2c0-2.25-0.36-4.23-1.08-5.95s-1.82-3.08-3.3-4.07c-1.49-0.988-3.35-1.48-5.6-1.48-5.6 0-9.37 3.11-11.3 9.34h-5.43v-8.62c3.62-1.71 7.01-2.94 10.2-3.71 3.16-0.763 6-1.14 8.52-1.14zm58.7-0.943c8.69 0 13 5.51 13 16.5 0 3.11-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.49-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09s-3.28-6.81-3.28-12.3c0-2.96 0.33-6.62 0.99-11 0.66-4.34 1.74-8.78 3.26-13.3 1.51-4.54 3.46-8.56 5.84-12.1s5.12-6.23 8.22-8.13 6.46-2.85 10.1-2.85z\" fill=\"#0070c0\" fill-rule=\"evenodd\" />\n </g>\n </g>\n</svg>\n\nAs we can see, the pair of these reflections combined amount to a counterclockwise rotation by an angle $2\\theta$. \nIf we repeat the Grover's iteration, reflecting the new state first along the horizontal axis and then along the $\\ket{\\text{all}}$ vector, it performs a rotation by $2\\theta$ again. The angle of this rotation depends only on the angle between the reflection axes and not on the state we reflect!\n\nEach iteration of Grover's search adds $2\\theta$ to the current angle in the expression of the system state as a superposition of $\\ket{\\text{good}}$ and $\\ket{\\text{bad}}$.\nAfter applying $R$ iterations of Grover's search the state of the system will become\n\n$$\\sin{(2R+1)\\theta}\\ket{\\text{good}} + \\cos{(2R+1)\\theta}\\ket{\\text{bad}}$$\n\nAt firat, each iteration brings the state of the system closer to the vertical axis, increasing the probability of measuring one of the basis states that are part of $\\ket{\\text{good}}$ - the states that are solutions to the problem."
6984
6984
  }
6985
6985
  ]
6986
6986
  },
@@ -7075,7 +7075,7 @@ export default {
7075
7075
  "items": [
7076
7076
  {
7077
7077
  "type": "text-content",
7078
- "content": "\nThe optimal number of iterations to use in Grover's search algorithm is typically defined as the number of iterations \nafter which the success probability of the algorithm - the probability of measuring one of the \"good\" states - is maximized.\n\nGeometrically, this means that the state vector should be rotated to be as close to the vertical axis as possible.\nMathematically, this means maximizing the ampitude $\\sin{(2R+1)\\theta}$ of the state $\\ket{\\text{good}}$ \nin the superposition.\nWith either definition, the goal is to have the angle $(2R+1)\\theta$ that describes the system after $R$ rotations\nas close to $\\frac{\\pi}{2}$ as possible:\n\n$$(2R+1)\\theta \\approx \\frac{\\pi}{2}$$\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"447\" height=\"370\" overflow=\"hidden\" version=\"1.1\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\">\n <style>\n :root {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n }\n @media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n }\n .kata_svg_path {\n stroke: var(--kata-svg-path);\n stroke-width: 10;\n stroke-linecap: round;\n fill: none;\n }\n .kata_svg_text {\n fill: var(--kata-svg-stroke);\n }\n .kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n }\n .kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n }\n .kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n }\n </style>\n <g transform=\"matrix(.25 0 0 .25 -333 -132)\">\n <g class=\"kata_svg_path\">\n <!-- Main circle -->\n <circle cx=\"2020\" cy=\"1310\" r=\"670\" />\n <!-- x axis -->\n <path d=\"M2685 1310 h-1335 m1335 0 l-32 -32 m32 32 l-32 32\" />\n <!-- y axis -->\n <path d=\"m2020 645 v1323 m0 -1323 l-32 32 m32 -32 l32 32\" />\n <!-- Angle line -->\n <path d=\"m2665 1145 l-645 165 m645 -165 l-32 45 m32 -45 l -45 -25\" />\n <path d=\"m2357 1225c6.73 27 10.1 54.7 10.1 82.5\" fill-rule=\"evenodd\" />\n <!-- upper angle line -->\n <path d=\"M2490 845 l-470 465 m470 -465 l-50 0 m50 0 l0 50\" stroke-width=\"10\" stroke-linecap=\"round\" />\n <path d=\"m2270 1065c43.2 45.4 73.5 102 88 160\" />\n <path d=\"M2150 655 l-130 655 m130 -655 l-45 30 m45 -30 l30 45\" stroke-width=\"10\" stroke-linecap=\"round\" class=\"kata_svg_stroke_accent\"/>\n <path d=\"m2090 956c67.8 16 129 51.7 177 103\" class=\"kata_svg_stroke_accent\"/>\n </g>\n <g class=\"kata_svg_text\">\n <!-- |good> ket -->\n <path d=\"m1889 530h6.91v83.6h-6.91z\" />\n <path d=\"m2040 554c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm-49 0c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm98.3-0.09c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.42 5.44 1.28 6.99 0.85 1.54 2.28 2.31 4.29 2.31 0.93 0 1.87-0.202 2.83-0.606 0.96-0.405 1.95-1.06 2.99-1.96 1.03-0.898 2.05-1.99 3.05-3.28s1.92-2.58 2.76-3.89c0.84-1.3 1.62-2.84 2.34-4.63 0.72-1.78 1.33-3.93 1.84-6.45l0.4-1.93c0.45-2.16 0.68-4.19 0.68-6.11 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm-148 0c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.45 5.44 1.35 6.99 0.89 1.54 2.3 2.31 4.22 2.31 1.53 0 3.05-0.524 4.56-1.57s3.13-2.71 4.85-4.99 3.06-4.45 4.02-6.51c0.96-2.07 1.77-4.64 2.45-7.73 0.67-3.08 1.01-5.76 1.01-8.04 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm100-3.5c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-49 0c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-51.7-0.045c1.88 0 3.66 0.225 5.34 0.674s3.37 1.21 5.08 2.29l4.13-2.96 2.88 0.719-4.63 20.9c-0.33 1.47-1.08 5.17-2.25 11.1-1.23 6.29-2.22 10.7-2.98 13.3-0.77 2.6-1.72 4.98-2.86 7.12s-2.6 4-4.4 5.59c-1.8 1.59-3.98 2.82-6.54 3.68-2.56 0.869-5.59 1.3-9.09 1.3-11.3 0-17-3.29-17-9.88 0-1.68 0.51-3.2 1.52-4.58 1.02-1.38 2.65-2.83 4.9-4.36l3.24 2.6c-0.57 0.689-1.05 1.37-1.44 2.04s-0.67 1.32-0.83 1.95c-0.17 0.629-0.25 1.38-0.25 2.25 0 2.25 0.81 3.89 2.43 4.92 1.61 1.03 4.05 1.55 7.32 1.55 3.68 0 6.64-0.831 8.87-2.49s4.14-4.34 5.73-8.02c1.58-3.68 3.13-9.25 4.62-16.7l-0.62-0.134c-2.91 3.98-5.6 6.89-8.09 8.72-2.49 1.83-5.17 2.74-8.04 2.74-3.27 0-5.8-1.23-7.62-3.68-1.81-2.46-2.71-5.96-2.71-10.5 0-5.12 1-10 3.01-14.8 2-4.72 4.79-8.47 8.35-11.3 3.57-2.78 7.53-4.18 11.9-4.18zm168-20.5h2.65l-11.2 49.7c-0.66 2.94-0.99 5.15-0.99 6.65 0 1.2 0.2 2.07 0.59 2.6s1 0.809 1.84 0.809c0.9 0 1.86-0.367 2.87-1.1 1.02-0.734 2.46-2.13 4.32-4.2l2.56 2.52c-2.76 2.9-5.08 4.96-6.97 6.15-1.88 1.2-3.92 1.8-6.1 1.8-1.86 0-3.34-0.614-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.65 0.34-3.4 1.03-5.26l-0.59-0.18c-2.87 4.19-5.6 7.26-8.17 9.21-2.58 1.95-5.3 2.92-8.18 2.92-3.29 0-5.84-1.24-7.66-3.73-1.81-2.48-2.71-5.97-2.71-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.33-11.2c3.54-2.74 7.47-4.11 11.8-4.11 1.82 0 3.51 0.187 5.05 0.562 1.54 0.374 3.12 1.02 4.74 1.95l2.33-10.4c0.24-0.989 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.899-0.16-1.58-0.49-2.04s-0.8-0.801-1.42-1.01c-0.61-0.209-1.71-0.359-3.3-0.449l0.54-2.34z\" />\n <path d=\"m2126 529 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |bad> ket -->\n <path d=\"m2766 1275h6.92v83.6h-6.92z\" />\n <path d=\"m2816 1301c-1.43 0-2.85 0.46-4.24 1.37s-2.94 2.43-4.65 4.54-3.1 4.27-4.18 6.49-1.99 5.05-2.74 8.49l-0.4 1.89c-0.45 2.09-0.68 4.13-0.68 6.11 0 2.36 0.52 4.07 1.55 5.12 1.04 1.05 2.75 1.57 5.15 1.57 1.22 0 2.39-0.2 3.5-0.61 1.11-0.4 2.24-1.07 3.39-2 1.15-0.92 2.25-2.14 3.28-3.66 1.03-1.51 1.99-3.37 2.85-5.59 0.87-2.22 1.55-4.59 2.03-7.12 0.47-2.53 0.71-4.95 0.71-7.25 0-3.12-0.44-5.46-1.32-7.01-0.88-1.56-2.3-2.34-4.25-2.34zm97.4-1.75c-3.06 0-5.8 1.23-8.22 3.71-2.43 2.47-4.34 5.8-5.73 9.99s-2.09 8.37-2.09 12.5c0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c0.93 0 1.87-0.2 2.83-0.6 0.96-0.41 1.96-1.06 2.99-1.96s2.05-1.99 3.05-3.28c1.01-1.29 1.93-2.58 2.77-3.88 0.83-1.31 1.61-2.85 2.33-4.63s1.33-3.93 1.84-6.45l0.41-1.93c0.45-2.15 0.67-4.19 0.67-6.11 0-2.33-0.49-4.03-1.48-5.1-0.99-1.06-2.64-1.59-4.94-1.59zm-50.9 0c-3.09 0-5.86 1.24-8.31 3.73-2.46 2.48-4.37 5.82-5.75 9.99-1.38 4.18-2.07 8.35-2.07 12.5 0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c1.98 0 3.92-0.85 5.82-2.56 1.9-1.7 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.8 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.3-0.49-4-1.48-5.07-0.99-1.08-2.67-1.62-5.03-1.62zm-0.9-3.55c1.95 0 3.77 0.22 5.46 0.65 1.69 0.44 3.43 1.21 5.23 2.32l4.13-2.97 2.88 0.72-6.6 28.5c-0.66 2.84-0.99 5.06-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.69 2.87-4.99 4.92-6.89 6.13-1.91 1.21-3.97 1.82-6.18 1.82-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11zm70.6-20.5h2.65l-11.2 49.7c-0.66 2.93-0.99 5.15-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.75 2.9-5.08 4.95-6.96 6.15-1.89 1.2-3.93 1.8-6.11 1.8-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11 1.83 0 3.51 0.19 5.05 0.56 1.55 0.38 3.13 1.03 4.74 1.96l2.34-10.4c0.24-0.99 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.9-0.17-1.58-0.5-2.05-0.33-0.46-0.8-0.8-1.41-1.01-0.62-0.21-1.72-0.36-3.3-0.45l0.54-2.33zm-124 0h2.61l-7.91 31.4 0.59 0.18c2.9-3.9 5.63-6.71 8.17-8.45 2.55-1.74 5.09-2.6 7.64-2.6 3.26 0 5.8 1.24 7.61 3.72 1.81 2.49 2.72 5.99 2.72 10.5 0 4.94-1 9.8-2.99 14.6-1.99 4.78-4.75 8.57-8.29 11.4-3.53 2.8-7.48 4.2-11.8 4.2-3.99 0-7.52-0.98-10.6-2.92l-4.13 2.92-2.87-0.72 11.6-51.4c0.69-3.05 1.03-5.27 1.03-6.64 0-1.26-0.38-2.15-1.14-2.66-0.77-0.5-2.14-0.79-4.11-0.85l0.54-2.33z\" />\n <path d=\"m2950 1275 17.9 40.3v3.33l-17.9 40.4-4.8-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- theta-->\n <path d=\"m2414 1260c-1.4 6.49-2.11 12-2.11 16.4 0 3.36 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.31 2.11-11.8 2.11-16.3 0-3.15-0.51-5.5-1.53-7.06-1.01-1.55-2.6-2.33-4.76-2.33zm0.54-3.64c8.69 0 13 5.51 13 16.5 0 3.12-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.5-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09-2.19-2.72-3.28-6.81-3.28-12.3 0-2.97 0.33-6.62 0.99-11 0.66-4.35 1.74-8.79 3.26-13.3 1.51-4.54 3.45-8.57 5.84-12.1 2.38-3.52 5.12-6.23 8.22-8.13s6.46-2.85 10.1-2.85z\" fill-rule=\"evenodd\" />\n <!--2 \\theta and angle -->\n <path d=\"m2410 1105c-1.41 6.5-2.12 12-2.12 16.4 0 3.35 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.32 2.11-11.8 2.11-16.3 0-3.14-0.51-5.5-1.52-7.05-1.02-1.56-2.61-2.34-4.77-2.34zm-58.2-2.7c5.57 0 9.77 1.22 12.6 3.66 2.84 2.44 4.27 5.98 4.27 10.6 0 1.59-0.16 3.05-0.48 4.38-0.31 1.33-0.8 2.65-1.48 3.95-0.67 1.3-1.58 2.7-2.72 4.2-1.13 1.5-2.39 3.02-3.77 4.56s-3.76 4.11-7.14 7.7c-5.69 6.02-9.87 11.3-12.5 15.8h16.9c1.47 0 2.65-0.09 3.55-0.27s1.62-0.479 2.16-0.898c0.54-0.42 0.96-0.966 1.28-1.64 0.31-0.674 0.71-1.72 1.19-3.12h3.82l-0.77 13.1h-37v-2.16c1.29-3.14 3.03-6.36 5.21-9.66 2.19-3.3 5.29-7.17 9.3-11.6 3.47-3.83 5.98-6.74 7.5-8.72 1.68-2.16 2.93-4.02 3.75-5.59 0.83-1.57 1.42-3.06 1.78-4.45s0.54-2.79 0.54-4.2c0-2.25-0.36-4.23-1.08-5.95s-1.82-3.08-3.3-4.07c-1.49-0.988-3.35-1.48-5.6-1.48-5.6 0-9.37 3.11-11.3 9.34h-5.43v-8.62c3.62-1.71 7.01-2.94 10.2-3.71 3.16-0.763 6-1.14 8.52-1.14zm58.7-0.943c8.69 0 13 5.51 13 16.5 0 3.11-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.49-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09s-3.28-6.81-3.28-12.3c0-2.96 0.33-6.62 0.99-11 0.66-4.34 1.74-8.78 3.26-13.3 1.51-4.54 3.46-8.56 5.84-12.1s5.12-6.23 8.22-8.13 6.46-2.85 10.1-2.85z\" />\n </g>\n <g class=\"kata_svg_fill_accent kata_svg_stroke_accent\" font-family=\"sans-serif\" font-size=\"64px\" font-weight=\"400\">\n <text transform=\"translate(2220 580)\">Close enough</text>\n <text transform=\"translate(2220 650)\">to measure</text>\n <!--2 \\theta and angle -->\n <path d=\"m2210 905c-1.41 6.5-2.12 12-2.12 16.4 0 3.35 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.32 2.11-11.8 2.11-16.3 0-3.14-0.51-5.5-1.52-7.05-1.02-1.56-2.61-2.34-4.77-2.34zm-58.2-2.7c5.57 0 9.77 1.22 12.6 3.66 2.84 2.44 4.27 5.98 4.27 10.6 0 1.59-0.16 3.05-0.48 4.38-0.31 1.33-0.8 2.65-1.48 3.95-0.67 1.3-1.58 2.7-2.72 4.2-1.13 1.5-2.39 3.02-3.77 4.56s-3.76 4.11-7.14 7.7c-5.69 6.02-9.87 11.3-12.5 15.8h16.9c1.47 0 2.65-0.09 3.55-0.27s1.62-0.479 2.16-0.898c0.54-0.42 0.96-0.966 1.28-1.64 0.31-0.674 0.71-1.72 1.19-3.12h3.82l-0.77 13.1h-37v-2.16c1.29-3.14 3.03-6.36 5.21-9.66 2.19-3.3 5.29-7.17 9.3-11.6 3.47-3.83 5.98-6.74 7.5-8.72 1.68-2.16 2.93-4.02 3.75-5.59 0.83-1.57 1.42-3.06 1.78-4.45s0.54-2.79 0.54-4.2c0-2.25-0.36-4.23-1.08-5.95s-1.82-3.08-3.3-4.07c-1.49-0.988-3.35-1.48-5.6-1.48-5.6 0-9.37 3.11-11.3 9.34h-5.43v-8.62c3.62-1.71 7.01-2.94 10.2-3.71 3.16-0.763 6-1.14 8.52-1.14zm58.7-0.943c8.69 0 13 5.51 13 16.5 0 3.11-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.49-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09s-3.28-6.81-3.28-12.3c0-2.96 0.33-6.62 0.99-11 0.66-4.34 1.74-8.78 3.26-13.3 1.51-4.54 3.46-8.56 5.84-12.1s5.12-6.23 8.22-8.13 6.46-2.85 10.1-2.85z\" fill=\"#0070c0\" fill-rule=\"evenodd\" />\n </g>\n </g>\n</svg>\n\nNow, recall that $\\theta = \\arcsin \\sqrt{\\frac{M}{N}}$. When $M$ is much smaller than $N$, $\\frac{M}{N}$ is close to 0, and $\\theta$ is a small angle that can approximated as $\\theta \\approx \\sqrt{\\frac{M}{N}}$. This gives the following equation for $R_{opt}$\n\n$$ 2R_{opt}+1 \\approx \\frac{\\pi}{2\\theta} = \\frac{\\pi}{2}\\sqrt{\\frac{N}{M}}$$\nSince $\\theta$ is small, $R_{opt}$ is large, and the $+1$ term next to $2R_{opt}$ can be ignored, giving the final formula:\n$$ R_{opt} \\approx \\frac{\\pi}{4}\\sqrt{\\frac{N}{M}}$$\n\nWhat happens if you use more iterations than is optimal? Each iteration will keep rotating the state $2\\theta$ counterclockwise,\ngetting it further away from the vertical axis and thus reducing the probability of measuring the correct answer.\n\nIn this demo you will see how success probability of Grover's algorithm changes when it uses different numbers of iterations\nbefore the final measurements."
7078
+ "content": "\nThe optimal number of iterations to use in Grover's search algorithm is typically defined as the number of iterations \nafter which the success probability of the algorithm - the probability of measuring one of the \"good\" states - is maximized.\n\nGeometrically, this means that the state vector should be rotated to be as close to the vertical axis as possible.\nMathematically, this means maximizing the ampitude $\\sin{(2R+1)\\theta}$ of the state $\\ket{\\text{good}}$ \nin the superposition.\nWith either definition, the goal is to have the angle $(2R+1)\\theta$ that describes the system after $R$ rotations\nas close to $\\frac{\\pi}{2}$ as possible:\n\n$$(2R+1)\\theta \\approx \\frac{\\pi}{2}$$\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"447\" height=\"370\" overflow=\"hidden\" version=\"1.1\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\">\n<style>\n/* Default values, or theme set explicitly to light */\n:root, [data-theme=\"light\"] {\n --kata-svg-stroke: #222;\n --kata-svg-fill: #fff;\n --kata-svg-path: #777;\n --kata-svg-accent: #06c;\n}\n/* User has set OS preference for dark. (An explict light theme will override) */\n@media(prefers-color-scheme: dark) {\n :root {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n }\n}\n/* Explicit dark theme set (should match above dark preference values) */\n[data-theme=\"dark\"] {\n --kata-svg-stroke: #eee;\n --kata-svg-fill: #111;\n --kata-svg-path: #bbb;\n --kata-svg-accent: #08f;\n}\n/*** Kata specific styles ***/\n.kata_svg_path {\n stroke: var(--kata-svg-path);\n stroke-width: 2;\n stroke-linecap: round;\n fill: none;\n}\n.kata_svg_text {\n fill: var(--kata-svg-stroke);\n}\n.kata_svg_point {\n fill: var(--kata-svg-fill);\n stroke: var(--kata-svg-stroke);\n}\n.kata_svg_fill_accent {\n fill: var(--kata-svg-accent);\n}\n.kata_svg_stroke_accent {\n stroke: var(--kata-svg-accent);\n}\n</style>\n <g transform=\"matrix(.25 0 0 .25 -333 -132)\">\n <g class=\"kata_svg_path\">\n <!-- Main circle -->\n <circle cx=\"2020\" cy=\"1310\" r=\"670\" />\n <!-- x axis -->\n <path d=\"M2685 1310 h-1335 m1335 0 l-32 -32 m32 32 l-32 32\" />\n <!-- y axis -->\n <path d=\"m2020 645 v1323 m0 -1323 l-32 32 m32 -32 l32 32\" />\n <!-- Angle line -->\n <path d=\"m2665 1145 l-645 165 m645 -165 l-32 45 m32 -45 l -45 -25\" />\n <path d=\"m2357 1225c6.73 27 10.1 54.7 10.1 82.5\" fill-rule=\"evenodd\" />\n <!-- upper angle line -->\n <path d=\"M2490 845 l-470 465 m470 -465 l-50 0 m50 0 l0 50\" stroke-width=\"10\" stroke-linecap=\"round\" />\n <path d=\"m2270 1065c43.2 45.4 73.5 102 88 160\" />\n <path d=\"M2150 655 l-130 655 m130 -655 l-45 30 m45 -30 l30 45\" stroke-width=\"10\" stroke-linecap=\"round\" class=\"kata_svg_stroke_accent\"/>\n <path d=\"m2090 956c67.8 16 129 51.7 177 103\" class=\"kata_svg_stroke_accent\"/>\n </g>\n <g class=\"kata_svg_text\">\n <!-- |good> ket -->\n <path d=\"m1889 530h6.91v83.6h-6.91z\" />\n <path d=\"m2040 554c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm-49 0c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.05 7.3 1.36 1.57 3.42 2.36 6.17 2.36 2.94 0 5.54-1.32 7.82-3.95 2.28-2.64 4.07-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.24-0.63-5.67-1.89-7.3s-3.22-2.45-5.89-2.45zm98.3-0.09c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.42 5.44 1.28 6.99 0.85 1.54 2.28 2.31 4.29 2.31 0.93 0 1.87-0.202 2.83-0.606 0.96-0.405 1.95-1.06 2.99-1.96 1.03-0.898 2.05-1.99 3.05-3.28s1.92-2.58 2.76-3.89c0.84-1.3 1.62-2.84 2.34-4.63 0.72-1.78 1.33-3.93 1.84-6.45l0.4-1.93c0.45-2.16 0.68-4.19 0.68-6.11 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm-148 0c-3.05 0-5.79 1.24-8.22 3.71-2.42 2.47-4.33 5.8-5.72 10-1.4 4.19-2.09 8.37-2.09 12.5 0 3.12 0.45 5.44 1.35 6.99 0.89 1.54 2.3 2.31 4.22 2.31 1.53 0 3.05-0.524 4.56-1.57s3.13-2.71 4.85-4.99 3.06-4.45 4.02-6.51c0.96-2.07 1.77-4.64 2.45-7.73 0.67-3.08 1.01-5.76 1.01-8.04 0-2.34-0.5-4.04-1.48-5.1-0.99-1.06-2.64-1.6-4.95-1.6zm100-3.5c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-49 0c4.8 0 8.45 1.31 11 3.93 2.52 2.62 3.78 6.37 3.78 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.88 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.57 6.09-2.93 1.36-6.3 2.04-10.1 2.04-4.65 0-8.25-1.3-10.8-3.91-2.56-2.6-3.84-6.35-3.84-11.2 0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.48-7.97 4.67-11.1 2.19-3.18 4.88-5.61 8.09-7.3 3.2-1.69 6.72-2.54 10.6-2.54zm-51.7-0.045c1.88 0 3.66 0.225 5.34 0.674s3.37 1.21 5.08 2.29l4.13-2.96 2.88 0.719-4.63 20.9c-0.33 1.47-1.08 5.17-2.25 11.1-1.23 6.29-2.22 10.7-2.98 13.3-0.77 2.6-1.72 4.98-2.86 7.12s-2.6 4-4.4 5.59c-1.8 1.59-3.98 2.82-6.54 3.68-2.56 0.869-5.59 1.3-9.09 1.3-11.3 0-17-3.29-17-9.88 0-1.68 0.51-3.2 1.52-4.58 1.02-1.38 2.65-2.83 4.9-4.36l3.24 2.6c-0.57 0.689-1.05 1.37-1.44 2.04s-0.67 1.32-0.83 1.95c-0.17 0.629-0.25 1.38-0.25 2.25 0 2.25 0.81 3.89 2.43 4.92 1.61 1.03 4.05 1.55 7.32 1.55 3.68 0 6.64-0.831 8.87-2.49s4.14-4.34 5.73-8.02c1.58-3.68 3.13-9.25 4.62-16.7l-0.62-0.134c-2.91 3.98-5.6 6.89-8.09 8.72-2.49 1.83-5.17 2.74-8.04 2.74-3.27 0-5.8-1.23-7.62-3.68-1.81-2.46-2.71-5.96-2.71-10.5 0-5.12 1-10 3.01-14.8 2-4.72 4.79-8.47 8.35-11.3 3.57-2.78 7.53-4.18 11.9-4.18zm168-20.5h2.65l-11.2 49.7c-0.66 2.94-0.99 5.15-0.99 6.65 0 1.2 0.2 2.07 0.59 2.6s1 0.809 1.84 0.809c0.9 0 1.86-0.367 2.87-1.1 1.02-0.734 2.46-2.13 4.32-4.2l2.56 2.52c-2.76 2.9-5.08 4.96-6.97 6.15-1.88 1.2-3.92 1.8-6.1 1.8-1.86 0-3.34-0.614-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.65 0.34-3.4 1.03-5.26l-0.59-0.18c-2.87 4.19-5.6 7.26-8.17 9.21-2.58 1.95-5.3 2.92-8.18 2.92-3.29 0-5.84-1.24-7.66-3.73-1.81-2.48-2.71-5.97-2.71-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.33-11.2c3.54-2.74 7.47-4.11 11.8-4.11 1.82 0 3.51 0.187 5.05 0.562 1.54 0.374 3.12 1.02 4.74 1.95l2.33-10.4c0.24-0.989 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.899-0.16-1.58-0.49-2.04s-0.8-0.801-1.42-1.01c-0.61-0.209-1.71-0.359-3.3-0.449l0.54-2.34z\" />\n <path d=\"m2126 529 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- |bad> ket -->\n <path d=\"m2766 1275h6.92v83.6h-6.92z\" />\n <path d=\"m2816 1301c-1.43 0-2.85 0.46-4.24 1.37s-2.94 2.43-4.65 4.54-3.1 4.27-4.18 6.49-1.99 5.05-2.74 8.49l-0.4 1.89c-0.45 2.09-0.68 4.13-0.68 6.11 0 2.36 0.52 4.07 1.55 5.12 1.04 1.05 2.75 1.57 5.15 1.57 1.22 0 2.39-0.2 3.5-0.61 1.11-0.4 2.24-1.07 3.39-2 1.15-0.92 2.25-2.14 3.28-3.66 1.03-1.51 1.99-3.37 2.85-5.59 0.87-2.22 1.55-4.59 2.03-7.12 0.47-2.53 0.71-4.95 0.71-7.25 0-3.12-0.44-5.46-1.32-7.01-0.88-1.56-2.3-2.34-4.25-2.34zm97.4-1.75c-3.06 0-5.8 1.23-8.22 3.71-2.43 2.47-4.34 5.8-5.73 9.99s-2.09 8.37-2.09 12.5c0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c0.93 0 1.87-0.2 2.83-0.6 0.96-0.41 1.96-1.06 2.99-1.96s2.05-1.99 3.05-3.28c1.01-1.29 1.93-2.58 2.77-3.88 0.83-1.31 1.61-2.85 2.33-4.63s1.33-3.93 1.84-6.45l0.41-1.93c0.45-2.15 0.67-4.19 0.67-6.11 0-2.33-0.49-4.03-1.48-5.1-0.99-1.06-2.64-1.59-4.94-1.59zm-50.9 0c-3.09 0-5.86 1.24-8.31 3.73-2.46 2.48-4.37 5.82-5.75 9.99-1.38 4.18-2.07 8.35-2.07 12.5 0 3.12 0.43 5.45 1.28 6.99s2.29 2.31 4.29 2.31c1.98 0 3.92-0.85 5.82-2.56 1.9-1.7 3.86-4.14 5.88-7.3 2.03-3.16 3.46-6.8 4.29-10.9l0.41-1.93c0.27-1.23 0.45-2.29 0.54-3.19s0.13-1.87 0.13-2.92c0-2.3-0.49-4-1.48-5.07-0.99-1.08-2.67-1.62-5.03-1.62zm-0.9-3.55c1.95 0 3.77 0.22 5.46 0.65 1.69 0.44 3.43 1.21 5.23 2.32l4.13-2.97 2.88 0.72-6.6 28.5c-0.66 2.84-0.99 5.06-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.69 2.87-4.99 4.92-6.89 6.13-1.91 1.21-3.97 1.82-6.18 1.82-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11zm70.6-20.5h2.65l-11.2 49.7c-0.66 2.93-0.99 5.15-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.36 2.88-1.1 1.02-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.75 2.9-5.08 4.95-6.96 6.15-1.89 1.2-3.93 1.8-6.11 1.8-1.86 0-3.34-0.62-4.45-1.84-1.11-1.23-1.66-2.86-1.66-4.9 0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.2-5.6 7.27-8.18 9.21-2.57 1.95-5.3 2.92-8.17 2.92-3.3 0-5.85-1.24-7.66-3.73-1.81-2.48-2.72-5.97-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8s4.8-8.49 8.34-11.2c3.53-2.74 7.47-4.11 11.8-4.11 1.83 0 3.51 0.19 5.05 0.56 1.55 0.38 3.13 1.03 4.74 1.96l2.34-10.4c0.24-0.99 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.9-0.17-1.58-0.5-2.05-0.33-0.46-0.8-0.8-1.41-1.01-0.62-0.21-1.72-0.36-3.3-0.45l0.54-2.33zm-124 0h2.61l-7.91 31.4 0.59 0.18c2.9-3.9 5.63-6.71 8.17-8.45 2.55-1.74 5.09-2.6 7.64-2.6 3.26 0 5.8 1.24 7.61 3.72 1.81 2.49 2.72 5.99 2.72 10.5 0 4.94-1 9.8-2.99 14.6-1.99 4.78-4.75 8.57-8.29 11.4-3.53 2.8-7.48 4.2-11.8 4.2-3.99 0-7.52-0.98-10.6-2.92l-4.13 2.92-2.87-0.72 11.6-51.4c0.69-3.05 1.03-5.27 1.03-6.64 0-1.26-0.38-2.15-1.14-2.66-0.77-0.5-2.14-0.79-4.11-0.85l0.54-2.33z\" />\n <path d=\"m2950 1275 17.9 40.3v3.33l-17.9 40.4-4.8-1.71 14.4-40.3-14.4-40.4z\" />\n <!-- theta-->\n <path d=\"m2414 1260c-1.4 6.49-2.11 12-2.11 16.4 0 3.36 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.31 2.11-11.8 2.11-16.3 0-3.15-0.51-5.5-1.53-7.06-1.01-1.55-2.6-2.33-4.76-2.33zm0.54-3.64c8.69 0 13 5.51 13 16.5 0 3.12-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.5-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09-2.19-2.72-3.28-6.81-3.28-12.3 0-2.97 0.33-6.62 0.99-11 0.66-4.35 1.74-8.79 3.26-13.3 1.51-4.54 3.45-8.57 5.84-12.1 2.38-3.52 5.12-6.23 8.22-8.13s6.46-2.85 10.1-2.85z\" fill-rule=\"evenodd\" />\n <!--2 \\theta and angle -->\n <path d=\"m2410 1105c-1.41 6.5-2.12 12-2.12 16.4 0 3.35 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.32 2.11-11.8 2.11-16.3 0-3.14-0.51-5.5-1.52-7.05-1.02-1.56-2.61-2.34-4.77-2.34zm-58.2-2.7c5.57 0 9.77 1.22 12.6 3.66 2.84 2.44 4.27 5.98 4.27 10.6 0 1.59-0.16 3.05-0.48 4.38-0.31 1.33-0.8 2.65-1.48 3.95-0.67 1.3-1.58 2.7-2.72 4.2-1.13 1.5-2.39 3.02-3.77 4.56s-3.76 4.11-7.14 7.7c-5.69 6.02-9.87 11.3-12.5 15.8h16.9c1.47 0 2.65-0.09 3.55-0.27s1.62-0.479 2.16-0.898c0.54-0.42 0.96-0.966 1.28-1.64 0.31-0.674 0.71-1.72 1.19-3.12h3.82l-0.77 13.1h-37v-2.16c1.29-3.14 3.03-6.36 5.21-9.66 2.19-3.3 5.29-7.17 9.3-11.6 3.47-3.83 5.98-6.74 7.5-8.72 1.68-2.16 2.93-4.02 3.75-5.59 0.83-1.57 1.42-3.06 1.78-4.45s0.54-2.79 0.54-4.2c0-2.25-0.36-4.23-1.08-5.95s-1.82-3.08-3.3-4.07c-1.49-0.988-3.35-1.48-5.6-1.48-5.6 0-9.37 3.11-11.3 9.34h-5.43v-8.62c3.62-1.71 7.01-2.94 10.2-3.71 3.16-0.763 6-1.14 8.52-1.14zm58.7-0.943c8.69 0 13 5.51 13 16.5 0 3.11-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.49-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09s-3.28-6.81-3.28-12.3c0-2.96 0.33-6.62 0.99-11 0.66-4.34 1.74-8.78 3.26-13.3 1.51-4.54 3.46-8.56 5.84-12.1s5.12-6.23 8.22-8.13 6.46-2.85 10.1-2.85z\" />\n </g>\n <g class=\"kata_svg_fill_accent kata_svg_stroke_accent\" font-family=\"sans-serif\" font-size=\"64px\" font-weight=\"400\">\n <text transform=\"translate(2220 580)\">Close enough</text>\n <text transform=\"translate(2220 650)\">to measure</text>\n <!--2 \\theta and angle -->\n <path d=\"m2210 905c-1.41 6.5-2.12 12-2.12 16.4 0 3.35 0.51 5.82 1.53 7.39s2.67 2.36 4.94 2.36c3.36 0 6.54-2.25 9.55-6.76s5.56-11 7.66-19.4zm18.4-30.3c-3.5 0-6.74 2.22-9.72 6.65s-5.52 10.8-7.62 19h21.5c1.41-6.32 2.11-11.8 2.11-16.3 0-3.14-0.51-5.5-1.52-7.05-1.02-1.56-2.61-2.34-4.77-2.34zm-58.2-2.7c5.57 0 9.77 1.22 12.6 3.66 2.84 2.44 4.27 5.98 4.27 10.6 0 1.59-0.16 3.05-0.48 4.38-0.31 1.33-0.8 2.65-1.48 3.95-0.67 1.3-1.58 2.7-2.72 4.2-1.13 1.5-2.39 3.02-3.77 4.56s-3.76 4.11-7.14 7.7c-5.69 6.02-9.87 11.3-12.5 15.8h16.9c1.47 0 2.65-0.09 3.55-0.27s1.62-0.479 2.16-0.898c0.54-0.42 0.96-0.966 1.28-1.64 0.31-0.674 0.71-1.72 1.19-3.12h3.82l-0.77 13.1h-37v-2.16c1.29-3.14 3.03-6.36 5.21-9.66 2.19-3.3 5.29-7.17 9.3-11.6 3.47-3.83 5.98-6.74 7.5-8.72 1.68-2.16 2.93-4.02 3.75-5.59 0.83-1.57 1.42-3.06 1.78-4.45s0.54-2.79 0.54-4.2c0-2.25-0.36-4.23-1.08-5.95s-1.82-3.08-3.3-4.07c-1.49-0.988-3.35-1.48-5.6-1.48-5.6 0-9.37 3.11-11.3 9.34h-5.43v-8.62c3.62-1.71 7.01-2.94 10.2-3.71 3.16-0.763 6-1.14 8.52-1.14zm58.7-0.943c8.69 0 13 5.51 13 16.5 0 3.11-0.35 6.84-1.06 11.2-0.7 4.33-1.82 8.74-3.34 13.2-1.53 4.49-3.46 8.47-5.8 11.9-2.33 3.46-5.03 6.13-8.08 8.02-3.06 1.89-6.35 2.83-9.89 2.83-4.46 0-7.78-1.36-9.97-4.09s-3.28-6.81-3.28-12.3c0-2.96 0.33-6.62 0.99-11 0.66-4.34 1.74-8.78 3.26-13.3 1.51-4.54 3.46-8.56 5.84-12.1s5.12-6.23 8.22-8.13 6.46-2.85 10.1-2.85z\" fill=\"#0070c0\" fill-rule=\"evenodd\" />\n </g>\n </g>\n</svg>\n\nNow, recall that $\\theta = \\arcsin \\sqrt{\\frac{M}{N}}$. When $M$ is much smaller than $N$, $\\frac{M}{N}$ is close to 0, and $\\theta$ is a small angle that can approximated as $\\theta \\approx \\sqrt{\\frac{M}{N}}$. This gives the following equation for $R_{opt}$\n\n$$ 2R_{opt}+1 \\approx \\frac{\\pi}{2\\theta} = \\frac{\\pi}{2}\\sqrt{\\frac{N}{M}}$$\nSince $\\theta$ is small, $R_{opt}$ is large, and the $+1$ term next to $2R_{opt}$ can be ignored, giving the final formula:\n$$ R_{opt} \\approx \\frac{\\pi}{4}\\sqrt{\\frac{N}{M}}$$\n\nWhat happens if you use more iterations than is optimal? Each iteration will keep rotating the state $2\\theta$ counterclockwise,\ngetting it further away from the vertical axis and thus reducing the probability of measuring the correct answer.\n\nIn this demo you will see how success probability of Grover's algorithm changes when it uses different numbers of iterations\nbefore the final measurements."
7079
7079
  },
7080
7080
  {
7081
7081
  "type": "example",
@@ -7354,6 +7354,901 @@ export default {
7354
7354
  ],
7355
7355
  "published": true
7356
7356
  },
7357
+ {
7358
+ "id": "solving_graph_coloring",
7359
+ "title": "Solving Graph Coloring Using Grover's Algorithm",
7360
+ "sections": [
7361
+ {
7362
+ "type": "lesson",
7363
+ "id": "solving_graph_coloring__overview",
7364
+ "title": "Overview",
7365
+ "items": [
7366
+ {
7367
+ "type": "text-content",
7368
+ "content": "\nThe key part of solving a classical problem using Grover's search algorithm is implementing the quantum oracle for that problem.\nIn practice, implementing a quantum oracle for a specific problem can be quite challenging.\n\nThis kata walks you through implementing the quantum oracles for several kinds of graph coloring problems - \nproblems that look for an assignment of labels, commonly referred to as \"colors\", to vertices or edges of the graph \nin a way that satisfies the given set of constraints.\nIt also encourages you to experiment with using these oracles to solve graph coloring problems with Grover's search.\n\n**This kata covers the following topics:**\n\n- Implementation of marking oracles for several versions of graph coloring problems\n- Using Grover's search algorithm to solve graph coloring problems\n\n**What you should know to start working on this kata:**\n\n- Fundamental quantum concepts\n- Controlled gates\n- Oracles, in particular marking oracles\n- Grover's search algorithm"
7369
+ }
7370
+ ]
7371
+ },
7372
+ {
7373
+ "type": "lesson",
7374
+ "id": "solving_graph_coloring__vertex_coloring",
7375
+ "title": "Vertex Coloring Problem",
7376
+ "items": [
7377
+ {
7378
+ "type": "text-content",
7379
+ "content": "\nVertex coloring problem is the simplest form of a graph coloring problem. In it, you look for a coloring of graph vertices which labels each vertex with one of the given colors so that no two vertices of the same color are connected by an edge. In other words, the colors of any pair of vertices that is connected by an edge must be different.\n\nIn this lesson, you will implement the marking oracle for the vertex coloring problem, as well as several building blocks you'll need for an end-to-end implementation of Grover's search for this problem."
7380
+ }
7381
+ ]
7382
+ },
7383
+ {
7384
+ "type": "exercise",
7385
+ "id": "solving_graph_coloring__vertex_coloring_classical",
7386
+ "title": "Is Vertex Coloring Valid? (Classical)",
7387
+ "description": {
7388
+ "type": "text-content",
7389
+ "content": "**Inputs:**\n\n1. The number of vertices in the graph $V$ ($V \\leq 6$).\n2. An array of $E$ tuples of integers, representing the edges of the graph ($E \\leq 12$).\nEach tuple gives the indices of the start and the end vertices of the edge.\nThe vertices are numbered $0$ through $V - 1$.\n3. An array of $V$ integers, representing the vertex coloring of the graph. \nThe $i$-th element of the array is the color of the vertex number $i$.\n\nFor example, the graph `0 -- 1 -- 2` has $V = 3$ and `edges = [(0, 1), (1, 2)]`. \nSome of the valid colorings for it would be `[0, 1, 0]` and `[-1, 5, 18]`.\nNotice that in this exercise, unlike in some of the later ones, the coloring is not limited to numbers from $0$ to $3$.\n\n**Output:**\nTrue if the given vertex coloring is valid (that is, no two vertices connected by an edge have the same color), and false otherwise."
7390
+ },
7391
+ "sourceIds": [
7392
+ "solving_graph_coloring__vertex_coloring_classical__Verification.qs",
7393
+ "KatasLibrary.qs",
7394
+ "solving_graph_coloring__Common.qs"
7395
+ ],
7396
+ "placeholderCode": "namespace Kata {\n function IsVertexColoringValid(V : Int, edges: (Int, Int)[], colors: Int[]) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
7397
+ "explainedSolution": {
7398
+ "type": "explained-solution",
7399
+ "items": [
7400
+ {
7401
+ "type": "text-content",
7402
+ "content": "\nA graph coloring is valid when the nodes connected by every edge have a different color. This means that we have to check every edge, see if the nodes have the same color, and if it is the case, return that the graph coloring is invalid. If every edge passed the test, we can safely say the graph coloring is valid.\n\nSince the color of vertex $n$ is the $n$-th element of the `colors` array, we simply loop through every edge, which is a pair of vertex indices, and compare their colors."
7403
+ },
7404
+ {
7405
+ "type": "solution",
7406
+ "id": "solving_graph_coloring__vertex_coloring_classical_solution",
7407
+ "code": "namespace Kata {\n function IsVertexColoringValid(V : Int, edges: (Int, Int)[], colors: Int[]) : Bool {\n for (v0, v1) in edges {\n if colors[v0] == colors[v1] {\n return false;\n }\n }\n return true;\n }\n}\n"
7408
+ }
7409
+ ]
7410
+ }
7411
+ },
7412
+ {
7413
+ "type": "exercise",
7414
+ "id": "solving_graph_coloring__read_coloring",
7415
+ "title": "Read Coloring From a Qubit Array",
7416
+ "description": {
7417
+ "type": "text-content",
7418
+ "content": "In this task, you need to read the coloring of an $V$-vertex graph stored in a qubit array.\nThis is the last step of Grover's search algorithm: performing measurements and interpreting the results as the potential solution to your problem.\n\n**Inputs**:\n\n 1. The number of bits in each color of the coloring $nBits$.\n 2. An array of $V \\cdot nBits$ qubits which are guaranteed to be in a basis state.\n\n**Output**:\n\nAn array of $V$ $nBits$-bit integers that represent this basis state.\n$i$-th integer of the array is stored in qubits with indices $i \\cdot nBits$, $i \\cdot nBits + 1$, ..., $(i + 1) \\cdot nBits - 1$ in big-endian format. \n\nFor example, the input $nBits = 2$ and basis state $\\ket{000110}$ correspond to two-bit colors $00, 01, 10$, or, in decimal, $0, 1, 2$.\n\nThe operation should not change the state of the qubits.\n"
7419
+ },
7420
+ "sourceIds": [
7421
+ "solving_graph_coloring__read_coloring__Verification.qs",
7422
+ "KatasLibrary.qs",
7423
+ "solving_graph_coloring__Common.qs"
7424
+ ],
7425
+ "placeholderCode": "namespace Kata {\n operation ReadColoring(nBits : Int, qs : Qubit[]) : Int[] {\n // Implement your solution here...\n\n return [];\n }\n}\n",
7426
+ "explainedSolution": {
7427
+ "type": "explained-solution",
7428
+ "items": [
7429
+ {
7430
+ "type": "text-content",
7431
+ "content": "\nThe solution to this exercise consists of two parts:\n\n1. Read an integer from an array of qubits of length `nBits`.\n Since you are guaranteed that the qubits in the array are in a basis state, simply measuring them will give you the necessary information and leave the state of the qubits unchanged. \n You can use the library operation `MeasureEachZ` to measure each qubit in the array without resetting it to the $\\ket{0}$ state afterwards. \n Then, you can convert the array of measurement results to an integer using the function `ResultArrayAsInt`.\n Note that this function does the conversion from a little endian binary encoding, and the exercise asks for the colors to be represented in big endian, so you need to reverse the array of measurement results using the function `Reversed`.\n2. Split the given array of qubits into chunks of length `nBits` and read an integer from each of them.\n A convenient library function `Chunks` does exactly that, splitting the array into chunks of the given length.\n Finally, you can apply the integer readout operation to each chunk using the operation `ForEach`."
7432
+ },
7433
+ {
7434
+ "type": "solution",
7435
+ "id": "solving_graph_coloring__read_coloring_solution",
7436
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n\n operation ReadColoring(nBits : Int, qs : Qubit[]) : Int[] {\n let colorPartitions = Chunks(nBits, qs);\n let measureColor = qs => ResultArrayAsInt(Reversed(MeasureEachZ(qs)));\n return ForEach(measureColor, colorPartitions);\n }\n}\n"
7437
+ }
7438
+ ]
7439
+ }
7440
+ },
7441
+ {
7442
+ "type": "exercise",
7443
+ "id": "solving_graph_coloring__color_equality",
7444
+ "title": "Are Colors Equal?",
7445
+ "description": {
7446
+ "type": "text-content",
7447
+ "content": "**Inputs:**\n\n1. An array of $nBits$ qubits in an arbitrary state $\\ket{x_0}$ representing the first color.\n2. An array of $nBits$ qubits in an arbitrary state $\\ket{x_1}$ representing the second color.\n3. A qubit in an arbitrary state $\\ket{y}$ (output/target qubit).\n\n**Goal:**\nImplement a quantum oracle which checks whether the two given colors are equal.\nIn other words, flip the state of qubit $\\ket{y}$ if $x_0 = x_1$, and leave it unchanged otherwise.\n \nLeave the qubits in the input register in the same state they started in.\nYour solution should work on inputs in superposition, and not use any measurements."
7448
+ },
7449
+ "sourceIds": [
7450
+ "solving_graph_coloring__color_equality__Verification.qs",
7451
+ "KatasLibrary.qs",
7452
+ "solving_graph_coloring__Common.qs"
7453
+ ],
7454
+ "placeholderCode": "namespace Kata {\n operation Oracle_ColorEquality(x0 : Qubit[], x1 : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}\n",
7455
+ "explainedSolution": {
7456
+ "type": "explained-solution",
7457
+ "items": [
7458
+ {
7459
+ "type": "text-content",
7460
+ "content": "\nThe goal is to flip the qubit $\\ket{y}$ if and only if each of the matching pairs of qubits in the arrays `x0` and `x1` are in the same state.\n\nYou can check whether two qubits are in the same state by computing their $\\textrm{XOR}$: if their state was the same, their $\\textrm{XOR}$ will be $0$. You can use the $\\textrm{CNOT}$ gate to compute $\\textrm{XOR}$ of two qubits in place, for example, using the qubit of the array `x0` as the control and the qubit of the array `x1` as the target.\n\nOnce you've used $nBits$ $\\textrm{CNOT}$ gates to compute all pairwise $\\textrm{XOR}$'s, you'll need to flip the target qubit $\\ket{y}$ only if all qubits in `x1` are in the $\\ket{0}$ state. \nThis can be done by using zero-controlled $X$ gate, that is, `ApplyControlledOnInt(0, X, x1, y)`.\n\nFinally, you need to uncompute the bitwise $\\textrm{XOR}$'s to ensure that the qubits in `x1` are returned to their original state."
7461
+ },
7462
+ {
7463
+ "type": "solution",
7464
+ "id": "solving_graph_coloring__color_equality_solution",
7465
+ "code": "namespace Kata {\n operation Oracle_ColorEquality(x0 : Qubit[], x1 : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n within {\n for i in 0..Length(x0) - 1 {\n CNOT(x0[i], x1[i]);\n }\n } apply {\n ApplyControlledOnInt(0, X, x1, y);\n }\n }\n}\n"
7466
+ }
7467
+ ]
7468
+ }
7469
+ },
7470
+ {
7471
+ "type": "exercise",
7472
+ "id": "solving_graph_coloring__vertex_coloring_quantum",
7473
+ "title": "Is Vertex Coloring Valid? (Quantum)",
7474
+ "description": {
7475
+ "type": "text-content",
7476
+ "content": "**Inputs:**\n\n1. The number of vertices in the graph $V$ ($V \\leq 6$).\n2. An array of $E$ tuples of integers, representing the edges of the graph ($E \\leq 12$).\nEach tuple gives the indices of the start and the end vertices of the edge.\nThe vertices are numbered $0$ through $V - 1$.\n3. An array of $2V$ qubits in an arbitrary state $\\ket{x}$ representing the assigned coloring of the vertices using four colors ($nBits = 2$) in the same format as in the exercise \"Read Coloring From a Qubit Array\".\n4. A qubit in an arbitrary state $\\ket{y}$ (output/target qubit).\n\nFor example, the graph `0 -- 1 -- 2` has $V = 3$ and `edges = [(0, 1), (1, 2)]`. \nThe color assignments for this graph are represented with $6$ qubits.\nSome of the valid colorings are $\\ket{000110}$ (vertices `0, 1, 2` assigned colors `0, 1, 2`) and $\\ket{011001}$ (vertices `0, 1, 2` assigned colors `1, 2, 1`).\n\n**Goal:**\nImplement a quantum oracle which checks whether the given coloring of this graph is a valid vertex coloring,\nthat is, whether the colors assigned to each pair of vertices connected with an edge are different.\n \nLeave the qubits in the input register in the same state they started in.\nYour solution should work on inputs in superposition, and not use any measurements."
7477
+ },
7478
+ "sourceIds": [
7479
+ "solving_graph_coloring__vertex_coloring__Verification.qs",
7480
+ "KatasLibrary.qs",
7481
+ "solving_graph_coloring__Common.qs"
7482
+ ],
7483
+ "placeholderCode": "namespace Kata {\n operation Oracle_VertexColoring(V : Int, edges: (Int, Int)[], x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n\n // You might find this helper operation from an earlier task useful.\n operation Oracle_ColorEquality(x0 : Qubit[], x1 : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n within {\n for i in 0..Length(x0) - 1 {\n CNOT(x0[i], x1[i]);\n }\n } apply {\n ApplyControlledOnInt(0, X, x1, y);\n }\n }\n}\n",
7484
+ "explainedSolution": {
7485
+ "type": "explained-solution",
7486
+ "items": [
7487
+ {
7488
+ "type": "text-content",
7489
+ "content": "\nYou need to allocate an array of auxiliary qubits, one for each edge of the graph, that will have their states flipped if the vertices connected by the corresponding edge have the same color. \nThis can be done easily using with the operation `Oracle_ColorEquality` from the previous task. \n\nThen, you need to check if these auxiliary qubits are still in state $\\ket{0...0}$; if they are, all the necessary pairs of colors are distinct, the coloring is valid.\n\nSince the coloring is provided as an array of qubits, with two qubits per vertex (2 qubits = 4 basis states = 4 colors), you have to take the correct chunks of the coloring to extract the color of each vertex. You can deduce that the coloring of vertex $j$ is encoded in qubits in positions $2j$ and $2j+1$.\n\nMake sure to uncompute the changes to the auxiliary qubits after you evaluate the final result to leave them clean before their release."
7490
+ },
7491
+ {
7492
+ "type": "solution",
7493
+ "id": "solving_graph_coloring__vertex_coloring_quantum_solution",
7494
+ "code": "namespace Kata {\n operation Oracle_VertexColoring(V : Int, edges: (Int, Int)[], x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n let edgesNumber = Length(edges);\n use conflicts = Qubit[edgesNumber];\n within {\n for i in 0 .. edgesNumber - 1 {\n let (v0, v1) = edges[i];\n Oracle_ColorEquality(x[2 * v0 .. 2 * v0 + 1], \n x[2 * v1 .. 2 * v1 + 1], conflicts[i]);\n }\n } apply {\n ApplyControlledOnInt(0, X, conflicts, y);\n }\n }\n\n operation Oracle_ColorEquality(x0 : Qubit[], x1 : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n within {\n for i in 0..Length(x0) - 1 {\n CNOT(x0[i], x1[i]);\n }\n } apply {\n ApplyControlledOnInt(0, X, x1, y);\n }\n }\n}\n"
7495
+ }
7496
+ ]
7497
+ }
7498
+ },
7499
+ {
7500
+ "type": "lesson",
7501
+ "id": "solving_graph_coloring__weak_coloring",
7502
+ "title": "Weak Coloring Problem",
7503
+ "items": [
7504
+ {
7505
+ "type": "text-content",
7506
+ "content": "\nWeak graph coloring is a coloring of graph vertices which labels each vertex with one of the given colors in such a way that each non-isolated vertex is connected by an edge to at least one neighbor of a different color.\n\nIn this lesson, you will implement the marking oracle for the weak graph coloring problem."
7507
+ }
7508
+ ]
7509
+ },
7510
+ {
7511
+ "type": "exercise",
7512
+ "id": "solving_graph_coloring__weak_coloring_classical",
7513
+ "title": "Is Weak Coloring Valid? (Classical)",
7514
+ "description": {
7515
+ "type": "text-content",
7516
+ "content": "**Inputs:**\n\n1. The number of vertices in the graph $V$ ($V \\leq 6$).\n2. An array of $E$ tuples of integers, representing the edges of the graph ($E \\leq 12$).\nEach tuple gives the indices of the start and the end vertices of the edge.\nThe vertices are numbered $0$ through $V - 1$.\n3. An array of $V$ integers, representing the vertex coloring of the graph. \nThe $i$-th element of the array is the color of the vertex number $i$.\n\nFor example, consider the triangular graph `0 -- 1 -- 2 -- 0` with $V = 3$ and `edges = [(0, 1), (1, 2), (0, 2)]`. \nThe coloring `[0, 1, 0]` is a valid weak coloring for it despite the fact that the connected vertices $0$ and $2$ are assigned the same color, since each of them is also connected to the vertex $1$ of a different color.\n\n**Output:**\nTrue if the given weak coloring is valid (that is, each vertex either has no neighbors, or has at least one neighbor of a different color), and false otherwise."
7517
+ },
7518
+ "sourceIds": [
7519
+ "solving_graph_coloring__weak_coloring_classical__Verification.qs",
7520
+ "KatasLibrary.qs",
7521
+ "solving_graph_coloring__Common.qs"
7522
+ ],
7523
+ "placeholderCode": "namespace Kata {\n function IsWeakColoringValid(V : Int, edges: (Int, Int)[], colors: Int[]) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
7524
+ "explainedSolution": {
7525
+ "type": "explained-solution",
7526
+ "items": [
7527
+ {
7528
+ "type": "text-content",
7529
+ "content": "\nA weak coloring is valid when each of the vertices is weakly colored, that is, has either no neighbors or has at least one neighbor of a different color. This means that the solution needs to iterate through all vertices and check this condition for each of them, tracking separately the number of vertices connected to it with an edge and the existence of a connected vertex of a different color."
7530
+ },
7531
+ {
7532
+ "type": "solution",
7533
+ "id": "solving_graph_coloring__weak_coloring_classical_solution",
7534
+ "code": "namespace Kata {\n function IsWeakColoringValid(V : Int, edges: (Int, Int)[], colors: Int[]) : Bool {\n for vertex in 0 .. V - 1 {\n mutable neighborCount = 0;\n mutable hasDifferentNeighbor = false;\n\n for (start, end) in edges {\n if start == vertex or end == vertex {\n set neighborCount += 1;\n if colors[start] != colors[end] {\n set hasDifferentNeighbor = true;\n }\n }\n }\n\n if neighborCount > 0 and not hasDifferentNeighbor {\n return false;\n }\n }\n return true;\n }\n}\n"
7535
+ }
7536
+ ]
7537
+ }
7538
+ },
7539
+ {
7540
+ "type": "exercise",
7541
+ "id": "solving_graph_coloring__weak_coloring_one_vertex",
7542
+ "title": "Is One-Vertex Weak Coloring Valid? (Quantum)",
7543
+ "description": {
7544
+ "type": "text-content",
7545
+ "content": "**Inputs:**\n\n1. The number of vertices in the graph $V$ ($V \\leq 6$).\n2. An array of $E$ tuples of integers, representing the edges of the graph ($E \\leq 12$).\nEach tuple gives the indices of the start and the end vertices of the edge.\nThe vertices are numbered $0$ through $V - 1$.\n3. An array of $2V$ qubits in an arbitrary state $\\ket{x}$ representing the assigned coloring of the vertices using four colors ($nBits = 2$) in the same format as in the exercise \"Read Coloring From a Qubit Array\".\n4. A qubit in an arbitrary state $\\ket{y}$ (output/target qubit).\n5. An index of a vertex in the graph between $0$ and $V - 1$, inclusive.\n\n**Goal:**\nImplement a quantum oracle which checks whether the given vertex is weakly colored in the given coloring of the given graph,\nthat is, whether it is either isolated or is connected to at least one vertex of a different color.\n \nLeave the qubits in the input register in the same state they started in.\nYour solution should work on inputs in superposition, and not use any measurements."
7546
+ },
7547
+ "sourceIds": [
7548
+ "solving_graph_coloring__weak_coloring_one_vertex__Verification.qs",
7549
+ "KatasLibrary.qs",
7550
+ "solving_graph_coloring__Common.qs"
7551
+ ],
7552
+ "placeholderCode": "namespace Kata {\n operation Oracle_WeakColoring_OneVertex(\n V : Int, edges: (Int, Int)[], x : Qubit[], y : Qubit, vertex : Int\n ) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n\n // You might find this helper operation from an earlier task useful.\n operation Oracle_ColorEquality(x0 : Qubit[], x1 : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n within {\n for i in 0..Length(x0) - 1 {\n CNOT(x0[i], x1[i]);\n }\n } apply {\n ApplyControlledOnInt(0, X, x1, y);\n }\n }\n}\n",
7553
+ "explainedSolution": {
7554
+ "type": "explained-solution",
7555
+ "items": [
7556
+ {
7557
+ "type": "text-content",
7558
+ "content": "\nTo implement this check, you need to start by counting the vertices connected to the given vertex \nand allocating an array of auxiliary qubits, one for each neighboring vertex. These qubits will have their states flipped if the vertices connected by the corresponding edge have the same color. \nThis can be done easily using with the operation `Oracle_ColorEquality` from an earlier task, similarly to how you did in when validating the vertex coloring of the graph. \n\nNow, for the coloring of the vertex to be valid, it needs to either have no neighbors, or to have at least one neighbor of a different color, so the array of auxiliary qubits should be in any state but $\\ket{1...1}$. To implement this, you can flip the target qubit $\\ket{y}$ unconditionally using the $X$ gate, and then flip it again only if qubits are in state $\\ket{1...1}$.\n\nMake sure to uncompute the changes to the auxiliary qubits after you evaluate the final result to leave them clean before their release."
7559
+ },
7560
+ {
7561
+ "type": "solution",
7562
+ "id": "solving_graph_coloring__weak_coloring_one_vertex_solution",
7563
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation Oracle_WeakColoring_OneVertex(\n V : Int, edges: (Int, Int)[], x : Qubit[], y : Qubit, vertex : Int\n ) : Unit is Adj + Ctl {\n let neighborEdges = Filtered((a, b) -> a == vertex or b == vertex, edges);\n let nNeighbors = Length(neighborEdges);\n use sameColorChecks = Qubit[nNeighbors];\n within {\n for ((a, b), checkQubit) in Zipped(neighborEdges, sameColorChecks) {\n Oracle_ColorEquality(x[a * 2 .. a * 2 + 1],\n x[b * 2 .. b * 2 + 1], \n checkQubit);\n }\n } apply {\n X(y);\n if nNeighbors > 0 {\n Controlled X(sameColorChecks, y);\n }\n }\n }\n\n operation Oracle_ColorEquality(x0 : Qubit[], x1 : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n within {\n for i in 0..Length(x0) - 1 {\n CNOT(x0[i], x1[i]);\n }\n } apply {\n ApplyControlledOnInt(0, X, x1, y);\n }\n }\n}\n"
7564
+ }
7565
+ ]
7566
+ }
7567
+ },
7568
+ {
7569
+ "type": "exercise",
7570
+ "id": "solving_graph_coloring__weak_coloring_quantum",
7571
+ "title": "Is Weak Coloring Valid? (Quantum)",
7572
+ "description": {
7573
+ "type": "text-content",
7574
+ "content": "**Inputs:**\n\n1. The number of vertices in the graph $V$ ($V \\leq 6$).\n2. An array of $E$ tuples of integers, representing the edges of the graph ($E \\leq 12$).\nEach tuple gives the indices of the start and the end vertices of the edge.\nThe vertices are numbered $0$ through $V - 1$.\n3. An array of $2V$ qubits in an arbitrary state $\\ket{x}$ representing the assigned coloring of the vertices using four colors ($nBits = 2$) in the same format as in the exercise \"Read Coloring From a Qubit Array\".\n4. A qubit in an arbitrary state $\\ket{y}$ (output/target qubit).\n\n**Goal:**\nImplement a quantum oracle which checks whether the given weak coloring is valid for the given graph,\nthat is, whether each vertex of the graph is either isolated or connected to at least one vertex of a different color.\n \nLeave the qubits in the input register in the same state they started in.\nYour solution should work on inputs in superposition, and not use any measurements."
7575
+ },
7576
+ "sourceIds": [
7577
+ "solving_graph_coloring__weak_coloring__Verification.qs",
7578
+ "KatasLibrary.qs",
7579
+ "solving_graph_coloring__Common.qs"
7580
+ ],
7581
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation Oracle_WeakColoring(\n V : Int, edges: (Int, Int)[], x : Qubit[], y : Qubit\n ) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n\n // You might find these helper operations from earlier tasks useful.\n operation Oracle_WeakColoring_OneVertex(\n V : Int, edges: (Int, Int)[], x : Qubit[], y : Qubit, vertex : Int\n ) : Unit is Adj + Ctl {\n let neighborEdges = Filtered((a, b) -> a == vertex or b == vertex, edges);\n let nNeighbors = Length(neighborEdges);\n use sameColorChecks = Qubit[nNeighbors];\n within {\n for ((a, b), checkQubit) in Zipped(neighborEdges, sameColorChecks) {\n Oracle_ColorEquality(x[a * 2 .. a * 2 + 1],\n x[b * 2 .. b * 2 + 1], \n checkQubit);\n }\n } apply {\n X(y);\n if nNeighbors > 0 {\n Controlled X(sameColorChecks, y);\n }\n }\n }\n\n operation Oracle_ColorEquality(x0 : Qubit[], x1 : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n within {\n for i in 0..Length(x0) - 1 {\n CNOT(x0[i], x1[i]);\n }\n } apply {\n ApplyControlledOnInt(0, X, x1, y);\n }\n }\n}\n",
7582
+ "explainedSolution": {
7583
+ "type": "explained-solution",
7584
+ "items": [
7585
+ {
7586
+ "type": "text-content",
7587
+ "content": "\nTo implement this oracle, you need to check whether each vertex is colored correctly and combine the results of individual checks. You'll need to allocate an array of qubits, one per vertex, that will be flipped if the corresponding vertex is weakly colored.\nThis can be done easily using the `Oracle_WeakColoring_OneVertex` operation defined in the previous task. Then, you need to check if all qubits in the array is in state $\\ket{1...1}$ using the Controlled $X$ gate; if they are, the coloring is valid.\n\nAs usual, remember to uncompute the changes to the auxiliary qubits after you evaluate the final result to leave them clean before their release."
7588
+ },
7589
+ {
7590
+ "type": "solution",
7591
+ "id": "solving_graph_coloring__weak_coloring_quantum_solution",
7592
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation Oracle_WeakColoring(\n V : Int, edges: (Int, Int)[], x : Qubit[], y : Qubit\n ) : Unit is Adj + Ctl {\n use vertexQubits = Qubit[V];\n within {\n for v in 0 .. V - 1 {\n Oracle_WeakColoring_OneVertex(V, edges, x, vertexQubits[v], v);\n }\n } apply {\n Controlled X(vertexQubits, y);\n }\n }\n\n // You might find these helper operations from earlier tasks useful.\n operation Oracle_WeakColoring_OneVertex(\n V : Int, edges: (Int, Int)[], x : Qubit[], y : Qubit, vertex : Int\n ) : Unit is Adj + Ctl {\n let neighborEdges = Filtered((a, b) -> a == vertex or b == vertex, edges);\n let nNeighbors = Length(neighborEdges);\n use sameColorChecks = Qubit[nNeighbors];\n within {\n for ((a, b), checkQubit) in Zipped(neighborEdges, sameColorChecks) {\n Oracle_ColorEquality(x[a * 2 .. a * 2 + 1],\n x[b * 2 .. b * 2 + 1], \n checkQubit);\n }\n } apply {\n X(y);\n if nNeighbors > 0 {\n Controlled X(sameColorChecks, y);\n }\n }\n }\n\n operation Oracle_ColorEquality(x0 : Qubit[], x1 : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n within {\n for i in 0..Length(x0) - 1 {\n CNOT(x0[i], x1[i]);\n }\n } apply {\n ApplyControlledOnInt(0, X, x1, y);\n }\n }\n}\n"
7593
+ }
7594
+ ]
7595
+ }
7596
+ },
7597
+ {
7598
+ "type": "lesson",
7599
+ "id": "solving_graph_coloring__using_grover",
7600
+ "title": "Using Grover's Algorithm to Solve Graph Coloring Problems",
7601
+ "items": [
7602
+ {
7603
+ "type": "text-content",
7604
+ "content": "\nIn this lesson, you will experiment with using Grover's algorithm to solve graph coloring problems.\n\nIn this case, it's not as easy to know the number of solutions to the problem upfront as it was for the prefix function used in the \"Grover's Search Algorithm\" kata.\nExperiment with choosing the number of iterations at random. How does this affect the success probability?\n\n> Notice that the example used in this demo, a three-vertex graph with two edges, has the search space of size $4^3 = 64$.\n> A bit over half of the colorings in the search space are valid vertex colorings. You can count them by assigning any color to vertex $1$ and then assigning any of the remaining three colors to vertices $0$ and $2$ independently, to get $4 \\cdot 3 \\cdot 3 = 36$ solutions to the problem.\n> This example is one of the scenarios in which Grover's search behaves in a non-intuitive way: not doing any iterations \n> yields a success probability of over $50\\%$, so the first iteration actually reduces the probability of getting a correct answer!"
7605
+ },
7606
+ {
7607
+ "type": "example",
7608
+ "id": "solving_graph_coloring__e2edemo",
7609
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation SolvingGraphColoringWithGroverDemo() : Unit {\n // Experiment with the parameters to explore algorithm behavior in different conditions!\n let V = 3;\n // The 0 -- 1 -- 2 graph from the examples\n let edges = [(0, 1), (1, 2)];\n let markingOracle = Oracle_VertexColoring(V, edges, _, _);\n for iterations in 0 .. 9 {\n mutable success = 0;\n for _ in 1 .. 100 {\n let res = GroversSearch(2 * V, markingOracle, iterations);\n // Convert measurement results to integers\n let colorPartitions = Chunks(2, res);\n let colors = Mapped(bits -> BoolArrayAsInt(Reversed(bits)), colorPartitions);\n if IsVertexColoringValid(V, edges, colors) {\n set success += 1;\n }\n }\n Message($\"{iterations} iterations - {success}% success rate\");\n }\n }\n\n operation GroversSearch(\n n : Int,\n markingOracle : (Qubit[], Qubit) => Unit is Adj + Ctl, \n iterations : Int\n ) : Bool[] {\n use qs = Qubit[n];\n\n // Operation that prepares the state |all⟩.\n let meanStatePrep = ApplyToEachCA(H, _);\n\n // The phase oracle.\n let phaseOracle = ApplyMarkingOracleAsPhaseOracle(markingOracle, _);\n\n // Prepare the system in the state |all⟩.\n meanStatePrep(qs);\n\n // Do Grover's iterations.\n for _ in 1 .. iterations {\n // Apply the phase oracle.\n phaseOracle(qs);\n\n // Apply \"reflection about the mean\".\n ReflectionAboutState(qs, meanStatePrep);\n }\n\n // Measure to get the result.\n return ResultArrayAsBoolArray(MResetEachZ(qs));\n }\n\n operation ApplyMarkingOracleAsPhaseOracle(\n markingOracle : (Qubit[], Qubit) => Unit is Adj + Ctl,\n qubits : Qubit[])\n : Unit is Adj + Ctl {\n use minus = Qubit();\n within {\n X(minus);\n H(minus);\n } apply {\n markingOracle(qubits, minus);\n }\n }\n\n operation ReflectionAboutState(\n qs : Qubit[],\n statePrep : Qubit[] => Unit is Adj + Ctl)\n : Unit is Adj + Ctl {\n within {\n Adjoint statePrep(qs);\n } apply {\n ConditionalPhaseFlip(qs);\n }\n }\n\n operation ConditionalPhaseFlip(qs : Qubit[]) : Unit is Adj + Ctl {\n within {\n ApplyToEachA(X, qs);\n } apply {\n Controlled Z(qs[1 ...], qs[0]);\n }\n R(PauliI, 2.0 * PI(), qs[0]);\n }\n\n operation Oracle_VertexColoring(V : Int, edges: (Int, Int)[], x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n let edgesNumber = Length(edges);\n use conflicts = Qubit[edgesNumber];\n within {\n for i in 0 .. edgesNumber - 1 {\n let (v0, v1) = edges[i];\n Oracle_ColorEquality(x[2 * v0 .. 2 * v0 + 1], \n x[2 * v1 .. 2 * v1 + 1], conflicts[i]);\n }\n } apply {\n ApplyControlledOnInt(0, X, conflicts, y);\n }\n }\n\n operation Oracle_ColorEquality(x0 : Qubit[], x1 : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n within {\n for i in 0..Length(x0) - 1 {\n CNOT(x0[i], x1[i]);\n }\n } apply {\n ApplyControlledOnInt(0, X, x1, y);\n }\n }\n\n function IsVertexColoringValid(V : Int, edges: (Int, Int)[], colors: Int[]) : Bool {\n for (v0, v1) in edges {\n if colors[v0] == colors[v1] {\n return false;\n }\n }\n return true;\n }\n}"
7610
+ }
7611
+ ]
7612
+ },
7613
+ {
7614
+ "type": "lesson",
7615
+ "id": "solving_graph_coloring__conclusion",
7616
+ "title": "Conclusion",
7617
+ "items": [
7618
+ {
7619
+ "type": "text-content",
7620
+ "content": "\nCongratulations! In this kata you learned to solve graph coloring problems using Grover's search."
7621
+ }
7622
+ ]
7623
+ }
7624
+ ],
7625
+ "published": true
7626
+ },
7627
+ {
7628
+ "id": "qft",
7629
+ "title": "Quantum Fourier Transform",
7630
+ "sections": [
7631
+ {
7632
+ "type": "lesson",
7633
+ "id": "qft__overview",
7634
+ "title": "Overview",
7635
+ "items": [
7636
+ {
7637
+ "type": "text-content",
7638
+ "content": "\nThis kata introduces you to quantum Fourier transform (QFT) - an important tool in quantum phase estimation, integer factoring, and many other quantum computing algorithms.\n\n**This kata covers the following topics:**\n\n- The definition of quantum Fourier transform\n- The iterative implementation of QFT\n- Simple state preparation and state analysis tasks that can be solved using QFT\n\n**What you should know to start working on this kata:**\n\n- Basic knowledge of quantum states and quantum gates.\n\nIf you need a refresher on these topics, you can check out the previous katas."
7639
+ }
7640
+ ]
7641
+ },
7642
+ {
7643
+ "type": "lesson",
7644
+ "id": "qft__implement",
7645
+ "title": "Implementing Quantum Fourier Transform",
7646
+ "items": [
7647
+ {
7648
+ "type": "text-content",
7649
+ "content": "\n*Discrete Fourier transform* (DFT) is a transform that acts on vectors of complex numbers of fixed length $N$. The effect of DFT on a vector $x_0, x_1, ..., x_{N-1}$ is another vector $y_0, y_1, ..., y_{N-1}$ defined as follows:\n\n$$y_k = \\frac1{\\sqrt{N}}\\sum_{j=0}^{N-1} x_j e^{2\\pi i jk/N}$$\n\nQuantum Fourier transform is the quantum version of the DFT. It acts on $n$-qubit quantum states and is defined via its effects on basis states as follows:\n\n$$\\ket{j} \\rightarrow \\frac1{\\sqrt{2^n}}\\sum_{k=0}^{2^n-1} e^{2\\pi i jk/2^n} \\ket{k}$$\n\nThe result of applying QFT to an arbitrary superposition state with amplitudes $x_j$ can thus be expressed as a superposition state with amplitudes $y_k$ that are exactly the DFT of the amplitudes $x_j$ for $N = 2^n$:\n\n$$\\sum_{j=0}^{N-1} x_j\\ket{j} \\rightarrow \\sum_{k=0}^{N-1} y_k\\ket{k}$$\n\nIn the first part of this kata, you will learn to implement quantum Fourier transform using the iterative algorithm.\n\nAll the numbers used in this kata use big endian encoding: the most significant bit of the number is stored in the first (leftmost) bit/qubit.\n \nThis means that you represent an integer as a binary bit string in the following format:\n\n$$x = x_1x_2...x_n = x_1 2^{n-1} + x_2 2^{n-2}+...x_n 2^{0}$$\n \nYou can also use this notation for binary fractions: \n \n$$0.x_1x_2...x_n = \\frac{x_1}{2^1}+ \\frac{x_2}{2^2}+...\\frac{x_n}{2^n}$$"
7650
+ }
7651
+ ]
7652
+ },
7653
+ {
7654
+ "type": "exercise",
7655
+ "id": "qft__single_qubit",
7656
+ "title": "Single-Qubit QFT",
7657
+ "description": {
7658
+ "type": "text-content",
7659
+ "content": "**Input**: A qubit in state $\\ket{\\psi} = x_0 \\ket{0} + x_1 \\ket{1}$.\n\n**Goal**: \nApply quantum Fourier transform to this qubit, that is, transform it to a state $\\frac1{\\sqrt2} \\big((x_0 + x_1) \\ket{0} + (x_0 - x_1) \\ket{1}\\big)$.\n\nIn other words, transform each basis state $\\ket{j}$ into $\\frac1{\\sqrt2} (\\ket{0} + e^{2\\pi i \\cdot \\frac{j}{2}} \\ket{1} )$."
7660
+ },
7661
+ "sourceIds": [
7662
+ "qft__single_qubit__Verification.qs",
7663
+ "KatasLibrary.qs"
7664
+ ],
7665
+ "placeholderCode": "namespace Kata {\n operation SingleQubitQFT(q : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n",
7666
+ "explainedSolution": {
7667
+ "type": "explained-solution",
7668
+ "items": [
7669
+ {
7670
+ "type": "text-content",
7671
+ "content": "\nThe required transformation is actually just the expression for the transformation of an arbitrary state in the $Z$ basis (that is, the computational basis) to one in the $X$ basis (the Hadamard basis). \n\nFor the starting state $\\ket{0}$, $x_0=1$ and $x_1=0$, so the new state will be $\\frac1{\\sqrt2} (\\ket{0} + \\ket{1}) = \\ket{+}$.\nSimilarly, for the starting state $\\ket{1}$, $x_0=0$ and $x_1=1$, so the new state will be $\\frac1{\\sqrt2} (\\ket{0} - \\ket{1}) = \\ket{-}$.\n\nAnd you already know a gate that will do this: the Hadamard gate!"
7672
+ },
7673
+ {
7674
+ "type": "solution",
7675
+ "id": "qft__single_qubit_solution",
7676
+ "code": "namespace Kata {\n operation SingleQubitQFT(q : Qubit) : Unit is Adj + Ctl {\n H(q);\n }\n}"
7677
+ }
7678
+ ]
7679
+ }
7680
+ },
7681
+ {
7682
+ "type": "exercise",
7683
+ "id": "qft__rotation_gate",
7684
+ "title": "Rotation Gate",
7685
+ "description": {
7686
+ "type": "text-content",
7687
+ "content": "**Inputs**:\n\n1. A qubit in state $\\ket{\\psi} = \\alpha \\ket{0} + \\beta \\ket{1}$.\n2. An integer $k \\geq 0$.\n\n**Goal**: \nChange the state of the qubit to $\\alpha \\ket{0} + \\beta \\cdot e^{\\frac{2\\pi i}{2^{k}}} \\ket{1}$\n\n> Be careful not to introduce an extra global phase! \nThis is going to be important in the later exercises."
7688
+ },
7689
+ "sourceIds": [
7690
+ "qft__rotation_gate__Verification.qs",
7691
+ "KatasLibrary.qs"
7692
+ ],
7693
+ "placeholderCode": "namespace Kata {\n operation Rotation(q : Qubit, k : Int) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n",
7694
+ "explainedSolution": {
7695
+ "type": "explained-solution",
7696
+ "items": [
7697
+ {
7698
+ "type": "text-content",
7699
+ "content": "\nTo avoid adding the extra global phase, we have to use a gate that does not modify the $\\ket{0}$ state, and only impacts $\\ket{1}$: that is, $U\\ket{\\psi} = \\alpha\\ket{0} + \\beta \\cdot U\\ket{1}$.\n\nThe built-in [R1Frac gate](https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.intrinsic/r1frac) does exactly that:\n\n$$\\textrm{R1Frac}(n,k) = \\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\pi n/2^{k}} \\end{bmatrix} $$\n\nWe specify $n=2$ to get the transformation required: \n\n$$\\textrm{R1Frac}(2,k) = \\begin{bmatrix} 1 & 0 \\\\ 0 & e^{2\\pi i/2^{k}} \\end{bmatrix} $$"
7700
+ },
7701
+ {
7702
+ "type": "solution",
7703
+ "id": "qft__rotation_gate_solution",
7704
+ "code": "namespace Kata {\n operation Rotation(q : Qubit, k : Int) : Unit is Adj + Ctl {\n R1Frac(2, k, q);\n }\n}"
7705
+ }
7706
+ ]
7707
+ }
7708
+ },
7709
+ {
7710
+ "type": "exercise",
7711
+ "id": "qft__binary_fraction_classical",
7712
+ "title": "Binary Fraction Exponent (Classical Input)",
7713
+ "description": {
7714
+ "type": "text-content",
7715
+ "content": "**Inputs**:\n\n1. A qubit in state $\\ket{\\psi} = \\alpha \\ket{0} + \\beta \\ket{1}$.\n2. An array of $n$ bits $[j_1, j_2, ..., j_n]$, stored as `Bool[]`.\n\n**Goal**: \nChange the state of the qubit to $\\alpha \\ket{0} + \\beta \\cdot e^{2\\pi i \\cdot 0.j_1 j_2 ... j_n} \\ket{1}$, where $0.j_1 j_2 ... j_n$ is a binary fraction in big endian notation, similar to decimal fractions:\n\n$$0.j_1 j_2 ... j_n = j_1 \\cdot \\frac{1}{2^1} + j_2 \\cdot \\frac{1}{2^2} + ... + j_n \\cdot \\frac{1}{2^n}$$\n"
7716
+ },
7717
+ "sourceIds": [
7718
+ "qft__binary_fraction_classical__Verification.qs",
7719
+ "KatasLibrary.qs"
7720
+ ],
7721
+ "placeholderCode": "namespace Kata {\n operation BinaryFractionClassical(q : Qubit, j : Bool[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n",
7722
+ "explainedSolution": {
7723
+ "type": "explained-solution",
7724
+ "items": [
7725
+ {
7726
+ "type": "text-content",
7727
+ "content": "\nSince you can express the exponent of a sum as a product of exponents ($e^{a+b} = e^a \\cdot e^b$), you can implement the required transformation as a sequence of rotation gates from the previous task with increasing $k$.\n\nEach of the individual rotations will use the bit $j_k$ to decide whether to apply the rotation (you only want to apply the rotation if $j_k$ is true), and the index of that bit $k$ to define the rotation angle.\nThe gate applied for each $k$ will be:\n\n$$U_k = \\begin{cases}\nI, j_k=0 \\\\\n\\textrm{R1Frac}(2, k), j_k=1\n\\end{cases}$$\n\nRecall that \n\n$$ \\textrm{R1Frac}(2, k)( \\alpha \\ket{0} + \\beta \\ket{1}) = \\alpha \\ket{0} + \\beta \\cdot e^{2\\pi i/2^{k}} \\ket{1} = \\alpha \\ket{0} + \\beta \\cdot e^{2\\pi i \\cdot 0. \\underset{k-1}{\\underbrace{0\\dots0}} 1} \\ket{1}$$\n\nThis means that the overall effect of the gate $U_k$ for each $k$ is:\n\n$$U_k (\\alpha \\ket{0} + \\beta \\ket{1}) = \\alpha \\ket{0} + \\beta \\cdot e^{2\\pi i \\cdot 0. \\underset{k-1}{\\underbrace{0\\dots0}} j_k} \\ket{1}$$\n\nAs you iterate over $k$, the resulting state will get closer and closer to the required one:\n\n<table>\n <tr>\n <th>$k$</th>\n <th>State after step $k$</th>\n </tr>\n <tr>\n <td>$1$</td>\n <td>$$\\alpha \\ket{0} + \\beta \\cdot e^{2\\pi i \\cdot 0.j_1} \\ket{1}$$</td>\n </tr>\n <tr>\n <td>$2$</td>\n <td>$$\\alpha \\ket{0} + \\beta \\cdot e^{2\\pi i \\cdot 0.j_1j_2} \\ket{1}$$</td>\n </tr>\n <tr>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <td>$n$</td>\n <td>$$\\alpha \\ket{0} + \\beta \\cdot e^{2\\pi i \\cdot 0.j_1j_2 \\dots j_n}\\ket{1}$$</td>\n </tr>\n</table>"
7728
+ },
7729
+ {
7730
+ "type": "solution",
7731
+ "id": "qft__binary_fraction_classical_solution_a",
7732
+ "code": "namespace Kata {\n operation BinaryFractionClassical(q : Qubit, j : Bool[]) : Unit is Adj + Ctl {\n for ind in 0 .. Length(j) - 1 {\n if j[ind] {\n R1Frac(2, ind + 1, q);\n }\n }\n }\n}"
7733
+ },
7734
+ {
7735
+ "type": "text-content",
7736
+ "content": "\nAlternatively, you can do this in a single rotation using the $R1$ gate if you convert the array $j$ into a rotation angle. You'll need the angle $2\\pi \\cdot 0.j_1j_2 \\dots j_n$, and this fraction can be calculated by converting the bit string into an integer $j$ (using big endian notation) and dividing it by $2^n$.\n\nThis solution is better when considered on its own, since it involves doing only a single rotation rather than a series of them. However, it will not be as helpful as the first one once you get to the next task!"
7737
+ },
7738
+ {
7739
+ "type": "solution",
7740
+ "id": "qft__binary_fraction_classical_solution_b",
7741
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n\n operation BinaryFractionClassical(q : Qubit, j : Bool[]) : Unit is Adj + Ctl {\n let n = Length(j);\n let jIntBE = BoolArrayAsInt(Reversed(j));\n R1(2.0 * PI() * IntAsDouble(jIntBE) / IntAsDouble(1 <<< n), q);\n }\n}"
7742
+ }
7743
+ ]
7744
+ }
7745
+ },
7746
+ {
7747
+ "type": "exercise",
7748
+ "id": "qft__binary_fraction_quantum",
7749
+ "title": "Binary Fraction Exponent (Quantum Input)",
7750
+ "description": {
7751
+ "type": "text-content",
7752
+ "content": "**Inputs**:\n\n1. A qubit in state $\\ket{\\psi} = \\alpha \\ket{0} + \\beta \\ket{1}$.\n2. An array of $n$ qubits $j$ in state $\\ket{j_1 j_2 ... j_n}$.\n\n**Goal**: \nChange the state of the input qubits from $(\\alpha \\ket{0} + \\beta \\ket{1}) \\otimes \\ket{j_1 j_2 ... j_n}$ to $(\\alpha \\ket{0} + \\beta \\cdot e^{2\\pi i \\cdot 0.j_1 j_2 ... j_n} \\ket{1}) \\otimes \\ket{j_1 j_2 ... j_n}$, where $0.j_1 j_2 ... j_n$ is a binary fraction corresponding to the basis state $j_1 j_2 ... j_n$ of the qubit array $j$.\n\n> The qubit array can be in superposition as well;\nthe behavior of the transformation in this case is defined by its behavior on the basis states and the linearity of unitary transformations.\n"
7753
+ },
7754
+ "sourceIds": [
7755
+ "qft__binary_fraction_quantum__Verification.qs",
7756
+ "KatasLibrary.qs"
7757
+ ],
7758
+ "placeholderCode": "namespace Kata {\n operation BinaryFractionQuantum(q : Qubit, j : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n",
7759
+ "explainedSolution": {
7760
+ "type": "explained-solution",
7761
+ "items": [
7762
+ {
7763
+ "type": "text-content",
7764
+ "content": "\nFrom the goal of the exercise, you can see that the register $j$ has to remain unchanged, while the first input qubit should acquire a phase that depends on the value of the qubits in the register $j$.\n\nSince $j$ is a quantum register and can be in a superposition of basis states, you cannot just measure the register and then apply the operation from the previous task using measurement results as the second argument. Instead, you have to convert the solution to the previous task from using $\\textrm{R1Frac}$ gates with classical conditions to using them as controlled operations, with the qubits of the register $j$ as quantum conditions. You can do this using the `Controlled` functor."
7765
+ },
7766
+ {
7767
+ "type": "solution",
7768
+ "id": "qft__binary_fraction_quantum_solution",
7769
+ "code": "namespace Kata {\n operation BinaryFractionQuantum(q : Qubit, j : Qubit[]) : Unit is Adj + Ctl {\n for ind in 0 .. Length(j) - 1 {\n Controlled R1Frac([j[ind]], (2, ind + 1, q));\n }\n }\n}"
7770
+ }
7771
+ ]
7772
+ }
7773
+ },
7774
+ {
7775
+ "type": "exercise",
7776
+ "id": "qft__binary_fraction_inplace",
7777
+ "title": "Binary Fraction Exponent In-Place (Quantum Input)",
7778
+ "description": {
7779
+ "type": "text-content",
7780
+ "content": "**Input**:\nA register of $n$ qubits in state $\\ket{j_1 j_2 ... j_n}$.\n\n**Goal**: \nChange the state of the register from $\\ket{j_1} \\otimes \\ket{j_2 ... j_n}$ to $\\frac1{\\sqrt2}(\\ket{0} + e^{2\\pi i \\cdot 0.j_1 j_2 ... j_n} \\ket{1}) \\otimes \\ket{j_2 ... j_n}$.\n\n<details>\n <summary><b>Need a hint?</b></summary>\n \nThis task is very similar to the previous task, but the digit $j_1$ has to be encoded in-place. You can do this using the first task of the kata, \"Single-Qubit QFT\".\n</details>\n"
7781
+ },
7782
+ "sourceIds": [
7783
+ "qft__binary_fraction_inplace__Verification.qs",
7784
+ "KatasLibrary.qs"
7785
+ ],
7786
+ "placeholderCode": "namespace Kata {\n operation BinaryFractionQuantumInPlace(j : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n}\n",
7787
+ "explainedSolution": {
7788
+ "type": "explained-solution",
7789
+ "items": [
7790
+ {
7791
+ "type": "text-content",
7792
+ "content": "\nFirst, let's recall the first task of the kata: a Hadamard gate applied to a single qubit, $H\\ket{j_1}$, will give either\n$\\frac1{\\sqrt2}(\\ket{0} + \\ket{1})$ or $\\frac{1}{\\sqrt{2}}(\\ket{0} - \\ket{1})$ depending on the state of $\\ket{j_1}$. This operation can also be written as\n$$H\\ket{j_1} = \\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot \\frac{j_1}{2}}\\ket{1} \\big)= \\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_1}\\ket{1} \\big)$$\n\nSo, if the starting register state is $\\ket{j_1 j_2 ... j_n}$, applying a Hadamard gate to the first qubit will result in:\n\n$$\\big(H_1\\otimes I_{n-1} \\big) \\big(\\ket{j_1} \\otimes \\ket{j_2 ... j_n} \\big)= \\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_1}\\ket{1} \\big) \\otimes \\ket{j_2 ... j_n} $$\n\nAfter this, we can repeat the loop we used in the previous task for qubits $\\ket{j_2 ... j_n}$ with the first qubit as the target to adjust the remaining phase terms via the controlled $\\textrm{R1Frac}$ gate."
7793
+ },
7794
+ {
7795
+ "type": "solution",
7796
+ "id": "qft__binary_fraction_inplace_solution",
7797
+ "code": "namespace Kata {\n operation BinaryFractionQuantumInPlace(j : Qubit[]) : Unit is Adj + Ctl {\n H(j[0]);\n for ind in 1 .. Length(j) - 1 {\n Controlled R1Frac([j[ind]], (2, ind + 1, j[0]));\n }\n }\n}"
7798
+ }
7799
+ ]
7800
+ }
7801
+ },
7802
+ {
7803
+ "type": "exercise",
7804
+ "id": "qft__qft",
7805
+ "title": "Quantum Fourier Transform",
7806
+ "description": {
7807
+ "type": "text-content",
7808
+ "content": "**Input**:\nA register of $n$ qubits in state $\\ket{j_1 j_2 ... j_n}$.\n\n**Goal**: \nApply quantum Fourier transform to the input register, that is, transform it to a state\n\n$$\\begin{align*}\n&\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_n} \\ket{1} \\big) \\otimes \\\\\n\\otimes &\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_{n-1} j_n} \\ket{1} \\big) \\otimes ... \\otimes \\\\\n\\otimes &\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_1 j_2 ... j_{n-1} j_n} \\ket{1} \\big)\n\\end{align*}$$\n\nThe register of qubits can be in superposition as well;\nthe behavior in this case is defined by behavior on the basis states and the linearity of unitary transformations.\n\n> Notice that this implementation will let you use inverse QFT without writing any extra code, just by using the adjoint of this operation!\n\n<details>\n <summary><b>Need a hint?</b></summary>\n \nConsider first preparing a state with the states of individual qubits reversed and then transforming it to the goal state.\n</details>"
7809
+ },
7810
+ "sourceIds": [
7811
+ "qft__qft__Verification.qs",
7812
+ "KatasLibrary.qs"
7813
+ ],
7814
+ "placeholderCode": "namespace Kata {\n operation QuantumFourierTransform(j : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n \n }\n\n // You might find this helper operation from an earlier task useful.\n operation BinaryFractionQuantumInPlace(j : Qubit[]) : Unit is Adj + Ctl {\n H(j[0]);\n for ind in 1 .. Length(j) - 1 {\n Controlled R1Frac([j[ind]], (2, ind + 1, j[0]));\n }\n }\n}\n",
7815
+ "explainedSolution": {
7816
+ "type": "explained-solution",
7817
+ "items": [
7818
+ {
7819
+ "type": "text-content",
7820
+ "content": "\nLet's use the hint and start by preparing the described state with the qubits reversed:\n\n$$\\begin{align*}\n&\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_1 j_2 ... j_{n-1} j_n} \\ket{1} \\big) \\otimes \\\\\n&\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_2 ... j_{n-1} j_n} \\ket{1} \\big) \\otimes ... \\otimes \\\\\n\\otimes &\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_{n-1} j_n} \\ket{1} \\big) \\otimes \\\\\n\\otimes &\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_n} \\ket{1} \\big)\n\\end{align*}$$\n\nYou've already found a way to prepare a binary fraction exponent (the desired state of the first qubit) in-place in the previous task. The state $\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_1 j_2 ... j_{n-1} j_n} \\ket{1} \\big) \\otimes \\ket{j_2 ... j_n}$ can be prepared by first applying the Hadamard gate to the first qubit in state $\\ket{j_1}$ and then applying a succession of controlled rotations using qubits $\\ket{j_k}$ with increasing values of $k$ as controls, so that an extra phase terms from $e^{2\\pi i \\cdot j_2/2^2}$ all the way up to $e^{2\\pi i \\cdot j_n/2^{n}}$ are added with each rotation. \n\nThis will prepare the first qubit in the right state. You can see that $j_1$ doesn't appear in the rest of the expression for the target state, so you won't need to use it in the rest of the code.\n\nTo prepare the remaining qubits in the right states, you can work backwards from this state.\nThe second qubit in the sequence needs to be prepared in the state $\\frac{1}{\\sqrt{2}} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_2 ... j_{n-1} j_n} \\ket{1} \\big)$. \nSimilarly to the first qubit, you can do this by applying a Hadamard gate to the qubit $\\ket{j_2}$ and then using qubits $\\ket{j_3}$ to $\\ket{j_n}$ to apply $n-2$ controlled rotation gates to the second qubit. \nAfter this operation, the total system state will be: \n\n$$\\frac{1}{\\sqrt{2}} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_1 j_2 ... j_{n-1} j_n} \\ket{1} \\big)\\otimes\n\\frac{1}{\\sqrt{2}} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_2 ... j_{n-1} j_n} \\ket{1} \\big) \\otimes \\ket{j_3 ... j_n}$$\n\nThese two steps allow us to see a pattern: for each qubit $j_k, k = 1 .. n$ :\n\n1. Apply a Hadamard gate to $|j_k\\rangle$.\n2. Apply the controlled rotation operator $n-k$ times to the qubit $|j_k\\rangle$, using qubits $|j_{k+1}\\rangle$ through $|j_n\\rangle$ as the controls, with phases corresponding to fractions from $2^2$ to $2^{n-k+1}$.\n\nThe effect of these steps will be preparing the state that almost matches the required state, but has the qubit order reversed compared to it. \nYou can fix that by using a series of $\\textrm{SWAP}$ gates to reverse the order of qubits in the state."
7821
+ },
7822
+ {
7823
+ "type": "solution",
7824
+ "id": "qft__qft_solution",
7825
+ "code": "namespace Kata {\n operation QuantumFourierTransform(j : Qubit[]) : Unit is Adj + Ctl {\n let n = Length(j);\n for ind in 0 .. n - 1 {\n BinaryFractionQuantumInPlace(j[ind ...]);\n }\n for ind in 0 .. n / 2 - 1 {\n SWAP(j[ind], j[n - 1 - ind]);\n } \n }\n\n operation BinaryFractionQuantumInPlace(j : Qubit[]) : Unit is Adj + Ctl {\n H(j[0]);\n for ind in 1 .. Length(j) - 1 {\n Controlled R1Frac([j[ind]], (2, ind + 1, j[0]));\n }\n }\n}"
7826
+ }
7827
+ ]
7828
+ }
7829
+ },
7830
+ {
7831
+ "type": "lesson",
7832
+ "id": "qft__equivalence",
7833
+ "title": "The Equivalence of Two QFT Notations",
7834
+ "items": [
7835
+ {
7836
+ "type": "text-content",
7837
+ "content": "\nHow to show that the transformation defined in the last exercise is the same as the original definition of QFT?\nIn other words, how to prove the equality below?\n\n$$\\frac1{\\sqrt{2^n}} \\sum_{k=0}^{2^n-1} e^{2\\pi i \\cdot \\frac{jk}{2^{n}}} \\ket{k} = $$\n$$\\begin{align*}\n= &\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_n} \\ket{1} \\big) \\otimes \\\\\n\\otimes &\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_{n-1} j_n} \\ket{1} \\big) \\otimes ... \\otimes \\\\\n\\otimes &\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot 0.j_1 j_2 ... j_{n-1} j_n} \\ket{1} \\big)\n\\end{align*}$$\n \nThe tensor product state is defined in terms of the digits $j_1, j_2, ..., j_n$. Let's spell the exponents used in each term of the tensor product in terms of the integer $j$ instead:\n$$e^{2\\pi i \\cdot 0.j_1 j_2 ... j_{n-1} j_n} = e^{2\\pi i \\cdot \\frac{j}{2^n}}$$\n$$e^{2\\pi i \\cdot 0.j_2 ... j_{n-1} j_n} = e^{2\\pi i \\cdot j_1} e^{2\\pi i \\cdot 0.j_2 ... j_{n-1} j_n} = e^{2\\pi i \\cdot j_1.j_2 ... j_{n-1} j_n} = e^{2\\pi i \\cdot \\frac{j \\cdot 2}{2^n}}$$\n(Remember that since $j_1$ can only be $0$ or $1$, $e^{2\\pi i \\cdot j_1}$ is either $e^0$ or $e^{2\\pi i}$, which are both $1$. Any exponents of integer multiples of $e^{2\\pi i}$ are $1$ and thus can be ignored.)\n\nAnd so on, until the last term:\n$$e^{2\\pi i \\cdot 0.j_n} = e^{2\\pi i \\cdot \\frac{j \\cdot 2^{n-1}}{2^n}}$$\n\nNow, the complete state looks as follows:\n$$\\begin{align*}\n&\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot \\frac{j \\cdot 2^{n-1}}{2^n}} \\ket{1} \\big) \\otimes \\\\\n\\otimes &\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot \\frac{j \\cdot 2^{n-2}}{2^n}} \\ket{1} \\big) \\otimes ... \\otimes \\\\\n\\otimes &\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot \\frac{j}{2^n}} \\ket{1} \\big)\n\\end{align*}$$\n\nWhat happens if you open the brackets and compare the results to the definition of the QFT?\nLet's do this exercise for $n = 2$.\n\n$$\\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot \\frac{j \\cdot 2}{4}} \\ket{1} \\big) \\otimes \\frac1{\\sqrt2} \\big(\\ket{0} + e^{2\\pi i \\cdot \\frac{j}{4}} \\ket{1} \\big) = $$\n$$= \\frac14 \\big( \\ket{00} + e^{2\\pi i \\cdot \\frac{j}{4}}\\ket{01} + e^{2\\pi i \\cdot \\frac{j \\cdot 2}{4}}\\ket{10} + e^{2\\pi i \\cdot \\frac{j \\cdot 2 + j}{4}} \\ket{11} \\big)$$\n\nRemember that this kata uses big endian to map bit strings to integers, so this can be rewritten as follows:\n$$\\frac14 \\big( \\ket{0} + e^{2\\pi i \\cdot \\frac{j}{4}}\\ket{1} + e^{2\\pi i \\cdot \\frac{j \\cdot 2}{4}}\\ket{2} + e^{2\\pi i \\cdot \\frac{j \\cdot 3}{4}} \\ket{3} \\big)$$\nAnd that's exactly the original definition of QFT:\n$$\\frac1{\\sqrt{4}}\\sum_{k=0}^{3} e^{2\\pi i jk/4} \\ket{k}$$\n\nThe same can be done for an arbitrary $n$."
7838
+ }
7839
+ ]
7840
+ },
7841
+ {
7842
+ "type": "lesson",
7843
+ "id": "qft__use",
7844
+ "title": "Using Quantum Fourier Transform",
7845
+ "items": [
7846
+ {
7847
+ "type": "text-content",
7848
+ "content": "\nThis section offers you tasks on state preparation and state analysis that can be solved using QFT or inverse QFT. \nYou can solve them without QFT, but it is useful to try and come up with a QFT-based solution as an exercise."
7849
+ }
7850
+ ]
7851
+ },
7852
+ {
7853
+ "type": "exercise",
7854
+ "id": "qft__all_basis_vectors",
7855
+ "title": "Prepare Even Superposition of All Basis Vectors",
7856
+ "description": {
7857
+ "type": "text-content",
7858
+ "content": "**Input:** $n$ qubits in the $\\ket{0 \\dots 0}$ state.\n\n**Goal:** Change the state of the qubits to an equal superposition of all basis vectors $\\frac{1}{\\sqrt{2^N}} \\big (\\ket{0 \\dots 0} + \\dots + \\ket{1 \\dots 1}\\big)$. \n"
7859
+ },
7860
+ "sourceIds": [
7861
+ "qft__all_basis_vectors__Verification.qs",
7862
+ "KatasLibrary.qs"
7863
+ ],
7864
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation AllBasisVectors(qs : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n\n // You might find this helper operation that implements QFT using a library operation useful.\n operation QFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n}\n",
7865
+ "explainedSolution": {
7866
+ "type": "explained-solution",
7867
+ "items": [
7868
+ {
7869
+ "type": "text-content",
7870
+ "content": "\nYou can think of the required equal superposition of all basis states as the QFT of the state $\\ket{0...0}$. Indeed, if $j_1 = j_2 = ... = j_n = 0$, $j = 0$, and you get the following state:\n\n$$\\frac1{\\sqrt{2^n}} \\sum_{k=0}^{2^n-1} e^{2\\pi i \\cdot \\frac{jk}{2^{n}}} \\ket{k} = \\frac{1}{\\sqrt{2^n}} \\sum_{k=0}^{2^n-1} e^{0} \\ket{k} = \\frac{1}{\\sqrt{2^n}} \\sum_{k=0}^{2^n-1} \\ket{k}$$\n\nThis means that you can solve this task by simply applying the QFT to the given qubit register."
7871
+ },
7872
+ {
7873
+ "type": "solution",
7874
+ "id": "qft__all_basis_vectors_solution",
7875
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation AllBasisVectors(qs : Qubit[]) : Unit is Adj + Ctl {\n QFT(qs);\n }\n\n operation QFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n}\n"
7876
+ }
7877
+ ]
7878
+ }
7879
+ },
7880
+ {
7881
+ "type": "exercise",
7882
+ "id": "qft__periodic_state",
7883
+ "title": "Prepare a Periodic State",
7884
+ "description": {
7885
+ "type": "text-content",
7886
+ "content": "**Inputs:**\n\n1. $n$ qubits in the $\\ket{0 \\dots 0}$ state.\n2. An integer frequency $F$ ($0 \\leq F \\leq 2^{n}-1$).\n\n**Goal:** Change the state of the qubits to a periodic state with frequency $F$:\n\n$$\\frac1{\\sqrt{2^n}} \\sum_{k=0}^{2^n-1} e^{2\\pi i \\cdot \\frac{Fk}{2^{n}}} \\ket{k}$$\n\n> For example, for $n = 2$ and $F = 1$ the goal state is $\\frac12\\big(\\ket{0} + i\\ket{1} - \\ket{2} - i\\ket{3} \\big)$.\n"
7887
+ },
7888
+ "sourceIds": [
7889
+ "qft__periodic_state__Verification.qs",
7890
+ "KatasLibrary.qs"
7891
+ ],
7892
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation PeriodicState(qs : Qubit[], F : Int) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n\n // You might find this helper operation that implements QFT using a library operation useful.\n operation QFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n}\n",
7893
+ "explainedSolution": {
7894
+ "type": "explained-solution",
7895
+ "items": [
7896
+ {
7897
+ "type": "text-content",
7898
+ "content": "\nRecall the definition of the QFT: \nfor a basis state $\\ket{j}$, the QFT is defined as \n\n$$QFT\\ket{j}= \\frac1{\\sqrt{2^n}} \\sum_{k=0}^{2^n-1} e^{2\\pi i \\cdot j k/2^{n}} \\ket{k}$$\n\nYou can see that using $j = F$ will produce exactly the required state!\n\nTo prepare the state $\\ket{F}$ on the input register, you need to convert the integer value $F$ into a big endian binary representation and encode it in the register. \n\n> When writing the code, make sure that you pay attention to whether library functions use little or big endian! In particular, `IntAsBoolArray` uses little endian encoding, and the QFT operation uses big endian, so the result of converting the integer into a bit string must be reversed before encoding it in the register."
7899
+ },
7900
+ {
7901
+ "type": "solution",
7902
+ "id": "qft__periodic_state_solution",
7903
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n\n operation PeriodicState(qs : Qubit[], F : Int) : Unit is Adj + Ctl {\n let bitsBE = Reversed(IntAsBoolArray(F, Length(qs)));\n ApplyPauliFromBitString(PauliX, true, bitsBE, qs);\n QFT(qs);\n }\n\n operation QFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n}\n"
7904
+ }
7905
+ ]
7906
+ }
7907
+ },
7908
+ {
7909
+ "type": "exercise",
7910
+ "id": "qft__alternating_amplitudes",
7911
+ "title": "Prepare a State with Alternating Amplitudes",
7912
+ "description": {
7913
+ "type": "text-content",
7914
+ "content": "**Input:** $n$ qubits in the $\\ket{0 \\dots 0}$ state.\n\n**Goal:** Change the state of the qubits to a periodic state with alternating $1$ and $-1$ amplitudes of basis states:\n\n$$\\frac1{\\sqrt{2^n}} \\big(\\ket{0} - \\ket{1} + \\ket{2} - \\ket{3} + ... - \\ket{2^n-1} \\big)$$\n\n> For example, for $n = 2$ the goal state is $\\frac12 \\big(\\ket{0} - \\ket{1} + \\ket{2} - \\ket{3}\\big)$."
7915
+ },
7916
+ "sourceIds": [
7917
+ "qft__alternating_amplitudes__Verification.qs",
7918
+ "KatasLibrary.qs"
7919
+ ],
7920
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation AlternatingAmplitudes(qs : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n\n // You might find this helper operation that implements QFT using a library operation useful.\n operation QFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n}\n",
7921
+ "explainedSolution": {
7922
+ "type": "explained-solution",
7923
+ "items": [
7924
+ {
7925
+ "type": "text-content",
7926
+ "content": "\nSince the amplitudes of this state have no imaginary parts, it is clear that the value of exponents for an arbitrary amplitude $e^{2\\pi i \\cdot \\frac{Fk}{2^n}}$ must be either $2\\pi i$ to get an amplitude equal $1$ or $\\pi i$ for an amplitude of $-1$. \nThis means that only $j_1$ can be $1$: all other bits of $F$ must be $0$. \nIndeed, you can check that using $F = 10...0 = 2^{n - 1}$ with the solution of the previous task yields the required state.\n\nYou can simplify preparing this state: instead of using the general encoding of $F$ in the register, you can apply an $X$ gate to the first qubit of the register."
7927
+ },
7928
+ {
7929
+ "type": "solution",
7930
+ "id": "qft__alternating_amplitudes_solution",
7931
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation AlternatingAmplitudes(qs : Qubit[]) : Unit is Adj + Ctl {\n X(qs[0]);\n QFT(qs);\n }\n\n operation QFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n}\n"
7932
+ }
7933
+ ]
7934
+ }
7935
+ },
7936
+ {
7937
+ "type": "exercise",
7938
+ "id": "qft__all_even_vectors",
7939
+ "title": "Prepare Even Superposition of All Even Basis Vectors",
7940
+ "description": {
7941
+ "type": "text-content",
7942
+ "content": "**Input:** $n$ qubits in the $\\ket{0 \\dots 0}$ state.\n\n**Goal:** Change the state of the qubits to an equal superposition of all even basis vectors:\n\n$$\\frac1{\\sqrt{2^{n-1}}} \\big(\\ket{0} + \\ket{2} + ... + \\ket{2^n-2} \\big)$$\n\n> For example, for $n = 2$ the goal state is $\\frac1{\\sqrt2} \\big(\\ket{0} + \\ket{2}\\big)$.\n\n<details>\n <summary><b>Need a hint?</b></summary>\n Which superposition of two basis states can be mapped to this state using QFT?\n Use the solutions to earlier tasks in this lesson to figure out the answer.\n</details>"
7943
+ },
7944
+ "sourceIds": [
7945
+ "qft__all_even_vectors__Verification.qs",
7946
+ "KatasLibrary.qs"
7947
+ ],
7948
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation AllEvenVectors(qs : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n\n // You might find this helper operation that implements QFT using a library operation useful.\n operation QFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n}\n",
7949
+ "explainedSolution": {
7950
+ "type": "explained-solution",
7951
+ "items": [
7952
+ {
7953
+ "type": "text-content",
7954
+ "content": "\nYou can see that the even superposition of two states from the first and the third tasks in this lesson will give the desired result. Indeed,\n\n$$\\frac1{\\sqrt{2^{n-1}}} \\big(\\ket{0} + \\ket{2} + ... + \\ket{2^n-2}\\big) =$$\n$$=\\frac{1}{\\sqrt{2}} \\bigg( \\frac1{\\sqrt{2^n}} \\big(\\ket{0} - \\ket{1} + \\ket{2} - \\ket{3} + ... - \\ket{2^n-1}\\big) + \\frac1{\\sqrt{2^n}} \\big(\\ket{0} + \\ket{1} + \\ket{2} + \\ket{3} + ... + \\ket{2^n-1}\\big)\\bigg)$$\n\nNow, you can use the fact that QFT is a linear transformation.\nThe two periodic states from earlier tasks are created by applying the QFT to the states $\\ket{100...0}$ and $\\ket{000...0}$ state. \nTo prepare an equal superposition of these two states, you can apply a Hadamard gate to the first qubit in the register:\n\n$$ \\frac1{\\sqrt2} \\big(\\ket{0} + \\ket{1}\\big) \\otimes \\ket{00...0} $$\n\nThen you apply QFT to the register: \n\n$$ QFT\\big(\\frac1{\\sqrt2} (\\ket{0} + \\ket{1}) \\otimes \\ket{00...0}\\big) = \\frac1{\\sqrt2} \\big( QFT\\ket{000...0} + QFT\\ket{100...0}\\big)$$\n\nThis results in the desired end state."
7955
+ },
7956
+ {
7957
+ "type": "solution",
7958
+ "id": "qft__all_even_vectors_solution",
7959
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation AllEvenVectors(qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n QFT(qs);\n }\n\n operation QFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n}\n"
7960
+ }
7961
+ ]
7962
+ }
7963
+ },
7964
+ {
7965
+ "type": "exercise",
7966
+ "id": "qft__square_wave",
7967
+ "title": "Prepare Square-Wave Signal",
7968
+ "description": {
7969
+ "type": "text-content",
7970
+ "content": "**Input:** $n \\ge 2$ qubits in the $\\ket{0 \\dots 0}$ state.\n\n**Goal:** Change the state of the qubits to a periodic state with alternating $1, 1, -1, -1$ amplitudes of basis states:\n\n$$\\frac1{\\sqrt{2^n}} \\big(\\ket{0} + \\ket{1} - \\ket{2} - \\ket{3} + ... - \\ket{2^n-2} - \\ket{2^n-1} \\big)$$\n\n> For example, for $n = 2$ the goal state is $\\frac12 \\big(\\ket{0} + \\ket{1} - \\ket{2} - \\ket{3}\\big)$.\n"
7971
+ },
7972
+ "sourceIds": [
7973
+ "qft__square_wave__Verification.qs",
7974
+ "KatasLibrary.qs"
7975
+ ],
7976
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation SquareWave(qs : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n\n // You might find this helper operation that implements QFT using a library operation useful.\n operation QFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n}\n",
7977
+ "explainedSolution": {
7978
+ "type": "explained-solution",
7979
+ "items": [
7980
+ {
7981
+ "type": "text-content",
7982
+ "content": "\nThe target state written in binary notation instead of integers can have its terms grouped in fours that look as follows:\n\n$$ \\ket{...00} + \\ket{...01} - \\ket{...10} - \\ket{...11} $$\n\nThe states which have $1$ as their second-least significant bit have a $-1$ relative phase, and the states with $0$ in that bit have a $1$ relative phase. Written as a tensor product of single-qubit states, the target state looks as follows:\n\n$$\\frac1{\\sqrt{2^n}} (\\ket{0} + \\ket{1}) \\otimes (\\ket{0} + \\ket{1}) \\otimes ... \\otimes (\\ket{0} - \\ket{1}) \\otimes (\\ket{0} + \\ket{1})$$\n\nYou could try to prepare this state by setting only $j_2$ to $1$ and the rest of bits of $j$ to $0$ and then applying the QFT. This will add the required relative phase of $-1$ on the second-to-last qubit bit, but will also add a relative phase of $i$ on the last qubit bit:\n\n$$QFT(\\ket{010...0}) = \\frac1{\\sqrt{2^n}} (\\ket{0} + \\ket{1}) \\otimes (\\ket{0} + \\ket{1}) \\otimes ... \\otimes (\\ket{0} - \\ket{1}) \\otimes (\\ket{0} + i\\ket{1})$$\n\nTo fix this last qubit state, you need to cancel out that last $i$ relative phase in some form. This can be achieved by using the following state as the input to QFT:\n\n$$\\frac1{\\sqrt2} \\big(e^{-i\\pi/4} \\ket{010...0} + e^{i\\pi/4} \\ket{110...0}\\big)$$\n\nYou can write out the result of applying QFT to this state as follows, using the fact that $e^{\\pm i\\pi/4} = \\frac{1 \\pm i}{\\sqrt2}$:\n\n$$QFT\\bigg(\\frac1{\\sqrt2} \\big(e^{-i\\pi/4} \\ket{010...0} + e^{i\\pi/4} \\ket{110...0}\\big)\\bigg) =$$\n$$= \\frac1{\\sqrt2}\\bigg( \\frac{1-i}{\\sqrt2} QFT\\ket{010...0} + \\frac{1+i}{\\sqrt2} QFT\\ket{110...0} \\bigg) = $$\n$$= \\frac{(1-i)}{2\\sqrt{2^n}} (\\ket{0} + \\ket{1}) \\otimes (\\ket{0} + \\ket{1}) \\otimes ... \\otimes (\\ket{0} - \\ket{1}) \\otimes (\\ket{0} + i\\ket{1}) + $$\n$$+ \\frac{(1+i)}{2\\sqrt{2^n}} (\\ket{0} + \\ket{1}) \\otimes (\\ket{0} + \\ket{1}) \\otimes ... \\otimes (\\ket{0} - \\ket{1}) \\otimes (\\ket{0} - i\\ket{1}) =$$\n$$= \\frac{1}{\\sqrt{2^{n}}} (\\ket{0} + \\ket{1}) \\otimes (\\ket{0} + \\ket{1}) \\otimes ... \\otimes (\\ket{0} - \\ket{1}) \\otimes (\\ket{0} + \\ket{1})$$\n \nCreating the required initial superposition state can be done using the $T$ gate and its adjoint in addition to the more standard $X$ and $H$ gates:\n\n1. Apply an $H$ gate to the first qubit and an $X$ gate to the second qubit:\n $$\\frac1{\\sqrt2} \\big(\\ket{010...0} + \\ket{110...0}\\big)$$\n2. Add the relative phase $e^{i\\pi/4}$ to the second term by applying a $T$ gate to the first qubit:\n $$\\frac1{\\sqrt2} \\big(\\ket{010...0} + e^{i\\pi/4} \\ket{110...0}\\big)$$\n3. Add the relative phase $e^{-i\\pi/4}$ to the first term by applying an adjoint $T$ gate wrapped in $X$ gates to the first qubit (this way, the relative phase will be applied to $\\ket{0}$ basis state of that qubit):\n $$\\frac1{\\sqrt2} \\big(e^{-i\\pi/4} \\ket{010...0} + e^{i\\pi/4} \\ket{110...0}\\big)$$"
7983
+ },
7984
+ {
7985
+ "type": "solution",
7986
+ "id": "qft__square_wave_solution",
7987
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation SquareWave(qs : Qubit[]) : Unit is Adj + Ctl {\n X(qs[1]);\n H(qs[0]);\n T(qs[0]);\n X(qs[0]);\n Adjoint T(qs[0]);\n X(qs[0]);\n QFT(qs);\n }\n\n operation QFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n}\n"
7988
+ }
7989
+ ]
7990
+ }
7991
+ },
7992
+ {
7993
+ "type": "exercise",
7994
+ "id": "qft__signal_frequency",
7995
+ "title": "Get Signal Frequency",
7996
+ "description": {
7997
+ "type": "text-content",
7998
+ "content": "**Input:**\n$n$ qubits in the state\n\n$$\\frac1{\\sqrt{2^n}} \\sum_{k=0}^{2^n-1} e^{2\\pi i \\cdot \\frac{Fk}{2^{n}}} \\ket{k}$$\n\n**Output:** The frequency $F$ of the \"signal\" encoded in this state ($0\\leq F\\leq 2^n-1$).\n\n> For example, for $n = 2$ and the state $\\frac12\\big(\\ket{0} + i\\ket{1} - \\ket{2} - i\\ket{3} \\big)$ the output should be $F = 1$.\n\nThe state of the qubits at the end of the operation does not matter."
7999
+ },
8000
+ "sourceIds": [
8001
+ "qft__signal_frequency__Verification.qs",
8002
+ "KatasLibrary.qs"
8003
+ ],
8004
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation SignalFrequency(qs : Qubit[]) : Int {\n // Implement your solution here...\n \n return -1;\n }\n\n // You might find this helper operation that implements QFT using a library operation useful.\n operation QFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n}\n",
8005
+ "explainedSolution": {
8006
+ "type": "explained-solution",
8007
+ "items": [
8008
+ {
8009
+ "type": "text-content",
8010
+ "content": "\nThe classical Fourier transform produces a time-domain signal's decomposition in the frequency domain, and the inverse Fourier transform produces a frequency-domain signal's time-domain representation.\n\nKeeping this in mind, if you have the state that is the result of applying QFT to a basis state $\\ket{F}$, the value $F$ can be recovered by applying the inverse QFT to this state and then measuring the qubits to find the resulting basis state.\n\nKeep in mind that QFT acts on arrays in big endian notation, and `MeasureInteger` assumes that the input is in little endian, so you need to reverse the register before measuring it and coverting results to an integer."
8011
+ },
8012
+ {
8013
+ "type": "solution",
8014
+ "id": "qft__signal_frequency_solution",
8015
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation SignalFrequency(qs : Qubit[]) : Int {\n Adjoint QFT(qs);\n return MeasureInteger(Reversed(qs));\n }\n\n operation QFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n}\n"
8016
+ }
8017
+ ]
8018
+ }
8019
+ },
8020
+ {
8021
+ "type": "lesson",
8022
+ "id": "qft__conclusion",
8023
+ "title": "Conclusion",
8024
+ "items": [
8025
+ {
8026
+ "type": "text-content",
8027
+ "content": "\nCongratulations! In this kata you learned to implement the quantum Fourier transform and to use it in simple tasks. In the next kata, you will learn to use the QFT to solve a more complicated problem - the phase estimation task."
8028
+ }
8029
+ ]
8030
+ }
8031
+ ],
8032
+ "published": true
8033
+ },
8034
+ {
8035
+ "id": "phase_estimation",
8036
+ "title": "Phase Estimation",
8037
+ "sections": [
8038
+ {
8039
+ "type": "lesson",
8040
+ "id": "phase_estimation__overview",
8041
+ "title": "Overview",
8042
+ "items": [
8043
+ {
8044
+ "type": "text-content",
8045
+ "content": "\nThis kata introduces you to the phase estimation algorithm - an important building block in more advanced quantum algorithms such as integer factoring.\n\n**This kata covers the following topics:**\n\n- The definition of eigenvalues and eigenvectors\n- The phase estimation problem\n- The quantum phase estimation algorithm based on quantum Fourier transform\n\n**What you should know to start working on this kata:**\n\n- Basic quantum gates and measurements.\n- Quantum Fourier transform."
8046
+ }
8047
+ ]
8048
+ },
8049
+ {
8050
+ "type": "lesson",
8051
+ "id": "phase_estimation__eigen",
8052
+ "title": "Eigenvectors, Eigenvalues, and Eigenphases",
8053
+ "items": [
8054
+ {
8055
+ "type": "text-content",
8056
+ "content": "\nAn *eigenvector* of a matrix $A$ is a non-zero vector that, when multiplied by that matrix, changes by a scalar factor:\n\n$$A \\ket{v} = \\lambda \\ket{v}$$\n\nThe number $\\lambda$ is called an *eigenvalue* that corresponds to this eigenvector. In general, eigenvalues of matrices can be complex numbers.\n\nRecall that all quantum gates are unitary matrices, for which their inverse equals their adjoint ($U^{-1} = U^\\dagger$). This means that the eigenvalues of their eigenvectors have the property that their modulus equals $1$: \n\n$$|\\lambda| = 1$$\n\nThus, they can be written in the following form:\n$$\\lambda = e^{i\\theta}$$\n\nThe value $\\theta$ is called an *eigenphase* that corresponds to this eigenvector.\n\n> How can you prove that the modulus of an eigenvalue of a unitary matrix equals $1$?\n> \n> On one hand, by definition of an eigenvalue, \n> $$U \\ket{v} = \\lambda \\ket{v}$$\n> $$|U \\ket{v}| = |\\lambda| \\cdot |\\ket{v}|$$\n> On the other hand, using the properties of the unitary matrix, you can write the following equation:\n> $$|U \\ket{v}|^2 = \\bra{v} U^\\dagger U \\ket{v} = \\bra{v} U^{-1} U \\ket{v} = \\bra{v} I \\ket{v} = \\braket{v|v} = |\\ket{v}|^2$$\n>\n> From these two equations, you get the following equality:\n> $$(|\\lambda| \\cdot |\\ket{v}|)^2 = |\\ket{v}|^2$$\n> And then, finally:\n> $$|\\lambda| = 1$$\n\nIf the quantum gate is self-adjoint, that is, its matrix equals its inverse $U^{-1} = U$, the eigenvalues of this matrix can only be $+1$ and $-1$, with eigenphases $0$ and $\\pi$, respectively.\n\n> You can prove this in a similar manner, using the defintion of an eigenvalue:\n> $$U^2 \\ket{v} = U(U \\ket{v}) = U(\\lambda \\ket{v}) = \\lambda U \\ket{v} = \\lambda^2 \\ket{v}$$\n> At the same time,\n> $$U^2 \\ket{v} = UU \\ket{v} = U^{-1}U \\ket{v} = I \\ket{v} = \\ket{v}$$\n> So you can conclude that $\\lambda^2 = 1$.\n\nFor example, the $Z$ gate has two eigenvctors:\n- $\\ket{0}$, with eigenvalue $1$\n- $\\ket{1}$, with eigenvalue $-1$"
8057
+ }
8058
+ ]
8059
+ },
8060
+ {
8061
+ "type": "exercise",
8062
+ "id": "phase_estimation__eigenvalues_s",
8063
+ "title": "Find Eigenvalues of the S Gate",
8064
+ "description": {
8065
+ "type": "text-content",
8066
+ "content": "**Input:** None.\n\n**Output:** Return an array of two eigenvalues of the $S$ gate.\n\n$$S = \\begin{bmatrix} 1 & 0 \\\\ 0 & i \\end{bmatrix}$$\n\nSort the eigenvalues in decreasing order of their real parts.\n\n> In this task, the eigenvalues are represented as complex numbers of Q# `Complex` type.\n"
8067
+ },
8068
+ "sourceIds": [
8069
+ "phase_estimation__eigenvalues_s__Verification.qs",
8070
+ "KatasLibrary.qs"
8071
+ ],
8072
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function EigenvaluesS() : Complex[] {\n // Replace the return value with correct answer.\n return [Complex(0.0, 0.0),\n Complex(0.0, 0.0)];\n }\n}\n",
8073
+ "explainedSolution": {
8074
+ "type": "explained-solution",
8075
+ "items": [
8076
+ {
8077
+ "type": "text-content",
8078
+ "content": "\nSince the $S$ gate is diagonal, it's easy to realize that its eigenvectors are the basis vectors $\\ket{0}$ and $\\ket{1}$.\n\nTo find the corresponding eigenvalues, you need to solve the two equations:\n- $S\\ket{0} = \\lambda \\ket{0}$, which gives you $\\lambda = 1$.\n- $S\\ket{1} = \\lambda \\ket{1}$, which gives you $\\lambda = i$."
8079
+ },
8080
+ {
8081
+ "type": "solution",
8082
+ "id": "phase_estimation__eigenvalues_s_solution",
8083
+ "code": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function EigenvaluesS() : Complex[] {\n return [Complex(1.0, 0.0),\n Complex(0.0, 1.0)];\n }\n}\n"
8084
+ }
8085
+ ]
8086
+ }
8087
+ },
8088
+ {
8089
+ "type": "exercise",
8090
+ "id": "phase_estimation__eigenvectors_x",
8091
+ "title": "Find Eigenvectors of the X Gate",
8092
+ "description": {
8093
+ "type": "text-content",
8094
+ "content": "**Input:** None.\n\n**Output:** Return an array of two eigenvectors of the $X$ gate that correspond to different eigenvalues.\n\n$$X = \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$$\n\nThe eigenvectors don't have to be normalized, that is, they don't have to describe valid quantum states.\nBoth eigenvectors have to be non-zero.\n\n> In this task, the eigenvectors are represented as arrays of Q# `Double` type of length $2$. Your return should be an array of two such arrays.\n"
8095
+ },
8096
+ "sourceIds": [
8097
+ "phase_estimation__eigenvectors_x__Verification.qs",
8098
+ "KatasLibrary.qs"
8099
+ ],
8100
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function EigenvectorsX() : Double[][] {\n // Replace the return value with correct answer.\n return [[0.0, 0.0], \n [0.0, 0.0]];\n }\n}\n",
8101
+ "explainedSolution": {
8102
+ "type": "explained-solution",
8103
+ "items": [
8104
+ {
8105
+ "type": "text-content",
8106
+ "content": "\nSince the $X$ gate is self-adjoint, you know that its eigenvalues can only be $+1$ and $-1$.\nNow, you need to find the eigenvectors that correspond to these eigenvalues. \nTo do this, you need to solve the two equations:\n- $X \\begin{bmatrix} v_0 \\\\ v_1 \\end{bmatrix} = \\begin{bmatrix} v_0 \\\\ v_1 \\end{bmatrix}$, which gives you $v_0 = v_1$.\n- $X \\begin{bmatrix} v_0 \\\\ v_1 \\end{bmatrix} = -\\begin{bmatrix} v_0 \\\\ v_1 \\end{bmatrix}$, which gives you $v_0 = -v_1$.\n\nOne of the eigenvectors should consist of two equal elements, and the other - of two elements with equal absolute values but opposite signs."
8107
+ },
8108
+ {
8109
+ "type": "solution",
8110
+ "id": "phase_estimation__eigenvectors_x_solution",
8111
+ "code": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function EigenvectorsX() : Double[][] {\n return [[1.0, 1.0], \n [1.0, -1.0]];\n }\n}\n"
8112
+ }
8113
+ ]
8114
+ }
8115
+ },
8116
+ {
8117
+ "type": "exercise",
8118
+ "id": "phase_estimation__state_eigenvector",
8119
+ "title": "Is Given State an Eigenvector of the Gate?",
8120
+ "description": {
8121
+ "type": "text-content",
8122
+ "content": "**Inputs:**\n\n1. A single-qubit unitary $U$.\n2. A single-qubit state $\\ket{\\psi}$, given as a unitary $P$ that prepares it from the $\\ket{0}$ state. In other words, the result of applying the unitary $P$ to the state $\\ket{0}$ is the $\\ket{\\psi}$ state:\n $$P\\ket{0} = \\ket{\\psi}$$\n\n**Output:** Return true if the given state is an eigenstate of the given unitary, and false otherwise.\n\n<details>\n <summary><b>Need a hint?</b></summary>\n\nThe library operation <code>CheckZero</code> allows you to check whether the state of the given qubit is $\\ket{0}$.\n\n</details>"
8123
+ },
8124
+ "sourceIds": [
8125
+ "phase_estimation__state_eigenvector__Verification.qs",
8126
+ "KatasLibrary.qs"
8127
+ ],
8128
+ "placeholderCode": "namespace Kata {\n operation IsEigenvector(U : Qubit => Unit, P : Qubit => Unit is Adj) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
8129
+ "explainedSolution": {
8130
+ "type": "explained-solution",
8131
+ "items": [
8132
+ {
8133
+ "type": "text-content",
8134
+ "content": "\nA quantum state is an eigenstate of a quantum gate if applying that gate to that state doesn't change it, other than multiply it by a global phase. This means that your solution should probably start by preparing the state $\\ket{\\psi}$ and applying the unitary $U$ to it. How can you check that the state after that is still $\\ket{\\psi}$ (up to a global phase)?\n\nLet's consider what happens if you apply the adjoint of $P$ to the state $\\ket{\\psi}$:\n\n$$P^\\dagger \\ket{\\psi} = P^\\dagger P\\ket{0} = I\\ket{0} = \\ket{0}$$\n\nYou can use this to finish the solution: apply `Adjoint P` to the state you obtained after applying $U$ and check whether the result is $\\ket{0}$ using the library operation `CheckZero`."
8135
+ },
8136
+ {
8137
+ "type": "solution",
8138
+ "id": "phase_estimation__state_eigenvector_solution",
8139
+ "code": "namespace Kata {\n import Microsoft.Quantum.Diagnostics.CheckZero;\n operation IsEigenvector(U : Qubit => Unit, P : Qubit => Unit is Adj) : Bool {\n use q = Qubit();\n P(q);\n U(q);\n Adjoint P(q);\n let ret = CheckZero(q);\n Reset(q);\n return ret;\n }\n}\n"
8140
+ }
8141
+ ]
8142
+ }
8143
+ },
8144
+ {
8145
+ "type": "lesson",
8146
+ "id": "phase_estimation__problem",
8147
+ "title": "Phase Estimation Problem",
8148
+ "items": [
8149
+ {
8150
+ "type": "text-content",
8151
+ "content": "\nThe phase estimation problem is formulated as follows. \n\nYou are given a unitary operator $U$ and its eigenvector $\\ket{\\psi}$. The eigenvector is given as a unitary operator $P$ that, when applied to $\\ket{0}$, results in the state $\\ket{\\psi}$.\n\nYour goal is to find the eigenvalue $\\lambda$ associated with this eigenvector, or, in a more common formulation, the corresponding eigenphase $\\theta$:\n\n$$U\\ket{\\psi} = e^{2 \\pi i \\theta} \\ket{\\psi}, \\theta = ?$$\n\nThe value of $\\theta$ is defined to be between $0$ and $1$, since any value outside of this range has an equivalent value within it. Instead of representing $\\theta$ as a decimal, sometimes it is represented as a binary fraction with $n$ digits:\n\n$$\\theta = 0.\\theta_1 \\theta_2... \\theta_n = \\frac{\\theta_1}{2^1}+ \\frac{\\theta_2}{2^2}+...\\frac{\\theta_n}{2^n}$$\n\nLet's consider a simplified variant of the phase estimation problem, in which you are guaranteed that the phase $\\theta$ has exactly one binary digit, that is, it's either $0$ or $\\frac12$."
8152
+ }
8153
+ ]
8154
+ },
8155
+ {
8156
+ "type": "exercise",
8157
+ "id": "phase_estimation__one_bit_eigenphase",
8158
+ "title": "One-Bit Phase Estimation",
8159
+ "description": {
8160
+ "type": "text-content",
8161
+ "content": "**Inputs:**\n\n1. A single-qubit unitary $U$ that is guaranteed to have an eigenvalue $+1$ or $-1$ \n(with eigenphases $0$ or $\\frac12$, respectively). The unitary will have its controlled variant defined.\n2. A single-qubit state $\\ket{\\psi}$, given as a unitary $P$ that prepares it from the $\\ket{0}$ state. In other words, the result of applying the unitary $P$ to the state $\\ket{0}$ is the $\\ket{\\psi}$ state:\n $$P\\ket{0} = \\ket{\\psi}$$\n\n**Output:** Return the eigenvalue which corresponds to the eigenstate $\\ket{\\psi}$ ($+1$ or $-1$).\n\n<details>\n <summary><b>Need a hint?</b></summary>\n You can do this by allocating exactly two qubits and calling <code>Controlled U<\\code> exactly once.\n</details>"
8162
+ },
8163
+ "sourceIds": [
8164
+ "phase_estimation__one_bit_eigenphase__Verification.qs",
8165
+ "KatasLibrary.qs"
8166
+ ],
8167
+ "placeholderCode": "namespace Kata {\n operation OneBitPhaseEstimation(U : Qubit => Unit is Ctl, P : Qubit => Unit) : Int {\n // Implement your solution here...\n\n return 0;\n }\n}\n",
8168
+ "explainedSolution": {
8169
+ "type": "explained-solution",
8170
+ "items": [
8171
+ {
8172
+ "type": "text-content",
8173
+ "content": "\nWhat happens if you apply the unitary $U$ to the state $\\ket{\\psi}$? You end up in one of the states $\\ket{\\psi}$ or $-\\ket{\\psi}$, depending on whether the eigenvalue is $+1$ or $-1$. You need to distinguish these two scenarios, but they differ by a global phase, so you can't do this using just one qubit.\n\nHowever, if you use the fact that you have access to controlled variant of $U$ and can allocate more than one qubit, you can use a variant of the phase kickback trick to distinguish these scenarios.\n\nIf you apply a controlled $U$ gate to two qubits: the control qubit in the $\\ket{+}$ state and the target qubit in the state $\\ket{\\psi}$, you'll get the following state:\n\n$$CU \\ket{+}\\ket{\\psi} = \\frac1{\\sqrt2}(CU \\ket{0}\\ket{\\psi} + CU \\ket{1}\\ket{\\psi}) = \\frac1{\\sqrt2}(\\ket{0}\\ket{\\psi} + \\ket{1}U\\ket{\\psi}) = $$\n$$= \\frac1{\\sqrt2}(\\ket{0}\\ket{\\psi} + \\ket{1}\\lambda\\ket{\\psi}) = \n\\begin{cases}\n\\ket{+}\\ket{\\psi} \\textrm{ if } \\lambda = 1 \\\\ \n\\ket{-}\\ket{\\psi} \\textrm{ if } \\lambda = -1\n\\end{cases}$$\n\nYou only need to measure the control qubit in the Hadamard basis to figure out whether its state is $\\ket{+}$ or $\\ket{-}$, and you'll be able to tell the value of the eigenvalue $\\lambda$."
8174
+ },
8175
+ {
8176
+ "type": "solution",
8177
+ "id": "phase_estimation__one_bit_eigenphase_solution",
8178
+ "code": "namespace Kata {\n operation OneBitPhaseEstimation(U : Qubit => Unit is Ctl, P : Qubit => Unit) : Int {\n use (control, eigenstate) = (Qubit(), Qubit());\n H(control);\n P(eigenstate);\n Controlled U([control], eigenstate);\n Reset(eigenstate);\n\n return MResetX(control) == Zero ? 1 | -1;\n }\n}\n"
8179
+ }
8180
+ ]
8181
+ }
8182
+ },
8183
+ {
8184
+ "type": "lesson",
8185
+ "id": "phase_estimation__qpe",
8186
+ "title": "Quantum Phase Estimation Algorithm",
8187
+ "items": [
8188
+ {
8189
+ "type": "text-content",
8190
+ "content": "\nThe quantum phase estimation algorithm is the most common algorithm used for estimating the eigenphase that corresponds to the given unitary-eigenvector pair.\nIt relies on the quantum Fourier transform, and allows you to estimate $n$ binary digits of the eigenphase $\\theta$.\nLet's see how this algorithm works.\n\n### Inputs\n\n1. A single-qubit unitary $U$ that acts on $m$ qubits.\n2. An $m$-qubit state $\\ket{\\psi}$ - an eigenvector of $U$.\n3. An integer $n$ that specifies the desired binary precision of the eigenphase estimate.\n\n### The starting state\n\nThe algorithm acts on $n+m$ qubits, split in two registers.\n- The first $n$ qubits start in the state $\\ket{0...0} = \\ket{0}^{\\otimes N}$. These qubits are used to get the eigenvalue.\n- The last $m$ qubits start in the state $\\ket{\\psi}$ - the eigenvector of $U$.\n\n### Step 1. Apply the Hadamard transform to each qubit of the first register\n\nThis step prepares the first qubit in an even superposition of all $n$-qubit basis states, or, equivalently, in an even superposition of all integers from $\\ket{0}$ to $\\ket{2^n-1}$.\n\nThe state of the system will end up being\n\n$$\\frac1{\\sqrt{2^n}}\\sum_{k=0}^{2^n-1} \\ket{k} \\otimes \\ket{\\psi}$$\n\n\n### Step 2. Apply the controlled $U$ ladder\n\nOn this step, the algorithm applies a series of controlled $U$ gates, with different qubits of the first register as controls and the second register as the target.\n\nLet's assume that the first register stores integers in little-endian notation: the first qubit corresponds to the least-significant bit, and the last qubit - to the most-significant bit. Then, the sequence of gates applied on this step looks as follows:\n\n1. Controlled $U$ gate with the first qubit as control.\n2. Controlled $U^2$ gate with the second qubit as control.\n3. Controlled $U^4$ gate with the third qubit as control.\n4. And so on, ending with controlled $U^{2^{n-1}}$ gate with qubit $n$ as control.\n\nWhat does this sequence of gates do?\n\nLet's consider the scenario in which the first register is in the basis state $\\ket{k} = \\ket{k_0} \\otimes \\ket{k_1} \\otimes ... \\otimes \\ket{k_{n-1}}$, where $k$ is an integer with $n$ bits in its binary notation: \n$$k = 2^0k_0 + 2^1 k_1 + 2^2k_2 + ... + 2^{n-1}k_{n-1}$$\n\nIn this case, this sequence of gates will apply the unitary $U^k$ to the second register! Indeed, \n\n1. Controlled $U$ gate with the first qubit as control will apply the $U$ gate if $k_0 = 1$, and do nothing if $k_0 = 0$.\n2. Controlled $U^2$ gate with the second qubit as control will apply the $U^2$ gate if $k_1 = 1$, and do nothing if $k_1 = 0$.\n3. Controlled $U^4$ gate with the third qubit as control will apply the $U^4$ gate if $k_2 = 1$, and do nothing if $k_2 = 0$.\n4. And so on.\n\nYou can see that in the end all the powers of $U$ applied to the second register add up to exactly the number $k$ written in the first register.\n\nIf the first register is in a superposition of states, as is the case for this algorithm, you can write the effect of controlled gates on the state of the system using linearity of unitary transformations:\n\n$$\\frac1{\\sqrt{2^n}}\\sum_{k=0}^{2^n-1} \\ket{k} \\otimes \\ket{\\psi}\\rightarrow \\frac1{\\sqrt{2^n}}\\sum_{k=0}^{2^n-1} \\ket{k} \\otimes U^k\\ket{\\psi}$$\n\nNow, recall that $\\ket{\\psi}$ is an eigenvector of $U$: \n$$U\\ket{\\psi} = e^{2 \\pi i \\theta} \\ket{\\psi}$$\n\nThis means that\n$$U^k\\ket{\\psi} = (e^{2 \\pi i \\theta})^k \\ket{\\psi} = e^{2 \\pi i \\theta \\cdot k} \\ket{\\psi}$$\n\nYou can use this to write the following expression for the state of the system after this step:\n\n$$\\frac1{\\sqrt{2^n}}\\sum_{k=0}^{2^n-1} e^{2 \\pi i \\theta \\cdot k} \\ket{k} \\otimes \\ket{\\psi}$$\n\nNotice that the first and second registers end up not being entangled with each other.\n\n\n### Step 3. Apply the inverse QFT\n\nNow, recall that the quantum Fourier transform that acts on a basis state $\\ket{j}$ that represents an $n$-bit integer $j$ performs the following transformation:\n\n$$\\ket{j} \\rightarrow \\frac1{\\sqrt{2^n}}\\sum_{k=0}^{2^n-1} e^{2\\pi i jk/2^n} \\ket{k} = \\frac1{\\sqrt{2^n}}\\sum_{k=0}^{2^n-1} e^{2\\pi i (j/2^n) \\cdot k} \\ket{k}$$\n\nIf you compare this expression with the state of the first register at the end of the previous step, you'll notice that they match exactly, with $\\theta = j / {2^n}$.\n\nThis means that you can use the inverse Fourier transform (the adjoint of the Fourier transform) to convert the state of the first register to a binary notation of the integer that stores the first $n$ bits of $\\theta$ written as a binary fraction.\nIf $\\theta = 0.\\theta_1 \\theta_2... \\theta_n$, applying the inverse QFT to the first register will yield a state \n\n$$\\ket{j} = \\ket{\\theta_n} \\otimes ... \\otimes \\ket{\\theta_1}$$\n\n(Remember that the previous step assumed that the first register stores the integers in little-endian notation, so you have to use the same notation on this step.)\n\n### Step 4. Measure the first register\n\nOn the last step, you measure the first register, convert the measurement results to an integer, and divide it by $2^n$ to get the eigenphase $\\theta$."
8191
+ }
8192
+ ]
8193
+ },
8194
+ {
8195
+ "type": "exercise",
8196
+ "id": "phase_estimation__implement_qpe",
8197
+ "title": "Implement QPE Algorithm",
8198
+ "description": {
8199
+ "type": "text-content",
8200
+ "content": "**Inputs:**\n\n1. A single-qubit unitary $U$. The unitary will have its controlled variant defined.\n2. A single-qubit state $\\ket{\\psi}$, given as a unitary $P$ that prepares it from the $\\ket{0}$ state. In other words, the result of applying the unitary $P$ to the state $\\ket{0}$ is the $\\ket{\\psi}$ state:\n $$P\\ket{0} = \\ket{\\psi}$$\n3. A positive integer $n$.\n\n**Output:** Return the eigenphase $\\theta$ which corresponds to the eigenstate $\\ket{\\psi}$, multiplied by $2^n$. You are guaranteed that this eigenvalue has at most $n$ digits of binary precision, so multiplying it by $2^n$ yields an integer.\n"
8201
+ },
8202
+ "sourceIds": [
8203
+ "phase_estimation__implement_qpe__Verification.qs",
8204
+ "KatasLibrary.qs"
8205
+ ],
8206
+ "placeholderCode": "namespace Kata {\n operation PhaseEstimation(\n U : Qubit => Unit is Ctl, \n P : Qubit => Unit,\n n : Int\n ) : Int {\n // Implement your solution here...\n\n return 0;\n }\n}\n",
8207
+ "explainedSolution": {
8208
+ "type": "explained-solution",
8209
+ "items": [
8210
+ {
8211
+ "type": "text-content",
8212
+ "content": "\nTo solve this exercise, you need to follow the QPE algorithm as described in this lesson.\n\n1. Allocate two qubit registers, $n$-qubit `phaseRegister` and single-qubit `eigenstate` (this one can be just an individual qubit rather than a qubit array for simplicity).\n2. Prepare the initial state of the algorithm: `eigenstate` in the state $\\ket{\\psi}$ using the unitary $P$ and `phaseRegister` in the state that is an even superposition of all basis states using Hadamard gates.\n3. Apply the controlled $U$ gates using two `for` loops. The outer loop will iterate over the qubits of `phaseRegister`, from the first qubit storing the least significant digit to the last one storing the most significant one. The inner loop will apply controlled $U$ $2^k$ times, where $k$ is the variable used as the outer loop counter.\n4. Apply the adjoint QFT. Here, you can use the library operation `ApplyQFT`, keeping in mind that it applies only the rotations part of the quantum Fourier transform. To implement the complete transform using this operation, you need to reverse the order of qubits in the register after applying `ApplyQFT`. Since here you need to use adjoint QFT, you need to reverse the order of qubits before calling `Adjoint ApplyQFT`.\n5. Measure the qubits in `phaseRegister` and convert the result to an integer. `MeasureInteger` does exactly that for a register in little endian. You also need to reset the qubit used as the eigenstate before releasing it."
8213
+ },
8214
+ {
8215
+ "type": "solution",
8216
+ "id": "phase_estimation__implement_qpe_solution",
8217
+ "code": "namespace Kata {\n operation PhaseEstimation(\n U : Qubit => Unit is Ctl, \n P : Qubit => Unit,\n n : Int\n ) : Int {\n use (phaseRegister, eigenstate) = (Qubit[n], Qubit());\n P(eigenstate);\n ApplyToEach(H, phaseRegister);\n for k in 0 .. n - 1 {\n for _ in 1 .. 1 <<< k {\n Controlled U([phaseRegister[k]], eigenstate);\n }\n }\n SwapReverseRegister(phaseRegister);\n Adjoint ApplyQFT(phaseRegister);\n\n Reset(eigenstate);\n return MeasureInteger(phaseRegister);\n }\n}\n"
8218
+ }
8219
+ ]
8220
+ }
8221
+ },
8222
+ {
8223
+ "type": "lesson",
8224
+ "id": "phase_estimation__practicality",
8225
+ "title": "QPE Algorithm: Practical Considerations",
8226
+ "items": [
8227
+ {
8228
+ "type": "text-content",
8229
+ "content": "\nNow that you've learned to implement the QPE algorithm, let's discuss several practical aspects of its applications.\n\n### Applying QPE to a superposition of eigenvectors\n\nFirst of all, the algorithm inputs include an eigenvector of the unitary for which you want to estimate the eigenphase. In some applications, the eigenvector is either unknown or hard to prepare accurately. Is there a workaround for these scenarios?\n\nTo answer this, let's see what happens if you run the phase estimation algorithm for a state $\\ket{\\phi}$ that is not an eigenstate of the unitary $U$.\n\nFor any unitary $U$, you can find a basis that consists of its eigenvectors. This means that any state $\\ket{\\phi}$ can be represented as a superposition of eigenvectors $\\ket{\\psi_k}$: \n$$\\ket{\\phi} = \\sum_k a_k\\ket{\\psi_k}$$\n\nYou can notice that all the steps of the QPE algorithm until the final measurement are linear transformations. This means that you can apply them to each term in the superposition independently.\n\nThe state of the system right before the final measurement will look as follows:\n\n$$\\sum_k a_k \\ket{j_k} \\ket{\\psi_k}$$\n\nHere $j_k$ is the integer representation of the $n$ binary digits of the eigenphase that corresponds to the eigenvector $\\ket{\\psi_k}$. \n\nNow, when you measure the first register, this measurement will cause the collapse of the superposition: you'll get one of the values $j_k$ that describes one of the eigenphases, and the second register will collapse to the matching eigenvector.\n\nThis means that if you're looking for *any* eigenphase of the unitary, you can just run the QPE algorithm with any state in place of the eigenvector. And if you know the eigenvector you want to use but it's tricky to prepare precisely, you can prepare it approximately and run the QPE algorithm on this state to get the eigenphase associated with it with high probability.\n\n\n### Eigenphases that are not $n$-bit binary fractions\n\nThe algorithm derivation in the previous lesson assumed that the eigenphase $\\theta$ can be written down with exactly $n$ binary bits of precision. However, this is not always the case. What happens if the eigenphase of the given eigenvector can't be written down using exactly $n$ binary bits?\n\nIt turns out that the QPE algorithm running with $n$ bits of precision is deterministic only for eigenphases that can be represented precisely as $n$-bit binary fractions. Running it for any eigenphases that don't have such a representation yields probabilistic results. The outcomes that are the closest $n$-bit fractions to the true eigenphase are produced with the highest probability, but it's also possible to get outcomes that are pretty far away from the true eigenphase.\n\nThe following demo allows you to play with the QPE algorithm for different eigenphases and to observe its behavior in different scenarios.\nFor example, you can see that running phase estimation for the gate `R1Frac(1, 3, _)` which has eigenphase $\\frac1{16} = 0.0625$\nwith $n = 3$ bits of precision yields non-deterministic results, with the two most frequent outcomes being $0$ and $\\frac18 = 0.125$."
8230
+ },
8231
+ {
8232
+ "type": "example",
8233
+ "id": "phase_estimation__e2edemo",
8234
+ "code": "namespace Kata {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation QuantumPhaseEstimationDemo() : Unit {\n // Experiment with the parameters to explore algorithm behavior for different eigenphases!\n // Use R1Frac(k, n, _) for eigenvalue exp(2π𝑖 k/2^(n+1)), eigenphase k/2^(n+1)\n // or R1(theta, _) for eigenvalue exp(2π𝑖 theta/2), eigenphase theta/2\n // Here are some convenient unitaries and their eigenphases\n // R1Frac(1, 0, _) | 0.5\n // R1Frac(1, 1, _) | 0.25\n // R1Frac(1, 2, _) | 0.125\n // R1Frac(1, 3, _) | 0.0625\n let U = R1Frac(1, 3, _);\n let P = X; // |1⟩ basis state is convenient to experiment with R1 and R1Frac gates\n let n = 3;\n mutable counts = [0, size = 2 ^ n];\n for _ in 1 .. 100 {\n let res = PhaseEstimation(U, P, n);\n set counts w/= res <- counts[res] + 1;\n }\n for i in 0 .. 2 ^ n - 1 {\n if counts[i] > 0 {\n Message($\"Eigenphase {IntAsDouble(i) / IntAsDouble(2 ^ n)} - {counts[i]}%\");\n }\n }\n }\n\n operation PhaseEstimation(\n U : Qubit => Unit is Ctl, \n P : Qubit => Unit,\n n : Int\n ) : Int {\n use (phaseRegister, eigenstate) = (Qubit[n], Qubit());\n P(eigenstate);\n ApplyToEach(H, phaseRegister);\n for k in 0 .. n - 1 {\n for _ in 1 .. 1 <<< k {\n Controlled U([phaseRegister[k]], eigenstate);\n } \n }\n SwapReverseRegister(phaseRegister);\n Adjoint ApplyQFT(phaseRegister);\n\n Reset(eigenstate);\n return MeasureInteger(phaseRegister);\n }\n}"
8235
+ }
8236
+ ]
8237
+ },
8238
+ {
8239
+ "type": "lesson",
8240
+ "id": "phase_estimation__conclusion",
8241
+ "title": "Conclusion",
8242
+ "items": [
8243
+ {
8244
+ "type": "text-content",
8245
+ "content": "\nCongratulations! In this kata you learned about the phase estimation problem and its solution using the quantum phase estimation algorithm."
8246
+ }
8247
+ ]
8248
+ }
8249
+ ],
8250
+ "published": true
8251
+ },
7357
8252
  {
7358
8253
  "id": "qec_shor",
7359
8254
  "title": "QEC: Bit Flip, Phase Flip, and Shor Codes",
@@ -7365,7 +8260,7 @@ export default {
7365
8260
  "items": [
7366
8261
  {
7367
8262
  "type": "text-content",
7368
- "content": "\nThis kata introduces you to the basic concepts of quantum error correction using several simple error correction codes.\n\n**This kata covers the following topics:**\n\n- Simple models of noise in quantum systems\n- Parity measurements in Z and X bases\n- Bit flip code - the simplest code that protects qubits from the effects of bit flip noise\n- Phase flip code - the simplest code that protects qubits from the effects of phase flip noise\n- Shor code - the simplest code that can protect from an arbitrary error on a single qubit\n\n**What you should know to start working on this kata:**\n\n- Basic knowledge of single-qubit and multi-qubit gates\n- Basic knowledge of single-qubit and multi-qubit quantum measurements and their effect on quantum systems"
8263
+ "content": "\nThis kata introduces you to the basic concepts of quantum error correction using several simple error correction codes.\n\n**This kata covers the following topics:**\n\n- Simple models of noise in quantum systems\n- Parity measurements in Z and X bases\n- Bit flip code - the simplest code that protects qubits from the effects of bit flip noise\n- Phase flip code - the simplest code that protects qubits from the effects of phase flip noise\n- Shor code - the simplest code that can protect from an arbitrary error on a single qubit\n\n**What you should know to start working on this kata:**\n\n- Basic single-qubit and multi-qubit gates\n- Single-qubit and multi-qubit quantum measurements, and their effect on quantum systems\n\nIf you need a refresher on these topics, you can check out the previous katas."
7369
8264
  }
7370
8265
  ]
7371
8266
  },
@@ -7697,7 +8592,7 @@ export default {
7697
8592
  "items": [
7698
8593
  {
7699
8594
  "type": "text-content",
7700
- "content": "\nThis kata introduces three quantum nonlocal games that display \"quantum pseudo-telepathy\" -\nthe use of quantum entanglement to eliminate the need for classical communication.\nIn this context, \"nonlocal\" means that the playing parties are separated by a great distance,\nso they cannot communicate with each other during the game.\nAnother characteristics of these games is that they are \"refereed\", which means the players try to win against the referee.\n\n**This kata covers the following topics:**\n - Clauser, Horne, Shimony, and Hold thought experiment (often abbreviated as CHSH game)\n - Greenberger-Horne-Zeilinger game (often abbreviated as GHZ game)\n - The Mermin-Peres Magic Square game\n\n**What you should know to start working on this kata:**\n - Basic linear algebra\n - Basic knowledge of quantum gates and measurements"
8595
+ "content": "\nThis kata introduces three quantum nonlocal games that display \"quantum pseudo-telepathy\" -\nthe use of quantum entanglement to eliminate the need for classical communication.\nIn this context, \"nonlocal\" means that the playing parties are separated by a great distance,\nso they cannot communicate with each other during the game.\nAnother characteristics of these games is that they are \"refereed\", which means the players try to win against the referee.\n\n**This kata covers the following topics:**\n\n- Clauser, Horne, Shimony, and Hold thought experiment (often abbreviated as CHSH game)\n- Greenberger-Horne-Zeilinger game (often abbreviated as GHZ game)\n- The Mermin-Peres Magic Square game\n\n**What you should know to start working on this kata:**\n\n- Basic linear algebra\n- Basic knowledge of quantum gates and measurements"
7701
8596
  }
7702
8597
  ]
7703
8598
  },
@@ -7708,18 +8603,7 @@ export default {
7708
8603
  "items": [
7709
8604
  {
7710
8605
  "type": "text-content",
7711
- "content": "\nIn **CHSH Game**, two players (Alice and Bob) try to win the following game:\n\nEach of them is given a bit (Alice gets X and Bob gets Y), and\nthey have to return new bits (Alice returns A and Bob returns B)\nso that X Y = A B. The trick is, they can not communicate during the game.\n\n> * is the standard bitwise AND operator.\n> * is the exclusive or, or XOR operator, so (P Q) is true if exactly one of P and Q is true."
7712
- }
7713
- ]
7714
- },
7715
- {
7716
- "type": "lesson",
7717
- "id": "nonlocal_games__chsh_game_classical",
7718
- "title": "Part I. Classical CHSH",
7719
- "items": [
7720
- {
7721
- "type": "text-content",
7722
- "content": "\nTo start with, let's take a look at how you would play the classical variant of this game without access to any quantum tools."
8606
+ "content": "\nIn **CHSH Game**, two players (Alice and Bob) try to win the following game:\n\nEach of them is given a bit (Alice gets X and Bob gets Y), and\nthey have to return new bits (Alice returns A and Bob returns B)\nso that X $\\land$ Y = A $\\oplus$ B. The trick is, they can not communicate during the game.\n\n> - $\\land$ is the standard bitwise AND operator.\n> - $\\oplus$ is the exclusive or, or XOR operator, so (P $\\oplus$ Q) is true if exactly one of P and Q is true.\n\nTo start with, let's take a look at how you would play the classical variant of this game without access to any quantum tools.\nThen, let's proceed with quantum strategies for Alice and Bob."
7723
8607
  }
7724
8608
  ]
7725
8609
  },
@@ -7729,7 +8613,7 @@ export default {
7729
8613
  "title": "Win Condition",
7730
8614
  "description": {
7731
8615
  "type": "text-content",
7732
- "content": "**Input:** \n* Alice and Bob's starting bits (X and Y).\n* Alice and Bob's output bits (A and B).\n\n**Output:**\n True if Alice and Bob won the CHSH game, that is, if X Y = A B, and false otherwise.\n\n"
8616
+ "content": "**Inputs:** \n\n- Alice and Bob's starting bits (X and Y).\n- Alice and Bob's output bits (A and B).\n\n**Output:**\n True if Alice and Bob won the CHSH game, that is, if X $\\land$ Y = A $\\oplus$ B, and false otherwise.\n\n"
7733
8617
  },
7734
8618
  "sourceIds": [
7735
8619
  "nonlocal_games__chsh_classical_win_condition__Verification.qs",
@@ -7741,7 +8625,7 @@ export default {
7741
8625
  "items": [
7742
8626
  {
7743
8627
  "type": "text-content",
7744
- "content": "\nThere are four input pairs (X, Y) possible, (0,0), (0,1), (1,0), and (1,1), each with 25% probability.\nIn order to win, Alice and Bob have to output different bits if the input is (1,1), and same bits otherwise.\n\nTo check whether the win condition holds, you need to compute $x y$ and $a b$ and to compare these values: if they are equal, Alice and Bob won. You can compute these values using [built-in operators](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions): $x y$ as `x and y` and $a b$ as `a != b`."
8628
+ "content": "\nThere are four input pairs (X, Y) possible, (0,0), (0,1), (1,0), and (1,1), each with $25\\%$ probability.\nIn order to win, Alice and Bob have to output different bits if the input is (1,1), and same bits otherwise.\n\nTo check whether the win condition holds, you need to compute X $\\land$ Y and A $\\oplus$ B and to compare these values:\nif they are equal, Alice and Bob won. You can compute these values using\n[built-in operators](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions):\nX $\\land$ Y as `x and y` and A $\\oplus$ B as `a != b`."
7745
8629
  },
7746
8630
  {
7747
8631
  "type": "solution",
@@ -7769,7 +8653,7 @@ export default {
7769
8653
  "items": [
7770
8654
  {
7771
8655
  "type": "text-content",
7772
- "content": "\nIf Alice and Bob always return TRUE, they will have a 75% win rate, since TRUE TRUE = FALSE, and the AND operation on their input bits will be FALSE with 75% probability.\nAlternatively, Alice and Bob could agree to always return FALSE to achieve the same 75% win probability. A classical strategy cannot achieve a higher success probability."
8656
+ "content": "\nIf Alice and Bob always return TRUE, they will have a $75\\%$ win rate, since TRUE $\\oplus$ TRUE == FALSE, and the AND operation on their input bits will be FALSE with $75\\%$ probability.\nAlternatively, Alice and Bob could agree to always return FALSE to achieve the same $75\\%$ win probability. A classical strategy cannot achieve a higher success probability."
7773
8657
  },
7774
8658
  {
7775
8659
  "type": "solution",
@@ -7779,6 +8663,184 @@ export default {
7779
8663
  ]
7780
8664
  }
7781
8665
  },
8666
+ {
8667
+ "type": "exercise",
8668
+ "id": "nonlocal_games__chsh_quantum_alice_strategy",
8669
+ "title": "Alice's Quantum Strategy",
8670
+ "description": {
8671
+ "type": "text-content",
8672
+ "content": "In the quantum version of the game, the players still can not communicate during the game,\nbut they are allowed to share qubits from a Bell pair before the start of the game.\n\n**Inputs:**\n\n- Alice's starting bit (X).\n- Alice's half of Bell pair she shares with Bob.\n\n**Goal:**\n Measure Alice's qubit in the Z basis if her bit is 0 (false), or the X basis if her bit is 1 (true) and\n return the measurement result as Boolean value: map `Zero` to false and `One` to true.\n The state of the qubit after the operation does not matter.\n"
8673
+ },
8674
+ "sourceIds": [
8675
+ "nonlocal_games__chsh_quantum_alice_strategy__Verification.qs",
8676
+ "KatasLibrary.qs"
8677
+ ],
8678
+ "placeholderCode": "namespace Kata {\n operation AliceQuantum (bit : Bool, qubit : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
8679
+ "explainedSolution": {
8680
+ "type": "explained-solution",
8681
+ "items": [
8682
+ {
8683
+ "type": "text-content",
8684
+ "content": "\nIn Q#, you can perform measurements in a specific basis using either the\n[Measure operation](https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.intrinsic/measure)\nor convenient shorthands for measure-and-reset-to-$\\ket{0}$ sequence of operations\n[MResetZ](https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.measurement/mresetz) and\n[MResetX](https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.measurement/mresetx).\n\n(See the the lesson below for details on why Alice should follow this strategy.)"
8685
+ },
8686
+ {
8687
+ "type": "solution",
8688
+ "id": "nonlocal_games__chsh_quantum_alice_strategy_solution",
8689
+ "code": "namespace Kata {\n operation AliceQuantum (bit : Bool, qubit : Qubit) : Bool {\n if bit {\n let q = MResetX(qubit);\n return q == One;\n }\n else {\n let q = MResetZ(qubit);\n return q == One;\n }\n }\n}\n"
8690
+ }
8691
+ ]
8692
+ }
8693
+ },
8694
+ {
8695
+ "type": "exercise",
8696
+ "id": "nonlocal_games__chsh_quantum_bob_strategy",
8697
+ "title": "Bob's Quantum Strategy",
8698
+ "description": {
8699
+ "type": "text-content",
8700
+ "content": "**Inputs:**\n\n- Bob's starting bit (Y).\n- Bob's half of Bell pair he shares with Alice.\n\n**Goal:**\nMeasure Bob's qubit in the $\\frac{\\pi}{8}$ basis if his bit is 0 (false), or the $-\\frac{\\pi}{8}$ basis\nif his bit is 1 (true) and return the measurement result as a Boolean value: map `Zero` to false and `One` to true.\nThe state of the qubit after the operation does not matter.\n\nMeasuring a qubit in the $\\theta$ basis is the same as rotating the qubit by $\\theta$, clockwise, and then making a standard measurement in the Z basis.\n"
8701
+ },
8702
+ "sourceIds": [
8703
+ "nonlocal_games__chsh_quantum_bob_strategy__Verification.qs",
8704
+ "KatasLibrary.qs"
8705
+ ],
8706
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n operation BobQuantum (bit : Bool, qubit : Qubit) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
8707
+ "explainedSolution": {
8708
+ "type": "explained-solution",
8709
+ "items": [
8710
+ {
8711
+ "type": "text-content",
8712
+ "content": "\nA suitable $R_y$ rotation can be used to go from the computational basis $\\{ \\ket{0}, \\ket{1} \\}$ to the $\\{ \\ket{\\psi_+}, \\ket{\\psi_-} \\}$ basis and vice versa.\n\nTo implement the described transformation in Q#, we need to rotate the qubit by $\\frac{\\pi}{8}$ clockwise if `bit == false` or counterclockwise if `bit == true` and then perform a measurement.\nWe can do the rotation using the $R_y$ gate (note the negation of the Boolean parameter we need to do).\n\n(See the lesson below for details on why Bob should follow this strategy.)"
8713
+ },
8714
+ {
8715
+ "type": "solution",
8716
+ "id": "nonlocal_games__chsh_quantum_bob_strategy_solution",
8717
+ "code": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n operation BobQuantum (bit : Bool, qubit : Qubit) : Bool {\n let angle = 2.0 * PI() / 8.0;\n Ry(not bit ? -angle | angle, qubit);\n return M(qubit) == One;\n }\n}\n"
8718
+ }
8719
+ ]
8720
+ }
8721
+ },
8722
+ {
8723
+ "type": "lesson",
8724
+ "id": "nonlocal_games__discussion",
8725
+ "title": "Discussion: Probability of Victory for Quantum Strategy",
8726
+ "items": [
8727
+ {
8728
+ "type": "text-content",
8729
+ "content": "\nThe above quantum strategy adopted by Alice and Bob offers a win rate of $\\frac{2 + \\sqrt{2}}{4}$, or about $85.36\\%$. Let's see why this is the case.\n\nFirst, consider the outcome if Alice and Bob simply measure their qubits in the Z basis without manipulating them at all. Because of the entanglement inherent to the Bell state they hold, their measurements will always agree (i.e., both true or both false).\nThis will suffice for victory in the three scenarios (0,0), (0,1) and (1,0) and fail for (1,1), so their win probability is $75\\%$, the same as that for the straightforward classical strategies of invariably returning both true or both false.\n\nNow let's analyze the optimal quantum strategy.\n\n> As a reminder, probability \"wavefunction\" for a two-qubit state is given by the following length-4 vector of amplitudes:\n> $$\\begin{bmatrix}\\psi_{00}\\\\\\psi_{01}\\\\\\psi_{10}\\\\\\psi_{11}\\end{bmatrix}$$\n> $|\\psi_{ij}|^2$ gives the probability of observing the corresponding basis state $\\ket{ij}$ upon measuring the qubit pair.\n\nThe initial state $\\ket{00}$ has $\\psi_{00} = 1$ and $\\psi_{01} = \\psi_{10} = \\psi_{11} = 0$.\nThe Bell state we prepare as the first step of the game has an amplitude vector as follows (we'll use decimal approximations for matrix elements):\n\n$$\\begin{bmatrix}1/\\sqrt{2}\\\\0\\\\0\\\\1/\\sqrt{2}\\end{bmatrix} = \\begin{bmatrix}0.7071\\\\0\\\\0\\\\0.7071\\end{bmatrix}$$\n\nLet's analyze the probabilities of outcomes in case of different bits received by players.\n\n## Case 1: Alice holds bit 0\n\nIn this case Alice simply measures in the Z basis as above.\n\n- When Bob's bit is 0, he rotates his qubit clockwise by $\\pi/8$, which corresponds to the operator\n\n$$\\begin{bmatrix}\n 0.9239 & 0.3827 & 0 & 0\\\\\n -0.3827 & 0.9239 & 0 & 0\\\\\n 0 & 0 & 0.9239 & 0.3827\\\\\n 0 & 0 & -0.3827 & 0.9239\n\\end{bmatrix}$$\nThis performs the $R_y$ rotation by $\\pi/8$ radians clockwise on Bob's qubit while leaving Alice's qubit unchanged.\n\n- If Bob's bit were 1, he would rotate his qubit counterclockwise by $\\pi/8$, applying a very similar operator\n\n$$\\begin{bmatrix}\n 0.9239 & -0.3827 & 0 & 0\\\\\n 0.3827 & 0.9239 & 0 & 0\\\\\n 0 & 0 & 0.9239 & -0.3827\\\\\n 0 & 0 & 0.3827 & 0.9239\n\\end{bmatrix}$$\n\nTherefore, when Alice has bit 0, the application of the rotation operator to the Bell state gives\n$$\\begin{bmatrix}\n 0.6533 \\\\\n -0.2706 \\\\\n 0.2706 \\\\\n 0.6533\n\\end{bmatrix} \\text{ or }\n\\begin{bmatrix}\n 0.6533\\\\\n 0.2706\\\\\n -0.2706\\\\\n 0.6533\n\\end{bmatrix}$$\ndepending on whether Bob holds 0 (left-hand case) or 1 (right-hand case).\n\nThe result of AND on their input bits will always be 0; thus they win when their outputs agree. These two cases correspond to the top and bottom elements of the vectors above, with a combined probability of $(0.6533)^2 + (0.6533)^2 = 0.4268 + 0.4268 = 0.8536$, so they have an $85.36\\%$ win chance.\n\n## Case 2: Alice holds bit 1\n\nWhen Alice holds bit 1, she measures in basis X (or, equivalently, Hadamard-transforms her qubit, leaving Bob's qubit unchanged,\nbefore making her Z-basis measurement). This corresponds to applying the operator\n$$\\begin{bmatrix}\n 0.7071 & 0 & 0.7071 & 0\\\\\n 0 & 0.7071 & 0 & 0.7071\\\\\n 0.7071 & 0 & -0.7071 & 0\\\\\n 0 & 0.7071 & 0 & -0.7071\n\\end{bmatrix}$$\nto the Bell state, resulting in a vector of:\n$$\\begin{bmatrix}\n 0.5\\\\\n 0.5\\\\\n 0.5\\\\\n -0.5\n\\end{bmatrix}$$\n\nNow, one of the two rotation operators is applied depending on what bit Bob holds, transforming this vector into:\n$$\\begin{bmatrix}\n 0.6533 \\\\\n 0.2706 \\\\\n 0.2706 \\\\\n -0.6533\n\\end{bmatrix} \\text{ or }\n\\begin{bmatrix}\n 0.2706\\\\\n 0.6533\\\\\n 0.6533\\\\\n -0.2706\n \\end{bmatrix}$$\n\nWhen Bob holds 0, they still want to return the same parity, which they again do with $85.36\\%$ probability (left-hand vector above).\nBut when Bob holds 1, the AND condition is now true and the players want to answer in opposite parity. This corresponds to the second and third elements of the right-hand vector above.\nThanks to the \"magic\" of the combination of the counterclockwise rotation and Hadamard transform, they now do this with probability $(0.6533)^2 + (0.6533)^2 = 0.8536$ and thus $85.36\\%$ becomes their win odds once more.\n\n## Side notes\n\n- If Bob never rotated his qubit, their entangled state would remain the Bell state if Alice held bit 0 and the state corresponding to $\\frac12 \\big(\\ket{00} + \\ket{01} + \\ket{10} - \\ket{11}\\big)$ if Alice held bit 1.\nWhile she and Bob would have a $100\\%$ success probability against Alice's 0 bit, they would have only a $50\\%$ chance of success if she held bit 1, and thus their win chance would revert to the $75\\%$ of the classical strategy again.\n- It can be proven that Alice and Bob cannot surpass an overall win probability of $85.36\\%$ in the CHSH game. This entails a higher-level discussion of quantum observable theory, for instance see [Tsirelson's bound](https://en.wikipedia.org/wiki/Tsirelson's_bound)."
8730
+ }
8731
+ ]
8732
+ },
8733
+ {
8734
+ "type": "lesson",
8735
+ "id": "nonlocal_games__chsh_e2e",
8736
+ "title": "Running CHSH Game End to End",
8737
+ "items": [
8738
+ {
8739
+ "type": "text-content",
8740
+ "content": "\nPutting together the building blocks we've implemented into a strategy is very simple:\n- Allocate two qubits and prepare a Bell state on them.\n- Send one of the qubits to Alice and another to Bob (this step is \"virtual\", not directly reflected in Q# code, other than making sure that Alice and Bob each act on their qubit only).\n- Have Alice and Bob perform their measurements on their respective qubits using `AliceQuantum` and `BobQuantum` operations.\n- Reset used qubits to $\\ket{0}$ before they are released.\n- Return their measurement results.\n\nIn the example below you can compare winning percentage of classical and quantum games.\n\n>You may play with the code and check if there is a difference in results when\n>1. The referee picks non-random bits. How can the referee minimize Alice and Bob's win probability?\n>2. Bob's qubit is measured first.\n>3. Alice and Bob get unentangled qubit pair."
8741
+ },
8742
+ {
8743
+ "type": "example",
8744
+ "id": "nonlocal_games__chsh_e2edemo",
8745
+ "code": "namespace Quantum.Kata.CHSHGame {\n open Microsoft.Quantum.Random;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Convert;\n\n function WinCondition (x : Bool, y : Bool, a : Bool, b : Bool) : Bool {\n return (x and y) == (a != b);\n }\n\n function AliceClassical (x : Bool) : Bool {\n return false;\n }\n\n function BobClassical (y : Bool) : Bool {\n return false;\n }\n\n operation AliceQuantum (bit : Bool, qubit : Qubit) : Bool {\n if bit {\n return MResetX(qubit) == One;\n }\n return MResetZ(qubit) == One;\n }\n\n operation BobQuantum (bit : Bool, qubit : Qubit) : Bool {\n let angle = 2.0 * PI() / 8.0;\n Ry(not bit ? -angle | angle, qubit);\n return M(qubit) == One;\n }\n\n @EntryPoint()\n operation CHSH_GameDemo() : Unit {\n use (aliceQubit, bobQubit) = (Qubit(), Qubit());\n mutable classicalWins = 0;\n mutable quantumWins = 0;\n let iterations = 1000;\n for _ in 1 .. iterations {\n H(aliceQubit);\n CNOT(aliceQubit, bobQubit);\n let (x, y) = (DrawRandomBool(0.5), DrawRandomBool(0.5));\n if WinCondition(x, y, AliceClassical(x), BobClassical(y)) {\n set classicalWins += 1;\n }\n if WinCondition(x, y, AliceQuantum(x, aliceQubit), BobQuantum(y, bobQubit)) {\n set quantumWins += 1;\n }\n ResetAll([aliceQubit, bobQubit]);\n }\n Message($\"Percentage of classical wins is {100.0*IntAsDouble(classicalWins)/IntAsDouble(iterations)}%\");\n Message($\"Percentage of quantum wins is {100.0*IntAsDouble(quantumWins)/IntAsDouble(iterations)}%\");\n }\n}\n"
8746
+ }
8747
+ ]
8748
+ },
8749
+ {
8750
+ "type": "lesson",
8751
+ "id": "nonlocal_games__ghz_game",
8752
+ "title": "GHZ Game",
8753
+ "items": [
8754
+ {
8755
+ "type": "text-content",
8756
+ "content": "\nIn **GHZ Game** three players (Alice, Bob and Charlie) try to win the following game:\n\nEach of them is given a bit (R, S and T respectively), and they have to return new bits (A, B and C respectively) so that \nR $\\lor$ S $\\lor$ T = A $\\oplus$ B $\\oplus$ C.\nThe input bits will have zero or two bits set to true and three or one bits set to false. \nThe players are free to share information (and even qubits!) before the game starts, but are forbidden from communicating\nwith each other afterwards.\n\n> - $\\lor$ is the standard bitwise OR operator.\n> - $\\oplus$ is the exclusive or, or XOR operator, so (P $\\oplus$ Q) is true if exactly one of P and Q is true.\n\nTo start with, take a look at how you would play the classical variant of this game without access to any quantum tools.\nThen, let's proceed with quantum strategy and game implementation."
8757
+ }
8758
+ ]
8759
+ },
8760
+ {
8761
+ "type": "exercise",
8762
+ "id": "nonlocal_games__ghz_win_condition",
8763
+ "title": "Win Condition",
8764
+ "description": {
8765
+ "type": "text-content",
8766
+ "content": "**Inputs:**\n\n1. Alice, Bob and Charlie's input bits (r, s and t), stored as an array of length 3.\n The input bits will have zero or two bits set to true.\n2. Alice, Bob and Charlie's output bits (a, b and c), stored as an array of length 3.\n\n**Goal:**\n\nTrue if Alice, Bob and Charlie won the GHZ game, that is, if R $\\lor$ S $\\lor$ T = A $\\oplus$ B $\\oplus$ C, and false otherwise.\n"
8767
+ },
8768
+ "sourceIds": [
8769
+ "nonlocal_games__ghz_win_condition__Verification.qs",
8770
+ "KatasLibrary.qs"
8771
+ ],
8772
+ "placeholderCode": "namespace Kata {\n function WinCondition (rst : Bool[], abc : Bool[]) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
8773
+ "explainedSolution": {
8774
+ "type": "explained-solution",
8775
+ "items": [
8776
+ {
8777
+ "type": "text-content",
8778
+ "content": "\nThere are four inputs possible, (0,0,0), (0,1,1), (1,0,1), and (1,1,0), each with $25\\%$ probability.\nTherefore, in order to win, the sum of the output bits has to be even if the input is (0,0,0) and odd otherwise.\n\nTo check whether the win condition holds, you need to compute the expressions R $\\lor$ S $\\lor$ T and A $\\oplus$ B $\\oplus$ C and to compare them:\nif they are equal, the game is won. To compute the expressions, you can use [built-in operators](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions):\nX $\\lor$ Y as `x or y` and A $\\oplus$ B as `a != b`."
8779
+ },
8780
+ {
8781
+ "type": "solution",
8782
+ "id": "nonlocal_games__ghz_win_condition_solution",
8783
+ "code": "namespace Kata {\n function WinCondition (rst : Bool[], abc : Bool[]) : Bool {\n return (rst[0] or rst[1] or rst[2]) == (abc[0] != abc[1] != abc[2]);\n }\n}\n"
8784
+ }
8785
+ ]
8786
+ }
8787
+ },
8788
+ {
8789
+ "type": "exercise",
8790
+ "id": "nonlocal_games__ghz_classical_strategy",
8791
+ "title": "Classical Strategy",
8792
+ "description": {
8793
+ "type": "text-content",
8794
+ "content": "In this task you have to implement three functions, one for each player's classical strategy.\nNote that they are covered by one test, so you have to implement all of them to pass the test.\nIn each function, the input is the starting bit of the corresponding player, and it should return the output bit chosen by that player.\n\n**Input:**\n\nAlice, Bob, and Charlie's starting bits (R, S, and T).\n\n**Output:**\n\nAlice, Bob, and Charlie's output bits (A, B, and C) to maximize their chance of winning.\n"
8795
+ },
8796
+ "sourceIds": [
8797
+ "nonlocal_games__ghz_classical_strategy__Verification.qs",
8798
+ "KatasLibrary.qs"
8799
+ ],
8800
+ "placeholderCode": "namespace Kata {\n operation AliceClassical (r : Bool) : Bool {\n // Implement your solution here...\n\n return false;\n }\n\n operation BobClassical (s : Bool) : Bool {\n // Implement your solution here...\n\n return false;\n }\n\n operation CharlieClassical (t : Bool) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
8801
+ "explainedSolution": {
8802
+ "type": "explained-solution",
8803
+ "items": [
8804
+ {
8805
+ "type": "text-content",
8806
+ "content": "\nIf all three players return TRUE, then A $\\oplus$ B $\\oplus$ C == TRUE by necessity (since the sum of their bits is odd).\nThis will win against inputs 011, 101, and 110 and lose against 000.\nAnother solution is one player retuns TRUE, and two others return FALSE.\n\nSince the four above inputs have equal probability, and represent all possible inputs,\neither of these deterministic strategies wins with $75\\%$ probability."
8807
+ },
8808
+ {
8809
+ "type": "solution",
8810
+ "id": "nonlocal_games__ghz_classical_strategy_solution",
8811
+ "code": "namespace Kata {\n operation AliceClassical (r : Bool) : Bool {\n return true;\n }\n\n operation BobClassical (s : Bool) : Bool {\n return true;\n }\n\n operation CharlieClassical (t : Bool) : Bool {\n return true;\n }\n}\n\n"
8812
+ }
8813
+ ]
8814
+ }
8815
+ },
8816
+ {
8817
+ "type": "exercise",
8818
+ "id": "nonlocal_games__ghz_classical_game",
8819
+ "title": "Classical GHZ Game",
8820
+ "description": {
8821
+ "type": "text-content",
8822
+ "content": "**Inputs:**\n\n1. An array of three operations which implement the classical strategies of the players (that is, take an input bit and produce an output bit),\n2. An array of 3 input bits that should be passed to the players.\n\n**Output:**\n\nAn array of three bits that will be produced if each player uses their given strategy.\n"
8823
+ },
8824
+ "sourceIds": [
8825
+ "nonlocal_games__ghz_classical_game__Verification.qs",
8826
+ "KatasLibrary.qs"
8827
+ ],
8828
+ "placeholderCode": "namespace Kata {\n operation PlayClassicalGHZ (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] {\n // Implement your solution here...\n\n return [];\n }\n}\n",
8829
+ "explainedSolution": {
8830
+ "type": "explained-solution",
8831
+ "items": [
8832
+ {
8833
+ "type": "text-content",
8834
+ "content": "\nYou are given both the input bits and the strategy each of the players are using, so you have simply to convert them to the output bits and return those."
8835
+ },
8836
+ {
8837
+ "type": "solution",
8838
+ "id": "nonlocal_games__ghz_classical_game_solution",
8839
+ "code": "namespace Kata {\n operation PlayClassicalGHZ (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] {\n let r = inputs[0];\n let s = inputs[1];\n let t = inputs[2];\n let a = strategies[0](r);\n let b = strategies[1](s);\n let c = strategies[2](t);\n return [a, b, c];\n }\n}\n"
8840
+ }
8841
+ ]
8842
+ }
8843
+ },
7782
8844
  {
7783
8845
  "type": "lesson",
7784
8846
  "id": "nonlocal_games__conclusion",
@@ -8149,7 +9211,7 @@ export default {
8149
9211
  },
8150
9212
  {
8151
9213
  "id": "multi_qubit_measurements__state_modification__Verification.qs",
8152
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n\n // State selection using partial measurements\n operation StateInitialize_StateSelection(alpha : Double, qs : Qubit[]) : Unit {\n // Prepare the state to be input to the testImplementation\n // set the second qubit in a superposition a |0⟩ + b|1⟩\n // with a = cos alpha, b = sin alpha\n Ry(2.0 * alpha, qs[1]);\n\n H(qs[0]);\n // Apply CX gate\n CX(qs[0], qs[1]);\n }\n\n // Prepare the expected state of the second qubit for the exercise.\n operation StatePrepare_StateSelection(alpha : Double, ind : Int, q : Qubit) : Unit is Adj {\n // set the second qubit in a superposition a|0⟩ + b|1⟩\n // with a = cos alpha, b = sin alpha\n Ry(2.0 * alpha, q);\n if ind == 1 {\n // change the state to b|0⟩ + a|1⟩\n X(q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n use qs = Qubit[2];\n for i in 0 .. 5 {\n let alpha = (PI() * IntAsDouble(i)) / 5.0;\n let params = $\"a = {Cos(alpha)}, b = {Sin(alpha)}\";\n\n for ind in 0 .. 1 {\n // Prepare the state to be input to the testImplementation\n StateInitialize_StateSelection(alpha, qs);\n\n // operate testImplementation\n Kata.StateSelection(qs, ind);\n // reset the first qubit, since its state does not matter\n Reset(qs[0]);\n\n // apply adjoint reference operation and check that the result is correct\n Adjoint StatePrepare_StateSelection(alpha, ind, qs[1]);\n\n if not CheckAllZero(qs) {\n ResetAll(qs);\n Message(\"Incorrect.\");\n Message($\"The state of the second qubit for {params}, ind = {ind} does not match expectation.\");\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
9214
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n\n // State selection using partial measurements\n operation StateInitialize_StateSelection(alpha : Double, qs : Qubit[]) : Unit {\n // Prepare the state to be input to the testImplementation\n // set the second qubit in a superposition a |0⟩ + b|1⟩\n // with a = cos alpha, b = sin alpha\n Ry(2.0 * alpha, qs[1]);\n\n H(qs[0]);\n // Apply CX gate\n CX(qs[0], qs[1]);\n }\n\n // Prepare the expected state of the second qubit for the exercise.\n operation StatePrepare_StateSelection(alpha : Double, ind : Int, q : Qubit) : Unit is Adj {\n // set the second qubit in a superposition a|0⟩ + b|1⟩\n // with a = cos alpha, b = sin alpha\n Ry(2.0 * alpha, q);\n if ind == 1 {\n // change the state to b|0⟩ + a|1⟩\n X(q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n use qs = Qubit[2];\n for i in 0 .. 5 {\n let alpha = (PI() * IntAsDouble(i)) / 5.0;\n let params = $\"a = {Cos(alpha)}, b = {Sin(alpha)}\";\n\n for ind in 0 .. 1 {\n // Prepare the state to be input to the testImplementation\n StateInitialize_StateSelection(alpha, qs);\n\n Kata.StateSelection(qs, ind);\n\n // Apply adjoint of state preparation operation\n Adjoint StatePrepare_StateSelection(alpha, ind, qs[1]);\n\n // We only care about the state of the second qubit; \n // if it's still entangled with the first one or not in zero state, this check will fail.\n if not CheckZero(qs[1]) {\n ResetAll(qs);\n Message(\"Incorrect.\");\n Message($\"The state of the second qubit for {params}, ind = {ind} does not match expectation.\");\n return false;\n }\n\n Reset(qs[0]);\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
8153
9215
  },
8154
9216
  {
8155
9217
  "id": "multi_qubit_measurements__state_preparation__Verification.qs",
@@ -8583,6 +9645,106 @@ export default {
8583
9645
  "id": "solving_sat__exactly_one_one_formula__Verification.qs",
8584
9646
  "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Random;\n\n function F_Exactly1SATClause (args : Bool[], clause : (Int, Bool)[]) : Bool {\n mutable nOnes = 0;\n for (index, isTrue) in clause {\n if isTrue == args[index] {\n set nOnes += 1;\n }\n }\n return nOnes == 1;\n }\n\n function F_Exactly1SATFormula (args : Bool[], formula : (Int, Bool)[][]) : Bool {\n for clause in formula {\n if not F_Exactly1SATClause(args, clause) {\n return false;\n }\n }\n return true;\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for nVar in 3 .. 6 {\n for _ in 1 .. 3 {\n let formula = GenerateSATInstance(nVar, nVar - 1, 3);\n \n if not CheckOracleImplementsFunction(nVar, Kata.Oracle_Exactly13SATFormula(_, _, formula), F_Exactly1SATFormula(_, formula)) {\n Message($\"Test failed for SAT formula {SATFormulaAsString(formula)}\");\n return false;\n }\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
8585
9647
  },
9648
+ {
9649
+ "id": "solving_graph_coloring__vertex_coloring_classical__Verification.qs",
9650
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Katas;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let testGraphs = ExampleGraphs()[0 .. 4];\n let testColorings = [\n [([0, 0, 0], true), ([2, 1, 3], true)],\n [([0, 2, 1, 3], true), ([3, 0, 1, 2], true), ([0, 2, 1, 0], false)],\n [([0, 1, 2, 3, 4], true), ([0, 2, 1, 0, 3], true), ([1, 0, 1, 2, 1], false), ([0, 0, 0, 0, 0], false)],\n [([0, 1, 0, 2, 1], true), ([0, 2, 0, 1, 3], true), ([0, 1, 0, 1, 2], false)],\n [([1, 2, 3, 1, 2], true), ([1, 2, 3, 4, 1], false)]\n ];\n for ((V, edges), colorings) in Zipped(testGraphs, testColorings) {\n for (coloring, expected) in colorings {\n if Kata.IsVertexColoringValid(V, edges, coloring) != expected {\n Message($\"Coloring {coloring} evaluated incorrectly for graph V = {V}, edges = {edges}: expected {expected}\");\n return false;\n }\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
9651
+ },
9652
+ {
9653
+ "id": "solving_graph_coloring__Common.qs",
9654
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Katas;\n\n // Hardcoded graphs used for testing the vertex coloring problem:\n // - trivial graph with zero edges\n // - complete graph with 4 vertices (4-colorable)\n // - disconnected graph\n // - random connected graph with more edges and vertices (3-colorable)\n // - regular-ish graph with 5 vertices (3-colorable, as shown at https://en.wikipedia.org/wiki/File:3-coloringEx.svg without one vertex)\n // - 6-vertex graph from https://en.wikipedia.org/wiki/File:3-coloringEx.svg\n function ExampleGraphs() : (Int, (Int, Int)[])[] {\n return [(3, []),\n (4, [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]),\n (5, [(4, 0), (2, 1), (3, 1), (3, 2)]),\n (5, [(0, 1), (1, 2), (1, 3), (3, 2), (4, 2), (3, 4)]),\n (5, [(0, 1), (0, 2), (0, 4), (1, 2), (1, 3), (2, 3), (2, 4), (3, 4)]),\n (6, [(0, 1), (0, 2), (0, 4), (0, 5), (1, 2), (1, 3), (1, 5), (2, 3), (2, 4), (3, 4), (3, 5), (4, 5)])];\n // Graphs with 6+ vertices can take several minutes to be processed; \n // in the interest of keeping test runtime reasonable we're limiting most of the testing to graphs with 5 vertices or fewer.\n }\n\n\n function IsVertexColoringValid_Reference (V : Int, edges: (Int, Int)[], colors: Int[]) : Bool {\n for (start, end) in edges {\n if colors[start] == colors[end] {\n return false;\n }\n }\n return true;\n }\n\n\n operation ReadColoring_Reference(nBits : Int, qs : Qubit[]) : Int[] {\n let colorPartitions = Chunks(nBits, qs);\n let measureColor = qs => ResultArrayAsInt(Reversed(MeasureEachZ(qs)));\n return ForEach(measureColor, colorPartitions);\n }\n\n\n // Helper function specific to Graph Coloring kata.\n operation CheckOracleRecognizesColoring (\n V : Int,\n edges : (Int, Int)[],\n oracle : (Int, (Int, Int)[],Qubit[], Qubit) => Unit,\n classicalFunction : (Int, (Int, Int)[], Int[]) -> Bool\n ) : Bool {\n // Message($\"Testing V = {V}, edges = {edges}\");\n let N = 2 * V;\n use (coloringRegister, target) = (Qubit[N], Qubit());\n // Try all possible colorings of 4 colors on V vertices and check if they are calculated correctly.\n // Hack: fix the color of the first vertex, since all colorings are agnostic to the specific colors used.\n for k in 0 .. (1 <<< (N - 2)) - 1 {\n // Prepare k-th coloring\n let binary = [false, false] + IntAsBoolArray(k, N - 2);\n ApplyPauliFromBitString(PauliX, true, binary, coloringRegister);\n\n // Read out the coloring (convert one bitmask into V integers) - does not change the state\n let coloring = ReadColoring_Reference(2, coloringRegister);\n\n // Apply the oracle\n oracle(V, edges, coloringRegister, target);\n\n // Check that the oracle result matches the classical result\n let val = classicalFunction(V, edges, coloring);\n if val {\n X(target);\n }\n // Uncompute\n ApplyPauliFromBitString(PauliX, true, binary, coloringRegister);\n\n if not CheckAllZero(coloringRegister + [target]) {\n Message($\"Incorrect result for V = {V}, edges = {edges}\");\n Message($\"For test case with input = {BoolArrayAsKetState(binary)}, coloring = {coloring}\");\n if not CheckZero(target) {\n Message($\"Expected answer = {val}, got {not val}\");\n } else {\n Message(\"The input state should not change\");\n }\n ResetAll(coloringRegister + [target]);\n return false;\n }\n }\n\n true\n }\n\n function IsWeakColoringValid_OneVertex_Reference (V : Int, edges: (Int, Int)[], colors: Int[], vertex : Int) : Bool {\n mutable neighborCount = 0;\n mutable hasDifferentNeighbor = false;\n\n for (start, end) in edges {\n if start == vertex or end == vertex {\n set neighborCount += 1;\n if colors[start] != colors[end] {\n set hasDifferentNeighbor = true;\n }\n }\n }\n\n return neighborCount == 0 or hasDifferentNeighbor;\n }\n\n function IsWeakColoringValid_Reference (V : Int, edges: (Int, Int)[], colors: Int[]) : Bool {\n for v in 0 .. V - 1 {\n if not IsWeakColoringValid_OneVertex_Reference(V, edges, colors, v) {\n return false;\n }\n }\n\n return true;\n }\n\n}"
9655
+ },
9656
+ {
9657
+ "id": "solving_graph_coloring__read_coloring__Verification.qs",
9658
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for nBits in 1..3 {\n for V in 1..3 {\n use qs = Qubit[V * nBits];\n for state in 0..(1 <<< (V * nBits)) - 1 {\n // Prepare the register in the input state\n let binaryState = IntAsBoolArray(state, V * nBits);\n ApplyPauliFromBitString(PauliX, true, binaryState, qs);\n\n // Call the solution\n let result = Kata.ReadColoring(nBits, qs);\n\n // verify that the register remained in the same state\n ApplyPauliFromBitString(PauliX, true, binaryState, qs);\n if not CheckAllZero(qs) {\n Message(\"The input state should not change\");\n ResetAll(qs);\n return false;\n }\n\n // Get the expected coloring by splitting binaryState into parts and converting them into integers\n // (remember to use big endian)\n let partitions = Chunks(nBits, binaryState);\n let partitionToInt = bits -> BoolArrayAsInt(Reversed(bits));\n let expectedColors = Mapped(partitionToInt, partitions);\n\n // Verify the return value\n if Length(result) != V {\n Message($\"Unexpected number of colors for V = {V}, nBits = {nBits} : {Length(result)}\");\n return false;\n }\n for (expected, actual) in Zipped(expectedColors, result) {\n if expected != actual {\n Message($\"Unexpected colors for V = {V}, nBits = {nBits}, \" + \n $\"state = {BoolArrayAsKetState(binaryState)} : expected {expectedColors}, got {result}\");\n return false;\n }\n }\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
9659
+ },
9660
+ {
9661
+ "id": "solving_graph_coloring__color_equality__Verification.qs",
9662
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Arrays;\n\n function F_ColorEquality(args : Bool[]) : Bool {\n // Check that the first half equals the second half\n let nBits = Length(args) / 2;\n for (f, s) in Zipped(args[...nBits - 1], args[nBits...]) {\n if f != s {\n return false;\n }\n }\n return true;\n }\n\n operation Oracle_ColorEquality_Wrapper(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n let nBits = Length(x) / 2;\n Kata.Oracle_ColorEquality(x[...nBits - 1], x[nBits...], y);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for nBits in 1..3 {\n if not CheckOracleImplementsFunction(2 * nBits, Oracle_ColorEquality_Wrapper, F_ColorEquality) {\n Message($\"Test failed for nBits = {nBits}\");\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
9663
+ },
9664
+ {
9665
+ "id": "solving_graph_coloring__vertex_coloring__Verification.qs",
9666
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Katas;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for (V, edges) in Most(ExampleGraphs()) {\n if not CheckOracleRecognizesColoring(V, edges, Kata.Oracle_VertexColoring, IsVertexColoringValid_Reference) {\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
9667
+ },
9668
+ {
9669
+ "id": "solving_graph_coloring__weak_coloring_classical__Verification.qs",
9670
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Katas;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let testGraphs = ExampleGraphs()[0 .. 4];\n let testColorings = [\n // Every coloring would pass on a disconnected graph of 3 vertices\n [([0, 0, 0], true), ([2, 1, 3], true)],\n // Every coloring would pass on a fully connected graph of 4 vertices,\n // except for the last coloring in which all vertices are of the same color.\n [([0, 2, 1, 3], true), ([3, 0, 1, 0], true), ([0, 0, 0, 0], false)],\n // The colorings for 5-vertex graphs:\n // - the first one is invalid for all graphs except disconnected\n // - the second one is valid for all types of graphs regardless of their structure\n // - two colorings that is valid or invalid depending on the graph\n [([0, 0, 0, 0, 0], false), ([0, 1, 2, 3, 4], true), ([0, 1, 1, 2, 0], false), ([0, 0, 1, 1, 1], true)],\n [([0, 0, 0, 0, 0], false), ([0, 1, 2, 3, 4], true), ([0, 1, 1, 2, 0], true), ([0, 0, 1, 1, 1], false)],\n [([0, 0, 0, 0, 0], false), ([0, 1, 2, 3, 4], true), ([0, 1, 1, 2, 0], true), ([0, 0, 1, 1, 1], true)]\n ];\n for ((V, edges), colorings) in Zipped(testGraphs, testColorings) {\n for (coloring, expected) in colorings {\n if Kata.IsWeakColoringValid(V, edges, coloring) != expected {\n Message($\"Weak coloring {coloring} evaluated incorrectly for graph V = {V}, edges = {edges}: expected {expected}\");\n return false;\n }\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
9671
+ },
9672
+ {
9673
+ "id": "solving_graph_coloring__weak_coloring_one_vertex__Verification.qs",
9674
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Katas;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for (V, edges) in Most(ExampleGraphs()) {\n for vertex in 0 .. V - 1 {\n if not CheckOracleRecognizesColoring(V, edges, \n Kata.Oracle_WeakColoring_OneVertex(_, _, _, _, vertex), \n IsWeakColoringValid_OneVertex_Reference(_, _, _, vertex)\n ) {\n Message($\"Testing vertex {vertex}\");\n return false;\n }\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
9675
+ },
9676
+ {
9677
+ "id": "solving_graph_coloring__weak_coloring__Verification.qs",
9678
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Katas;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for (V, edges) in Most(ExampleGraphs()) {\n if not CheckOracleRecognizesColoring(V, edges, \n Kata.Oracle_WeakColoring, IsWeakColoringValid_Reference\n ) {\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
9679
+ },
9680
+ {
9681
+ "id": "qft__single_qubit__Verification.qs",
9682
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let solution = qs => Kata.SingleQubitQFT(qs[0]);\n let reference = qs => H(qs[0]);\n let isCorrect = CheckOperationsAreEqualStrict(1, solution, reference);\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"
9683
+ },
9684
+ {
9685
+ "id": "qft__rotation_gate__Verification.qs",
9686
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for k in 0 .. 10 {\n let solution = qs => Kata.Rotation(qs[0], k);\n let reference = qs => R1Frac(2, k, qs[0]);\n if not CheckOperationsAreEqualStrict(1, solution, reference) {\n Message($\"Incorrect for k = {k}.\");\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"
9687
+ },
9688
+ {
9689
+ "id": "qft__binary_fraction_classical__Verification.qs",
9690
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation BinaryFractionClassical_Alternative (q : Qubit, j : Bool[]) : Unit is Adj+Ctl {\n // Convert the number to an integer and apply a single R1 rotation\n R1(2.0 * PI() * IntAsDouble(BoolArrayAsInt(Reversed(j))) / IntAsDouble(1 <<< Length(j)), q);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for n in 1 .. 5 {\n for exp in 0 .. (1 <<< n) - 1 {\n let j = Reversed(IntAsBoolArray(exp, n));\n let solution = qs => Kata.BinaryFractionClassical(qs[0], j);\n let reference = qs => BinaryFractionClassical_Alternative(qs[0], j);\n if not CheckOperationsAreEqualStrict(1, solution, reference) {\n Message($\"Incorrect for j = {j}.\");\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\n Message(\"Correct!\");\n true\n }\n}\n"
9691
+ },
9692
+ {
9693
+ "id": "qft__binary_fraction_quantum__Verification.qs",
9694
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation BinaryFractionQuantum_Reference(q : Qubit, j : Qubit[]) : Unit is Adj + Ctl {\n for ind in 0 .. Length(j) - 1 {\n Controlled R1Frac([j[ind]], (2, ind + 1, q));\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for n in 1 .. 5 {\n let solution = qs => Kata.BinaryFractionQuantum(qs[0], qs[1 ...]);\n let reference = qs => BinaryFractionQuantum_Reference(qs[0], qs[1 ...]);\n if not CheckOperationsAreEqualStrict(n + 1, solution, reference) {\n Message($\"Incorrect for n = {n}.\");\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
9695
+ },
9696
+ {
9697
+ "id": "qft__binary_fraction_inplace__Verification.qs",
9698
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation BinaryFractionQuantumInPlace_Reference(j : Qubit[]) : Unit is Adj + Ctl {\n H(j[0]);\n for ind in 1 .. Length(j) - 1 {\n Controlled R1Frac([j[ind]], (2, ind + 1, j[0]));\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for n in 1 .. 5 {\n if not CheckOperationsAreEqualStrict(n, Kata.BinaryFractionQuantumInPlace, BinaryFractionQuantumInPlace_Reference) {\n Message($\"Incorrect for n = {n}.\");\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
9699
+ },
9700
+ {
9701
+ "id": "qft__qft__Verification.qs",
9702
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Katas;\n \n operation LibraryQFT(qs : Qubit[]) : Unit is Adj + Ctl {\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for n in 1 .. 5 {\n if not CheckOperationsAreEqualStrict(n, Kata.QuantumFourierTransform, LibraryQFT) {\n Message($\"Incorrect for n = {n}.\");\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
9703
+ },
9704
+ {
9705
+ "id": "qft__all_basis_vectors__Verification.qs",
9706
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation AllBasisVectors_Reference (qs : Qubit[]) : Unit is Adj + Ctl {\n for q in qs {\n H(q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for n in 1 .. 5 {\n let solution = Kata.AllBasisVectors;\n let reference = AllBasisVectors_Reference;\n if not CheckOperationsEquivalenceOnZeroState(solution, reference, n) {\n Message($\"Incorrect for {n} qubit(s)\");\n ShowQuantumStateComparison(n, qs => (), solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n return true;\n }\n}\n"
9707
+ },
9708
+ {
9709
+ "id": "qft__periodic_state__Verification.qs",
9710
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Unstable.StatePreparation;\n\n operation PeriodicState_Reference (qs : Qubit[], F : Int) : Unit is Adj + Ctl {\n let n = Length(qs);\n let amps = MappedOverRange(\n k -> ComplexPolar(1.0, 2. * PI() * IntAsDouble(F * k) / IntAsDouble(2 ^ n)), \n 0 .. 2 ^ n - 1);\n ApproximatelyPreparePureStateCP(0.0, amps, qs);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for n in 1 .. 3 {\n for F in 0 .. 2 ^ n - 1 {\n let solution = Kata.PeriodicState(_, F);\n let reference = PeriodicState_Reference(_, F);\n if not CheckOperationsEquivalenceOnZeroState(solution, reference, n) {\n Message($\"Incorrect for {n} qubit(s), F = {F}\");\n ShowQuantumStateComparison(n, qs => (), solution, reference);\n return false;\n }\n }\n }\n\n Message(\"Correct!\");\n return true;\n }\n}\n"
9711
+ },
9712
+ {
9713
+ "id": "qft__alternating_amplitudes__Verification.qs",
9714
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation AlternatingAmplitudes_Reference (qs : Qubit[]) : Unit is Adj + Ctl {\n for q in qs {\n H(q);\n }\n Z(qs[Length(qs) - 1]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for n in 1 .. 5 {\n let solution = Kata.AlternatingAmplitudes;\n let reference = AlternatingAmplitudes_Reference;\n if not CheckOperationsEquivalenceOnZeroState(solution, reference, n) {\n Message($\"Incorrect for {n} qubit(s)\");\n ShowQuantumStateComparison(n, qs => (), solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n return true;\n }\n}\n"
9715
+ },
9716
+ {
9717
+ "id": "qft__all_even_vectors__Verification.qs",
9718
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation AllEvenVectors_Reference (qs : Qubit[]) : Unit is Adj + Ctl {\n for q in qs[...Length(qs) - 2] {\n H(q);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for n in 1 .. 5 {\n let solution = Kata.AllEvenVectors;\n let reference = AllEvenVectors_Reference;\n if not CheckOperationsEquivalenceOnZeroState(solution, reference, n) {\n Message($\"Incorrect for {n} qubit(s)\");\n ShowQuantumStateComparison(n, qs => (), solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n return true;\n }\n}\n"
9719
+ },
9720
+ {
9721
+ "id": "qft__square_wave__Verification.qs",
9722
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation SquareWave_Reference (qs : Qubit[]) : Unit is Adj + Ctl {\n for q in qs {\n H(q);\n }\n Z(qs[Length(qs) - 2]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for n in 2 .. 5 {\n let solution = Kata.SquareWave;\n let reference = SquareWave_Reference;\n if not CheckOperationsEquivalenceOnZeroState(solution, reference, n) {\n Message($\"Incorrect for {n} qubit(s)\");\n ShowQuantumStateComparison(n, qs => (), solution, reference);\n return false;\n }\n }\n\n Message(\"Correct!\");\n return true;\n }\n}\n"
9723
+ },
9724
+ {
9725
+ "id": "qft__signal_frequency__Verification.qs",
9726
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n\n operation PreparePeriodicState(qs : Qubit[], F : Int) : Unit is Adj + Ctl {\n let bitsBE = Reversed(IntAsBoolArray(F, Length(qs)));\n ApplyPauliFromBitString(PauliX, true, bitsBE, qs);\n ApplyQFT(Reversed(qs));\n SwapReverseRegister(qs);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for n in 2 .. 4 {\n use qs = Qubit[n];\n for F in 0 .. 2 ^ n - 1 {\n PreparePeriodicState(qs, F);\n let fRes = Kata.SignalFrequency(qs);\n ResetAll(qs);\n if fRes != F {\n Message($\"Incorrect frequency for n = {n}, F = {F}: got {fRes}\");\n return false;\n }\n }\n }\n\n Message(\"Correct!\");\n return true;\n }\n}\n"
9727
+ },
9728
+ {
9729
+ "id": "phase_estimation__eigenvalues_s__Verification.qs",
9730
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n\n function ComplexEqual(x : Complex, y : Complex) : Bool { \n // Tests two complex numbers for equality.\n AbsD(x::Real - y::Real) <= 0.001 and AbsD(x::Imag - y::Imag) <= 0.001\n }\n\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let actual = Kata.EigenvaluesS();\n let expected = [Complex(1.0, 0.0), Complex(0.0, 1.0)];\n if Length(actual) != 2 {\n Message(\"The array of eigenvalues should have exactly two elements.\");\n return false;\n }\n if ComplexEqual(actual[0], expected[0]) and ComplexEqual(actual[1], expected[1]) or \n ComplexEqual(actual[0], expected[1]) and ComplexEqual(actual[1], expected[0]) {\n Message(\"Correct!\");\n return true;\n }\n Message(\"Incorrect value for one of the eigenvalues.\");\n return false;\n }\n}\n"
9731
+ },
9732
+ {
9733
+ "id": "phase_estimation__eigenvectors_x__Verification.qs",
9734
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let actual = Kata.EigenvectorsX();\n if Length(actual) != 2 {\n Message(\"The array of eigenvectors should have exactly two elements.\");\n return false;\n }\n for i in 0 .. 1 {\n if Length(actual[i]) != 2 {\n Message(\"Each eigenvector should have exactly two elements.\");\n return false;\n }\n if AbsD(actual[i][0]) + AbsD(actual[i][1]) < 1E-9 {\n Message(\"Each eigenvector should be non-zero.\");\n return false;\n }\n }\n\n // One eigenvector has to have equal components, the other one - opposite ones\n if AbsD(actual[0][0] - actual[0][1]) < 1e-9 and AbsD(actual[1][0] + actual[1][1]) < 1e-9 or \n AbsD(actual[0][0] + actual[0][1]) < 1e-9 and AbsD(actual[1][0] - actual[1][1]) < 1e-9 {\n Message(\"Correct!\");\n return true;\n }\n\n Message(\"Incorrect value for one of the eigenvectors.\");\n return false;\n }\n}\n"
9735
+ },
9736
+ {
9737
+ "id": "phase_estimation__state_eigenvector__Verification.qs",
9738
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Unstable.StatePreparation;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let eigenvectors = [\n (Z, I, \"Z, |0⟩\"), \n (Z, X, \"Z, |1⟩\"), \n (S, I, \"S, |0⟩\"), \n (S, X, \"S, |1⟩\"), \n (X, H, \"X, |+⟩\"), \n (X, q => PreparePureStateD([1., -1.], [q]), \"X, |-⟩\")];\n for (U, P, msg) in eigenvectors {\n if not Kata.IsEigenvector(U, P) {\n Message($\"Incorrect for (U, P) = ({msg}): expected true\");\n return false;\n }\n }\n\n let notEigenvectors = [\n (Z, H, \"Z, |+⟩\"), \n (X, X, \"X, |1⟩\"), \n (X, Z, \"X, |0⟩\"), \n (Y, H, \"Y, |+⟩\"), \n (Y, X, \"Y, |1⟩\")];\n for (U, P, msg) in notEigenvectors {\n if Kata.IsEigenvector(U, P) {\n Message($\"Incorrect for (U, |ψ⟩) = ({msg}): expected false\");\n return false;\n }\n }\n \n Message(\"Correct!\");\n return true;\n }\n}\n"
9739
+ },
9740
+ {
9741
+ "id": "phase_estimation__one_bit_eigenphase__Verification.qs",
9742
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Unstable.StatePreparation;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let eigenvectors = [\n (Z, I, 1, \"Z, |0⟩\"), \n (Z, X, -1, \"Z, |1⟩\"), \n (S, I, 1, \"S, |0⟩\"), \n (X, H, 1, \"X, |+⟩\"), \n (X, q => PreparePureStateD([1., -1.], [q]), -1, \"X, |-⟩\")];\n for (U, P, expected, msg) in eigenvectors {\n let actual = Kata.OneBitPhaseEstimation(U, P);\n if actual != expected {\n Message($\"Incorrect eigenvalue for (U, |ψ⟩) = ({msg}): expected {expected}, got {actual}\");\n return false;\n }\n }\n \n Message(\"Correct!\");\n return true;\n }\n}\n"
9743
+ },
9744
+ {
9745
+ "id": "phase_estimation__implement_qpe__Verification.qs",
9746
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Unstable.StatePreparation;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let tests = [\n (Z, I, 1, 0, \"Z, |0⟩\"), \n (Z, X, 1, 1, \"Z, |1⟩\"), \n (X, H, 1, 0, \"X, |+⟩\"), \n (X, q => PreparePureStateD([1., -1.], [q]), 1, 1, \"X, |-⟩\"),\n (S, I, 2, 0, \"S, |0⟩\"), \n (S, X, 2, 1, \"S, |1⟩\"), \n (Z, X, 2, 2, \"Z, |1⟩\"), // Higher precision than necessary\n (T, I, 3, 0, \"T, |0⟩\"),\n (T, X, 3, 1, \"T, |1⟩\"),\n (S, X, 3, 2, \"S, |1⟩\"), // Higher precision than necessary\n (Z, X, 3, 4, \"Z, |1⟩\"), // Higher precision than necessary\n ];\n for (U, P, n, expected, msg) in tests {\n for _ in 1 .. 10 { // Repeat several times to catch probabilistic failures\n let actual = Kata.PhaseEstimation(U, P, n);\n if actual != expected {\n Message($\"Incorrect eigenphase for (U, |ψ⟩, n) = ({msg}, {n}): expected {expected}, got {actual}\");\n return false;\n }\n }\n }\n \n Message(\"Correct!\");\n return true;\n }\n}\n"
9747
+ },
8586
9748
  {
8587
9749
  "id": "qec_shor__zz_measurement__Verification.qs",
8588
9750
  "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation StatePrep_ZZMeasurement(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 X(qs[0]);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let isCorrect = DistinguishStates_MultiQubit(\n 2,\n 2,\n StatePrep_ZZMeasurement,\n Kata.ZZMeasurement,\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"
@@ -8625,7 +9787,27 @@ export default {
8625
9787
  },
8626
9788
  {
8627
9789
  "id": "nonlocal_games__chsh_classical_strategy__Verification.qs",
8628
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Random;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n mutable wins = 0;\n for i in 1..1000 {\n let x = DrawRandomInt(0, 1) == 1 ? true | false;\n let y = DrawRandomInt(0, 1) == 1 ? true | false;\n let (a, b) = (Kata.AliceClassical(x), Kata.BobClassical(y));\n if ((x and y) == (a != b)) {\n set wins = wins + 1;\n }\n }\n Message($\"Win rate {IntAsDouble(wins) / 1000.}\");\n if (wins < 700) {\n Message(\"Alice and Bob's classical strategy is not optimal\");\n return false;\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
9790
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Random;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n mutable wins = 0;\n for i in 1..1000 {\n let x = DrawRandomBool(0.5);\n let y = DrawRandomBool(0.5);\n let (a, b) = (Kata.AliceClassical(x), Kata.BobClassical(y));\n if ((x and y) == (a != b)) {\n set wins = wins + 1;\n }\n }\n Message($\"Win rate {IntAsDouble(wins) / 1000.}\");\n if (wins < 700) {\n Message(\"Alice and Bob's classical strategy is not optimal\");\n return false;\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
9791
+ },
9792
+ {
9793
+ "id": "nonlocal_games__chsh_quantum_alice_strategy__Verification.qs",
9794
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Random;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n use q = Qubit();\n for _ in 1 .. 4 {\n // repeat 4 times since we are testing a measurement and wrong basis still might get\n // the correct answer, reduces probability of false positives\n let result = Kata.AliceQuantum(false, q);\n Reset(q);\n if (result != false) {\n Message(\"Measuring |0⟩ in the Z basis returned incorrect value; expected false\");\n return false;\n }\n\n // apply the Pauli X gate\n X(q);\n let result = Kata.AliceQuantum(false, q);\n Reset(q);\n if (result != true) {\n Message(\"Measuring |1⟩ in the Z basis returned incorrect value; expected true\");\n return false;\n }\n\n // apply the Hadamard gate\n H(q);\n let result = Kata.AliceQuantum(true, q);\n Reset(q);\n if (result != false) {\n Message(\"Measuring |+⟩ in the X basis returned incorrect value; expected false\");\n return false;\n }\n\n // apply the Pauli X and then the Hadamard gate\n X(q);\n H(q);\n let result = Kata.AliceQuantum(true, q);\n Reset(q);\n if (result != true) {\n Message(\"Measuring |-⟩ in the X basis returned incorrect value; expected true\");\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
9795
+ },
9796
+ {
9797
+ "id": "nonlocal_games__chsh_quantum_bob_strategy__Verification.qs",
9798
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n\n operation RotateBobQubit (clockwise : Bool, qubit : Qubit) : Unit {\n if (clockwise) {\n Ry(-PI()/4.0, qubit);\n } else {\n Ry(PI()/4.0, qubit);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for _ in 1 .. 4 {\n // repeat 4 times since we are testing a measurement and wrong basis still might get\n // the correct answer, reduces probability of false positives\n use q = Qubit();\n RotateBobQubit(false, q);\n let result = Kata.BobQuantum(false, q);\n Reset(q);\n if (result != false) {\n Message(\"π/8 from |0⟩ not measured as false\");\n return false;\n }\n\n X(q);\n RotateBobQubit(false, q);\n let result = Kata.BobQuantum(false, q);\n Reset(q);\n if (result != true) {\n Message(\"π/8 from |1⟩ not measured as true\");\n return false;\n }\n\n RotateBobQubit(true, q);\n let result = Kata.BobQuantum(true, q);\n Reset(q);\n if (result != false) {\n Message(\"-π/8 from |0⟩ not measured as false\");\n return false;\n }\n\n X(q);\n RotateBobQubit(true, q);\n let result = Kata.BobQuantum(true, q);\n Reset(q);\n if (result != true) {\n Message(\"-π/8 from |1⟩ not measured as true\");\n return false;\n }\n }\n Message(\"Correct!\");\n true\n } \n}\n"
9799
+ },
9800
+ {
9801
+ "id": "nonlocal_games__ghz_win_condition__Verification.qs",
9802
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n\n function WinCondition_Reference (rst : Bool[], abc : Bool[]) : Bool {\n return (rst[0] or rst[1] or rst[2]) == (abc[0] != abc[1] != abc[2]);\n }\n\n // All possible starting bits (r, s and t) that the referee can give\n // to Alice, Bob and Charlie.\n function RefereeBits () : Bool[][] {\n return [[false, false, false],\n [true, true, false],\n [false, true, true],\n [true, false, true]];\n }\n\n @EntryPoint()\n function CheckSolution() : Bool {\n for rst in RefereeBits() {\n for i in 0 .. 1 <<< 3 - 1 {\n let abc = IntAsBoolArray(i, 3);\n let expected = WinCondition_Reference(rst, abc);\n let actual = Kata.WinCondition(rst, abc);\n\n if actual != expected {\n Message($\"Win condition '{actual}' is wrong for rst={rst}, abc={abc}\");\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
9803
+ },
9804
+ {
9805
+ "id": "nonlocal_games__ghz_classical_strategy__Verification.qs",
9806
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Logical; \n open Microsoft.Quantum.Random;\n\n function WinCondition_Reference (rst : Bool[], abc : Bool[]) : Bool {\n return (rst[0] or rst[1] or rst[2]) == (abc[0] != abc[1] != abc[2]);\n }\n\n // All possible starting bits (r, s and t) that the referee can give\n // to Alice, Bob and Charlie.\n function RefereeBits () : Bool[][] {\n return [[false, false, false],\n [true, true, false],\n [false, true, true],\n [true, false, true]];\n }\n\n operation PlayClassicalGHZ_Reference (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] {\n let r = inputs[0];\n let s = inputs[1];\n let t = inputs[2];\n let a = strategies[0](r);\n let b = strategies[1](s);\n let c = strategies[2](t);\n return [a, b, c];\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let inputs = RefereeBits();\n let strategies = [Kata.AliceClassical, Kata.BobClassical, Kata.CharlieClassical];\n\n let iterations = 1000;\n mutable wins = 0;\n for _ in 0 .. iterations - 1 {\n for bits in inputs {\n let abc = PlayClassicalGHZ_Reference(strategies, bits);\n if WinCondition_Reference(bits, abc) {\n set wins = wins + 1;\n }\n }\n }\n // The solution is correct if the players win 75% (3/4) of the time.\n if wins < iterations*Length(inputs)*3/4 {\n Message($\"Alice, Bob, and Charlie's classical strategy gets {wins} wins out of {iterations*Length(inputs)} possible inputs, which is not optimal\");\n return false;\n }\n Message(\"Correct!\");\n true\n }\n}\n"
9807
+ },
9808
+ {
9809
+ "id": "nonlocal_games__ghz_classical_game__Verification.qs",
9810
+ "code": "namespace Kata.Verification {\n\n // All possible starting bits (r, s and t) that the referee can give\n // to Alice, Bob and Charlie.\n function RefereeBits () : Bool[][] {\n return [[false, false, false],\n [true, true, false],\n [false, true, true],\n [true, false, true]];\n }\n\n operation TestStrategy (input : Bool, mode : Int) : Bool {\n return mode == 0 ? false | mode == 1 ? true | mode == 2 ? input | not input;\n }\n\n operation PlayClassicalGHZ_Reference (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] {\n let r = inputs[0];\n let s = inputs[1];\n let t = inputs[2];\n let a = strategies[0](r);\n let b = strategies[1](s);\n let c = strategies[2](t);\n return [a, b, c];\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let inputs = RefereeBits();\n for rst in inputs {\n // To test the interaction, run it on deterministic strategies (not necessarily good ones)\n // This logic helps to detect errors in user PlayClassicalGHZ implementation like\n // using the wrong sequence of output bits or not using the strategies at all. \n for mode_1 in 0 .. 3 {\n for mode_2 in 0 .. 3 {\n for mode_3 in 0 .. 3 {\n let strategies = [TestStrategy(_, mode_1), TestStrategy(_, mode_2), TestStrategy(_, mode_3)];\n let actual = Kata.PlayClassicalGHZ(strategies, rst);\n let expected = PlayClassicalGHZ_Reference(strategies, rst);\n if actual != expected {\n Message($\"Expected {expected}, got {actual} for {rst}\");\n return false;\n }\n }\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
8629
9811
  }
8630
9812
  ]
8631
9813
  };