qsharp-lang 1.17.1-dev → 1.17.2-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 (350) hide show
  1. package/dist/browser.d.ts +10 -8
  2. package/dist/browser.js +5 -3
  3. package/dist/compiler/compiler.d.ts +1 -1
  4. package/dist/compiler/compiler.js +8 -7
  5. package/dist/{shared → data-structures}/circuit.d.ts +24 -0
  6. package/dist/data-structures/circuit.js +130 -0
  7. package/dist/data-structures/legacyCircuitUpdate.d.ts +16 -0
  8. package/dist/{shared → data-structures}/legacyCircuitUpdate.js +117 -61
  9. package/dist/{shared → data-structures}/register.d.ts +4 -0
  10. package/dist/data-structures/register.js +20 -0
  11. package/dist/debug-service/debug-service.d.ts +1 -1
  12. package/dist/debug-service/debug-service.js +1 -1
  13. package/dist/diagnostics.d.ts +21 -0
  14. package/dist/diagnostics.js +84 -0
  15. package/dist/katas-content.generated.js +7 -7
  16. package/dist/katas-content.generated.md.js +7 -7
  17. package/dist/main.d.ts +2 -2
  18. package/dist/main.js +2 -1
  19. package/dist/project.d.ts +10 -0
  20. package/dist/project.js +17 -0
  21. package/dist/samples.generated.js +1 -6
  22. package/dist/utils.d.ts +2 -10
  23. package/dist/utils.js +0 -39
  24. package/dist/workers/common.js +62 -17
  25. package/docs/Microsoft.Quantum.Core/Length.md +1 -1
  26. package/docs/Microsoft.Quantum.Core/Repeated.md +1 -1
  27. package/docs/Microsoft.Quantum.Core/index.md +1 -3
  28. package/docs/Std.Arithmetic/AddLE.md +1 -1
  29. package/docs/Std.Arithmetic/ApplyIfEqualL.md +1 -1
  30. package/docs/Std.Arithmetic/ApplyIfEqualLE.md +1 -1
  31. package/docs/Std.Arithmetic/ApplyIfGreaterL.md +1 -1
  32. package/docs/Std.Arithmetic/ApplyIfGreaterLE.md +1 -1
  33. package/docs/Std.Arithmetic/ApplyIfGreaterOrEqualL.md +1 -1
  34. package/docs/Std.Arithmetic/ApplyIfGreaterOrEqualLE.md +1 -1
  35. package/docs/Std.Arithmetic/ApplyIfLessL.md +1 -1
  36. package/docs/Std.Arithmetic/ApplyIfLessLE.md +1 -1
  37. package/docs/Std.Arithmetic/ApplyIfLessOrEqualL.md +1 -1
  38. package/docs/Std.Arithmetic/ApplyIfLessOrEqualLE.md +1 -1
  39. package/docs/Std.Arithmetic/FourierTDIncByLE.md +1 -1
  40. package/docs/Std.Arithmetic/IncByI.md +1 -1
  41. package/docs/Std.Arithmetic/IncByIUsingIncByLE.md +1 -1
  42. package/docs/Std.Arithmetic/IncByL.md +1 -1
  43. package/docs/Std.Arithmetic/IncByLE.md +1 -1
  44. package/docs/Std.Arithmetic/IncByLEUsingAddLE.md +1 -1
  45. package/docs/Std.Arithmetic/IncByLUsingIncByLE.md +1 -1
  46. package/docs/Std.Arithmetic/LookAheadDKRSAddLE.md +1 -1
  47. package/docs/Std.Arithmetic/MAJ.md +1 -1
  48. package/docs/Std.Arithmetic/ReflectAboutInteger.md +1 -1
  49. package/docs/Std.Arithmetic/RippleCarryCGAddLE.md +1 -1
  50. package/docs/Std.Arithmetic/RippleCarryCGIncByLE.md +1 -1
  51. package/docs/Std.Arithmetic/RippleCarryTTKIncByLE.md +1 -1
  52. package/docs/Std.Arithmetic/index.md +1 -3
  53. package/docs/Std.Arrays/All.md +1 -1
  54. package/docs/Std.Arrays/Any.md +1 -1
  55. package/docs/Std.Arrays/Chunks.md +1 -1
  56. package/docs/Std.Arrays/CircularlyShifted.md +1 -1
  57. package/docs/Std.Arrays/ColumnAt.md +1 -1
  58. package/docs/Std.Arrays/Count.md +1 -1
  59. package/docs/Std.Arrays/Diagonal.md +1 -1
  60. package/docs/Std.Arrays/DrawMany.md +1 -1
  61. package/docs/Std.Arrays/Enumerated.md +1 -1
  62. package/docs/Std.Arrays/Excluding.md +1 -1
  63. package/docs/Std.Arrays/Filtered.md +1 -1
  64. package/docs/Std.Arrays/FlatMapped.md +1 -1
  65. package/docs/Std.Arrays/Flattened.md +1 -1
  66. package/docs/Std.Arrays/Fold.md +1 -1
  67. package/docs/Std.Arrays/ForEach.md +1 -1
  68. package/docs/Std.Arrays/Head.md +1 -1
  69. package/docs/Std.Arrays/HeadAndRest.md +1 -1
  70. package/docs/Std.Arrays/IndexOf.md +1 -1
  71. package/docs/Std.Arrays/IndexRange.md +1 -1
  72. package/docs/Std.Arrays/Interleaved.md +1 -1
  73. package/docs/Std.Arrays/IsEmpty.md +1 -1
  74. package/docs/Std.Arrays/IsRectangularArray.md +1 -1
  75. package/docs/Std.Arrays/IsSorted.md +1 -1
  76. package/docs/Std.Arrays/IsSquareArray.md +1 -1
  77. package/docs/Std.Arrays/Mapped.md +1 -1
  78. package/docs/Std.Arrays/MappedByIndex.md +1 -1
  79. package/docs/Std.Arrays/MappedOverRange.md +1 -1
  80. package/docs/Std.Arrays/Most.md +1 -1
  81. package/docs/Std.Arrays/MostAndTail.md +1 -1
  82. package/docs/Std.Arrays/Padded.md +1 -1
  83. package/docs/Std.Arrays/Partitioned.md +1 -1
  84. package/docs/Std.Arrays/Rest.md +1 -1
  85. package/docs/Std.Arrays/Reversed.md +1 -1
  86. package/docs/Std.Arrays/SequenceI.md +1 -1
  87. package/docs/Std.Arrays/SequenceL.md +1 -1
  88. package/docs/Std.Arrays/Sorted.md +1 -1
  89. package/docs/Std.Arrays/Subarray.md +1 -1
  90. package/docs/Std.Arrays/Swapped.md +1 -1
  91. package/docs/Std.Arrays/Tail.md +1 -1
  92. package/docs/Std.Arrays/Transposed.md +1 -1
  93. package/docs/Std.Arrays/Unzipped.md +1 -1
  94. package/docs/Std.Arrays/Where.md +1 -1
  95. package/docs/Std.Arrays/Windows.md +1 -1
  96. package/docs/Std.Arrays/Zipped.md +1 -1
  97. package/docs/Std.Arrays/index.md +1 -3
  98. package/docs/Std.Canon/ApplyCNOTChain.md +1 -1
  99. package/docs/Std.Canon/ApplyControlledOnBitString.md +1 -1
  100. package/docs/Std.Canon/ApplyControlledOnInt.md +1 -1
  101. package/docs/Std.Canon/ApplyOperationPowerA.md +1 -1
  102. package/docs/Std.Canon/ApplyOperationPowerCA.md +24 -0
  103. package/docs/Std.Canon/ApplyP.md +1 -1
  104. package/docs/Std.Canon/ApplyPauli.md +1 -1
  105. package/docs/Std.Canon/ApplyPauliFromBitString.md +1 -1
  106. package/docs/Std.Canon/ApplyPauliFromInt.md +1 -1
  107. package/docs/Std.Canon/ApplyQFT.md +1 -1
  108. package/docs/Std.Canon/ApplyQPE.md +51 -0
  109. package/docs/Std.Canon/ApplyToEach.md +1 -1
  110. package/docs/Std.Canon/ApplyToEachA.md +1 -1
  111. package/docs/Std.Canon/ApplyToEachC.md +1 -1
  112. package/docs/Std.Canon/ApplyToEachCA.md +1 -1
  113. package/docs/Std.Canon/ApplyXorInPlace.md +1 -1
  114. package/docs/Std.Canon/ApplyXorInPlaceL.md +1 -1
  115. package/docs/Std.Canon/CX.md +1 -1
  116. package/docs/Std.Canon/CY.md +1 -1
  117. package/docs/Std.Canon/CZ.md +1 -1
  118. package/docs/Std.Canon/Fst.md +1 -1
  119. package/docs/Std.Canon/Relabel.md +1 -1
  120. package/docs/Std.Canon/Snd.md +1 -1
  121. package/docs/Std.Canon/SwapReverseRegister.md +1 -1
  122. package/docs/Std.Canon/index.md +3 -3
  123. package/docs/Std.Convert/BigIntAsBoolArray.md +1 -1
  124. package/docs/Std.Convert/BigIntAsInt.md +1 -1
  125. package/docs/Std.Convert/BoolArrayAsBigInt.md +1 -1
  126. package/docs/Std.Convert/BoolArrayAsInt.md +1 -1
  127. package/docs/Std.Convert/BoolArrayAsResultArray.md +1 -1
  128. package/docs/Std.Convert/BoolAsResult.md +1 -1
  129. package/docs/Std.Convert/ComplexAsComplexPolar.md +1 -1
  130. package/docs/Std.Convert/ComplexPolarAsComplex.md +1 -1
  131. package/docs/Std.Convert/DoubleAsStringWithPrecision.md +1 -1
  132. package/docs/Std.Convert/IntAsBigInt.md +1 -1
  133. package/docs/Std.Convert/IntAsBoolArray.md +1 -1
  134. package/docs/Std.Convert/IntAsDouble.md +1 -1
  135. package/docs/Std.Convert/ResultArrayAsBoolArray.md +1 -1
  136. package/docs/Std.Convert/ResultArrayAsInt.md +1 -1
  137. package/docs/Std.Convert/ResultAsBool.md +1 -1
  138. package/docs/Std.Convert/index.md +1 -3
  139. package/docs/Std.Core/Length.md +1 -1
  140. package/docs/Std.Core/Repeated.md +1 -1
  141. package/docs/Std.Core/index.md +1 -3
  142. package/docs/Std.Diagnostics/ApplyIdleNoise.md +1 -1
  143. package/docs/Std.Diagnostics/BitFlipNoise.md +1 -1
  144. package/docs/Std.Diagnostics/CheckAllZero.md +1 -1
  145. package/docs/Std.Diagnostics/CheckOperationsAreEqual.md +1 -1
  146. package/docs/Std.Diagnostics/CheckZero.md +1 -1
  147. package/docs/Std.Diagnostics/ConfigurePauliNoise.md +1 -1
  148. package/docs/Std.Diagnostics/DepolarizingNoise.md +1 -1
  149. package/docs/Std.Diagnostics/DumpMachine.md +1 -1
  150. package/docs/Std.Diagnostics/DumpOperation.md +1 -1
  151. package/docs/Std.Diagnostics/DumpRegister.md +1 -1
  152. package/docs/Std.Diagnostics/Fact.md +1 -1
  153. package/docs/Std.Diagnostics/NoNoise.md +1 -1
  154. package/docs/Std.Diagnostics/PhaseFlipNoise.md +1 -1
  155. package/docs/Std.Diagnostics/StartCountingFunction.md +1 -1
  156. package/docs/Std.Diagnostics/StartCountingOperation.md +1 -1
  157. package/docs/Std.Diagnostics/StartCountingQubits.md +1 -1
  158. package/docs/Std.Diagnostics/StopCountingFunction.md +1 -1
  159. package/docs/Std.Diagnostics/StopCountingOperation.md +1 -1
  160. package/docs/Std.Diagnostics/StopCountingQubits.md +1 -1
  161. package/docs/Std.Diagnostics/index.md +1 -3
  162. package/docs/Std.Intrinsic/AND.md +1 -1
  163. package/docs/Std.Intrinsic/ApplyUnitary.md +1 -1
  164. package/docs/Std.Intrinsic/CCNOT.md +1 -1
  165. package/docs/Std.Intrinsic/CNOT.md +1 -1
  166. package/docs/Std.Intrinsic/Exp.md +1 -1
  167. package/docs/Std.Intrinsic/H.md +1 -1
  168. package/docs/Std.Intrinsic/I.md +1 -1
  169. package/docs/Std.Intrinsic/M.md +1 -1
  170. package/docs/Std.Intrinsic/Measure.md +1 -1
  171. package/docs/Std.Intrinsic/Message.md +1 -1
  172. package/docs/Std.Intrinsic/R.md +1 -1
  173. package/docs/Std.Intrinsic/R1.md +1 -1
  174. package/docs/Std.Intrinsic/R1Frac.md +1 -1
  175. package/docs/Std.Intrinsic/RFrac.md +1 -1
  176. package/docs/Std.Intrinsic/Reset.md +1 -1
  177. package/docs/Std.Intrinsic/ResetAll.md +1 -1
  178. package/docs/Std.Intrinsic/Rx.md +1 -1
  179. package/docs/Std.Intrinsic/Rxx.md +1 -1
  180. package/docs/Std.Intrinsic/Ry.md +1 -1
  181. package/docs/Std.Intrinsic/Ryy.md +1 -1
  182. package/docs/Std.Intrinsic/Rz.md +1 -1
  183. package/docs/Std.Intrinsic/Rzz.md +1 -1
  184. package/docs/Std.Intrinsic/S.md +1 -1
  185. package/docs/Std.Intrinsic/SWAP.md +1 -1
  186. package/docs/Std.Intrinsic/SX.md +1 -1
  187. package/docs/Std.Intrinsic/T.md +1 -1
  188. package/docs/Std.Intrinsic/X.md +1 -1
  189. package/docs/Std.Intrinsic/Y.md +1 -1
  190. package/docs/Std.Intrinsic/Z.md +1 -1
  191. package/docs/Std.Intrinsic/index.md +1 -3
  192. package/docs/Std.Logical/Xor.md +1 -1
  193. package/docs/Std.Logical/index.md +1 -3
  194. package/docs/Std.Math/AbsComplex.md +1 -1
  195. package/docs/Std.Math/AbsComplexPolar.md +1 -1
  196. package/docs/Std.Math/AbsD.md +1 -1
  197. package/docs/Std.Math/AbsI.md +1 -1
  198. package/docs/Std.Math/AbsL.md +1 -1
  199. package/docs/Std.Math/AbsSquaredComplex.md +1 -1
  200. package/docs/Std.Math/AbsSquaredComplexPolar.md +1 -1
  201. package/docs/Std.Math/ApproximateFactorial.md +1 -1
  202. package/docs/Std.Math/ArcCos.md +1 -1
  203. package/docs/Std.Math/ArcCosh.md +1 -1
  204. package/docs/Std.Math/ArcSin.md +1 -1
  205. package/docs/Std.Math/ArcSinh.md +1 -1
  206. package/docs/Std.Math/ArcTan.md +1 -1
  207. package/docs/Std.Math/ArcTan2.md +1 -1
  208. package/docs/Std.Math/ArcTanh.md +1 -1
  209. package/docs/Std.Math/ArgComplex.md +1 -1
  210. package/docs/Std.Math/ArgComplexPolar.md +1 -1
  211. package/docs/Std.Math/Binom.md +1 -1
  212. package/docs/Std.Math/BitSizeI.md +1 -1
  213. package/docs/Std.Math/BitSizeL.md +1 -1
  214. package/docs/Std.Math/Ceiling.md +1 -1
  215. package/docs/Std.Math/Complex.md +1 -1
  216. package/docs/Std.Math/ComplexPolar.md +1 -1
  217. package/docs/Std.Math/ContinuedFractionConvergentI.md +1 -1
  218. package/docs/Std.Math/ContinuedFractionConvergentL.md +1 -1
  219. package/docs/Std.Math/Cos.md +1 -1
  220. package/docs/Std.Math/Cosh.md +1 -1
  221. package/docs/Std.Math/DivRemI.md +1 -1
  222. package/docs/Std.Math/DivRemL.md +1 -1
  223. package/docs/Std.Math/DividedByC.md +1 -1
  224. package/docs/Std.Math/DividedByCP.md +1 -1
  225. package/docs/Std.Math/E.md +1 -1
  226. package/docs/Std.Math/ExpModI.md +1 -1
  227. package/docs/Std.Math/ExpModL.md +1 -1
  228. package/docs/Std.Math/ExtendedGreatestCommonDivisorI.md +1 -1
  229. package/docs/Std.Math/ExtendedGreatestCommonDivisorL.md +1 -1
  230. package/docs/Std.Math/FactorialI.md +1 -1
  231. package/docs/Std.Math/FactorialL.md +1 -1
  232. package/docs/Std.Math/Floor.md +1 -1
  233. package/docs/Std.Math/GreatestCommonDivisorI.md +1 -1
  234. package/docs/Std.Math/GreatestCommonDivisorL.md +1 -1
  235. package/docs/Std.Math/HammingWeightI.md +1 -1
  236. package/docs/Std.Math/InverseModI.md +1 -1
  237. package/docs/Std.Math/InverseModL.md +1 -1
  238. package/docs/Std.Math/IsCoprimeI.md +1 -1
  239. package/docs/Std.Math/IsCoprimeL.md +1 -1
  240. package/docs/Std.Math/IsInfinite.md +1 -1
  241. package/docs/Std.Math/IsNaN.md +1 -1
  242. package/docs/Std.Math/LargestFixedPoint.md +1 -1
  243. package/docs/Std.Math/Lg.md +1 -1
  244. package/docs/Std.Math/Log.md +1 -1
  245. package/docs/Std.Math/Log10.md +1 -1
  246. package/docs/Std.Math/LogFactorialD.md +1 -1
  247. package/docs/Std.Math/LogGammaD.md +1 -1
  248. package/docs/Std.Math/LogOf2.md +1 -1
  249. package/docs/Std.Math/Max.md +1 -1
  250. package/docs/Std.Math/MaxD.md +1 -1
  251. package/docs/Std.Math/MaxI.md +1 -1
  252. package/docs/Std.Math/MaxL.md +1 -1
  253. package/docs/Std.Math/Min.md +1 -1
  254. package/docs/Std.Math/MinD.md +1 -1
  255. package/docs/Std.Math/MinI.md +1 -1
  256. package/docs/Std.Math/MinL.md +1 -1
  257. package/docs/Std.Math/MinusC.md +1 -1
  258. package/docs/Std.Math/MinusCP.md +1 -1
  259. package/docs/Std.Math/ModulusI.md +1 -1
  260. package/docs/Std.Math/ModulusL.md +1 -1
  261. package/docs/Std.Math/NegationC.md +1 -1
  262. package/docs/Std.Math/NegationCP.md +1 -1
  263. package/docs/Std.Math/PI.md +1 -1
  264. package/docs/Std.Math/PNorm.md +1 -1
  265. package/docs/Std.Math/PNormalized.md +1 -1
  266. package/docs/Std.Math/PlusC.md +1 -1
  267. package/docs/Std.Math/PlusCP.md +1 -1
  268. package/docs/Std.Math/PowC.md +1 -1
  269. package/docs/Std.Math/PowCP.md +1 -1
  270. package/docs/Std.Math/RealMod.md +1 -1
  271. package/docs/Std.Math/Round.md +1 -1
  272. package/docs/Std.Math/RoundHalfAwayFromZero.md +1 -1
  273. package/docs/Std.Math/SignD.md +1 -1
  274. package/docs/Std.Math/SignI.md +1 -1
  275. package/docs/Std.Math/SignL.md +1 -1
  276. package/docs/Std.Math/Sin.md +1 -1
  277. package/docs/Std.Math/Sinh.md +1 -1
  278. package/docs/Std.Math/SmallestFixedPoint.md +1 -1
  279. package/docs/Std.Math/Sqrt.md +1 -1
  280. package/docs/Std.Math/SquaredNorm.md +1 -1
  281. package/docs/Std.Math/Tan.md +1 -1
  282. package/docs/Std.Math/Tanh.md +1 -1
  283. package/docs/Std.Math/TimesC.md +1 -1
  284. package/docs/Std.Math/TimesCP.md +1 -1
  285. package/docs/Std.Math/TrailingZeroCountI.md +1 -1
  286. package/docs/Std.Math/TrailingZeroCountL.md +1 -1
  287. package/docs/Std.Math/Truncate.md +1 -1
  288. package/docs/Std.Math/index.md +1 -3
  289. package/docs/Std.Measurement/MResetEachZ.md +1 -1
  290. package/docs/Std.Measurement/MResetX.md +1 -1
  291. package/docs/Std.Measurement/MResetY.md +1 -1
  292. package/docs/Std.Measurement/MResetZ.md +1 -1
  293. package/docs/Std.Measurement/MeasureAllZ.md +1 -1
  294. package/docs/Std.Measurement/MeasureEachZ.md +1 -1
  295. package/docs/Std.Measurement/MeasureInteger.md +1 -1
  296. package/docs/Std.Measurement/index.md +1 -3
  297. package/docs/Std.Random/DrawRandomBool.md +1 -1
  298. package/docs/Std.Random/DrawRandomDouble.md +1 -1
  299. package/docs/Std.Random/DrawRandomInt.md +1 -1
  300. package/docs/Std.Random/index.md +1 -3
  301. package/docs/Std.Range/IsRangeEmpty.md +1 -1
  302. package/docs/Std.Range/RangeEnd.md +1 -1
  303. package/docs/Std.Range/RangeReverse.md +1 -1
  304. package/docs/Std.Range/RangeStart.md +1 -1
  305. package/docs/Std.Range/RangeStep.md +1 -1
  306. package/docs/Std.Range/index.md +1 -3
  307. package/docs/Std.ResourceEstimation/AccountForEstimates.md +1 -1
  308. package/docs/Std.ResourceEstimation/AuxQubitCount.md +1 -1
  309. package/docs/Std.ResourceEstimation/BeginEstimateCaching.md +1 -1
  310. package/docs/Std.ResourceEstimation/BeginRepeatEstimates.md +1 -1
  311. package/docs/Std.ResourceEstimation/CczCount.md +1 -1
  312. package/docs/Std.ResourceEstimation/EndEstimateCaching.md +1 -1
  313. package/docs/Std.ResourceEstimation/EndRepeatEstimates.md +1 -1
  314. package/docs/Std.ResourceEstimation/MeasurementCount.md +1 -1
  315. package/docs/Std.ResourceEstimation/PSSPCLayout.md +1 -1
  316. package/docs/Std.ResourceEstimation/RepeatEstimates.md +1 -1
  317. package/docs/Std.ResourceEstimation/RotationCount.md +1 -1
  318. package/docs/Std.ResourceEstimation/RotationDepth.md +1 -1
  319. package/docs/Std.ResourceEstimation/SingleVariant.md +1 -1
  320. package/docs/Std.ResourceEstimation/TCount.md +1 -1
  321. package/docs/Std.ResourceEstimation/index.md +1 -3
  322. package/docs/Std.StatePreparation/ApproximatelyPreparePureStateCP.md +1 -1
  323. package/docs/Std.StatePreparation/PreparePureStateD.md +1 -1
  324. package/docs/Std.StatePreparation/PrepareUniformSuperposition.md +1 -1
  325. package/docs/Std.StatePreparation/index.md +1 -3
  326. package/docs/Std.TableLookup/Select.md +1 -1
  327. package/docs/Std.TableLookup/index.md +1 -3
  328. package/docs/index.md +19 -21
  329. package/docs/toc.yml +2 -0
  330. package/lib/node/qsc_wasm.cjs +9 -6
  331. package/lib/node/qsc_wasm.d.cts +2 -1
  332. package/lib/node/qsc_wasm_bg.wasm +0 -0
  333. package/lib/web/qsc_wasm.d.ts +3 -2
  334. package/lib/web/qsc_wasm.js +9 -6
  335. package/lib/web/qsc_wasm_bg.wasm +0 -0
  336. package/package.json +4 -3
  337. package/ux/circuit-vis/circuit.ts +3 -3
  338. package/ux/circuit-vis/draggable.ts +1 -1
  339. package/ux/circuit-vis/events.ts +2 -1
  340. package/ux/circuit-vis/index.ts +3 -1
  341. package/ux/circuit-vis/panel.ts +64 -1
  342. package/ux/circuit-vis/register.ts +1 -1
  343. package/ux/circuit-vis/sqore.ts +7 -1
  344. package/ux/circuit-vis/utils.ts +47 -0
  345. package/ux/circuit.tsx +66 -25
  346. package/ux/data.ts +1 -0
  347. package/ux/qsharp-circuit.css +31 -0
  348. package/dist/shared/circuit.js +0 -20
  349. package/dist/shared/legacyCircuitUpdate.d.ts +0 -9
  350. package/dist/shared/register.js +0 -10
@@ -0,0 +1,84 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { log } from "./log.js";
4
+ /**
5
+ * Public error type for most `qsharp-lang` functions.
6
+ *
7
+ * This is typically thrown by functions that deal with compiling and
8
+ * running code. Contains one or more VS Code-like diagnostics.
9
+ */
10
+ export class QdkDiagnostics extends Error {
11
+ constructor(diagnostics) {
12
+ const message = shortMessage(diagnostics);
13
+ super(message);
14
+ this.diagnostics = diagnostics;
15
+ this.name = "QdkDiagnostics";
16
+ }
17
+ }
18
+ /**
19
+ * Wrapper around QDK WASM functions to convert exceptions to a more ergonomic type.
20
+ *
21
+ * Many of the WASM functions throw exceptions that are of type `string`,
22
+ * which are really just JSON-serialized `IQSharpError[]`s.
23
+ *
24
+ * This function converts those exceptions into `QdkDiagnostics` instances
25
+ * that properly inherit from `Error`.
26
+ */
27
+ export async function callAndTransformExceptions(fn) {
28
+ try {
29
+ return await fn();
30
+ }
31
+ catch (e) {
32
+ const QdkDiagnostics = tryParseQdkDiagnostics(e);
33
+ if (QdkDiagnostics) {
34
+ throw QdkDiagnostics;
35
+ }
36
+ throw e;
37
+ }
38
+ }
39
+ /**
40
+ * If the error is a string containing JSON-serialized `IQSharpError[]`,
41
+ * creates a `QdkDiagnostics` instance from it.
42
+ */
43
+ function tryParseQdkDiagnostics(e) {
44
+ if (typeof e === "string") {
45
+ try {
46
+ const errors = JSON.parse(e);
47
+ // Check for the shape of IQSharpError[]
48
+ if (Array.isArray(errors) &&
49
+ errors.length > 0 &&
50
+ errors[0].document &&
51
+ errors[0].diagnostic) {
52
+ return new QdkDiagnostics(errors);
53
+ }
54
+ }
55
+ catch {
56
+ // Couldn't parse the error as JSON.
57
+ log.warn(`could not parse error string ${e}`);
58
+ }
59
+ }
60
+ return undefined;
61
+ }
62
+ /**
63
+ * Constructs a human-readable message from the first error.
64
+ */
65
+ function shortMessage(errors) {
66
+ const error = errors[0];
67
+ return `${error.diagnostic.message} at ${friendlyLocation(error.document, error.diagnostic.range)}`;
68
+ }
69
+ /**
70
+ * Constructs a human-readable location string for an error.
71
+ */
72
+ function friendlyLocation(uriOrName, range) {
73
+ // Don't make any assumptions about the format of uriOrName,
74
+ // it could be a file path, a URI with an arbitrary scheme, or just a name.
75
+ // If it contains slashes, we assume it's a path and extract the basename.
76
+ // Best effort, for display only.
77
+ const lastSlash = Math.max(uriOrName.lastIndexOf("/"), uriOrName.lastIndexOf("\\"));
78
+ const basename = lastSlash >= 0 ? uriOrName.substring(lastSlash + 1) : uriOrName;
79
+ // avoid printing :1:1 since that's the default if the original error didn't specify a range
80
+ const lineColumn = range.start.line > 0 || range.start.character > 0
81
+ ? `:${range.start.line + 1}:${range.start.character + 1}`
82
+ : "";
83
+ return `${basename}${lineColumn}`;
84
+ }
@@ -1094,7 +1094,7 @@ export default {
1094
1094
  "items": [
1095
1095
  {
1096
1096
  "type": "text-content",
1097
- "content": "<p>There is another way to represent quantum gates, this time using Dirac notation. However, kets aren't enough to represent arbitrary matrices. An additional notation is required: the <strong>bra</strong> (this is why Dirac notation is sometimes called <strong>bra-ket notation</strong>).</p>\n<p>Recall that kets represent column vectors; a bra is a ket's row vector counterpart. For any ket $\\ket{\\psi}$, the corresponding bra is its adjoint (conjugate transpose): $\\bra{\\psi} = \\ket{\\psi}^\\dagger$.</p>\n<p>Some examples:</p>\n<table>\n <tr>\n <th>Ket</th>\n <th>Bra</th>\n </tr>\n <tr>\n <td>$\\ket{0} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}$</td>\n <td>$\\bra{0} = \\begin{bmatrix} 1 & 0 \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{1} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$</td>\n <td>$\\bra{1} = \\begin{bmatrix} 0 & 1 \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{i} = \\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ \\frac{i}{\\sqrt{2}} \\end{bmatrix}$</td>\n <td>$\\bra{ i} = \\begin{bmatrix} \\frac{1}{\\sqrt{2}} & -\\frac{i}{\\sqrt{2}} \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{\\psi} = \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix}$</td>\n <td>$\\bra{\\psi} = \\begin{bmatrix} \\overline{\\alpha} & \\overline{\\beta} \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</td>\n <td>$\\bra{\\psi} = \\overline{\\alpha}\\bra{0} + \\overline{\\beta}\\bra{1}$</td>\n </tr>\n</table>\n<p>Kets and bras give us a neat way to express inner and outer products. The inner product of $\\ket{\\phi}$ and $\\ket{\\psi}$ is the matrix product of $\\bra{\\phi}$ and $\\ket{\\psi}$, denoted as $\\braket{\\phi|\\psi}$, and their outer product is the matrix product of $\\ket{\\phi}$ and $\\bra{\\psi}$, denoted as $\\ket{\\phi}\\bra{\\psi}$. Notice that the norm of $\\ket{\\psi}$ is $\\sqrt{\\braket{\\psi|\\psi}}$.</p>\n<p>This leads to the representation of matrices via outer products. Recall that the outer product of two vectors of the same size produces a square matrix. You can use a linear combination of several outer products of simple vectors (such as basis vectors) to express any square matrix. For example, the $X$ gate can be expressed as follows:</p>\n<p>$$X = \\ket{0}\\bra{1} + \\ket{1}\\bra{0}$$</p>\n<p>$$\n\\ket{0}\\bra{1} + \\ket{1}\\bra{0} =\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 &amp; 1 \\end{bmatrix} +\n\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\\begin{bmatrix} 1 &amp; 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 &amp; 1 \\\\ 0 &amp; 0 \\end{bmatrix} + \\begin{bmatrix} 0 &amp; 0 \\\\ 1 &amp; 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 &amp; 1 \\\\ 1 &amp; 0 \\end{bmatrix}\n$$</p>\n<p>This representation can be used to carry out calculations in Dirac notation without ever switching back to matrix representation:</p>\n<p>$$X\\ket{0} = \\big(\\ket{0}\\bra{1} + \\ket{1}\\bra{0}\\big)\\ket{0} = \\ket{0}\\braket{1|0} + \\ket{1}\\braket{0|0} = \\ket{0}\\big(\\braket{1|0}\\big) + \\ket{1}\\big(\\braket{0|0}\\big) = \\ket{0}(0) + \\ket{1}(1) = \\ket{1}$$</p>\n<blockquote>\n<p>That last step may seem a bit confusing. Recall that $\\ket{0}$ and $\\ket{1}$ form an <strong>orthonormal basis</strong>. That is, they're both normalized, and they're orthogonal to each other.</p>\n<p>A vector is normalized if its norm is equal to $1$, which only happens if its inner product with itself is equal to $1$. This means that $\\braket{0|0} = \\braket{1|1} = 1$</p>\n<p>Two vectors are orthogonal to each other if their inner product equals $0$. This means that $\\braket{0|1} = \\braket{1|0} = 0$.</p>\n</blockquote>\n<p>In general case, a matrix\n$$A = \\begin{bmatrix} a_{00} &amp; a_{01} \\\\ a_{10} &amp; a_{11} \\end{bmatrix}$$\nwill have the following ket-bra representation:\n$$A = a_{00} \\ket{0}\\bra{0} + a_{01} \\ket{0}\\bra{1} + a_{10} \\ket{1}\\bra{0} + a_{11} \\ket{1}\\bra{1}$$</p>\n"
1097
+ "content": "<p>There is another way to represent quantum gates, this time using Dirac notation. However, kets aren't enough to represent arbitrary matrices. An additional notation is required: the <strong>bra</strong> (this is why Dirac notation is sometimes called <strong>bra-ket notation</strong>).</p>\n<p>Recall that kets represent column vectors; a bra is a ket's row vector counterpart. For any ket $\\ket{\\psi}$, the corresponding bra is its adjoint (conjugate transpose): $\\bra{\\psi} = \\ket{\\psi}^\\dagger$.</p>\n<p>Some examples:</p>\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <th>Ket</th>\n <th>Bra</th>\n </tr>\n <tr>\n <td>$\\ket{0} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}$</td>\n <td>$\\bra{0} = \\begin{bmatrix} 1 & 0 \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{1} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$</td>\n <td>$\\bra{1} = \\begin{bmatrix} 0 & 1 \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{i} = \\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ \\frac{i}{\\sqrt{2}} \\end{bmatrix}$</td>\n <td>$\\bra{ i} = \\begin{bmatrix} \\frac{1}{\\sqrt{2}} & -\\frac{i}{\\sqrt{2}} \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{\\psi} = \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix}$</td>\n <td>$\\bra{\\psi} = \\begin{bmatrix} \\overline{\\alpha} & \\overline{\\beta} \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</td>\n <td>$\\bra{\\psi} = \\overline{\\alpha}\\bra{0} + \\overline{\\beta}\\bra{1}$</td>\n </tr>\n </table>\n</div>\n<p>Kets and bras give us a neat way to express inner and outer products. The inner product of $\\ket{\\phi}$ and $\\ket{\\psi}$ is the matrix product of $\\bra{\\phi}$ and $\\ket{\\psi}$, denoted as $\\braket{\\phi|\\psi}$, and their outer product is the matrix product of $\\ket{\\phi}$ and $\\bra{\\psi}$, denoted as $\\ket{\\phi}\\bra{\\psi}$. Notice that the norm of $\\ket{\\psi}$ is $\\sqrt{\\braket{\\psi|\\psi}}$.</p>\n<p>This leads to the representation of matrices via outer products. Recall that the outer product of two vectors of the same size produces a square matrix. You can use a linear combination of several outer products of simple vectors (such as basis vectors) to express any square matrix. For example, the $X$ gate can be expressed as follows:</p>\n<p>$$X = \\ket{0}\\bra{1} + \\ket{1}\\bra{0}$$</p>\n<p>$$\n\\ket{0}\\bra{1} + \\ket{1}\\bra{0} =\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 &amp; 1 \\end{bmatrix} +\n\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\\begin{bmatrix} 1 &amp; 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 &amp; 1 \\\\ 0 &amp; 0 \\end{bmatrix} + \\begin{bmatrix} 0 &amp; 0 \\\\ 1 &amp; 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 &amp; 1 \\\\ 1 &amp; 0 \\end{bmatrix}\n$$</p>\n<p>This representation can be used to carry out calculations in Dirac notation without ever switching back to matrix representation:</p>\n<p>$$X\\ket{0} = \\big(\\ket{0}\\bra{1} + \\ket{1}\\bra{0}\\big)\\ket{0} = \\ket{0}\\braket{1|0} + \\ket{1}\\braket{0|0} = \\ket{0}\\big(\\braket{1|0}\\big) + \\ket{1}\\big(\\braket{0|0}\\big) = \\ket{0}(0) + \\ket{1}(1) = \\ket{1}$$</p>\n<blockquote>\n<p>That last step may seem a bit confusing. Recall that $\\ket{0}$ and $\\ket{1}$ form an <strong>orthonormal basis</strong>. That is, they're both normalized, and they're orthogonal to each other.</p>\n<p>A vector is normalized if its norm is equal to $1$, which only happens if its inner product with itself is equal to $1$. This means that $\\braket{0|0} = \\braket{1|1} = 1$</p>\n<p>Two vectors are orthogonal to each other if their inner product equals $0$. This means that $\\braket{0|1} = \\braket{1|0} = 0$.</p>\n</blockquote>\n<p>In general case, a matrix\n$$A = \\begin{bmatrix} a_{00} &amp; a_{01} \\\\ a_{10} &amp; a_{11} \\end{bmatrix}$$\nwill have the following ket-bra representation:\n$$A = a_{00} \\ket{0}\\bra{0} + a_{01} \\ket{0}\\bra{1} + a_{10} \\ket{1}\\bra{0} + a_{11} \\ket{1}\\bra{1}$$</p>\n"
1098
1098
  }
1099
1099
  ]
1100
1100
  },
@@ -1116,7 +1116,7 @@ export default {
1116
1116
  "items": [
1117
1117
  {
1118
1118
  "type": "text-content",
1119
- "content": "<p>This section introduces some of the common single-qubit gates, including their matrix form, their ket-bra decomposition, and a brief &quot;cheat sheet&quot; listing their effect on some common qubit states.</p>\n<p>You can use a tool called <a href=\"https://algassert.com/quirk\" target=\"_blank\">Quirk</a> to visualize how these gates interact with various qubit states.</p>\n<p>This section relies on the following notation:</p>\n<table>\n <tr>\n <td>$\\ket{+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + \\ket{1}\\big)$</td>\n <td>$\\ket{-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - \\ket{1}\\big)$</td>\n </tr>\n <tr>\n <td>$\\ket{i} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + i\\ket{1}\\big)$</td>\n <td>$\\ket{-i} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - i\\ket{1}\\big)$</td>\n </tr>\n</table>\n<p>The Pauli gates, named after <a href=\"https://en.wikipedia.org/wiki/Wolfgang_Pauli\" target=\"_blank\">Wolfgang Pauli</a>, are based on the so-called <strong>Pauli matrices</strong>, $X$, $Y$ and $Z$. All three Pauli gates are <strong>self-adjoint</strong>, meaning that each one is its own inverse, $XX = \\mathbb{I}$.</p>\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$X$</td>\n <td>$\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{1} + \\ket{1}\\bra{0}$</td>\n <td>$X\\ket{\\psi} = \\alpha\\ket{1} + \\beta\\ket{0}$</td>\n <td>\n $X\\ket{0} = \\ket{1}$<br>\n $X\\ket{1} = \\ket{0}$<br>\n $X\\ket{+} = \\ket{+}$<br>\n $X\\ket{-} = -\\ket{-}$<br>\n $X\\ket{i} = i\\ket{-i}$<br>\n $X\\ket{-i} = -i\\ket{i}$\n </td>\n </tr>\n <tr>\n <td>$Y$</td>\n <td>$\\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}$</td>\n <td>$i(\\ket{1}\\bra{0} - \\ket{0}\\bra{1})$</td>\n <td>$Y\\ket{\\psi} = i\\big(\\alpha\\ket{1} - \\beta\\ket{0}\\big)$</td>\n <td>\n $Y\\ket{0} = i\\ket{1}$<br>\n $Y\\ket{1} = -i\\ket{0}$<br>\n $Y\\ket{+} = -i\\ket{-}$<br>\n $Y\\ket{-} = i\\ket{+}$<br>\n $Y\\ket{i} = \\ket{i}$<br>\n $Y\\ket{-i} = -\\ket{-i}$<br>\n </td>\n </tr>\n <tr>\n <td>$Z$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} - \\ket{1}\\bra{1}$</td>\n <td>$Z\\ket{\\psi} = \\alpha\\ket{0} - \\beta\\ket{1}$</td>\n <td>\n $Z\\ket{0} = \\ket{0}$<br>\n $Z\\ket{1} = -\\ket{1}$<br>\n $Z\\ket{+} = \\ket{-}$<br>\n $Z\\ket{-} = \\ket{+}$<br>\n $Z\\ket{i} = \\ket{-i}$<br>\n $Z\\ket{-i} = \\ket{i}$<br>\n </td>\n </tr>\n</table>\n<blockquote>\n<p>The $X$ gate is sometimes referred to as the <strong>bit flip</strong> gate, or the <strong>NOT</strong> gate, because it acts like the classical NOT gate on the computational basis.</p>\n<p>The $Z$ gate is sometimes referred to as the <strong>phase flip</strong> gate.</p>\n</blockquote>\n<p>Here are several properties of the Pauli gates that are easy to verify and convenient to remember:</p>\n<ul>\n<li>Different Pauli gates <em>anti-commute</em>:\n$$XZ = -ZX, XY = -YX, YZ = -ZY$$</li>\n<li>A product of any two Pauli gates equals the third gate, with an extra $i$ (or $-i$) phase:\n$$XY = iZ, YZ = iX, ZX = iY$$</li>\n<li>A product of all three Pauli gates equals identity (with an extra $i$ phase):\n$$XYZ = iI$$</li>\n</ul>\n"
1119
+ "content": "<p>This section introduces some of the common single-qubit gates, including their matrix form, their ket-bra decomposition, and a brief &quot;cheat sheet&quot; listing their effect on some common qubit states.</p>\n<p>You can use a tool called <a href=\"https://algassert.com/quirk\" target=\"_blank\">Quirk</a> to visualize how these gates interact with various qubit states.</p>\n<p>This section relies on the following notation:</p>\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <td>$\\ket{+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + \\ket{1}\\big)$</td>\n <td>$\\ket{-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - \\ket{1}\\big)$</td>\n </tr>\n <tr>\n <td>$\\ket{i} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + i\\ket{1}\\big)$</td>\n <td>$\\ket{-i} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - i\\ket{1}\\big)$</td>\n </tr>\n </table>\n</div>\n<p>The Pauli gates, named after <a href=\"https://en.wikipedia.org/wiki/Wolfgang_Pauli\" target=\"_blank\">Wolfgang Pauli</a>, are based on the so-called <strong>Pauli matrices</strong>, $X$, $Y$ and $Z$. All three Pauli gates are <strong>self-adjoint</strong>, meaning that each one is its own inverse, $XX = \\mathbb{I}$.</p>\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$X$</td>\n <td>$\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{1} + \\ket{1}\\bra{0}$</td>\n <td>$X\\ket{\\psi} = \\alpha\\ket{1} + \\beta\\ket{0}$</td>\n <td>\n $X\\ket{0} = \\ket{1}$<br>\n $X\\ket{1} = \\ket{0}$<br>\n $X\\ket{+} = \\ket{+}$<br>\n $X\\ket{-} = -\\ket{-}$<br>\n $X\\ket{i} = i\\ket{-i}$<br>\n $X\\ket{-i} = -i\\ket{i}$\n </td>\n </tr>\n <tr>\n <td>$Y$</td>\n <td>$\\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}$</td>\n <td>$i(\\ket{1}\\bra{0} - \\ket{0}\\bra{1})$</td>\n <td>$Y\\ket{\\psi} = i\\big(\\alpha\\ket{1} - \\beta\\ket{0}\\big)$</td>\n <td>\n $Y\\ket{0} = i\\ket{1}$<br>\n $Y\\ket{1} = -i\\ket{0}$<br>\n $Y\\ket{+} = -i\\ket{-}$<br>\n $Y\\ket{-} = i\\ket{+}$<br>\n $Y\\ket{i} = \\ket{i}$<br>\n $Y\\ket{-i} = -\\ket{-i}$<br>\n </td>\n </tr>\n <tr>\n <td>$Z$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} - \\ket{1}\\bra{1}$</td>\n <td>$Z\\ket{\\psi} = \\alpha\\ket{0} - \\beta\\ket{1}$</td>\n <td>\n $Z\\ket{0} = \\ket{0}$<br>\n $Z\\ket{1} = -\\ket{1}$<br>\n $Z\\ket{+} = \\ket{-}$<br>\n $Z\\ket{-} = \\ket{+}$<br>\n $Z\\ket{i} = \\ket{-i}$<br>\n $Z\\ket{-i} = \\ket{i}$<br>\n </td>\n </tr>\n </table>\n</div>\n<blockquote>\n<p>The $X$ gate is sometimes referred to as the <strong>bit flip</strong> gate, or the <strong>NOT</strong> gate, because it acts like the classical NOT gate on the computational basis.</p>\n<p>The $Z$ gate is sometimes referred to as the <strong>phase flip</strong> gate.</p>\n</blockquote>\n<p>Here are several properties of the Pauli gates that are easy to verify and convenient to remember:</p>\n<ul>\n<li>Different Pauli gates <em>anti-commute</em>:\n$$XZ = -ZX, XY = -YX, YZ = -ZY$$</li>\n<li>A product of any two Pauli gates equals the third gate, with an extra $i$ (or $-i$) phase:\n$$XY = iZ, YZ = iX, ZX = iY$$</li>\n<li>A product of all three Pauli gates equals identity (with an extra $i$ phase):\n$$XYZ = iI$$</li>\n</ul>\n"
1120
1120
  }
1121
1121
  ]
1122
1122
  },
@@ -1311,7 +1311,7 @@ export default {
1311
1311
  "items": [
1312
1312
  {
1313
1313
  "type": "text-content",
1314
- "content": "<p>The identity gate is mostly here for completeness, at least for now. It will come in handy when dealing with multi-qubit systems and multi-qubit gates. It's represented by the identity matrix, and doesn't affect the state of the qubit.</p>\n<table>\n<tr>\n<th>Gate</th>\n<th>Matrix</th>\n<th>Ket-Bra</th>\n<th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n</tr>\n<tr>\n<td>$I$</td>\n<td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}$</td>\n<td>$\\ket{0}\\bra{0} + \\ket{1}\\bra{1}$</td>\n<td>$I\\ket{\\psi} = \\ket{\\psi}$</td>\n</tr>\n</table>"
1314
+ "content": "<p>The identity gate is mostly here for completeness, at least for now. It will come in handy when dealing with multi-qubit systems and multi-qubit gates. It's represented by the identity matrix, and doesn't affect the state of the qubit.</p>\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n </tr>\n <tr>\n <td>$I$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + \\ket{1}\\bra{1}$</td>\n <td>$I\\ket{\\psi} = \\ket{\\psi}$</td>\n </tr>\n </table>\n</div>"
1315
1315
  }
1316
1316
  ]
1317
1317
  },
@@ -1322,7 +1322,7 @@ export default {
1322
1322
  "items": [
1323
1323
  {
1324
1324
  "type": "text-content",
1325
- "content": "<p>The <strong>Hadamard</strong> gate is an extremely important quantum gate. Unlike the previous gates, applying the Hadamard gate to a qubit in a computational basis state puts that qubit into a superposition.\nLike the Pauli gates, the Hadamard gate is self-adjoint.</p>\n<table>\n<tr>\n<th>Gate</th>\n<th>Matrix</th>\n<th>Ket-Bra</th>\n<th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n<th>Applying to basis states</th>\n</tr>\n<tr>\n<td>$H$</td>\n<td>$\\begin{bmatrix} \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}} \\end{bmatrix} = \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix}$</td>\n<td>$\\ket{0}\\bra{+} + \\ket{1}\\bra{-}$</td>\n<td>$H\\ket{\\psi} = \\alpha\\ket{+} + \\beta\\ket{-} = \\frac{\\alpha + \\beta}{\\sqrt{2}}\\ket{0} + \\frac{\\alpha - \\beta}{\\sqrt{2}}\\ket{1}$</td>\n<td>$H\\ket{0} = \\ket{+}$ <br>\n$H\\ket{1} = \\ket{-}$ <br>\n$H\\ket{+} = \\ket{0}$ <br>\n$H\\ket{-} = \\ket{1}$ <br>\n$H\\ket{i} = e^{i\\pi/4}\\ket{-i}$ <br>\n$H\\ket{-i} = e^{-i\\pi/4}\\ket{i} $ <br>\n</tr>\n</table>\n<blockquote>\n<p>As a reminder, $e^{i\\pi/4} = \\frac{1}{\\sqrt2} (1 + i)$ and $e^{-i\\pi/4} = \\frac{1}{\\sqrt2} (1 - i)$. This is an application of Euler's formula, $e^{i\\theta} = \\cos \\theta + i\\sin \\theta$, where $\\theta$ is measured in radians.\nSee this <a href=\"https://en.wikipedia.org/wiki/Euler%27s_formula\">Wikipedia article</a> for an explanation of Euler's formula and/or <a href=\"https://youtu.be/v0YEaeIClKY\">this video</a> for a more intuitive explanation.</p>\n</blockquote>\n"
1325
+ "content": "<p>The <strong>Hadamard</strong> gate is an extremely important quantum gate. Unlike the previous gates, applying the Hadamard gate to a qubit in a computational basis state puts that qubit into a superposition.\nLike the Pauli gates, the Hadamard gate is self-adjoint.</p>\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$H$</td>\n <td>$\\begin{bmatrix} \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}} \\end{bmatrix} = \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{+} + \\ket{1}\\bra{-}$</td>\n <td>$H\\ket{\\psi} = \\alpha\\ket{+} + \\beta\\ket{-} = \\frac{\\alpha + \\beta}{\\sqrt{2}}\\ket{0} + \\frac{\\alpha - \\beta}{\\sqrt{2}}\\ket{1}$</td>\n <td>$H\\ket{0} = \\ket{+}$ <br>\n $H\\ket{1} = \\ket{-}$ <br>\n $H\\ket{+} = \\ket{0}$ <br>\n $H\\ket{-} = \\ket{1}$ <br>\n $H\\ket{i} = e^{i\\pi/4}\\ket{-i}$ <br>\n $H\\ket{-i} = e^{-i\\pi/4}\\ket{i} $ <br>\n </tr>\n </table>\n</div>\n<blockquote>\n<p>As a reminder, $e^{i\\pi/4} = \\frac{1}{\\sqrt2} (1 + i)$ and $e^{-i\\pi/4} = \\frac{1}{\\sqrt2} (1 - i)$. This is an application of Euler's formula, $e^{i\\theta} = \\cos \\theta + i\\sin \\theta$, where $\\theta$ is measured in radians.\nSee this <a href=\"https://en.wikipedia.org/wiki/Euler%27s_formula\">Wikipedia article</a> for an explanation of Euler's formula and/or <a href=\"https://youtu.be/v0YEaeIClKY\">this video</a> for a more intuitive explanation.</p>\n</blockquote>\n"
1326
1326
  }
1327
1327
  ]
1328
1328
  },
@@ -1389,7 +1389,7 @@ export default {
1389
1389
  "items": [
1390
1390
  {
1391
1391
  "type": "text-content",
1392
- "content": "<p>The next two gates are known as <strong>phase shift gates</strong>. They apply a phase to the $\\ket{1}$ state, and leave the $\\ket{0}$ state unchanged.</p>\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$S$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & i \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + i\\ket{1}\\bra{1}$</td>\n <td>$S\\ket{\\psi} = \\alpha\\ket{0} + i\\beta\\ket{1}$</td>\n <td>\n $S\\ket{0} = \\ket{0}$<br>\n $S\\ket{1} = i\\ket{1}$<br>\n $S\\ket{+} = \\ket{i}$<br>\n $S\\ket{-} = \\ket{-i}$<br>\n $S\\ket{i} = \\ket{-}$<br>\n $S\\ket{-i} = \\ket{+}$<br>\n </td>\n </tr>\n <tr>\n <td>$T$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\pi/4} \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + e^{i\\pi/4}\\ket{1}$$\\bra{1}$</td>\n <td>$T\\ket{\\psi} = \\alpha\\ket{0} + e^{i\\pi/4} \\beta \\ket{1}$</td>\n <td>\n $T\\ket{0} = \\ket{0}$<br>\n $T\\ket{1} = e^{i\\pi/4}\\ket{1}$\n </td>\n </tr>\n</table>\n<blockquote>\n<p>Notice that applying the $T$ gate twice is equivalent to applying the $S$ gate, and applying the $S$ gate twice is equivalent to applying the $Z$ gate:\n$$T^2 = S, S^2 = Z$$</p>\n</blockquote>\n"
1392
+ "content": "<p>The next two gates are known as <strong>phase shift gates</strong>. They apply a phase to the $\\ket{1}$ state, and leave the $\\ket{0}$ state unchanged.</p>\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$S$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & i \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + i\\ket{1}\\bra{1}$</td>\n <td>$S\\ket{\\psi} = \\alpha\\ket{0} + i\\beta\\ket{1}$</td>\n <td>\n $S\\ket{0} = \\ket{0}$<br>\n $S\\ket{1} = i\\ket{1}$<br>\n $S\\ket{+} = \\ket{i}$<br>\n $S\\ket{-} = \\ket{-i}$<br>\n $S\\ket{i} = \\ket{-}$<br>\n $S\\ket{-i} = \\ket{+}$<br>\n </td>\n </tr>\n <tr>\n <td>$T$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\pi/4} \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + e^{i\\pi/4}\\ket{1}$$\\bra{1}$</td>\n <td>$T\\ket{\\psi} = \\alpha\\ket{0} + e^{i\\pi/4} \\beta \\ket{1}$</td>\n <td>\n $T\\ket{0} = \\ket{0}$<br>\n $T\\ket{1} = e^{i\\pi/4}\\ket{1}$\n </td>\n </tr>\n </table>\n</div>\n<blockquote>\n<p>Notice that applying the $T$ gate twice is equivalent to applying the $S$ gate, and applying the $S$ gate twice is equivalent to applying the $Z$ gate:\n$$T^2 = S, S^2 = Z$$</p>\n</blockquote>\n"
1393
1393
  }
1394
1394
  ]
1395
1395
  },
@@ -1465,7 +1465,7 @@ export default {
1465
1465
  "items": [
1466
1466
  {
1467
1467
  "type": "text-content",
1468
- "content": "<p>The next few gates are parametrized: their exact behavior depends on a numeric parameter - an angle $\\theta$, given in radians.\nThese gates are the $X$ rotation gate $R_x(\\theta)$, $Y$ rotation gate $R_y(\\theta)$, $Z$ rotation gate $R_z(\\theta)$, and the arbitrary phase gate $R_1(\\theta)$.\nNote that for the first three gates the parameter $\\theta$ is multiplied by $\\frac{1}{2}$ within the gate's matrix.</p>\n<blockquote>\n<p>These gates are known as rotation gates, because they represent rotations around various axes on the Bloch sphere. The Bloch sphere is a way of representing the qubit states visually, mapping them onto the surface of a sphere.\nUnfortunately, this visualization isn't very useful beyond single-qubit states, which is why this kata doesn't go into details.\nIf you're curious about it, you can learn more in <a href=\"https://en.wikipedia.org/wiki/Bloch_sphere\" target=\"_blank\">this Wikipedia article</a>.</p>\n</blockquote>\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$R_x(\\theta)$</td>\n <td>\n $$\n \\begin{bmatrix} \\cos\\frac{\\theta}{2} & -i\\sin\\frac{\\theta}{2} \\\\ -i\\sin\\frac{\\theta}{2} & \\cos\\frac{\\theta}{2} \\end{bmatrix}\n $$\n </td>\n <td>$R_x(\\theta)\\ket{\\psi} = (\\alpha\\cos\\frac{\\theta}{2} - i\\beta\\sin\\frac{\\theta}{2})\\ket{0} + (\\beta\\cos\\frac{\\theta}{2} - i\\alpha\\sin\\frac{\\theta}{2})\\ket{1}$</td>\n <td>\n $R_x(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} - i\\sin\\frac{\\theta}{2}\\ket{1}$<br>\n $R_x(\\theta)\\ket{1} = \\cos\\frac{\\theta}{2}\\ket{1} - i\\sin\\frac{\\theta}{2}\\ket{0}$\n </td>\n </tr>\n <tr>\n <td>$R_y(\\theta)$</td>\n <td>$\\begin{bmatrix} \\cos\\frac{\\theta}{2} & -\\sin\\frac{\\theta}{2} \\\\ \\sin\\frac{\\theta}{2} & \\cos\\frac{\\theta}{2} \\end{bmatrix}$</td>\n <td>$R_y(\\theta)\\ket{\\psi} = (\\alpha\\cos\\frac{\\theta}{2} - \\beta\\sin\\frac{\\theta}{2})\\ket{0} + (\\beta\\cos\\frac{\\theta}{2} + \\alpha\\sin\\frac{\\theta}{2})\\ket{1}$</td>\n <td>\n $R_y(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} + \\sin\\frac{\\theta}{2}\\ket{1}$<br>\n $R_y(\\theta)\\ket{1} = \\cos\\frac{\\theta}{2}\\ket{1} - \\sin\\frac{\\theta}{2}\\ket{0}$\n </td>\n </tr>\n <tr>\n <td>$R_z(\\theta)$</td>\n <td>$\\begin{bmatrix} e^{-i\\theta/2} & 0 \\\\ 0 & e^{i\\theta/2} \\end{bmatrix}$</td>\n <td>$R_z(\\theta)\\ket{\\psi} = \\alpha e^{-i\\theta/2}\\ket{0} + \\beta e^{i\\theta/2}\\ket{1}$</td>\n <td>\n $R_z(\\theta)\\ket{0} = e^{-i\\theta/2}\\ket{0}$<br>\n $R_z(\\theta)\\ket{1} = e^{i\\theta/2}\\ket{1}$\n </td>\n </tr>\n <tr>\n <td>$R_1(\\theta)$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\theta} \\end{bmatrix}$</td>\n <td>$R_1(\\theta)\\ket{\\psi} = \\alpha\\ket{0} + \\beta e^{i\\theta}\\ket{1}$</td>\n <td>\n $R_1(\\theta)\\ket{0} = \\ket{0}$<br>\n $R_1(\\theta)\\ket{1} = e^{i\\theta}\\ket{1}$\n </td> \n </tr>\n</table>\n<p>You have already encountered some special cases of the $R_1$ gate:</p>\n<p>$$T = R_1(\\frac{\\pi}{4}), S = R_1(\\frac{\\pi}{2}), Z = R_1(\\pi)$$</p>\n<p>In addition, this gate is closely related to the $R_z$ gate: applying $R_1$ gate is equivalent to applying the $R_z$ gate, and then applying a global phase:</p>\n<p>$$R_1(\\theta) = e^{i\\theta/2}R_z(\\theta)$$</p>\n<p>In addition, the rotation gates are very closely related to their respective Pauli gates:</p>\n<p>$$X = iR_x(\\pi), Y = iR_y(\\pi), Z = iR_z(\\pi)$$</p>\n"
1468
+ "content": "<p>The next few gates are parametrized: their exact behavior depends on a numeric parameter - an angle $\\theta$, given in radians.\nThese gates are the $X$ rotation gate $R_x(\\theta)$, $Y$ rotation gate $R_y(\\theta)$, $Z$ rotation gate $R_z(\\theta)$, and the arbitrary phase gate $R_1(\\theta)$.\nNote that for the first three gates the parameter $\\theta$ is multiplied by $\\frac{1}{2}$ within the gate's matrix.</p>\n<blockquote>\n<p>These gates are known as rotation gates, because they represent rotations around various axes on the Bloch sphere. The Bloch sphere is a way of representing the qubit states visually, mapping them onto the surface of a sphere.\nUnfortunately, this visualization isn't very useful beyond single-qubit states, which is why this kata doesn't go into details.\nIf you're curious about it, you can learn more in <a href=\"https://en.wikipedia.org/wiki/Bloch_sphere\" target=\"_blank\">this Wikipedia article</a>.</p>\n</blockquote>\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$R_x(\\theta)$</td>\n <td>\n $$\n \\begin{bmatrix} \\cos\\frac{\\theta}{2} & -i\\sin\\frac{\\theta}{2} \\\\ -i\\sin\\frac{\\theta}{2} & \\cos\\frac{\\theta}{2} \\end{bmatrix}\n $$\n </td>\n <td>$R_x(\\theta)\\ket{\\psi} = (\\alpha\\cos\\frac{\\theta}{2} - i\\beta\\sin\\frac{\\theta}{2})\\ket{0} + (\\beta\\cos\\frac{\\theta}{2} - i\\alpha\\sin\\frac{\\theta}{2})\\ket{1}$</td>\n <td>\n $R_x(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} - i\\sin\\frac{\\theta}{2}\\ket{1}$<br>\n $R_x(\\theta)\\ket{1} = \\cos\\frac{\\theta}{2}\\ket{1} - i\\sin\\frac{\\theta}{2}\\ket{0}$\n </td>\n </tr>\n <tr>\n <td>$R_y(\\theta)$</td>\n <td>$\\begin{bmatrix} \\cos\\frac{\\theta}{2} & -\\sin\\frac{\\theta}{2} \\\\ \\sin\\frac{\\theta}{2} & \\cos\\frac{\\theta}{2} \\end{bmatrix}$</td>\n <td>$R_y(\\theta)\\ket{\\psi} = (\\alpha\\cos\\frac{\\theta}{2} - \\beta\\sin\\frac{\\theta}{2})\\ket{0} + (\\beta\\cos\\frac{\\theta}{2} + \\alpha\\sin\\frac{\\theta}{2})\\ket{1}$</td>\n <td>\n $R_y(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} + \\sin\\frac{\\theta}{2}\\ket{1}$<br>\n $R_y(\\theta)\\ket{1} = \\cos\\frac{\\theta}{2}\\ket{1} - \\sin\\frac{\\theta}{2}\\ket{0}$\n </td>\n </tr>\n <tr>\n <td>$R_z(\\theta)$</td>\n <td>$\\begin{bmatrix} e^{-i\\theta/2} & 0 \\\\ 0 & e^{i\\theta/2} \\end{bmatrix}$</td>\n <td>$R_z(\\theta)\\ket{\\psi} = \\alpha e^{-i\\theta/2}\\ket{0} + \\beta e^{i\\theta/2}\\ket{1}$</td>\n <td>\n $R_z(\\theta)\\ket{0} = e^{-i\\theta/2}\\ket{0}$<br>\n $R_z(\\theta)\\ket{1} = e^{i\\theta/2}\\ket{1}$\n </td>\n </tr>\n <tr>\n <td>$R_1(\\theta)$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\theta} \\end{bmatrix}$</td>\n <td>$R_1(\\theta)\\ket{\\psi} = \\alpha\\ket{0} + \\beta e^{i\\theta}\\ket{1}$</td>\n <td>\n $R_1(\\theta)\\ket{0} = \\ket{0}$<br>\n $R_1(\\theta)\\ket{1} = e^{i\\theta}\\ket{1}$\n </td> \n </tr>\n </table>\n</div>\n<p>You have already encountered some special cases of the $R_1$ gate:</p>\n<p>$$T = R_1(\\frac{\\pi}{4}), S = R_1(\\frac{\\pi}{2}), Z = R_1(\\pi)$$</p>\n<p>In addition, this gate is closely related to the $R_z$ gate: applying $R_1$ gate is equivalent to applying the $R_z$ gate, and then applying a global phase:</p>\n<p>$$R_1(\\theta) = e^{i\\theta/2}R_z(\\theta)$$</p>\n<p>In addition, the rotation gates are very closely related to their respective Pauli gates:</p>\n<p>$$X = iR_x(\\pi), Y = iR_y(\\pi), Z = iR_z(\\pi)$$</p>\n"
1469
1469
  }
1470
1470
  ]
1471
1471
  },
@@ -6873,7 +6873,7 @@ export default {
6873
6873
  "items": [
6874
6874
  {
6875
6875
  "type": "text-content",
6876
- "content": "<p>To wrap up the 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"
6876
+ "content": "<p>To wrap up the 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}{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}{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}{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}{2^N} \\sum_{x=0}^{2^N-1} 1 = \\frac{1}{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
  },
@@ -1094,7 +1094,7 @@ export default {
1094
1094
  "items": [
1095
1095
  {
1096
1096
  "type": "text-content",
1097
- "content": "\nThere is another way to represent quantum gates, this time using Dirac notation. However, kets aren't enough to represent arbitrary matrices. An additional notation is required: the **bra** (this is why Dirac notation is sometimes called **bra-ket notation**).\n\nRecall that kets represent column vectors; a bra is a ket's row vector counterpart. For any ket $\\ket{\\psi}$, the corresponding bra is its adjoint (conjugate transpose): $\\bra{\\psi} = \\ket{\\psi}^\\dagger$.\n\nSome examples:\n\n<table>\n <tr>\n <th>Ket</th>\n <th>Bra</th>\n </tr>\n <tr>\n <td>$\\ket{0} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}$</td>\n <td>$\\bra{0} = \\begin{bmatrix} 1 & 0 \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{1} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$</td>\n <td>$\\bra{1} = \\begin{bmatrix} 0 & 1 \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{i} = \\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ \\frac{i}{\\sqrt{2}} \\end{bmatrix}$</td>\n <td>$\\bra{ i} = \\begin{bmatrix} \\frac{1}{\\sqrt{2}} & -\\frac{i}{\\sqrt{2}} \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{\\psi} = \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix}$</td>\n <td>$\\bra{\\psi} = \\begin{bmatrix} \\overline{\\alpha} & \\overline{\\beta} \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</td>\n <td>$\\bra{\\psi} = \\overline{\\alpha}\\bra{0} + \\overline{\\beta}\\bra{1}$</td>\n </tr>\n</table>\n\nKets and bras give us a neat way to express inner and outer products. The inner product of $\\ket{\\phi}$ and $\\ket{\\psi}$ is the matrix product of $\\bra{\\phi}$ and $\\ket{\\psi}$, denoted as $\\braket{\\phi|\\psi}$, and their outer product is the matrix product of $\\ket{\\phi}$ and $\\bra{\\psi}$, denoted as $\\ket{\\phi}\\bra{\\psi}$. Notice that the norm of $\\ket{\\psi}$ is $\\sqrt{\\braket{\\psi|\\psi}}$.\n\nThis leads to the representation of matrices via outer products. Recall that the outer product of two vectors of the same size produces a square matrix. You can use a linear combination of several outer products of simple vectors (such as basis vectors) to express any square matrix. For example, the $X$ gate can be expressed as follows:\n\n$$X = \\ket{0}\\bra{1} + \\ket{1}\\bra{0}$$\n\n$$\n\\ket{0}\\bra{1} + \\ket{1}\\bra{0} =\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 & 1 \\end{bmatrix} +\n\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\\begin{bmatrix} 1 & 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 & 1 \\\\ 0 & 0 \\end{bmatrix} + \\begin{bmatrix} 0 & 0 \\\\ 1 & 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n$$\n\nThis representation can be used to carry out calculations in Dirac notation without ever switching back to matrix representation:\n\n$$X\\ket{0} = \\big(\\ket{0}\\bra{1} + \\ket{1}\\bra{0}\\big)\\ket{0} = \\ket{0}\\braket{1|0} + \\ket{1}\\braket{0|0} = \\ket{0}\\big(\\braket{1|0}\\big) + \\ket{1}\\big(\\braket{0|0}\\big) = \\ket{0}(0) + \\ket{1}(1) = \\ket{1}$$\n\n> That last step may seem a bit confusing. Recall that $\\ket{0}$ and $\\ket{1}$ form an **orthonormal basis**. That is, they're both normalized, and they're orthogonal to each other.\n>\n> A vector is normalized if its norm is equal to $1$, which only happens if its inner product with itself is equal to $1$. This means that $\\braket{0|0} = \\braket{1|1} = 1$\n>\n> Two vectors are orthogonal to each other if their inner product equals $0$. This means that $\\braket{0|1} = \\braket{1|0} = 0$.\n\nIn general case, a matrix\n$$A = \\begin{bmatrix} a_{00} & a_{01} \\\\ a_{10} & a_{11} \\end{bmatrix}$$\nwill have the following ket-bra representation:\n$$A = a_{00} \\ket{0}\\bra{0} + a_{01} \\ket{0}\\bra{1} + a_{10} \\ket{1}\\bra{0} + a_{11} \\ket{1}\\bra{1}$$"
1097
+ "content": "\nThere is another way to represent quantum gates, this time using Dirac notation. However, kets aren't enough to represent arbitrary matrices. An additional notation is required: the **bra** (this is why Dirac notation is sometimes called **bra-ket notation**).\n\nRecall that kets represent column vectors; a bra is a ket's row vector counterpart. For any ket $\\ket{\\psi}$, the corresponding bra is its adjoint (conjugate transpose): $\\bra{\\psi} = \\ket{\\psi}^\\dagger$.\n\nSome examples:\n\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <th>Ket</th>\n <th>Bra</th>\n </tr>\n <tr>\n <td>$\\ket{0} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}$</td>\n <td>$\\bra{0} = \\begin{bmatrix} 1 & 0 \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{1} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$</td>\n <td>$\\bra{1} = \\begin{bmatrix} 0 & 1 \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{i} = \\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ \\frac{i}{\\sqrt{2}} \\end{bmatrix}$</td>\n <td>$\\bra{ i} = \\begin{bmatrix} \\frac{1}{\\sqrt{2}} & -\\frac{i}{\\sqrt{2}} \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{\\psi} = \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix}$</td>\n <td>$\\bra{\\psi} = \\begin{bmatrix} \\overline{\\alpha} & \\overline{\\beta} \\end{bmatrix}$</td>\n </tr>\n <tr>\n <td>$\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</td>\n <td>$\\bra{\\psi} = \\overline{\\alpha}\\bra{0} + \\overline{\\beta}\\bra{1}$</td>\n </tr>\n </table>\n</div>\n\nKets and bras give us a neat way to express inner and outer products. The inner product of $\\ket{\\phi}$ and $\\ket{\\psi}$ is the matrix product of $\\bra{\\phi}$ and $\\ket{\\psi}$, denoted as $\\braket{\\phi|\\psi}$, and their outer product is the matrix product of $\\ket{\\phi}$ and $\\bra{\\psi}$, denoted as $\\ket{\\phi}\\bra{\\psi}$. Notice that the norm of $\\ket{\\psi}$ is $\\sqrt{\\braket{\\psi|\\psi}}$.\n\nThis leads to the representation of matrices via outer products. Recall that the outer product of two vectors of the same size produces a square matrix. You can use a linear combination of several outer products of simple vectors (such as basis vectors) to express any square matrix. For example, the $X$ gate can be expressed as follows:\n\n$$X = \\ket{0}\\bra{1} + \\ket{1}\\bra{0}$$\n\n$$\n\\ket{0}\\bra{1} + \\ket{1}\\bra{0} =\n\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 & 1 \\end{bmatrix} +\n\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\\begin{bmatrix} 1 & 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 & 1 \\\\ 0 & 0 \\end{bmatrix} + \\begin{bmatrix} 0 & 0 \\\\ 1 & 0 \\end{bmatrix} =\n\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n$$\n\nThis representation can be used to carry out calculations in Dirac notation without ever switching back to matrix representation:\n\n$$X\\ket{0} = \\big(\\ket{0}\\bra{1} + \\ket{1}\\bra{0}\\big)\\ket{0} = \\ket{0}\\braket{1|0} + \\ket{1}\\braket{0|0} = \\ket{0}\\big(\\braket{1|0}\\big) + \\ket{1}\\big(\\braket{0|0}\\big) = \\ket{0}(0) + \\ket{1}(1) = \\ket{1}$$\n\n> That last step may seem a bit confusing. Recall that $\\ket{0}$ and $\\ket{1}$ form an **orthonormal basis**. That is, they're both normalized, and they're orthogonal to each other.\n>\n> A vector is normalized if its norm is equal to $1$, which only happens if its inner product with itself is equal to $1$. This means that $\\braket{0|0} = \\braket{1|1} = 1$\n>\n> Two vectors are orthogonal to each other if their inner product equals $0$. This means that $\\braket{0|1} = \\braket{1|0} = 0$.\n\nIn general case, a matrix\n$$A = \\begin{bmatrix} a_{00} & a_{01} \\\\ a_{10} & a_{11} \\end{bmatrix}$$\nwill have the following ket-bra representation:\n$$A = a_{00} \\ket{0}\\bra{0} + a_{01} \\ket{0}\\bra{1} + a_{10} \\ket{1}\\bra{0} + a_{11} \\ket{1}\\bra{1}$$"
1098
1098
  }
1099
1099
  ]
1100
1100
  },
@@ -1116,7 +1116,7 @@ export default {
1116
1116
  "items": [
1117
1117
  {
1118
1118
  "type": "text-content",
1119
- "content": "\nThis section introduces some of the common single-qubit gates, including their matrix form, their ket-bra decomposition, and a brief \"cheat sheet\" listing their effect on some common qubit states.\n\nYou can use a tool called <a href=\"https://algassert.com/quirk\" target=\"_blank\">Quirk</a> to visualize how these gates interact with various qubit states.\n\nThis section relies on the following notation:\n\n<table>\n <tr>\n <td>$\\ket{+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + \\ket{1}\\big)$</td>\n <td>$\\ket{-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - \\ket{1}\\big)$</td>\n </tr>\n <tr>\n <td>$\\ket{i} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + i\\ket{1}\\big)$</td>\n <td>$\\ket{-i} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - i\\ket{1}\\big)$</td>\n </tr>\n</table>\n\nThe Pauli gates, named after <a href=\"https://en.wikipedia.org/wiki/Wolfgang_Pauli\" target=\"_blank\">Wolfgang Pauli</a>, are based on the so-called **Pauli matrices**, $X$, $Y$ and $Z$. All three Pauli gates are **self-adjoint**, meaning that each one is its own inverse, $XX = \\mathbb{I}$.\n\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$X$</td>\n <td>$\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{1} + \\ket{1}\\bra{0}$</td>\n <td>$X\\ket{\\psi} = \\alpha\\ket{1} + \\beta\\ket{0}$</td>\n <td>\n $X\\ket{0} = \\ket{1}$<br>\n $X\\ket{1} = \\ket{0}$<br>\n $X\\ket{+} = \\ket{+}$<br>\n $X\\ket{-} = -\\ket{-}$<br>\n $X\\ket{i} = i\\ket{-i}$<br>\n $X\\ket{-i} = -i\\ket{i}$\n </td>\n </tr>\n <tr>\n <td>$Y$</td>\n <td>$\\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}$</td>\n <td>$i(\\ket{1}\\bra{0} - \\ket{0}\\bra{1})$</td>\n <td>$Y\\ket{\\psi} = i\\big(\\alpha\\ket{1} - \\beta\\ket{0}\\big)$</td>\n <td>\n $Y\\ket{0} = i\\ket{1}$<br>\n $Y\\ket{1} = -i\\ket{0}$<br>\n $Y\\ket{+} = -i\\ket{-}$<br>\n $Y\\ket{-} = i\\ket{+}$<br>\n $Y\\ket{i} = \\ket{i}$<br>\n $Y\\ket{-i} = -\\ket{-i}$<br>\n </td>\n </tr>\n <tr>\n <td>$Z$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} - \\ket{1}\\bra{1}$</td>\n <td>$Z\\ket{\\psi} = \\alpha\\ket{0} - \\beta\\ket{1}$</td>\n <td>\n $Z\\ket{0} = \\ket{0}$<br>\n $Z\\ket{1} = -\\ket{1}$<br>\n $Z\\ket{+} = \\ket{-}$<br>\n $Z\\ket{-} = \\ket{+}$<br>\n $Z\\ket{i} = \\ket{-i}$<br>\n $Z\\ket{-i} = \\ket{i}$<br>\n </td>\n </tr>\n</table>\n\n> The $X$ gate is sometimes referred to as the **bit flip** gate, or the **NOT** gate, because it acts like the classical NOT gate on the computational basis.\n>\n> The $Z$ gate is sometimes referred to as the **phase flip** gate.\n\nHere are several properties of the Pauli gates that are easy to verify and convenient to remember:\n\n- Different Pauli gates _anti-commute_:\n $$XZ = -ZX, XY = -YX, YZ = -ZY$$\n- A product of any two Pauli gates equals the third gate, with an extra $i$ (or $-i$) phase:\n $$XY = iZ, YZ = iX, ZX = iY$$\n- A product of all three Pauli gates equals identity (with an extra $i$ phase):\n $$XYZ = iI$$"
1119
+ "content": "\nThis section introduces some of the common single-qubit gates, including their matrix form, their ket-bra decomposition, and a brief \"cheat sheet\" listing their effect on some common qubit states.\n\nYou can use a tool called <a href=\"https://algassert.com/quirk\" target=\"_blank\">Quirk</a> to visualize how these gates interact with various qubit states.\n\nThis section relies on the following notation:\n\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <td>$\\ket{+} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + \\ket{1}\\big)$</td>\n <td>$\\ket{-} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - \\ket{1}\\big)$</td>\n </tr>\n <tr>\n <td>$\\ket{i} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} + i\\ket{1}\\big)$</td>\n <td>$\\ket{-i} = \\frac{1}{\\sqrt{2}}\\big(\\ket{0} - i\\ket{1}\\big)$</td>\n </tr>\n </table>\n</div>\n\nThe Pauli gates, named after <a href=\"https://en.wikipedia.org/wiki/Wolfgang_Pauli\" target=\"_blank\">Wolfgang Pauli</a>, are based on the so-called **Pauli matrices**, $X$, $Y$ and $Z$. All three Pauli gates are **self-adjoint**, meaning that each one is its own inverse, $XX = \\mathbb{I}$.\n\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$X$</td>\n <td>$\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{1} + \\ket{1}\\bra{0}$</td>\n <td>$X\\ket{\\psi} = \\alpha\\ket{1} + \\beta\\ket{0}$</td>\n <td>\n $X\\ket{0} = \\ket{1}$<br>\n $X\\ket{1} = \\ket{0}$<br>\n $X\\ket{+} = \\ket{+}$<br>\n $X\\ket{-} = -\\ket{-}$<br>\n $X\\ket{i} = i\\ket{-i}$<br>\n $X\\ket{-i} = -i\\ket{i}$\n </td>\n </tr>\n <tr>\n <td>$Y$</td>\n <td>$\\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}$</td>\n <td>$i(\\ket{1}\\bra{0} - \\ket{0}\\bra{1})$</td>\n <td>$Y\\ket{\\psi} = i\\big(\\alpha\\ket{1} - \\beta\\ket{0}\\big)$</td>\n <td>\n $Y\\ket{0} = i\\ket{1}$<br>\n $Y\\ket{1} = -i\\ket{0}$<br>\n $Y\\ket{+} = -i\\ket{-}$<br>\n $Y\\ket{-} = i\\ket{+}$<br>\n $Y\\ket{i} = \\ket{i}$<br>\n $Y\\ket{-i} = -\\ket{-i}$<br>\n </td>\n </tr>\n <tr>\n <td>$Z$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} - \\ket{1}\\bra{1}$</td>\n <td>$Z\\ket{\\psi} = \\alpha\\ket{0} - \\beta\\ket{1}$</td>\n <td>\n $Z\\ket{0} = \\ket{0}$<br>\n $Z\\ket{1} = -\\ket{1}$<br>\n $Z\\ket{+} = \\ket{-}$<br>\n $Z\\ket{-} = \\ket{+}$<br>\n $Z\\ket{i} = \\ket{-i}$<br>\n $Z\\ket{-i} = \\ket{i}$<br>\n </td>\n </tr>\n </table>\n</div>\n\n> The $X$ gate is sometimes referred to as the **bit flip** gate, or the **NOT** gate, because it acts like the classical NOT gate on the computational basis.\n>\n> The $Z$ gate is sometimes referred to as the **phase flip** gate.\n\nHere are several properties of the Pauli gates that are easy to verify and convenient to remember:\n\n- Different Pauli gates _anti-commute_:\n $$XZ = -ZX, XY = -YX, YZ = -ZY$$\n- A product of any two Pauli gates equals the third gate, with an extra $i$ (or $-i$) phase:\n $$XY = iZ, YZ = iX, ZX = iY$$\n- A product of all three Pauli gates equals identity (with an extra $i$ phase):\n $$XYZ = iI$$"
1120
1120
  }
1121
1121
  ]
1122
1122
  },
@@ -1311,7 +1311,7 @@ export default {
1311
1311
  "items": [
1312
1312
  {
1313
1313
  "type": "text-content",
1314
- "content": "\nThe identity gate is mostly here for completeness, at least for now. It will come in handy when dealing with multi-qubit systems and multi-qubit gates. It's represented by the identity matrix, and doesn't affect the state of the qubit.\n\n<table>\n<tr>\n<th>Gate</th>\n<th>Matrix</th>\n<th>Ket-Bra</th>\n<th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n</tr>\n<tr>\n<td>$I$</td>\n<td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}$</td>\n<td>$\\ket{0}\\bra{0} + \\ket{1}\\bra{1}$</td>\n<td>$I\\ket{\\psi} = \\ket{\\psi}$</td>\n</tr>\n</table>"
1314
+ "content": "\nThe identity gate is mostly here for completeness, at least for now. It will come in handy when dealing with multi-qubit systems and multi-qubit gates. It's represented by the identity matrix, and doesn't affect the state of the qubit.\n\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n </tr>\n <tr>\n <td>$I$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + \\ket{1}\\bra{1}$</td>\n <td>$I\\ket{\\psi} = \\ket{\\psi}$</td>\n </tr>\n </table>\n</div>"
1315
1315
  }
1316
1316
  ]
1317
1317
  },
@@ -1322,7 +1322,7 @@ export default {
1322
1322
  "items": [
1323
1323
  {
1324
1324
  "type": "text-content",
1325
- "content": "\nThe **Hadamard** gate is an extremely important quantum gate. Unlike the previous gates, applying the Hadamard gate to a qubit in a computational basis state puts that qubit into a superposition.\nLike the Pauli gates, the Hadamard gate is self-adjoint.\n\n<table>\n<tr>\n<th>Gate</th>\n<th>Matrix</th>\n<th>Ket-Bra</th>\n<th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n<th>Applying to basis states</th>\n</tr>\n<tr>\n<td>$H$</td>\n<td>$\\begin{bmatrix} \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}} \\end{bmatrix} = \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix}$</td>\n<td>$\\ket{0}\\bra{+} + \\ket{1}\\bra{-}$</td>\n<td>$H\\ket{\\psi} = \\alpha\\ket{+} + \\beta\\ket{-} = \\frac{\\alpha + \\beta}{\\sqrt{2}}\\ket{0} + \\frac{\\alpha - \\beta}{\\sqrt{2}}\\ket{1}$</td>\n<td>$H\\ket{0} = \\ket{+}$ <br>\n$H\\ket{1} = \\ket{-}$ <br>\n$H\\ket{+} = \\ket{0}$ <br>\n$H\\ket{-} = \\ket{1}$ <br>\n$H\\ket{i} = e^{i\\pi/4}\\ket{-i}$ <br>\n$H\\ket{-i} = e^{-i\\pi/4}\\ket{i} $ <br>\n</tr>\n</table>\n\n> As a reminder, $e^{i\\pi/4} = \\frac{1}{\\sqrt2} (1 + i)$ and $e^{-i\\pi/4} = \\frac{1}{\\sqrt2} (1 - i)$. This is an application of Euler's formula, $e^{i\\theta} = \\cos \\theta + i\\sin \\theta$, where $\\theta$ is measured in radians.\n> See this [Wikipedia article](https://en.wikipedia.org/wiki/Euler%27s_formula) for an explanation of Euler's formula and/or [this video](https://youtu.be/v0YEaeIClKY) for a more intuitive explanation."
1325
+ "content": "\nThe **Hadamard** gate is an extremely important quantum gate. Unlike the previous gates, applying the Hadamard gate to a qubit in a computational basis state puts that qubit into a superposition.\nLike the Pauli gates, the Hadamard gate is self-adjoint.\n\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$H$</td>\n <td>$\\begin{bmatrix} \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}} \\end{bmatrix} = \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{+} + \\ket{1}\\bra{-}$</td>\n <td>$H\\ket{\\psi} = \\alpha\\ket{+} + \\beta\\ket{-} = \\frac{\\alpha + \\beta}{\\sqrt{2}}\\ket{0} + \\frac{\\alpha - \\beta}{\\sqrt{2}}\\ket{1}$</td>\n <td>$H\\ket{0} = \\ket{+}$ <br>\n $H\\ket{1} = \\ket{-}$ <br>\n $H\\ket{+} = \\ket{0}$ <br>\n $H\\ket{-} = \\ket{1}$ <br>\n $H\\ket{i} = e^{i\\pi/4}\\ket{-i}$ <br>\n $H\\ket{-i} = e^{-i\\pi/4}\\ket{i} $ <br>\n </tr>\n </table>\n</div>\n\n> As a reminder, $e^{i\\pi/4} = \\frac{1}{\\sqrt2} (1 + i)$ and $e^{-i\\pi/4} = \\frac{1}{\\sqrt2} (1 - i)$. This is an application of Euler's formula, $e^{i\\theta} = \\cos \\theta + i\\sin \\theta$, where $\\theta$ is measured in radians.\n> See this [Wikipedia article](https://en.wikipedia.org/wiki/Euler%27s_formula) for an explanation of Euler's formula and/or [this video](https://youtu.be/v0YEaeIClKY) for a more intuitive explanation."
1326
1326
  }
1327
1327
  ]
1328
1328
  },
@@ -1389,7 +1389,7 @@ export default {
1389
1389
  "items": [
1390
1390
  {
1391
1391
  "type": "text-content",
1392
- "content": "\nThe next two gates are known as **phase shift gates**. They apply a phase to the $\\ket{1}$ state, and leave the $\\ket{0}$ state unchanged.\n\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$S$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & i \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + i\\ket{1}\\bra{1}$</td>\n <td>$S\\ket{\\psi} = \\alpha\\ket{0} + i\\beta\\ket{1}$</td>\n <td>\n $S\\ket{0} = \\ket{0}$<br>\n $S\\ket{1} = i\\ket{1}$<br>\n $S\\ket{+} = \\ket{i}$<br>\n $S\\ket{-} = \\ket{-i}$<br>\n $S\\ket{i} = \\ket{-}$<br>\n $S\\ket{-i} = \\ket{+}$<br>\n </td>\n </tr>\n <tr>\n <td>$T$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\pi/4} \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + e^{i\\pi/4}\\ket{1}$$\\bra{1}$</td>\n <td>$T\\ket{\\psi} = \\alpha\\ket{0} + e^{i\\pi/4} \\beta \\ket{1}$</td>\n <td>\n $T\\ket{0} = \\ket{0}$<br>\n $T\\ket{1} = e^{i\\pi/4}\\ket{1}$\n </td>\n </tr>\n</table>\n\n> Notice that applying the $T$ gate twice is equivalent to applying the $S$ gate, and applying the $S$ gate twice is equivalent to applying the $Z$ gate:\n$$T^2 = S, S^2 = Z$$"
1392
+ "content": "\nThe next two gates are known as **phase shift gates**. They apply a phase to the $\\ket{1}$ state, and leave the $\\ket{0}$ state unchanged.\n\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Ket-Bra</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$S$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & i \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + i\\ket{1}\\bra{1}$</td>\n <td>$S\\ket{\\psi} = \\alpha\\ket{0} + i\\beta\\ket{1}$</td>\n <td>\n $S\\ket{0} = \\ket{0}$<br>\n $S\\ket{1} = i\\ket{1}$<br>\n $S\\ket{+} = \\ket{i}$<br>\n $S\\ket{-} = \\ket{-i}$<br>\n $S\\ket{i} = \\ket{-}$<br>\n $S\\ket{-i} = \\ket{+}$<br>\n </td>\n </tr>\n <tr>\n <td>$T$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\pi/4} \\end{bmatrix}$</td>\n <td>$\\ket{0}\\bra{0} + e^{i\\pi/4}\\ket{1}$$\\bra{1}$</td>\n <td>$T\\ket{\\psi} = \\alpha\\ket{0} + e^{i\\pi/4} \\beta \\ket{1}$</td>\n <td>\n $T\\ket{0} = \\ket{0}$<br>\n $T\\ket{1} = e^{i\\pi/4}\\ket{1}$\n </td>\n </tr>\n </table>\n</div>\n\n> Notice that applying the $T$ gate twice is equivalent to applying the $S$ gate, and applying the $S$ gate twice is equivalent to applying the $Z$ gate:\n$$T^2 = S, S^2 = Z$$"
1393
1393
  }
1394
1394
  ]
1395
1395
  },
@@ -1465,7 +1465,7 @@ export default {
1465
1465
  "items": [
1466
1466
  {
1467
1467
  "type": "text-content",
1468
- "content": "\nThe next few gates are parametrized: their exact behavior depends on a numeric parameter - an angle $\\theta$, given in radians.\nThese gates are the $X$ rotation gate $R_x(\\theta)$, $Y$ rotation gate $R_y(\\theta)$, $Z$ rotation gate $R_z(\\theta)$, and the arbitrary phase gate $R_1(\\theta)$.\nNote that for the first three gates the parameter $\\theta$ is multiplied by $\\frac{1}{2}$ within the gate's matrix.\n\n> These gates are known as rotation gates, because they represent rotations around various axes on the Bloch sphere. The Bloch sphere is a way of representing the qubit states visually, mapping them onto the surface of a sphere.\n> Unfortunately, this visualization isn't very useful beyond single-qubit states, which is why this kata doesn't go into details.\n> If you're curious about it, you can learn more in <a href=\"https://en.wikipedia.org/wiki/Bloch_sphere\" target=\"_blank\">this Wikipedia article</a>.\n\n<table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$R_x(\\theta)$</td>\n <td>\n $$\n \\begin{bmatrix} \\cos\\frac{\\theta}{2} & -i\\sin\\frac{\\theta}{2} \\\\ -i\\sin\\frac{\\theta}{2} & \\cos\\frac{\\theta}{2} \\end{bmatrix}\n $$\n </td>\n <td>$R_x(\\theta)\\ket{\\psi} = (\\alpha\\cos\\frac{\\theta}{2} - i\\beta\\sin\\frac{\\theta}{2})\\ket{0} + (\\beta\\cos\\frac{\\theta}{2} - i\\alpha\\sin\\frac{\\theta}{2})\\ket{1}$</td>\n <td>\n $R_x(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} - i\\sin\\frac{\\theta}{2}\\ket{1}$<br>\n $R_x(\\theta)\\ket{1} = \\cos\\frac{\\theta}{2}\\ket{1} - i\\sin\\frac{\\theta}{2}\\ket{0}$\n </td>\n </tr>\n <tr>\n <td>$R_y(\\theta)$</td>\n <td>$\\begin{bmatrix} \\cos\\frac{\\theta}{2} & -\\sin\\frac{\\theta}{2} \\\\ \\sin\\frac{\\theta}{2} & \\cos\\frac{\\theta}{2} \\end{bmatrix}$</td>\n <td>$R_y(\\theta)\\ket{\\psi} = (\\alpha\\cos\\frac{\\theta}{2} - \\beta\\sin\\frac{\\theta}{2})\\ket{0} + (\\beta\\cos\\frac{\\theta}{2} + \\alpha\\sin\\frac{\\theta}{2})\\ket{1}$</td>\n <td>\n $R_y(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} + \\sin\\frac{\\theta}{2}\\ket{1}$<br>\n $R_y(\\theta)\\ket{1} = \\cos\\frac{\\theta}{2}\\ket{1} - \\sin\\frac{\\theta}{2}\\ket{0}$\n </td>\n </tr>\n <tr>\n <td>$R_z(\\theta)$</td>\n <td>$\\begin{bmatrix} e^{-i\\theta/2} & 0 \\\\ 0 & e^{i\\theta/2} \\end{bmatrix}$</td>\n <td>$R_z(\\theta)\\ket{\\psi} = \\alpha e^{-i\\theta/2}\\ket{0} + \\beta e^{i\\theta/2}\\ket{1}$</td>\n <td>\n $R_z(\\theta)\\ket{0} = e^{-i\\theta/2}\\ket{0}$<br>\n $R_z(\\theta)\\ket{1} = e^{i\\theta/2}\\ket{1}$\n </td>\n </tr>\n <tr>\n <td>$R_1(\\theta)$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\theta} \\end{bmatrix}$</td>\n <td>$R_1(\\theta)\\ket{\\psi} = \\alpha\\ket{0} + \\beta e^{i\\theta}\\ket{1}$</td>\n <td>\n $R_1(\\theta)\\ket{0} = \\ket{0}$<br>\n $R_1(\\theta)\\ket{1} = e^{i\\theta}\\ket{1}$\n </td> \n </tr>\n</table>\n\nYou have already encountered some special cases of the $R_1$ gate:\n\n$$T = R_1(\\frac{\\pi}{4}), S = R_1(\\frac{\\pi}{2}), Z = R_1(\\pi)$$\n\nIn addition, this gate is closely related to the $R_z$ gate: applying $R_1$ gate is equivalent to applying the $R_z$ gate, and then applying a global phase:\n\n$$R_1(\\theta) = e^{i\\theta/2}R_z(\\theta)$$\n\nIn addition, the rotation gates are very closely related to their respective Pauli gates:\n\n$$X = iR_x(\\pi), Y = iR_y(\\pi), Z = iR_z(\\pi)$$"
1468
+ "content": "\nThe next few gates are parametrized: their exact behavior depends on a numeric parameter - an angle $\\theta$, given in radians.\nThese gates are the $X$ rotation gate $R_x(\\theta)$, $Y$ rotation gate $R_y(\\theta)$, $Z$ rotation gate $R_z(\\theta)$, and the arbitrary phase gate $R_1(\\theta)$.\nNote that for the first three gates the parameter $\\theta$ is multiplied by $\\frac{1}{2}$ within the gate's matrix.\n\n> These gates are known as rotation gates, because they represent rotations around various axes on the Bloch sphere. The Bloch sphere is a way of representing the qubit states visually, mapping them onto the surface of a sphere.\n> Unfortunately, this visualization isn't very useful beyond single-qubit states, which is why this kata doesn't go into details.\n> If you're curious about it, you can learn more in <a href=\"https://en.wikipedia.org/wiki/Bloch_sphere\" target=\"_blank\">this Wikipedia article</a>.\n\n<div class=\"table-with-latex\">\n <table>\n <tr>\n <th>Gate</th>\n <th>Matrix</th>\n <th>Applying to $\\ket{\\psi} = \\alpha\\ket{0} + \\beta\\ket{1}$</th>\n <th>Applying to basis states</th>\n </tr>\n <tr>\n <td>$R_x(\\theta)$</td>\n <td>\n $$\n \\begin{bmatrix} \\cos\\frac{\\theta}{2} & -i\\sin\\frac{\\theta}{2} \\\\ -i\\sin\\frac{\\theta}{2} & \\cos\\frac{\\theta}{2} \\end{bmatrix}\n $$\n </td>\n <td>$R_x(\\theta)\\ket{\\psi} = (\\alpha\\cos\\frac{\\theta}{2} - i\\beta\\sin\\frac{\\theta}{2})\\ket{0} + (\\beta\\cos\\frac{\\theta}{2} - i\\alpha\\sin\\frac{\\theta}{2})\\ket{1}$</td>\n <td>\n $R_x(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} - i\\sin\\frac{\\theta}{2}\\ket{1}$<br>\n $R_x(\\theta)\\ket{1} = \\cos\\frac{\\theta}{2}\\ket{1} - i\\sin\\frac{\\theta}{2}\\ket{0}$\n </td>\n </tr>\n <tr>\n <td>$R_y(\\theta)$</td>\n <td>$\\begin{bmatrix} \\cos\\frac{\\theta}{2} & -\\sin\\frac{\\theta}{2} \\\\ \\sin\\frac{\\theta}{2} & \\cos\\frac{\\theta}{2} \\end{bmatrix}$</td>\n <td>$R_y(\\theta)\\ket{\\psi} = (\\alpha\\cos\\frac{\\theta}{2} - \\beta\\sin\\frac{\\theta}{2})\\ket{0} + (\\beta\\cos\\frac{\\theta}{2} + \\alpha\\sin\\frac{\\theta}{2})\\ket{1}$</td>\n <td>\n $R_y(\\theta)\\ket{0} = \\cos\\frac{\\theta}{2}\\ket{0} + \\sin\\frac{\\theta}{2}\\ket{1}$<br>\n $R_y(\\theta)\\ket{1} = \\cos\\frac{\\theta}{2}\\ket{1} - \\sin\\frac{\\theta}{2}\\ket{0}$\n </td>\n </tr>\n <tr>\n <td>$R_z(\\theta)$</td>\n <td>$\\begin{bmatrix} e^{-i\\theta/2} & 0 \\\\ 0 & e^{i\\theta/2} \\end{bmatrix}$</td>\n <td>$R_z(\\theta)\\ket{\\psi} = \\alpha e^{-i\\theta/2}\\ket{0} + \\beta e^{i\\theta/2}\\ket{1}$</td>\n <td>\n $R_z(\\theta)\\ket{0} = e^{-i\\theta/2}\\ket{0}$<br>\n $R_z(\\theta)\\ket{1} = e^{i\\theta/2}\\ket{1}$\n </td>\n </tr>\n <tr>\n <td>$R_1(\\theta)$</td>\n <td>$\\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\theta} \\end{bmatrix}$</td>\n <td>$R_1(\\theta)\\ket{\\psi} = \\alpha\\ket{0} + \\beta e^{i\\theta}\\ket{1}$</td>\n <td>\n $R_1(\\theta)\\ket{0} = \\ket{0}$<br>\n $R_1(\\theta)\\ket{1} = e^{i\\theta}\\ket{1}$\n </td> \n </tr>\n </table>\n</div>\n\nYou have already encountered some special cases of the $R_1$ gate:\n\n$$T = R_1(\\frac{\\pi}{4}), S = R_1(\\frac{\\pi}{2}), Z = R_1(\\pi)$$\n\nIn addition, this gate is closely related to the $R_z$ gate: applying $R_1$ gate is equivalent to applying the $R_z$ gate, and then applying a global phase:\n\n$$R_1(\\theta) = e^{i\\theta/2}R_z(\\theta)$$\n\nIn addition, the rotation gates are very closely related to their respective Pauli gates:\n\n$$X = iR_x(\\pi), Y = iR_y(\\pi), Z = iR_z(\\pi)$$"
1469
1469
  }
1470
1470
  ]
1471
1471
  },
@@ -6873,7 +6873,7 @@ export default {
6873
6873
  "items": [
6874
6874
  {
6875
6875
  "type": "text-content",
6876
- "content": "\nTo wrap up the 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 *scalar product function*, that is, there exists an $N$-bit string $s$\nthat allows the following representation ($\\cdot$ is bitwise inner product of integers modulo $2$):\n\n$$f(x) = x \\cdot s = \\sum_{k=0}^{N-1} x_k s_k \\bmod 2$$\n\nThe task is to recover the hidden bit string $s$.\n\n**Examples**\n\n- $f(x) \\equiv 0$ is an example of such a function with $s = 0, \\dots, 0$.\n- $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$.\n\nIf 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.\n\nWhat 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.\n\n### Apply Hadamard transform to each qubit: a different view\n\nWhen you apply an $H$ gate to a single qubit in the basis state $\\ket{x}$, you can write the result as the following sum:\n\n$$H\\ket{x} = \\frac1{\\sqrt2} (\\ket{0} + (-1)^{x} \\ket{1}) = \\frac1{\\sqrt2} \\sum_{z \\in {0, 1}} (-1)^{x \\cdot z} \\ket{z}$$\n\nIf 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:\n\n$$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}} =$$\n\n$$= \\frac1{\\sqrt{2^N}} \\sum_{z = 0}^{2^N-1} (-1)^{x \\cdot z} \\ket{z}$$\n\nWith this in mind, let's revisit the algorithm and see how you can write the exact quantum state after it.\n\n### Bernstein-Vazirani algorithm\n\nBernstein-Vazirani algorithm follows the same outline as Deutsch-Jozsa algorithm:\n\n1. Apply the $H$ gate to each qubit.\n2. Apply the oracle.\n3. Apply the $H$ gate to each qubit again.\n4. Measure all qubits.\n\nYou know that after the second step the qubits end up in the following state:\n\n$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x)} \\ket{x}$$\n\nNow, once you apply the Hadamard gates to each qubit, the system state becomes:\n\n$$\\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}$$\n\n> 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)}$.\n\nNow, 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 \n\n$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x) + x \\cdot s}$$\n\nSince $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 \n\n$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} 1 = \\frac{1}{\\sqrt{2^N}} 2^N = 1$$\n\nThis 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."
6876
+ "content": "\nTo wrap up the 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 *scalar product function*, that is, there exists an $N$-bit string $s$\nthat allows the following representation ($\\cdot$ is bitwise inner product of integers modulo $2$):\n\n$$f(x) = x \\cdot s = \\sum_{k=0}^{N-1} x_k s_k \\bmod 2$$\n\nThe task is to recover the hidden bit string $s$.\n\n**Examples**\n\n- $f(x) \\equiv 0$ is an example of such a function with $s = 0, \\dots, 0$.\n- $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$.\n\nIf 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.\n\nWhat 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.\n\n### Apply Hadamard transform to each qubit: a different view\n\nWhen you apply an $H$ gate to a single qubit in the basis state $\\ket{x}$, you can write the result as the following sum:\n\n$$H\\ket{x} = \\frac1{\\sqrt2} (\\ket{0} + (-1)^{x} \\ket{1}) = \\frac1{\\sqrt2} \\sum_{z \\in \\{0, 1\\}} (-1)^{x \\cdot z} \\ket{z}$$\n\nIf 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:\n\n$$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}} =$$\n\n$$= \\frac1{\\sqrt{2^N}} \\sum_{z = 0}^{2^N-1} (-1)^{x \\cdot z} \\ket{z}$$\n\nWith this in mind, let's revisit the algorithm and see how you can write the exact quantum state after it.\n\n### Bernstein-Vazirani algorithm\n\nBernstein-Vazirani algorithm follows the same outline as Deutsch-Jozsa algorithm:\n\n1. Apply the $H$ gate to each qubit.\n2. Apply the oracle.\n3. Apply the $H$ gate to each qubit again.\n4. Measure all qubits.\n\nYou know that after the second step the qubits end up in the following state:\n\n$$\\frac{1}{\\sqrt{2^N}} \\sum_{x=0}^{2^N-1} (-1)^{f(x)} \\ket{x}$$\n\nNow, once you apply the Hadamard gates to each qubit, the system state becomes:\n\n$$\\frac{1}{2^N} \\sum_{x=0}^{2^N-1} \\sum_{z=0}^{2^N-1} (-1)^{f(x) + x \\cdot z} \\ket{z}$$\n\n> In Deutsch-Jozsa algorithm, you looked at the amplitude of the $\\ket{0}$ state in this expression, which was \n> $\\frac{1}{2^N} \\sum_{x=0}^{2^N-1} (-1)^{f(x)}$.\n\nNow, 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 \n\n$$\\frac{1}{2^N} \\sum_{x=0}^{2^N-1} (-1)^{f(x) + x \\cdot s}$$\n\nSince $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 \n\n$$\\frac{1}{2^N} \\sum_{x=0}^{2^N-1} 1 = \\frac{1}{2^N} 2^N = 1$$\n\nThis 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."
6877
6877
  }
6878
6878
  ]
6879
6879
  },
package/dist/main.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ICompiler, ICompilerWorker } from "./compiler/compiler.js";
2
2
  import { IDebugService, IDebugServiceWorker } from "./debug-service/debug-service.js";
3
3
  import { ILanguageService, ILanguageServiceWorker, qsharpLibraryUriScheme } from "./language-service/language-service.js";
4
- import type { ProjectLoader } from "../lib/web/qsc_wasm.js";
5
- import { IProjectHost } from "./browser.js";
4
+ import { ProjectLoader } from "./project.js";
5
+ import type { IProjectHost } from "./browser.js";
6
6
  export { qsharpLibraryUriScheme };
7
7
  export declare function getLibrarySourceContent(path: string): Promise<string | undefined>;
8
8
  export declare function getCompiler(): ICompiler;
package/dist/main.js CHANGED
@@ -8,6 +8,7 @@ import { QSharpDebugService, debugServiceProtocol, } from "./debug-service/debug
8
8
  import { QSharpLanguageService, languageServiceProtocol, qsharpLibraryUriScheme, } from "./language-service/language-service.js";
9
9
  import { log } from "./log.js";
10
10
  import { createProxy } from "./workers/node.js";
11
+ import { ProjectLoader } from "./project.js";
11
12
  export { qsharpLibraryUriScheme };
12
13
  let wasm = null;
13
14
  function ensureWasm() {
@@ -29,7 +30,7 @@ export function getCompiler() {
29
30
  }
30
31
  export function getProjectLoader(host) {
31
32
  ensureWasm();
32
- return new wasm.ProjectLoader(host);
33
+ return new ProjectLoader(wasm, host);
33
34
  }
34
35
  export function getCompilerWorker() {
35
36
  return createProxy("../compiler/worker-node.js", compilerProtocol);
@@ -0,0 +1,10 @@
1
+ import * as wasm from "../lib/web/qsc_wasm.js";
2
+ type QscWasm = typeof import("../lib/web/qsc_wasm.js");
3
+ export declare class ProjectLoader {
4
+ private nativeLoader;
5
+ constructor(wasm: QscWasm, host: wasm.IProjectHost);
6
+ dispose(): void;
7
+ loadQSharpProject(directory: string): Promise<wasm.IProjectConfig>;
8
+ loadOpenQasmProject(document: string): Promise<wasm.IProjectConfig>;
9
+ }
10
+ export {};
@@ -0,0 +1,17 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { callAndTransformExceptions } from "./diagnostics.js";
4
+ export class ProjectLoader {
5
+ constructor(wasm, host) {
6
+ this.nativeLoader = new wasm.ProjectLoader(host);
7
+ }
8
+ dispose() {
9
+ this.nativeLoader.free();
10
+ }
11
+ loadQSharpProject(directory) {
12
+ return callAndTransformExceptions(() => this.nativeLoader.load_project_with_deps(directory));
13
+ }
14
+ loadOpenQasmProject(document) {
15
+ return callAndTransformExceptions(() => this.nativeLoader.load_openqasm_project(document));
16
+ }
17
+ }
@@ -62,11 +62,6 @@ export default [
62
62
  {
63
63
  "title": "Random Number Generator",
64
64
  "shots": 1000,
65
- "code": "/// # Sample\n/// Quantum Random Number Generator\n///\n/// # Description\n/// This program implements a quantum random number generator by setting qubits\n/// in superposition and then using the measurement results as random bits.\nimport Std.Measurement.*;\nimport Std.Intrinsic.*;\n\noperation Main() : Result[] {\n // Generate 5-bit random number.\n let nBits = 5;\n return GenerateNRandomBits(nBits);\n}\n\n/// # Summary\n/// Generates N random bits.\noperation GenerateNRandomBits(nBits : Int) : Result[] {\n // Allocate N qubits.\n use register = Qubit[nBits];\n\n // Set the qubits into superposition of 0 and 1 using the Hadamard\n // operation `H`.\n for qubit in register {\n H(qubit);\n }\n\n // At this point each has 50% chance of being measured in the |0〉 state\n // and 50% chance of being measured in the |1〉 state.\n // Measure each qubit and reset them all so they can be safely\n // deallocated.\n let results = MResetEachZ(register);\n return results;\n}\n"
66
- },
67
- {
68
- "title": "Random Number Generator (Advanced)",
69
- "shots": 1000,
70
65
  "code": "/// # Sample\n/// Quantum Random Number Generator\n///\n/// # Description\n/// This program implements a quantum random number generator by setting qubits\n/// in superposition and then using the measurement results as random bits.\nimport Std.Convert.*;\nimport Std.Intrinsic.*;\nimport Std.Math.*;\n\noperation Main() : Int {\n let max = 100;\n Message($\"Sampling a random number between 0 and {max}:\");\n\n // Generate random number in the 0..max range.\n return GenerateRandomNumberInRange(max);\n}\n\n/// # Summary\n/// Generates a random number between 0 and `max`.\noperation GenerateRandomNumberInRange(max : Int) : Int {\n // Determine the number of bits needed to represent `max` and store it\n // in the `nBits` variable. Then generate `nBits` random bits which will\n // represent the generated random number.\n mutable bits = [];\n let nBits = BitSizeI(max);\n for idxBit in 1..nBits {\n bits += [GenerateRandomBit()];\n }\n let sample = ResultArrayAsInt(bits);\n\n // Return random number if it is within the requested range.\n // Generate it again if it is outside the range.\n return sample > max ? GenerateRandomNumberInRange(max) | sample;\n}\n\n/// # Summary\n/// Generates a random bit.\noperation GenerateRandomBit() : Result {\n // Allocate a qubit.\n use q = Qubit();\n\n // Set the qubit into superposition of 0 and 1 using the Hadamard\n // operation `H`.\n H(q);\n\n // At this point the qubit `q` has 50% chance of being measured in the\n // |0〉 state and 50% chance of being measured in the |1〉 state.\n // Measure the qubit value using the `M` operation, and store the\n // measurement value in the `result` variable.\n let result = M(q);\n\n // Reset qubit to the |0〉 state.\n // Qubits must be in the |0〉 state by the time they are released.\n Reset(q);\n\n // Return the result of the measurement.\n return result;\n\n // Note that Qubit `q` is automatically released at the end of the block.\n}\n"
71
66
  },
72
67
  {
@@ -92,7 +87,7 @@ export default [
92
87
  {
93
88
  "title": "Grover's Search",
94
89
  "shots": 100,
95
- "code": "/// # Sample\n/// Grover's Search Algorithm\n///\n/// # Description\n/// Grover's search algorithm is a quantum algorithm that finds with high\n/// probability the unique input to a black box function that produces a\n/// particular output value.\n///\n/// This Q# program implements the Grover's search algorithm.\nimport Std.Convert.*;\nimport Std.Math.*;\nimport Std.Arrays.*;\nimport Std.Measurement.*;\nimport Std.Diagnostics.*;\n\noperation Main() : Result[] {\n let nQubits = 5;\n\n // Grover's algorithm relies on performing a \"Grover iteration\" an\n // optimal number of times to maximize the probability of finding the\n // value we are searching for.\n // You can set the number iterations to a value lower than optimal to\n // intentionally reduce precision.\n let iterations = CalculateOptimalIterations(nQubits);\n Message($\"Number of iterations: {iterations}\");\n\n // Use Grover's algorithm to find a particular marked state.\n let results = GroverSearch(nQubits, iterations, ReflectAboutMarked);\n return results;\n}\n\n/// # Summary\n/// Implements Grover's algorithm, which searches all possible inputs to an\n/// operation to find a particular marked state.\noperation GroverSearch(\n nQubits : Int,\n iterations : Int,\n phaseOracle : Qubit[] => Unit\n) : Result[] {\n\n use qubits = Qubit[nQubits];\n\n // Initialize a uniform superposition over all possible inputs.\n PrepareUniform(qubits);\n\n // The search itself consists of repeatedly reflecting about the marked\n // state and our start state, which we can write out in Q# as a for loop.\n for _ in 1..iterations {\n phaseOracle(qubits);\n ReflectAboutUniform(qubits);\n }\n\n // Measure and return the answer.\n return MResetEachZ(qubits);\n}\n\n/// # Summary\n/// Returns the optimal number of Grover iterations needed to find a marked\n/// item, given the number of qubits in a register.\nfunction CalculateOptimalIterations(nQubits : Int) : Int {\n if nQubits > 126 {\n fail \"This sample supports at most 126 qubits.\";\n }\n\n let nItems = 2.0^IntAsDouble(nQubits);\n let angle = ArcSin(1. / Sqrt(nItems));\n let iterations = Round(0.25 * PI() / angle - 0.5);\n iterations\n}\n\n/// # Summary\n/// Reflects about the basis state marked by alternating zeros and ones.\n/// This operation defines what input we are trying to find in the search.\noperation ReflectAboutMarked(inputQubits : Qubit[]) : Unit {\n Message(\"Reflecting about marked state...\");\n use outputQubit = Qubit();\n within {\n // We initialize the outputQubit to (|0⟩ - |1⟩) / √2, so that\n // toggling it results in a (-1) phase.\n X(outputQubit);\n H(outputQubit);\n // Flip the outputQubit for marked states.\n // Here, we get the state with alternating 0s and 1s by using the X\n // operation on every other qubit.\n for q in inputQubits[...2...] {\n X(q);\n }\n } apply {\n Controlled X(inputQubits, outputQubit);\n }\n}\n\n/// # Summary\n/// Given a register in the all-zeros state, prepares a uniform\n/// superposition over all basis states.\noperation PrepareUniform(inputQubits : Qubit[]) : Unit is Adj + Ctl {\n for q in inputQubits {\n H(q);\n }\n}\n\n/// # Summary\n/// Reflects about the all-ones state.\noperation ReflectAboutAllOnes(inputQubits : Qubit[]) : Unit {\n Controlled Z(Most(inputQubits), Tail(inputQubits));\n}\n\n/// # Summary\n/// Reflects about the uniform superposition state.\noperation ReflectAboutUniform(inputQubits : Qubit[]) : Unit {\n within {\n // Transform the uniform superposition to all-zero.\n Adjoint PrepareUniform(inputQubits);\n // Transform the all-zero state to all-ones\n for q in inputQubits {\n X(q);\n }\n } apply {\n // Now that we've transformed the uniform superposition to the\n // all-ones state, reflect about the all-ones state, then let the\n // within/apply block transform us back.\n ReflectAboutAllOnes(inputQubits);\n }\n}\n"
90
+ "code": "/// # Sample\n/// Grover's Search Algorithm\n///\n/// # Description\n/// Grover's search algorithm is a quantum algorithm that finds with high\n/// probability the unique input to a black box function that produces a\n/// particular output value.\n///\n/// This Q# program implements the Grover's search algorithm and applies it\n/// to a specific problem: finding a marked state in a register of qubits.\n/// The marked state selected for this sample is |01010⟩.\n\nimport Std.Convert.*;\nimport Std.Math.*;\nimport Std.Arrays.*;\nimport Std.Measurement.*;\nimport Std.Diagnostics.*;\n\noperation Main() : Result[] {\n let nQubits = 5;\n\n // Grover's algorithm relies on performing a \"Grover iteration\" an\n // optimal number of times to maximize the probability of finding the\n // value we are searching for.\n // You can intentionally set the number iterations to a value lower\n // than optimal. In this case, the algorithm will find the marked state\n // with lower probability.\n let nIterations = IterationsToMarked(nQubits);\n Message($\"Number of iterations: {nIterations}\");\n\n // Use Grover's algorithm to find a particular marked state. The marked state\n // we are looking for in this sample is |01010⟩, which is represented\n // by the operation ReflectAboutMarked.\n let results = GroverSearch(nQubits, nIterations, ReflectAboutMarked);\n\n // Expected result is [Zero, One, Zero, One, Zero] with very high probability.\n return results;\n}\n\n/// # Summary\n/// Implements Grover's algorithm, which searches all possible inputs to an\n/// operation to find a particular marked state.\noperation GroverSearch(\n nQubits : Int,\n iterations : Int,\n phaseOracle : Qubit[] => Unit\n) : Result[] {\n\n use qubits = Qubit[nQubits];\n\n // Initialize a uniform superposition over all possible inputs.\n PrepareUniform(qubits);\n\n // The search itself consists of repeatedly reflecting about the marked\n // state and our start state, which we can write out in Q# as a for loop.\n for _ in 1..iterations {\n phaseOracle(qubits);\n ReflectAboutUniform(qubits);\n }\n\n // Measure and return the answer.\n return MResetEachZ(qubits);\n}\n\n/// # Summary\n/// Returns the optimal number of Grover iterations needed to find a marked\n/// item, given the number of qubits in a register. Setting the number of\n/// iterations to a different number may undershoot or overshoot the marked state.\nfunction IterationsToMarked(nQubits : Int) : Int {\n if nQubits > 126 {\n fail \"This sample supports at most 126 qubits.\";\n }\n\n let nItems = 2.0^IntAsDouble(nQubits);\n let angle = ArcSin(1. / Sqrt(nItems));\n let iterations = Round(0.25 * PI() / angle - 0.5);\n iterations\n}\n\n/// # Summary\n/// Reflects about the basis state marked by alternating zeros and ones.\n/// This operation defines what input we are trying to find in the search.\noperation ReflectAboutMarked(inputQubits : Qubit[]) : Unit {\n Message(\"Reflecting about marked state...\");\n use outputQubit = Qubit();\n within {\n // We initialize the outputQubit to (|0⟩ - |1⟩) / √2, so that\n // toggling it results in a (-1) phase.\n X(outputQubit);\n H(outputQubit);\n // Flip the outputQubit for marked states.\n // Here, we get the state with alternating 0s and 1s by using the X\n // operation on every other qubit.\n for q in inputQubits[...2...] {\n X(q);\n }\n } apply {\n Controlled X(inputQubits, outputQubit);\n }\n}\n\n/// # Summary\n/// Given a register in the all-zeros state, prepares a uniform\n/// superposition over all basis states.\noperation PrepareUniform(inputQubits : Qubit[]) : Unit is Adj + Ctl {\n for q in inputQubits {\n H(q);\n }\n}\n\n/// # Summary\n/// Reflects about the all-ones state.\noperation ReflectAboutAllOnes(inputQubits : Qubit[]) : Unit {\n Controlled Z(Most(inputQubits), Tail(inputQubits));\n}\n\n/// # Summary\n/// Reflects about the uniform superposition state.\noperation ReflectAboutUniform(inputQubits : Qubit[]) : Unit {\n within {\n // Transform the uniform superposition to all-zero.\n Adjoint PrepareUniform(inputQubits);\n // Transform the all-zero state to all-ones\n for q in inputQubits {\n X(q);\n }\n } apply {\n // Now that we've transformed the uniform superposition to the\n // all-ones state, reflect about the all-ones state, then let the\n // within/apply block transform us back.\n ReflectAboutAllOnes(inputQubits);\n }\n}\n"
96
91
  },
97
92
  {
98
93
  "title": "Hidden Shift",
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Operation } from "./shared/circuit.js";
2
- import { Register } from "./shared/register.js";
1
+ import { Operation } from "./data-structures/circuit.js";
2
+ import { Register } from "./data-structures/register.js";
3
3
  export type Tick = {
4
4
  value: number;
5
5
  label: string;
@@ -30,12 +30,4 @@ export declare function getRanges(data: SeriesOfPoints, rangeCoefficient: number
30
30
  * @returns An array of Register objects involved in the operation.
31
31
  */
32
32
  export declare function getOperationRegisters(operation: Operation): Register[];
33
- /**
34
- * Get the minimum and maximum register indices for a given operation.
35
- *
36
- * @param operation The operation for which to get the register indices.
37
- * @param numQubits The number of qubits in the circuit.
38
- * @returns A tuple containing the minimum and maximum register indices.
39
- */
40
- export declare function getMinMaxRegIdx(operation: Operation, numQubits: number): [number, number];
41
33
  export {};
package/dist/utils.js CHANGED
@@ -162,42 +162,3 @@ export function getOperationRegisters(operation) {
162
162
  return [...operation.qubits, ...(operation.results || [])];
163
163
  }
164
164
  }
165
- /**
166
- * Get the minimum and maximum register indices for a given operation.
167
- *
168
- * @param operation The operation for which to get the register indices.
169
- * @param numQubits The number of qubits in the circuit.
170
- * @returns A tuple containing the minimum and maximum register indices.
171
- */
172
- export function getMinMaxRegIdx(operation, numQubits) {
173
- let targets;
174
- let controls;
175
- switch (operation.kind) {
176
- case "measurement":
177
- targets = operation.results;
178
- controls = operation.qubits;
179
- break;
180
- case "unitary":
181
- targets = operation.targets;
182
- controls = operation.controls || [];
183
- break;
184
- case "ket":
185
- targets = operation.targets;
186
- controls = [];
187
- break;
188
- }
189
- const qRegs = [...controls, ...targets]
190
- .filter(({ result }) => result === undefined)
191
- .map(({ qubit }) => qubit);
192
- const clsControls = controls.filter(({ result }) => result !== undefined);
193
- const isClassicallyControlled = clsControls.length > 0;
194
- if (!isClassicallyControlled && qRegs.length === 0)
195
- return [-1, -1];
196
- // If operation is classically-controlled, pad all qubit registers. Otherwise, only pad
197
- // the contiguous range of registers that it covers.
198
- const minRegIdx = isClassicallyControlled ? 0 : Math.min(...qRegs);
199
- const maxRegIdx = isClassicallyControlled
200
- ? numQubits - 1
201
- : Math.max(...qRegs);
202
- return [minRegIdx, maxRegIdx];
203
- }