qsharp-lang 1.6.3-dev → 1.6.5-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 (296) hide show
  1. package/dist/katas-content.generated.js +604 -10
  2. package/dist/katas-content.generated.md.js +604 -10
  3. package/dist/language-service/language-service.js +7 -0
  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 +1 -1
  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/IntAsBigInt.md +1 -1
  76. package/docs/Microsoft.Quantum.Convert/IntAsBoolArray.md +1 -1
  77. package/docs/Microsoft.Quantum.Convert/IntAsDouble.md +1 -1
  78. package/docs/Microsoft.Quantum.Convert/ResultArrayAsBoolArray.md +1 -1
  79. package/docs/Microsoft.Quantum.Convert/ResultArrayAsInt.md +1 -1
  80. package/docs/Microsoft.Quantum.Convert/ResultAsBool.md +1 -1
  81. package/docs/Microsoft.Quantum.Core/IsRangeEmpty.md +1 -1
  82. package/docs/Microsoft.Quantum.Core/Length.md +1 -1
  83. package/docs/Microsoft.Quantum.Core/RangeEnd.md +1 -1
  84. package/docs/Microsoft.Quantum.Core/RangeReverse.md +1 -1
  85. package/docs/Microsoft.Quantum.Core/RangeStart.md +1 -1
  86. package/docs/Microsoft.Quantum.Core/RangeStep.md +1 -1
  87. package/docs/Microsoft.Quantum.Core/Repeated.md +1 -1
  88. package/docs/Microsoft.Quantum.Diagnostics/DumpMachine.md +1 -1
  89. package/docs/Microsoft.Quantum.Diagnostics/DumpRegister.md +1 -1
  90. package/docs/Microsoft.Quantum.Diagnostics/Fact.md +1 -1
  91. package/docs/Microsoft.Quantum.Intrinsic/AdjustForSingleControl.md +1 -1
  92. package/docs/Microsoft.Quantum.Intrinsic/ApplyGlobalPhase.md +1 -1
  93. package/docs/Microsoft.Quantum.Intrinsic/CCH.md +1 -1
  94. package/docs/Microsoft.Quantum.Intrinsic/CCNOT.md +1 -1
  95. package/docs/Microsoft.Quantum.Intrinsic/CCY.md +1 -1
  96. package/docs/Microsoft.Quantum.Intrinsic/CCZ.md +1 -1
  97. package/docs/Microsoft.Quantum.Intrinsic/CH.md +1 -1
  98. package/docs/Microsoft.Quantum.Intrinsic/CNOT.md +1 -1
  99. package/docs/Microsoft.Quantum.Intrinsic/CRxx.md +1 -1
  100. package/docs/Microsoft.Quantum.Intrinsic/CRyy.md +1 -1
  101. package/docs/Microsoft.Quantum.Intrinsic/CRz.md +1 -1
  102. package/docs/Microsoft.Quantum.Intrinsic/CRzz.md +1 -1
  103. package/docs/Microsoft.Quantum.Intrinsic/CS.md +1 -1
  104. package/docs/Microsoft.Quantum.Intrinsic/CT.md +1 -1
  105. package/docs/Microsoft.Quantum.Intrinsic/CollectControls.md +1 -1
  106. package/docs/Microsoft.Quantum.Intrinsic/ControllableGlobalPhase.md +1 -1
  107. package/docs/Microsoft.Quantum.Intrinsic/EntangleForJointMeasure.md +1 -1
  108. package/docs/Microsoft.Quantum.Intrinsic/Exp.md +1 -1
  109. package/docs/Microsoft.Quantum.Intrinsic/GlobalPhase.md +1 -1
  110. package/docs/Microsoft.Quantum.Intrinsic/H.md +1 -1
  111. package/docs/Microsoft.Quantum.Intrinsic/I.md +1 -1
  112. package/docs/Microsoft.Quantum.Intrinsic/IndicesOfNonIdentity.md +1 -1
  113. package/docs/Microsoft.Quantum.Intrinsic/M.md +1 -1
  114. package/docs/Microsoft.Quantum.Intrinsic/MapPauli.md +1 -1
  115. package/docs/Microsoft.Quantum.Intrinsic/Measure.md +1 -1
  116. package/docs/Microsoft.Quantum.Intrinsic/Message.md +1 -1
  117. package/docs/Microsoft.Quantum.Intrinsic/PhaseCCX.md +1 -1
  118. package/docs/Microsoft.Quantum.Intrinsic/R.md +1 -1
  119. package/docs/Microsoft.Quantum.Intrinsic/R1.md +1 -1
  120. package/docs/Microsoft.Quantum.Intrinsic/R1Frac.md +1 -1
  121. package/docs/Microsoft.Quantum.Intrinsic/RFrac.md +1 -1
  122. package/docs/Microsoft.Quantum.Intrinsic/RemovePauliI.md +1 -1
  123. package/docs/Microsoft.Quantum.Intrinsic/Reset.md +1 -1
  124. package/docs/Microsoft.Quantum.Intrinsic/ResetAll.md +1 -1
  125. package/docs/Microsoft.Quantum.Intrinsic/Rx.md +1 -1
  126. package/docs/Microsoft.Quantum.Intrinsic/Rxx.md +1 -1
  127. package/docs/Microsoft.Quantum.Intrinsic/Ry.md +1 -1
  128. package/docs/Microsoft.Quantum.Intrinsic/Ryy.md +1 -1
  129. package/docs/Microsoft.Quantum.Intrinsic/Rz.md +1 -1
  130. package/docs/Microsoft.Quantum.Intrinsic/Rzz.md +1 -1
  131. package/docs/Microsoft.Quantum.Intrinsic/S.md +1 -1
  132. package/docs/Microsoft.Quantum.Intrinsic/SWAP.md +1 -1
  133. package/docs/Microsoft.Quantum.Intrinsic/SpreadZ.md +1 -1
  134. package/docs/Microsoft.Quantum.Intrinsic/T.md +1 -1
  135. package/docs/Microsoft.Quantum.Intrinsic/X.md +1 -1
  136. package/docs/Microsoft.Quantum.Intrinsic/Y.md +1 -1
  137. package/docs/Microsoft.Quantum.Intrinsic/Z.md +1 -1
  138. package/docs/Microsoft.Quantum.Logical/Xor.md +1 -1
  139. package/docs/Microsoft.Quantum.Math/AbsComplex.md +1 -1
  140. package/docs/Microsoft.Quantum.Math/AbsComplexPolar.md +1 -1
  141. package/docs/Microsoft.Quantum.Math/AbsD.md +1 -1
  142. package/docs/Microsoft.Quantum.Math/AbsI.md +1 -1
  143. package/docs/Microsoft.Quantum.Math/AbsL.md +1 -1
  144. package/docs/Microsoft.Quantum.Math/AbsSquaredComplex.md +1 -1
  145. package/docs/Microsoft.Quantum.Math/AbsSquaredComplexPolar.md +1 -1
  146. package/docs/Microsoft.Quantum.Math/ApproximateFactorial.md +1 -1
  147. package/docs/Microsoft.Quantum.Math/ArcCos.md +1 -1
  148. package/docs/Microsoft.Quantum.Math/ArcCosh.md +1 -1
  149. package/docs/Microsoft.Quantum.Math/ArcSin.md +1 -1
  150. package/docs/Microsoft.Quantum.Math/ArcSinh.md +1 -1
  151. package/docs/Microsoft.Quantum.Math/ArcTan.md +1 -1
  152. package/docs/Microsoft.Quantum.Math/ArcTan2.md +1 -1
  153. package/docs/Microsoft.Quantum.Math/ArcTanh.md +1 -1
  154. package/docs/Microsoft.Quantum.Math/ArgComplex.md +1 -1
  155. package/docs/Microsoft.Quantum.Math/ArgComplexPolar.md +1 -1
  156. package/docs/Microsoft.Quantum.Math/Binom.md +1 -1
  157. package/docs/Microsoft.Quantum.Math/BitSizeI.md +1 -1
  158. package/docs/Microsoft.Quantum.Math/BitSizeL.md +1 -1
  159. package/docs/Microsoft.Quantum.Math/Ceiling.md +1 -1
  160. package/docs/Microsoft.Quantum.Math/Complex.md +1 -1
  161. package/docs/Microsoft.Quantum.Math/ComplexPolar.md +1 -1
  162. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentI.md +1 -1
  163. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentL.md +1 -1
  164. package/docs/Microsoft.Quantum.Math/Cos.md +1 -1
  165. package/docs/Microsoft.Quantum.Math/Cosh.md +1 -1
  166. package/docs/Microsoft.Quantum.Math/DivRemI.md +1 -1
  167. package/docs/Microsoft.Quantum.Math/DivRemL.md +1 -1
  168. package/docs/Microsoft.Quantum.Math/DividedByC.md +1 -1
  169. package/docs/Microsoft.Quantum.Math/DividedByCP.md +1 -1
  170. package/docs/Microsoft.Quantum.Math/E.md +1 -1
  171. package/docs/Microsoft.Quantum.Math/ExpModI.md +1 -1
  172. package/docs/Microsoft.Quantum.Math/ExpModL.md +1 -1
  173. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorI.md +1 -1
  174. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorL.md +1 -1
  175. package/docs/Microsoft.Quantum.Math/ExtendedTruncation.md +1 -1
  176. package/docs/Microsoft.Quantum.Math/FactorialI.md +1 -1
  177. package/docs/Microsoft.Quantum.Math/FactorialL.md +1 -1
  178. package/docs/Microsoft.Quantum.Math/Floor.md +1 -1
  179. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorI.md +1 -1
  180. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorL.md +1 -1
  181. package/docs/Microsoft.Quantum.Math/HammingWeightI.md +1 -1
  182. package/docs/Microsoft.Quantum.Math/InverseModI.md +1 -1
  183. package/docs/Microsoft.Quantum.Math/InverseModL.md +1 -1
  184. package/docs/Microsoft.Quantum.Math/IsCoprimeI.md +1 -1
  185. package/docs/Microsoft.Quantum.Math/IsCoprimeL.md +1 -1
  186. package/docs/Microsoft.Quantum.Math/IsInfinite.md +1 -1
  187. package/docs/Microsoft.Quantum.Math/IsNaN.md +1 -1
  188. package/docs/Microsoft.Quantum.Math/LargestFixedPoint.md +1 -1
  189. package/docs/Microsoft.Quantum.Math/Lg.md +1 -1
  190. package/docs/Microsoft.Quantum.Math/Log.md +1 -1
  191. package/docs/Microsoft.Quantum.Math/Log10.md +1 -1
  192. package/docs/Microsoft.Quantum.Math/LogFactorialD.md +1 -1
  193. package/docs/Microsoft.Quantum.Math/LogGammaD.md +1 -1
  194. package/docs/Microsoft.Quantum.Math/LogOf2.md +1 -1
  195. package/docs/Microsoft.Quantum.Math/Max.md +1 -1
  196. package/docs/Microsoft.Quantum.Math/MaxD.md +1 -1
  197. package/docs/Microsoft.Quantum.Math/MaxI.md +1 -1
  198. package/docs/Microsoft.Quantum.Math/MaxL.md +1 -1
  199. package/docs/Microsoft.Quantum.Math/Min.md +1 -1
  200. package/docs/Microsoft.Quantum.Math/MinD.md +1 -1
  201. package/docs/Microsoft.Quantum.Math/MinI.md +1 -1
  202. package/docs/Microsoft.Quantum.Math/MinL.md +1 -1
  203. package/docs/Microsoft.Quantum.Math/MinusC.md +1 -1
  204. package/docs/Microsoft.Quantum.Math/MinusCP.md +1 -1
  205. package/docs/Microsoft.Quantum.Math/ModulusI.md +1 -1
  206. package/docs/Microsoft.Quantum.Math/ModulusL.md +1 -1
  207. package/docs/Microsoft.Quantum.Math/NegationC.md +1 -1
  208. package/docs/Microsoft.Quantum.Math/NegationCP.md +1 -1
  209. package/docs/Microsoft.Quantum.Math/PI.md +1 -1
  210. package/docs/Microsoft.Quantum.Math/PNorm.md +1 -1
  211. package/docs/Microsoft.Quantum.Math/PNormalized.md +1 -1
  212. package/docs/Microsoft.Quantum.Math/PlusC.md +1 -1
  213. package/docs/Microsoft.Quantum.Math/PlusCP.md +1 -1
  214. package/docs/Microsoft.Quantum.Math/PowC.md +1 -1
  215. package/docs/Microsoft.Quantum.Math/PowCAsCP.md +1 -1
  216. package/docs/Microsoft.Quantum.Math/PowCP.md +1 -1
  217. package/docs/Microsoft.Quantum.Math/RealMod.md +1 -1
  218. package/docs/Microsoft.Quantum.Math/Round.md +1 -1
  219. package/docs/Microsoft.Quantum.Math/SignD.md +1 -1
  220. package/docs/Microsoft.Quantum.Math/SignI.md +1 -1
  221. package/docs/Microsoft.Quantum.Math/SignL.md +1 -1
  222. package/docs/Microsoft.Quantum.Math/Sin.md +1 -1
  223. package/docs/Microsoft.Quantum.Math/Sinh.md +1 -1
  224. package/docs/Microsoft.Quantum.Math/SmallestFixedPoint.md +1 -1
  225. package/docs/Microsoft.Quantum.Math/Sqrt.md +1 -1
  226. package/docs/Microsoft.Quantum.Math/SquaredNorm.md +1 -1
  227. package/docs/Microsoft.Quantum.Math/Tan.md +1 -1
  228. package/docs/Microsoft.Quantum.Math/Tanh.md +1 -1
  229. package/docs/Microsoft.Quantum.Math/TimesC.md +1 -1
  230. package/docs/Microsoft.Quantum.Math/TimesCP.md +1 -1
  231. package/docs/Microsoft.Quantum.Math/TrailingZeroCountI.md +1 -1
  232. package/docs/Microsoft.Quantum.Math/TrailingZeroCountL.md +1 -1
  233. package/docs/Microsoft.Quantum.Math/Truncate.md +1 -1
  234. package/docs/Microsoft.Quantum.Measurement/MResetEachZ.md +1 -1
  235. package/docs/Microsoft.Quantum.Measurement/MResetX.md +1 -1
  236. package/docs/Microsoft.Quantum.Measurement/MResetY.md +1 -1
  237. package/docs/Microsoft.Quantum.Measurement/MResetZ.md +1 -1
  238. package/docs/Microsoft.Quantum.Measurement/MeasureAllZ.md +1 -1
  239. package/docs/Microsoft.Quantum.Measurement/MeasureEachZ.md +1 -1
  240. package/docs/Microsoft.Quantum.Measurement/MeasureInteger.md +1 -1
  241. package/docs/Microsoft.Quantum.ResourceEstimation/AccountForEstimates.md +1 -1
  242. package/docs/Microsoft.Quantum.ResourceEstimation/AuxQubitCount.md +1 -1
  243. package/docs/Microsoft.Quantum.ResourceEstimation/BeginEstimateCaching.md +1 -1
  244. package/docs/Microsoft.Quantum.ResourceEstimation/BeginRepeatEstimates.md +1 -1
  245. package/docs/Microsoft.Quantum.ResourceEstimation/CczCount.md +1 -1
  246. package/docs/Microsoft.Quantum.ResourceEstimation/EndEstimateCaching.md +1 -1
  247. package/docs/Microsoft.Quantum.ResourceEstimation/EndRepeatEstimates.md +1 -1
  248. package/docs/Microsoft.Quantum.ResourceEstimation/MeasurementCount.md +1 -1
  249. package/docs/Microsoft.Quantum.ResourceEstimation/PSSPCLayout.md +1 -1
  250. package/docs/Microsoft.Quantum.ResourceEstimation/RepeatEstimates.md +1 -1
  251. package/docs/Microsoft.Quantum.ResourceEstimation/RotationCount.md +1 -1
  252. package/docs/Microsoft.Quantum.ResourceEstimation/RotationDepth.md +1 -1
  253. package/docs/Microsoft.Quantum.ResourceEstimation/SingleVariant.md +1 -1
  254. package/docs/Microsoft.Quantum.ResourceEstimation/TCount.md +1 -1
  255. package/docs/Microsoft.Quantum.Unstable.Arithmetic/AddLE.md +1 -1
  256. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyActionIfGreaterThanOrEqualConstant.md +1 -1
  257. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyActionIfSumOverflows.md +1 -1
  258. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyAsSinglyControlled.md +1 -1
  259. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualL.md +1 -1
  260. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualLE.md +1 -1
  261. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterL.md +1 -1
  262. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterLE.md +1 -1
  263. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualL.md +1 -1
  264. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualLE.md +1 -1
  265. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessL.md +1 -1
  266. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessLE.md +1 -1
  267. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualL.md +1 -1
  268. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualLE.md +1 -1
  269. package/docs/Microsoft.Quantum.Unstable.Arithmetic/FourierTDIncByLE.md +1 -1
  270. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByI.md +1 -1
  271. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByIUsingIncByLE.md +1 -1
  272. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByL.md +1 -1
  273. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLE.md +1 -1
  274. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLEUsingAddLE.md +1 -1
  275. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLUsingIncByLE.md +1 -1
  276. package/docs/Microsoft.Quantum.Unstable.Arithmetic/LookAheadDKRSAddLE.md +1 -1
  277. package/docs/Microsoft.Quantum.Unstable.Arithmetic/MAJ.md +1 -1
  278. package/docs/Microsoft.Quantum.Unstable.Arithmetic/PhaseGradient.md +1 -1
  279. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ReflectAboutInteger.md +1 -1
  280. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGAddLE.md +1 -1
  281. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGIncByLE.md +1 -1
  282. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryTTKIncByLE.md +1 -1
  283. package/docs/Microsoft.Quantum.Unstable.StatePreparation/ApproximatelyPreparePureStateCP.md +1 -1
  284. package/docs/Microsoft.Quantum.Unstable.StatePreparation/PreparePureStateD.md +1 -1
  285. package/docs/Microsoft.Quantum.Unstable.TableLookup/EncodeUnary.md +1 -1
  286. package/docs/Microsoft.Quantum.Unstable.TableLookup/MustBeFixed.md +1 -1
  287. package/docs/Microsoft.Quantum.Unstable.TableLookup/Select.md +1 -1
  288. package/docs/Microsoft.Quantum.Unstable.TableLookup/Unlookup.md +1 -1
  289. package/docs/Microsoft.Quantum.Unstable.TableLookup/WriteMemoryContents.md +1 -1
  290. package/lib/node/qsc_wasm.cjs +1 -1
  291. package/lib/node/qsc_wasm.d.cts +1 -0
  292. package/lib/node/qsc_wasm_bg.wasm +0 -0
  293. package/lib/web/qsc_wasm.d.ts +1 -0
  294. package/lib/web/qsc_wasm.js +1 -1
  295. package/lib/web/qsc_wasm_bg.wasm +0 -0
  296. package/package.json +1 -1
@@ -4955,7 +4955,7 @@ export default {
4955
4955
  "title": "Measure Qubits (Bob's Task)",
4956
4956
  "description": {
4957
4957
  "type": "text-content",
4958
- "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li><code>qs</code>: an array of $N$ qubits;<br />\neach qubit is in one of the following states: $|0\\rangle$, $|1\\rangle$, $|+\\rangle$, $|-\\rangle$.</li>\n<li><code>bases</code>: a <code>Bool</code> array of length $N$;\n<code>bases[i]</code> indicates the basis that should be used to measure the qubit <code>i</code>:\n<ul>\n<li><code>false</code>: use the basis $\\ket{0}$ / $\\ket{1}$ (computational),</li>\n<li><code>true</code>: use the basis $\\ket{+}$ / $\\ket{-}$ (Hadamard).</li>\n</ul>\n</li>\n</ol>\n<p><strong>Goal:</strong> Measure each qubit in the corresponding basis and return an array of results as Boolean values, encoding measurement result <code>Zero</code> as <code>false</code> and <code>One</code> as <code>true</code>.\nThe state of the qubits at the end of the operation does not matter.</p>\n"
4958
+ "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li><code>qs</code>: an array of $N$ qubits;<br />\neach qubit is in one of the following states: $\\ket{0}$, $\\ket{1}$, $\\ket{+}$, $\\ket{-}$.</li>\n<li><code>bases</code>: a <code>Bool</code> array of length $N$;\n<code>bases[i]</code> indicates the basis that should be used to measure the qubit <code>i</code>:\n<ul>\n<li><code>false</code>: use the basis $\\ket{0}$ / $\\ket{1}$ (computational),</li>\n<li><code>true</code>: use the basis $\\ket{+}$ / $\\ket{-}$ (Hadamard).</li>\n</ul>\n</li>\n</ol>\n<p><strong>Goal:</strong> Measure each qubit in the corresponding basis and return an array of results as Boolean values, encoding measurement result <code>Zero</code> as <code>false</code> and <code>One</code> as <code>true</code>.\nThe state of the qubits at the end of the operation does not matter.</p>\n"
4959
4959
  },
4960
4960
  "sourceIds": [
4961
4961
  "key_distribution__measure_qubits__Verification.qs",
@@ -6724,7 +6724,7 @@ export default {
6724
6724
  "items": [
6725
6725
  {
6726
6726
  "type": "text-content",
6727
- "content": "<p>This 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.</p>\n<p><strong>This kata covers the following topics:</strong></p>\n<ul>\n<li>The problem solved by Deutsch-Jozsa algorithm and the classical solution to it</li>\n<li>Multi-qubit phase oracles (for a more detailed introduction to phase oracles, see Oracles kata)</li>\n<li>Deutsch-Jozsa algorithm</li>\n<li>Implementing oracles and end-to-end Deutsch-Jozsa algorithm in Q#</li>\n<li>Bernstein-Vazirani algorithm and the problem solved by it</li>\n</ul>\n<p><strong>What you should know to start working on this kata:</strong></p>\n<ul>\n<li>Basic single-qubit gates</li>\n<li>Quantum measurements</li>\n<li>Deutsch algorithm - the single-qubit variant of Deutsch-Jozsa algorithm</li>\n</ul>\n"
6727
+ "content": "<p>This 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.</p>\n<p><strong>This kata covers the following topics:</strong></p>\n<ul>\n<li>The problem solved by Deutsch-Jozsa algorithm and the classical solution to it</li>\n<li>Multi-qubit phase oracles (for a more detailed introduction to phase oracles, see Oracles kata)</li>\n<li>Deutsch-Jozsa algorithm</li>\n<li>Implementing oracles and end-to-end Deutsch-Jozsa algorithm in Q#</li>\n<li>Bernstein-Vazirani algorithm and the problem solved by it</li>\n</ul>\n<p><strong>What you should know to start working on this kata:</strong></p>\n<ul>\n<li>Basic knowledge of single-qubit gates</li>\n<li>Basic knowledge of quantum measurements</li>\n<li>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.</li>\n</ul>\n"
6728
6728
  }
6729
6729
  ]
6730
6730
  },
@@ -6735,7 +6735,7 @@ export default {
6735
6735
  "items": [
6736
6736
  {
6737
6737
  "type": "text-content",
6738
- "content": "<p>You are given a classical function that takes an $N$-bit string as an input and returns one bit: $f(x): \\{0, 1\\}^N \\to \\{0, 1\\}$. You are guaranteed that the function $f$ is</p>\n<ul>\n<li>either <em>constant</em> (returns the same value for all inputs)</li>\n<li>or <em>balanced</em> (returns value $0$ for half of the inputs and $1$ for the other half of the inputs).</li>\n</ul>\n<p>The task is to figure out whether the function is constant or balanced.</p>\n<p><strong>Examples</strong></p>\n<ul>\n<li>$f(x) \\equiv 0$ or $f(x) \\equiv 1$ are constant functions (and they are actually the only constant functions in existence).</li>\n<li>$f(x) = x \\bmod 2$ (the least significant bit of $x$) or $f(x) = 1 \\text{ if the binary notation of }x \\text{ has odd number of 1s and 0 otherwise}$ are examples of multi-bit balanced functions. Indeed, for both these functions you can check that for every possible input $x$ for which $f(x) = 0$ there exists an input $x^\\prime$ (equal to $x$ with the least significant bit flipped) such that $f(x^\\prime) = 1$, and vice versa, which means that the function is balanced.</li>\n</ul>\n<p>If we solve this problem classically, how many calls to the given function will we need?</p>\n<p>The first call will give us no information - regardless of whether it returns $0$ or $1$, the function could still be constant or balanced.\nIn the best case scenario the second call will return a different value and we'll be able to conclude that the function is balanced in just $2$ calls.\nHowever, if we get the same value for the first two calls, we'll have to keep querying the function until either we get a different value or until we do $2^{N-1}+1$ queries that will return the same value - only in this case we'll know for certain that the function is constant.</p>\n<p>What about the quantum scenario?</p>\n"
6738
+ "content": "<p>You are given a classical function that takes an $N$-bit string as an input and returns one bit: $f(x): \\{0, 1\\}^N \\to \\{0, 1\\}$. You are guaranteed that the function $f$ is</p>\n<ul>\n<li>either <em>constant</em> (returns the same value for all inputs)</li>\n<li>or <em>balanced</em> (returns value $0$ for half of the inputs and $1$ for the other half of the inputs).</li>\n</ul>\n<p>The task is to figure out whether the function is constant or balanced.</p>\n<p><strong>Examples</strong></p>\n<ul>\n<li>$f(x) \\equiv 0$ or $f(x) \\equiv 1$ are constant functions (and they're actually the only constant functions in existence).</li>\n<li>$f(x) = x \\bmod 2$ (the least significant bit of $x$) or $f(x) = 1 \\text{ if the binary notation of }x \\text{ has odd number of 1s and 0 otherwise}$ are examples of multi-bit balanced functions. Indeed, for both these functions you can check that for every possible input $x$ for which $f(x) = 0$ there exists an input $x^\\prime$ (equal to $x$ with the least significant bit flipped) such that $f(x^\\prime) = 1$, and vice versa, which means that the function is balanced.</li>\n</ul>\n<p>If you solve this problem classically, how many calls to the given function will you need?</p>\n<p>The first call will give you no information - regardless of whether it returns $0$ or $1$, the function could still be constant or balanced.\nIn the best case scenario, the second call will return a different value. You'll be able to conclude that the function is balanced in just $2$ calls.\nHowever, if you get the same value for the first two calls, you'll have to keep querying the function until either the function returns a different value, or until you perform $2^{N-1}+1$ queries that return the same value - only in this case will you know with certainty that the function is constant.</p>\n<p>What about the quantum scenario?</p>\n"
6739
6739
  }
6740
6740
  ]
6741
6741
  },
@@ -6746,7 +6746,7 @@ export default {
6746
6746
  "items": [
6747
6747
  {
6748
6748
  "type": "text-content",
6749
- "content": "<p>In the quantum scenario, the classical function we're working with is implemented as a quantum oracle - a &quot;black box&quot; operation used as input to another algorithm. This operation is implemented in a way which allows to perform calculations not only on individual inputs, but also on superpositions of inputs.</p>\n<p>To enable the oracle to act on quantum states instead of classical values, the integer input $x$ is represented in binary $x = (x_{0}, x_{1}, \\dots, x_{N-1})$,\nand encoded into an $N$-qubit register: $\\ket{\\vec{x} } = \\ket{x_{0} } \\otimes \\ket{x_{1} } \\otimes \\cdots \\otimes \\ket{x_{N-1} }$.\nThe phase oracle $U_f$ for this function is defined as follows:</p>\n<p>$$U_f \\ket{\\vec{x} } = (-1)^{f(x)} \\ket{\\vec{x} }$$</p>\n<p>The function $f$ can return only two values, 0 or 1, which result in no phase change or multiplication by a relative phase $-1$, respectively.</p>\n<p>The effect of such an oracle on any single basis state is not particularly interesting: it just adds a global phase which is not something you can observe. However, if you apply this oracle to a <em>superposition</em> of basis states, its effect becomes noticeable.\nRemember that quantum operations are linear: if you define the effect of an operation on the basis states, you'll be able to deduce its effect on superposition states (which are just linear combinations of the basis states) using its linearity.</p>\n<p>Let's see how to implement several examples of multi-bit constant and balanced functions as phase oracles in Q#.</p>\n<ol>\n<li>$f(x) \\equiv 0$</li>\n</ol>\n<p>This is the easiest function to implement: if $f(x) \\equiv 0$,</p>\n<p>$$U_f \\ket{x} \\equiv (-1)^0 \\ket{x} = \\ket{x}$$</p>\n<p>This means that $U_f$ is an identity - a transformation which does absolutely nothing!</p>\n<ol start=\"2\">\n<li>$f(x) \\equiv 1$</li>\n</ol>\n<p>The second constant function is slightly trickier: if $f(x) \\equiv 1$</p>\n<p>$$U_f \\ket{x} \\equiv (-1)^1 \\ket{x} = - \\ket{x}$$</p>\n<p>Now $U_f$ is a negative identity, i.e., a transformation which applies a global phase of $-1$ to the state.\nA lot of algorithms just ignore the global phase accumulated in them, since it is not observable.\nHowever, if we want to be really meticulous, we can use the $R$ gate which performs a given rotation around the given axis.\nWhen called with <code>PauliI</code> axis, this operation applies a global phase to the given qubit.\nWe can use any qubit to apply this gate, for example, <code>qs[0]</code>.</p>\n<ol start=\"3\">\n<li>$f(x) = x \\bmod 2$</li>\n</ol>\n<p>The binary representation of $x$ is $x = (x_{0}, x_{1}, \\dots, x_{N-1})$, with the least significant bit encoded in the last bit (stored in the last qubit of the input array). Then we can rewrite the function as</p>\n<p>$$f(x) = x_{N-1}$$</p>\n<p>Let's use this in the oracle effect expression:</p>\n<p>$$U_f \\ket{x} = (-1)^{f(x)} \\ket{x} = (-1)^{x_{N-1}} \\ket{x} = \\ket{x_{0} } \\otimes \\cdots \\otimes \\ket{x_{N-2} } \\otimes (-1)^{x_{N-1}} \\ket{x_{N-1}}$$</p>\n<p>This means that we only need to use the last qubit in the implementation: do nothing if it is $\\ket{0}$ and apply a phase of $-1$ if it is $\\ket{1}$. This is exactly the effect of the $Z$ gate!</p>\n<p>We can write out the oracle unitary as follows:</p>\n<p>$$U_f = \\mathbb{1} \\otimes \\cdots \\otimes \\mathbb{1} \\otimes Z$$</p>\n<p>In this demo we will see how to implement three multi-bit functions as quantum oracles, and their effect on a quantum state.\nAfter that, you'll try to implement the oracles for two more functions on your own!</p>\n"
6749
+ "content": "<p>In the quantum scenario, the classical function you're working with is implemented as a quantum oracle - a &quot;black box&quot; operation used as input to another algorithm. This operation is implemented in a way which allows you to perform calculations not only on individual inputs, but also on superpositions of inputs.</p>\n<p>To enable the oracle to act on quantum states instead of classical values, the integer input $x$ is represented in binary $x = (x_{0}, x_{1}, \\dots, x_{N-1})$,\nand encoded into an $N$-qubit register: $\\ket{\\vec{x} } = \\ket{x_{0} } \\otimes \\ket{x_{1} } \\otimes \\cdots \\otimes \\ket{x_{N-1} }$.\nThe phase oracle $U_f$ for this function is defined as follows:</p>\n<p>$$U_f \\ket{\\vec{x} } = (-1)^{f(x)} \\ket{\\vec{x} }$$</p>\n<p>The function $f$ can return only two values, 0 or 1, which result in no phase change or multiplication by a relative phase $-1$, respectively.</p>\n<p>The effect of such an oracle on any single basis state isn't particularly interesting: it just adds a global phase which isn't something you can observe. However, if you apply this oracle to a <em>superposition</em> of basis states, its effect becomes noticeable.\nRemember that quantum operations are linear: if you define the effect of an operation on the basis states, you'll be able to deduce its effect on superposition states (which are just linear combinations of the basis states) using its linearity.</p>\n<p>Let's see how to implement several examples of multi-bit constant and balanced functions as phase oracles in Q#.</p>\n<ol>\n<li>$f(x) \\equiv 0$</li>\n</ol>\n<p>This is the easiest function to implement: if $f(x) \\equiv 0$,</p>\n<p>$$U_f \\ket{x} \\equiv (-1)^0 \\ket{x} = \\ket{x}$$</p>\n<p>This means that $U_f$ is an identity - a transformation which does absolutely nothing!</p>\n<ol start=\"2\">\n<li>$f(x) \\equiv 1$</li>\n</ol>\n<p>The second constant function is slightly trickier: if $f(x) \\equiv 1$</p>\n<p>$$U_f \\ket{x} \\equiv (-1)^1 \\ket{x} = - \\ket{x}$$</p>\n<p>Now $U_f$ is a negative identity, that is, a transformation which applies a global phase of $-1$ to the state.\nA lot of algorithms just ignore the global phase accumulated in them, since it isn't observable.\nHowever, if you want to be meticulous, you can use the $R$ gate which performs a given rotation around the given axis.\nWhen called with <code>PauliI</code> axis, this operation applies a global phase to the given qubit.\nYou can use any qubit to apply this gate, for example, <code>qs[0]</code>.</p>\n<ol start=\"3\">\n<li>$f(x) = x \\bmod 2$</li>\n</ol>\n<p>The binary representation of $x$ is $x = (x_{0}, x_{1}, \\dots, x_{N-1})$, with the least significant bit encoded in the last bit (stored in the last qubit of the input array). Then you can rewrite the function as</p>\n<p>$$f(x) = x_{N-1}$$</p>\n<p>Let's use this in the oracle effect expression:</p>\n<p>$$U_f \\ket{x} = (-1)^{f(x)} \\ket{x} = (-1)^{x_{N-1}} \\ket{x} = \\ket{x_{0} } \\otimes \\cdots \\otimes \\ket{x_{N-2} } \\otimes (-1)^{x_{N-1}} \\ket{x_{N-1}}$$</p>\n<p>This means that you only need to use the last qubit in the implementation: do nothing if it's $\\ket{0}$ and apply a phase of $-1$ if it's $\\ket{1}$. This is exactly the effect of the $Z$ gate!</p>\n<p>You can write out the oracle unitary as follows:</p>\n<p>$$U_f = \\mathbb{1} \\otimes \\cdots \\otimes \\mathbb{1} \\otimes Z$$</p>\n<p>In the following demo you'll see how to implement three multi-bit functions as quantum oracles, and their effect on a quantum state.\nAfter that, you'll try to implement the oracles for two more functions on your own!</p>\n"
6750
6750
  },
6751
6751
  {
6752
6752
  "type": "example",
@@ -6773,7 +6773,7 @@ export default {
6773
6773
  "items": [
6774
6774
  {
6775
6775
  "type": "text-content",
6776
- "content": "<p>The binary representation of $x$ is $x = (x_{0}, x_{1}, \\dots, x_{N-1})$, with the most significant bit encoded in the first bit (stored in the first qubit of the input array). Then we can rewrite the function as</p>\n<p>$$f(x) = x_0$$</p>\n<p>and its effect on the quantum state as</p>\n<p>$$U_f \\ket{x} = (-1)^{f(x)} \\ket{x} = (-1)^{x_0} \\ket{x} = (-1)^{x_0} \\ket{x_{0} } \\otimes \\ket{x_1} \\otimes \\cdots \\otimes \\ket{x_{N-1}}$$</p>\n<p>As we've seen in the previous oracle, this can be achieved by applying a $Z$ gate to the first qubit.</p>\n"
6776
+ "content": "<p>The binary representation of $x$ is $x = (x_{0}, x_{1}, \\dots, x_{N-1})$, with the most significant bit encoded in the first bit (stored in the first qubit of the input array). Then, you can rewrite the function as</p>\n<p>$$f(x) = x_0$$</p>\n<p>and its effect on the quantum state as</p>\n<p>$$U_f \\ket{x} = (-1)^{f(x)} \\ket{x} = (-1)^{x_0} \\ket{x} = (-1)^{x_0} \\ket{x_{0} } \\otimes \\ket{x_1} \\otimes \\cdots \\otimes \\ket{x_{N-1}}$$</p>\n<p>As you've seen in the previous exercise, this can be achieved by applying a $Z$ gate to the first qubit.</p>\n"
6777
6777
  },
6778
6778
  {
6779
6779
  "type": "solution",
@@ -6801,7 +6801,7 @@ export default {
6801
6801
  "items": [
6802
6802
  {
6803
6803
  "type": "text-content",
6804
- "content": "<p>In this oracle the answer depends on all bits of the input. We can write $f(x)$ as follows (here $\\bigoplus$ denotes sum modulo $2$):</p>\n<p>$$f(x) = \\bigoplus_{k=0}^{N-1} x_k$$</p>\n<p>Let's substitute this expression in the expression for the oracle effect on the quantum state:</p>\n<p>$$U_f \\ket{x} = (-1)^{f(x)} \\ket{x} = (-1)^{\\bigoplus_{k=0}^{N-1} x_k} \\ket{x}$$</p>\n<p>Since $(-1)^2 = 1$, we can replace sum modulo $2$ with a regular sum in the exponent. Then we'll be able to rewrite it as a product of individual exponents for each bit:</p>\n<p>$$U_f \\ket{x} = (-1)^{\\sum_{k=0}^{N-1} x_k} \\ket{x} = \\prod_{k=0}^{N-1} {(-1)^{x_k}} \\ket{x}$$</p>\n<p>Now let's spell out the system state as a tensor product of individual qubit states:</p>\n<p>$$U_f \\ket{x} = \\prod_{k=0}^{N-1} {(-1)^{x_k}} \\cdot \\ket{x_{0} } \\otimes \\cdots \\otimes \\ket{x_{N-1}}$$</p>\n<p>Tensor product is a linear operation, so we can bring each $(-1)^{x_k}$ scalar factor in next to the corresponding $\\ket{x_k}$:</p>\n<p>$$U_f \\ket{x} = (-1)^{x_0} \\ket{x_{k}} \\otimes \\dots \\otimes (-1)^{x_{N-1}} \\ket{x_{N-1}} = \\bigotimes_{k=0}^{N-1} (-1)^{x_k} \\ket{x_{k}}$$</p>\n<p>As we've seen in the previous oracle, this can be achieved by applying a $Z$ gate to each qubit.</p>\n"
6804
+ "content": "<p>In this oracle the answer depends on all bits of the input. You can write $f(x)$ as follows (here $\\bigoplus$ denotes sum modulo $2$):</p>\n<p>$$f(x) = \\bigoplus_{k=0}^{N-1} x_k$$</p>\n<p>Let's substitute this expression in the expression for the oracle effect on the quantum state:</p>\n<p>$$U_f \\ket{x} = (-1)^{f(x)} \\ket{x} = (-1)^{\\bigoplus_{k=0}^{N-1} x_k} \\ket{x}$$</p>\n<p>Since $(-1)^2 = 1$, you can replace sum modulo $2$ with a regular sum in the exponent. Then you'll be able to rewrite it as a product of individual exponents for each bit:</p>\n<p>$$U_f \\ket{x} = (-1)^{\\sum_{k=0}^{N-1} x_k} \\ket{x} = \\prod_{k=0}^{N-1} {(-1)^{x_k}} \\ket{x}$$</p>\n<p>Now let's spell out the system state as a tensor product of individual qubit states:</p>\n<p>$$U_f \\ket{x} = \\prod_{k=0}^{N-1} {(-1)^{x_k}} \\cdot \\ket{x_{0} } \\otimes \\cdots \\otimes \\ket{x_{N-1}}$$</p>\n<p>Tensor product is a linear operation, so you can bring each $(-1)^{x_k}$ scalar factor in next to the corresponding $\\ket{x_k}$:</p>\n<p>$$U_f \\ket{x} = (-1)^{x_0} \\ket{x_{k}} \\otimes \\dots \\otimes (-1)^{x_{N-1}} \\ket{x_{N-1}} = \\bigotimes_{k=0}^{N-1} (-1)^{x_k} \\ket{x_{k}}$$</p>\n<p>As you've seen in the previous oracle, this can be achieved by applying a $Z$ gate to each qubit.</p>\n"
6805
6805
  },
6806
6806
  {
6807
6807
  "type": "solution",
@@ -6818,7 +6818,7 @@ export default {
6818
6818
  "items": [
6819
6819
  {
6820
6820
  "type": "text-content",
6821
- "content": "<p>Now let's return to the problem of figuring out whether the given function is constant or balanced.\nWe'll present the algorithm in detail step-by-step and summarize it in the end.</p>\n<h3>Inputs</h3>\n<p>You are given the number of bits in the oracle input $N$ and the oracle itself - a &quot;black box&quot; operation $U_f$ that implements a classical function $f(x)$. You are guaranteed that the function implemented by the oracle is either constant or balanced.</p>\n<h3>The starting state</h3>\n<p>The algorithm starts with $N$ qubits in the $\\ket{0...0} = \\ket{0}^{\\otimes N}$ state.</p>\n<h3>Step 1. Apply Hadamard transform to each qubit</h3>\n<p>Applying the $H$ gate to one qubit in the $\\ket{0}$ state converts it to the $\\frac{1}{\\sqrt2} \\big(\\ket{0} + \\ket{1} \\big)$ state, which is an equal superposition of both basis states on one qubit.</p>\n<p>If we apply the $H$ gate to each of the two qubits in the $\\ket{00}$ state, we'll get</p>\n<p>$$(H \\otimes H) \\ket{00} = \\big(H \\ket{0} \\big) \\otimes \\big(H \\ket{0}\\big) = \\left(\\frac{1}{\\sqrt2} \\big(\\ket{0} + \\ket{1} \\big)\\right) \\otimes \\left(\\frac{1}{\\sqrt2} \\big(\\ket{0} + \\ket{1} \\big)\\right) = \\frac{1}{2} \\big(\\ket{00} + \\ket{01} + \\ket{10} + \\ket{11} \\big)$$</p>\n<p>This is just an equal superposition of all basis states on two qubits!\nWe can extend the same thinking to applying the $H$ gate to each of the $N$ qubits in the $\\ket{0...0}$ state to conclude that this transforms them into a state that is an equal superposition of all basis states on $N$ qubits.</p>\n<p>Mathematically the transformation &quot;apply $H$ gate to each of the $N$ qubits&quot; can be denoted as $H^{\\otimes N}$. After applying this transformation we'll get the following state:</p>\n<p>$$H^{\\otimes N} \\ket{0}^{\\otimes N} = \\big( H\\ket{0} \\big)^{\\otimes N} = \\left( \\frac{1}{\\sqrt2} \\big(\\ket{0} + \\ket{1} \\big) \\right)^{\\otimes N} = \\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} \\ket{x}$$</p>\n<h3>Step 2. Apply the oracle</h3>\n<p>This step is the only step in which we use the knowledge of the classical function, given to us as the quantum oracle.\nThis step will keep the amplitudes of the basis states for which $f(x) = 0$ unchanged, and multiply the amplitudes of the basis states for which $f(x) = 1$ by $-1$.</p>\n<p>Mathematically the results of oracle application can be written as follows:</p>\n<p>$$U_f \\left(\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} \\ket{x} \\right) = \\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} U_f\\ket{x} = \\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x)} \\ket{x}$$</p>\n<h3>Step 3. Apply Hadamard transform to each qubit again</h3>\n<p>In this step, let's not worry about the whole expression for the state of the qubits after applying the $H$ gates to them; instead let's calculate only the resulting amplitude of the basis state $\\ket{0}^{\\otimes N}$.</p>\n<p>Consider one of the basis states $\\ket{x}$ in the expression $\\sum_{x=0}^{2^N-1} (-1)^{f(x)} \\ket{x}$.<br />\nIt can be written as $\\ket{x} = \\ket{x_{0} } \\otimes \\cdots \\otimes \\ket{x_{N-1}}$, where each $\\ket{x_k}$ is either $\\ket{0}$ or $\\ket{1}$.<br />\nWhen we apply the $H$ gates to $\\ket{x}$, we'll get $H^{\\otimes N} \\ket{x} = H\\ket{x_{0} } \\otimes \\cdots \\otimes H\\ket{x_{N-1}}$, where each term of the tensor product is either $H\\ket{0} = \\frac{1}{\\sqrt2}\\big(\\ket{0} + \\ket{1} \\big) = \\ket{+}$ or $H\\ket{1} = \\frac{1}{\\sqrt2}\\big(\\ket{0} - \\ket{1} \\big) = \\ket{-}$.\nIf we open the brackets in this tensor product, we'll get a superposition of all $N$-qubit basis states, each of them with amplitude $\\frac{1}{\\sqrt{2^N}}$ or $-\\frac{1}{\\sqrt{2^N}}$ — and, since the amplitude of the $\\ket{0}$ state in both $\\ket{+}$ and $\\ket{-}$ is positive, we know that the amplitude of the basis state $\\ket{0}^{\\otimes N}$ will end up positive, i.e., $\\frac{1}{\\sqrt{2^N}}$.</p>\n<p>Now we can calculate the amplitude of the $\\ket{0}^{\\otimes N}$ state in the expression $H^{\\otimes N} \\left( \\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x)} \\ket{x} \\right)$: in each of the $2^N$ terms of the sum its amplitude is $\\frac{1}{\\sqrt{2^N}}$; therefore, we get the total amplitude</p>\n<p>$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x)} \\frac{1}{\\sqrt{2^N}} = \\frac{1}{2^N} \\sum_{x=0}^{2^N-1} (-1)^{f(x)}$$</p>\n<h3>Step 4. Perform measurements and interpret the result</h3>\n<p>So far we did not use the fact that the function we are given is constant or balanced. Let's see how this affects the amplitude of the $\\ket{0}^{\\otimes N}$ state.</p>\n<ul>\n<li>\n<p>If the function is constant, $f(x) = C$ (either always $0$ or always $1$), we get<br />\n$$\\frac{1}{2^N} \\sum_{x=0}^{2^N-1} (-1)^{f(x)} = \\frac{1}{2^N} \\sum_{x=0}^{2^N-1} (-1)^{C} = \\frac{1}{2^N} \\cdot 2^N (-1)^C = (-1)^C$$\nSince the sum of squares of amplitudes of all basis states always equals $1$, the amplitudes of the rest of the basis states have to be 0 - this means that the state of the qubits after step 3 <em>is</em> $\\ket{0}^{\\otimes N}$.</p>\n</li>\n<li>\n<p>If the function is balanced, i.e., returns $0$ for exactly half of the inputs and $1$ for the other half of the inputs, exactly half of the terms in the sum $\\frac{1}{2^N} \\sum_{x=0}^{2^N-1} (-1)^{f(x)}$ will be $1$ and the other half of the terms will be $-1$, and they will all cancel out, leaving the amplitude of $\\ket{0}^{\\otimes N}$ equal to $0$.</p>\n</li>\n</ul>\n<p>Now, what happens when we measure all qubits? (Remember that the probability of getting a certain state as a result of measurement equals to the square of the amplitude of this state.)</p>\n<p>If the function is constant, the only measurement result we can get is all zeros - the probability of getting any other result is $0$. If the function is balanced, the probability of getting all zeros is $0$, so we'll get any measurement result except this.</p>\n<p>This is exactly the last step of the algorithm: <strong>measure all qubits, if all measurement results are 0, the function is constant, otherwise it is balanced</strong>.</p>\n<h3>Summary</h3>\n<p>In the end the algorithm is very straightforward:</p>\n<ol>\n<li>Apply the $H$ gate to each qubit.</li>\n<li>Apply the oracle.</li>\n<li>Apply the $H$ gate to each qubit again.</li>\n<li>Measure all qubits.</li>\n<li>If all qubits were measured in $\\ket{0}$ state, the function is constant, otherwise it is balanced.</li>\n</ol>\n<p>Note that this algorithm requires only $1$ oracle call, and always produces the correct result!</p>\n"
6821
+ "content": "<p>Now let's return to the problem of figuring out whether the given function is constant or balanced.\nThe following sections present the algorithm in detail step-by-step.</p>\n<h3>Inputs</h3>\n<p>You are given the number of bits in the oracle input $N$ and the oracle itself - a &quot;black box&quot; operation $U_f$ that implements a classical function $f(x)$. You are guaranteed that the function implemented by the oracle is either constant or balanced.</p>\n<h3>The starting state</h3>\n<p>The algorithm starts with $N$ qubits in the $\\ket{0...0} = \\ket{0}^{\\otimes N}$ state.</p>\n<h3>Step 1. Apply Hadamard transform to each qubit</h3>\n<p>Applying the $H$ gate to one qubit in the $\\ket{0}$ state converts it to the $\\frac{1}{\\sqrt2} \\big(\\ket{0} + \\ket{1} \\big)$ state, which is an equal superposition of both basis states on one qubit.</p>\n<p>If you apply the $H$ gate to each of the two qubits in the $\\ket{00}$ state, you get</p>\n<p>$$(H \\otimes H) \\ket{00} = \\big(H \\ket{0} \\big) \\otimes \\big(H \\ket{0}\\big) = \\left(\\frac{1}{\\sqrt2} \\big(\\ket{0} + \\ket{1} \\big)\\right) \\otimes \\left(\\frac{1}{\\sqrt2} \\big(\\ket{0} + \\ket{1} \\big)\\right) = \\frac{1}{2} \\big(\\ket{00} + \\ket{01} + \\ket{10} + \\ket{11} \\big)$$</p>\n<p>This is just an equal superposition of all basis states on two qubits!\nYou can extend the same thinking to applying the $H$ gate to each of the $N$ qubits in the $\\ket{0...0}$ state to conclude that this transforms them into a state that is an equal superposition of all basis states on $N$ qubits.</p>\n<p>Mathematically, the transformation &quot;apply $H$ gate to each of the $N$ qubits&quot; can be denoted as $H^{\\otimes N}$. After applying this transformation, you get the following state:</p>\n<p>$$H^{\\otimes N} \\ket{0}^{\\otimes N} = \\big( H\\ket{0} \\big)^{\\otimes N} = \\left( \\frac{1}{\\sqrt2} \\big(\\ket{0} + \\ket{1} \\big) \\right)^{\\otimes N} = \\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} \\ket{x}$$</p>\n<h3>Step 2. Apply the oracle</h3>\n<p>This step is the only step in which you use the knowledge of the classical function, given as the quantum oracle.\nThis step keep the amplitudes of the basis states for which $f(x) = 0$ unchanged, and multiply the amplitudes of the basis states for which $f(x) = 1$ by $-1$.</p>\n<p>Mathematically, the results of oracle application can be written as follows:</p>\n<p>$$U_f \\left(\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} \\ket{x} \\right) = \\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} U_f\\ket{x} = \\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x)} \\ket{x}$$</p>\n<h3>Step 3. Apply Hadamard transform to each qubit again</h3>\n<p>In this step, you don't need to worry about the whole expression for the state of the qubits after applying the $H$ gates to them; it's enough to calculate only the resulting amplitude of the basis state $\\ket{0}^{\\otimes N}$.</p>\n<p>Consider one of the basis states $\\ket{x}$ in the expression $\\sum_{x=0}^{2^N-1} (-1)^{f(x)} \\ket{x}$.<br />\nIt can be written as $\\ket{x} = \\ket{x_{0} } \\otimes \\cdots \\otimes \\ket{x_{N-1}}$, where each $\\ket{x_k}$ is either $\\ket{0}$ or $\\ket{1}$.<br />\nWhen you apply the $H$ gates to $\\ket{x}$, we'll get $H^{\\otimes N} \\ket{x} = H\\ket{x_{0} } \\otimes \\cdots \\otimes H\\ket{x_{N-1}}$, where each term of the tensor product is either $H\\ket{0} = \\frac{1}{\\sqrt2}\\big(\\ket{0} + \\ket{1} \\big) = \\ket{+}$ or $H\\ket{1} = \\frac{1}{\\sqrt2}\\big(\\ket{0} - \\ket{1} \\big) = \\ket{-}$.\nIf you open the brackets in this tensor product, you get a superposition of all $N$-qubit basis states, each of them with amplitude $\\frac{1}{\\sqrt{2^N}}$ or $-\\frac{1}{\\sqrt{2^N}}$ — and, since the amplitude of the $\\ket{0}$ state in both $\\ket{+}$ and $\\ket{-}$ is positive, you know that the amplitude of the basis state $\\ket{0}^{\\otimes N}$ ends up positive, that is, $\\frac{1}{\\sqrt{2^N}}$.</p>\n<p>Now you can calculate the amplitude of the $\\ket{0}^{\\otimes N}$ state in the expression $H^{\\otimes N} \\left( \\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x)} \\ket{x} \\right)$: in each of the $2^N$ terms of the sum its amplitude is $\\frac{1}{\\sqrt{2^N}}$. Therefore, you get the total amplitude</p>\n<p>$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x)} \\frac{1}{\\sqrt{2^N}} = \\frac{1}{2^N} \\sum_{x=0}^{2^N-1} (-1)^{f(x)}$$</p>\n<h3>Step 4. Perform measurements and interpret the result</h3>\n<p>So far, you didn't use the fact that the function you are given is constant or balanced. Let's see how this affects the amplitude of the $\\ket{0}^{\\otimes N}$ state.</p>\n<ul>\n<li>\n<p>If the function is constant, $f(x) = C$ (either always $0$ or always $1$), you get<br />\n$$\\frac{1}{2^N} \\sum_{x=0}^{2^N-1} (-1)^{f(x)} = \\frac{1}{2^N} \\sum_{x=0}^{2^N-1} (-1)^{C} = \\frac{1}{2^N} \\cdot 2^N (-1)^C = (-1)^C$$\nSince the sum of squares of amplitudes of all basis states always equals $1$, the amplitudes of the rest of the basis states have to be 0 - this means that the state of the qubits after step 3 <em>is</em> $\\ket{0}^{\\otimes N}$.</p>\n</li>\n<li>\n<p>If the function is balanced, that is, returns $0$ for exactly half of the inputs and $1$ for the other half of the inputs, exactly half of the terms in the sum $\\frac{1}{2^N} \\sum_{x=0}^{2^N-1} (-1)^{f(x)}$ will be $1$ and the other half of the terms will be $-1$, and they will all cancel out, leaving the amplitude of $\\ket{0}^{\\otimes N}$ equal to $0$.</p>\n</li>\n</ul>\n<p>Now, what happens when you measure all qubits? (Remember that the probability of getting a certain state as a result of measurement equals to the square of the amplitude of this state.)</p>\n<p>If the function is constant, the only measurement result you can get is all zeros - the probability of getting any other result is $0$. If the function is balanced, the probability of getting all zeros is $0$, so you'll get any measurement result except this.</p>\n<p>This is exactly the last step of the algorithm: <strong>measure all qubits, if all measurement results are 0, the function is constant, otherwise it's balanced</strong>.</p>\n<h3>Summary</h3>\n<p>In the end, the algorithm is very straightforward:</p>\n<ol>\n<li>Apply the $H$ gate to each qubit.</li>\n<li>Apply the oracle.</li>\n<li>Apply the $H$ gate to each qubit again.</li>\n<li>Measure all qubits.</li>\n<li>If all qubits are measured in $\\ket{0}$ state, the function is constant, otherwise it's balanced.</li>\n</ol>\n<p>Note that this algorithm requires only $1$ oracle call, and always produces the correct result!</p>\n"
6822
6822
  }
6823
6823
  ]
6824
6824
  },
@@ -6840,7 +6840,7 @@ export default {
6840
6840
  "items": [
6841
6841
  {
6842
6842
  "type": "text-content",
6843
- "content": "<p>Follow the algorithm as outlined in the previous section:</p>\n<ol>\n<li>Allocate $N$ qubits - they start in the $\\ket{0}$ state.</li>\n<li>Apply the $H$ gate to each qubit. You can use <code>ApplyToEach</code> operation for this, or a <code>for</code> loop.</li>\n<li>Apply the oracle. The syntax for applying the oracle is the same as for applying any other gate or operation.</li>\n<li>Apply the $H$ gate to each qubit again.</li>\n<li>Measure each of the qubits. If any of the measurement results is <code>One</code>, the function is balanced.\nWe cannot return <code>false</code> as soon as we encounter a <code>One</code> result, though, since we need to return all qubits to $\\ket{0}$ state first.\nInstead, we'll update the mutable variable that stores our result and continue through the rest of the loop.</li>\n</ol>\n"
6843
+ "content": "<p>Follow the algorithm as outlined in the previous section:</p>\n<ol>\n<li>Allocate $N$ qubits - they start in the $\\ket{0}$ state.</li>\n<li>Apply the $H$ gate to each qubit. You can use <code>ApplyToEach</code> operation for this, or a <code>for</code> loop.</li>\n<li>Apply the oracle. The syntax for applying the oracle is the same as for applying any other gate or operation.</li>\n<li>Apply the $H$ gate to each qubit again.</li>\n<li>Measure each of the qubits. If any of the measurement results is <code>One</code>, the function is balanced.\nYou can't return <code>false</code> as soon as you encounter a <code>One</code> result, though, since you need to return all qubits to $\\ket{0}$ state first.\nInstead, you update the mutable variable that stores your result and continue through the rest of the loop.</li>\n</ol>\n"
6844
6844
  },
6845
6845
  {
6846
6846
  "type": "solution",
@@ -6873,7 +6873,7 @@ export default {
6873
6873
  "items": [
6874
6874
  {
6875
6875
  "type": "text-content",
6876
- "content": "<p>To wrap up our discussion in this kata, let's take a look at a problem solved using a similar approach - the Bernstein-Vazirani algorithm.\nIn this problem, you are also given an oracle implementing an $N$-bit function $f(x): \\{0, 1\\}^N \\to \\{0, 1\\}$.\nHowever, this time the function is guaranteed to be a <em>scalar product function</em>, that is, there exists an $N$-bit string $s$\nthat allows the following representation ($\\cdot$ is bitwise inner product of integers modulo $2$):</p>\n<p>$$f(x) = x \\cdot s = \\sum_{k=0}^{N-1} x_k s_k \\bmod 2$$</p>\n<p>The task is to recover the hidden bit string $s$.</p>\n<p><strong>Examples</strong></p>\n<ul>\n<li>$f(x) \\equiv 0$ is an example of such a function with $s = 0, \\dots, 0$.</li>\n<li>$f(x) = 1 \\text{ if x has odd number of 1s, and } 0 \\text{ otherwise }$ is another example of such a function, with $s = 1, \\dots, 1$.</li>\n</ul>\n<p>If we solve this problem classically, how many calls to the given function will we need?\nWe'd need to use one query to recover each bit of $s$ (the query for $k$-th bit can be a bit string with $1$ in the $k$-th bit and zeros in all other positions), for a total of $N$ queries.</p>\n<p>What about the quantum scenario?\nIt turns out that the algorithm that allows us to solve this problem looks just like Deutsch-Jozsa algorithm,\nexcept for the way we interpret the measurement results on the last step. To see this, we'll need to take another look\nat the math involved in applying Hadamard gates to multiple qubits.</p>\n<h3>Apply Hadamard transform to each qubit: a different view</h3>\n<p>When we apply an $H$ gate to a single qubit in the basis state $\\ket{x}$, we can write the result as the following sum:</p>\n<p>$$H\\ket{x} = \\frac1{\\sqrt2} (\\ket{0} + (-1)^{x} \\ket{1}) = \\frac1{\\sqrt2} \\sum_{z \\in {0, 1}} (-1)^{x \\cdot z} \\ket{z}$$</p>\n<p>If we use this representation to spell out the result of applying an $H$ gate to each qubit of an $N$-qubit basis state\n$\\ket{x} = \\ket{x_0}\\ket{x_1} \\dots \\ket{x_{N-1}}$, we'll get:</p>\n<p>$$H\\ket{x} = \\frac1{\\sqrt{2^N}} \\sum_{z_k \\in {0, 1}} (-1)^{x_0z_0 + \\dots + x_{N-1}z_{N-1}} \\ket{z_0}\\ket{z_1} \\dots \\ket{z_{N-1}} =$$</p>\n<p>$$= \\frac1{\\sqrt{2^N}} \\sum_{z = 0}^{2^N-1} (-1)^{x \\cdot z} \\ket{z}$$</p>\n<p>With this in mind, let's revisit the algorithm and see how we can write the exact quantum state after it.</p>\n<h3>Bernstein-Vazirani algorithm</h3>\n<p>Bernstein-Vazirani algorithm follows the same outline as Deutsch-Jozsa algorithm:</p>\n<ol>\n<li>Apply the $H$ gate to each qubit.</li>\n<li>Apply the oracle.</li>\n<li>Apply the $H$ gate to each qubit again.</li>\n<li>Measure all qubits.</li>\n</ol>\n<p>We know that after the second step the qubits end up in the following state:</p>\n<p>$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x)} \\ket{x}$$</p>\n<p>Now, once we apply the Hadamard gates to each qubit, the system state becomes:</p>\n<p>$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} \\sum_{z=0}^{2^N-1} (-1)^{f(x) + x \\cdot z} \\ket{z}$$</p>\n<blockquote>\n<p>In Deutsch-Jozsa algorithm, we looked at the amplitude of the $\\ket{0}$ state in this expression, which was\n$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x)}$.</p>\n</blockquote>\n<p>Now, let's take a look at the amplitude of the $\\ket{s}$ state - the state that encodes the hidden bit string we're looking for.\nThis amplitude is</p>\n<p>$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x) + x \\cdot s}$$</p>\n<p>Since $f(x) = x \\cdot s$, for all values of $x$ $f(x) + x \\cdot s = 2 x \\cdot s$, and $(-1)^{f(x) + x \\cdot s} = 1$.\nOverall the amplitude of $\\ket{s}$ is</p>\n<p>$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} 1 = \\frac{1}{\\sqrt{2^N}} 2^N = 1$$</p>\n<p>This means that our state after applying the Hadamard gates is just $\\ket{s}$, and measuring it will give us the bit string $s$!\nAnd, same as Deutsch-Jozsa algorithm, Bernstein-Vazirani algorithm takes only one oracle call.</p>\n"
6876
+ "content": "<p>To wrap up our discussion in this kata, let's take a look at a problem solved using a similar approach - the Bernstein-Vazirani algorithm.\nIn this problem, you are also given an oracle implementing an $N$-bit function $f(x): \\{0, 1\\}^N \\to \\{0, 1\\}$.\nHowever, this time the function is guaranteed to be a <em>scalar product function</em>, that is, there exists an $N$-bit string $s$\nthat allows the following representation ($\\cdot$ is bitwise inner product of integers modulo $2$):</p>\n<p>$$f(x) = x \\cdot s = \\sum_{k=0}^{N-1} x_k s_k \\bmod 2$$</p>\n<p>The task is to recover the hidden bit string $s$.</p>\n<p><strong>Examples</strong></p>\n<ul>\n<li>$f(x) \\equiv 0$ is an example of such a function with $s = 0, \\dots, 0$.</li>\n<li>$f(x) = 1 \\text{ if x has odd number of 1s, and } 0 \\text{ otherwise }$ is another example of such a function, with $s = 1, \\dots, 1$.</li>\n</ul>\n<p>If you solve this problem classically, how many calls to the given function will you need?\nYou'd need to use one query to recover each bit of $s$ (the query for $k$-th bit can be a bit string with $1$ in the $k$-th bit and zeros in all other positions), for a total of $N$ queries.</p>\n<p>What about the quantum scenario?\nIt turns out that the algorithm that allows you to solve this problem looks just like Deutsch-Jozsa algorithm,\nexcept for the way you interpret the measurement results on the last step. To see this, you'll need to take another look\nat the math involved in applying Hadamard gates to multiple qubits.</p>\n<h3>Apply Hadamard transform to each qubit: a different view</h3>\n<p>When you apply an $H$ gate to a single qubit in the basis state $\\ket{x}$, you can write the result as the following sum:</p>\n<p>$$H\\ket{x} = \\frac1{\\sqrt2} (\\ket{0} + (-1)^{x} \\ket{1}) = \\frac1{\\sqrt2} \\sum_{z \\in {0, 1}} (-1)^{x \\cdot z} \\ket{z}$$</p>\n<p>If you use this representation to spell out the result of applying an $H$ gate to each qubit of an $N$-qubit basis state\n$\\ket{x} = \\ket{x_0}\\ket{x_1} \\dots \\ket{x_{N-1}}$, you get:</p>\n<p>$$H\\ket{x} = \\frac1{\\sqrt{2^N}} \\sum_{z_k \\in {0, 1}} (-1)^{x_0z_0 + \\dots + x_{N-1}z_{N-1}} \\ket{z_0}\\ket{z_1} \\dots \\ket{z_{N-1}} =$$</p>\n<p>$$= \\frac1{\\sqrt{2^N}} \\sum_{z = 0}^{2^N-1} (-1)^{x \\cdot z} \\ket{z}$$</p>\n<p>With this in mind, let's revisit the algorithm and see how you can write the exact quantum state after it.</p>\n<h3>Bernstein-Vazirani algorithm</h3>\n<p>Bernstein-Vazirani algorithm follows the same outline as Deutsch-Jozsa algorithm:</p>\n<ol>\n<li>Apply the $H$ gate to each qubit.</li>\n<li>Apply the oracle.</li>\n<li>Apply the $H$ gate to each qubit again.</li>\n<li>Measure all qubits.</li>\n</ol>\n<p>You know that after the second step the qubits end up in the following state:</p>\n<p>$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x)} \\ket{x}$$</p>\n<p>Now, once you apply the Hadamard gates to each qubit, the system state becomes:</p>\n<p>$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} \\sum_{z=0}^{2^N-1} (-1)^{f(x) + x \\cdot z} \\ket{z}$$</p>\n<blockquote>\n<p>In Deutsch-Jozsa algorithm, you looked at the amplitude of the $\\ket{0}$ state in this expression, which was\n$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x)}$.</p>\n</blockquote>\n<p>Now, let's take a look at the amplitude of the $\\ket{s}$ state - the state that encodes the hidden bit string you're looking for.\nThis amplitude is</p>\n<p>$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x) + x \\cdot s}$$</p>\n<p>Since $f(x) = x \\cdot s$, for all values of $x$ $f(x) + x \\cdot s = 2 x \\cdot s$, and $(-1)^{f(x) + x \\cdot s} = 1$.\nOverall the amplitude of $\\ket{s}$ is</p>\n<p>$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} 1 = \\frac{1}{\\sqrt{2^N}} 2^N = 1$$</p>\n<p>This means that the state after applying the Hadamard gates is just $\\ket{s}$, and measuring it gives you the bit string $s$!\nAnd, same as Deutsch-Jozsa algorithm, Bernstein-Vazirani algorithm takes only one oracle call.</p>\n"
6877
6877
  }
6878
6878
  ]
6879
6879
  },
@@ -6912,7 +6912,442 @@ export default {
6912
6912
  "items": [
6913
6913
  {
6914
6914
  "type": "text-content",
6915
- "content": "<p>Congratulations! In this kata you have learned Deutsch-Jozsa and Bernstein-Vazirani algorithms.</p>\n<ul>\n<li>Deutsch-Jozsa algorithm is the simplest example of a quantum algorithm that is exponentially faster than any possible deterministic algorithm for the same problem.</li>\n<li>Bernstein-Vazirani algorithm is a similar algorithm that extracts information about the hidden bit string of the given function that is known to be a scalar product function. It offers a linear speedup compared to a classical algorithm for the same problem.</li>\n<li>Quantum oracles don't allow you to evaluate the function on all inputs at once! Instead, Deutsch-Jozsa algorithm finds a clever way to aggregate information about all function values into a few bits that indicate whether they are all the same or not. Bernstein-Vazirani algorithm uses a similar approach to encode the information about the hidden bit string into the state of the qubits at the end of the algorithm.</li>\n</ul>\n"
6915
+ "content": "<p>Congratulations! In this kata you learned Deutsch-Jozsa and Bernstein-Vazirani algorithms.</p>\n<ul>\n<li>Deutsch-Jozsa algorithm is the simplest example of a quantum algorithm that is exponentially faster than any possible deterministic algorithm for the same problem.</li>\n<li>Bernstein-Vazirani algorithm is a similar algorithm that extracts information about the hidden bit string of the given function that is known to be a scalar product function. It offers a linear speedup compared to a classical algorithm for the same problem.</li>\n<li>Quantum oracles don't allow you to evaluate the function on all inputs at once! Instead, Deutsch-Jozsa algorithm finds a clever way to aggregate information about all function values into a few bits that indicate whether they are all the same or not. Bernstein-Vazirani algorithm uses a similar approach to encode the information about the hidden bit string into the state of the qubits at the end of the algorithm.</li>\n</ul>\n"
6916
+ }
6917
+ ]
6918
+ }
6919
+ ],
6920
+ "published": true
6921
+ },
6922
+ {
6923
+ "id": "grovers_search",
6924
+ "title": "Grover's Search Algorithm",
6925
+ "sections": [
6926
+ {
6927
+ "type": "lesson",
6928
+ "id": "grovers_search__overview",
6929
+ "title": "Overview",
6930
+ "items": [
6931
+ {
6932
+ "type": "text-content",
6933
+ "content": "<p>This kata introduces you to Grover's search algorithm - one of the fundamental algorithms in quantum computing.</p>\n<p><strong>This kata covers the following topics:</strong></p>\n<ul>\n<li>The general problem solved by Grover's search algorithm - the search problem</li>\n<li>Implementing Grover's algorithm in Q# for a problem provided as a quantum oracle</li>\n<li>Some of the practical aspects of this algorithm</li>\n</ul>\n<p>Note 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.</p>\n<p><strong>What you should know to start working on this kata:</strong></p>\n<ul>\n<li>Basic knowledge of quantum gates and measurements</li>\n<li>Basic understanding of quantum oracles</li>\n</ul>\n"
6934
+ }
6935
+ ]
6936
+ },
6937
+ {
6938
+ "type": "lesson",
6939
+ "id": "grovers_search__search_problem",
6940
+ "title": "The Search Problem",
6941
+ "items": [
6942
+ {
6943
+ "type": "text-content",
6944
+ "content": "<p>The problem solved by Grover's search algorithm is called the <em>search problem</em> and can be formulated as follows.\nYou are given a classical function that takes an $n$-bit input and returns a one-bit output $f(x): \\{0, 1\\}^n \\to \\{0, 1\\}$.\nThe task is to find an input $x_0$ for which $f(x_0) = 1$.</p>\n<p>Importantly, you don't have any information about the internal structure of the function $f$! It is given to you as a &quot;black box&quot; that allows you to evaluate the value of the function for any input you want, but not to learn anything about how it works.</p>\n<blockquote>\n<p>This problem is sometimes described as <em>function inversion</em>, since it tries to evaluate the inverse of the function $f$.</p>\n</blockquote>\n<h3>Classical solution</h3>\n<p>If you solve the search problem classically, how many calls to the given function will you need?</p>\n<p>Since you don't know anything about the internal structure of the function, you can't do better than the brute force approach.\nYou need to try evaluating the function on different inputs until you either hit the input which produces the desired output or run out of inputs to try and conclude that the desired input doesn't exist.\nThis requires $O(2^n)$ function evaluations, since in the worst case scenario you'll need to try all inputs.</p>\n<h3>Example problems</h3>\n<p>Any problem that allows you to check whether a given value of $x$ is a solution to it can be formulated as a search problem,\nif you define $f(x)$ as &quot;$1$ if $x$ is a solution to the problem, and $0$ otherwise&quot;.</p>\n<p>Some of the problems can be formulated as a search problem more naturally than the others.\nFor example:</p>\n<ul>\n<li>The Boolean satisfiability problem aims to find an assignment of variables in the given Boolean formula\nfor which the formula evaluates to true (or to decide that such assignment doesn't exist).\nThis is exactly the definition of the search problem, with the input $x$ defined as the set of variables used in the formula and $f(x)$ - as the formula itself.</li>\n<li>Vertex coloring problem aims to find an assignment of colors to the vertices of a given graph that would satisfy the given constraints. In this case, $x$ describes the colors assigned to the vertices, and $f(x)$ is $1$ if the constraints are satisfied or $0$ otherwise.</li>\n</ul>\n<p>You will learn more about appliyng Grover's search to solving specific problems in later katas.\nThis kata focuses on Grover's search algorithm itself rather than on applying it to a specific problem, so\nit uses a very simple function definition as an example.</p>\n<p>Let's define a fixed bit string $p$ of length $P$. The function $f(x)$ is $1$ if the bit string $x$ starts with $p$, and $0$ otherwise.</p>\n<p>This function has a very simple implementation and will allow you to experiment with instances of the search problem with different parameters easily.\nFor example, if the length of the bit string $p$ equals the length of the input, the function $f(x) = 1$ if $x = p$, and $0$ otherwise. In this case, the equation $f(x) = 1$ has exactly one solution, the bit string $p$ itself.</p>\n"
6945
+ }
6946
+ ]
6947
+ },
6948
+ {
6949
+ "type": "exercise",
6950
+ "id": "grovers_search__prefix_oracle",
6951
+ "title": "Marking Oracle for Prefix Function",
6952
+ "description": {
6953
+ "type": "text-content",
6954
+ "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>$N$ qubits in an arbitrary state $\\ket{x}$ (input/query register).</li>\n<li>A qubit in an arbitrary state $\\ket{y}$ (output/target qubit).</li>\n<li>A bit pattern $p$ of length $P$ represented as a <code>Bool[]</code> ($1 ≤ P ≤ N$).</li>\n</ol>\n<p><strong>Goal:</strong>\nImplement a marking oracle which flips the state of $\\ket{y}$ if the pattern $p$ is the prefix of the input register $\\ket{x}$, that is, for all $j$ between $0$ and $P - 1$, inclusive, $p_j = x_j$. (<code>false</code> and <code>true</code> values represent states $\\ket{0}$ and $\\ket{1}$, respectively).</p>\n<p>For example, for $N = 3$ two bit strings start with the prefix <code>[true, false]</code>: <code>[true, false, false]</code> and <code>[true, false, true]</code>.</p>\n<p>Leave 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.</p>\n"
6955
+ },
6956
+ "sourceIds": [
6957
+ "grovers_search__prefix_oracle__Verification.qs",
6958
+ "KatasLibrary.qs"
6959
+ ],
6960
+ "placeholderCode": "namespace Kata {\n operation Oracle_StartsWith(x : Qubit[], y : Qubit, p : Bool[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n } \n}\n",
6961
+ "explainedSolution": {
6962
+ "type": "explained-solution",
6963
+ "items": [
6964
+ {
6965
+ "type": "text-content",
6966
+ "content": "<p>In this problem, the value of the function we're evaluating does not depend on the state of the qubits after qubit $P$. This means that we can just ignore them and consider only the qubits that matter - <code>x[... Length(p) - 1]</code>.</p>\n<p>Once we do that, the problem becomes much simpler: flip the state of the target qubit if the input qubits are in the given state. That's the definition of a controlled gate with arbitrary controls, and we can apply that easily using the library operation <code>ApplyControlledOnBitString</code>.</p>\n"
6967
+ },
6968
+ {
6969
+ "type": "solution",
6970
+ "id": "grovers_search__prefix_oracle_solution",
6971
+ "code": "namespace Kata {\n operation Oracle_StartsWith(x : Qubit[], y : Qubit, p : Bool[]) : Unit is Adj + Ctl {\n ApplyControlledOnBitString(p, X, x[... Length(p) - 1], y);\n }\n}\n"
6972
+ }
6973
+ ]
6974
+ }
6975
+ },
6976
+ {
6977
+ "type": "lesson",
6978
+ "id": "grovers_search__algorithm",
6979
+ "title": "Grover's Search Algorithm",
6980
+ "items": [
6981
+ {
6982
+ "type": "text-content",
6983
+ "content": "<h3>Inputs</h3>\n<p>You are given the number of bits in the function input $n$ and the phase oracle for the problem we're solving - a &quot;black box&quot; quantum operation $U_f$ that implements a classical function $f(x)$.</p>\n<p>As 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:</p>\n<p>$$U_f \\ket{x} = (-1)^{f(x)} \\ket{x}$$</p>\n<blockquote>\n<p>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.</p>\n</blockquote>\n<h3>Algorithm outline</h3>\n<p>The high-level outline of the algorithm is very simple:</p>\n<ol>\n<li>Initialize the quantum system to a well-known starting state.</li>\n<li>Apply a fixed sequence of &quot;Grover iterations&quot; several times. Each iteration is implemented as pair of operations that includes one call of the oracle &quot;black box&quot;.</li>\n<li>Finally, measuring all qubits will produce the desired output with high probability.</li>\n</ol>\n<p>Let's take a closer look at the algorithm.</p>\n<blockquote>\n<p>We will use a convenient visualization of the algorithm steps rather than mathematical derivation.\nThey are equivalent, but the visual representation is much easier to follow.</p>\n</blockquote>\n<h3>Initial state and definitions</h3>\n<p>Grover'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}} $$</p>\n<p>When this superposition is considered in the context of the equation $f(x) = 1$,\nall the basis states can be split in two groups: &quot;good&quot; (solutions) and &quot;bad&quot; (non-solutions).\nIf the number of states for which $f(x)=1$ (the number of equation solutions) is $M$,\ntwo uniform superpositions of &quot;good&quot; and &quot;bad&quot; states can be defined as follows:</p>\n<p>$$\\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}}$$</p>\n<p>Now, 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}}$$</p>\n<p>The 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$:</p>\n<p>$$\\sin \\theta = \\sqrt{\\frac{M}{N}}, \\cos \\theta = \\sqrt{\\frac{N-M}{N}}$$</p>\n<p>With this replacement, the initial state can be written as</p>\n<p>$$\\ket{\\text{all}} = \\sin \\theta \\ket{\\text{good}} + \\cos \\theta \\ket{\\text{bad}}$$</p>\n<p>The 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.</p>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<p><svg width=\"447\" height=\"366\" overflow=\"hidden\" version=\"1.1\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"><defs><linearGradient id=\"fill0\" x1=\"2824\" x2=\"2824\" y1=\"1084\" y2=\"1211\" gradientUnits=\"userSpaceOnUse\" spreadMethod=\"reflect\"><stop offset=\"0\"/><stop offset=\".0292\"/><stop offset=\".3\"/><stop offset=\"1\"/></linearGradient><linearGradient id=\"fill3\" x1=\"2026\" x2=\"2026\" y1=\"516\" y2=\"642\" gradientUnits=\"userSpaceOnUse\" spreadMethod=\"reflect\"><stop offset=\"0\"/><stop offset=\".0292\"/><stop offset=\".3\"/><stop offset=\"1\"/></linearGradient><linearGradient id=\"fill6\" x1=\"2877\" x2=\"2877\" y1=\"1261\" y2=\"1388\" gradientUnits=\"userSpaceOnUse\" spreadMethod=\"reflect\"><stop offset=\"0\"/><stop offset=\".0292\"/><stop offset=\".3\"/><stop offset=\"1\"/></linearGradient></defs><g transform=\"matrix(.25 0 0 .25 -333 -132)\"><path d=\"m1336 1325c0-368 308-666 689-666s689 298 689 666c0 368-308 666-689 666s-689-298-689-666z\" fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" stroke-miterlimit=\"8\" stroke-width=\"6.88\"/><path d=\"m1336 1322h1373v6.88h-1373zm1348-22.1 30.7 25.6-30.7 25.6c-1.46 1.21-3.62 1.02-4.84-0.44s-1.02-3.63 0.44-4.84l27.5-22.9v5.28l-27.5-22.9c-1.46-1.21-1.66-3.38-0.44-4.84s3.38-1.65 4.84-0.44z\"/><path d=\"m2028 664v1328h-6.88v-1328zm-29 25.3 25.6-30.7 25.6 30.7c1.21 1.46 1.02 3.63-0.44 4.84-1.46 1.22-3.63 1.02-4.84-0.44l-22.9-27.5h5.28l-22.9 27.5c-1.21 1.46-3.38 1.66-4.84 0.44-1.46-1.22-1.65-3.38-0.44-4.84z\"/><path d=\"m2735 1098h6.92v83.6h-6.92z\" fill=\"url(#fill0)\" fill-rule=\"evenodd\"/><text x=\"2735.3799\" y=\"1171.12\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"83.6px\">|</text><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\" fill=\"url(#fill0)\" fill-rule=\"evenodd\"/><text x=\"2758.22\" y=\"1154.85\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"65px\">𝑎𝑙𝑙</text><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\" fill=\"url(#fill0)\" fill-rule=\"evenodd\"/><text x=\"2870.6001\" y=\"1171.29\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84px\">〉</text><path d=\"m1889 530h6.91v83.6h-6.91z\" fill=\"url(#fill3)\" fill-rule=\"evenodd\"/><text x=\"1888.67\" y=\"602.83099\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"83.6px\">|</text><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\" fill=\"url(#fill3)\" fill-rule=\"evenodd\"/><text x=\"1908.14\" y=\"603.505\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84.3px\">𝑔𝑜𝑜𝑑</text><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\" fill=\"url(#fill3)\" fill-rule=\"evenodd\"/><text x=\"2121.28\" y=\"603\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84px\">〉</text><path transform=\"matrix(1 0 0 -1 2024 1326)\" d=\"m0.823-3.34 660 163-1.64 6.68-660-163zm641 135 23.7 32.2-35.9 17.5c-1.71 0.831-3.76 0.121-4.6-1.59s-0.121-3.76 1.59-4.6l32.2-15.7-1.26 5.13-21.2-28.8c-1.12-1.53-0.798-3.68 0.731-4.81s3.68-0.798 4.81 0.731z\"/><path d=\"m2766 1275h6.92v83.6h-6.92z\" fill=\"url(#fill6)\" fill-rule=\"evenodd\"/><text x=\"2766.3201\" y=\"1348.14\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"83.6px\">|</text><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\" fill=\"url(#fill6)\" fill-rule=\"evenodd\"/><text x=\"2788.5801\" y=\"1331.87\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"65px\">𝑏𝑎𝑑</text><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\" fill=\"url(#fill6)\" fill-rule=\"evenodd\"/><text x=\"2945.6599\" y=\"1348.3\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84px\">〉</text><path d=\"m2414 1269c-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\"/><text x=\"2404.45\" y=\"1290.41\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"63.7px\">𝜃</text><path d=\"m2357 1240c6.73 27 10.1 54.7 10.1 82.5\" fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" stroke-miterlimit=\"8\" stroke-width=\"6.88\"/><path d=\"m2722 1082v-49h89v-49 49h89v49\" fill=\"none\" fill-rule=\"evenodd\" stroke=\"#0070c0\" stroke-miterlimit=\"8\" stroke-width=\"6.88\"/><text transform=\"translate(2634 952)\" fill=\"#0070c0\" font-family=\"'Segoe UI', 'Segoe UI_MSFontService', sans-serif\" font-size=\"64px\" font-weight=\"400\">The starting state</text></g></svg></p>\n<h3>Grover's iteration</h3>\n<p>Each Grover's iteration consists of two operations.</p>\n<ol>\n<li>The phase oracle $U_f$.</li>\n<li>An operation called &quot;reflection about the mean&quot;.</li>\n</ol>\n<p>Applying 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:</p>\n<p>$$U_f\\ket{\\text{good}} = -\\ket{\\text{good}}$$\n$$U_f\\ket{\\text{bad}} = \\ket{\\text{bad}}$$</p>\n<p>On 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.</p>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<p><svg width=\"475\" height=\"368\" overflow=\"hidden\" version=\"1.1\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"><defs><linearGradient id=\"fill0\" x1=\"2830\" x2=\"2830\" y1=\"1062\" y2=\"1188\" gradientUnits=\"userSpaceOnUse\" spreadMethod=\"reflect\"><stop offset=\"0\"/><stop offset=\".0292\"/><stop offset=\".3\"/><stop offset=\"1\"/></linearGradient><linearGradient id=\"fill3\" x1=\"2031\" x2=\"2031\" y1=\"494\" y2=\"621\" gradientUnits=\"userSpaceOnUse\" spreadMethod=\"reflect\"><stop offset=\"0\"/><stop offset=\".0292\"/><stop offset=\".3\"/><stop offset=\"1\"/></linearGradient><linearGradient id=\"fill6\" x1=\"2876\" x2=\"2876\" y1=\"1238\" y2=\"1365\" gradientUnits=\"userSpaceOnUse\" spreadMethod=\"reflect\"><stop offset=\"0\"/><stop offset=\".0292\"/><stop offset=\".3\"/><stop offset=\"1\"/></linearGradient></defs><g transform=\"matrix(.25 0 0 .25 -332 -127)\"><path d=\"m2423 1245c-1.41 6.5-2.11 12-2.11 16.4 0 3.35 0.51 5.81 1.53 7.39 1.01 1.57 2.66 2.35 4.94 2.35 3.35 0 6.53-2.25 9.54-6.76 3.01-4.5 5.57-11 7.66-19.4zm18.4-30.3c-3.51 0-6.75 2.22-9.73 6.65s-5.52 10.8-7.61 19h21.5c1.4-6.32 2.11-11.8 2.11-16.3 0-3.14-0.51-5.49-1.53-7.05s-2.61-2.34-4.76-2.34zm0.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.45-5.03 6.13-8.09 8.01-3.05 1.89-6.35 2.83-9.88 2.83-4.46 0-7.79-1.36-9.97-4.08-2.19-2.73-3.28-6.82-3.28-12.3 0-2.96 0.33-6.62 0.98-11 0.66-4.34 1.75-8.78 3.26-13.3s3.46-8.56 5.84-12.1 5.12-6.23 8.22-8.13 6.46-2.86 10.1-2.86z\" fill=\"#243a5e\" fill-rule=\"evenodd\"/><text x=\"2413.1399\" y=\"1267.03\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"63.7px\">𝜃</text><path d=\"m2423 1344c-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\" fill=\"#0070c0\" fill-rule=\"evenodd\"/><text x=\"2413.0701\" y=\"1366.24\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"63.7px\">𝜃</text><path d=\"m1332 1302c0-373 313-675 698-675s698 302 698 675c0 373-313 675-698 675s-698-302-698-675z\" fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" stroke-miterlimit=\"8\" stroke-width=\"6.88\"/><path d=\"m2033 633v1345h-6.88v-1345zm-29 25.3 25.6-30.7 25.6 30.7c1.21 1.46 1.02 3.63-0.44 4.84s-3.63 1.02-4.84-0.44l-22.9-27.5h5.28l-22.9 27.5c-1.21 1.46-3.38 1.66-4.84 0.44s-1.65-3.38-0.44-4.84z\"/><path d=\"m2741 1075h6.92v83.6h-6.92z\" fill=\"url(#fill0)\" fill-rule=\"evenodd\"/><text x=\"2740.6201\" y=\"1148.61\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"83.6px\">|</text><path d=\"m2788 1100c-3.08 0-5.85 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.99 0.86 1.54 2.29 2.31 4.29 2.31 1.98 0 3.92-0.85 5.82-2.56 1.9-1.7 3.86-4.14 5.89-7.3 2.02-3.16 3.45-6.8 4.29-10.9l0.4-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.66-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.44 1.21 5.23 2.32l4.14-2.97 2.87 0.72-6.6 28.5c-0.66 2.85-0.99 5.06-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1.01 0.81 1.85 0.81c0.89 0 1.85-0.36 2.87-1.1 1.02-0.73 2.46-2.13 4.31-4.2l2.56 2.52c-2.69 2.87-4.99 4.92-6.89 6.13s-3.96 1.82-6.18 1.82c-1.86 0-3.34-0.62-4.45-1.84-1.1-1.23-1.66-2.86-1.66-4.9 0-1.65 0.35-3.4 1.03-5.26l-0.58-0.18c-2.87 4.2-5.6 7.27-8.17 9.21-2.58 1.95-5.31 2.92-8.18 2.92-3.29 0-5.85-1.24-7.66-3.72-1.81-2.49-2.72-5.98-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8 2.03-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.96-0.99 5.18-0.99 6.65 0 1.2 0.2 2.06 0.59 2.6s1 0.81 1.84 0.81c0.9 0 1.85-0.36 2.87-1.1 1.02-0.73 2.46-2.13 4.31-4.2l2.57 2.52c-2.91 3.05-5.28 5.14-7.12 6.26-1.85 1.13-3.91 1.69-6.18 1.69-1.95 0-3.51-0.71-4.67-2.14-1.17-1.42-1.76-3.24-1.76-5.45 0-2.01 0.42-4.91 1.26-8.72l8.04-36c0.36-1.59 0.62-2.85 0.77-3.8 0.15-0.94 0.22-1.82 0.22-2.62 0-0.9-0.16-1.58-0.49-2.05-0.33-0.46-0.8-0.8-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.33zm-29 0h2.65l-11 49.7c-0.66 2.96-0.99 5.18-0.99 6.65 0 1.2 0.2 2.06 0.59 2.6s1 0.81 1.84 0.81c0.9 0 1.85-0.36 2.87-1.1 1.02-0.73 2.46-2.13 4.31-4.2l2.57 2.52c-2.91 3.05-5.28 5.14-7.12 6.26-1.85 1.13-3.91 1.69-6.18 1.69-1.95 0-3.51-0.71-4.67-2.14-1.17-1.42-1.76-3.24-1.76-5.45 0-2.01 0.42-4.91 1.26-8.72l8.04-36c0.36-1.59 0.62-2.85 0.77-3.8 0.15-0.94 0.22-1.82 0.22-2.62 0-0.9-0.16-1.58-0.49-2.05-0.33-0.46-0.8-0.8-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.33z\" fill=\"url(#fill0)\" fill-rule=\"evenodd\"/><text x=\"2763.46\" y=\"1132.34\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"65px\">𝑎𝑙𝑙</text><path d=\"m2881 1075 17.9 40.3v3.33l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" fill=\"url(#fill0)\" fill-rule=\"evenodd\"/><text x=\"2875.8401\" y=\"1148.77\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84px\">〉</text><path d=\"m1893 508h6.92v83.6h-6.92z\" fill=\"url(#fill3)\" fill-rule=\"evenodd\"/><text x=\"1893.42\" y=\"580.99402\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"83.6px\">|</text><path d=\"m2045 532c-3.11 0-5.83 1.3-8.15 3.91-2.32 2.6-4.15 6.33-5.48 11.2-1.34 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.04 7.3 1.36 1.57 3.42 2.36 6.18 2.36 2.93 0 5.54-1.32 7.81-3.95 2.28-2.64 4.08-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.3-1.25-1.63-3.21-2.45-5.88-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.34 4.85-2 9.03-2 12.5 0 3.29 0.68 5.73 2.04 7.3 1.36 1.57 3.42 2.36 6.18 2.36 2.93 0 5.54-1.32 7.81-3.95 2.28-2.64 4.08-6.33 5.4-11.1 1.31-4.75 1.97-8.92 1.97-12.5 0-3.24-0.63-5.67-1.89-7.3-1.25-1.63-3.21-2.45-5.88-2.45zm98.3-0.09c-3.06 0-5.8 1.24-8.22 3.71-2.43 2.47-4.34 5.8-5.73 10s-2.09 8.37-2.09 12.5c0 3.12 0.43 5.44 1.28 6.99 0.86 1.54 2.29 2.31 4.29 2.31 0.93 0 1.87-0.202 2.83-0.606 0.96-0.405 1.96-1.06 2.99-1.96 1.03-0.898 2.05-1.99 3.05-3.28 1.01-1.29 1.93-2.58 2.77-3.89 0.84-1.3 1.61-2.84 2.33-4.63 0.72-1.78 1.34-3.93 1.85-6.45l0.4-1.93c0.45-2.16 0.67-4.19 0.67-6.11 0-2.34-0.49-4.04-1.48-5.1-0.99-1.06-2.63-1.59-4.94-1.59zm-148 0c-3.05 0-5.8 1.24-8.22 3.71-2.43 2.47-4.34 5.8-5.73 10s-2.09 8.37-2.09 12.5c0 3.12 0.45 5.44 1.35 6.99 0.9 1.54 2.31 2.31 4.22 2.31 1.53 0 3.05-0.524 4.56-1.57 1.51-1.05 3.13-2.71 4.85-4.99 1.73-2.28 3.07-4.45 4.02-6.51 0.96-2.07 1.78-4.64 2.45-7.73 0.68-3.08 1.01-5.76 1.01-8.04 0-2.34-0.49-4.04-1.48-5.1-0.99-1.06-2.63-1.59-4.94-1.59zm100-3.5c4.79 0 8.44 1.31 11 3.93 2.51 2.62 3.77 6.37 3.77 11.3 0 3.47-0.6 7.19-1.82 11.1-1.21 3.95-2.87 7.28-4.98 9.97-2.11 2.7-4.64 4.72-7.57 6.09-2.94 1.36-6.31 2.04-10.1 2.04-4.64 0-8.24-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.07-8.31 0.93-4.25 2.49-7.97 4.68-11.1 2.18-3.18 4.88-5.61 8.08-7.3 3.21-1.69 6.73-2.54 10.6-2.54zm-49 0c4.79 0 8.44 1.31 11 3.93 2.52 2.62 3.77 6.37 3.77 11.3 0 3.47-0.6 7.19-1.82 11.1-1.21 3.95-2.87 7.28-4.98 9.97-2.11 2.7-4.64 4.72-7.57 6.09-2.94 1.36-6.31 2.04-10.1 2.04-4.64 0-8.24-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.07-8.31 0.93-4.25 2.49-7.97 4.68-11.1 2.18-3.18 4.88-5.61 8.08-7.3 3.21-1.69 6.73-2.54 10.6-2.54zm-51.7-0.045c1.89 0 3.67 0.225 5.35 0.674 1.67 0.449 3.37 1.21 5.07 2.29l4.14-2.96 2.87 0.719-4.63 20.9c-0.33 1.47-1.07 5.17-2.24 11.1-1.23 6.29-2.23 10.7-2.99 13.3-0.76 2.6-1.71 4.98-2.85 7.12s-2.61 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.1 1.3-11.3 0-17-3.29-17-9.88 0-1.68 0.51-3.2 1.53-4.58 1.02-1.38 2.65-2.83 4.9-4.36l3.23 2.6c-0.57 0.689-1.05 1.37-1.44 2.04s-0.66 1.32-0.83 1.95c-0.16 0.629-0.25 1.38-0.25 2.25 0 2.25 0.81 3.89 2.43 4.92 1.62 1.03 4.06 1.55 7.32 1.55 3.69 0 6.64-0.831 8.87-2.49 2.24-1.66 4.15-4.34 5.73-8.02 1.59-3.68 3.13-9.25 4.63-16.7l-0.63-0.134c-2.9 3.98-5.6 6.89-8.09 8.72-2.48 1.83-5.16 2.74-8.04 2.74-3.26 0-5.8-1.23-7.61-3.68s-2.72-5.96-2.72-10.5c0-5.12 1-10 3.01-14.8 2.01-4.72 4.79-8.47 8.36-11.3 3.56-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.19 2.07 0.58 2.6s1.01 0.809 1.84 0.809c0.9 0 1.86-0.367 2.88-1.1s2.45-2.13 4.31-4.2l2.56 2.52c-2.75 2.9-5.07 4.96-6.96 6.15s-3.92 1.8-6.11 1.8c-1.86 0-3.34-0.614-4.45-1.84s-1.66-2.86-1.66-4.9c0-1.65 0.35-3.4 1.03-5.26l-0.58-0.18c-2.88 4.19-5.6 7.26-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.187 5.05 0.561 1.55 0.375 3.13 1.03 4.74 1.96l2.34-10.4c0.24-0.989 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.899-0.17-1.58-0.5-2.04s-0.8-0.801-1.41-1.01-1.72-0.359-3.3-0.449l0.54-2.34z\" fill=\"url(#fill3)\" fill-rule=\"evenodd\"/><text x=\"1912.89\" y=\"581.66803\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84.3px\">𝑔𝑜𝑜𝑑</text><path d=\"m2131 508 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" fill=\"url(#fill3)\" fill-rule=\"evenodd\"/><text x=\"2126.04\" y=\"581.16302\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84px\">〉</text><path transform=\"matrix(1 0 0 -1 2030 1303)\" d=\"m0.823-3.34 669 165-1.65 6.68-669-165zm649 137 23.7 32.2-35.9 17.5c-1.71 0.831-3.76 0.121-4.6-1.59s-0.121-3.76 1.59-4.6l32.2-15.7-1.26 5.13-21.2-28.8c-1.12-1.53-0.798-3.68 0.731-4.81 1.53-1.12 3.68-0.798 4.81 0.731z\"/><path d=\"m2765 1252h6.92v83.6h-6.92z\" fill=\"url(#fill6)\" fill-rule=\"evenodd\"/><text x=\"2765.25\" y=\"1324.91\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"83.6px\">|</text><path d=\"m2815 1278c-1.43 0-2.85 0.45-4.24 1.37-1.39 0.91-2.94 2.42-4.65 4.53-1.71 2.12-3.1 4.28-4.18 6.5-1.08 2.21-1.99 5.04-2.74 8.49l-0.4 1.88c-0.45 2.1-0.68 4.14-0.68 6.11 0 2.37 0.52 4.07 1.55 5.12 1.04 1.05 2.75 1.58 5.15 1.58 1.22 0 2.39-0.21 3.5-0.61 1.11-0.41 2.24-1.07 3.39-2 1.16-0.93 2.25-2.15 3.28-3.66s1.99-3.38 2.85-5.59c0.87-2.22 1.55-4.59 2.03-7.12 0.47-2.53 0.71-4.95 0.71-7.26 0-3.11-0.44-5.45-1.32-7.01-0.88-1.55-2.3-2.33-4.25-2.33zm97.4-1.75c-3.06 0-5.8 1.23-8.22 3.7-2.43 2.47-4.34 5.8-5.73 10-1.39 4.19-2.09 8.37-2.09 12.5 0 3.11 0.43 5.44 1.28 6.98 0.86 1.55 2.29 2.32 4.29 2.32 0.93 0 1.87-0.2 2.83-0.61 0.96-0.4 1.96-1.05 2.99-1.95s2.05-1.99 3.05-3.28c1.01-1.29 1.93-2.58 2.77-3.89 0.84-1.3 1.61-2.84 2.33-4.62 0.72-1.79 1.34-3.93 1.84-6.45l0.41-1.93c0.45-2.16 0.67-4.19 0.67-6.11 0-2.34-0.49-4.04-1.48-5.1s-2.64-1.59-4.94-1.59zm-50.9 0c-3.09 0-5.86 1.24-8.31 3.72-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.67-1.61-5.03-1.61zm-0.9-3.55c1.95 0 3.77 0.21 5.46 0.65 1.69 0.43 3.43 1.2 5.23 2.31l4.13-2.96 2.88 0.72-6.6 28.5c-0.66 2.84-0.99 5.06-0.99 6.64 0 1.2 0.19 2.07 0.58 2.61s1 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.91 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.89c0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.19-5.6 7.26-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.8 2.02-4.75 4.8-8.49 8.34-11.2 3.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.64 0 1.2 0.19 2.07 0.58 2.61s1 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.75 2.91-5.07 4.96-6.96 6.16s-3.92 1.79-6.11 1.79c-1.86 0-3.34-0.61-4.45-1.84s-1.66-2.86-1.66-4.89c0-1.65 0.34-3.4 1.03-5.26l-0.58-0.18c-2.88 4.19-5.6 7.26-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.8 2.02-4.75 4.8-8.49 8.34-11.2 3.53-2.74 7.47-4.11 11.8-4.11 1.83 0 3.51 0.18 5.05 0.56 1.55 0.37 3.13 1.02 4.74 1.95l2.34-10.4c0.24-0.99 0.45-2.09 0.63-3.28 0.18-1.2 0.27-2.25 0.27-3.15s-0.17-1.58-0.5-2.04c-0.33-0.47-0.8-0.8-1.41-1.01-0.62-0.21-1.72-0.36-3.3-0.45l0.54-2.34zm-124 0h2.61l-7.91 31.4 0.59 0.18c2.9-3.89 5.63-6.71 8.17-8.44 2.55-1.74 5.09-2.61 7.64-2.61 3.26 0 5.8 1.24 7.61 3.73s2.72 5.99 2.72 10.5c0 4.94-1 9.8-2.99 14.6s-4.75 8.56-8.28 11.4c-3.54 2.8-7.49 4.2-11.9 4.2-3.99 0-7.52-0.97-10.6-2.92l-4.13 2.92-2.87-0.71 11.6-51.4c0.69-3.05 1.03-5.27 1.03-6.65 0-1.26-0.38-2.14-1.14-2.65s-2.13-0.79-4.11-0.85l0.54-2.34z\" fill=\"url(#fill6)\" fill-rule=\"evenodd\"/><text x=\"2787.51\" y=\"1308.64\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"65px\">𝑏𝑎𝑑</text><path d=\"m2949 1252 17.9 40.3v3.32l-17.9 40.4-4.8-1.71 14.4-40.3-14.4-40.4z\" fill=\"url(#fill6)\" fill-rule=\"evenodd\"/><text x=\"2944.5901\" y=\"1325.08\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84px\">〉</text><path d=\"m2032 1298 675 161-1.59 6.69-675-161zm656 133 23.9 32-35.8 17.8c-1.7 0.85-3.76 0.15-4.61-1.55-0.84-1.7-0.15-3.76 1.55-4.61l32.1-15.9-1.22 5.14-21.4-28.7c-1.14-1.52-0.83-3.67 0.69-4.81s3.68-0.83 4.81 0.69z\" fill=\"#0070c0\"/><path d=\"m2367 1219c6.27 26.2 9.43 53.1 9.43 80.1\" fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" stroke-miterlimit=\"8\" stroke-width=\"6.88\"/><path transform=\"matrix(1 0 0 -1 1686 1644)\" d=\"m679 259c7.22 28.1 10.9 56.9 10.9 85.9\" fill=\"none\" fill-rule=\"evenodd\" stroke=\"#0070c0\" stroke-miterlimit=\"8\" stroke-width=\"6.88\"/><path d=\"m1332 1299h1390v6.88h-1390zm1365-22.1 30.7 25.6-30.7 25.6c-1.46 1.21-3.63 1.02-4.84-0.44-1.22-1.46-1.02-3.63 0.44-4.84l27.5-22.9v5.28l-27.5-22.9c-1.46-1.21-1.66-3.38-0.44-4.84 1.21-1.46 3.38-1.65 4.84-0.44z\"/><g fill=\"#0070c0\" font-family=\"'Segoe UI', 'Segoe UI_MSFontService', sans-serif\" font-size=\"64px\" font-weight=\"400\"><text transform=\"translate(2734 1521)\">State after</text><text transform=\"translate(2734 1598)\">the first </text><text transform=\"translate(2969 1598)\">reflection</text></g></g></svg></p>\n<p>&quot;Reflection about the mean&quot; 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.</p>\n<p>Mathematically, 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$.</p>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<p><svg width=\"428\" height=\"374\" overflow=\"hidden\" version=\"1.1\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"><defs><linearGradient id=\"fill0\" x1=\"2874\" x2=\"2874\" y1=\"1061\" y2=\"1188\" gradientUnits=\"userSpaceOnUse\" spreadMethod=\"reflect\"><stop offset=\"0\"/><stop offset=\".0292\"/><stop offset=\".3\"/><stop offset=\"1\"/></linearGradient><linearGradient id=\"fill3\" x1=\"2065\" x2=\"2065\" y1=\"482\" y2=\"609\" gradientUnits=\"userSpaceOnUse\" spreadMethod=\"reflect\"><stop offset=\"0\"/><stop offset=\".0292\"/><stop offset=\".3\"/><stop offset=\"1\"/></linearGradient><linearGradient id=\"fill6\" x1=\"2922\" x2=\"2922\" y1=\"1241\" y2=\"1368\" gradientUnits=\"userSpaceOnUse\" spreadMethod=\"reflect\"><stop offset=\"0\"/><stop offset=\".0292\"/><stop offset=\".3\"/><stop offset=\"1\"/></linearGradient></defs><g transform=\"matrix(.25 0 0 .25 -338 -124)\"><path d=\"m2319 1062c42.5 44.9 72.4 100 86.6 160\" fill=\"none\" fill-rule=\"evenodd\" stroke=\"#0070c0\" stroke-miterlimit=\"8\" stroke-width=\"6.88\"/><path d=\"m1356 1305c0-378 317-684 708-684s708 306 708 684c0 378-317 684-708 684s-708-306-708-684z\" fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" stroke-miterlimit=\"8\" stroke-width=\"6.88\"/><path d=\"m1356 1302h1410v6.88h-1410zm1385-22.1 30.7 25.6-30.7 25.6c-1.46 1.21-3.63 1.02-4.84-0.44-1.22-1.46-1.02-3.63 0.44-4.84l27.5-22.9v5.28l-27.5-22.9c-1.46-1.21-1.66-3.38-0.44-4.84 1.21-1.46 3.38-1.65 4.84-0.44z\"/><path d=\"m2067 626v1364h-6.88v-1364zm-29 25.3 25.6-30.7 25.6 30.7c1.21 1.46 1.02 3.63-0.44 4.84-1.46 1.22-3.63 1.02-4.84-0.44l-22.9-27.5h5.28l-22.9 27.5c-1.21 1.46-3.38 1.66-4.84 0.44-1.46-1.22-1.65-3.38-0.44-4.84z\"/><path d=\"m2785 1075h6.92v83.6h-6.92z\" fill=\"url(#fill0)\" fill-rule=\"evenodd\"/><text x=\"2784.6899\" y=\"1148.25\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"83.6px\">|</text><path d=\"m2832 1099c-3.09 0-5.86 1.25-8.32 3.73-2.45 2.49-4.37 5.82-5.75 10-1.37 4.17-2.06 8.35-2.06 12.5 0 3.11 0.43 5.44 1.28 6.98 0.85 1.55 2.28 2.32 4.29 2.32 1.98 0 3.91-0.86 5.82-2.56 1.9-1.71 3.86-4.14 5.88-7.3s3.45-6.81 4.29-10.9l0.41-1.93c0.26-1.23 0.44-2.29 0.53-3.19s0.14-1.88 0.14-2.92c0-2.31-0.5-4-1.48-5.08-0.99-1.08-2.67-1.62-5.03-1.62zm-0.9-3.55c1.94 0 3.76 0.22 5.46 0.66 1.69 0.43 3.43 1.2 5.23 2.31l4.13-2.97 2.88 0.72-6.61 28.5c-0.66 2.85-0.99 5.07-0.99 6.65 0 1.2 0.2 2.07 0.59 2.61s1 0.81 1.84 0.81c0.9 0 1.86-0.37 2.88-1.1 1.01-0.74 2.45-2.14 4.31-4.2l2.56 2.51c-2.7 2.88-5 4.92-6.9 6.13-1.9 1.22-3.96 1.82-6.17 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.4 1.03-5.25l-0.58-0.18c-2.88 4.19-5.6 7.26-8.18 9.21-2.58 1.94-5.3 2.92-8.18 2.92-3.29 0-5.84-1.25-7.65-3.73-1.82-2.49-2.72-5.98-2.72-10.5 0-5.15 1.01-10.1 3.03-14.8 2.02-4.75 4.8-8.49 8.33-11.2 3.54-2.74 7.47-4.11 11.8-4.11zm75.2-20.5h2.65l-11.1 49.7c-0.65 2.97-0.98 5.18-0.98 6.65 0 1.2 0.19 2.07 0.58 2.61s1 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.9 3.06-5.28 5.14-7.12 6.27-1.84 1.12-3.9 1.68-6.18 1.68-1.94 0-3.5-0.71-4.67-2.13s-1.75-3.24-1.75-5.46c0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.61-2.85 0.76-3.79 0.15-0.95 0.23-1.82 0.23-2.63 0-0.9-0.17-1.58-0.5-2.04-0.33-0.47-0.8-0.81-1.41-1.02-0.62-0.2-1.72-0.35-3.3-0.44l0.53-2.34zm-29 0h2.65l-11.1 49.7c-0.65 2.97-0.98 5.18-0.98 6.65 0 1.2 0.19 2.07 0.58 2.61s1 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.9 3.06-5.28 5.14-7.12 6.27-1.84 1.12-3.9 1.68-6.18 1.68-1.94 0-3.5-0.71-4.67-2.13s-1.75-3.24-1.75-5.46c0-2.01 0.42-4.91 1.26-8.71l8.04-36c0.36-1.58 0.61-2.85 0.76-3.79 0.15-0.95 0.23-1.82 0.23-2.63 0-0.9-0.17-1.58-0.5-2.04-0.33-0.47-0.8-0.81-1.41-1.02-0.62-0.2-1.72-0.35-3.3-0.44l0.53-2.34z\" fill=\"url(#fill0)\" fill-rule=\"evenodd\"/><text x=\"2807.53\" y=\"1131.98\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"65px\">𝑎𝑙𝑙</text><path d=\"m2925 1075 17.9 40.3v3.32l-17.9 40.4-4.81-1.7 14.4-40.3-14.4-40.4z\" fill=\"url(#fill0)\" fill-rule=\"evenodd\"/><text x=\"2919.9099\" y=\"1148.42\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84px\">〉</text><path d=\"m1927 496h6.91v83.6h-6.91z\" fill=\"url(#fill3)\" fill-rule=\"evenodd\"/><text x=\"1927.0699\" y=\"569.07397\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"83.6px\">|</text><path d=\"m2079 520c-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.98-1.95 1.04-0.899 2.06-1.99 3.06-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.34 6.99 0.9 1.54 2.31 2.31 4.23 2.31 1.52 0 3.04-0.524 4.56-1.57 1.51-1.05 3.13-2.71 4.85-4.99s3.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.79 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.97-4.63 4.72-7.57 6.09c-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.79 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.97-4.63 4.72-7.57 6.09c-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.135c-2.91 3.98-5.61 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.11 1.8-1.85 0-3.33-0.614-4.44-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\" fill=\"url(#fill3)\" fill-rule=\"evenodd\"/><text x=\"1946.54\" y=\"569.74799\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84.3px\">𝑔𝑜𝑜𝑑</text><path d=\"m2164 496 17.9 40.3v3.32l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" fill=\"url(#fill3)\" fill-rule=\"evenodd\"/><text x=\"2159.6799\" y=\"569.24298\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84px\">〉</text><path transform=\"matrix(1 0 0 -1 2064 1305)\" d=\"m0.823-3.34 678 167-1.64 6.68-678-167zm659 140 23.7 32.2-35.9 17.5c-1.71 0.831-3.76 0.121-4.6-1.58-0.831-1.71-0.121-3.76 1.59-4.6l32.2-15.7-1.26 5.13-21.2-28.8c-1.13-1.53-0.798-3.68 0.731-4.81 1.53-1.12 3.68-0.798 4.81 0.731z\"/><path d=\"m2811 1255h6.92v83.6h-6.92z\" fill=\"url(#fill6)\" fill-rule=\"evenodd\"/><text x=\"2811.4199\" y=\"1328.05\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"83.6px\">|</text><path d=\"m2861 1281c-1.44 0-2.86 0.46-4.25 1.37-1.39 0.92-2.94 2.43-4.65 4.54-1.7 2.11-3.1 4.27-4.18 6.49-1.07 2.22-1.99 5.05-2.74 8.49l-0.4 1.89c-0.45 2.09-0.67 4.13-0.67 6.11 0 2.36 0.51 4.07 1.55 5.12 1.03 1.05 2.74 1.57 5.14 1.57 1.23 0 2.4-0.2 3.5-0.61 1.11-0.4 2.24-1.07 3.4-2 1.15-0.92 2.24-2.14 3.27-3.66 1.04-1.51 1.99-3.37 2.86-5.59s1.54-4.59 2.02-7.12 0.72-4.95 0.72-7.25c0-3.12-0.44-5.46-1.33-7.01-0.88-1.56-2.3-2.34-4.24-2.34zm97.4-1.75c-3.05 0-5.79 1.24-8.22 3.71s-4.33 5.8-5.73 9.99c-1.39 4.19-2.09 8.37-2.09 12.5 0 3.12 0.43 5.45 1.28 6.99 0.86 1.54 2.29 2.31 4.29 2.31 0.93 0 1.88-0.2 2.83-0.6 0.96-0.41 1.96-1.06 2.99-1.96 1.04-0.9 2.05-1.99 3.06-3.28 1-1.28 1.92-2.58 2.76-3.88 0.84-1.31 1.62-2.85 2.34-4.63 0.71-1.78 1.33-3.93 1.84-6.45l0.4-1.93c0.45-2.15 0.68-4.19 0.68-6.11 0-2.33-0.5-4.03-1.49-5.1-0.99-1.06-2.63-1.59-4.94-1.59zm-50.9 0c-3.08 0-5.85 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.99 0.86 1.54 2.29 2.31 4.29 2.31 1.98 0 3.92-0.85 5.82-2.56 1.9-1.7 3.87-4.14 5.89-7.3s3.45-6.8 4.29-10.9l0.4-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.66-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.44 1.21 5.23 2.32l4.14-2.97 2.87 0.72-6.6 28.5c-0.66 2.85-0.99 5.06-0.99 6.65 0 1.2 0.19 2.06 0.58 2.6s1.01 0.81 1.85 0.81c0.89 0 1.85-0.36 2.87-1.1 1.02-0.73 2.46-2.13 4.31-4.2l2.56 2.52c-2.69 2.87-4.99 4.92-6.89 6.13s-3.96 1.82-6.18 1.82c-1.85 0-3.34-0.62-4.45-1.84-1.1-1.23-1.66-2.86-1.66-4.9 0-1.65 0.35-3.4 1.04-5.26l-0.59-0.18c-2.87 4.2-5.6 7.27-8.17 9.21-2.58 1.95-5.3 2.92-8.18 2.92-3.29 0-5.85-1.24-7.66-3.72-1.81-2.49-2.72-5.98-2.72-10.5 0-5.15 1.01-10.1 3.04-14.8 2.02-4.75 4.79-8.49 8.33-11.2 3.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.01 0.81 1.85 0.81c0.89 0 1.85-0.36 2.87-1.1 1.02-0.73 2.46-2.13 4.31-4.2l2.56 2.52c-2.75 2.9-5.07 4.95-6.96 6.15s-3.92 1.8-6.11 1.8c-1.85 0-3.34-0.62-4.45-1.84-1.1-1.23-1.66-2.86-1.66-4.9 0-1.65 0.35-3.4 1.04-5.26l-0.59-0.18c-2.87 4.2-5.6 7.27-8.17 9.21-2.58 1.95-5.3 2.92-8.18 2.92-3.29 0-5.85-1.24-7.66-3.72-1.81-2.49-2.72-5.98-2.72-10.5 0-5.15 1.01-10.1 3.04-14.8 2.02-4.75 4.79-8.49 8.33-11.2 3.53-2.74 7.47-4.11 11.8-4.11 1.83 0 3.51 0.19 5.06 0.56 1.54 0.38 3.12 1.03 4.74 1.96l2.33-10.4c0.24-0.99 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.9-0.16-1.58-0.49-2.05-0.33-0.46-0.8-0.8-1.42-1.01-0.61-0.21-1.71-0.36-3.3-0.45l0.54-2.33zm-124 0h2.6l-7.91 31.4 0.59 0.18c2.9-3.9 5.63-6.71 8.17-8.45 2.55-1.74 5.1-2.6 7.64-2.6 3.27 0 5.8 1.24 7.62 3.72 1.81 2.49 2.71 5.99 2.71 10.5 0 4.94-0.99 9.8-2.98 14.6-2 4.78-4.76 8.57-8.29 11.4-3.54 2.8-7.49 4.2-11.9 4.2-3.98 0-7.52-0.97-10.6-2.92l-4.14 2.92-2.87-0.72 11.6-51.4c0.69-3.05 1.04-5.27 1.04-6.64 0-1.26-0.38-2.15-1.15-2.65-0.76-0.51-2.13-0.8-4.11-0.86l0.54-2.33z\" fill=\"url(#fill6)\" fill-rule=\"evenodd\"/><text x=\"2833.6799\" y=\"1311.78\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"65px\">𝑏𝑎𝑑</text><path d=\"m3e3 1255 17.9 40.3v3.33l-17.9 40.4-4.81-1.71 14.4-40.3-14.4-40.4z\" fill=\"url(#fill6)\" fill-rule=\"evenodd\"/><text x=\"2990.76\" y=\"1328.21\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84px\">〉</text><path d=\"m2449 1254c-1.12 5.16-1.67 9.49-1.67 13 0 2.66 0.4 4.62 1.21 5.87 0.81 1.24 2.11 1.87 3.92 1.87 2.66 0 5.19-1.79 7.57-5.37 2.39-3.57 4.42-8.7 6.08-15.4zm14.6-24c-2.78 0-5.36 1.76-7.72 5.27-2.37 3.52-4.38 8.56-6.04 15.1h17.1c1.12-5.02 1.68-9.33 1.68-12.9 0-2.5-0.41-4.36-1.22-5.6-0.8-1.24-2.06-1.85-3.77-1.85zm0.42-2.89c6.89 0 10.3 4.37 10.3 13.1 0 2.47-0.28 5.42-0.84 8.85-0.56 3.44-1.44 6.94-2.65 10.5-1.21 3.57-2.75 6.72-4.6 9.47-1.85 2.74-3.99 4.86-6.42 6.36-2.42 1.5-5.03 2.24-7.84 2.24-3.54 0-6.18-1.08-7.91-3.24-1.74-2.16-2.6-5.41-2.6-9.73 0-2.35 0.26-5.25 0.78-8.7 0.52-3.44 1.38-6.97 2.58-10.6s2.75-6.79 4.64-9.59c1.89-2.79 4.06-4.94 6.52-6.45s5.13-2.26 8-2.26z\" fill-rule=\"evenodd\"/><text x=\"2441.72\" y=\"1271.74\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"50.5px\">𝜃</text><path d=\"m2067 1301 685 163-1.59 6.69-685-163zm666 136 23.9 32-35.8 17.8c-1.7 0.84-3.76 0.15-4.61-1.55-0.84-1.7-0.15-3.76 1.55-4.61l32.1-15.9-1.22 5.13-21.4-28.7c-1.14-1.52-0.83-3.67 0.69-4.81s3.68-0.83 4.82 0.69z\"/><path d=\"m2449 1350c-1.12 5.15-1.68 9.49-1.68 13 0 2.66 0.41 4.61 1.22 5.86 0.8 1.25 2.11 1.87 3.92 1.87 2.66 0 5.18-1.79 7.57-5.36 2.39-3.58 4.41-8.71 6.08-15.4zm14.6-24c-2.78 0-5.35 1.76-7.71 5.28-2.37 3.51-4.38 8.55-6.05 15.1h17.1c1.12-5.01 1.67-9.33 1.67-12.9 0-2.49-0.4-4.36-1.21-5.6-0.81-1.23-2.07-1.85-3.78-1.85zm0.43-2.89c6.89 0 10.3 4.38 10.3 13.1 0 2.47-0.28 5.42-0.84 8.86-0.56 3.43-1.44 6.93-2.66 10.5-1.21 3.56-2.74 6.71-4.59 9.46-1.86 2.74-4 4.86-6.42 6.36s-5.04 2.25-7.84 2.25c-3.54 0-6.18-1.08-7.91-3.25-1.74-2.16-2.61-5.4-2.61-9.73 0-2.35 0.27-5.25 0.79-8.69 0.52-3.45 1.38-6.97 2.58-10.6s2.75-6.8 4.64-9.59c1.88-2.79 4.06-4.94 6.52-6.45s5.13-2.27 8-2.27z\" fill-rule=\"evenodd\"/><text x=\"2441.6499\" y=\"1367.58\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"50.5px\">𝜃</text><path transform=\"matrix(1 0 0 -1 2062 1310)\" d=\"m2.4-2.46 498 484-4.79 4.93-498-484zm495 451 4.16 39.7-39.8-3.07c-1.89-0.146-3.31-1.8-3.16-3.69 0.145-1.89 1.8-3.31 3.69-3.16l35.7 2.75-3.68 3.79-3.73-35.6c-0.198-1.89 1.17-3.58 3.06-3.78 1.89-0.197 3.58 1.17 3.78 3.06z\" fill=\"#0070c0\"/><path d=\"m2443 1093c-1.12 5.16-1.68 9.5-1.68 13 0 2.66 0.41 4.61 1.22 5.86 0.8 1.25 2.11 1.87 3.92 1.87 2.66 0 5.18-1.79 7.57-5.36 2.39-3.58 4.42-8.71 6.08-15.4zm14.6-24c-2.78 0-5.35 1.76-7.71 5.28-2.37 3.51-4.38 8.55-6.04 15.1h17.1c1.12-5.01 1.67-9.33 1.67-12.9 0-2.49-0.4-4.36-1.21-5.6-0.81-1.23-2.07-1.85-3.78-1.85zm-46.7-2.14c4.42 0 7.76 0.97 10 2.91 2.25 1.93 3.38 4.74 3.38 8.43 0 1.26-0.12 2.41-0.37 3.47s-0.64 2.11-1.18 3.14c-0.53 1.03-1.25 2.14-2.15 3.33-0.91 1.19-1.9 2.4-3 3.62-1.09 1.22-2.98 3.26-5.67 6.11-4.51 4.78-7.83 8.95-9.94 12.5h13.4c1.16 0 2.1-0.07 2.81-0.21 0.72-0.14 1.29-0.38 1.71-0.71 0.43-0.34 0.77-0.77 1.02-1.3 0.25-0.54 0.56-1.36 0.95-2.48h3.02l-0.6 10.4h-29.3v-1.71c1.03-2.5 2.4-5.05 4.14-7.67 1.73-2.61 4.19-5.69 7.38-9.23 2.75-3.04 4.74-5.35 5.95-6.91 1.33-1.72 2.32-3.19 2.98-4.44 0.65-1.25 1.12-2.43 1.4-3.53 0.29-1.11 0.43-2.22 0.43-3.33 0-1.79-0.28-3.36-0.85-4.73-0.57-1.36-1.45-2.44-2.62-3.22-1.18-0.79-2.66-1.18-4.44-1.18-4.45 0-7.44 2.47-8.98 7.42h-4.32v-6.85c2.88-1.35 5.57-2.33 8.08-2.94 2.5-0.61 4.75-0.91 6.75-0.91zm47.1-0.75c6.89 0 10.3 4.38 10.3 13.1 0 2.47-0.28 5.42-0.84 8.86-0.56 3.43-1.44 6.93-2.65 10.5-1.22 3.56-2.75 6.71-4.6 9.46-1.86 2.74-3.99 4.86-6.42 6.36-2.42 1.5-5.04 2.25-7.84 2.25-3.54 0-6.18-1.08-7.91-3.25-1.74-2.16-2.61-5.4-2.61-9.73 0-2.35 0.27-5.25 0.79-8.69 0.52-3.45 1.38-6.97 2.58-10.6s2.75-6.8 4.64-9.59 4.06-4.94 6.52-6.45 5.13-2.27 8-2.27z\" fill=\"#0070c0\" fill-rule=\"evenodd\"/><text x=\"2395.01\" y=\"1110.6801\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"50.5px\">2𝜃</text><path d=\"m2406 1221c6.32 26.6 9.52 53.8 9.52 81.1\" fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" stroke-miterlimit=\"8\" stroke-width=\"6.88\"/><path transform=\"matrix(1 0 0 -1 1716 1652)\" d=\"m688 263c7.29 28.4 11 57.7 11 87\" fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" stroke-miterlimit=\"8\" stroke-width=\"6.88\"/><g fill=\"#0070c0\" font-family=\"'Segoe UI', 'Segoe UI_MSFontService', sans-serif\" font-size=\"64px\" font-weight=\"400\"><text transform=\"translate(2582 724)\">State after the</text><text transform=\"translate(2582 801)\">second </text><text transform=\"translate(2803 801)\">reflection</text></g></g></svg></p>\n<p>As 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!</p>\n<p>Each 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</p>\n<p>$$\\sin{(2R+1)\\theta}\\ket{\\text{good}} + \\cos{(2R+1)\\theta}\\ket{\\text{bad}}$$</p>\n<p>At 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.</p>\n"
6984
+ }
6985
+ ]
6986
+ },
6987
+ {
6988
+ "type": "exercise",
6989
+ "id": "grovers_search__phase_oracle",
6990
+ "title": "Phase Oracle from Marking Oracle",
6991
+ "description": {
6992
+ "type": "text-content",
6993
+ "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>A marking oracle implementing an unknown $N$-bit function $f(x)$.</li>\n<li>$N$ qubits in an arbitrary state (input/query register).</li>\n</ol>\n<p><strong>Goal:</strong></p>\n<p>Flip the phase of each basis state $\\ket{x}$ for which $f(x) = 1$. You can only access $f(x)$ via the marking oracle you are given.</p>\n<p>The operation you implement is the phase oracle for the same function.</p>\n<br/>\n<details>\n <summary><b>Need a hint?</b></summary>\n Recall that you can allocate extra qubits to assist in this operation. Is there a state that you could prepare with an auxiliary qubit which would help you to convert the marking oracle to a phase oracle?\n</details>\n"
6994
+ },
6995
+ "sourceIds": [
6996
+ "grovers_search__phase_oracle__Verification.qs",
6997
+ "KatasLibrary.qs"
6998
+ ],
6999
+ "placeholderCode": "namespace Kata {\n operation ApplyMarkingOracleAsPhaseOracle(\n markingOracle : (Qubit[], Qubit) => Unit is Adj + Ctl,\n qubits : Qubit[])\n : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}\n",
7000
+ "explainedSolution": {
7001
+ "type": "explained-solution",
7002
+ "items": [
7003
+ {
7004
+ "type": "text-content",
7005
+ "content": "<p>As we saw in the Oracles kata, we can allocate an additional qubit in the $\\ket{-}$ state and use it as the target for our marking oracle.\nThis will kick back the $-1$ relative phase for the basis states $\\ket{x}$ of the input register for which $f(x) = 1$.</p>\n"
7006
+ },
7007
+ {
7008
+ "type": "solution",
7009
+ "id": "grovers_search__phase_oracle_solution",
7010
+ "code": "namespace Kata {\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"
7011
+ }
7012
+ ]
7013
+ }
7014
+ },
7015
+ {
7016
+ "type": "exercise",
7017
+ "id": "grovers_search__conditional_phase_flip",
7018
+ "title": "Conditional Phase Flip",
7019
+ "description": {
7020
+ "type": "text-content",
7021
+ "content": "<p><strong>Input:</strong> A register of $N$ qubits in an arbitrary state.</p>\n<p><strong>Goal:</strong> Flip the sign of the state of the register if it is <em>not</em> in the $\\ket{0...0}$ state.\nThat is, if the register is in state $\\ket{0...0}$, leave it unchanged,\nbut if it is in any other basis state, multiply its phase by $-1$.</p>\n<blockquote>\n<p>This operation implements operator\n$$2\\ket{0...0}\\bra{0...0} - I = \n\\begin{bmatrix}\n 1 &amp; 0 &amp; ... &amp; 0 \\\\\n 0 &amp;-1 &amp; ... &amp; 0 \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\ \n 0 &amp; 0 &amp; ... &amp; -1\n\\end{bmatrix}$$</p>\n</blockquote>\n"
7022
+ },
7023
+ "sourceIds": [
7024
+ "grovers_search__conditional_phase_flip__Verification.qs",
7025
+ "KatasLibrary.qs"
7026
+ ],
7027
+ "placeholderCode": "namespace Kata {\n operation ConditionalPhaseFlip(qs : Qubit[]) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}\n",
7028
+ "explainedSolution": {
7029
+ "type": "explained-solution",
7030
+ "items": [
7031
+ {
7032
+ "type": "text-content",
7033
+ "content": "<p>This operation is equivalent to the operation of flipping the sign of only the $\\ket{0...0}$ basis state, with an additional global phase $-1$.\nThis means that you can implement it in two steps:</p>\n<ol>\n<li>Flip the sign of the $\\ket{0...0}$ basis state.\nYou can do this by applying $X$ gates to all qubits, then using the Controlled $Z$ gate to flip the sign of $\\ket{1...1}$, and then applying $X$ gates to all qubits again.</li>\n<li>Apply a global phase $-1$ to the whole state using an <code>R1</code> gate.</li>\n</ol>\n"
7034
+ },
7035
+ {
7036
+ "type": "solution",
7037
+ "id": "grovers_search__conditional_phase_flip_solution",
7038
+ "code": "namespace Kata {\n open Microsoft.Quantum.Math;\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"
7039
+ }
7040
+ ]
7041
+ }
7042
+ },
7043
+ {
7044
+ "type": "exercise",
7045
+ "id": "grovers_search__reflection_about_state",
7046
+ "title": "Reflection about Arbitrary State",
7047
+ "description": {
7048
+ "type": "text-content",
7049
+ "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>$N$ qubits in an arbitrary state.</li>\n<li>An operation $P$ that prepares an $N$-qubit state $\\ket{\\psi}$ from the state $\\ket{0...0}$.</li>\n</ol>\n<p><strong>Goal:</strong></p>\n<p>Reflect the state of the given qubits about the state $\\ket{\\psi}$.\nIn other words, implement an operation $2\\ket{\\psi}\\bra{\\psi} - I$.</p>\n<p>This operation allows you to implement the &quot;reflection about the mean&quot; operation, if you use the operation that prepares the mean as the input.</p>\n"
7050
+ },
7051
+ "sourceIds": [
7052
+ "grovers_search__reflection_about_state__Verification.qs",
7053
+ "KatasLibrary.qs"
7054
+ ],
7055
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n operation ReflectionAboutState(\n qs : Qubit[],\n statePrep : Qubit[] => Unit is Adj + Ctl)\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 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",
7056
+ "explainedSolution": {
7057
+ "type": "explained-solution",
7058
+ "items": [
7059
+ {
7060
+ "type": "text-content",
7061
+ "content": "<p>You know that $P\\ket{0...0} = \\ket{\\psi}$.\nYou can use this and the fact that $I = PP^\\dagger$ to write the following representation of the operation you need to implement:</p>\n<p>$$2\\ket{\\psi}\\bra{\\psi} - I = 2P\\ket{0...0}\\bra{0...}P^\\dagger - I =$$\n$$= 2P\\ket{0...0}\\bra{0...0}P^\\dagger - PP^\\dagger = P(2\\ket{0...0}\\bra{0...0} - I)P^\\dagger$$</p>\n<p>The middle operation is exactly the conditional phase flip you implemented in the previous exercise.\nThe overall solution is:</p>\n<ol>\n<li>Apply adjoint of the given operation $P$.</li>\n<li>Apply the conditional phase flip from the previous exercise.</li>\n<li>Apply the given operation $P$.</li>\n</ol>\n"
7062
+ },
7063
+ {
7064
+ "type": "solution",
7065
+ "id": "grovers_search__reflection_about_state_solution",
7066
+ "code": "namespace Kata {\n open Microsoft.Quantum.Math;\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"
7067
+ }
7068
+ ]
7069
+ }
7070
+ },
7071
+ {
7072
+ "type": "lesson",
7073
+ "id": "grovers_search__iterations",
7074
+ "title": "Optimal Number of Iterations",
7075
+ "items": [
7076
+ {
7077
+ "type": "text-content",
7078
+ "content": "<p>The 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 &quot;good&quot; states - is maximized.</p>\n<p>Geometrically, 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:</p>\n<p>$$(2R+1)\\theta \\approx \\frac{\\pi}{2}$$</p>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<p><svg width=\"421\" height=\"383\" overflow=\"hidden\" version=\"1.1\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"><defs><linearGradient id=\"fill3\" x1=\"2073\" x2=\"2073\" y1=\"475\" y2=\"601\" gradientUnits=\"userSpaceOnUse\" spreadMethod=\"reflect\"><stop offset=\"0\"/><stop offset=\".0292\"/><stop offset=\".3\"/><stop offset=\"1\"/></linearGradient><linearGradient id=\"fill6\" x1=\"2933\" x2=\"2933\" y1=\"1228\" y2=\"1354\" gradientUnits=\"userSpaceOnUse\" spreadMethod=\"reflect\"><stop offset=\"0\"/><stop offset=\".0292\"/><stop offset=\".3\"/><stop offset=\"1\"/></linearGradient></defs><g transform=\"matrix(.25 0 0 .25 -335 -117)\"><path d=\"m1344 1304c0-384 321-694 718-694s718 311 718 694c0 384-321 694-718 694s-718-311-718-694z\" fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" stroke-miterlimit=\"8\" stroke-width=\"6.88\"/><path d=\"m1344 1300h1430v6.88h-1430zm1405-22.1 30.7 25.6-30.7 25.6c-1.46 1.21-3.63 1.02-4.84-0.44-1.22-1.46-1.02-3.63 0.44-4.84l27.5-22.9v5.28l-27.5-22.9c-1.46-1.21-1.66-3.38-0.44-4.84 1.21-1.46 3.38-1.65 4.84-0.44z\"/><path d=\"m2065 615v1383h-6.88v-1383zm-29 25.3 25.6-30.7 25.6 30.7c1.21 1.46 1.02 3.63-0.44 4.84-1.46 1.22-3.63 1.02-4.84-0.44l-22.9-27.5h5.28l-22.9 27.5c-1.21 1.46-3.38 1.66-4.84 0.44s-1.65-3.38-0.44-4.84z\"/><path transform=\"matrix(1 0 0 -1 2062 1304)\" d=\"m0.823-3.34 688 170-1.65 6.68-688-170zm669 142 23.7 32.2-35.9 17.5c-1.71 0.831-3.76 0.121-4.6-1.58-0.832-1.71-0.121-3.76 1.58-4.6l32.2-15.7-1.26 5.13-21.2-28.8c-1.12-1.53-0.798-3.68 0.731-4.81 1.53-1.12 3.68-0.798 4.81 0.732z\"/><path d=\"m2464 1246c-1.41 6.5-2.11 12-2.11 16.4 0 3.35 0.5 5.81 1.52 7.39 1.02 1.57 2.67 2.35 4.94 2.35 3.36 0 6.54-2.25 9.55-6.76 3.01-4.5 5.56-11 7.66-19.4zm18.4-30.3c-3.51 0-6.75 2.22-9.73 6.65s-5.52 10.8-7.61 19h21.5c1.41-6.32 2.11-11.8 2.11-16.3 0-3.14-0.5-5.5-1.52-7.05-1.02-1.56-2.61-2.34-4.76-2.34zm0.53-3.64c8.69 0 13 5.51 13 16.5 0 3.12-0.35 6.84-1.05 11.2-0.71 4.32-1.82 8.73-3.35 13.2-1.53 4.49-3.46 8.46-5.8 11.9-2.33 3.46-5.03 6.14-8.08 8.02-3.06 1.89-6.35 2.83-9.88 2.83-4.47 0-7.79-1.36-9.98-4.09-2.18-2.72-3.28-6.81-3.28-12.3 0-2.96 0.33-6.62 0.99-11s1.75-8.78 3.26-13.3 3.46-8.56 5.84-12.1 5.12-6.23 8.22-8.13c3.1-1.91 6.46-2.86 10.1-2.86z\" fill-rule=\"evenodd\"/><text x=\"2454.7\" y=\"1369.71\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"63.7px\"/><path d=\"m2463 1095c-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.33zm-58.2-2.7c5.57 0 9.78 1.22 12.6 3.66 2.85 2.44 4.27 5.98 4.27 10.6 0 1.58-0.16 3.04-0.47 4.38-0.32 1.33-0.81 2.65-1.48 3.95-0.68 1.3-1.58 2.7-2.72 4.2s-2.4 3.02-3.78 4.56c-1.37 1.54-3.75 4.11-7.14 7.7-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.48 2.16-0.9 0.96-0.96 1.28-1.64c0.31-0.67 0.71-1.71 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.29 5.29-7.17 9.3-11.6 3.48-3.83 5.98-6.74 7.51-8.72 1.67-2.15 2.92-4.02 3.75-5.59 0.82-1.57 1.41-3.05 1.77-4.45 0.36-1.39 0.54-2.79 0.54-4.2 0-2.24-0.36-4.23-1.08-5.95s-1.82-3.08-3.3-4.06c-1.48-0.99-3.35-1.49-5.59-1.49-5.6 0-9.38 3.12-11.3 9.35h-5.44v-8.63c3.62-1.7 7.02-2.94 10.2-3.7 3.16-0.77 5.99-1.15 8.51-1.15zm58.7-0.94c8.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.81-3.28-12.3 0-2.97 0.33-6.62 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\" fill-rule=\"evenodd\"/><text x=\"2403.0801\" y=\"1117.16\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"63.7px\">2𝜃</text><path transform=\"matrix(1 0 0 -1 2062 1308)\" d=\"m3.34-0.795 161 676-6.69 1.59-161-676zm176 646-17.8 35.7-32-23.9c-1.52-1.14-1.83-3.29-0.691-4.81 1.14-1.52 3.29-1.83 4.81-0.69l28.7 21.5-5.14 1.22 15.9-32.1c0.845-1.7 2.91-2.39 4.61-1.55 1.7 0.845 2.39 2.91 1.55 4.61z\" fill=\"#0070c0\"/><g fill=\"none\" fill-rule=\"evenodd\" stroke-miterlimit=\"8\" stroke-width=\"6.88\"><path d=\"m2320 1057c43.2 45.4 73.5 102 88 163\" stroke=\"#000\"/><path d=\"m2145 956c67.8 16 129 51.7 177 103\" stroke=\"#0070c0\"/><path d=\"m2409 1219c6.43 27 9.68 54.6 9.68 82.3\" stroke=\"#000\"/></g><path d=\"m2291 924c-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\"/><text x=\"2231.1599\" y=\"945.87799\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"63.7px\">2𝜃</text><text x=\"2825.96\" y=\"1131.05\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"65px\">𝑎𝑙𝑙</text><path d=\"m1935 488h6.92v83.6h-6.92z\" fill=\"url(#fill3)\" fill-rule=\"evenodd\"/><text x=\"1935.1801\" y=\"561.573\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"83.6px\">|</text><path d=\"m2087 513c-3.12 0-5.83 1.3-8.16 3.91-2.32 2.61-4.14 6.33-5.48 11.2-1.33 4.85-2 9.03-2 12.5 0 3.29 0.69 5.73 2.05 7.3s3.42 2.36 6.18 2.36c2.93 0 5.54-1.32 7.81-3.95 2.28-2.64 4.08-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.23-0.63-5.67-1.89-7.3s-3.22-2.45-5.88-2.45zm-49 0c-3.12 0-5.83 1.3-8.16 3.91-2.32 2.61-4.14 6.33-5.48 11.2-1.33 4.85-1.99 9.03-1.99 12.5 0 3.29 0.68 5.73 2.04 7.3s3.42 2.36 6.18 2.36c2.93 0 5.54-1.32 7.81-3.95 2.28-2.64 4.08-6.33 5.39-11.1 1.32-4.75 1.98-8.92 1.98-12.5 0-3.23-0.63-5.67-1.89-7.3s-3.22-2.45-5.88-2.45zm98.3-0.09c-3.06 0-5.8 1.24-8.22 3.71-2.43 2.47-4.34 5.8-5.73 10-1.39 4.19-2.09 8.37-2.09 12.5 0 3.11 0.43 5.44 1.28 6.98s2.28 2.31 4.29 2.31c0.93 0 1.87-0.203 2.83-0.607s1.95-1.06 2.99-1.95c1.03-0.898 2.05-1.99 3.05-3.28 1.01-1.29 1.93-2.58 2.77-3.89 0.83-1.3 1.61-2.84 2.33-4.63s1.33-3.93 1.84-6.45l0.41-1.93c0.45-2.16 0.67-4.19 0.67-6.11 0-2.34-0.49-4.04-1.48-5.1s-2.64-1.6-4.94-1.6zm-148 0c-3.06 0-5.8 1.24-8.22 3.71-2.43 2.47-4.34 5.8-5.73 10-1.39 4.19-2.09 8.37-2.09 12.5 0 3.11 0.45 5.44 1.35 6.98s2.3 2.31 4.22 2.31c1.53 0 3.05-0.525 4.56-1.57s3.13-2.71 4.85-4.99 3.06-4.45 4.02-6.51c0.96-2.07 1.78-4.64 2.45-7.73 0.67-3.08 1.01-5.76 1.01-8.04 0-2.34-0.49-4.04-1.48-5.1s-2.64-1.6-4.94-1.6zm100-3.5c4.79 0 8.44 1.31 11 3.93 2.51 2.62 3.77 6.37 3.77 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.87 7.28-4.99 9.97c-2.11 2.7-4.63 4.72-7.56 6.09-2.94 1.36-6.31 2.04-10.1 2.04-4.64 0-8.24-1.3-10.8-3.91s-3.84-6.35-3.84-11.2c0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.49-7.97 4.67-11.1 2.19-3.17 4.89-5.61 8.09-7.3s6.72-2.54 10.6-2.54zm-49 0c4.79 0 8.44 1.31 11 3.93 2.51 2.62 3.77 6.37 3.77 11.3 0 3.47-0.61 7.19-1.82 11.1s-2.87 7.28-4.98 9.97c-2.12 2.7-4.64 4.72-7.57 6.09-2.94 1.36-6.31 2.04-10.1 2.04-4.64 0-8.24-1.3-10.8-3.91s-3.84-6.35-3.84-11.2c0-2.4 0.36-5.17 1.08-8.31 0.93-4.25 2.49-7.97 4.67-11.1 2.19-3.17 4.89-5.61 8.09-7.3s6.72-2.54 10.6-2.54zm-51.7-0.045c1.89 0 3.67 0.225 5.34 0.674 1.68 0.45 3.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.24 11.1-1.23 6.29-2.23 10.7-2.99 13.3-0.77 2.61-1.72 4.98-2.85 7.12-1.14 2.14-2.61 4.01-4.41 5.59-1.79 1.59-3.97 2.82-6.53 3.68-2.56 0.868-5.6 1.3-9.1 1.3-11.3 0-17-3.3-17-9.88 0-1.68 0.51-3.2 1.53-4.58s2.65-2.83 4.89-4.36l3.24 2.61c-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.92s4.06 1.55 7.32 1.55c3.68 0 6.64-0.831 8.87-2.49 2.23-1.66 4.14-4.33 5.73-8.02s3.13-9.25 4.63-16.7l-0.63-0.135c-2.91 3.98-5.6 6.89-8.09 8.72-2.48 1.83-5.16 2.74-8.04 2.74-3.26 0-5.8-1.23-7.61-3.68-1.81-2.46-2.72-5.96-2.72-10.5 0-5.12 1-10 3.01-14.8s4.79-8.47 8.35-11.3c3.57-2.78 7.54-4.18 11.9-4.18zm168-20.5h2.65l-11.2 49.7c-0.65 2.94-0.98 5.15-0.98 6.65 0 1.2 0.19 2.07 0.58 2.61s1 0.808 1.84 0.808c0.9 0 1.86-0.367 2.88-1.1 1.02-0.734 2.45-2.13 4.31-4.2l2.56 2.52c-2.76 2.9-5.08 4.96-6.96 6.15-1.89 1.2-3.93 1.8-6.11 1.8-1.86 0-3.34-0.614-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.19-5.6 7.26-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.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.33-11.2 3.54-2.74 7.48-4.11 11.8-4.11 1.83 0 3.51 0.188 5.05 0.562s3.12 1.03 4.74 1.95l2.34-10.4c0.24-0.988 0.45-2.08 0.63-3.28s0.27-2.25 0.27-3.14c0-0.898-0.17-1.58-0.5-2.04-0.33-0.464-0.8-0.801-1.41-1.01-0.62-0.21-1.72-0.36-3.3-0.45l0.53-2.34z\" fill=\"url(#fill3)\" fill-rule=\"evenodd\"/><text x=\"1954.65\" y=\"562.24701\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84.3px\">𝑔𝑜𝑜𝑑</text><path d=\"m2173 488 17.9 40.3v3.32l-17.9 40.4-4.8-1.71 14.4-40.3-14.4-40.4z\" fill=\"url(#fill3)\" fill-rule=\"evenodd\"/><text x=\"2167.8\" y=\"561.74103\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84px\">〉</text><path d=\"m2822 1242h6.92v83.6h-6.92z\" fill=\"url(#fill6)\" fill-rule=\"evenodd\"/><text x=\"2821.6101\" y=\"1314.8199\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"83.6px\">|</text><path d=\"m2871 1268c-1.44 0-2.85 0.46-4.24 1.37-1.4 0.91-2.95 2.43-4.65 4.54-1.71 2.11-3.1 4.27-4.18 6.49-1.08 2.21-1.99 5.04-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.03 1.04 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-2s2.25-2.15 3.28-3.66 1.98-3.37 2.85-5.59 1.54-4.59 2.02-7.12 0.72-4.95 0.72-7.26c0-3.11-0.44-5.45-1.32-7-0.89-1.56-2.3-2.34-4.25-2.34zm97.4-1.75c-3.06 0-5.8 1.23-8.22 3.7-2.43 2.48-4.34 5.81-5.73 10s-2.09 8.37-2.09 12.5c0 3.12 0.43 5.45 1.28 6.99s2.28 2.31 4.29 2.31c0.93 0 1.87-0.2 2.83-0.6 0.96-0.41 1.95-1.06 2.99-1.96 1.03-0.9 2.05-1.99 3.05-3.28 1.01-1.29 1.93-2.58 2.76-3.88 0.84-1.31 1.62-2.85 2.34-4.63s1.33-3.93 1.84-6.45l0.41-1.93c0.45-2.16 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.38 5.81-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.28 2.31 4.29 2.31c1.98 0 3.92-0.85 5.82-2.56s3.86-4.14 5.88-7.3 3.45-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.94 0 3.76 0.22 5.46 0.65 1.69 0.44 3.43 1.21 5.23 2.31l4.13-2.96 2.88 0.72-6.61 28.5c-0.65 2.84-0.98 5.06-0.98 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.37 2.88-1.1 1.01-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.7 2.87-4.99 4.92-6.9 6.13-1.9 1.21-3.96 1.82-6.17 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.82-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.33-11.2c3.54-2.74 7.48-4.11 11.8-4.11zm70.6-20.5h2.65l-11.2 49.7c-0.65 2.93-0.98 5.15-0.98 6.65 0 1.2 0.19 2.06 0.58 2.6s1 0.81 1.84 0.81c0.9 0 1.86-0.37 2.88-1.1 1.01-0.73 2.45-2.13 4.31-4.2l2.56 2.52c-2.76 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.82-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.33-11.2c3.54-2.74 7.48-4.11 11.8-4.11 1.83 0 3.51 0.19 5.05 0.56 1.54 0.38 3.12 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.15c0-0.89-0.17-1.58-0.5-2.04s-0.8-0.8-1.41-1.01c-0.62-0.21-1.72-0.36-3.31-0.45l0.54-2.34zm-124 0h2.61l-7.91 31.4 0.58 0.18c2.91-3.9 5.63-6.71 8.18-8.45s5.09-2.61 7.64-2.61c3.26 0 5.8 1.25 7.61 3.73 1.81 2.49 2.72 5.99 2.72 10.5 0 4.95-1 9.81-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.9 4.2-3.98 0-7.51-0.98-10.6-2.92l-4.13 2.92-2.88-0.72 11.6-51.4c0.69-3.05 1.03-5.27 1.03-6.65 0-1.25-0.38-2.14-1.14-2.65-0.77-0.51-2.14-0.79-4.11-0.85l0.54-2.34z\" fill=\"url(#fill6)\" fill-rule=\"evenodd\"/><text x=\"2843.8601\" y=\"1298.5601\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"65px\">𝑏𝑎𝑑</text><path d=\"m3006 1241 17.9 40.3v3.32l-17.9 40.4-4.8-1.71 14.4-40.3-14.4-40.4z\" fill=\"url(#fill6)\" fill-rule=\"evenodd\"/><text x=\"3000.95\" y=\"1314.99\" fill=\"#000000\" fill-opacity=\"0\" font-family=\"Arial, Arial_MSFontService, sans-serif\" font-size=\"84px\">〉</text><path transform=\"matrix(1 0 0 -1 2060 1308)\" d=\"m2.4-2.46 505 491-4.79 4.93-505-491zm502 458 4.16 39.7-39.8-3.07c-1.89-0.146-3.31-1.8-3.16-3.69 0.146-1.89 1.8-3.31 3.69-3.16l35.7 2.75-3.68 3.79-3.73-35.6c-0.198-1.89 1.17-3.58 3.06-3.78 1.89-0.198 3.58 1.17 3.78 3.06z\"/><text transform=\"translate(2240 517)\" fill=\"#0070c0\" font-family=\"'Segoe UI', 'Segoe UI_MSFontService', sans-serif\" font-size=\"64px\" font-weight=\"400\">Close enough</text><text transform=\"translate(2240 594)\" fill=\"#0070c0\" font-family=\"'Segoe UI', 'Segoe UI_MSFontService', sans-serif\" font-size=\"64px\" font-weight=\"400\">to measure</text></g></svg></p>\n<p>Now, 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}$</p>\n<p>$$ 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}}$$</p>\n<p>What 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.</p>\n<p>In this demo you will see how success probability of Grover's algorithm changes when it uses different numbers of iterations\nbefore the final measurements.</p>\n"
7079
+ },
7080
+ {
7081
+ "type": "example",
7082
+ "id": "grovers_search__e2edemo",
7083
+ "code": "namespace Kata {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation GroversSearchAlgorithmDemo() : Unit {\n // Experiment with the parameters to explore algorithm behavior in different conditions!\n let n = 3;\n let prefix = [false, true, false];\n let markingOracle = Oracle_StartsWith(_, _, prefix);\n for iterations in 0 .. 9 {\n mutable success = 0;\n for _ in 1 .. 100 {\n let res = GroversSearch(n, markingOracle, iterations);\n if BoolArrayAsInt(prefix) == BoolArrayAsInt(res) {\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 Oracle_StartsWith(x : Qubit[], y : Qubit, p : Bool[]) : Unit is Adj + Ctl {\n ApplyControlledOnBitString(p, X, x[... Length(p) - 1], y);\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}"
7084
+ },
7085
+ {
7086
+ "type": "text-content",
7087
+ "content": "<h3>Verifying that algorithm output is correct</h3>\n<p>Notice that even when using the optimal number of iterations, you are not guaranteed a $100\\%$ success probability.\nGrover's search is a probabilistic algorithm, which means that even in the best case it has a non-zero failure probability.\nWhen you use it to solve a problem, you need to check that the output is correct before using it for any purpose.</p>\n<p>This can be done classically, if you have access to the classical description of the problem\n(in the example used in this kata, you would check that the prefix of the returned state matches the given one.)</p>\n<p>In general, the algorithm only gets the marking oracle as an input and doesn't have the information about the classical problem structure.\nHowever, all information necessary to verify the output is already contained in the oracle itself!<br />\nThe effect of the marking oracle on an input, encoded as a basis states of the qubit register, is defined as\n$$U_f \\ket{x} \\ket{y} = \\ket{x} \\ket{y \\oplus f(x)}$$</p>\n<p>This means that if you encode the return of the algorithm $x_0$ as a basis state of the qubit register,\nallocate an extra qubit in the $\\ket{0}$ state, and apply the oracle $U_f$ to these qubits, you'll get\n$$U_f \\ket{x} \\ket{0} = \\ket{x} \\ket{f(x)}$$</p>\n<p>If you measure the last qubit now, you'll get exactly $f(x)$: if it is 1, the algorithm produced a correct answer, otherwise it didn't. If the algorithm failed, you can re-run it from scratch and hopefully get a correct answer on the next attempt!</p>\n<h3>Special cases</h3>\n<p>This calculation for the optimal number of iterations is done under the assumption that $M$ is much smaller than $N$ but greater than $0$. In other words, the algorithm works if solutions to the search problem exist, but there are very few of them.</p>\n<p>What happens if these assumptions are not valid?</p>\n<h4>No solutions ($M = 0$)</h4>\n<p>In this case the starting system state $\\ket{\\psi} = \\ket{\\text{bad}}$, and $\\theta = \\arcsin \\sqrt{\\frac{M}{N}} = 0$.\nNo matter how many iterations we do, the probability of our measurement yielding a marked state is $0$.</p>\n<p>In practice this means that Grover's search will yield a random non-solution every time.\nTo detect that this is the case, we need to run the algorithm multiple times and note the results. If none of them are problem solutions, we can conclude that the problem doesn't have a solution.</p>\n<h4>Solutions make up half of the search space</h4>\n<p>If $M = \\frac{N}{2}$, then $\\theta = \\arcsin \\sqrt\\frac{N/2}{N} = \\arcsin \\sqrt\\frac{1}{2} = \\frac{\\pi}{4}$.<br />\nThis means that after an arbitrary number of iterations $R$ the amplitude of the basis state $\\ket{\\text{good}}$ in the system will be:</p>\n<p>$$\\sin{(2R+1)\\theta} = \\sin\\frac{(2R+1)\\pi}{4} = \\pm \\frac{1}{\\sqrt{2}}$$</p>\n<p>The probability of the measurement yielding a solution is then $P(\\ket{\\text{good}}) = \\sin^2\\frac{(2R+1)\\theta}{2} = (\\pm \\frac{1}{\\sqrt{2}})^2 = \\frac{1}{2}$</p>\n<p>You can see that the probability of measuring a state that is a solution remains constant regardless of the number of iterations.</p>\n<h4>Solutions make up more than half of the search space</h4>\n<p>If $\\frac{N}{2} &lt; M \\leq N$, then $\\frac{\\pi}{4} &lt; \\theta \\leq \\frac{\\pi}{4}$.\nNow using even one iteration doesn't always increase $P(\\ket{\\text{good}}) = \\sin^2{(2R+1)\\theta}$.\nIn fact, the first iteration is likely to decrease the probability of success!</p>\n<blockquote>\n<p>Have you ever wondered why all tutorials on Grover's search start with two-bit functions?\nThat's the reason why: if you have only one bit, you only have functions for which $M=0$, $M=\\frac{N}{2}$, or $M=N$, and none of these make for a good illustration of the algorithm!</p>\n</blockquote>\n<p>The last two scenarios are a lot easier to handle classically.\nIndeed, a randomly selected classical value has a probability of being a problem solution $p = \\frac{M}{N} &gt; \\frac{1}{2}$!\nIf we repeat the random selection of the variable $k$ times, the probability of success grows to $1-(1-p)^k$, thus by increasing $k$ we can get this probabilty as close to $1$ as we need.\nFor example, For $p=0.5$ and $k=10$ the probality of success is about $99.9\\%$.</p>\n<h4>Unknown number of solutions</h4>\n<p>In practical applications you don't usually know how many solutions your problem has before you start solving it.\nIn this case, you can pick the number of iterations as a random number between 1 and $\\frac{\\pi}{4} \\sqrt{N}$,\nand if the search did not yield the result on the first run, re-run it with a different number of iterations.\nSince Grover's algorithm is probabilistic, you don't nee to get the exact number of iterations to get a correct answer!</p>\n"
7088
+ }
7089
+ ]
7090
+ },
7091
+ {
7092
+ "type": "lesson",
7093
+ "id": "grovers_search__practicality",
7094
+ "title": "Practicality of Grover's Search Algorithm",
7095
+ "items": [
7096
+ {
7097
+ "type": "text-content",
7098
+ "content": "<p>You saw that Grover's search algorithm offers a theoretical advantage over the classical brute force approach.\nDoes this mean that it is an algorithm that will offer us a practical advantage for search problems?</p>\n<p>Unfortunately, there are several reasons why the answer is &quot;no&quot;.</p>\n<p>First, Grover's algorithm uses no information about problem structure, and demonstrates the advantage over the classical algorithm under the assumption that the classical algorithm doesn't use this information either.\nHowever, the best classical algorithms exploit problem structure, allowing solutions that are much better than brute force search.\nCompared to these algorithms, Grover's algorithm often doesn't offer even a theoretical advantage.\nAdditionally, classical algorithms can use parallel processing and benefit from getting multiple computation results at once.</p>\n<p>Implementing the quantum oracle which encodes a problem instance on a quantum computer can be hard - both in terms of coming up with the code that does that and in terms of the execution time of a single oracle call. The advantage offered by Grover's algorithm is described in terms of the number of queries to the oracle and classical function evaluations. But, if a single oracle call takes many orders of magnitude longer to run than a single classical function evaluation, this overhead can easily negate the advantage in the number of calls. This limitation comes into play even for problems which don't have efficient classical algorithms, such as hash inversion.</p>\n<p>This means that Grover's search is unlikely to offer us a practical advantage over the best classical algorithms for any problems.\nHowever, it remains one of the several fundamental quantum computing algorithms, and a great educational algorithm.\nBesides, a technique that generalizes the idea behind Grover's algorithm called <em>amplitude amplification</em> can be used\nas a building block for other quantum algorithms.</p>\n"
7099
+ }
7100
+ ]
7101
+ },
7102
+ {
7103
+ "type": "lesson",
7104
+ "id": "grovers_search__conclusion",
7105
+ "title": "Conclusion",
7106
+ "items": [
7107
+ {
7108
+ "type": "text-content",
7109
+ "content": "<p>Congratulations! In this kata you learned Grover's search algorithm - one of the fundamental algorithms in quantum computing.\nHere are a few key concepts to keep in mind:</p>\n<ul>\n<li>Grover's search algorithm is an algorithm for unstructured search, also known as function inversion.</li>\n<li>This algorithm offers a theoretical advantage over classical brute force search algorithm.</li>\n<li>Grover's algorithm is unlikely to offer practical advantage for any problems, since classical algorithms typically rely on the knowledge of problem structure and thus do much better than brute force search.</li>\n</ul>\n<p>Next, you will practice applying Grover's algorithm to several more interesting problems.</p>\n"
7110
+ }
7111
+ ]
7112
+ }
7113
+ ],
7114
+ "published": true
7115
+ },
7116
+ {
7117
+ "id": "solving_sat",
7118
+ "title": "Solving SAT Problem Using Grover's Algorithm",
7119
+ "sections": [
7120
+ {
7121
+ "type": "lesson",
7122
+ "id": "solving_sat__overview",
7123
+ "title": "Overview",
7124
+ "items": [
7125
+ {
7126
+ "type": "text-content",
7127
+ "content": "<p>The 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.</p>\n<p>This kata walks you through implementing the quantum oracles for Boolean satisfiability problems, abbreviated as SAT problems,\nand using these oracles to solve these problems with Grover's search.</p>\n<p><strong>This kata covers the following topics:</strong></p>\n<ul>\n<li>Implementation of marking oracles for Boolean logic operators and Boolean expressions</li>\n<li>Implementation of marking oracles for several versions of SAT problems</li>\n</ul>\n<p><strong>What you should know to start working on this kata:</strong></p>\n<ul>\n<li>Fundamental quantum concepts</li>\n<li>Controlled gates</li>\n<li>Oracles, in particular marking oracles</li>\n<li>Grover's search algorithm</li>\n</ul>\n"
7128
+ }
7129
+ ]
7130
+ },
7131
+ {
7132
+ "type": "lesson",
7133
+ "id": "solving_sat__cnf",
7134
+ "title": "Canonical Satisfiability Problem",
7135
+ "items": [
7136
+ {
7137
+ "type": "text-content",
7138
+ "content": "<p>The Boolean satisfiability problem is the problem of determining whether there exists an assignment of Boolean variables $x_j$\nfor which the given Boolean formula evaluates to true.</p>\n<p>The canonical representation for SAT problems is based on the conjunctive normal form of Boolean formulas.\nTo define this form, we'll need several definitions:</p>\n<ul>\n<li>\n<p>The Boolean variables $x_0, ..., x_{n-1}$ are the inputs to the formula.</p>\n</li>\n<li>\n<p>A <em>literal</em> is either a variable $x_j$ (a positive literal) or the negation of a variable $\\neg x_j$ (called a negative literal).</p>\n</li>\n<li>\n<p>A <em>clause</em> is a disjunction (an OR operation) of one or several literals, for example, $x_0 \\vee \\neg x_1$.\nGenerally,\n$$clause(x) = \\bigvee_k y_{k},\\text{ where }y_{k} =\\text{ either }x_j\\text{ or }\\neg x_j\\text{ for some }j \\in \\{0, \\dots, n-1\\}$$</p>\n</li>\n<li>\n<p>Finally, the <em>conjunctive normal form</em> of a formula is a conjunction (an AND operation) of several clauses:\n$$f(x) = \\bigwedge_i \\big(\\bigvee_k y_{ik} \\big),\\text{ where }y_{ik} =\\text{ either }x_j\\text{ or }\\neg x_j\\text{ for some }j \\in \\{0, \\dots, n-1\\}$$</p>\n</li>\n</ul>\n<p>In this lesson, you will learn to implement marking oracles for SAT problems given as their conjunctive normal form descriptions.</p>\n"
7139
+ }
7140
+ ]
7141
+ },
7142
+ {
7143
+ "type": "exercise",
7144
+ "id": "solving_sat__and",
7145
+ "title": "Evaluate AND Operator",
7146
+ "description": {
7147
+ "type": "text-content",
7148
+ "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>$N$ qubits in an arbitrary state $\\ket{x}$ (input/query register).</li>\n<li>A qubit in an arbitrary state $\\ket{y}$ (output/target qubit).</li>\n</ol>\n<p><strong>Goal:</strong>\nImplement a quantum oracle which calculates the AND of the inputs, i.e., $f(x) = x_0 \\wedge x_1 \\wedge ... \\wedge x_{N-1}$.</p>\n<p>Leave 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.</p>\n"
7149
+ },
7150
+ "sourceIds": [
7151
+ "solving_sat__and__Verification.qs",
7152
+ "KatasLibrary.qs",
7153
+ "solving_sat__Common.qs"
7154
+ ],
7155
+ "placeholderCode": "namespace Kata {\n operation Oracle_And(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}\n",
7156
+ "explainedSolution": {
7157
+ "type": "explained-solution",
7158
+ "items": [
7159
+ {
7160
+ "type": "text-content",
7161
+ "content": "<p>The goal is to flip the qubit $\\ket{y}$ if and only if all qubits in the register $\\ket{x}$ are in the state $\\ket{1}$.</p>\n<p>The required unitary $U_{and}$ is such that:\n$$U_{and}\\ket{x}\\ket{y} = \\begin{cases} \n \\ket{x}\\ket{y} &amp; \\text{if }x \\neq 1...1 \\\\\n \\ket{x}X\\ket{y} &amp; \\text{if }x = 1...1 \n \\end{cases}$$</p>\n<p>This transformation can be implemented as a <code>Controlled X</code> gate, with the input register $\\ket{x}$ as control and the target qubit $\\ket{y}$ as target.</p>\n"
7162
+ },
7163
+ {
7164
+ "type": "solution",
7165
+ "id": "solving_sat__and_solution",
7166
+ "code": "namespace Kata {\n operation Oracle_And(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n Controlled X(x, y);\n } \n}\n"
7167
+ }
7168
+ ]
7169
+ }
7170
+ },
7171
+ {
7172
+ "type": "exercise",
7173
+ "id": "solving_sat__or",
7174
+ "title": "Evaluate OR Operator",
7175
+ "description": {
7176
+ "type": "text-content",
7177
+ "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>$N$ qubits in an arbitrary state $\\ket{x}$ (input/query register).</li>\n<li>A qubit in an arbitrary state $\\ket{y}$ (output/target qubit).</li>\n</ol>\n<p><strong>Goal:</strong>\nImplement a quantum oracle which calculates the OR of the inputs, i.e., $f(x) = x_0 \\vee x_1 \\vee ... \\vee x_{N-1}$.</p>\n<p>Leave 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.</p>\n"
7178
+ },
7179
+ "sourceIds": [
7180
+ "solving_sat__or__Verification.qs",
7181
+ "KatasLibrary.qs",
7182
+ "solving_sat__Common.qs"
7183
+ ],
7184
+ "placeholderCode": "namespace Kata {\n operation Oracle_Or(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}\n",
7185
+ "explainedSolution": {
7186
+ "type": "explained-solution",
7187
+ "items": [
7188
+ {
7189
+ "type": "text-content",
7190
+ "content": "<p>The goal is to flip the qubit $\\ket{y}$ if and only if at least one of the qubits in the register $\\ket{x}$ is in the state $\\ket{1}$.</p>\n<p>The required unitary $U_{or}$ is such that:\n$$U_{or}\\ket{x}\\ket{y} = \\begin{cases} \n \\ket{x}\\ket{y} &amp; \\text{if }x = 0...0 \\\\\n \\ket{x}X\\ket{y} &amp; \\text{if }x \\neq 0...0\n \\end{cases}$$</p>\n<p>This transformation can be implemented as a sequence of two steps:</p>\n<ol>\n<li>Flip the state of the target qubit if $x = 0...0$ using a controlled-on-zero $X$ gate.</li>\n<li>Flip the state of the target qubit using an $X$ gate. This will negate the results of the previous step,\nmaking sure that overall the state of the target qubit is flipped if $x \\neq 0...0$.</li>\n</ol>\n"
7191
+ },
7192
+ {
7193
+ "type": "solution",
7194
+ "id": "solving_sat__or_solution",
7195
+ "code": "namespace Kata {\n operation Oracle_Or(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n ApplyControlledOnInt(0, X, x, y);\n X(y);\n } \n}\n"
7196
+ }
7197
+ ]
7198
+ }
7199
+ },
7200
+ {
7201
+ "type": "exercise",
7202
+ "id": "solving_sat__sat_clause",
7203
+ "title": "Evaluate One Clause",
7204
+ "description": {
7205
+ "type": "text-content",
7206
+ "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>$N$ qubits in an arbitrary state $\\ket{x}$ (input/query register).</li>\n<li>A qubit in an arbitrary state $\\ket{y}$ (output/target qubit).</li>\n<li>An array of tuples <code>clause</code> which describes one clause of a SAT problem instance $clause(x)$.\nEach tuple is an <code>(Int, Bool)</code> pair describing one component of the clause:\n<ul>\n<li>the first element is the index $j$ of the variable $x_j$,</li>\n<li>the second element is <code>true</code> if the variable is included as itself ($x_j$) and <code>false</code> if it is included as a negation ($\\neg x_j$).</li>\n</ul>\n</li>\n</ol>\n<p>For example, clause $x_0 \\vee \\neg x_1$ can be represented as <code>[(0, true), (1, false)]</code>.</p>\n<p><strong>Goal:</strong>\nImplement a quantum oracle which evaluates the clause $clause(x)$.</p>\n<p>Leave 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.</p>\n"
7207
+ },
7208
+ "sourceIds": [
7209
+ "solving_sat__sat_clause__Verification.qs",
7210
+ "KatasLibrary.qs",
7211
+ "solving_sat__Common.qs"
7212
+ ],
7213
+ "placeholderCode": "namespace Kata {\n operation Oracle_SATClause(x : Qubit[], y : Qubit, clause : (Int, Bool)[]) : 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_Or(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n ApplyControlledOnInt(0, X, x, y);\n X(y);\n } \n}\n",
7214
+ "explainedSolution": {
7215
+ "type": "explained-solution",
7216
+ "items": [
7217
+ {
7218
+ "type": "text-content",
7219
+ "content": "<p>This task involves evaluating a clause which is a disjunction (OR) of negated and non-negated variables encoded in the input $x$.\nThis can be done in two steps:</p>\n<ol>\n<li>First, flip the qubits which are negated in <code>clause</code> (and later undo this operation).<br />\nTo do this, apply an $X$ gate to qubit $j$ if and only if the clause has a term of the form <code>(j, false)</code>.</li>\n<li>Use the $U_{or}$ unitary (implemented by the operation <code>Oracle_Or</code>) to calculate the clause.<br />\nTo do this, you need to first construct an array <code>clauseQubits</code> - all qubits which are included as a negated or non-negated variable in the clause. Then, you can apply the <code>Oracle_Or</code> operation to qubits <code>clauseQubits</code> and <code>y</code>.</li>\n</ol>\n<p>Note that the implementation of <code>Oracle_SATClause</code> should be adjointable, and it's nice to be able to rely on Q# compiler to generate the adjoint variant of this operation.\nThat's why the solution uses the library function <code>Mapped</code> instead of classical computations that involve manipulating mutable variables - those would have to be moved to a separate function, making the code bulkier.</p>\n"
7220
+ },
7221
+ {
7222
+ "type": "solution",
7223
+ "id": "solving_sat__sat_clause_solution",
7224
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n operation Oracle_SATClause(x : Qubit[], y : Qubit, clause : (Int, Bool)[]) : Unit is Adj + Ctl {\n let clauseQubits = Mapped((ind, _) -> x[ind], clause);\n within {\n for (ind, positive) in clause {\n if not positive {\n X(x[ind]);\n }\n }\n } apply {\n Oracle_Or(clauseQubits, y);\n }\n }\n\n operation Oracle_Or(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n ApplyControlledOnInt(0, X, x, y);\n X(y);\n } \n}\n"
7225
+ }
7226
+ ]
7227
+ }
7228
+ },
7229
+ {
7230
+ "type": "exercise",
7231
+ "id": "solving_sat__sat_formula",
7232
+ "title": "Evaluate SAT Formula",
7233
+ "description": {
7234
+ "type": "text-content",
7235
+ "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>$N$ qubits in an arbitrary state $\\ket{x}$ (input/query register).</li>\n<li>A qubit in an arbitrary state $\\ket{y}$ (output/target qubit).</li>\n<li>A two-dimensional array of tuples <code>formula</code> which describes a SAT problem instance $f(x)$.\n$i$-th element of <code>formula</code> is an array of tuples that describes the $i$-th clause of $f(x)$ using the same format as the previous exercise.</li>\n</ol>\n<p>For example, a two-variable SAT formula that evaluates the XOR of two inputs $f(x) = (x_0 \\vee x_1) \\wedge (\\neg x_0 \\vee \\neg x_1)$ can be represented as <code>[[(0, true), (1, true)], [(0, false), (1, false)]]</code>.</p>\n<p><strong>Goal:</strong>\nImplement a quantum oracle which evaluates the formula $f(x)$.</p>\n<p>Leave 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.</p>\n"
7236
+ },
7237
+ "sourceIds": [
7238
+ "solving_sat__sat_formula__Verification.qs",
7239
+ "KatasLibrary.qs",
7240
+ "solving_sat__Common.qs"
7241
+ ],
7242
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation Oracle_SATFormula(x : Qubit[], y : Qubit, formula : (Int, Bool)[][]) : 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_SATClause(x : Qubit[], y : Qubit, clause : (Int, Bool)[]) : Unit is Adj + Ctl {\n let clauseQubits = Mapped((ind, _) -> x[ind], clause);\n within {\n for (ind, positive) in clause {\n if not positive {\n X(x[ind]);\n }\n }\n } apply {\n Oracle_Or(clauseQubits, y);\n }\n }\n\n operation Oracle_Or(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n ApplyControlledOnInt(0, X, x, y);\n X(y);\n } \n\n operation Oracle_And(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n Controlled X(x, y);\n } \n}\n",
7243
+ "explainedSolution": {
7244
+ "type": "explained-solution",
7245
+ "items": [
7246
+ {
7247
+ "type": "text-content",
7248
+ "content": "<p>This task consists of a conjunction (AND) of results of multiple clause evaluations. Each clause individually can be evaluated using the code you've written in the previous exercise. The computation results of these clauses must be stored temporarily in freshly allocated qubits. Then the conjunction of these results can be computed using <code>Oracle_And</code> from the first exercise.</p>\n<p>Let's denote the number of clauses in the formula as $m$. The steps for implementing the SAT oracle will be:</p>\n<ol>\n<li>Allocate an array of $m$ qubits <code>aux</code> in the state $\\ket{0}$.</li>\n<li>Evaluate each clause using <code>Oracle_SATClause</code> from the previous exercise, with the corresponding element of <code>aux</code> as the target qubit.</li>\n<li>Evaluate the SAT formula using <code>Oracle_And</code> implemented in the first task with <code>aux</code> as the input register and <code>target</code> as the target qubit.</li>\n<li>Undo step 2 to restore the auxiliary qubits back into the $\\ket{0}$ state before releasing them.</li>\n</ol>\n<p>You can again use the within-apply Q# language construct to perform steps 2, 3 and 4 with the last step generated automatically.</p>\n"
7249
+ },
7250
+ {
7251
+ "type": "solution",
7252
+ "id": "solving_sat__sat_formula_solution",
7253
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation Oracle_SATFormula(x : Qubit[], y : Qubit, formula : (Int, Bool)[][]) : Unit is Adj + Ctl {\n use aux = Qubit[Length(formula)];\n within {\n for i in 0 .. Length(formula) - 1 {\n Oracle_SATClause(x, aux[i], formula[i]);\n }\n } apply {\n Oracle_And(aux, y);\n }\n }\n\n operation Oracle_SATClause(x : Qubit[], y : Qubit, clause : (Int, Bool)[]) : Unit is Adj + Ctl {\n let clauseQubits = Mapped((ind, _) -> x[ind], clause);\n within {\n for (ind, positive) in clause {\n if not positive {\n X(x[ind]);\n }\n }\n } apply {\n Oracle_Or(clauseQubits, y);\n }\n }\n\n operation Oracle_Or(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n ApplyControlledOnInt(0, X, x, y);\n X(y);\n } \n\n operation Oracle_And(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n Controlled X(x, y);\n } \n}\n"
7254
+ }
7255
+ ]
7256
+ }
7257
+ },
7258
+ {
7259
+ "type": "lesson",
7260
+ "id": "solving_sat__exactly_one_3sat",
7261
+ "title": "Exactly-1 3-SAT Problem",
7262
+ "items": [
7263
+ {
7264
+ "type": "text-content",
7265
+ "content": "<p>Exactly-1 3-SAT problem (also known as &quot;one-in-three 3-SAT&quot;) is a variant of a general SAT problem.\nThe structure of the formula that describes an instance of an exactly-1 3-SAT problem is exactly the same as that of the canonical SAT problem, with each clause consisting of exactly three literals.\nHowever, the problem is to find an assignment of the variables that makes each clause have <em>exactly one</em> true literal,\nwhile in a normal SAT problem each clause can have one or more true literal to satisfy the formula.</p>\n<p>Formally, the clauses of exactly-1 3-SAT problem can be defined via the use of a ternary operator that is <code>true</code> if and only if exactly one of the arguments is <code>true</code>. However, this kata uses the same formula notation for these clauses as the canonical SAT problem.</p>\n"
7266
+ }
7267
+ ]
7268
+ },
7269
+ {
7270
+ "type": "exercise",
7271
+ "id": "solving_sat__exactly_one_one",
7272
+ "title": "Evaluate \"Exactly 1 One\" Operator",
7273
+ "description": {
7274
+ "type": "text-content",
7275
+ "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>Three qubits in an arbitrary state $\\ket{x}$ (input/query register).</li>\n<li>A qubit in an arbitrary state $\\ket{y}$ (output/target qubit).</li>\n</ol>\n<p><strong>Goal:</strong>\nImplement a quantum oracle which calculates the function that checks whether exactly one of the inputs is $1$, i.e., $f(x) = 1$ if exactly one bit of $x$ is $1$, and $0$ otherwise.</p>\n<p>Leave 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.</p>\n"
7276
+ },
7277
+ "sourceIds": [
7278
+ "solving_sat__exactly_one_one__Verification.qs",
7279
+ "KatasLibrary.qs",
7280
+ "solving_sat__Common.qs"
7281
+ ],
7282
+ "placeholderCode": "namespace Kata {\n operation Oracle_Exactly1One(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n}\n",
7283
+ "explainedSolution": {
7284
+ "type": "explained-solution",
7285
+ "items": [
7286
+ {
7287
+ "type": "text-content",
7288
+ "content": "<p>Consider the set of all bit strings $x$ of length $n$ which have only one bit of $x$ equal to $1$.<br />\nThis set of bit strings is $S=\\{00...01, 00...10, ..., 00..1..00, ..., 01...00, 10...00\\}$,\nor, if we convert the bit strings to integers,\n$$S=\\{1,2,4,..2^i,..,2^{n-1}\\} = \\{2^k: 0 \\le k \\le n-1\\}$$</p>\n<p>You need to implement an oracle that flips $\\ket{y}$ if the input basis state $\\ket{x}$ corresponds to one of the bit strings in $S$.\nThe easiest way to do this is to use $n$ controlled $X$ gates, with <code>x</code> as control and the qubit <code>y</code> flipped if and only if the control register is in a particular state of the form $2^k$.\nYou can use the library operation <code>ApplyControlledOnInt</code> for this with integers $1, 2, 4, ...$ as controls.\nNotice that this operation uses little endian notation to convert integers to bit strings, but it doesn't matter for this exercise.\nYou need to iterate through all bit strings that have exactly one $1$ in their notation, and the order in which you iterate is not important.</p>\n"
7289
+ },
7290
+ {
7291
+ "type": "solution",
7292
+ "id": "solving_sat__exactly_one_one_solution",
7293
+ "code": "namespace Kata {\n operation Oracle_Exactly1One(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n for i in 0 .. Length(x) - 1 {\n ApplyControlledOnInt(2 ^ i, X, x, y);\n }\n } \n}\n"
7294
+ }
7295
+ ]
7296
+ }
7297
+ },
7298
+ {
7299
+ "type": "exercise",
7300
+ "id": "solving_sat__exactly_one_one_formula",
7301
+ "title": "Evaluate Exactly-1 3-SAT Formula",
7302
+ "description": {
7303
+ "type": "text-content",
7304
+ "content": "<p><strong>Inputs:</strong></p>\n<ol>\n<li>$N$ qubits in an arbitrary state $\\ket{x}$ (input/query register).</li>\n<li>A qubit in an arbitrary state $\\ket{y}$ (output/target qubit).</li>\n<li>A two-dimensional array of tuples <code>formula</code> which describes a SAT problem instance $f(x)$.\n$i$-th element of <code>formula</code> is an array of tuples that describes the $i$-th clause of $f(x)$ using the same format as the previous exercise. Each clause of the formula is guaranteed to have exactly three literals.</li>\n</ol>\n<p>For example, a three-variable SAT formula with one clause $f(x) = (x_0 \\vee x_1 \\vee x_2)$ can be represented as <code>[[(0, true), (1, true), (2, true)]]</code>,\nand its solutions will be <code>(true, false, false)</code>, <code>(false, true, false)</code> and <code>(false, false, true)</code>.</p>\n<p><strong>Goal:</strong>\nImplement a quantum oracle which evaluates the exactly-1 3-SAT formula $f(x)$.</p>\n<p>Leave 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.</p>\n"
7305
+ },
7306
+ "sourceIds": [
7307
+ "solving_sat__exactly_one_one_formula__Verification.qs",
7308
+ "KatasLibrary.qs",
7309
+ "solving_sat__Common.qs"
7310
+ ],
7311
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation Oracle_Exactly13SATFormula(x : Qubit[], y : Qubit, formula : (Int, Bool)[][]) : Unit is Adj + Ctl {\n // Implement your solution here...\n\n }\n\n // You might want to implement this helper operation that evaluates a single clause and use it in your solution.\n operation Oracle_Exactly13SATClause(x : Qubit[], y : Qubit, clause : (Int, Bool)[]) : 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_Exactly1One(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n for i in 0 .. Length(x) - 1 {\n ApplyControlledOnInt(2 ^ i, X, x, y);\n }\n } \n\n operation Oracle_And(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n Controlled X(x, y);\n } \n}\n",
7312
+ "explainedSolution": {
7313
+ "type": "explained-solution",
7314
+ "items": [
7315
+ {
7316
+ "type": "text-content",
7317
+ "content": "<p>This exercise is similar to the task of evaluating a SAT formula from the first lesson: it consists of a conjunction (AND) of results of multiple clause evaluations. This time, though, each clause has to be evaluated using the &quot;Exactly One 1&quot; policy you've implemented in the previous exercise instead of the <code>Oracle_Or</code> you used in the first lesson.</p>\n<p>With this replacement, the code that evaluates a single clause is very similar to that from the exercise &quot;Evaluate One Clause&quot;,\nand the code that evaluates the whole formula - to that from the exercise &quot;Evaluate SAT Formula&quot;.</p>\n"
7318
+ },
7319
+ {
7320
+ "type": "solution",
7321
+ "id": "solving_sat__exactly_one_one_formula_solution",
7322
+ "code": "namespace Kata {\n open Microsoft.Quantum.Arrays;\n\n operation Oracle_Exactly13SATFormula(x : Qubit[], y : Qubit, formula : (Int, Bool)[][]) : Unit is Adj + Ctl {\n use aux = Qubit[Length(formula)];\n within {\n for i in 0 .. Length(formula) - 1 {\n Oracle_Exactly13SATClause(x, aux[i], formula[i]);\n }\n } apply {\n Oracle_And(aux, y);\n }\n }\n\n // You might want to implement this helper operation that evaluates a single clause and use it in your solution.\n operation Oracle_Exactly13SATClause(x : Qubit[], y : Qubit, clause : (Int, Bool)[]) : Unit is Adj + Ctl {\n let clauseQubits = Mapped((ind, _) -> x[ind], clause);\n within {\n for (ind, positive) in clause {\n if not positive {\n X(x[ind]);\n }\n }\n } apply {\n Oracle_Exactly1One(clauseQubits, y);\n }\n }\n\n // You might find these helper operations from earlier tasks useful.\n operation Oracle_Exactly1One(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n for i in 0 .. Length(x) - 1 {\n ApplyControlledOnInt(2 ^ i, X, x, y);\n }\n } \n\n operation Oracle_And(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n Controlled X(x, y);\n } \n}\n"
7323
+ }
7324
+ ]
7325
+ }
7326
+ },
7327
+ {
7328
+ "type": "lesson",
7329
+ "id": "solving_sat__using_grover",
7330
+ "title": "Using Grover's Algorithm to Solve SAT Problems",
7331
+ "items": [
7332
+ {
7333
+ "type": "text-content",
7334
+ "content": "<p>In this lesson, you will experiment with using Grover's algorithm to solve SAT problems.</p>\n<p>Notice that in 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 &quot;Grover's Search Algorithm&quot; kata.\nExperiment with choosing the number of iterations at random. How does this affect the success probability?</p>\n"
7335
+ },
7336
+ {
7337
+ "type": "example",
7338
+ "id": "solving_sat__e2edemo",
7339
+ "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 SolvingSATWithGroverDemo() : Unit {\n // Experiment with the parameters to explore algorithm behavior in different conditions!\n let n = 3;\n // (x₀ ∨ x₁) ∧ (¬x₀ ∨ ¬x₁) ∧ ¬x₂\n let formula = [[(0, true), (1, true)], [(0, false), (1, false)], [(2, false)]];\n let markingOracle = Oracle_SATFormula(_, _, formula);\n for iterations in 0 .. 9 {\n mutable success = 0;\n for _ in 1 .. 100 {\n let res = GroversSearch(n, markingOracle, iterations);\n if F_SATFormula(res, formula) {\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_SATFormula(x : Qubit[], y : Qubit, formula : (Int, Bool)[][]) : Unit is Adj + Ctl {\n use aux = Qubit[Length(formula)];\n within {\n for i in 0 .. Length(formula) - 1 {\n Oracle_SATClause(x, aux[i], formula[i]);\n }\n } apply {\n Oracle_And(aux, y);\n }\n }\n\n operation Oracle_SATClause(x : Qubit[], y : Qubit, clause : (Int, Bool)[]) : Unit is Adj + Ctl {\n let clauseQubits = Mapped((ind, _) -> x[ind], clause);\n within {\n for (ind, positive) in clause {\n if not positive {\n X(x[ind]);\n }\n }\n } apply {\n Oracle_Or(clauseQubits, y);\n }\n }\n\n operation Oracle_Or(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n ApplyControlledOnInt(0, X, x, y);\n X(y);\n } \n\n operation Oracle_And(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {\n Controlled X(x, y);\n }\n\n function F_SATClause(args : Bool[], clause : (Int, Bool)[]) : Bool {\n for (index, positive) in clause {\n if positive == args[index] {\n // one true literal is sufficient for the clause to be true\n return true;\n }\n }\n // none of the literals is true - the whole clause is false\n return false;\n }\n\n function F_SATFormula(args : Bool[], formula : (Int, Bool)[][]) : Bool {\n for clause in formula {\n // one false clause invalidates the whole formula\n if not F_SATClause(args, clause) {\n return false\n }\n }\n return true;\n }\n}"
7340
+ }
7341
+ ]
7342
+ },
7343
+ {
7344
+ "type": "lesson",
7345
+ "id": "solving_sat__conclusion",
7346
+ "title": "Conclusion",
7347
+ "items": [
7348
+ {
7349
+ "type": "text-content",
7350
+ "content": "<p>Congratulations! In this kata you learned to solve Boolean satisfiability problems using Grover's search.</p>\n"
6916
7351
  }
6917
7352
  ]
6918
7353
  }
@@ -7250,6 +7685,113 @@ export default {
7250
7685
  }
7251
7686
  ],
7252
7687
  "published": true
7688
+ },
7689
+ {
7690
+ "id": "nonlocal_games",
7691
+ "title": "Nonlocal Games",
7692
+ "sections": [
7693
+ {
7694
+ "type": "lesson",
7695
+ "id": "nonlocal_games__overview",
7696
+ "title": "Overview",
7697
+ "items": [
7698
+ {
7699
+ "type": "text-content",
7700
+ "content": "<p>This kata introduces three quantum nonlocal games that display &quot;quantum pseudo-telepathy&quot; -\nthe use of quantum entanglement to eliminate the need for classical communication.\nIn this context, &quot;nonlocal&quot; 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 &quot;refereed&quot;, which means the players try to win against the referee.</p>\n<p><strong>This kata covers the following topics:</strong></p>\n<ul>\n<li>Clauser, Horne, Shimony, and Hold thought experiment (often abbreviated as CHSH game)</li>\n<li>Greenberger-Horne-Zeilinger game (often abbreviated as GHZ game)</li>\n<li>The Mermin-Peres Magic Square game</li>\n</ul>\n<p><strong>What you should know to start working on this kata:</strong></p>\n<ul>\n<li>Basic linear algebra</li>\n<li>Basic knowledge of quantum gates and measurements</li>\n</ul>\n"
7701
+ }
7702
+ ]
7703
+ },
7704
+ {
7705
+ "type": "lesson",
7706
+ "id": "nonlocal_games__chsh_game",
7707
+ "title": "CHSH Game",
7708
+ "items": [
7709
+ {
7710
+ "type": "text-content",
7711
+ "content": "<p>In <strong>CHSH Game</strong>, two players (Alice and Bob) try to win the following game:</p>\n<p>Each 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.</p>\n<blockquote>\n<ul>\n<li>∧ is the standard bitwise AND operator.</li>\n<li>⊕ is the exclusive or, or XOR operator, so (P ⊕ Q) is true if exactly one of P and Q is true.</li>\n</ul>\n</blockquote>\n"
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": "<p>To start with, let's take a look at how you would play the classical variant of this game without access to any quantum tools.</p>\n"
7723
+ }
7724
+ ]
7725
+ },
7726
+ {
7727
+ "type": "exercise",
7728
+ "id": "nonlocal_games__chsh_classical_win_condition",
7729
+ "title": "Win Condition",
7730
+ "description": {
7731
+ "type": "text-content",
7732
+ "content": "<p><strong>Input:</strong></p>\n<ul>\n<li>Alice and Bob's starting bits (X and Y).</li>\n<li>Alice and Bob's output bits (A and B).</li>\n</ul>\n<p><strong>Output:</strong>\nTrue if Alice and Bob won the CHSH game, that is, if X ∧ Y = A ⊕ B, and false otherwise.</p>\n"
7733
+ },
7734
+ "sourceIds": [
7735
+ "nonlocal_games__chsh_classical_win_condition__Verification.qs",
7736
+ "KatasLibrary.qs"
7737
+ ],
7738
+ "placeholderCode": "namespace Kata {\n function WinCondition (x : Bool, y : Bool, a : Bool, b : Bool) : Bool {\n // Implement your solution here...\n\n return false;\n }\n}\n",
7739
+ "explainedSolution": {
7740
+ "type": "explained-solution",
7741
+ "items": [
7742
+ {
7743
+ "type": "text-content",
7744
+ "content": "<p>There 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.</p>\n<p>To 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 <a href=\"https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions\">built-in operators</a>: $x ∧ y$ as <code>x and y</code> and $a ⊕ b$ as <code>a != b</code>.</p>\n"
7745
+ },
7746
+ {
7747
+ "type": "solution",
7748
+ "id": "nonlocal_games__chsh_classical_win_condition_solution",
7749
+ "code": "namespace Kata {\n function WinCondition (x : Bool, y : Bool, a : Bool, b : Bool) : Bool {\n return (x and y) == (a != b);\n }\n}\n"
7750
+ }
7751
+ ]
7752
+ }
7753
+ },
7754
+ {
7755
+ "type": "exercise",
7756
+ "id": "nonlocal_games__chsh_classical_strategy",
7757
+ "title": "Alice and Bob's Classical Strategy",
7758
+ "description": {
7759
+ "type": "text-content",
7760
+ "content": "<p>In this task you have to implement two functions, one for Alice's classical strategy and one for Bob's.\nNote that they are covered by one test, so you have to implement both to pass the test.</p>\n<p><strong>Input:</strong>\nAlice and Bob's starting bits (X and Y).</p>\n<p><strong>Output:</strong>\nAlice and Bob's output bits (A and B) to maximize their chance of winning.</p>\n"
7761
+ },
7762
+ "sourceIds": [
7763
+ "nonlocal_games__chsh_classical_strategy__Verification.qs",
7764
+ "KatasLibrary.qs"
7765
+ ],
7766
+ "placeholderCode": "namespace Kata {\n function AliceClassical (x : Bool) : Bool {\n // Implement your solution here...\n\n return false;\n }\n\n function BobClassical (y : Bool) : Bool {\n // Implement your solution here...\n\n return true;\n }\n}\n",
7767
+ "explainedSolution": {
7768
+ "type": "explained-solution",
7769
+ "items": [
7770
+ {
7771
+ "type": "text-content",
7772
+ "content": "<p>If 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.</p>\n"
7773
+ },
7774
+ {
7775
+ "type": "solution",
7776
+ "id": "nonlocal_games__chsh_classical_strategy_solution",
7777
+ "code": "namespace Kata {\n function AliceClassical (x : Bool) : Bool {\n return false;\n }\n\n function BobClassical (y : Bool) : Bool {\n return false;\n }\n}\n"
7778
+ }
7779
+ ]
7780
+ }
7781
+ },
7782
+ {
7783
+ "type": "lesson",
7784
+ "id": "nonlocal_games__conclusion",
7785
+ "title": "Conclusion",
7786
+ "items": [
7787
+ {
7788
+ "type": "text-content",
7789
+ "content": "<p>Congratulations! In this kata you learned how to use quantum entanglement in nonlocal quantum games to get results that are better than any classical strategy can offer.</p>\n"
7790
+ }
7791
+ ]
7792
+ }
7793
+ ],
7794
+ "published": false
7253
7795
  }
7254
7796
  ],
7255
7797
  "globalCodeSources": [
@@ -7997,6 +8539,50 @@ export default {
7997
8539
  "id": "deutsch_jozsa__implement_bv__Verification.qs",
7998
8540
  "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n\n operation CheckSolution() : Bool {\n for (n, oracle, expected, name) in [(2, qs => (), [0, 0], \"f(x) = 0\"), \n (3, qs => (), [0, 0, 0], \"f(x) = 0\"), \n (2, ApplyToEach(Z, _), [1, 1], \"f(x) = parity of x\"), \n (3, ApplyToEach(Z, _), [1, 1, 1], \"f(x) = parity of x\"), \n (2, qs => Z(qs[0]), [1, 0], \"f(x) = most significant bit of x\"), \n (3, qs => Z(qs[2]), [0, 0, 1], \"f(x) = least significant bit of x\"), \n (3, qs => Z(qs[1]), [0, 1, 0], \"f(x) = middle bit of x\")\n ] {\n let actual = Kata.BernsteinVaziraniAlgorithm(n, oracle);\n if actual != expected {\n Message(\"Incorrect.\");\n Message($\"The bit string for {name} for {n} bits identified as {actual} but it is {expected}.\");\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
7999
8541
  },
8542
+ {
8543
+ "id": "grovers_search__prefix_oracle__Verification.qs",
8544
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n function F_StartsWith(args : Bool[], p : Bool[]) : Bool {\n for i in 0 .. Length(p) - 1 {\n if p[i] != args[i] {\n return false;\n }\n }\n return true;\n } \n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for (n, p) in [\n (2, []),\n (2, [true]),\n (2, [true, false]),\n (3, [false, true]),\n (4, [true, true, false]),\n (5, [false])\n ] {\n if not CheckOracleImplementsFunction(n, Kata.Oracle_StartsWith(_, _, p), F_StartsWith(_, p)) {\n Message($\"Test failed for N = {n}, p = {p}\");\n return false; \n }\n }\n\n Message(\"Correct!\");\n true \n } \n}\n"
8545
+ },
8546
+ {
8547
+ "id": "grovers_search__phase_oracle__Verification.qs",
8548
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Random;\n\n operation ApplyMarkingOracleAsPhaseOracle_Reference(\n markingOracle : ((Qubit[], Qubit) => Unit is Adj + Ctl),\n qubits : Qubit[]) : Unit is Adj + Ctl {\n\n use minus = Qubit();\n within {\n X(minus);\n H(minus);\n } apply {\n markingOracle(qubits, minus);\n }\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 1 .. 3 {\n for k in 0 .. 2^N - 1 {\n let pattern = IntAsBoolArray(k, N);\n let marking = ApplyControlledOnBitString(pattern, X, _, _);\n let sol = Kata.ApplyMarkingOracleAsPhaseOracle(marking, _);\n let ref = ApplyMarkingOracleAsPhaseOracle_Reference(marking, _);\n\n let isCorrect = CheckOperationsAreEqualStrict(N, sol, ref);\n\n if not isCorrect {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit oracle that marks the bit string {pattern}\");\n ShowQuantumStateComparison(N, PrepDemoState, sol, ref);\n return false;\n }\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
8549
+ },
8550
+ {
8551
+ "id": "grovers_search__conditional_phase_flip__Verification.qs",
8552
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\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 @EntryPoint()\n operation CheckSolution() : Bool {\n for N in 2 .. 4 {\n if not CheckOperationsAreEqualStrict(N, Kata.ConditionalPhaseFlip, ConditionalPhaseFlip) {\n Message(\"Incorrect.\");\n Message(\"Hint: examine how your solution transforms the given state and compare it with the expected \" +\n $\"transformation for the {N}-bit inputs\");\n ShowQuantumStateComparison(N, PrepDemoState, Kata.ConditionalPhaseFlip, ConditionalPhaseFlip);\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n\n}\n"
8553
+ },
8554
+ {
8555
+ "id": "grovers_search__reflection_about_state__Verification.qs",
8556
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Katas;\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 // You might find this helper operation from an earlier task useful.\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 @EntryPoint()\n operation CheckSolution() : Bool {\n for (N, statePrep) in [(2, qs => I(qs[0])), (3, ApplyToEachCA(H, _)), (1, qs => Ry(0.5, qs[0]))] {\n let sol = Kata.ReflectionAboutState(_, statePrep);\n let ref = ReflectionAboutState(_, statePrep);\n if not CheckOperationsAreEqualStrict(N, sol, ref) {\n Message(\"Incorrect.\");\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
8557
+ },
8558
+ {
8559
+ "id": "solving_sat__and__Verification.qs",
8560
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Arrays;\n\n function F_And(args : Bool[]) : Bool {\n return Count(x -> not x, args) == 0;\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for n in 1..5 {\n if not CheckOracleImplementsFunction(n, Kata.Oracle_And, F_And) {\n Message($\"Test failed for n = {n}\");\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
8561
+ },
8562
+ {
8563
+ "id": "solving_sat__Common.qs",
8564
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Random;\n\n // Helper functions to pretty-print SAT formulas\n function SATVariableAsString (var : (Int, Bool)) : String {\n let (index, positive) = var;\n return (positive ? \"\" | \"¬\") + $\"x{index}\";\n }\n\n function SATClauseAsString (clause : (Int, Bool)[]) : String {\n mutable ret = SATVariableAsString(clause[0]);\n for ind in 1 .. Length(clause) - 1 {\n set ret = ret + \" ∨ \" + SATVariableAsString(clause[ind]);\n }\n return ret;\n }\n\n function SATFormulaAsString (formula : (Int, Bool)[][]) : String {\n mutable ret = \"(\" + SATClauseAsString(formula[0]) + \")\";\n for ind in 1 .. Length(formula) - 1 {\n set ret = ret + \" ∧ (\" + SATClauseAsString(formula[ind]) + \")\";\n }\n return ret;\n }\n\n // Helper operations to generate random SAT formulas\n operation Generate_SAT_Clause (nVar : Int, nTerms : Int) : (Int, Bool)[] {\n // number of terms in clause is either given or (if nTerms <= 0) chosen randomly\n mutable nVarInClause = (nTerms > 0) ? nTerms | DrawRandomInt(1, 4);\n if nVarInClause > nVar {\n set nVarInClause = nVar;\n }\n \n mutable clause = [(0, false), size = nVarInClause];\n mutable usedVariables = [false, size = nVar];\n // Make sure variables in the clause are distinct\n for k in 0 .. nVarInClause - 1 {\n mutable nextInd = -1;\n repeat { \n set nextInd = DrawRandomInt(0, nVar - 1);\n } until (not usedVariables[nextInd])\n fixup {}\n set clause w/= k <- (nextInd, DrawRandomBool(0.5));\n set usedVariables w/= nextInd <- true;\n }\n return clause;\n }\n\n operation GenerateSATInstance (nVar : Int, nClause : Int, nTerms : Int) : (Int, Bool)[][] {\n mutable problem = [[(0, false), size = 0], size = nClause];\n\n for j in 0 .. nClause - 1 {\n set problem w/= j <- Generate_SAT_Clause(nVar, nTerms);\n }\n return problem;\n }\n}"
8565
+ },
8566
+ {
8567
+ "id": "solving_sat__or__Verification.qs",
8568
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Arrays;\n\n function F_Or(args : Bool[]) : Bool {\n return Count(x -> x, args) > 0;\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for n in 1..5 {\n if not CheckOracleImplementsFunction(n, Kata.Oracle_Or, F_Or) {\n Message($\"Test failed for n = {n}\");\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
8569
+ },
8570
+ {
8571
+ "id": "solving_sat__sat_clause__Verification.qs",
8572
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Random;\n\n function F_SATClause(args : Bool[], clause : (Int, Bool)[]) : Bool {\n for (index, positive) in clause {\n if positive == args[index] {\n // one true literal is sufficient for the clause to be true\n return true;\n }\n }\n // none of the literals is true - the whole clause is false\n return false;\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for i in 1 .. 6 {\n let nVar = DrawRandomInt(3, 7);\n let clause = Generate_SAT_Clause(nVar, i);\n \n if not CheckOracleImplementsFunction(nVar, Kata.Oracle_SATClause(_, _, clause), F_SATClause(_, clause)) {\n Message($\"Test failed for SAT clause {SATClauseAsString(clause)}\");\n return false;\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
8573
+ },
8574
+ {
8575
+ "id": "solving_sat__sat_formula__Verification.qs",
8576
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Random;\n\n function F_SATClause(args : Bool[], clause : (Int, Bool)[]) : Bool {\n for (index, positive) in clause {\n if positive == args[index] {\n // one true literal is sufficient for the clause to be true\n return true;\n }\n }\n // none of the literals is true - the whole clause is false\n return false;\n }\n\n function F_SATFormula(args : Bool[], formula : (Int, Bool)[][]) : Bool {\n for clause in formula {\n // one false clause invalidates the whole formula\n if not F_SATClause(args, clause) {\n return false\n }\n }\n return true;\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for nVar in 2 .. 6 {\n for _ in 1 .. 3 {\n let formula = GenerateSATInstance(nVar, nVar - 1, -1);\n \n if not CheckOracleImplementsFunction(nVar, Kata.Oracle_SATFormula(_, _, formula), F_SATFormula(_, 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"
8577
+ },
8578
+ {
8579
+ "id": "solving_sat__exactly_one_one__Verification.qs",
8580
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Katas;\n\n function F_Exactly1One (args : Bool[]) : Bool {\n return Count(x -> x, args) == 1;\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n if not CheckOracleImplementsFunction(3, Kata.Oracle_Exactly1One, F_Exactly1One) {\n return false;\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
8581
+ },
8582
+ {
8583
+ "id": "solving_sat__exactly_one_one_formula__Verification.qs",
8584
+ "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
+ },
8000
8586
  {
8001
8587
  "id": "qec_shor__zz_measurement__Verification.qs",
8002
8588
  "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"
@@ -8032,6 +8618,14 @@ export default {
8032
8618
  {
8033
8619
  "id": "qec_shor__shor_detect__Verification.qs",
8034
8620
  "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Katas;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Random;\n\n operation ShorEncode (qs : Qubit[]) : Unit is Adj + Ctl {\n BitflipEncode(qs[0 .. 3 .. 8]);\n ApplyToEachCA(H, qs[0 .. 3 .. 8]);\n for i in 0 .. 2 {\n BitflipEncode(qs[3 * i .. 3 * i + 2]);\n }\n }\n\n operation BitflipEncode (qs : Qubit[]) : Unit is Adj + Ctl {\n CNOT(qs[0], qs[1]);\n CNOT(qs[0], qs[2]);\n }\n\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for err_ind in -1 .. 8 {\n for err in [PauliX, PauliZ, PauliY] {\n for _ in 1 .. 10 {\n mutable correct = true;\n mutable msg = \"\";\n use qs = Qubit[9];\n let theta = DrawRandomDouble(0.0, 1.0);\n within {\n // Prepare logical state on first qubit\n Ry(2.0 * theta * PI(), qs[0]);\n // Encode the state in multiple qubits\n ShorEncode(qs);\n // Introduce the error\n if err_ind > -1 {\n if err == PauliX {\n X(qs[err_ind]);\n } elif err == PauliZ {\n Z(qs[err_ind]);\n } else {\n Y(qs[err_ind]);\n }\n }\n } apply {\n // Call solution to detect error\n let (detected_ind, detected_err) = Kata.ShorDetectError(qs);\n // Check that it is correct\n if err_ind == -1 {\n // No error\n if detected_ind != -1 {\n set correct = false;\n set msg = $\"There was no error, but the solution detected error at qubit {detected_ind}\";\n }\n } else {\n // There was an error\n if detected_err != err {\n set correct = false;\n set msg = $\"There was a {err} error, but the solution detected {detected_err} error\";\n } else {\n if err == PauliX or err == PauliY {\n if detected_ind != err_ind {\n set correct = false;\n set msg = $\"There was a {err} error at qubit {err_ind}, but the solution detected it at qubit {detected_ind}\";\n }\n } else {\n // For PauliZ errors, cannot say for certain in which qubit of the triplet it happened, so identify triplet\n if detected_ind != err_ind / 3 {\n set correct = false;\n set msg = $\"There was a {err} error at qubit {err_ind}, but the solution detected it at qubit triplet {detected_ind}\";\n }\n }\n }\n }\n }\n // Check that the state was not modified by the solution\n if not CheckAllZero(qs) {\n set correct = false;\n set msg = \"The state of the qubits changed after the solution was applied\";\n }\n\n if not correct {\n Message(\"Incorrect.\");\n Message(msg);\n ResetAll(qs);\n return false;\n }\n }\n }\n }\n\n Message(\"Correct!\");\n true\n }\n}\n"
8621
+ },
8622
+ {
8623
+ "id": "nonlocal_games__chsh_classical_win_condition__Verification.qs",
8624
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Convert;\n\n function WinCondition_Reference(x : Bool, y : Bool, a : Bool, b : Bool) : Bool {\n return (x and y) == (a != b);\n }\n\n @EntryPoint()\n function CheckSolution() : Bool {\n for i in 0..1 <<< 4 - 1 {\n let bits = IntAsBoolArray(i, 4);\n let expected = WinCondition_Reference(bits[0], bits[1], bits[2], bits[3]);\n let actual = Kata.WinCondition(bits[0], bits[1], bits[2], bits[3]);\n\n if actual != expected {\n Message($\"Win condition '{actual}' isn't as expected for X = {bits[0]}, Y = {bits[1]}, \" + \n\t\t $\"A = {bits[2]}, B = {bits[3]}\");\n return false;\n }\n }\n Message(\"Correct!\");\n true\n }\n}\n"
8625
+ },
8626
+ {
8627
+ "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"
8035
8629
  }
8036
8630
  ]
8037
8631
  };