qsharp-lang 1.4.0 → 1.4.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 (279) hide show
  1. package/dist/compiler/common.d.ts +1 -1
  2. package/dist/compiler/compiler.d.ts +6 -6
  3. package/dist/compiler/compiler.js +10 -6
  4. package/dist/compiler/events.d.ts +1 -1
  5. package/dist/katas-content.generated.js +2337 -788
  6. package/dist/samples.generated.js +7 -7
  7. package/docs/Microsoft.Quantum.Arrays/All.md +1 -1
  8. package/docs/Microsoft.Quantum.Arrays/Any.md +1 -1
  9. package/docs/Microsoft.Quantum.Arrays/Chunks.md +1 -1
  10. package/docs/Microsoft.Quantum.Arrays/CircularlyShifted.md +1 -1
  11. package/docs/Microsoft.Quantum.Arrays/ColumnAt.md +1 -1
  12. package/docs/Microsoft.Quantum.Arrays/Count.md +1 -1
  13. package/docs/Microsoft.Quantum.Arrays/Diagonal.md +1 -1
  14. package/docs/Microsoft.Quantum.Arrays/DrawMany.md +1 -1
  15. package/docs/Microsoft.Quantum.Arrays/Enumerated.md +1 -1
  16. package/docs/Microsoft.Quantum.Arrays/Excluding.md +1 -1
  17. package/docs/Microsoft.Quantum.Arrays/Filtered.md +1 -1
  18. package/docs/Microsoft.Quantum.Arrays/FlatMapped.md +1 -1
  19. package/docs/Microsoft.Quantum.Arrays/Flattened.md +1 -1
  20. package/docs/Microsoft.Quantum.Arrays/Fold.md +1 -1
  21. package/docs/Microsoft.Quantum.Arrays/ForEach.md +1 -1
  22. package/docs/Microsoft.Quantum.Arrays/Head.md +1 -1
  23. package/docs/Microsoft.Quantum.Arrays/HeadAndRest.md +1 -1
  24. package/docs/Microsoft.Quantum.Arrays/IndexOf.md +1 -1
  25. package/docs/Microsoft.Quantum.Arrays/IndexRange.md +1 -1
  26. package/docs/Microsoft.Quantum.Arrays/Interleaved.md +1 -1
  27. package/docs/Microsoft.Quantum.Arrays/IsEmpty.md +1 -1
  28. package/docs/Microsoft.Quantum.Arrays/IsRectangularArray.md +1 -1
  29. package/docs/Microsoft.Quantum.Arrays/IsSorted.md +1 -1
  30. package/docs/Microsoft.Quantum.Arrays/IsSquareArray.md +1 -1
  31. package/docs/Microsoft.Quantum.Arrays/Mapped.md +1 -1
  32. package/docs/Microsoft.Quantum.Arrays/MappedByIndex.md +1 -1
  33. package/docs/Microsoft.Quantum.Arrays/MappedOverRange.md +1 -1
  34. package/docs/Microsoft.Quantum.Arrays/Most.md +1 -1
  35. package/docs/Microsoft.Quantum.Arrays/MostAndTail.md +1 -1
  36. package/docs/Microsoft.Quantum.Arrays/Padded.md +1 -1
  37. package/docs/Microsoft.Quantum.Arrays/Partitioned.md +1 -1
  38. package/docs/Microsoft.Quantum.Arrays/Rest.md +1 -1
  39. package/docs/Microsoft.Quantum.Arrays/Reversed.md +1 -1
  40. package/docs/Microsoft.Quantum.Arrays/SequenceI.md +1 -1
  41. package/docs/Microsoft.Quantum.Arrays/SequenceL.md +1 -1
  42. package/docs/Microsoft.Quantum.Arrays/Sorted.md +1 -1
  43. package/docs/Microsoft.Quantum.Arrays/Subarray.md +1 -1
  44. package/docs/Microsoft.Quantum.Arrays/Swapped.md +1 -1
  45. package/docs/Microsoft.Quantum.Arrays/Tail.md +1 -1
  46. package/docs/Microsoft.Quantum.Arrays/Transposed.md +1 -1
  47. package/docs/Microsoft.Quantum.Arrays/Unzipped.md +1 -1
  48. package/docs/Microsoft.Quantum.Arrays/Where.md +1 -1
  49. package/docs/Microsoft.Quantum.Arrays/Windows.md +1 -1
  50. package/docs/Microsoft.Quantum.Arrays/Zipped.md +1 -1
  51. package/docs/Microsoft.Quantum.Canon/ApplyCNOTChain.md +1 -1
  52. package/docs/Microsoft.Quantum.Canon/ApplyControlledOnBitString.md +1 -1
  53. package/docs/Microsoft.Quantum.Canon/ApplyControlledOnInt.md +1 -1
  54. package/docs/Microsoft.Quantum.Canon/ApplyP.md +1 -1
  55. package/docs/Microsoft.Quantum.Canon/ApplyPauli.md +1 -1
  56. package/docs/Microsoft.Quantum.Canon/ApplyPauliFromBitString.md +1 -1
  57. package/docs/Microsoft.Quantum.Canon/ApplyPauliFromInt.md +1 -1
  58. package/docs/Microsoft.Quantum.Canon/ApplyQFT.md +1 -1
  59. package/docs/Microsoft.Quantum.Canon/ApplyToEach.md +1 -1
  60. package/docs/Microsoft.Quantum.Canon/ApplyToEachA.md +1 -1
  61. package/docs/Microsoft.Quantum.Canon/ApplyToEachC.md +1 -1
  62. package/docs/Microsoft.Quantum.Canon/ApplyToEachCA.md +1 -1
  63. package/docs/Microsoft.Quantum.Canon/ApplyXorInPlace.md +1 -1
  64. package/docs/Microsoft.Quantum.Canon/ApplyXorInPlaceL.md +1 -1
  65. package/docs/Microsoft.Quantum.Canon/CX.md +1 -1
  66. package/docs/Microsoft.Quantum.Canon/CY.md +1 -1
  67. package/docs/Microsoft.Quantum.Canon/CZ.md +1 -1
  68. package/docs/Microsoft.Quantum.Canon/Fst.md +1 -1
  69. package/docs/Microsoft.Quantum.Canon/Snd.md +1 -1
  70. package/docs/Microsoft.Quantum.Canon/SwapReverseRegister.md +1 -1
  71. package/docs/Microsoft.Quantum.Convert/BigIntAsBoolArray.md +1 -1
  72. package/docs/Microsoft.Quantum.Convert/BoolArrayAsBigInt.md +1 -1
  73. package/docs/Microsoft.Quantum.Convert/BoolArrayAsInt.md +1 -1
  74. package/docs/Microsoft.Quantum.Convert/ComplexAsComplexPolar.md +1 -1
  75. package/docs/Microsoft.Quantum.Convert/ComplexPolarAsComplex.md +1 -1
  76. package/docs/Microsoft.Quantum.Convert/IntAsBigInt.md +1 -1
  77. package/docs/Microsoft.Quantum.Convert/IntAsBoolArray.md +1 -1
  78. package/docs/Microsoft.Quantum.Convert/IntAsDouble.md +1 -1
  79. package/docs/Microsoft.Quantum.Core/IsRangeEmpty.md +1 -1
  80. package/docs/Microsoft.Quantum.Core/Length.md +1 -1
  81. package/docs/Microsoft.Quantum.Core/RangeEnd.md +1 -1
  82. package/docs/Microsoft.Quantum.Core/RangeReverse.md +1 -1
  83. package/docs/Microsoft.Quantum.Core/RangeStart.md +1 -1
  84. package/docs/Microsoft.Quantum.Core/RangeStep.md +1 -1
  85. package/docs/Microsoft.Quantum.Core/Repeated.md +1 -1
  86. package/docs/Microsoft.Quantum.Diagnostics/DumpMachine.md +1 -1
  87. package/docs/Microsoft.Quantum.Diagnostics/DumpRegister.md +1 -1
  88. package/docs/Microsoft.Quantum.Diagnostics/Fact.md +1 -1
  89. package/docs/Microsoft.Quantum.Intrinsic/CCNOT.md +1 -1
  90. package/docs/Microsoft.Quantum.Intrinsic/CNOT.md +1 -1
  91. package/docs/Microsoft.Quantum.Intrinsic/Exp.md +1 -1
  92. package/docs/Microsoft.Quantum.Intrinsic/H.md +1 -1
  93. package/docs/Microsoft.Quantum.Intrinsic/I.md +1 -1
  94. package/docs/Microsoft.Quantum.Intrinsic/M.md +1 -1
  95. package/docs/Microsoft.Quantum.Intrinsic/Measure.md +1 -1
  96. package/docs/Microsoft.Quantum.Intrinsic/Message.md +1 -1
  97. package/docs/Microsoft.Quantum.Intrinsic/R.md +1 -1
  98. package/docs/Microsoft.Quantum.Intrinsic/R1.md +1 -1
  99. package/docs/Microsoft.Quantum.Intrinsic/R1Frac.md +1 -1
  100. package/docs/Microsoft.Quantum.Intrinsic/RFrac.md +1 -1
  101. package/docs/Microsoft.Quantum.Intrinsic/Reset.md +1 -1
  102. package/docs/Microsoft.Quantum.Intrinsic/ResetAll.md +1 -1
  103. package/docs/Microsoft.Quantum.Intrinsic/Rx.md +1 -1
  104. package/docs/Microsoft.Quantum.Intrinsic/Rxx.md +1 -1
  105. package/docs/Microsoft.Quantum.Intrinsic/Ry.md +1 -1
  106. package/docs/Microsoft.Quantum.Intrinsic/Ryy.md +1 -1
  107. package/docs/Microsoft.Quantum.Intrinsic/Rz.md +1 -1
  108. package/docs/Microsoft.Quantum.Intrinsic/Rzz.md +1 -1
  109. package/docs/Microsoft.Quantum.Intrinsic/S.md +1 -1
  110. package/docs/Microsoft.Quantum.Intrinsic/SWAP.md +1 -1
  111. package/docs/Microsoft.Quantum.Intrinsic/T.md +1 -1
  112. package/docs/Microsoft.Quantum.Intrinsic/X.md +1 -1
  113. package/docs/Microsoft.Quantum.Intrinsic/Y.md +1 -1
  114. package/docs/Microsoft.Quantum.Intrinsic/Z.md +1 -1
  115. package/docs/Microsoft.Quantum.Logical/Xor.md +1 -1
  116. package/docs/Microsoft.Quantum.Math/AbsComplex.md +1 -1
  117. package/docs/Microsoft.Quantum.Math/AbsComplexPolar.md +1 -1
  118. package/docs/Microsoft.Quantum.Math/AbsD.md +1 -1
  119. package/docs/Microsoft.Quantum.Math/AbsI.md +1 -1
  120. package/docs/Microsoft.Quantum.Math/AbsL.md +1 -1
  121. package/docs/Microsoft.Quantum.Math/AbsSquaredComplex.md +1 -1
  122. package/docs/Microsoft.Quantum.Math/AbsSquaredComplexPolar.md +1 -1
  123. package/docs/Microsoft.Quantum.Math/ApproximateFactorial.md +1 -1
  124. package/docs/Microsoft.Quantum.Math/ArcCos.md +1 -1
  125. package/docs/Microsoft.Quantum.Math/ArcCosh.md +1 -1
  126. package/docs/Microsoft.Quantum.Math/ArcSin.md +1 -1
  127. package/docs/Microsoft.Quantum.Math/ArcSinh.md +1 -1
  128. package/docs/Microsoft.Quantum.Math/ArcTan.md +1 -1
  129. package/docs/Microsoft.Quantum.Math/ArcTan2.md +1 -1
  130. package/docs/Microsoft.Quantum.Math/ArcTanh.md +1 -1
  131. package/docs/Microsoft.Quantum.Math/ArgComplex.md +1 -1
  132. package/docs/Microsoft.Quantum.Math/ArgComplexPolar.md +1 -1
  133. package/docs/Microsoft.Quantum.Math/Binom.md +1 -1
  134. package/docs/Microsoft.Quantum.Math/BitSizeI.md +1 -1
  135. package/docs/Microsoft.Quantum.Math/BitSizeL.md +1 -1
  136. package/docs/Microsoft.Quantum.Math/Ceiling.md +1 -1
  137. package/docs/Microsoft.Quantum.Math/Complex.md +1 -1
  138. package/docs/Microsoft.Quantum.Math/ComplexPolar.md +1 -1
  139. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentI.md +1 -1
  140. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentL.md +1 -1
  141. package/docs/Microsoft.Quantum.Math/Cos.md +1 -1
  142. package/docs/Microsoft.Quantum.Math/Cosh.md +1 -1
  143. package/docs/Microsoft.Quantum.Math/DivRemI.md +1 -1
  144. package/docs/Microsoft.Quantum.Math/DivRemL.md +1 -1
  145. package/docs/Microsoft.Quantum.Math/DividedByC.md +1 -1
  146. package/docs/Microsoft.Quantum.Math/DividedByCP.md +1 -1
  147. package/docs/Microsoft.Quantum.Math/E.md +1 -1
  148. package/docs/Microsoft.Quantum.Math/ExpModI.md +1 -1
  149. package/docs/Microsoft.Quantum.Math/ExpModL.md +1 -1
  150. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorI.md +1 -1
  151. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorL.md +1 -1
  152. package/docs/Microsoft.Quantum.Math/FactorialI.md +1 -1
  153. package/docs/Microsoft.Quantum.Math/FactorialL.md +1 -1
  154. package/docs/Microsoft.Quantum.Math/Floor.md +1 -1
  155. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorI.md +1 -1
  156. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorL.md +1 -1
  157. package/docs/Microsoft.Quantum.Math/HammingWeightI.md +1 -1
  158. package/docs/Microsoft.Quantum.Math/InverseModI.md +1 -1
  159. package/docs/Microsoft.Quantum.Math/InverseModL.md +1 -1
  160. package/docs/Microsoft.Quantum.Math/IsCoprimeI.md +1 -1
  161. package/docs/Microsoft.Quantum.Math/IsCoprimeL.md +1 -1
  162. package/docs/Microsoft.Quantum.Math/IsInfinite.md +1 -1
  163. package/docs/Microsoft.Quantum.Math/IsNaN.md +1 -1
  164. package/docs/Microsoft.Quantum.Math/LargestFixedPoint.md +1 -1
  165. package/docs/Microsoft.Quantum.Math/Lg.md +1 -1
  166. package/docs/Microsoft.Quantum.Math/Log.md +1 -1
  167. package/docs/Microsoft.Quantum.Math/Log10.md +1 -1
  168. package/docs/Microsoft.Quantum.Math/LogFactorialD.md +1 -1
  169. package/docs/Microsoft.Quantum.Math/LogGammaD.md +1 -1
  170. package/docs/Microsoft.Quantum.Math/LogOf2.md +1 -1
  171. package/docs/Microsoft.Quantum.Math/Max.md +1 -1
  172. package/docs/Microsoft.Quantum.Math/MaxD.md +1 -1
  173. package/docs/Microsoft.Quantum.Math/MaxI.md +1 -1
  174. package/docs/Microsoft.Quantum.Math/MaxL.md +1 -1
  175. package/docs/Microsoft.Quantum.Math/Min.md +1 -1
  176. package/docs/Microsoft.Quantum.Math/MinD.md +1 -1
  177. package/docs/Microsoft.Quantum.Math/MinI.md +1 -1
  178. package/docs/Microsoft.Quantum.Math/MinL.md +1 -1
  179. package/docs/Microsoft.Quantum.Math/MinusC.md +1 -1
  180. package/docs/Microsoft.Quantum.Math/MinusCP.md +1 -1
  181. package/docs/Microsoft.Quantum.Math/ModulusI.md +1 -1
  182. package/docs/Microsoft.Quantum.Math/ModulusL.md +1 -1
  183. package/docs/Microsoft.Quantum.Math/NegationC.md +1 -1
  184. package/docs/Microsoft.Quantum.Math/NegationCP.md +1 -1
  185. package/docs/Microsoft.Quantum.Math/PI.md +1 -1
  186. package/docs/Microsoft.Quantum.Math/PNorm.md +1 -1
  187. package/docs/Microsoft.Quantum.Math/PNormalized.md +1 -1
  188. package/docs/Microsoft.Quantum.Math/PlusC.md +1 -1
  189. package/docs/Microsoft.Quantum.Math/PlusCP.md +1 -1
  190. package/docs/Microsoft.Quantum.Math/PowC.md +1 -1
  191. package/docs/Microsoft.Quantum.Math/PowCP.md +1 -1
  192. package/docs/Microsoft.Quantum.Math/RealMod.md +1 -1
  193. package/docs/Microsoft.Quantum.Math/Round.md +1 -1
  194. package/docs/Microsoft.Quantum.Math/SignD.md +1 -1
  195. package/docs/Microsoft.Quantum.Math/SignI.md +1 -1
  196. package/docs/Microsoft.Quantum.Math/SignL.md +1 -1
  197. package/docs/Microsoft.Quantum.Math/Sin.md +1 -1
  198. package/docs/Microsoft.Quantum.Math/Sinh.md +1 -1
  199. package/docs/Microsoft.Quantum.Math/SmallestFixedPoint.md +1 -1
  200. package/docs/Microsoft.Quantum.Math/Sqrt.md +1 -1
  201. package/docs/Microsoft.Quantum.Math/SquaredNorm.md +1 -1
  202. package/docs/Microsoft.Quantum.Math/Tan.md +1 -1
  203. package/docs/Microsoft.Quantum.Math/Tanh.md +1 -1
  204. package/docs/Microsoft.Quantum.Math/TimesC.md +1 -1
  205. package/docs/Microsoft.Quantum.Math/TimesCP.md +1 -1
  206. package/docs/Microsoft.Quantum.Math/TrailingZeroCountI.md +1 -1
  207. package/docs/Microsoft.Quantum.Math/TrailingZeroCountL.md +1 -1
  208. package/docs/Microsoft.Quantum.Math/Truncate.md +1 -1
  209. package/docs/Microsoft.Quantum.Measurement/MResetEachZ.md +1 -1
  210. package/docs/Microsoft.Quantum.Measurement/MResetX.md +1 -1
  211. package/docs/Microsoft.Quantum.Measurement/MResetY.md +1 -1
  212. package/docs/Microsoft.Quantum.Measurement/MResetZ.md +1 -1
  213. package/docs/Microsoft.Quantum.Measurement/MeasureAllZ.md +1 -1
  214. package/docs/Microsoft.Quantum.Measurement/MeasureEachZ.md +1 -1
  215. package/docs/Microsoft.Quantum.ResourceEstimation/AccountForEstimates.md +1 -1
  216. package/docs/Microsoft.Quantum.ResourceEstimation/AuxQubitCount.md +1 -1
  217. package/docs/Microsoft.Quantum.ResourceEstimation/BeginEstimateCaching.md +1 -1
  218. package/docs/Microsoft.Quantum.ResourceEstimation/BeginRepeatEstimates.md +1 -1
  219. package/docs/Microsoft.Quantum.ResourceEstimation/CczCount.md +1 -1
  220. package/docs/Microsoft.Quantum.ResourceEstimation/EndEstimateCaching.md +1 -1
  221. package/docs/Microsoft.Quantum.ResourceEstimation/EndRepeatEstimates.md +1 -1
  222. package/docs/Microsoft.Quantum.ResourceEstimation/MeasurementCount.md +1 -1
  223. package/docs/Microsoft.Quantum.ResourceEstimation/PSSPCLayout.md +1 -1
  224. package/docs/Microsoft.Quantum.ResourceEstimation/RepeatEstimates.md +1 -1
  225. package/docs/Microsoft.Quantum.ResourceEstimation/RotationCount.md +1 -1
  226. package/docs/Microsoft.Quantum.ResourceEstimation/RotationDepth.md +1 -1
  227. package/docs/Microsoft.Quantum.ResourceEstimation/SingleVariant.md +1 -1
  228. package/docs/Microsoft.Quantum.ResourceEstimation/TCount.md +1 -1
  229. package/docs/Microsoft.Quantum.Unstable.Arithmetic/AddLE.md +1 -1
  230. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualL.md +1 -1
  231. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualLE.md +1 -1
  232. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterL.md +1 -1
  233. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterLE.md +1 -1
  234. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualL.md +1 -1
  235. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualLE.md +1 -1
  236. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessL.md +1 -1
  237. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessLE.md +1 -1
  238. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualL.md +1 -1
  239. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualLE.md +1 -1
  240. package/docs/Microsoft.Quantum.Unstable.Arithmetic/FourierTDIncByLE.md +1 -1
  241. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByI.md +1 -1
  242. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByIUsingIncByLE.md +1 -1
  243. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByL.md +1 -1
  244. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLE.md +1 -1
  245. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLEUsingAddLE.md +1 -1
  246. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLUsingIncByLE.md +1 -1
  247. package/docs/Microsoft.Quantum.Unstable.Arithmetic/LookAheadDKRSAddLE.md +1 -1
  248. package/docs/Microsoft.Quantum.Unstable.Arithmetic/MAJ.md +1 -1
  249. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ReflectAboutInteger.md +1 -1
  250. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGAddLE.md +1 -1
  251. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGIncByLE.md +1 -1
  252. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryTTKIncByLE.md +1 -1
  253. package/docs/Microsoft.Quantum.Unstable.StatePreparation/ApproximatelyPreparePureStateCP.md +1 -1
  254. package/docs/Microsoft.Quantum.Unstable.StatePreparation/PreparePureStateD.md +1 -1
  255. package/docs/toc.yml +1 -19
  256. package/lib/node/qsc_wasm.cjs +48 -25
  257. package/lib/node/qsc_wasm.d.cts +11 -5
  258. package/lib/node/qsc_wasm_bg.wasm +0 -0
  259. package/lib/web/qsc_wasm.d.ts +14 -8
  260. package/lib/web/qsc_wasm.js +48 -25
  261. package/lib/web/qsc_wasm_bg.wasm +0 -0
  262. package/package.json +1 -1
  263. package/ux/estimatesPanel.tsx +1 -2
  264. package/ux/index.ts +1 -0
  265. package/ux/qsharp-ux.css +8 -0
  266. package/ux/reTable.tsx +7 -11
  267. package/ux/renderers.tsx +32 -0
  268. package/docs/Microsoft.Quantum.Convert/BoolArrayAsResultArray.md +0 -29
  269. package/docs/Microsoft.Quantum.Convert/BoolAsResult.md +0 -29
  270. package/docs/Microsoft.Quantum.Convert/ResultArrayAsBoolArray.md +0 -29
  271. package/docs/Microsoft.Quantum.Convert/ResultArrayAsInt.md +0 -34
  272. package/docs/Microsoft.Quantum.Convert/ResultAsBool.md +0 -29
  273. package/docs/Microsoft.Quantum.Diagnostics/CheckAllZero.md +0 -18
  274. package/docs/Microsoft.Quantum.Diagnostics/CheckOperationsAreEqual.md +0 -47
  275. package/docs/Microsoft.Quantum.Diagnostics/CheckZero.md +0 -18
  276. package/docs/Microsoft.Quantum.Measurement/MeasureInteger.md +0 -34
  277. package/docs/Microsoft.Quantum.Random/DrawRandomDouble.md +0 -38
  278. package/docs/Microsoft.Quantum.Random/DrawRandomInt.md +0 -38
  279. package/docs/Microsoft.Quantum.Unstable.TableLookup/Select.md +0 -53
@@ -17,12 +17,12 @@ export default [
17
17
  {
18
18
  "title": "Bell States",
19
19
  "shots": 100,
20
- "code": "/// # Sample\n/// Bell States\n///\n/// # Description\n/// Bell states or EPR pairs are specific quantum states of two qubits\n/// that represent the simplest (and maximal) examples of quantum entanglement.\n///\n/// This Q# program implements the four different Bell states.\nnamespace Sample {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation BellStates() : (Result, Result)[] {\n // Allocate the two qubits that will be used to create a Bell state.\n use register = Qubit[2];\n\n // This array contains a label and a preparation operation for each one\n // of the four Bell states.\n let bellStateTuples = [\n (\"|Φ+〉\", PreparePhiPlus),\n (\"|Φ-〉\", PreparePhiMinus),\n (\"|Ψ+〉\", PreparePsiPlus),\n (\"|Ψ-〉\", PreparePsiMinus)\n ];\n\n // Prepare all Bell states, show them using the `DumpMachine` operation\n // and measure the Bell state qubits.\n mutable measurements = [];\n for (label, prepare) in bellStateTuples {\n prepare(register);\n Message($\"Bell state {label}:\");\n DumpMachine();\n set measurements += [(MResetZ(register[0]), MResetZ(register[1]))];\n }\n return measurements;\n }\n\n operation PreparePhiPlus(register : Qubit[]) : Unit {\n ResetAll(register); // |00〉\n H(register[0]); // |+0〉\n CNOT(register[0], register[1]); // 1/sqrt(2)(|00〉 + |11〉)\n }\n\n operation PreparePhiMinus(register : Qubit[]) : Unit {\n ResetAll(register); // |00〉\n H(register[0]); // |+0〉\n Z(register[0]); // |-0〉\n CNOT(register[0], register[1]); // 1/sqrt(2)(|00〉 - |11〉)\n }\n\n operation PreparePsiPlus(register : Qubit[]) : Unit {\n ResetAll(register); // |00〉\n H(register[0]); // |+0〉\n X(register[1]); // |+1〉\n CNOT(register[0], register[1]); // 1/sqrt(2)(|01〉 + |10〉)\n }\n\n operation PreparePsiMinus(register : Qubit[]) : Unit {\n ResetAll(register); // |00〉\n H(register[0]); // |+0〉\n Z(register[0]); // |-0〉\n X(register[1]); // |-1〉\n CNOT(register[0], register[1]); // 1/sqrt(2)(|01〉 - |10〉)\n }\n}\n"
20
+ "code": "/// # Sample\n/// Bell States\n///\n/// # Description\n/// Bell states or EPR pairs are specific quantum states of two qubits\n/// that represent the simplest (and maximal) examples of quantum entanglement.\n///\n/// This Q# program implements the four different Bell states.\nnamespace Sample {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation BellStates() : (Result, Result)[] {\n // This array contains a label and a preparation operation for each one\n // of the four Bell states.\n let bellStateTuples = [\n (\"|Φ+〉\", PreparePhiPlus),\n (\"|Φ-〉\", PreparePhiMinus),\n (\"|Ψ+〉\", PreparePsiPlus),\n (\"|Ψ-〉\", PreparePsiMinus)\n ];\n\n // Prepare all Bell states, show them using the `DumpMachine` operation\n // and measure the Bell state qubits.\n mutable measurements = [];\n for (label, prepare) in bellStateTuples {\n // Allocate the two qubits that will be used to create a Bell state.\n use register = Qubit[2];\n prepare(register);\n Message($\"Bell state {label}:\");\n DumpMachine();\n set measurements += [(MResetZ(register[0]), MResetZ(register[1]))];\n }\n return measurements;\n }\n\n /// # Summary\n /// Prepares |Φ+⟩ = (|00⟩+|11⟩)/√2 state assuming `register` is in |00⟩ state.\n operation PreparePhiPlus(register : Qubit[]) : Unit {\n H(register[0]); // |+0〉\n CNOT(register[0], register[1]); // 1/sqrt(2)(|00〉 + |11〉)\n }\n\n /// # Summary\n /// Prepares |Φ−⟩ = (|00⟩-|11⟩)/√2 state assuming `register` is in |00⟩ state.\n operation PreparePhiMinus(register : Qubit[]) : Unit {\n H(register[0]); // |+0〉\n Z(register[0]); // |-0〉\n CNOT(register[0], register[1]); // 1/sqrt(2)(|00〉 - |11〉)\n }\n\n /// # Summary\n /// Prepares |Ψ+⟩ = (|01⟩+|10⟩)/√2 state assuming `register` is in |00⟩ state.\n operation PreparePsiPlus(register : Qubit[]) : Unit {\n H(register[0]); // |+0〉\n X(register[1]); // |+1〉\n CNOT(register[0], register[1]); // 1/sqrt(2)(|01〉 + |10〉)\n }\n\n /// # Summary\n /// Prepares |Ψ−⟩ = (|01⟩-|10⟩)/√2 state assuming `register` is in |00⟩ state.\n operation PreparePsiMinus(register : Qubit[]) : Unit {\n H(register[0]); // |+0〉\n Z(register[0]); // |-0〉\n X(register[1]); // |-1〉\n CNOT(register[0], register[1]); // 1/sqrt(2)(|01〉 - |10〉)\n }\n}\n"
21
21
  },
22
22
  {
23
23
  "title": "Teleportation",
24
24
  "shots": 1,
25
- "code": "/// # Sample\n/// Quantum Teleportation\n///\n/// # Description\n/// Quantum teleportation provides a way of moving a quantum state from one\n/// location to another without having to move physical particle(s) along with\n/// it. This is done with the help of previously shared quantum entanglement\n/// between the sending and the receiving locations, and classical\n/// communication.\n///\n/// This Q# program implements quantum teleportation.\nnamespace Sample {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation Main() : Result[] {\n // Allocate the message and target qubits.\n use (message, target) = (Qubit(), Qubit());\n\n // Use the `Teleport` operation to send different quantum states.\n let stateInitializerBasisTuples = [\n (\"|0〉\", I, PauliZ),\n (\"|1〉\", X, PauliZ),\n (\"|+〉\", SetToPlus, PauliX),\n (\"|-〉\", SetToMinus, PauliX)\n ];\n\n mutable results = [];\n for (state, initializer, basis) in stateInitializerBasisTuples {\n // Initialize the message and show its state using the `DumpMachine`\n // function.\n initializer(message);\n Message($\"Teleporting state {state}\");\n DumpMachine();\n\n // Teleport the message and show the quantum state after\n // teleportation.\n Teleport(message, target);\n Message($\"Received state {state}\");\n DumpMachine();\n\n // Measure target in the corresponding basis and reset the qubits to\n // continue teleporting more messages.\n let result = Measure([basis], [target]);\n set results += [result];\n ResetAll([message, target]);\n }\n\n return results;\n }\n\n /// # Summary\n /// Sends the state of one qubit to a target qubit by using teleportation.\n ///\n /// Notice that after calling Teleport, the state of `message` is collapsed.\n ///\n /// # Input\n /// ## message\n /// A qubit whose state we wish to send.\n /// ## target\n /// A qubit initially in the |0〉 state that we want to send\n /// the state of message to.\n operation Teleport(message : Qubit, target : Qubit) : Unit {\n // Allocate an auxiliary qubit.\n use auxiliary = Qubit();\n\n // Create some entanglement that we can use to send our message.\n H(auxiliary);\n CNOT(auxiliary, target);\n\n // Encode the message into the entangled pair.\n CNOT(message, auxiliary);\n H(message);\n\n // Measure the qubits to extract the classical data we need to decode\n // the message by applying the corrections on the target qubit\n // accordingly.\n if M(message) == One {\n Z(target);\n }\n if M(auxiliary) == One {\n X(target);\n }\n\n // Reset auxiliary qubit before releasing.\n Reset(auxiliary);\n }\n\n /// # Summary\n /// Sets a qubit in state |0⟩ to |+⟩.\n operation SetToPlus(q : Qubit) : Unit is Adj + Ctl {\n H(q);\n }\n\n /// # Summary\n /// Sets a qubit in state |0⟩ to |−⟩.\n operation SetToMinus(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n H(q);\n }\n}\n"
25
+ "code": "/// # Sample\n/// Quantum Teleportation\n///\n/// # Description\n/// Quantum teleportation provides a way of moving a quantum state from one\n/// location to another without having to move physical particle(s) along with\n/// it. This is done with the help of previously shared quantum entanglement\n/// between the sending and the receiving locations, and classical\n/// communication.\n///\n/// This Q# program implements quantum teleportation.\nnamespace Sample {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation Main() : Result[] {\n // Use the `Teleport` operation to send different quantum states.\n let stateInitializerBasisTuples = [\n (\"|0〉\", I, PauliZ),\n (\"|1〉\", X, PauliZ),\n (\"|+〉\", SetToPlus, PauliX),\n (\"|-〉\", SetToMinus, PauliX)\n ];\n\n mutable results = [];\n for (state, initializer, basis) in stateInitializerBasisTuples {\n // Allocate the message and target qubits.\n use (message, target) = (Qubit(), Qubit());\n\n // Initialize the message and show its state using the `DumpMachine`\n // function.\n initializer(message);\n Message($\"Teleporting state {state}\");\n DumpRegister([message]);\n\n // Teleport the message and show the quantum state after\n // teleportation.\n Teleport(message, target);\n Message($\"Received state {state}\");\n DumpRegister([target]);\n\n // Measure target in the corresponding basis and reset the qubits to\n // continue teleporting more messages.\n let result = Measure([basis], [target]);\n set results += [result];\n ResetAll([message, target]);\n }\n\n return results;\n }\n\n /// # Summary\n /// Sends the state of one qubit to a target qubit by using teleportation.\n ///\n /// Notice that after calling Teleport, the state of `message` is collapsed.\n ///\n /// # Input\n /// ## message\n /// A qubit whose state we wish to send.\n /// ## target\n /// A qubit initially in the |0〉 state that we want to send\n /// the state of message to.\n operation Teleport(message : Qubit, target : Qubit) : Unit {\n // Allocate an auxiliary qubit.\n use auxiliary = Qubit();\n\n // Create some entanglement that we can use to send our message.\n H(auxiliary);\n CNOT(auxiliary, target);\n\n // Encode the message into the entangled pair.\n CNOT(message, auxiliary);\n H(message);\n\n // Measure the qubits to extract the classical data we need to decode\n // the message by applying the corrections on the target qubit\n // accordingly.\n if M(auxiliary) == One {\n X(target);\n }\n\n if M(message) == One {\n Z(target);\n }\n\n // Reset auxiliary qubit before releasing.\n Reset(auxiliary);\n }\n\n /// # Summary\n /// Sets a qubit in state |0⟩ to |+⟩.\n operation SetToPlus(q : Qubit) : Unit is Adj + Ctl {\n H(q);\n }\n\n /// # Summary\n /// Sets a qubit in state |0⟩ to |−⟩.\n operation SetToMinus(q : Qubit) : Unit is Adj + Ctl {\n X(q);\n H(q);\n }\n}\n"
26
26
  },
27
27
  {
28
28
  "title": "Random Bit",
@@ -52,27 +52,27 @@ export default [
52
52
  {
53
53
  "title": "Bernstein–Vazirani",
54
54
  "shots": 1,
55
- "code": "/// # Sample\n/// Bernstein-Vazirani algorithm\n///\n/// # Description\n/// The Bernstein-Vazirani algorithm determines the value of a bit string\n/// encoded in a function.\n///\n/// This Q# program implements the Bernstein-Vazirani algorithm.\nnamespace Sample {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation Main() : Result[] {\n // Consider a function 𝑓(𝑥⃗) on bitstrings 𝑥⃗ = (𝑥₀, …, 𝑥ₙ₋₁) of the form\n // 𝑓(𝑥⃗) ≔ Σᵢ 𝑥ᵢ 𝑟ᵢ\n // where 𝑟⃗ = (𝑟₀, …, 𝑟ₙ₋₁) is an unknown bit string that determines the\n // parity of 𝑓.\n\n // The Bernstein–Vazirani algorithm allows determining 𝑟 given a\n // quantum operation that implements\n // |𝑥〉|𝑦〉 ↦ |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉.\n\n // This entry point function of this program, `Main`, shows how to use\n // the `BernsteinVazirani` operation to determine the value of bitstring\n // 𝑟.\n let secretBitString = SecretBitStringAsBoolArray();\n let parityOperation = EncodeBitStringAsParityOperation(secretBitString);\n let decodedBitString = BernsteinVazirani(\n parityOperation,\n Length(secretBitString)\n );\n\n return decodedBitString;\n }\n\n /// # Summary\n /// This operation implements the Bernstein-Vazirani quantum algorithm.\n /// This algorithm computes for a given Boolean function that is promised to\n /// be a parity 𝑓(𝑥₀, …, 𝑥ₙ₋₁) = Σᵢ 𝑟ᵢ 𝑥ᵢ a result in the form of a bit\n /// vector (𝑟₀, …, 𝑟ₙ₋₁) corresponding to the parity function.\n /// Note that it is promised that the function is actually a parity\n /// function.\n ///\n /// # Input\n /// ## Uf\n /// A quantum operation that implements |𝑥〉|𝑦〉 ↦ |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉,\n /// where 𝑓 is a Boolean function that implements a parity Σᵢ 𝑟ᵢ 𝑥ᵢ.\n /// ## n\n /// The number of bits in the input register |𝑥〉.\n ///\n /// # Output\n /// An array of type `Result[]` that contains the parity 𝑟⃗ = (𝑟₀, …, 𝑟ₙ₋₁).\n ///\n /// # See Also\n /// - For details see Section 1.4.3 of Nielsen & Chuang.\n ///\n /// # References\n /// - [ *Ethan Bernstein and Umesh Vazirani*,\n /// SIAM J. Comput., 26(5), 1411–1473, 1997 ]\n /// (https://doi.org/10.1137/S0097539796300921)\n operation BernsteinVazirani(Uf : ((Qubit[], Qubit) => Unit), n : Int) : Result[] {\n // We allocate n + 1 clean qubits. Note that the function parameter Uf is defined\n // on inputs of the form (x, y), where x has n bits and y has 1 bit.\n use queryRegister = Qubit[n];\n use target = Qubit();\n\n // The last qubit needs to be flipped so that a relative phase is\n // introduced when we apply a Hadamard gate later on and we can use\n // phase kickback when Uf is applied.\n X(target);\n\n within {\n // Now, a Hadamard transform is applied to each of the qubits. As\n // the last step before the measurement, a Hadamard transform is\n // applied to all qubits except the last one. We could also\n // transform the last qubit, but this would not affect the\n // final outcome.\n // We use a within-apply block to ensure that the Hadamard transform\n // is correctly inverted.\n ApplyToEachA(H, queryRegister);\n } apply {\n H(target);\n // We now apply Uf to the n+1 qubits, computing\n // |x, y〉 ↦ |x, y ⊕ f(x)〉.\n Uf(queryRegister, target);\n }\n\n // Measure all qubits and reset them to the |0〉 state so that they can\n // be safely deallocated at the end of the block.\n let resultArray = ForEach(MResetZ, queryRegister);\n\n // Finally, the last qubit, which held the y-register, is reset.\n Reset(target);\n\n // The result is already contained in resultArray so no further\n // post-processing is necessary.\n return resultArray;\n }\n\n /// # Summary\n /// Given bit string 𝑟⃗ = (r₀, …, rₙ₋₁), represented as an array of Booleans,\n /// this operation applies a unitary 𝑈 that acts on 𝑛 + 1 qubits as:\n /// 𝑈 |𝑥〉|𝑦〉 = |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉\n /// where 𝑓(𝑥) = Σᵢ 𝑥ᵢ 𝑟ᵢ mod 2.\n ///\n /// # Input\n /// ## bitStringAsBoolArray\n /// A bit string 𝑟⃗, represented as an array of Booleans, used to define the\n /// function 𝑓.\n /// ## xRegister\n /// Represents the |𝑥〉 register that 𝑈 acts on.\n /// ## yQubit\n /// Represents the |𝑦〉 qubit that 𝑈 acts on.\n operation ApplyParityOperation(\n bitStringAsBoolArray : Bool[],\n xRegister : Qubit[],\n yQubit : Qubit\n ) : Unit {\n // `xRegister` muts have enough qubits to represent the integer.\n let requiredBits = Length(bitStringAsBoolArray);\n let availableQubits = Length(xRegister);\n Fact(\n availableQubits >= requiredBits,\n $\"The bitstring has {requiredBits} bits but the quantum register \" + $\"only has {availableQubits} qubits\"\n );\n\n // Apply the quantum operations that encode the bit string.\n for (index, bit) in Enumerated(bitStringAsBoolArray) {\n if bit {\n CNOT(xRegister[index], yQubit);\n }\n }\n }\n\n /// # Summary\n /// This is a higher-order operation which returns an operation (Qubit[], Qubit) => () of the form\n /// U_f |𝑥〉|𝑦〉 = |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉.\n /// We define 𝑓 by providing the bit string 𝑟⃗ as an integer.\n operation EncodeBitStringAsParityOperation(bitStringAsBoolArray : Bool[]) : (Qubit[], Qubit) => Unit {\n return ApplyParityOperation(bitStringAsBoolArray, _, _);\n }\n\n /// # Summary\n /// Returns a particular bit string as an array of Booleans.\n function SecretBitStringAsBoolArray() : Bool[] {\n return [true, false, true, false, true];\n }\n}\n"
55
+ "code": "/// # Sample\n/// Bernstein-Vazirani algorithm\n///\n/// # Description\n/// The Bernstein-Vazirani algorithm determines the value of a bit string\n/// encoded in a function.\n///\n/// This Q# program implements the Bernstein-Vazirani algorithm.\nnamespace Sample {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation Main() : Result[] {\n // Consider a function 𝑓(𝑥⃗) on bitstrings 𝑥⃗ = (𝑥₀, …, 𝑥ₙ₋₁) of the form\n // 𝑓(𝑥⃗) ≔ Σᵢ 𝑥ᵢ 𝑟ᵢ\n // where 𝑟⃗ = (𝑟₀, …, 𝑟ₙ₋₁) is an unknown bit string that determines the\n // parity of 𝑓.\n\n // The Bernstein–Vazirani algorithm allows determining 𝑟 given a\n // quantum operation that implements\n // |𝑥〉|𝑦〉 ↦ |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉.\n\n // This entry point function of this program, `Main`, shows how to use\n // the `BernsteinVazirani` operation to determine the value of bitstring\n // 𝑟.\n let secretBitString = SecretBitStringAsBoolArray();\n let parityOperation = EncodeBitStringAsParityOperation(secretBitString);\n let decodedBitString = BernsteinVazirani(\n parityOperation,\n Length(secretBitString)\n );\n\n return decodedBitString;\n }\n\n /// # Summary\n /// This operation implements the Bernstein-Vazirani quantum algorithm.\n /// This algorithm computes for a given Boolean function that is promised to\n /// be a parity 𝑓(𝑥₀, …, 𝑥ₙ₋₁) = Σᵢ 𝑟ᵢ 𝑥ᵢ a result in the form of a bit\n /// vector (𝑟₀, …, 𝑟ₙ₋₁) corresponding to the parity function.\n /// Note that it is promised that the function is actually a parity\n /// function.\n ///\n /// # Input\n /// ## Uf\n /// A quantum operation that implements |𝑥〉|𝑦〉 ↦ |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉,\n /// where 𝑓 is a Boolean function that implements a parity Σᵢ 𝑟ᵢ 𝑥ᵢ.\n /// ## n\n /// The number of bits in the input register |𝑥〉.\n ///\n /// # Output\n /// An array of type `Result[]` that contains the parity 𝑟⃗ = (𝑟₀, …, 𝑟ₙ₋₁).\n ///\n /// # See Also\n /// - For details see Section 1.4.3 of Nielsen & Chuang.\n ///\n /// # References\n /// - [ *Ethan Bernstein and Umesh Vazirani*,\n /// SIAM J. Comput., 26(5), 1411–1473, 1997 ]\n /// (https://doi.org/10.1137/S0097539796300921)\n operation BernsteinVazirani(Uf : ((Qubit[], Qubit) => Unit), n : Int) : Result[] {\n // We allocate n + 1 clean qubits. Note that the function parameter Uf is defined\n // on inputs of the form (x, y), where x has n bits and y has 1 bit.\n use queryRegister = Qubit[n];\n use target = Qubit();\n\n // The last qubit needs to be flipped so that a relative phase is\n // introduced when we apply a Hadamard gate later on and we can use\n // phase kickback when Uf is applied.\n X(target);\n\n within {\n // Now, a Hadamard transform is applied to each of the qubits. As\n // the last step before the measurement, a Hadamard transform is\n // applied to all qubits except the last one. We could also\n // transform the last qubit, but this would not affect the\n // final outcome.\n // We use a within-apply block to ensure that the Hadamard transform\n // is correctly inverted.\n ApplyToEachA(H, queryRegister);\n } apply {\n H(target);\n // We now apply Uf to the n+1 qubits, computing\n // |x, y〉 ↦ |x, y ⊕ f(x)〉.\n Uf(queryRegister, target);\n }\n\n // Measure all qubits and reset them to the |0〉 state so that they can\n // be safely deallocated at the end of the block.\n let resultArray = MResetEachZ(queryRegister);\n\n // Finally, the last qubit, which held the y-register, is reset.\n Reset(target);\n\n // The result is already contained in resultArray so no further\n // post-processing is necessary.\n return resultArray;\n }\n\n /// # Summary\n /// Given bit string 𝑟⃗ = (r₀, …, rₙ₋₁), represented as an array of Booleans,\n /// this operation applies a unitary 𝑈 that acts on 𝑛 + 1 qubits as:\n /// 𝑈 |𝑥〉|𝑦〉 = |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉\n /// where 𝑓(𝑥) = Σᵢ 𝑥ᵢ 𝑟ᵢ mod 2.\n ///\n /// # Input\n /// ## bitStringAsBoolArray\n /// A bit string 𝑟⃗, represented as an array of Booleans, used to define the\n /// function 𝑓.\n /// ## xRegister\n /// Represents the |𝑥〉 register that 𝑈 acts on.\n /// ## yQubit\n /// Represents the |𝑦〉 qubit that 𝑈 acts on.\n operation ApplyParityOperation(\n bitStringAsBoolArray : Bool[],\n xRegister : Qubit[],\n yQubit : Qubit\n ) : Unit {\n // `xRegister` muts have enough qubits to represent the integer.\n let requiredBits = Length(bitStringAsBoolArray);\n let availableQubits = Length(xRegister);\n Fact(\n availableQubits >= requiredBits,\n $\"The bitstring has {requiredBits} bits but the quantum register \" + $\"only has {availableQubits} qubits\"\n );\n\n // Apply the quantum operations that encode the bit string.\n for (index, bit) in Enumerated(bitStringAsBoolArray) {\n if bit {\n CNOT(xRegister[index], yQubit);\n }\n }\n }\n\n /// # Summary\n /// This is a higher-order operation which returns an operation (Qubit[], Qubit) => () of the form\n /// U_f |𝑥〉|𝑦〉 = |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉.\n /// We define 𝑓 by providing the bit string 𝑟⃗ as an integer.\n operation EncodeBitStringAsParityOperation(bitStringAsBoolArray : Bool[]) : (Qubit[], Qubit) => Unit {\n return ApplyParityOperation(bitStringAsBoolArray, _, _);\n }\n\n /// # Summary\n /// Returns a particular bit string as an array of Booleans.\n function SecretBitStringAsBoolArray() : Bool[] {\n return [true, false, true, false, true];\n }\n}\n"
56
56
  },
57
57
  {
58
58
  "title": "Bernstein–Vazirani (Advanced)",
59
59
  "shots": 1,
60
- "code": "/// # Sample\n/// Bernstein-Vazirani algorithm\n///\n/// # Description\n/// The Bernstein-Vazirani algorithm determines the value of a bit string\n/// encoded in a function.\n///\n/// This Q# program implements the Bernstein-Vazirani algorithm.\nnamespace Sample {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation Main() : Int[] {\n // Consider a function 𝑓(𝑥⃗) on bitstrings 𝑥⃗ = (𝑥₀, …, 𝑥ₙ₋₁) of the form\n // 𝑓(𝑥⃗) ≔ Σᵢ 𝑥ᵢ 𝑟ᵢ\n // where 𝑟⃗ = (𝑟₀, …, 𝑟ₙ₋₁) is an unknown bitstring that determines the\n // parity of 𝑓.\n\n // The Bernstein–Vazirani algorithm allows determining 𝑟 given a\n // quantum operation that implements\n // |𝑥〉|𝑦〉 ↦ |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉.\n\n // The entry point function of this program, `Main`, shows how to use\n // the `BernsteinVazirani` operation to determine the value of various\n // integers whose bits describe 𝑟.\n let nQubits = 10;\n\n // Use the Bernstein–Vazirani algorithm to determine the bit strings\n // that various integers represent.\n let integers = [127, 238, 512];\n mutable decodedIntegers = [];\n for integer in integers {\n // Create an operation that encodes a bit string represented by an\n // integer as a parity operation.\n let parityOperation = EncodeIntegerAsParityOperation(integer);\n\n // Use the parity operation as input to the Bernstein-Vazirani\n // algorithm to determine the bit string.\n let decodedBitString = BernsteinVazirani(parityOperation, nQubits);\n let decodedInteger = ResultArrayAsInt(decodedBitString);\n Fact(\n decodedInteger == integer,\n $\"Decoded integer {decodedInteger}, but expected {integer}.\"\n );\n\n Message($\"Successfully decoded bit string as int: {decodedInteger}\");\n set decodedIntegers += [decodedInteger];\n }\n\n return decodedIntegers;\n }\n\n /// # Summary\n /// This operation implements the Bernstein-Vazirani quantum algorithm.\n /// This algorithm computes for a given Boolean function that is promised to\n /// be a parity 𝑓(𝑥₀, …, 𝑥ₙ₋₁) = Σᵢ 𝑟ᵢ 𝑥ᵢ a result in the form of a bit\n /// vector (𝑟₀, …, 𝑟ₙ₋₁) corresponding to the parity function.\n /// Note that it is promised that the function is actually a parity\n /// function.\n ///\n /// # Input\n /// ## Uf\n /// A quantum operation that implements |𝑥〉|𝑦〉 ↦ |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉,\n /// where 𝑓 is a Boolean function that implements a parity Σᵢ 𝑟ᵢ 𝑥ᵢ.\n /// ## n\n /// The number of bits in the input register |𝑥〉.\n ///\n /// # Output\n /// An array of type `Result[]` that contains the parity 𝑟⃗ = (𝑟₀, …, 𝑟ₙ₋₁).\n ///\n /// # See Also\n /// - For details see Section 1.4.3 of Nielsen & Chuang.\n ///\n /// # References\n /// - [ *Ethan Bernstein and Umesh Vazirani*,\n /// SIAM J. Comput., 26(5), 1411–1473, 1997 ]\n /// (https://doi.org/10.1137/S0097539796300921)\n operation BernsteinVazirani(Uf : ((Qubit[], Qubit) => Unit), n : Int) : Result[] {\n // We allocate n + 1 clean qubits. Note that the function Uf is defined\n // on inputs of the form (x, y), where x has n bits and y has 1 bit.\n use queryRegister = Qubit[n];\n use target = Qubit();\n\n // The last qubit needs to be flipped so that the function will actually\n // be computed into the phase when Uf is applied.\n X(target);\n\n within {\n // Now, a Hadamard transform is applied to each of the qubits. As\n // the last step before the measurement, a Hadamard transform is\n // applied to all qubits except last one. We could apply the\n // transform to the last qubit also, but this would not affect the\n // final outcome.\n // We use a within-apply block to ensure that the Hadamard transform\n // is correctly inverted.\n ApplyToEachA(H, queryRegister);\n } apply {\n H(target);\n // We now apply Uf to the n+1 qubits, computing\n // |x, y〉 ↦ |x, y ⊕ f(x)〉.\n Uf(queryRegister, target);\n }\n\n // Measure all qubits and reset them to the |0〉 state so that they can\n // be safely deallocated at the end of the block.\n let resultArray = ForEach(MResetZ, queryRegister);\n\n // Finally, the last qubit, which held the y-register, is reset.\n Reset(target);\n\n // The result is already contained in resultArray so no further\n // post-processing is necessary.\n return resultArray;\n }\n\n /// # Summary\n /// Given an integer that can be represented as a bit string\n /// 𝑟⃗ = (r₀, …, rₙ₋₁), this operation applies a unitary 𝑈 that acts on 𝑛 + 1\n /// qubits as:\n /// 𝑈 |𝑥〉|𝑦〉 = |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉\n /// where 𝑓(𝑥) = Σᵢ 𝑥ᵢ 𝑟ᵢ mod 2.\n ///\n /// # Input\n /// ## bitStringAsInt\n /// An integer that can be represented as a bit string 𝑟⃗ used to define the\n /// function 𝑓.\n /// ## xRegister\n /// Represents the |𝑥〉 register that 𝑈 acts on.\n /// ## yQubit\n /// Represents the |𝑦〉 qubit that 𝑈 acts on.\n operation ApplyParityOperation(\n bitStringAsInt : Int,\n xRegister : Qubit[],\n yQubit : Qubit\n ) : Unit {\n // `xRegister` muts have enough qubits to represent the integer.\n let requiredBits = BitSizeI(bitStringAsInt);\n let availableQubits = Length(xRegister);\n Fact(\n availableQubits >= requiredBits,\n $\"Integer value {bitStringAsInt} requires {requiredBits} bits to be represented but the quantum register only has {availableQubits} qubits\"\n );\n\n // Apply the quantum operations that encode the bit string.\n for index in IndexRange(xRegister) {\n if ((bitStringAsInt &&& 2^index) != 0) {\n CNOT(xRegister[index], yQubit);\n }\n }\n }\n\n /// # Summary\n /// Returns black-box operations (Qubit[], Qubit) => () of the form\n /// U_f |𝑥〉|𝑦〉 = |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉.\n /// We define 𝑓 by providing the bit string 𝑟⃗ as an integer.\n operation EncodeIntegerAsParityOperation(bitStringAsInt : Int) : (Qubit[], Qubit) => Unit {\n return ApplyParityOperation(bitStringAsInt, _, _);\n }\n}\n"
60
+ "code": "/// # Sample\n/// Bernstein-Vazirani algorithm\n///\n/// # Description\n/// The Bernstein-Vazirani algorithm determines the value of a bit string\n/// encoded in a function.\n///\n/// This Q# program implements the Bernstein-Vazirani algorithm.\nnamespace Sample {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation Main() : Int[] {\n // Consider a function 𝑓(𝑥⃗) on bitstrings 𝑥⃗ = (𝑥₀, …, 𝑥ₙ₋₁) of the form\n // 𝑓(𝑥⃗) ≔ Σᵢ 𝑥ᵢ 𝑟ᵢ\n // where 𝑟⃗ = (𝑟₀, …, 𝑟ₙ₋₁) is an unknown bitstring that determines the\n // parity of 𝑓.\n\n // The Bernstein–Vazirani algorithm allows determining 𝑟 given a\n // quantum operation that implements\n // |𝑥〉|𝑦〉 ↦ |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉.\n\n // The entry point function of this program, `Main`, shows how to use\n // the `BernsteinVazirani` operation to determine the value of various\n // integers whose bits describe 𝑟.\n let nQubits = 10;\n\n // Use the Bernstein–Vazirani algorithm to determine the bit strings\n // that various integers represent.\n let integers = [127, 238, 512];\n mutable decodedIntegers = [];\n for integer in integers {\n // Create an operation that encodes a bit string represented by an\n // integer as a parity operation.\n let parityOperation = EncodeIntegerAsParityOperation(integer);\n\n // Use the parity operation as input to the Bernstein-Vazirani\n // algorithm to determine the bit string.\n let decodedBitString = BernsteinVazirani(parityOperation, nQubits);\n let decodedInteger = ResultArrayAsInt(decodedBitString);\n Fact(\n decodedInteger == integer,\n $\"Decoded integer {decodedInteger}, but expected {integer}.\"\n );\n\n Message($\"Successfully decoded bit string as int: {decodedInteger}\");\n set decodedIntegers += [decodedInteger];\n }\n\n return decodedIntegers;\n }\n\n /// # Summary\n /// This operation implements the Bernstein-Vazirani quantum algorithm.\n /// This algorithm computes for a given Boolean function that is promised to\n /// be a parity 𝑓(𝑥₀, …, 𝑥ₙ₋₁) = Σᵢ 𝑟ᵢ 𝑥ᵢ a result in the form of a bit\n /// vector (𝑟₀, …, 𝑟ₙ₋₁) corresponding to the parity function.\n /// Note that it is promised that the function is actually a parity\n /// function.\n ///\n /// # Input\n /// ## Uf\n /// A quantum operation that implements |𝑥〉|𝑦〉 ↦ |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉,\n /// where 𝑓 is a Boolean function that implements a parity Σᵢ 𝑟ᵢ 𝑥ᵢ.\n /// ## n\n /// The number of bits in the input register |𝑥〉.\n ///\n /// # Output\n /// An array of type `Result[]` that contains the parity 𝑟⃗ = (𝑟₀, …, 𝑟ₙ₋₁).\n ///\n /// # See Also\n /// - For details see Section 1.4.3 of Nielsen & Chuang.\n ///\n /// # References\n /// - [ *Ethan Bernstein and Umesh Vazirani*,\n /// SIAM J. Comput., 26(5), 1411–1473, 1997 ]\n /// (https://doi.org/10.1137/S0097539796300921)\n operation BernsteinVazirani(Uf : ((Qubit[], Qubit) => Unit), n : Int) : Result[] {\n // We allocate n + 1 clean qubits. Note that the function Uf is defined\n // on inputs of the form (x, y), where x has n bits and y has 1 bit.\n use queryRegister = Qubit[n];\n use target = Qubit();\n\n // The last qubit needs to be flipped so that the function will actually\n // be computed into the phase when Uf is applied.\n X(target);\n\n within {\n // Now, a Hadamard transform is applied to each of the qubits. As\n // the last step before the measurement, a Hadamard transform is\n // applied to all qubits except last one. We could apply the\n // transform to the last qubit also, but this would not affect the\n // final outcome.\n // We use a within-apply block to ensure that the Hadamard transform\n // is correctly inverted.\n ApplyToEachA(H, queryRegister);\n } apply {\n H(target);\n // We now apply Uf to the n+1 qubits, computing\n // |x, y〉 ↦ |x, y ⊕ f(x)〉.\n Uf(queryRegister, target);\n }\n\n // Measure all qubits and reset them to the |0〉 state so that they can\n // be safely deallocated at the end of the block.\n let resultArray = MResetEachZ(queryRegister);\n\n // Finally, the last qubit, which held the y-register, is reset.\n Reset(target);\n\n // The result is already contained in resultArray so no further\n // post-processing is necessary.\n return resultArray;\n }\n\n /// # Summary\n /// Given an integer that can be represented as a bit string\n /// 𝑟⃗ = (r₀, …, rₙ₋₁), this operation applies a unitary 𝑈 that acts on 𝑛 + 1\n /// qubits as:\n /// 𝑈 |𝑥〉|𝑦〉 = |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉\n /// where 𝑓(𝑥) = Σᵢ 𝑥ᵢ 𝑟ᵢ mod 2.\n ///\n /// # Input\n /// ## bitStringAsInt\n /// An integer that can be represented as a bit string 𝑟⃗ used to define the\n /// function 𝑓.\n /// ## xRegister\n /// Represents the |𝑥〉 register that 𝑈 acts on.\n /// ## yQubit\n /// Represents the |𝑦〉 qubit that 𝑈 acts on.\n operation ApplyParityOperation(\n bitStringAsInt : Int,\n xRegister : Qubit[],\n yQubit : Qubit\n ) : Unit {\n // `xRegister` muts have enough qubits to represent the integer.\n let requiredBits = BitSizeI(bitStringAsInt);\n let availableQubits = Length(xRegister);\n Fact(\n availableQubits >= requiredBits,\n $\"Integer value {bitStringAsInt} requires {requiredBits} bits to be represented but the quantum register only has {availableQubits} qubits\"\n );\n\n // Apply the quantum operations that encode the bit string.\n for index in IndexRange(xRegister) {\n if ((bitStringAsInt &&& 2^index) != 0) {\n CNOT(xRegister[index], yQubit);\n }\n }\n }\n\n /// # Summary\n /// Returns black-box operations (Qubit[], Qubit) => () of the form\n /// U_f |𝑥〉|𝑦〉 = |𝑥〉|𝑦 ⊕ 𝑓(𝑥)〉.\n /// We define 𝑓 by providing the bit string 𝑟⃗ as an integer.\n operation EncodeIntegerAsParityOperation(bitStringAsInt : Int) : (Qubit[], Qubit) => Unit {\n return ApplyParityOperation(bitStringAsInt, _, _);\n }\n}\n"
61
61
  },
62
62
  {
63
63
  "title": "Grover's search",
64
64
  "shots": 100,
65
- "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.\nnamespace Sample {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Measurement;\n open Microsoft.Quantum.Diagnostics;\n\n @EntryPoint()\n operation 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.\n operation 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.\n function CalculateOptimalIterations(nQubits : Int) : Int {\n if nQubits > 63 {\n fail \"This sample supports at most 63 qubits.\";\n }\n let nItems = 1 <<< nQubits; // 2^nQubits\n let angle = ArcSin(1. / Sqrt(IntAsDouble(nItems)));\n let iterations = Round(0.25 * PI() / angle - 0.5);\n return 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.\n operation 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.\n operation 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.\n operation ReflectAboutAllOnes(inputQubits : Qubit[]) : Unit {\n Controlled Z(Most(inputQubits), Tail(inputQubits));\n }\n\n /// # Summary\n /// Reflects about the uniform superposition state.\n operation 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}\n"
65
+ "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.\nnamespace Sample {\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Measurement;\n open Microsoft.Quantum.Diagnostics;\n\n @EntryPoint()\n operation 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.\n operation 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.\n function 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.\n operation 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.\n operation 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.\n operation ReflectAboutAllOnes(inputQubits : Qubit[]) : Unit {\n Controlled Z(Most(inputQubits), Tail(inputQubits));\n }\n\n /// # Summary\n /// Reflects about the uniform superposition state.\n operation 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}\n"
66
66
  },
67
67
  {
68
68
  "title": "Hidden Shift",
69
69
  "shots": 1,
70
- "code": "/// # Sample\n/// Hidden shift\n///\n/// # Description\n/// There is a family of problems known as hidden shift problems, in which it\n/// is given that two Boolean functions 𝑓 and 𝑔 satisfy the relation\n/// 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠) for all 𝑥\n/// where 𝑠 is a hidden bit string that we would like to find.\n///\n/// This Q# program implements an algorithm to solve the hidden shift problem.\nnamespace Sample {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation Main() : Result[] {\n // Consider the case of finding a hidden shift 𝑠 between two Boolean\n // functions 𝑓(𝑥) and 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠).\n // This problem can be solved on a quantum computer with one call to\n // each of 𝑓 and 𝑔 in the special case that both functions are bent;\n // that is, that they are as far from linear as possible.\n\n // Here, we find the hidden shift encoded in the following array of\n // Booleans.\n let shiftAsBoolArray = [true, false, false, false, false, true];\n let shiftAsInt = BoolArrayAsInt(shiftAsBoolArray);\n let hiddenShiftBitString = FindHiddenShift(\n BentFunction,\n register => ShiftedBentFunction(shiftAsInt, register),\n Length(shiftAsBoolArray)\n );\n\n return hiddenShiftBitString;\n }\n\n /// # Summary\n /// Implements a correlation-based algorithm to solve the hidden shift\n /// problem for bent functions.\n ///\n /// # Description\n /// Implements a solution for the hidden shift problem, which is to identify\n /// an unknown shift 𝑠 of the arguments of two Boolean functions 𝑓 and 𝑔\n /// that are promised to satisfy the relation 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠) for all 𝑥.\n ///\n /// 𝑓 and 𝑔 are assumed to be bent functions. A Boolean function is bent if\n /// it is as far from linear as possible. In particular, bent functions have\n /// flat Fourier (Walsh–Hadamard) spectra.\n ///\n /// In this case, the Roetteler algorithm (see References, below) uses\n /// black-box oracles for 𝑓^* and 𝑔, where 𝑓^* is the dual bent function to\n /// 𝑓, and computes the hidden shift 𝑠 between 𝑓 and 𝑔.\n ///\n /// # Input\n /// ## Ufstar\n /// A quantum operation that implements\n /// $U_f^*: |𝑥〉 ↦ (-1)^{f^*(x)} |𝑥〉$,\n /// where $f^*$ is a Boolean function, 𝑥 is an $n$ bit register\n /// ## Ug\n /// A quantum operation that implements\n /// $U_g:|𝑥〉 ↦ (-1)^{g(x)} |𝑥〉$,\n /// where 𝑔 is a Boolean function that is shifted by unknown\n /// 𝑠 from 𝑓, and 𝑥 is an $n$ bit register.\n /// ## n\n /// The number of bits of the input register |𝑥〉.\n ///\n /// # Output\n /// An array of type `Result[]` which encodes the bit representation\n /// of the hidden shift.\n ///\n /// # References\n /// - [*Martin Roetteler*,\n /// Proc. SODA 2010, ACM, pp. 448-457, 2010]\n /// (https://doi.org/10.1137/1.9781611973075.37)\n operation FindHiddenShift(\n Ufstar : (Qubit[] => Unit),\n Ug : (Qubit[] => Unit),\n n : Int\n ) : Result[] {\n // We allocate n clean qubits. Note that the function Ufstar and Ug are\n // unitary operations on n qubits defined via phase encoding.\n use qubits = Qubit[n];\n\n // First, a Hadamard transform is applied to each of the qubits.\n ApplyToEach(H, qubits);\n\n // We now apply the shifted function Ug to the n qubits, computing\n // |x〉 -> (-1)^{g(x)} |x〉.\n Ug(qubits);\n\n within {\n // A Hadamard transform is applied to each of the n qubits.\n ApplyToEachA(H, qubits);\n } apply {\n // we now apply the dual function of the unshifted function, i.e.,\n // Ufstar, to the n qubits, computing |x〉 -> (-1)^{fstar(x)} |x〉.\n Ufstar(qubits);\n }\n\n // Measure the n qubits and reset them to zero so that they can be\n // safely deallocated at the end of the block.\n return ForEach(MResetZ, qubits);\n }\n\n /// # Summary\n /// Implements an oracle for a bent function constructed from the inner\n /// product of Boolean functions.\n ///\n /// # Description\n /// This operation defines the Boolean function IP(x_0, ..., x_{n-1}) which\n /// is computed into the phase, i.e., a diagonal operator that maps\n /// |x〉 -> (-1)^{IP(x)} |x〉, where x stands for x=(x_0, ..., x_{n-1}) and all\n /// the x_i are binary. The IP function is defined as\n /// IP(y, z) = y_0 z_0 + y_1 z_1 + ... y_{u-1} z_{u-1} where\n /// y = (y_0, ..., y_{u-1}) and z = (z_0, ..., z_{u-1}) are two bit vectors\n /// of length u. Notice that the function IP is a Boolean function on n = 2u\n /// bits. IP is a special case of bent function. These are functions for\n /// which the Walsh-Hadamard transform is perfectly flat (in absolute\n /// value).\n /// Because of this flatness, the Walsh-Hadamard spectrum of any bent\n /// function defines a +1/-1 function, i.e., gives rise to another Boolean\n /// function, called the dual bent function. Moreover, for the case of the\n /// IP function it can be shown that IP is equal to its own dual bent\n /// function.\n ///\n /// # Remarks\n /// Notice that a diagonal operator implementing IP between 2 variables y_0\n /// and z_0 is nothing but the AND function between those variables, i.e.,\n /// in phase encoding it is computed by a Controlled-Z gate.\n /// Extending this to an XOR of the AND of more variables, as required in\n /// the definition of the IP function can then be accomplished by applying\n /// several Controlled-Z gates between the respective inputs.\n operation BentFunction(register : Qubit[]) : Unit {\n Fact(Length(register) % 2 == 0, \"Length of register must be even.\");\n let u = Length(register) / 2;\n let xs = register[0..u - 1];\n let ys = register[u...];\n for index in 0..u - 1 {\n CZ(xs[index], ys[index]);\n }\n }\n\n /// # Summary\n /// Implements a shifted bend function 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠).\n ///\n /// # Description\n /// For the hidden shift problem we need another function g which is related\n /// to IP via g(x) = IP(x + s), i.e., we have to shift the argument of the\n /// IP function by a given shift. Notice that the '+' operation here is the\n /// Boolean addition, i.e., a bit-wise operation. Notice further, that in\n /// general a diagonal operation |x〉 -> (-1)^{f(x)} can be turned into a\n /// shifted version by applying a bit flip to the |x〉 register first, then\n /// applying the diagonal operation, and then undoing the bit flips to the\n /// |x〉 register. We use this principle to define shifted versions of the IP\n /// operation.\n operation ShiftedBentFunction(shift : Int, register : Qubit[]) : Unit {\n Fact(Length(register) % 2 == 0, \"Length of register must be even.\");\n let u = Length(register) / 2;\n within {\n // Flips the bits in shift.\n ApplyXorInPlace(shift, register);\n } apply {\n // Compute the IP function into the phase.\n BentFunction(register);\n }\n }\n}\n"
70
+ "code": "/// # Sample\n/// Hidden shift\n///\n/// # Description\n/// There is a family of problems known as hidden shift problems, in which it\n/// is given that two Boolean functions 𝑓 and 𝑔 satisfy the relation\n/// 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠) for all 𝑥\n/// where 𝑠 is a hidden bit string that we would like to find.\n///\n/// This Q# program implements an algorithm to solve the hidden shift problem.\nnamespace Sample {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation Main() : Result[] {\n // Consider the case of finding a hidden shift 𝑠 between two Boolean\n // functions 𝑓(𝑥) and 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠).\n // This problem can be solved on a quantum computer with one call to\n // each of 𝑓 and 𝑔 in the special case that both functions are bent;\n // that is, that they are as far from linear as possible.\n\n // Here, we find the hidden shift encoded in the following array of\n // Booleans.\n let shiftAsBoolArray = [true, false, false, false, false, true];\n let shiftAsInt = BoolArrayAsInt(shiftAsBoolArray);\n let hiddenShiftBitString = FindHiddenShift(\n BentFunction,\n register => ShiftedBentFunction(shiftAsInt, register),\n Length(shiftAsBoolArray)\n );\n\n return hiddenShiftBitString;\n }\n\n /// # Summary\n /// Implements a correlation-based algorithm to solve the hidden shift\n /// problem for bent functions.\n ///\n /// # Description\n /// Implements a solution for the hidden shift problem, which is to identify\n /// an unknown shift 𝑠 of the arguments of two Boolean functions 𝑓 and 𝑔\n /// that are promised to satisfy the relation 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠) for all 𝑥.\n ///\n /// 𝑓 and 𝑔 are assumed to be bent functions. A Boolean function is bent if\n /// it is as far from linear as possible. In particular, bent functions have\n /// flat Fourier (Walsh–Hadamard) spectra.\n ///\n /// In this case, the Roetteler algorithm (see References, below) uses\n /// black-box oracles for 𝑓^* and 𝑔, where 𝑓^* is the dual bent function to\n /// 𝑓, and computes the hidden shift 𝑠 between 𝑓 and 𝑔.\n ///\n /// # Input\n /// ## Ufstar\n /// A quantum operation that implements\n /// $U_f^*: |𝑥〉 ↦ (-1)^{f^*(x)} |𝑥〉$,\n /// where $f^*$ is a Boolean function, 𝑥 is an $n$ bit register\n /// ## Ug\n /// A quantum operation that implements\n /// $U_g:|𝑥〉 ↦ (-1)^{g(x)} |𝑥〉$,\n /// where 𝑔 is a Boolean function that is shifted by unknown\n /// 𝑠 from 𝑓, and 𝑥 is an $n$ bit register.\n /// ## n\n /// The number of bits of the input register |𝑥〉.\n ///\n /// # Output\n /// An array of type `Result[]` which encodes the bit representation\n /// of the hidden shift.\n ///\n /// # References\n /// - [*Martin Roetteler*,\n /// Proc. SODA 2010, ACM, pp. 448-457, 2010]\n /// (https://doi.org/10.1137/1.9781611973075.37)\n operation FindHiddenShift(\n Ufstar : (Qubit[] => Unit),\n Ug : (Qubit[] => Unit),\n n : Int\n ) : Result[] {\n // We allocate n clean qubits. Note that the function Ufstar and Ug are\n // unitary operations on n qubits defined via phase encoding.\n use qubits = Qubit[n];\n\n // First, a Hadamard transform is applied to each of the qubits.\n ApplyToEach(H, qubits);\n\n // We now apply the shifted function Ug to the n qubits, computing\n // |x〉 -> (-1)^{g(x)} |x〉.\n Ug(qubits);\n\n within {\n // A Hadamard transform is applied to each of the n qubits.\n ApplyToEachA(H, qubits);\n } apply {\n // we now apply the dual function of the unshifted function, i.e.,\n // Ufstar, to the n qubits, computing |x〉 -> (-1)^{fstar(x)} |x〉.\n Ufstar(qubits);\n }\n\n // Measure the n qubits and reset them to zero so that they can be\n // safely deallocated at the end of the block.\n return MResetEachZ(qubits);\n }\n\n /// # Summary\n /// Implements an oracle for a bent function constructed from the inner\n /// product of Boolean functions.\n ///\n /// # Description\n /// This operation defines the Boolean function IP(x_0, ..., x_{n-1}) which\n /// is computed into the phase, i.e., a diagonal operator that maps\n /// |x〉 -> (-1)^{IP(x)} |x〉, where x stands for x=(x_0, ..., x_{n-1}) and all\n /// the x_i are binary. The IP function is defined as\n /// IP(y, z) = y_0 z_0 + y_1 z_1 + ... y_{u-1} z_{u-1} where\n /// y = (y_0, ..., y_{u-1}) and z = (z_0, ..., z_{u-1}) are two bit vectors\n /// of length u. Notice that the function IP is a Boolean function on n = 2u\n /// bits. IP is a special case of bent function. These are functions for\n /// which the Walsh-Hadamard transform is perfectly flat (in absolute\n /// value).\n /// Because of this flatness, the Walsh-Hadamard spectrum of any bent\n /// function defines a +1/-1 function, i.e., gives rise to another Boolean\n /// function, called the dual bent function. Moreover, for the case of the\n /// IP function it can be shown that IP is equal to its own dual bent\n /// function.\n ///\n /// # Remarks\n /// Notice that a diagonal operator implementing IP between 2 variables y_0\n /// and z_0 is nothing but the AND function between those variables, i.e.,\n /// in phase encoding it is computed by a Controlled-Z gate.\n /// Extending this to an XOR of the AND of more variables, as required in\n /// the definition of the IP function can then be accomplished by applying\n /// several Controlled-Z gates between the respective inputs.\n operation BentFunction(register : Qubit[]) : Unit {\n Fact(Length(register) % 2 == 0, \"Length of register must be even.\");\n let u = Length(register) / 2;\n let xs = register[0..u - 1];\n let ys = register[u...];\n for index in 0..u - 1 {\n CZ(xs[index], ys[index]);\n }\n }\n\n /// # Summary\n /// Implements a shifted bend function 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠).\n ///\n /// # Description\n /// For the hidden shift problem we need another function g which is related\n /// to IP via g(x) = IP(x + s), i.e., we have to shift the argument of the\n /// IP function by a given shift. Notice that the '+' operation here is the\n /// Boolean addition, i.e., a bit-wise operation. Notice further, that in\n /// general a diagonal operation |x〉 -> (-1)^{f(x)} can be turned into a\n /// shifted version by applying a bit flip to the |x〉 register first, then\n /// applying the diagonal operation, and then undoing the bit flips to the\n /// |x〉 register. We use this principle to define shifted versions of the IP\n /// operation.\n operation ShiftedBentFunction(shift : Int, register : Qubit[]) : Unit {\n Fact(Length(register) % 2 == 0, \"Length of register must be even.\");\n let u = Length(register) / 2;\n within {\n // Flips the bits in shift.\n ApplyXorInPlace(shift, register);\n } apply {\n // Compute the IP function into the phase.\n BentFunction(register);\n }\n }\n}\n"
71
71
  },
72
72
  {
73
73
  "title": "Hidden Shift (Advanced)",
74
74
  "shots": 1,
75
- "code": "/// # Sample\n/// Hidden shift\n///\n/// # Description\n/// There is a family of problems known as hidden shift problems, in which it\n/// is given that two Boolean functions 𝑓 and 𝑔 satisfy the relation\n/// 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠) for all 𝑥\n/// where 𝑠 is a hidden bit string that we would like to find.\n///\n/// This Q# program implements an algorithm to solve the hidden shift problem.\nnamespace Sample {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation Main() : Int[] {\n let nQubits = 10;\n\n // Consider the case of finding a hidden shift 𝑠 between two Boolean\n // functions 𝑓(𝑥) and 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠).\n // This problem can be solved on a quantum computer with one call to\n // each of 𝑓 and 𝑔 in the special case that both functions are bent;\n // that is, that they are as far from linear as possible.\n\n // Here, we find the hidden shift for various pairs of bent functions.\n let shifts = [170, 512, 999];\n mutable hiddenShifts = [];\n for shift in shifts {\n let hiddenShiftBitString = FindHiddenShift(\n BentFunction,\n register => ShiftedBentFunction(shift, register),\n nQubits\n );\n let hiddenShift = ResultArrayAsInt(hiddenShiftBitString);\n Fact(\n hiddenShift == shift,\n $\"Found shift {hiddenShift}, but expected {shift}.\"\n );\n Message($\"Found {shift} successfully!\");\n set hiddenShifts += [hiddenShift];\n }\n\n return hiddenShifts;\n }\n\n /// # Summary\n /// Implements a correlation-based algorithm to solve the hidden shift\n /// problem for bent functions.\n ///\n /// # Description\n /// Implements a solution for the hidden shift problem, which is to identify\n /// an unknown shift 𝑠 of the arguments of two Boolean functions 𝑓 and 𝑔\n /// that are promised to satisfy the relation 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠) for all 𝑥.\n ///\n /// 𝑓 and 𝑔 are assumed to be bent functions. A Boolean function is bent if\n /// it is as far from linear as possible. In particular, bent functions have\n /// flat Fourier (Walsh–Hadamard) spectra.\n ///\n /// In this case, the Roetteler algorithm (see References, below) uses\n /// black-box oracles for 𝑓^* and 𝑔, where 𝑓^* is the dual bent function to\n /// 𝑓, and computes the hidden shift 𝑠 between 𝑓 and 𝑔.\n ///\n /// # Input\n /// ## Ufstar\n /// A quantum operation that implements\n /// $U_f^*: |𝑥〉 ↦ (-1)^{f^*(x)} |𝑥〉$,\n /// where $f^*$ is a Boolean function, 𝑥 is an $n$ bit register\n /// ## Ug\n /// A quantum operation that implements\n /// $U_g:|𝑥〉 ↦ (-1)^{g(x)} |𝑥〉$,\n /// where 𝑔 is a Boolean function that is shifted by unknown\n /// 𝑠 from 𝑓, and 𝑥 is an $n$ bit register.\n /// ## n\n /// The number of bits of the input register |𝑥〉.\n ///\n /// # Output\n /// An array of type `Result[]` which encodes the bit representation\n /// of the hidden shift.\n ///\n /// # References\n /// - [*Martin Roetteler*,\n /// Proc. SODA 2010, ACM, pp. 448-457, 2010]\n /// (https://doi.org/10.1137/1.9781611973075.37)\n operation FindHiddenShift(\n Ufstar : (Qubit[] => Unit),\n Ug : (Qubit[] => Unit),\n n : Int\n ) : Result[] {\n // We allocate n clean qubits. Note that the function Ufstar and Ug are\n // unitary operations on n qubits defined via phase encoding.\n use qubits = Qubit[n];\n\n // First, a Hadamard transform is applied to each of the qubits.\n ApplyToEach(H, qubits);\n\n // We now apply the shifted function Ug to the n qubits, computing\n // |x〉 -> (-1)^{g(x)} |x〉.\n Ug(qubits);\n\n within {\n // A Hadamard transform is applied to each of the n qubits.\n ApplyToEachA(H, qubits);\n } apply {\n // we now apply the dual function of the unshifted function, i.e.,\n // Ufstar, to the n qubits, computing |x〉 -> (-1)^{fstar(x)} |x〉.\n Ufstar(qubits);\n }\n\n // Measure the n qubits and reset them to zero so that they can be\n // safely deallocated at the end of the block.\n return ForEach(MResetZ, qubits);\n }\n\n /// # Summary\n /// Implements an oracle for a bent function constructed from the inner\n /// product of Boolean functions.\n ///\n /// # Description\n /// This operation defines the Boolean function IP(x_0, ..., x_{n-1}) which\n /// is computed into the phase, i.e., a diagonal operator that maps\n /// |x〉 -> (-1)^{IP(x)} |x〉, where x stands for x=(x_0, ..., x_{n-1}) and all\n /// the x_i are binary. The IP function is defined as\n /// IP(y, z) = y_0 z_0 + y_1 z_1 + ... y_{u-1} z_{u-1} where\n /// y = (y_0, ..., y_{u-1}) and z = (z_0, ..., z_{u-1}) are two bit vectors\n /// of length u. Notice that the function IP is a Boolean function on n = 2u\n /// bits. IP is a special case of bent function. These are functions for\n /// which the Walsh-Hadamard transform is perfectly flat (in absolute\n /// value).\n /// Because of this flatness, the Walsh-Hadamard spectrum of any bent\n /// function defines a +1/-1 function, i.e., gives rise to another Boolean\n /// function, called the dual bent function. Moreover, for the case of the\n /// IP function it can be shown that IP is equal to its own dual bent\n /// function.\n ///\n /// # Remarks\n /// Notice that a diagonal operator implementing IP between 2 variables y_0\n /// and z_0 is nothing but the AND function between those variables, i.e.,\n /// in phase encoding it is computed by a Controlled-Z gate.\n /// Extending this to an XOR of the AND of more variables, as required in\n /// the definition of the IP function can then be accomplished by applying\n /// several Controlled-Z gates between the respective inputs.\n operation BentFunction(register : Qubit[]) : Unit {\n Fact(Length(register) % 2 == 0, \"Length of register must be even.\");\n let u = Length(register) / 2;\n let xs = register[0..u - 1];\n let ys = register[u...];\n for index in 0..u - 1 {\n CZ(xs[index], ys[index]);\n }\n }\n\n /// # Summary\n /// Implements a shifted bend function 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠).\n ///\n /// # Description\n /// For the hidden shift problem we need another function g which is related\n /// to IP via g(x) = IP(x + s), i.e., we have to shift the argument of the\n /// IP function by a given shift. Notice that the '+' operation here is the\n /// Boolean addition, i.e., a bit-wise operation. Notice further, that in\n /// general a diagonal operation |x〉 -> (-1)^{f(x)} can be turned into a\n /// shifted version by applying a bit flip to the |x〉 register first, then\n /// applying the diagonal operation, and then undoing the bit flips to the\n /// |x〉 register. We use this principle to define shifted versions of the IP\n /// operation.\n operation ShiftedBentFunction(shift : Int, register : Qubit[]) : Unit {\n Fact(Length(register) % 2 == 0, \"Length of register must be even.\");\n let u = Length(register) / 2;\n within {\n // Flips the bits in shift.\n ApplyXorInPlace(shift, register);\n } apply {\n // Compute the IP function into the phase.\n BentFunction(register);\n }\n }\n}\n"
75
+ "code": "/// # Sample\n/// Hidden shift\n///\n/// # Description\n/// There is a family of problems known as hidden shift problems, in which it\n/// is given that two Boolean functions 𝑓 and 𝑔 satisfy the relation\n/// 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠) for all 𝑥\n/// where 𝑠 is a hidden bit string that we would like to find.\n///\n/// This Q# program implements an algorithm to solve the hidden shift problem.\nnamespace Sample {\n open Microsoft.Quantum.Arrays;\n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Measurement;\n\n @EntryPoint()\n operation Main() : Int[] {\n let nQubits = 10;\n\n // Consider the case of finding a hidden shift 𝑠 between two Boolean\n // functions 𝑓(𝑥) and 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠).\n // This problem can be solved on a quantum computer with one call to\n // each of 𝑓 and 𝑔 in the special case that both functions are bent;\n // that is, that they are as far from linear as possible.\n\n // Here, we find the hidden shift for various pairs of bent functions.\n let shifts = [170, 512, 999];\n mutable hiddenShifts = [];\n for shift in shifts {\n let hiddenShiftBitString = FindHiddenShift(\n BentFunction,\n register => ShiftedBentFunction(shift, register),\n nQubits\n );\n let hiddenShift = ResultArrayAsInt(hiddenShiftBitString);\n Fact(\n hiddenShift == shift,\n $\"Found shift {hiddenShift}, but expected {shift}.\"\n );\n Message($\"Found {shift} successfully!\");\n set hiddenShifts += [hiddenShift];\n }\n\n return hiddenShifts;\n }\n\n /// # Summary\n /// Implements a correlation-based algorithm to solve the hidden shift\n /// problem for bent functions.\n ///\n /// # Description\n /// Implements a solution for the hidden shift problem, which is to identify\n /// an unknown shift 𝑠 of the arguments of two Boolean functions 𝑓 and 𝑔\n /// that are promised to satisfy the relation 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠) for all 𝑥.\n ///\n /// 𝑓 and 𝑔 are assumed to be bent functions. A Boolean function is bent if\n /// it is as far from linear as possible. In particular, bent functions have\n /// flat Fourier (Walsh–Hadamard) spectra.\n ///\n /// In this case, the Roetteler algorithm (see References, below) uses\n /// black-box oracles for 𝑓^* and 𝑔, where 𝑓^* is the dual bent function to\n /// 𝑓, and computes the hidden shift 𝑠 between 𝑓 and 𝑔.\n ///\n /// # Input\n /// ## Ufstar\n /// A quantum operation that implements\n /// $U_f^*: |𝑥〉 ↦ (-1)^{f^*(x)} |𝑥〉$,\n /// where $f^*$ is a Boolean function, 𝑥 is an $n$ bit register\n /// ## Ug\n /// A quantum operation that implements\n /// $U_g:|𝑥〉 ↦ (-1)^{g(x)} |𝑥〉$,\n /// where 𝑔 is a Boolean function that is shifted by unknown\n /// 𝑠 from 𝑓, and 𝑥 is an $n$ bit register.\n /// ## n\n /// The number of bits of the input register |𝑥〉.\n ///\n /// # Output\n /// An array of type `Result[]` which encodes the bit representation\n /// of the hidden shift.\n ///\n /// # References\n /// - [*Martin Roetteler*,\n /// Proc. SODA 2010, ACM, pp. 448-457, 2010]\n /// (https://doi.org/10.1137/1.9781611973075.37)\n operation FindHiddenShift(\n Ufstar : (Qubit[] => Unit),\n Ug : (Qubit[] => Unit),\n n : Int\n ) : Result[] {\n // We allocate n clean qubits. Note that the function Ufstar and Ug are\n // unitary operations on n qubits defined via phase encoding.\n use qubits = Qubit[n];\n\n // First, a Hadamard transform is applied to each of the qubits.\n ApplyToEach(H, qubits);\n\n // We now apply the shifted function Ug to the n qubits, computing\n // |x〉 -> (-1)^{g(x)} |x〉.\n Ug(qubits);\n\n within {\n // A Hadamard transform is applied to each of the n qubits.\n ApplyToEachA(H, qubits);\n } apply {\n // we now apply the dual function of the unshifted function, i.e.,\n // Ufstar, to the n qubits, computing |x〉 -> (-1)^{fstar(x)} |x〉.\n Ufstar(qubits);\n }\n\n // Measure the n qubits and reset them to zero so that they can be\n // safely deallocated at the end of the block.\n return MResetEachZ(qubits);\n }\n\n /// # Summary\n /// Implements an oracle for a bent function constructed from the inner\n /// product of Boolean functions.\n ///\n /// # Description\n /// This operation defines the Boolean function IP(x_0, ..., x_{n-1}) which\n /// is computed into the phase, i.e., a diagonal operator that maps\n /// |x〉 -> (-1)^{IP(x)} |x〉, where x stands for x=(x_0, ..., x_{n-1}) and all\n /// the x_i are binary. The IP function is defined as\n /// IP(y, z) = y_0 z_0 + y_1 z_1 + ... y_{u-1} z_{u-1} where\n /// y = (y_0, ..., y_{u-1}) and z = (z_0, ..., z_{u-1}) are two bit vectors\n /// of length u. Notice that the function IP is a Boolean function on n = 2u\n /// bits. IP is a special case of bent function. These are functions for\n /// which the Walsh-Hadamard transform is perfectly flat (in absolute\n /// value).\n /// Because of this flatness, the Walsh-Hadamard spectrum of any bent\n /// function defines a +1/-1 function, i.e., gives rise to another Boolean\n /// function, called the dual bent function. Moreover, for the case of the\n /// IP function it can be shown that IP is equal to its own dual bent\n /// function.\n ///\n /// # Remarks\n /// Notice that a diagonal operator implementing IP between 2 variables y_0\n /// and z_0 is nothing but the AND function between those variables, i.e.,\n /// in phase encoding it is computed by a Controlled-Z gate.\n /// Extending this to an XOR of the AND of more variables, as required in\n /// the definition of the IP function can then be accomplished by applying\n /// several Controlled-Z gates between the respective inputs.\n operation BentFunction(register : Qubit[]) : Unit {\n Fact(Length(register) % 2 == 0, \"Length of register must be even.\");\n let u = Length(register) / 2;\n let xs = register[0..u - 1];\n let ys = register[u...];\n for index in 0..u - 1 {\n CZ(xs[index], ys[index]);\n }\n }\n\n /// # Summary\n /// Implements a shifted bend function 𝑔(𝑥) = 𝑓(𝑥 ⊕ 𝑠).\n ///\n /// # Description\n /// For the hidden shift problem we need another function g which is related\n /// to IP via g(x) = IP(x + s), i.e., we have to shift the argument of the\n /// IP function by a given shift. Notice that the '+' operation here is the\n /// Boolean addition, i.e., a bit-wise operation. Notice further, that in\n /// general a diagonal operation |x〉 -> (-1)^{f(x)} can be turned into a\n /// shifted version by applying a bit flip to the |x〉 register first, then\n /// applying the diagonal operation, and then undoing the bit flips to the\n /// |x〉 register. We use this principle to define shifted versions of the IP\n /// operation.\n operation ShiftedBentFunction(shift : Int, register : Qubit[]) : Unit {\n Fact(Length(register) % 2 == 0, \"Length of register must be even.\");\n let u = Length(register) / 2;\n within {\n // Flips the bits in shift.\n ApplyXorInPlace(shift, register);\n } apply {\n // Compute the IP function into the phase.\n BentFunction(register);\n }\n }\n}\n"
76
76
  },
77
77
  {
78
78
  "title": "Shor",
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.All
3
3
  title: All function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Any
3
3
  title: Any function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Chunks
3
3
  title: Chunks function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.CircularlyShifted
3
3
  title: CircularlyShifted function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.ColumnAt
3
3
  title: ColumnAt function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Count
3
3
  title: Count function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Diagonal
3
3
  title: Diagonal function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.DrawMany
3
3
  title: DrawMany operation
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: operation
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Enumerated
3
3
  title: Enumerated function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Excluding
3
3
  title: Excluding function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Filtered
3
3
  title: Filtered function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.FlatMapped
3
3
  title: FlatMapped function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Flattened
3
3
  title: Flattened function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Fold
3
3
  title: Fold function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.ForEach
3
3
  title: ForEach operation
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: operation
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Head
3
3
  title: Head function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.HeadAndRest
3
3
  title: HeadAndRest function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.IndexOf
3
3
  title: IndexOf function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.IndexRange
3
3
  title: IndexRange function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Interleaved
3
3
  title: Interleaved function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.IsEmpty
3
3
  title: IsEmpty function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.IsRectangularArray
3
3
  title: IsRectangularArray function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.IsSorted
3
3
  title: IsSorted function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.IsSquareArray
3
3
  title: IsSquareArray function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Mapped
3
3
  title: Mapped function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.MappedByIndex
3
3
  title: MappedByIndex function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.MappedOverRange
3
3
  title: MappedOverRange function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Most
3
3
  title: Most function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.MostAndTail
3
3
  title: MostAndTail function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Padded
3
3
  title: Padded function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Partitioned
3
3
  title: Partitioned function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Rest
3
3
  title: Rest function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.Reversed
3
3
  title: Reversed function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.SequenceI
3
3
  title: SequenceI function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  uid: Qdk.Microsoft.Quantum.Arrays.SequenceL
3
3
  title: SequenceL function
4
- ms.date: 04/23/2024 12:00:00 AM
4
+ ms.date: 05/14/2024 12:00:00 AM
5
5
  ms.topic: managed-reference
6
6
  qsharp.kind: function
7
7
  qsharp.namespace: Microsoft.Quantum.Arrays