qsharp-lang 1.3.0 → 1.3.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 (275) hide show
  1. package/dist/browser.d.ts +4 -6
  2. package/dist/browser.js +1 -1
  3. package/dist/compiler/compiler.d.ts +3 -1
  4. package/dist/compiler/compiler.js +4 -0
  5. package/dist/katas-content.generated.js +555 -3
  6. package/docs/Microsoft.Quantum.Arrays/All.md +1 -1
  7. package/docs/Microsoft.Quantum.Arrays/Any.md +1 -1
  8. package/docs/Microsoft.Quantum.Arrays/Chunks.md +1 -1
  9. package/docs/Microsoft.Quantum.Arrays/CircularlyShifted.md +1 -1
  10. package/docs/Microsoft.Quantum.Arrays/ColumnAt.md +1 -1
  11. package/docs/Microsoft.Quantum.Arrays/Count.md +1 -1
  12. package/docs/Microsoft.Quantum.Arrays/Diagonal.md +1 -1
  13. package/docs/Microsoft.Quantum.Arrays/DrawMany.md +1 -1
  14. package/docs/Microsoft.Quantum.Arrays/Enumerated.md +1 -1
  15. package/docs/Microsoft.Quantum.Arrays/Excluding.md +1 -1
  16. package/docs/Microsoft.Quantum.Arrays/Filtered.md +1 -1
  17. package/docs/Microsoft.Quantum.Arrays/FlatMapped.md +1 -1
  18. package/docs/Microsoft.Quantum.Arrays/Flattened.md +1 -1
  19. package/docs/Microsoft.Quantum.Arrays/Fold.md +1 -1
  20. package/docs/Microsoft.Quantum.Arrays/ForEach.md +1 -1
  21. package/docs/Microsoft.Quantum.Arrays/Head.md +1 -1
  22. package/docs/Microsoft.Quantum.Arrays/HeadAndRest.md +1 -1
  23. package/docs/Microsoft.Quantum.Arrays/IndexOf.md +1 -1
  24. package/docs/Microsoft.Quantum.Arrays/IndexRange.md +1 -1
  25. package/docs/Microsoft.Quantum.Arrays/Interleaved.md +1 -1
  26. package/docs/Microsoft.Quantum.Arrays/IsEmpty.md +1 -1
  27. package/docs/Microsoft.Quantum.Arrays/IsRectangularArray.md +1 -1
  28. package/docs/Microsoft.Quantum.Arrays/IsSorted.md +1 -1
  29. package/docs/Microsoft.Quantum.Arrays/IsSquareArray.md +1 -1
  30. package/docs/Microsoft.Quantum.Arrays/Mapped.md +1 -1
  31. package/docs/Microsoft.Quantum.Arrays/MappedByIndex.md +1 -1
  32. package/docs/Microsoft.Quantum.Arrays/MappedOverRange.md +1 -1
  33. package/docs/Microsoft.Quantum.Arrays/Most.md +1 -1
  34. package/docs/Microsoft.Quantum.Arrays/MostAndTail.md +1 -1
  35. package/docs/Microsoft.Quantum.Arrays/Padded.md +1 -1
  36. package/docs/Microsoft.Quantum.Arrays/Partitioned.md +1 -1
  37. package/docs/Microsoft.Quantum.Arrays/Rest.md +1 -1
  38. package/docs/Microsoft.Quantum.Arrays/Reversed.md +1 -1
  39. package/docs/Microsoft.Quantum.Arrays/SequenceI.md +1 -1
  40. package/docs/Microsoft.Quantum.Arrays/SequenceL.md +1 -1
  41. package/docs/Microsoft.Quantum.Arrays/Sorted.md +1 -1
  42. package/docs/Microsoft.Quantum.Arrays/Subarray.md +1 -1
  43. package/docs/Microsoft.Quantum.Arrays/Swapped.md +1 -1
  44. package/docs/Microsoft.Quantum.Arrays/Tail.md +1 -1
  45. package/docs/Microsoft.Quantum.Arrays/Transposed.md +1 -1
  46. package/docs/Microsoft.Quantum.Arrays/Unzipped.md +1 -1
  47. package/docs/Microsoft.Quantum.Arrays/Where.md +1 -1
  48. package/docs/Microsoft.Quantum.Arrays/Windows.md +1 -1
  49. package/docs/Microsoft.Quantum.Arrays/Zipped.md +1 -1
  50. package/docs/Microsoft.Quantum.Canon/ApplyCNOTChain.md +1 -1
  51. package/docs/Microsoft.Quantum.Canon/ApplyControlledOnBitString.md +1 -1
  52. package/docs/Microsoft.Quantum.Canon/ApplyControlledOnInt.md +1 -1
  53. package/docs/Microsoft.Quantum.Canon/ApplyP.md +1 -1
  54. package/docs/Microsoft.Quantum.Canon/ApplyPauli.md +1 -1
  55. package/docs/Microsoft.Quantum.Canon/ApplyPauliFromBitString.md +1 -1
  56. package/docs/Microsoft.Quantum.Canon/ApplyPauliFromInt.md +1 -1
  57. package/docs/Microsoft.Quantum.Canon/ApplyQFT.md +1 -1
  58. package/docs/Microsoft.Quantum.Canon/ApplyToEach.md +1 -1
  59. package/docs/Microsoft.Quantum.Canon/ApplyToEachA.md +1 -1
  60. package/docs/Microsoft.Quantum.Canon/ApplyToEachC.md +1 -1
  61. package/docs/Microsoft.Quantum.Canon/ApplyToEachCA.md +1 -1
  62. package/docs/Microsoft.Quantum.Canon/ApplyXorInPlace.md +1 -1
  63. package/docs/Microsoft.Quantum.Canon/ApplyXorInPlaceL.md +1 -1
  64. package/docs/Microsoft.Quantum.Canon/CX.md +1 -1
  65. package/docs/Microsoft.Quantum.Canon/CY.md +1 -1
  66. package/docs/Microsoft.Quantum.Canon/CZ.md +1 -1
  67. package/docs/Microsoft.Quantum.Canon/Fst.md +1 -1
  68. package/docs/Microsoft.Quantum.Canon/Snd.md +1 -1
  69. package/docs/Microsoft.Quantum.Canon/SwapReverseRegister.md +1 -1
  70. package/docs/Microsoft.Quantum.Convert/BigIntAsBoolArray.md +1 -1
  71. package/docs/Microsoft.Quantum.Convert/BoolArrayAsBigInt.md +1 -1
  72. package/docs/Microsoft.Quantum.Convert/BoolArrayAsInt.md +1 -1
  73. package/docs/Microsoft.Quantum.Convert/BoolArrayAsResultArray.md +1 -1
  74. package/docs/Microsoft.Quantum.Convert/BoolAsResult.md +1 -1
  75. package/docs/Microsoft.Quantum.Convert/ComplexAsComplexPolar.md +1 -1
  76. package/docs/Microsoft.Quantum.Convert/ComplexPolarAsComplex.md +1 -1
  77. package/docs/Microsoft.Quantum.Convert/IntAsBigInt.md +1 -1
  78. package/docs/Microsoft.Quantum.Convert/IntAsBoolArray.md +1 -1
  79. package/docs/Microsoft.Quantum.Convert/IntAsDouble.md +1 -1
  80. package/docs/Microsoft.Quantum.Convert/ResultArrayAsBoolArray.md +1 -1
  81. package/docs/Microsoft.Quantum.Convert/ResultArrayAsInt.md +1 -1
  82. package/docs/Microsoft.Quantum.Convert/ResultAsBool.md +1 -1
  83. package/docs/Microsoft.Quantum.Core/IsRangeEmpty.md +1 -1
  84. package/docs/Microsoft.Quantum.Core/Length.md +1 -1
  85. package/docs/Microsoft.Quantum.Core/RangeEnd.md +1 -1
  86. package/docs/Microsoft.Quantum.Core/RangeReverse.md +1 -1
  87. package/docs/Microsoft.Quantum.Core/RangeStart.md +1 -1
  88. package/docs/Microsoft.Quantum.Core/RangeStep.md +1 -1
  89. package/docs/Microsoft.Quantum.Core/Repeated.md +1 -1
  90. package/docs/Microsoft.Quantum.Diagnostics/CheckAllZero.md +1 -1
  91. package/docs/Microsoft.Quantum.Diagnostics/CheckOperationsAreEqual.md +1 -1
  92. package/docs/Microsoft.Quantum.Diagnostics/CheckZero.md +1 -1
  93. package/docs/Microsoft.Quantum.Diagnostics/DumpMachine.md +1 -1
  94. package/docs/Microsoft.Quantum.Diagnostics/DumpRegister.md +1 -1
  95. package/docs/Microsoft.Quantum.Diagnostics/Fact.md +1 -1
  96. package/docs/Microsoft.Quantum.Intrinsic/CCNOT.md +1 -1
  97. package/docs/Microsoft.Quantum.Intrinsic/CNOT.md +1 -1
  98. package/docs/Microsoft.Quantum.Intrinsic/Exp.md +1 -1
  99. package/docs/Microsoft.Quantum.Intrinsic/H.md +1 -1
  100. package/docs/Microsoft.Quantum.Intrinsic/I.md +1 -1
  101. package/docs/Microsoft.Quantum.Intrinsic/M.md +1 -1
  102. package/docs/Microsoft.Quantum.Intrinsic/Measure.md +1 -1
  103. package/docs/Microsoft.Quantum.Intrinsic/Message.md +1 -1
  104. package/docs/Microsoft.Quantum.Intrinsic/R.md +1 -1
  105. package/docs/Microsoft.Quantum.Intrinsic/R1.md +1 -1
  106. package/docs/Microsoft.Quantum.Intrinsic/R1Frac.md +1 -1
  107. package/docs/Microsoft.Quantum.Intrinsic/RFrac.md +1 -1
  108. package/docs/Microsoft.Quantum.Intrinsic/Reset.md +1 -1
  109. package/docs/Microsoft.Quantum.Intrinsic/ResetAll.md +1 -1
  110. package/docs/Microsoft.Quantum.Intrinsic/Rx.md +1 -1
  111. package/docs/Microsoft.Quantum.Intrinsic/Rxx.md +1 -1
  112. package/docs/Microsoft.Quantum.Intrinsic/Ry.md +1 -1
  113. package/docs/Microsoft.Quantum.Intrinsic/Ryy.md +1 -1
  114. package/docs/Microsoft.Quantum.Intrinsic/Rz.md +1 -1
  115. package/docs/Microsoft.Quantum.Intrinsic/Rzz.md +1 -1
  116. package/docs/Microsoft.Quantum.Intrinsic/S.md +1 -1
  117. package/docs/Microsoft.Quantum.Intrinsic/SWAP.md +1 -1
  118. package/docs/Microsoft.Quantum.Intrinsic/T.md +1 -1
  119. package/docs/Microsoft.Quantum.Intrinsic/X.md +1 -1
  120. package/docs/Microsoft.Quantum.Intrinsic/Y.md +1 -1
  121. package/docs/Microsoft.Quantum.Intrinsic/Z.md +1 -1
  122. package/docs/Microsoft.Quantum.Logical/Xor.md +1 -1
  123. package/docs/Microsoft.Quantum.Math/AbsComplex.md +1 -1
  124. package/docs/Microsoft.Quantum.Math/AbsComplexPolar.md +1 -1
  125. package/docs/Microsoft.Quantum.Math/AbsD.md +1 -1
  126. package/docs/Microsoft.Quantum.Math/AbsI.md +1 -1
  127. package/docs/Microsoft.Quantum.Math/AbsL.md +1 -1
  128. package/docs/Microsoft.Quantum.Math/AbsSquaredComplex.md +1 -1
  129. package/docs/Microsoft.Quantum.Math/AbsSquaredComplexPolar.md +1 -1
  130. package/docs/Microsoft.Quantum.Math/ApproximateFactorial.md +1 -1
  131. package/docs/Microsoft.Quantum.Math/ArcCos.md +1 -1
  132. package/docs/Microsoft.Quantum.Math/ArcCosh.md +1 -1
  133. package/docs/Microsoft.Quantum.Math/ArcSin.md +1 -1
  134. package/docs/Microsoft.Quantum.Math/ArcSinh.md +1 -1
  135. package/docs/Microsoft.Quantum.Math/ArcTan.md +1 -1
  136. package/docs/Microsoft.Quantum.Math/ArcTan2.md +1 -1
  137. package/docs/Microsoft.Quantum.Math/ArcTanh.md +1 -1
  138. package/docs/Microsoft.Quantum.Math/ArgComplex.md +1 -1
  139. package/docs/Microsoft.Quantum.Math/ArgComplexPolar.md +1 -1
  140. package/docs/Microsoft.Quantum.Math/Binom.md +1 -1
  141. package/docs/Microsoft.Quantum.Math/BitSizeI.md +1 -1
  142. package/docs/Microsoft.Quantum.Math/BitSizeL.md +1 -1
  143. package/docs/Microsoft.Quantum.Math/Ceiling.md +1 -1
  144. package/docs/Microsoft.Quantum.Math/Complex.md +1 -1
  145. package/docs/Microsoft.Quantum.Math/ComplexPolar.md +1 -1
  146. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentI.md +1 -1
  147. package/docs/Microsoft.Quantum.Math/ContinuedFractionConvergentL.md +1 -1
  148. package/docs/Microsoft.Quantum.Math/Cos.md +1 -1
  149. package/docs/Microsoft.Quantum.Math/Cosh.md +1 -1
  150. package/docs/Microsoft.Quantum.Math/DivRemI.md +1 -1
  151. package/docs/Microsoft.Quantum.Math/DivRemL.md +1 -1
  152. package/docs/Microsoft.Quantum.Math/DividedByC.md +1 -1
  153. package/docs/Microsoft.Quantum.Math/DividedByCP.md +1 -1
  154. package/docs/Microsoft.Quantum.Math/E.md +1 -1
  155. package/docs/Microsoft.Quantum.Math/ExpModI.md +1 -1
  156. package/docs/Microsoft.Quantum.Math/ExpModL.md +1 -1
  157. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorI.md +1 -1
  158. package/docs/Microsoft.Quantum.Math/ExtendedGreatestCommonDivisorL.md +1 -1
  159. package/docs/Microsoft.Quantum.Math/FactorialI.md +1 -1
  160. package/docs/Microsoft.Quantum.Math/FactorialL.md +1 -1
  161. package/docs/Microsoft.Quantum.Math/Floor.md +1 -1
  162. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorI.md +1 -1
  163. package/docs/Microsoft.Quantum.Math/GreatestCommonDivisorL.md +1 -1
  164. package/docs/Microsoft.Quantum.Math/HammingWeightI.md +1 -1
  165. package/docs/Microsoft.Quantum.Math/InverseModI.md +1 -1
  166. package/docs/Microsoft.Quantum.Math/InverseModL.md +1 -1
  167. package/docs/Microsoft.Quantum.Math/IsCoprimeI.md +1 -1
  168. package/docs/Microsoft.Quantum.Math/IsCoprimeL.md +1 -1
  169. package/docs/Microsoft.Quantum.Math/IsInfinite.md +1 -1
  170. package/docs/Microsoft.Quantum.Math/IsNaN.md +1 -1
  171. package/docs/Microsoft.Quantum.Math/LargestFixedPoint.md +1 -1
  172. package/docs/Microsoft.Quantum.Math/Lg.md +1 -1
  173. package/docs/Microsoft.Quantum.Math/Log.md +1 -1
  174. package/docs/Microsoft.Quantum.Math/Log10.md +1 -1
  175. package/docs/Microsoft.Quantum.Math/LogFactorialD.md +1 -1
  176. package/docs/Microsoft.Quantum.Math/LogGammaD.md +1 -1
  177. package/docs/Microsoft.Quantum.Math/LogOf2.md +1 -1
  178. package/docs/Microsoft.Quantum.Math/Max.md +1 -1
  179. package/docs/Microsoft.Quantum.Math/MaxD.md +1 -1
  180. package/docs/Microsoft.Quantum.Math/MaxI.md +1 -1
  181. package/docs/Microsoft.Quantum.Math/MaxL.md +1 -1
  182. package/docs/Microsoft.Quantum.Math/Min.md +1 -1
  183. package/docs/Microsoft.Quantum.Math/MinD.md +1 -1
  184. package/docs/Microsoft.Quantum.Math/MinI.md +1 -1
  185. package/docs/Microsoft.Quantum.Math/MinL.md +1 -1
  186. package/docs/Microsoft.Quantum.Math/MinusC.md +1 -1
  187. package/docs/Microsoft.Quantum.Math/MinusCP.md +1 -1
  188. package/docs/Microsoft.Quantum.Math/ModulusI.md +1 -1
  189. package/docs/Microsoft.Quantum.Math/ModulusL.md +1 -1
  190. package/docs/Microsoft.Quantum.Math/NegationC.md +1 -1
  191. package/docs/Microsoft.Quantum.Math/NegationCP.md +1 -1
  192. package/docs/Microsoft.Quantum.Math/PI.md +1 -1
  193. package/docs/Microsoft.Quantum.Math/PNorm.md +1 -1
  194. package/docs/Microsoft.Quantum.Math/PNormalized.md +1 -1
  195. package/docs/Microsoft.Quantum.Math/PlusC.md +1 -1
  196. package/docs/Microsoft.Quantum.Math/PlusCP.md +1 -1
  197. package/docs/Microsoft.Quantum.Math/PowC.md +1 -1
  198. package/docs/Microsoft.Quantum.Math/PowCP.md +1 -1
  199. package/docs/Microsoft.Quantum.Math/RealMod.md +1 -1
  200. package/docs/Microsoft.Quantum.Math/Round.md +1 -1
  201. package/docs/Microsoft.Quantum.Math/SignD.md +1 -1
  202. package/docs/Microsoft.Quantum.Math/SignI.md +1 -1
  203. package/docs/Microsoft.Quantum.Math/SignL.md +1 -1
  204. package/docs/Microsoft.Quantum.Math/Sin.md +1 -1
  205. package/docs/Microsoft.Quantum.Math/Sinh.md +1 -1
  206. package/docs/Microsoft.Quantum.Math/SmallestFixedPoint.md +1 -1
  207. package/docs/Microsoft.Quantum.Math/Sqrt.md +1 -1
  208. package/docs/Microsoft.Quantum.Math/SquaredNorm.md +1 -1
  209. package/docs/Microsoft.Quantum.Math/Tan.md +1 -1
  210. package/docs/Microsoft.Quantum.Math/Tanh.md +1 -1
  211. package/docs/Microsoft.Quantum.Math/TimesC.md +1 -1
  212. package/docs/Microsoft.Quantum.Math/TimesCP.md +1 -1
  213. package/docs/Microsoft.Quantum.Math/TrailingZeroCountI.md +1 -1
  214. package/docs/Microsoft.Quantum.Math/TrailingZeroCountL.md +1 -1
  215. package/docs/Microsoft.Quantum.Math/Truncate.md +1 -1
  216. package/docs/Microsoft.Quantum.Measurement/MResetEachZ.md +1 -1
  217. package/docs/Microsoft.Quantum.Measurement/MResetX.md +1 -1
  218. package/docs/Microsoft.Quantum.Measurement/MResetY.md +1 -1
  219. package/docs/Microsoft.Quantum.Measurement/MResetZ.md +1 -1
  220. package/docs/Microsoft.Quantum.Measurement/MeasureAllZ.md +1 -1
  221. package/docs/Microsoft.Quantum.Measurement/MeasureEachZ.md +1 -1
  222. package/docs/Microsoft.Quantum.Measurement/MeasureInteger.md +1 -1
  223. package/docs/Microsoft.Quantum.Random/DrawRandomDouble.md +1 -1
  224. package/docs/Microsoft.Quantum.Random/DrawRandomInt.md +1 -1
  225. package/docs/Microsoft.Quantum.ResourceEstimation/AccountForEstimates.md +1 -1
  226. package/docs/Microsoft.Quantum.ResourceEstimation/AuxQubitCount.md +1 -1
  227. package/docs/Microsoft.Quantum.ResourceEstimation/BeginEstimateCaching.md +1 -1
  228. package/docs/Microsoft.Quantum.ResourceEstimation/BeginRepeatEstimates.md +1 -1
  229. package/docs/Microsoft.Quantum.ResourceEstimation/CczCount.md +1 -1
  230. package/docs/Microsoft.Quantum.ResourceEstimation/EndEstimateCaching.md +1 -1
  231. package/docs/Microsoft.Quantum.ResourceEstimation/EndRepeatEstimates.md +1 -1
  232. package/docs/Microsoft.Quantum.ResourceEstimation/MeasurementCount.md +1 -1
  233. package/docs/Microsoft.Quantum.ResourceEstimation/PSSPCLayout.md +1 -1
  234. package/docs/Microsoft.Quantum.ResourceEstimation/RepeatEstimates.md +1 -1
  235. package/docs/Microsoft.Quantum.ResourceEstimation/RotationCount.md +1 -1
  236. package/docs/Microsoft.Quantum.ResourceEstimation/RotationDepth.md +1 -1
  237. package/docs/Microsoft.Quantum.ResourceEstimation/SingleVariant.md +1 -1
  238. package/docs/Microsoft.Quantum.ResourceEstimation/TCount.md +1 -1
  239. package/docs/Microsoft.Quantum.Unstable.Arithmetic/AddLE.md +1 -1
  240. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualL.md +1 -1
  241. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfEqualLE.md +1 -1
  242. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterL.md +1 -1
  243. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterLE.md +1 -1
  244. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualL.md +1 -1
  245. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfGreaterOrEqualLE.md +1 -1
  246. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessL.md +1 -1
  247. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessLE.md +1 -1
  248. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualL.md +1 -1
  249. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ApplyIfLessOrEqualLE.md +1 -1
  250. package/docs/Microsoft.Quantum.Unstable.Arithmetic/FourierTDIncByLE.md +1 -1
  251. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByI.md +1 -1
  252. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByIUsingIncByLE.md +1 -1
  253. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByL.md +1 -1
  254. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLE.md +1 -1
  255. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLEUsingAddLE.md +1 -1
  256. package/docs/Microsoft.Quantum.Unstable.Arithmetic/IncByLUsingIncByLE.md +1 -1
  257. package/docs/Microsoft.Quantum.Unstable.Arithmetic/LookAheadDKRSAddLE.md +1 -1
  258. package/docs/Microsoft.Quantum.Unstable.Arithmetic/MAJ.md +1 -1
  259. package/docs/Microsoft.Quantum.Unstable.Arithmetic/ReflectAboutInteger.md +1 -1
  260. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGAddLE.md +1 -1
  261. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryCGIncByLE.md +1 -1
  262. package/docs/Microsoft.Quantum.Unstable.Arithmetic/RippleCarryTTKIncByLE.md +1 -1
  263. package/docs/Microsoft.Quantum.Unstable.StatePreparation/ApproximatelyPreparePureStateCP.md +1 -1
  264. package/docs/Microsoft.Quantum.Unstable.StatePreparation/PreparePureStateD.md +1 -1
  265. package/docs/Microsoft.Quantum.Unstable.TableLookup/Select.md +1 -1
  266. package/lib/node/qsc_wasm.cjs +41 -4
  267. package/lib/node/qsc_wasm.d.cts +18 -2
  268. package/lib/node/qsc_wasm_bg.wasm +0 -0
  269. package/lib/web/qsc_wasm.d.ts +19 -2
  270. package/lib/web/qsc_wasm.js +40 -4
  271. package/lib/web/qsc_wasm_bg.wasm +0 -0
  272. package/package.json +1 -1
  273. package/ux/circuit.tsx +48 -0
  274. package/ux/index.ts +2 -0
  275. package/ux/qsharp-circuit.css +185 -0
@@ -59,8 +59,8 @@ export default {
59
59
  "items": [
60
60
  {
61
61
  "type": "text-content",
62
- "asHtml": "<p>This kata introduces you to complex arithmetic. This topic isn&#39;t particularly expansive, but it&#39;s important to understand it to be able to work with quantum computing.</p>\n<p>This tutorial covers the following topics:</p>\n<ul>\n<li>Imaginary and complex numbers</li>\n<li>Basic complex arithmetic</li>\n<li>Complex plane</li>\n<li>Modulus operator</li>\n<li>Imaginary exponents</li>\n<li>Polar representation</li>\n</ul>\n<p>If you are curious to learn more, you can find more information at <a href=\"https://en.wikipedia.org/wiki/Complex_number\">Wikipedia</a>.</p>\n<p>This kata has several tasks that require you to write Q# code to test your understanding of the concepts. It will introduce the necessary Q# language constructs as it goes.</p>\n",
63
- "asMarkdown": "\nThis kata introduces you to complex arithmetic. This topic isn't particularly expansive, but it's important to understand it to be able to work with quantum computing.\n\nThis tutorial covers the following topics:\n\n* Imaginary and complex numbers\n* Basic complex arithmetic\n* Complex plane\n* Modulus operator\n* Imaginary exponents\n* Polar representation\n\nIf you are curious to learn more, you can find more information at [Wikipedia](https://en.wikipedia.org/wiki/Complex_number).\n\nThis kata has several tasks that require you to write Q# code to test your understanding of the concepts. It will introduce the necessary Q# language constructs as it goes."
62
+ "asHtml": "<p>This kata introduces you to complex arithmetic. This topic isn&#39;t particularly expansive, but it&#39;s important to understand it to be able to work with quantum computing.</p>\n<p><strong>This kata covers the following topics:</strong></p>\n<ul>\n<li>Imaginary and complex numbers</li>\n<li>Basic complex arithmetic</li>\n<li>Complex plane</li>\n<li>Modulus operator</li>\n<li>Imaginary exponents</li>\n<li>Polar representation</li>\n</ul>\n<p>If you are curious to learn more, you can find more information at <a href=\"https://en.wikipedia.org/wiki/Complex_number\">Wikipedia</a>.</p>\n<p>This kata has several tasks that require you to write Q# code to test your understanding of the concepts. It will introduce the necessary Q# language constructs as it goes.</p>\n",
63
+ "asMarkdown": "\nThis kata introduces you to complex arithmetic. This topic isn't particularly expansive, but it's important to understand it to be able to work with quantum computing.\n\n**This kata covers the following topics:**\n\n* Imaginary and complex numbers\n* Basic complex arithmetic\n* Complex plane\n* Modulus operator\n* Imaginary exponents\n* Polar representation\n\nIf you are curious to learn more, you can find more information at [Wikipedia](https://en.wikipedia.org/wiki/Complex_number).\n\nThis kata has several tasks that require you to write Q# code to test your understanding of the concepts. It will introduce the necessary Q# language constructs as it goes."
64
64
  }
65
65
  ]
66
66
  },
@@ -491,6 +491,510 @@ export default {
491
491
  }
492
492
  ]
493
493
  },
494
+ {
495
+ "id": "linear_algebra",
496
+ "title": "Linear Algebra",
497
+ "sections": [
498
+ {
499
+ "type": "lesson",
500
+ "id": "linear_algebra__overview",
501
+ "title": "Overview",
502
+ "items": [
503
+ {
504
+ "type": "text-content",
505
+ "asHtml": "<p>This kata introduces you to the basics of linear algebra. Linear algebra is a branch of mathematics dedicated to studying the properties of matrices and vectors, which are used extensively in quantum computing to represent quantum states and operations on them.\nThis kata doesn&#39;t come close to covering the full breadth of the topic, but it should be enough to get you comfortable with the main concepts of linear algebra used in quantum computing.</p>\n<p><strong>This kata covers the following topics:</strong></p>\n<ul>\n<li>Matrices and vectors</li>\n<li>Basic matrix operations</li>\n<li>Operations and properties of complex-valued matrices</li>\n<li>Inner and outer vector products</li>\n<li>Tensor product</li>\n</ul>\n<p><strong>What you should know to start working on this kata:</strong></p>\n<ul>\n<li>Complex numbers. If you need a review of this topic, we recommend that you complete the Complex Arithmetic kata before tackling this one.</li>\n</ul>\n<p><em>In this kata, the exercises focus on pen-and-paper work rather than on writing programs, since you&#39;re much more likely to do the linear algebra for a quantum computing problem before you start writing the code for it than to do it in Q#. Every task asks you to fill in the results of a math calculation for a specific example that you can do by hand. The Q# code is used as a way to check the results of the calculations rather than as a way to carry them out.</em></p>\n",
506
+ "asMarkdown": "\nThis kata introduces you to the basics of linear algebra. Linear algebra is a branch of mathematics dedicated to studying the properties of matrices and vectors, which are used extensively in quantum computing to represent quantum states and operations on them.\nThis kata doesn't come close to covering the full breadth of the topic, but it should be enough to get you comfortable with the main concepts of linear algebra used in quantum computing.\n\n**This kata covers the following topics:**\n\n* Matrices and vectors\n* Basic matrix operations\n* Operations and properties of complex-valued matrices\n* Inner and outer vector products\n* Tensor product\n\n**What you should know to start working on this kata:**\n\n* Complex numbers. If you need a review of this topic, we recommend that you complete the Complex Arithmetic kata before tackling this one.\n\n*In this kata, the exercises focus on pen-and-paper work rather than on writing programs, since you're much more likely to do the linear algebra for a quantum computing problem before you start writing the code for it than to do it in Q#. Every task asks you to fill in the results of a math calculation for a specific example that you can do by hand. The Q# code is used as a way to check the results of the calculations rather than as a way to carry them out.*"
507
+ }
508
+ ]
509
+ },
510
+ {
511
+ "type": "lesson",
512
+ "id": "linear_algebra__matrices_and_vectors",
513
+ "title": "Matrices and Vectors",
514
+ "items": [
515
+ {
516
+ "type": "text-content",
517
+ "asHtml": "<p>A <strong>matrix</strong> is set of numbers arranged in a rectangular grid. Here is a $2$ by $2$ matrix:</p>\n<p>$$A =\n\\begin{bmatrix} 1 &amp; 2 \\\\ 3 &amp; 4 \\end{bmatrix}$$</p>\n<p>$A_{i,j}$ refers to the element in row $i$ and column $j$ of matrix $A$ (all indices are 0-based). In the above example, $A_{0,1} = 2$.</p>\n<p>An $n \\times m$ matrix will have $n$ rows and $m$ columns:</p>\n<p>$$\\begin{bmatrix}\n x_{0,0} &amp; x_{0,1} &amp; \\dotsb &amp; x_{0,m-1} \\\\\n x_{1,0} &amp; x_{1,1} &amp; \\dotsb &amp; x_{1,m-1} \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n x_{n-1,0} &amp; x_{n-1,1} &amp; \\dotsb &amp; x_{n-1,m-1}\n\\end{bmatrix}$$</p>\n<p>A $1 \\times 1$ matrix is equivalent to a scalar:</p>\n<p>$$\\begin{bmatrix} 3 \\end{bmatrix} = 3$$</p>\n<p>Quantum computing uses complex-valued matrices: the elements of a matrix can be complex numbers. This, for example, is a valid complex-valued matrix:</p>\n<p>$$\\begin{bmatrix}\n 1 &amp; i \\\\\n -2i &amp; 3 + 4i\n\\end{bmatrix}$$</p>\n<p>Finally, a <strong>vector</strong> is an $n \\times 1$ matrix. Here, for example, is a $3 \\times 1$ vector:</p>\n<p>$$V = \\begin{bmatrix} 1 \\\\ 2i \\\\ 3 + 4i \\end{bmatrix}$$</p>\n<p>Since vectors always have a width of $1$, vector elements are sometimes written using only one index. In the above example, $V_0 = 1$ and $V_1 = 2i$.</p>\n",
518
+ "asMarkdown": "\nA **matrix** is set of numbers arranged in a rectangular grid. Here is a $2$ by $2$ matrix:\n\n$$A =\n\\begin{bmatrix} 1 & 2 \\\\\\ 3 & 4 \\end{bmatrix}$$\n\n$A_{i,j}$ refers to the element in row $i$ and column $j$ of matrix $A$ (all indices are 0-based). In the above example, $A_{0,1} = 2$.\n\nAn $n \\times m$ matrix will have $n$ rows and $m$ columns:\n\n$$\\begin{bmatrix}\n x_{0,0} & x_{0,1} & \\dotsb & x_{0,m-1} \\\\\\\\\n x_{1,0} & x_{1,1} & \\dotsb & x_{1,m-1} \\\\\\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n x_{n-1,0} & x_{n-1,1} & \\dotsb & x_{n-1,m-1}\n\\end{bmatrix}$$\n\nA $1 \\times 1$ matrix is equivalent to a scalar:\n\n$$\\begin{bmatrix} 3 \\end{bmatrix} = 3$$\n\nQuantum computing uses complex-valued matrices: the elements of a matrix can be complex numbers. This, for example, is a valid complex-valued matrix:\n\n$$\\begin{bmatrix}\n 1 & i \\\\\\\\\n -2i & 3 + 4i\n\\end{bmatrix}$$\n\nFinally, a **vector** is an $n \\times 1$ matrix. Here, for example, is a $3 \\times 1$ vector:\n\n$$V = \\begin{bmatrix} 1 \\\\\\ 2i \\\\\\ 3 + 4i \\end{bmatrix}$$\n\nSince vectors always have a width of $1$, vector elements are sometimes written using only one index. In the above example, $V_0 = 1$ and $V_1 = 2i$."
519
+ }
520
+ ]
521
+ },
522
+ {
523
+ "type": "lesson",
524
+ "id": "linear_algebra__matrix_addition",
525
+ "title": "Matrix Addition",
526
+ "items": [
527
+ {
528
+ "type": "text-content",
529
+ "asHtml": "<p>The easiest matrix operation is <strong>matrix addition</strong>. Matrix addition works between two matrices of the same size, and adds each number from the first matrix to the number in the same position in the second matrix:</p>\n<p>$$\\begin{bmatrix}\n x_{0,0} &amp; x_{0,1} &amp; \\dotsb &amp; x_{0,m-1} \\\\\n x_{1,0} &amp; x_{1,1} &amp; \\dotsb &amp; x_{1,m-1} \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n x_{n-1,0} &amp; x_{n-1,1} &amp; \\dotsb &amp; x_{n-1,m-1}\n\\end{bmatrix} +$$\n$$+ \\begin{bmatrix}\n y_{0,0} &amp; y_{0,1} &amp; \\dotsb &amp; y_{0,m-1} \\\\\n y_{1,0} &amp; y_{1,1} &amp; \\dotsb &amp; y_{1,m-1} \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n y_{n-1,0} &amp; y_{n-1,1} &amp; \\dotsb &amp; y_{n-1,m-1}\n\\end{bmatrix} =$$\n$$= \\begin{bmatrix}\n x_{0,0} + y_{0,0} &amp; x_{0,1} + y_{0,1} &amp; \\dotsb &amp; x_{0,m-1} + y_{0,m-1} \\\\\n x_{1,0} + y_{1,0} &amp; x_{1,1} + y_{1,1} &amp; \\dotsb &amp; x_{1,m-1} + y_{1,m-1} \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n x_{n-1,0} + y_{n-1,0} &amp; x_{n-1,1} + y_{n-1,1} &amp; \\dotsb &amp; x_{n-1,m-1} + y_{n-1,m-1}\n\\end{bmatrix}$$</p>\n<p>Similarly, we can compute $A - B$ by subtracting elements of $B$ from corresponding elements of $A$.</p>\n<p>Matrix addition has the following properties:</p>\n<ul>\n<li>Commutativity: $A + B = B + A$</li>\n<li>Associativity: $(A + B) + C = A + (B + C)$</li>\n</ul>\n",
530
+ "asMarkdown": "\nThe easiest matrix operation is **matrix addition**. Matrix addition works between two matrices of the same size, and adds each number from the first matrix to the number in the same position in the second matrix:\n\n$$\\begin{bmatrix}\n x_{0,0} & x_{0,1} & \\dotsb & x_{0,m-1} \\\\\\\\\n x_{1,0} & x_{1,1} & \\dotsb & x_{1,m-1} \\\\\\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n x_{n-1,0} & x_{n-1,1} & \\dotsb & x_{n-1,m-1}\n\\end{bmatrix} +$$\n$$+ \\begin{bmatrix}\n y_{0,0} & y_{0,1} & \\dotsb & y_{0,m-1} \\\\\\\\\n y_{1,0} & y_{1,1} & \\dotsb & y_{1,m-1} \\\\\\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n y_{n-1,0} & y_{n-1,1} & \\dotsb & y_{n-1,m-1}\n\\end{bmatrix} =$$\n$$= \\begin{bmatrix}\n x_{0,0} + y_{0,0} & x_{0,1} + y_{0,1} & \\dotsb & x_{0,m-1} + y_{0,m-1} \\\\\\\\\n x_{1,0} + y_{1,0} & x_{1,1} + y_{1,1} & \\dotsb & x_{1,m-1} + y_{1,m-1} \\\\\\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n x_{n-1,0} + y_{n-1,0} & x_{n-1,1} + y_{n-1,1} & \\dotsb & x_{n-1,m-1} + y_{n-1,m-1}\n\\end{bmatrix}$$\n\nSimilarly, we can compute $A - B$ by subtracting elements of $B$ from corresponding elements of $A$.\n\nMatrix addition has the following properties:\n\n* Commutativity: $A + B = B + A$\n* Associativity: $(A + B) + C = A + (B + C)$"
531
+ }
532
+ ]
533
+ },
534
+ {
535
+ "type": "exercise",
536
+ "id": "linear_algebra__addition",
537
+ "title": "Add Matrices",
538
+ "description": {
539
+ "type": "text-content",
540
+ "asHtml": "<p><strong>Input:</strong> None.</p>\n<p><strong>Goal:</strong> Return the sum of the following two matrices:</p>\n<p>$$\\begin{bmatrix} 1 &amp; 2 \\\\ 3 &amp; 4 \\end{bmatrix} + \\begin{bmatrix} 5 &amp; 6 \\\\ 7 &amp; 8 \\end{bmatrix}$$</p>\n<blockquote>\n<p>In this and the next few tasks, the matrices are represented as Q# <code>Double[][]</code> type, two-dimensional arrays of floating-point numbers. Make sure the constants you use in the return array are floating-point rather than integers.</p>\n</blockquote>\n",
541
+ "asMarkdown": "**Input:** None.\n\n**Goal:** Return the sum of the following two matrices:\n\n$$\\begin{bmatrix} 1 & 2 \\\\\\ 3 & 4 \\end{bmatrix} + \\begin{bmatrix} 5 & 6 \\\\\\ 7 & 8 \\end{bmatrix}$$\n\n> In this and the next few tasks, the matrices are represented as Q# `Double[][]` type, two-dimensional arrays of floating-point numbers. Make sure the constants you use in the return array are floating-point rather than integers.\n"
542
+ },
543
+ "sourceIds": [
544
+ "linear_algebra__addition__Verification.qs",
545
+ "linear_algebra__Common.qs"
546
+ ],
547
+ "placeholderCode": "namespace Kata {\n function Addition() : Double[][] {\n // Replace the return value with correct answer.\n return [[0., 0.],\n [0., 0.]];\n }\n}\n",
548
+ "explainedSolution": {
549
+ "type": "explained-solution",
550
+ "items": [
551
+ {
552
+ "type": "text-content",
553
+ "asHtml": "<p>Following the definition, the sum of two matrices is a matrix of element-wise sums of matrix elements:</p>\n<p>$$\\begin{bmatrix} 1 &amp; 2 \\\\ 3 &amp; 4 \\end{bmatrix} + \\begin{bmatrix} 5 &amp; 6 \\\\ 7 &amp; 8 \\end{bmatrix} = $$\n$$= \\begin{bmatrix} 1 + 5 &amp; 2 + 6 \\\\ 3 + 7 &amp; 4 + 8 \\end{bmatrix} = \\begin{bmatrix} 6 &amp; 8 \\\\ 10 &amp; 12 \\end{bmatrix}$$</p>\n",
554
+ "asMarkdown": "\nFollowing the definition, the sum of two matrices is a matrix of element-wise sums of matrix elements:\n\n$$\\begin{bmatrix} 1 & 2 \\\\\\ 3 & 4 \\end{bmatrix} + \\begin{bmatrix} 5 & 6 \\\\\\ 7 & 8 \\end{bmatrix} = $$\n$$= \\begin{bmatrix} 1 + 5 & 2 + 6 \\\\\\ 3 + 7 & 4 + 8 \\end{bmatrix} = \\begin{bmatrix} 6 & 8 \\\\\\ 10 & 12 \\end{bmatrix}$$"
555
+ },
556
+ {
557
+ "type": "solution",
558
+ "id": "linear_algebra__addition_solution",
559
+ "code": "namespace Kata {\n function Addition() : Double[][] {\n return [[6., 8.], \n [10., 12.]];\n }\n}\n"
560
+ }
561
+ ]
562
+ }
563
+ },
564
+ {
565
+ "type": "lesson",
566
+ "id": "linear_algebra__scalar_multiplication",
567
+ "title": "Scalar Multiplication",
568
+ "items": [
569
+ {
570
+ "type": "text-content",
571
+ "asHtml": "<p>The next matrix operation is <strong>scalar multiplication</strong> - multiplying the entire matrix by a scalar (real or complex number):</p>\n<p>$$a \\cdot\n\\begin{bmatrix}\n x_{0,0} &amp; x_{0,1} &amp; \\dotsb &amp; x_{0,m-1} \\\\\n x_{1,0} &amp; x_{1,1} &amp; \\dotsb &amp; x_{1,m-1} \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n x_{n-1,0} &amp; x_{n-1,1} &amp; \\dotsb &amp; x_{n-1,m-1}\n\\end{bmatrix} =\n\\begin{bmatrix}\n a \\cdot x_{0,0} &amp; a \\cdot x_{0,1} &amp; \\dotsb &amp; a \\cdot x_{0,m-1} \\\\\n a \\cdot x_{1,0} &amp; a \\cdot x_{1,1} &amp; \\dotsb &amp; a \\cdot x_{1,m-1} \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n a \\cdot x_{n-1,0} &amp; a \\cdot x_{n-1,1} &amp; \\dotsb &amp; a \\cdot x_{n-1,m-1}\n\\end{bmatrix}$$</p>\n<p>Scalar multiplication has the following properties:</p>\n<ul>\n<li>Associativity: $x \\cdot (yA) = (x \\cdot y)A$</li>\n<li>Distributivity over matrix addition: $x(A + B) = xA + xB$</li>\n<li>Distributivity over scalar addition: $(x + y)A = xA + yA$</li>\n</ul>\n",
572
+ "asMarkdown": "\nThe next matrix operation is **scalar multiplication** - multiplying the entire matrix by a scalar (real or complex number):\n\n$$a \\cdot\n\\begin{bmatrix}\n x_{0,0} & x_{0,1} & \\dotsb & x_{0,m-1} \\\\\\\\\n x_{1,0} & x_{1,1} & \\dotsb & x_{1,m-1} \\\\\\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n x_{n-1,0} & x_{n-1,1} & \\dotsb & x_{n-1,m-1}\n\\end{bmatrix} =\n\\begin{bmatrix}\n a \\cdot x_{0,0} & a \\cdot x_{0,1} & \\dotsb & a \\cdot x_{0,m-1} \\\\\\\\\n a \\cdot x_{1,0} & a \\cdot x_{1,1} & \\dotsb & a \\cdot x_{1,m-1} \\\\\\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n a \\cdot x_{n-1,0} & a \\cdot x_{n-1,1} & \\dotsb & a \\cdot x_{n-1,m-1}\n\\end{bmatrix}$$\n\nScalar multiplication has the following properties:\n\n* Associativity: $x \\cdot (yA) = (x \\cdot y)A$\n* Distributivity over matrix addition: $x(A + B) = xA + xB$\n* Distributivity over scalar addition: $(x + y)A = xA + yA$"
573
+ }
574
+ ]
575
+ },
576
+ {
577
+ "type": "exercise",
578
+ "id": "linear_algebra__scalar_multiplication_ex",
579
+ "title": "Multiply a Matrix by a Scalar",
580
+ "description": {
581
+ "type": "text-content",
582
+ "asHtml": "<p><strong>Input:</strong> None.</p>\n<p><strong>Goal:</strong> Return the result of multiplying the following matrix by the scalar:</p>\n<p>$$0.5 \\cdot \\begin{bmatrix} 1 &amp; 2 \\\\ 3 &amp; 4 \\end{bmatrix}$$</p>\n",
583
+ "asMarkdown": "**Input:** None.\n\n**Goal:** Return the result of multiplying the following matrix by the scalar:\n\n$$0.5 \\cdot \\begin{bmatrix} 1 & 2 \\\\\\ 3 & 4 \\end{bmatrix}$$\n"
584
+ },
585
+ "sourceIds": [
586
+ "linear_algebra__scalar_multiplication__Verification.qs",
587
+ "linear_algebra__Common.qs"
588
+ ],
589
+ "placeholderCode": "namespace Kata {\n function ScalarMultiplication() : Double[][] {\n // Replace the return value with correct answer.\n return [[0., 0.],\n [0., 0.]];\n }\n}\n",
590
+ "explainedSolution": {
591
+ "type": "explained-solution",
592
+ "items": [
593
+ {
594
+ "type": "text-content",
595
+ "asHtml": "<p>We can again follow the definition given: to calculate the product of a number and a matrix, multiply each matrix element by that number. </p>\n<p>$$0.5 \\cdot \\begin{bmatrix} 1 &amp; 2 \\\\ 3 &amp; 4 \\end{bmatrix} =\n= \\begin{bmatrix} 0.5 \\cdot 1 &amp; 0.5 \\cdot 2 \\\\ 0.5 \\cdot 3 &amp; 0.5 \\cdot 4\\end{bmatrix} = \\begin{bmatrix} 0.5 &amp; 1 \\\\ 1.5 &amp; 2 \\end{bmatrix}$$</p>\n",
596
+ "asMarkdown": "\nWe can again follow the definition given: to calculate the product of a number and a matrix, multiply each matrix element by that number. \n\n$$0.5 \\cdot \\begin{bmatrix} 1 & 2 \\\\\\ 3 & 4 \\end{bmatrix} =\n= \\begin{bmatrix} 0.5 \\cdot 1 & 0.5 \\cdot 2 \\\\\\ 0.5 \\cdot 3 & 0.5 \\cdot 4\\end{bmatrix} = \\begin{bmatrix} 0.5 & 1 \\\\\\ 1.5 & 2 \\end{bmatrix}$$"
597
+ },
598
+ {
599
+ "type": "solution",
600
+ "id": "linear_algebra__scalar_multiplication_solution",
601
+ "code": "namespace Kata {\n function ScalarMultiplication() : Double[][] {\n return [[0.5, 1.], \n [1.5, 2.]];\n }\n}\n"
602
+ }
603
+ ]
604
+ }
605
+ },
606
+ {
607
+ "type": "lesson",
608
+ "id": "linear_algebra__matrix_multiplication",
609
+ "title": "Matrix Multiplication",
610
+ "items": [
611
+ {
612
+ "type": "text-content",
613
+ "asHtml": "<p><strong>Matrix multiplication</strong> is a very important and somewhat unusual operation. The unusual thing about it is that neither its operands nor its output are the same size: an $n \\times m$ matrix multiplied by an $m \\times k$ matrix results in an $n \\times k$ matrix. \nThat is, for matrix multiplication to be applicable, the number of columns in the first matrix must equal the number of rows in the second matrix.</p>\n<p>Here is how matrix product is calculated: if we are calculating $AB = C$, then</p>\n<p>$$C_{i,j} = A_{i,0} \\cdot B_{0,j} + A_{i,1} \\cdot B_{1,j} + \\dotsb + A_{i,m-1} \\cdot B_{m-1,j} = \\sum_{t = 0}^{m-1} A_{i,t} \\cdot B_{t,j}$$</p>\n<p>Here is a small example:</p>\n<p>$$\\begin{bmatrix}\n 1 &amp; 2 &amp; 3 \\\\\n 4 &amp; 5 &amp; 6\n\\end{bmatrix}\n\\begin{bmatrix}\n 1 \\\\\n 2 \\\\\n 3\n\\end{bmatrix} =\n\\begin{bmatrix}\n 1 \\cdot 1 + 2 \\cdot 2 + 3 \\cdot 3 \\\\\n 4 \\cdot 1 + 5 \\cdot 2 + 6 \\cdot 3\n\\end{bmatrix} =\n\\begin{bmatrix}\n 14 \\\\\n 32\n\\end{bmatrix}$$</p>\n<p>Matrix multiplication has the following properties:</p>\n<ul>\n<li>Associativity: $A(BC) = (AB)C$</li>\n<li>Distributivity over matrix addition: $A(B + C) = AB + AC$ and $(A + B)C = AC + BC$</li>\n<li>Associativity with scalar multiplication: $xAB = x(AB) = A(xB)$</li>\n</ul>\n<blockquote>\n<p>Note that matrix multiplication is <strong>not commutative:</strong> $AB$ rarely equals $BA$.</p>\n</blockquote>\n<p>Another very important property of matrix multiplication is that a matrix multiplied by a vector produces another vector.</p>\n<p>An <strong>identity matrix</strong> $I_n$ is a special $n \\times n$ matrix which has $1$s on the main diagonal, and $0$s everywhere else:</p>\n<p>$$I_n =\n\\begin{bmatrix}\n 1 &amp; 0 &amp; \\dotsb &amp; 0 \\\\\n 0 &amp; 1 &amp; \\dotsb &amp; 0 \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n 0 &amp; 0 &amp; \\dotsb &amp; 1\n\\end{bmatrix}$$</p>\n<p>What makes it special is that multiplying any matrix (of compatible size) by $I_n$ returns the original matrix. To put it another way, if $A$ is an $n \\times m$ matrix:</p>\n<p>$$AI_m = I_nA = A$$</p>\n<p>This is why $I_n$ is called an identity matrix - it acts as a <strong>multiplicative identity</strong>. In other words, it is the matrix equivalent of the number $1$.</p>\n",
614
+ "asMarkdown": "\n**Matrix multiplication** is a very important and somewhat unusual operation. The unusual thing about it is that neither its operands nor its output are the same size: an $n \\times m$ matrix multiplied by an $m \\times k$ matrix results in an $n \\times k$ matrix. \nThat is, for matrix multiplication to be applicable, the number of columns in the first matrix must equal the number of rows in the second matrix.\n\nHere is how matrix product is calculated: if we are calculating $AB = C$, then\n\n$$C_{i,j} = A_{i,0} \\cdot B_{0,j} + A_{i,1} \\cdot B_{1,j} + \\dotsb + A_{i,m-1} \\cdot B_{m-1,j} = \\sum_{t = 0}^{m-1} A_{i,t} \\cdot B_{t,j}$$\n\nHere is a small example:\n\n$$\\begin{bmatrix}\n 1 & 2 & 3 \\\\\\\\\n 4 & 5 & 6\n\\end{bmatrix}\n\\begin{bmatrix}\n 1 \\\\\\\\\n 2 \\\\\\\\\n 3\n\\end{bmatrix} =\n\\begin{bmatrix}\n 1 \\cdot 1 + 2 \\cdot 2 + 3 \\cdot 3 \\\\\\\\\n 4 \\cdot 1 + 5 \\cdot 2 + 6 \\cdot 3\n\\end{bmatrix} =\n\\begin{bmatrix}\n 14 \\\\\\\\\n 32\n\\end{bmatrix}$$\n\nMatrix multiplication has the following properties:\n\n* Associativity: $A(BC) = (AB)C$\n* Distributivity over matrix addition: $A(B + C) = AB + AC$ and $(A + B)C = AC + BC$\n* Associativity with scalar multiplication: $xAB = x(AB) = A(xB)$\n\n> Note that matrix multiplication is **not commutative:** $AB$ rarely equals $BA$.\n\nAnother very important property of matrix multiplication is that a matrix multiplied by a vector produces another vector.\n\nAn **identity matrix** $I_n$ is a special $n \\times n$ matrix which has $1$s on the main diagonal, and $0$s everywhere else:\n\n$$I_n =\n\\begin{bmatrix}\n 1 & 0 & \\dotsb & 0 \\\\\\\\\n 0 & 1 & \\dotsb & 0 \\\\\\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n 0 & 0 & \\dotsb & 1\n\\end{bmatrix}$$\n\nWhat makes it special is that multiplying any matrix (of compatible size) by $I_n$ returns the original matrix. To put it another way, if $A$ is an $n \\times m$ matrix:\n\n$$AI_m = I_nA = A$$\n\nThis is why $I_n$ is called an identity matrix - it acts as a **multiplicative identity**. In other words, it is the matrix equivalent of the number $1$."
615
+ }
616
+ ]
617
+ },
618
+ {
619
+ "type": "exercise",
620
+ "id": "linear_algebra__matrix_multiplication_ex",
621
+ "title": "Multiply Two Matrices",
622
+ "description": {
623
+ "type": "text-content",
624
+ "asHtml": "<p><strong>Input:</strong> None.</p>\n<p><strong>Goal:</strong> Return the product of the following two matrices:</p>\n<p>$$\\begin{bmatrix} 1 &amp; 2 \\\\ 3 &amp; 4 \\end{bmatrix} \\cdot \\begin{bmatrix} 5 &amp; 6 \\\\ 7 &amp; 8 \\end{bmatrix}$$</p>\n",
625
+ "asMarkdown": "**Input:** None.\n\n**Goal:** Return the product of the following two matrices:\n\n$$\\begin{bmatrix} 1 & 2 \\\\\\ 3 & 4 \\end{bmatrix} \\cdot \\begin{bmatrix} 5 & 6 \\\\\\ 7 & 8 \\end{bmatrix}$$\n"
626
+ },
627
+ "sourceIds": [
628
+ "linear_algebra__multiplication__Verification.qs",
629
+ "linear_algebra__Common.qs"
630
+ ],
631
+ "placeholderCode": "namespace Kata {\n function Multiplication() : Double[][] {\n // Replace the return value with correct answer.\n return [[0., 0.],\n [0., 0.]];\n }\n}\n",
632
+ "explainedSolution": {
633
+ "type": "explained-solution",
634
+ "items": [
635
+ {
636
+ "type": "text-content",
637
+ "asHtml": "<p>Following the definition, we can calculate the product of these two matrices as follows:</p>\n<p>$$\\begin{bmatrix} 1 &amp; 2 \\\\ 3 &amp; 4 \\end{bmatrix} \\cdot \\begin{bmatrix} 5 &amp; 6 \\\\ 7 &amp; 8 \\end{bmatrix} = $$\n$$= \\begin{bmatrix} 1 \\cdot 5 + 2 \\cdot 7 &amp; 1 \\cdot 6 + 2 \\cdot 8 \\\\ 3 \\cdot 5 + 4 \\cdot 7 &amp; 3 \\cdot 6 + 4 \\cdot 8 \\end{bmatrix} = \\begin{bmatrix} 19 &amp; 22 \\\\ 43 &amp; 50 \\end{bmatrix}$$</p>\n",
638
+ "asMarkdown": "\nFollowing the definition, we can calculate the product of these two matrices as follows:\n\n$$\\begin{bmatrix} 1 & 2 \\\\\\ 3 & 4 \\end{bmatrix} \\cdot \\begin{bmatrix} 5 & 6 \\\\\\ 7 & 8 \\end{bmatrix} = $$\n$$= \\begin{bmatrix} 1 \\cdot 5 + 2 \\cdot 7 & 1 \\cdot 6 + 2 \\cdot 8 \\\\\\ 3 \\cdot 5 + 4 \\cdot 7 & 3 \\cdot 6 + 4 \\cdot 8 \\end{bmatrix} = \\begin{bmatrix} 19 & 22 \\\\\\ 43 & 50 \\end{bmatrix}$$"
639
+ },
640
+ {
641
+ "type": "solution",
642
+ "id": "linear_algebra__multiplication_solution",
643
+ "code": "namespace Kata {\n function Multiplication() : Double[][] {\n return [[19., 22.], \n [43., 50.]];\n }\n}\n"
644
+ }
645
+ ]
646
+ }
647
+ },
648
+ {
649
+ "type": "lesson",
650
+ "id": "linear_algebra__inverse_matrices",
651
+ "title": "Inverse Matrices",
652
+ "items": [
653
+ {
654
+ "type": "text-content",
655
+ "asHtml": "<p>A square $n \\times n$ matrix $A$ is <strong>invertible</strong> if it has an inverse $n \\times n$ matrix $A^{-1}$ with the following property:</p>\n<p>$$AA^{-1} = A^{-1}A = I_n$$</p>\n<p>In other words, $A^{-1}$ acts as the <strong>multiplicative inverse</strong> of $A$.</p>\n<p>Another, equivalent definition highlights what makes this an interesting property. For any matrices $B$ and $C$ of compatible sizes:</p>\n<p>$$A^{-1}(AB) = A(A^{-1}B) = B$$\n$$(CA)A^{-1} = (CA^{-1})A = C$$</p>\n<p>A square matrix has a property called the <strong>determinant</strong>, with the determinant of matrix $A$ being written as $|A|$. A matrix is invertible if and only if its determinant isn&#39;t equal to $0$.</p>\n<p>For a $2 \\times 2$ matrix $A$, the determinant is defined as $|A| = A_{0,0} \\cdot A_{1,1} - A_{0,1} \\cdot A_{1,0}$.</p>\n<p>For larger matrices, the determinant is defined through determinants of sub-matrices. You can learn more from <a href=\"https://en.wikipedia.org/wiki/Determinant\">Wikipedia</a> or from <a href=\"http://mathworld.wolfram.com/Determinant.html\">Wolfram MathWorld</a>.</p>\n",
656
+ "asMarkdown": "\nA square $n \\times n$ matrix $A$ is **invertible** if it has an inverse $n \\times n$ matrix $A^{-1}$ with the following property:\n\n$$AA^{-1} = A^{-1}A = I_n$$\n\nIn other words, $A^{-1}$ acts as the **multiplicative inverse** of $A$.\n\nAnother, equivalent definition highlights what makes this an interesting property. For any matrices $B$ and $C$ of compatible sizes:\n\n$$A^{-1}(AB) = A(A^{-1}B) = B$$\n$$(CA)A^{-1} = (CA^{-1})A = C$$\n\nA square matrix has a property called the **determinant**, with the determinant of matrix $A$ being written as $|A|$. A matrix is invertible if and only if its determinant isn't equal to $0$.\n\nFor a $2 \\times 2$ matrix $A$, the determinant is defined as $|A| = A_{0,0} \\cdot A_{1,1} - A_{0,1} \\cdot A_{1,0}$.\n\nFor larger matrices, the determinant is defined through determinants of sub-matrices. You can learn more from [Wikipedia](https://en.wikipedia.org/wiki/Determinant) or from [Wolfram MathWorld](http://mathworld.wolfram.com/Determinant.html)."
657
+ }
658
+ ]
659
+ },
660
+ {
661
+ "type": "exercise",
662
+ "id": "linear_algebra__inverse_matrix_ex",
663
+ "title": "Invert a Matrix",
664
+ "description": {
665
+ "type": "text-content",
666
+ "asHtml": "<p><strong>Input:</strong> None.</p>\n<p><strong>Goal:</strong> Return the inverse of the following matrix:</p>\n<p>$$\\begin{bmatrix} 1 &amp; 2 \\\\ 3 &amp; 4 \\end{bmatrix}$$</p>\n<details>\n <summary><b>Need a hint?</b></summary>\n \n<p>You may find <a href=\"https://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_2_%C3%97_2_matrices\">this Wikipedia article</a> useful.</p>\n</details>\n",
667
+ "asMarkdown": "**Input:** None.\n\n**Goal:** Return the inverse of the following matrix:\n\n$$\\begin{bmatrix} 1 & 2 \\\\\\ 3 & 4 \\end{bmatrix}$$\n\n<details>\n <summary><b>Need a hint?</b></summary>\n \nYou may find [this Wikipedia article](https://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_2_%C3%97_2_matrices) useful.\n\n</details>\n"
668
+ },
669
+ "sourceIds": [
670
+ "linear_algebra__inverse__Verification.qs",
671
+ "linear_algebra__Common.qs"
672
+ ],
673
+ "placeholderCode": "namespace Kata {\n function Inverse() : Double[][] {\n // Replace the return value with correct answer.\n return [[0., 0.],\n [0., 0.]];\n }\n}\n",
674
+ "explainedSolution": {
675
+ "type": "explained-solution",
676
+ "items": [
677
+ {
678
+ "type": "text-content",
679
+ "asHtml": "<p>We will follow the algorithm described in the <a href=\"https://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_2_%C3%97_2_matrices\">Wikipedia article</a> for $2 \\times 2$ matrices:</p>\n<p>$$ A = \\begin{bmatrix} a &amp; b \\\\ c &amp; d \\end{bmatrix} $$</p>\n<p>Then the determinant of the matrix is defined as \n$$ |A| = a \\cdot d - b \\cdot c = 1 \\cdot 4 - 2 \\cdot 3 = -2$$</p>\n<p>And the inverse of the matrix is</p>\n<p>$$A^{-1} = \\frac{1}{|A|} \\cdot \\begin{bmatrix} d &amp; -b \\\\ -c &amp; a \\end{bmatrix} = -\\frac12 \\begin{bmatrix} 4 &amp; -2 \\\\ -3 &amp; 1 \\end{bmatrix} = \\begin{bmatrix} -2 &amp; 1 \\\\ \\frac32 &amp; -\\frac12 \\end{bmatrix}$$</p>\n",
680
+ "asMarkdown": "\nWe will follow the algorithm described in the [Wikipedia article](https://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_2_%C3%97_2_matrices) for $2 \\times 2$ matrices:\n\n$$ A = \\begin{bmatrix} a & b \\\\\\ c & d \\end{bmatrix} $$\n\nThen the determinant of the matrix is defined as \n$$ |A| = a \\cdot d - b \\cdot c = 1 \\cdot 4 - 2 \\cdot 3 = -2$$\n\nAnd the inverse of the matrix is\n\n$$A^{-1} = \\frac{1}{|A|} \\cdot \\begin{bmatrix} d & -b \\\\\\ -c & a \\end{bmatrix} = -\\frac12 \\begin{bmatrix} 4 & -2 \\\\\\ -3 & 1 \\end{bmatrix} = \\begin{bmatrix} -2 & 1 \\\\\\ \\frac32 & -\\frac12 \\end{bmatrix}$$"
681
+ },
682
+ {
683
+ "type": "solution",
684
+ "id": "linear_algebra__inverse_solution",
685
+ "code": "namespace Kata {\n function Inverse() : Double[][] {\n return [[-2., 1.], \n [1.5, -0.5]];\n }\n}\n"
686
+ }
687
+ ]
688
+ }
689
+ },
690
+ {
691
+ "type": "lesson",
692
+ "id": "linear_algebra__transpose",
693
+ "title": "Transpose",
694
+ "items": [
695
+ {
696
+ "type": "text-content",
697
+ "asHtml": "<p>The <strong>transpose</strong> operation, denoted as $A^T$, is essentially a reflection of the matrix across the diagonal: $A^T_{i,j} = A_{j,i}$.</p>\n<p>Given an $n \\times m$ matrix $A$, its transpose is the $m \\times n$ matrix $A^T$, such that if:</p>\n<p>$$A =\n\\begin{bmatrix}\n x_{0,0} &amp; x_{0,1} &amp; \\dotsb &amp; x_{0,m-1} \\\\\n x_{1,0} &amp; x_{1,1} &amp; \\dotsb &amp; x_{1,m-1} \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n x_{n-1,0} &amp; x_{n-1,1} &amp; \\dotsb &amp; x_{n-1,m-1}\n\\end{bmatrix}$$</p>\n<p>then:</p>\n<p>$$A^T =\n\\begin{bmatrix}\n x_{0,0} &amp; x_{1,0} &amp; \\dotsb &amp; x_{n-1,0} \\\\\n x_{0,1} &amp; x_{1,1} &amp; \\dotsb &amp; x_{n-1,1} \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n x_{0,m-1} &amp; x_{1,m-1} &amp; \\dotsb &amp; x_{n-1,m-1}\n\\end{bmatrix}$$</p>\n<p>For example:</p>\n<p>$$\\begin{bmatrix}\n 1 &amp; 2 \\\\\n 3 &amp; 4 \\\\\n 5 &amp; 6\n\\end{bmatrix}^T =\n\\begin{bmatrix}\n 1 &amp; 3 &amp; 5 \\\\\n 2 &amp; 4 &amp; 6\n\\end{bmatrix}$$</p>\n<p>A <strong>symmetric</strong> matrix is a square matrix which equals its own transpose: $A = A^T$. To put it another way, it has reflection symmetry (hence the name) across the main diagonal. For example, the following matrix is symmetric:</p>\n<p>$$\\begin{bmatrix}\n 1 &amp; 2 &amp; 3 \\\\\n 2 &amp; 4 &amp; 5 \\\\\n 3 &amp; 5 &amp; 6\n\\end{bmatrix}$$</p>\n<p>The transpose of a matrix product is equal to the product of transposed matrices, taken in reverse order:</p>\n<p>$$(AB)^T = B^TA^T$$</p>\n",
698
+ "asMarkdown": "\nThe **transpose** operation, denoted as $A^T$, is essentially a reflection of the matrix across the diagonal: $A^T_{i,j} = A_{j,i}$.\n\nGiven an $n \\times m$ matrix $A$, its transpose is the $m \\times n$ matrix $A^T$, such that if:\n\n$$A =\n\\begin{bmatrix}\n x_{0,0} & x_{0,1} & \\dotsb & x_{0,m-1} \\\\\\\\\n x_{1,0} & x_{1,1} & \\dotsb & x_{1,m-1} \\\\\\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n x_{n-1,0} & x_{n-1,1} & \\dotsb & x_{n-1,m-1}\n\\end{bmatrix}$$\n\nthen:\n\n$$A^T =\n\\begin{bmatrix}\n x_{0,0} & x_{1,0} & \\dotsb & x_{n-1,0} \\\\\\\\\n x_{0,1} & x_{1,1} & \\dotsb & x_{n-1,1} \\\\\\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n x_{0,m-1} & x_{1,m-1} & \\dotsb & x_{n-1,m-1}\n\\end{bmatrix}$$\n\nFor example:\n\n$$\\begin{bmatrix}\n 1 & 2 \\\\\\\\\n 3 & 4 \\\\\\\\\n 5 & 6\n\\end{bmatrix}^T =\n\\begin{bmatrix}\n 1 & 3 & 5 \\\\\\\\\n 2 & 4 & 6\n\\end{bmatrix}$$\n\nA **symmetric** matrix is a square matrix which equals its own transpose: $A = A^T$. To put it another way, it has reflection symmetry (hence the name) across the main diagonal. For example, the following matrix is symmetric:\n\n$$\\begin{bmatrix}\n 1 & 2 & 3 \\\\\\\\\n 2 & 4 & 5 \\\\\\\\\n 3 & 5 & 6\n\\end{bmatrix}$$\n\nThe transpose of a matrix product is equal to the product of transposed matrices, taken in reverse order:\n\n$$(AB)^T = B^TA^T$$"
699
+ }
700
+ ]
701
+ },
702
+ {
703
+ "type": "exercise",
704
+ "id": "linear_algebra__transpose_ex",
705
+ "title": "Transpose a Matrix",
706
+ "description": {
707
+ "type": "text-content",
708
+ "asHtml": "<p><strong>Input:</strong> None.</p>\n<p><strong>Goal:</strong> Return the transpose of the following matrix:</p>\n<p>$$\\begin{bmatrix} 1 &amp; 2 \\\\ 3 &amp; 4 \\end{bmatrix}$$</p>\n",
709
+ "asMarkdown": "**Input:** None.\n\n**Goal:** Return the transpose of the following matrix:\n\n$$\\begin{bmatrix} 1 & 2 \\\\\\ 3 & 4 \\end{bmatrix}$$\n"
710
+ },
711
+ "sourceIds": [
712
+ "linear_algebra__transpose__Verification.qs",
713
+ "linear_algebra__Common.qs"
714
+ ],
715
+ "placeholderCode": "namespace Kata {\n function Transpose() : Double[][] {\n // Replace the return value with correct answer.\n return [[0., 0.],\n [0., 0.]];\n }\n}\n",
716
+ "explainedSolution": {
717
+ "type": "explained-solution",
718
+ "items": [
719
+ {
720
+ "type": "text-content",
721
+ "asHtml": "<p>Following the definition of matrix transpose, we just need to fill the transpose matrix with the elements of the original matrix in the right order: the elements on the main diagonal remain in their places, and the elements off the main diagonal are swapped.</p>\n",
722
+ "asMarkdown": "\nFollowing the definition of matrix transpose, we just need to fill the transpose matrix with the elements of the original matrix in the right order: the elements on the main diagonal remain in their places, and the elements off the main diagonal are swapped."
723
+ },
724
+ {
725
+ "type": "solution",
726
+ "id": "linear_algebra__transpose_solution",
727
+ "code": "namespace Kata {\n function Transpose() : Double[][] {\n return [[1., 3.], \n [2., 4.]];\n }\n}\n"
728
+ }
729
+ ]
730
+ }
731
+ },
732
+ {
733
+ "type": "lesson",
734
+ "id": "linear_algebra__conjugate",
735
+ "title": "Conjugate",
736
+ "items": [
737
+ {
738
+ "type": "text-content",
739
+ "asHtml": "<p>The next important single-matrix operation is the <strong>matrix conjugate</strong>, denoted as $\\overline{A}$. This operation makes sense only for complex-valued matrices; as the name might suggest, it involves taking the complex conjugate of every element of the matrix: if</p>\n<p>$$A =\n\\begin{bmatrix}\n x_{0,0} &amp; x_{0,1} &amp; \\dotsb &amp; x_{0,m-1} \\\\\n x_{1,0} &amp; x_{1,1} &amp; \\dotsb &amp; x_{1,m-1} \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n x_{n-1,0} &amp; x_{n-1,1} &amp; \\dotsb &amp; x_{n-1,m-1}\n\\end{bmatrix}$$</p>\n<p>Then:</p>\n<p>$$\\overline{A} =\n\\begin{bmatrix}\n \\overline{x}_{0,0} &amp; \\overline{x}_{0,1} &amp; \\dotsb &amp; \\overline{x}_{0,m-1} \\\\\n \\overline{x}_{1,0} &amp; \\overline{x}_{1,1} &amp; \\dotsb &amp; \\overline{x}_{1,m-1} \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n \\overline{x}_{n-1,0} &amp; \\overline{x}_{n-1,1} &amp; \\dotsb &amp; \\overline{x}_{n-1,m-1}\n\\end{bmatrix}$$</p>\n<blockquote>\n<p>As a reminder, a conjugate of a complex number $x = a + bi$ is $\\overline{x} = a - bi$.</p>\n</blockquote>\n<p>The conjugate of a matrix product equals to the product of conjugates of the matrices:</p>\n<p>$$\\overline{AB} = (\\overline{A})(\\overline{B})$$</p>\n",
740
+ "asMarkdown": "\nThe next important single-matrix operation is the **matrix conjugate**, denoted as $\\overline{A}$. This operation makes sense only for complex-valued matrices; as the name might suggest, it involves taking the complex conjugate of every element of the matrix: if\n\n$$A =\n\\begin{bmatrix}\n x_{0,0} & x_{0,1} & \\dotsb & x_{0,m-1} \\\\\\\\\n x_{1,0} & x_{1,1} & \\dotsb & x_{1,m-1} \\\\\\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n x_{n-1,0} & x_{n-1,1} & \\dotsb & x_{n-1,m-1}\n\\end{bmatrix}$$\n\nThen:\n\n$$\\overline{A} =\n\\begin{bmatrix}\n \\overline{x}\\_{0,0} & \\overline{x}\\_{0,1} & \\dotsb & \\overline{x}\\_{0,m-1} \\\\\\\\\n \\overline{x}\\_{1,0} & \\overline{x}\\_{1,1} & \\dotsb & \\overline{x}\\_{1,m-1} \\\\\\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n \\overline{x}\\_{n-1,0} & \\overline{x}\\_{n-1,1} & \\dotsb & \\overline{x}\\_{n-1,m-1}\n\\end{bmatrix}$$\n\n> As a reminder, a conjugate of a complex number $x = a + bi$ is $\\overline{x} = a - bi$.\n\nThe conjugate of a matrix product equals to the product of conjugates of the matrices:\n\n$$\\overline{AB} = (\\overline{A})(\\overline{B})$$"
741
+ }
742
+ ]
743
+ },
744
+ {
745
+ "type": "exercise",
746
+ "id": "linear_algebra__conjugate_ex",
747
+ "title": "Conjugate of a Matrix",
748
+ "description": {
749
+ "type": "text-content",
750
+ "asHtml": "<p><strong>Input:</strong> None.</p>\n<p><strong>Goal:</strong> Return the conjugate of the following matrix:</p>\n<p>$$\\begin{bmatrix} 1 + 5i &amp; 2 \\\\ 3 - 6i &amp; 4i \\end{bmatrix}$$</p>\n<blockquote>\n<p>In this and the next few tasks, the matrices are represented as Q# <code>Complex[][]</code> type, two-dimensional arrays of complex numbers. If you need a refresher on how to work with this data type, check out Complex Arithmetic kata.</p>\n</blockquote>\n",
751
+ "asMarkdown": "**Input:** None.\n\n**Goal:** Return the conjugate of the following matrix:\n\n$$\\begin{bmatrix} 1 + 5i & 2 \\\\\\ 3 - 6i & 4i \\end{bmatrix}$$\n\n> In this and the next few tasks, the matrices are represented as Q# `Complex[][]` type, two-dimensional arrays of complex numbers. If you need a refresher on how to work with this data type, check out Complex Arithmetic kata.\n"
752
+ },
753
+ "sourceIds": [
754
+ "linear_algebra__conjugate__Verification.qs",
755
+ "linear_algebra__Common.qs"
756
+ ],
757
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function Conjugate() : Complex[][] {\n // Replace the return value with correct answer.\n return [[Complex(0., 0.), Complex(0., 0.)],\n [Complex(0., 0.), Complex(0., 0.)]];\n }\n}\n",
758
+ "explainedSolution": {
759
+ "type": "explained-solution",
760
+ "items": [
761
+ {
762
+ "type": "text-content",
763
+ "asHtml": "<p>Following the definition of matrix conjugate, we just need to fill the transpose matrix with the elements of the original matrix, remembering to flip the signs of imaginary parts of the numbers.</p>\n",
764
+ "asMarkdown": "\nFollowing the definition of matrix conjugate, we just need to fill the transpose matrix with the elements of the original matrix, remembering to flip the signs of imaginary parts of the numbers."
765
+ },
766
+ {
767
+ "type": "solution",
768
+ "id": "linear_algebra__conjugate_solution",
769
+ "code": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function Conjugate() : Complex[][] {\n return [[Complex(1., -5.), Complex(2., 0.)],\n [Complex(3., 6.), Complex(0., -4.)]];\n }\n}\n"
770
+ }
771
+ ]
772
+ }
773
+ },
774
+ {
775
+ "type": "lesson",
776
+ "id": "linear_algebra__adjoint",
777
+ "title": "Adjoint",
778
+ "items": [
779
+ {
780
+ "type": "text-content",
781
+ "asHtml": "<p>The final important single-matrix operation is a combination of the previous two. The <strong>conjugate transpose</strong>, also called the <strong>adjoint</strong> of matrix $A$, is defined as $A^\\dagger = \\overline{(A^T)} = (\\overline{A})^T$.</p>\n<p>A matrix is known as <strong>Hermitian</strong> or <strong>self-adjoint</strong> if it equals its own adjoint: $A = A^\\dagger$. For example, the following matrix is Hermitian:</p>\n<p>$$\\begin{bmatrix}\n 1 &amp; i \\\\\n -i &amp; 2\n\\end{bmatrix}$$</p>\n<p>The adjoint of a matrix product can be calculated as follows:</p>\n<p>$$(AB)^\\dagger = B^\\dagger A^\\dagger$$</p>\n",
782
+ "asMarkdown": "\nThe final important single-matrix operation is a combination of the previous two. The **conjugate transpose**, also called the **adjoint** of matrix $A$, is defined as $A^\\dagger = \\overline{(A^T)} = (\\overline{A})^T$.\n\nA matrix is known as **Hermitian** or **self-adjoint** if it equals its own adjoint: $A = A^\\dagger$. For example, the following matrix is Hermitian:\n\n$$\\begin{bmatrix}\n 1 & i \\\\\\\\\n -i & 2\n\\end{bmatrix}$$\n\nThe adjoint of a matrix product can be calculated as follows:\n\n$$(AB)^\\dagger = B^\\dagger A^\\dagger$$"
783
+ }
784
+ ]
785
+ },
786
+ {
787
+ "type": "exercise",
788
+ "id": "linear_algebra__adjoint_ex",
789
+ "title": "Adjoint of a Matrix",
790
+ "description": {
791
+ "type": "text-content",
792
+ "asHtml": "<p><strong>Input:</strong> None.</p>\n<p><strong>Goal:</strong> Return the adjoint of the following matrix:</p>\n<p>$$\\begin{bmatrix} 1 + 5i &amp; 2 \\\\ 3 - 6i &amp; 4i \\end{bmatrix}$$</p>\n",
793
+ "asMarkdown": "**Input:** None.\n\n**Goal:** Return the adjoint of the following matrix:\n\n$$\\begin{bmatrix} 1 + 5i & 2 \\\\\\ 3 - 6i & 4i \\end{bmatrix}$$\n"
794
+ },
795
+ "sourceIds": [
796
+ "linear_algebra__adjoint__Verification.qs",
797
+ "linear_algebra__Common.qs"
798
+ ],
799
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function MatrixAdjoint() : Complex[][] {\n // Replace the return value with correct answer.\n return [[Complex(0., 0.), Complex(0., 0.)],\n [Complex(0., 0.), Complex(0., 0.)]];\n }\n}\n",
800
+ "explainedSolution": {
801
+ "type": "explained-solution",
802
+ "items": [
803
+ {
804
+ "type": "text-content",
805
+ "asHtml": "<p>To get the adjoint, we perform both transpose and conjugate operations on the input matrix, in any order.\nThe easiest way is to start with the conjugate of the matrix that we found in the previous exercise, and then transpose it.</p>\n",
806
+ "asMarkdown": "\nTo get the adjoint, we perform both transpose and conjugate operations on the input matrix, in any order.\nThe easiest way is to start with the conjugate of the matrix that we found in the previous exercise, and then transpose it."
807
+ },
808
+ {
809
+ "type": "solution",
810
+ "id": "linear_algebra__adjoint_solution",
811
+ "code": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function MatrixAdjoint() : Complex[][] {\n return [[Complex(1., -5.), Complex(3., 6.)],\n [Complex(2., 0.), Complex(0., -4.)]];\n }\n}\n"
812
+ }
813
+ ]
814
+ }
815
+ },
816
+ {
817
+ "type": "lesson",
818
+ "id": "linear_algebra__unitary",
819
+ "title": "Unitary Matrices",
820
+ "items": [
821
+ {
822
+ "type": "text-content",
823
+ "asHtml": "<p><strong>Unitary matrices</strong> are very important for quantum computing. A matrix is unitary when it is invertible, and its inverse is equal to its adjoint: $U^{-1} = U^\\dagger$. That is, an $n \\times n$ square matrix $U$ is unitary if and only if $UU^\\dagger = U^\\dagger U = I_n$.</p>\n<h2>🔎 Analyze</h2>\n<p>Is this matrix unitary?</p>\n<p>$$A = \\begin{bmatrix}\n \\frac{1}{\\sqrt{2}} &amp; \\frac{1}{\\sqrt{2}} \\\\\n \\frac{i}{\\sqrt{2}} &amp; \\frac{-i}{\\sqrt{2}}\n\\end{bmatrix} = \n\\frac{1}{\\sqrt{2}} \\begin{bmatrix}\n 1 &amp; 1 \\\\\n i &amp; -i\n\\end{bmatrix}$$</p>\n<details>\n<summary><b>Solution</b></summary>\nTo check whether the input matrix is unitary, we will need to perform the following steps:\n\n<ol>\n<li>Calculate the adjoint of the input matrix $A^\\dagger$.</li>\n</ol>\n<p>$$A^\\dagger = \\frac{1}{\\sqrt{2}} \\begin{bmatrix}\n 1 &amp; -i \\\\\n 1 &amp; i\n\\end{bmatrix}$$</p>\n<ol start=\"2\">\n<li>Multiply it by the input matrix.</li>\n</ol>\n<p>$$AA^\\dagger = \\frac12 \\begin{bmatrix}\n 1 &amp; 1 \\\\\n i &amp; -i\n\\end{bmatrix} \\begin{bmatrix}\n 1 &amp; -i \\\\\n 1 &amp; i\n\\end{bmatrix} = \\frac12 \\begin{bmatrix}\n 1 \\cdot 1 + 1 \\cdot 1 &amp; 1 \\cdot (-i) + 1 \\cdot i \\\\\n i \\cdot 1 + (-i) \\cdot 1 &amp; i \\cdot (-i) + (-i) \\cdot i\n\\end{bmatrix} = \\begin{bmatrix}\n 1 &amp; 0 \\\\\n 0 &amp; 1\n\\end{bmatrix}$$</p>\n<p>If the multiplication result $AA^\\dagger$ is an identity matrix, which is indeed the case, \nand the product $A^\\dagger A$ is also an identity matrix (which you can verify in a similar manner),\nthe matrix is unitary.</p>\n</details>",
824
+ "asMarkdown": "\n**Unitary matrices** are very important for quantum computing. A matrix is unitary when it is invertible, and its inverse is equal to its adjoint: $U^{-1} = U^\\dagger$. That is, an $n \\times n$ square matrix $U$ is unitary if and only if $UU^\\dagger = U^\\dagger U = I_n$.\n\n## 🔎 Analyze\n\nIs this matrix unitary?\n\n$$A = \\begin{bmatrix}\n \\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\\\\\\n \\frac{i}{\\sqrt{2}} & \\frac{-i}{\\sqrt{2}}\n\\end{bmatrix} = \n\\frac{1}{\\sqrt{2}} \\begin{bmatrix}\n 1 & 1 \\\\\\\\\n i & -i\n\\end{bmatrix}$$\n\n<details>\n<summary><b>Solution</b></summary>\nTo check whether the input matrix is unitary, we will need to perform the following steps:\n\n1. Calculate the adjoint of the input matrix $A^\\dagger$.\n\n$$A^\\dagger = \\frac{1}{\\sqrt{2}} \\begin{bmatrix}\n 1 & -i \\\\\\\\\n 1 & i\n\\end{bmatrix}$$\n\n2. Multiply it by the input matrix.\n\n$$AA^\\dagger = \\frac12 \\begin{bmatrix}\n 1 & 1 \\\\\\\\\n i & -i\n\\end{bmatrix} \\begin{bmatrix}\n 1 & -i \\\\\\\\\n 1 & i\n\\end{bmatrix} = \\frac12 \\begin{bmatrix}\n 1 \\cdot 1 + 1 \\cdot 1 & 1 \\cdot (-i) + 1 \\cdot i \\\\\\\\\n i \\cdot 1 + (-i) \\cdot 1 & i \\cdot (-i) + (-i) \\cdot i\n\\end{bmatrix} = \\begin{bmatrix}\n 1 & 0 \\\\\\\\\n 0 & 1\n\\end{bmatrix}$$\n\nIf the multiplication result $AA^\\dagger$ is an identity matrix, which is indeed the case, \nand the product $A^\\dagger A$ is also an identity matrix (which you can verify in a similar manner),\nthe matrix is unitary.\n\n</details>"
825
+ }
826
+ ]
827
+ },
828
+ {
829
+ "type": "lesson",
830
+ "id": "linear_algebra__inner_product",
831
+ "title": "Inner Product",
832
+ "items": [
833
+ {
834
+ "type": "text-content",
835
+ "asHtml": "<p>The <strong>inner product</strong> is yet another important matrix operation that is only applied to vectors. Given two vectors $V$ and $W$ of the same size, their inner product $\\langle V , W \\rangle$ is defined as a product of matrices $V^\\dagger$ and $W$:</p>\n<p>$$\\langle V , W \\rangle = V^\\dagger W$$</p>\n<p>Let&#39;s break this down so it&#39;s a bit easier to understand. A $1 \\times n$ matrix (the adjoint of an $n \\times 1$ vector) multiplied by an $n \\times 1$ vector results in a $1 \\times 1$ matrix (which is equivalent to a scalar). The result of an inner product is that scalar. </p>\n<p>To put it another way, to calculate the inner product of two vectors, take the corresponding elements $V_k$ and $W_k$, multiply the complex conjugate of $V_k$ by $W_k$, and add up those products:</p>\n<p>$$\\langle V , W \\rangle = \\sum_{k=0}^{n-1}\\overline{V_k}W_k$$</p>\n<p>If you are familiar with the <strong>dot product</strong>, you will notice that it is equivalent to inner product for real-numbered vectors.</p>\n<blockquote>\n<p>We use our definition for these tutorials because it matches the notation used in quantum computing. You might encounter other sources which define the inner product a little differently: $\\langle V , W \\rangle = W^\\dagger V = V^T\\overline{W}$, in contrast to the $V^\\dagger W$ that we use. These definitions are almost equivalent, with some differences in the scalar multiplication by a complex number.</p>\n</blockquote>\n<p>An immediate application for the inner product is computing the <strong>vector norm</strong>. The norm of vector $V$ is defined as $||V|| = \\sqrt{\\langle V , V \\rangle}$. This condenses the vector down to a single non-negative real value. If the vector represents coordinates in space, the norm happens to be the length of the vector. A vector is called <strong>normalized</strong> if its norm is equal to $1$.</p>\n<p>The inner product has the following properties:</p>\n<ul>\n<li>Distributivity over addition: $\\langle V + W , X \\rangle = \\langle V , X \\rangle + \\langle W , X \\rangle$ and $\\langle V , W + X \\rangle = \\langle V , W \\rangle + \\langle V , X \\rangle$</li>\n<li>Partial associativity with scalar multiplication: $x \\cdot \\langle V , W \\rangle = \\langle \\overline{x}V , W \\rangle = \\langle V , xW \\rangle$</li>\n<li>Skew symmetry: $\\langle V , W \\rangle = \\overline{\\langle W , V \\rangle}$</li>\n<li>Multiplying a vector by a unitary matrix <strong>preserves the vector&#39;s inner product with itself</strong> (and therefore the vector&#39;s norm): $\\langle UV , UV \\rangle = \\langle V , V \\rangle$</li>\n</ul>\n<blockquote>\n<p>Note that just like matrix multiplication, the inner product is <strong>not commutative</strong>: $\\langle V , W \\rangle$ won&#39;t always equal $\\langle W , V \\rangle$.</p>\n</blockquote>\n",
836
+ "asMarkdown": "\nThe **inner product** is yet another important matrix operation that is only applied to vectors. Given two vectors $V$ and $W$ of the same size, their inner product $\\langle V , W \\rangle$ is defined as a product of matrices $V^\\dagger$ and $W$:\n\n$$\\langle V , W \\rangle = V^\\dagger W$$\n\nLet's break this down so it's a bit easier to understand. A $1 \\times n$ matrix (the adjoint of an $n \\times 1$ vector) multiplied by an $n \\times 1$ vector results in a $1 \\times 1$ matrix (which is equivalent to a scalar). The result of an inner product is that scalar. \n\nTo put it another way, to calculate the inner product of two vectors, take the corresponding elements $V_k$ and $W_k$, multiply the complex conjugate of $V_k$ by $W_k$, and add up those products:\n\n$$\\langle V , W \\rangle = \\sum_{k=0}^{n-1}\\overline{V_k}W_k$$\n\nIf you are familiar with the **dot product**, you will notice that it is equivalent to inner product for real-numbered vectors.\n\n> We use our definition for these tutorials because it matches the notation used in quantum computing. You might encounter other sources which define the inner product a little differently: $\\langle V , W \\rangle = W^\\dagger V = V^T\\overline{W}$, in contrast to the $V^\\dagger W$ that we use. These definitions are almost equivalent, with some differences in the scalar multiplication by a complex number.\n\nAn immediate application for the inner product is computing the **vector norm**. The norm of vector $V$ is defined as $||V|| = \\sqrt{\\langle V , V \\rangle}$. This condenses the vector down to a single non-negative real value. If the vector represents coordinates in space, the norm happens to be the length of the vector. A vector is called **normalized** if its norm is equal to $1$.\n\nThe inner product has the following properties:\n\n* Distributivity over addition: $\\langle V + W , X \\rangle = \\langle V , X \\rangle + \\langle W , X \\rangle$ and $\\langle V , W + X \\rangle = \\langle V , W \\rangle + \\langle V , X \\rangle$\n* Partial associativity with scalar multiplication: $x \\cdot \\langle V , W \\rangle = \\langle \\overline{x}V , W \\rangle = \\langle V , xW \\rangle$\n* Skew symmetry: $\\langle V , W \\rangle = \\overline{\\langle W , V \\rangle}$\n* Multiplying a vector by a unitary matrix **preserves the vector's inner product with itself** (and therefore the vector's norm): $\\langle UV , UV \\rangle = \\langle V , V \\rangle$\n\n> Note that just like matrix multiplication, the inner product is **not commutative**: $\\langle V , W \\rangle$ won't always equal $\\langle W , V \\rangle$."
837
+ }
838
+ ]
839
+ },
840
+ {
841
+ "type": "exercise",
842
+ "id": "linear_algebra__inner_product_ex",
843
+ "title": "Inner Product of Two Vectors",
844
+ "description": {
845
+ "type": "text-content",
846
+ "asHtml": "<p><strong>Input:</strong> None.</p>\n<p><strong>Goal:</strong> Return the inner product $\\langle V , W \\rangle$ of the following vectors:</p>\n<p>$$V = \\begin{bmatrix} -6 \\\\ 9i \\end{bmatrix}, W = \\begin{bmatrix} 3 \\\\ -8 \\end{bmatrix}$$</p>\n",
847
+ "asMarkdown": "**Input:** None.\n\n**Goal:** Return the inner product $\\langle V , W \\rangle$ of the following vectors:\n\n$$V = \\begin{bmatrix} -6 \\\\\\ 9i \\end{bmatrix}, W = \\begin{bmatrix} 3 \\\\\\ -8 \\end{bmatrix}$$\n"
848
+ },
849
+ "sourceIds": [
850
+ "linear_algebra__inner_product__Verification.qs",
851
+ "linear_algebra__Common.qs"
852
+ ],
853
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function InnerProduct() : Complex {\n // Replace the return value with correct answer.\n return Complex(0., 0.);\n }\n}\n",
854
+ "explainedSolution": {
855
+ "type": "explained-solution",
856
+ "items": [
857
+ {
858
+ "type": "text-content",
859
+ "asHtml": "<p>$$\\langle V, W \\rangle = V^\\dagger W = \n\\begin{bmatrix}\n -6 \\\\\n 9i\n\\end{bmatrix}^\\dagger\n\\begin{bmatrix}\n 3 \\\\\n -8\n\\end{bmatrix} =\n\\begin{bmatrix} -6 &amp; -9i \\end{bmatrix}\n\\begin{bmatrix}\n 3 \\\\\n -8\n\\end{bmatrix}\n= (-6) \\cdot 3 + (-9i) \\cdot (-8) = -18 + 72i$$</p>\n",
860
+ "asMarkdown": "\n$$\\langle V, W \\rangle = V^\\dagger W = \n\\begin{bmatrix}\n -6 \\\\\\\\\n 9i\n\\end{bmatrix}^\\dagger\n\\begin{bmatrix}\n 3 \\\\\\\\\n -8\n\\end{bmatrix} =\n\\begin{bmatrix} -6 & -9i \\end{bmatrix}\n\\begin{bmatrix}\n 3 \\\\\\\\\n -8\n\\end{bmatrix}\n= (-6) \\cdot 3 + (-9i) \\cdot (-8) = -18 + 72i$$"
861
+ },
862
+ {
863
+ "type": "solution",
864
+ "id": "linear_algebra__inner_product_solution",
865
+ "code": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function InnerProduct() : Complex {\n return Complex(-18., 72.);\n }\n}\n"
866
+ }
867
+ ]
868
+ }
869
+ },
870
+ {
871
+ "type": "exercise",
872
+ "id": "linear_algebra__normalized_vector",
873
+ "title": "Normalized Vector",
874
+ "description": {
875
+ "type": "text-content",
876
+ "asHtml": "<p><strong>Input:</strong> None.</p>\n<p><strong>Goal:</strong> Return the normalized vector $V$, defined as $\\frac{V}{||V||}$, where </p>\n<p>$$V = \\begin{bmatrix} -6 \\\\ 8i \\end{bmatrix}$$</p>\n<blockquote>\n<p>Vectors are $n \\times 1$ matrices, so in this exercise the result is represented as a two-dimensional array of complex numbers, with two rows each containing exactly one element. Vectors are commonly represented as one-dimensional arrays.</p>\n</blockquote>\n",
877
+ "asMarkdown": "**Input:** None.\n\n**Goal:** Return the normalized vector $V$, defined as $\\frac{V}{||V||}$, where \n\n$$V = \\begin{bmatrix} -6 \\\\\\ 8i \\end{bmatrix}$$\n\n> Vectors are $n \\times 1$ matrices, so in this exercise the result is represented as a two-dimensional array of complex numbers, with two rows each containing exactly one element. Vectors are commonly represented as one-dimensional arrays.\n"
878
+ },
879
+ "sourceIds": [
880
+ "linear_algebra__normalized_vector__Verification.qs",
881
+ "linear_algebra__Common.qs"
882
+ ],
883
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function NormalizedVector() : Complex[][] {\n // Replace the return value with correct answer.\n return [[Complex(0., 0.)],\n [Complex(0., 0.)]];\n }\n}\n",
884
+ "explainedSolution": {
885
+ "type": "explained-solution",
886
+ "items": [
887
+ {
888
+ "type": "text-content",
889
+ "asHtml": "<p>We start by calculating the norm of the vector</p>\n<p>$$||V|| = \\sqrt{\\langle V , V \\rangle} = \\sqrt{-6 \\cdot (-6) + (-8i) \\cdot 8i} = \\sqrt{6^2 + 8^2} = 10$$</p>\n<p>Then the normalized vector can be obtained by dividing each element of the original vector by its norm:</p>\n<p>$$\\frac{V}{||V||} = \\begin{bmatrix} -0.6 \\\\ 0.8i \\end{bmatrix}$$</p>\n",
890
+ "asMarkdown": "\nWe start by calculating the norm of the vector\n\n$$||V|| = \\sqrt{\\langle V , V \\rangle} = \\sqrt{-6 \\cdot (-6) + (-8i) \\cdot 8i} = \\sqrt{6^2 + 8^2} = 10$$\n\nThen the normalized vector can be obtained by dividing each element of the original vector by its norm:\n \n$$\\frac{V}{||V||} = \\begin{bmatrix} -0.6 \\\\\\ 0.8i \\end{bmatrix}$$"
891
+ },
892
+ {
893
+ "type": "solution",
894
+ "id": "linear_algebra__normalized_vector_solution",
895
+ "code": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function NormalizedVector() : Complex[][] {\n return [[Complex(-0.6, 0.)],\n [Complex(0., 0.8)]];\n }\n}\n"
896
+ }
897
+ ]
898
+ }
899
+ },
900
+ {
901
+ "type": "lesson",
902
+ "id": "linear_algebra__outer_product",
903
+ "title": "Outer Product",
904
+ "items": [
905
+ {
906
+ "type": "text-content",
907
+ "asHtml": "<p>The <strong>outer product</strong> of two vectors $V$ and $W$ is defined as $VW^\\dagger$. That is, the outer product of an $n \\times 1$ vector and an $m \\times 1$ vector is an $n \\times m$ matrix. If we denote the outer product of $V$ and $W$ as $X$, then $X_{i,j} = V_i \\cdot \\overline{W_j}$.</p>\n",
908
+ "asMarkdown": "\nThe **outer product** of two vectors $V$ and $W$ is defined as $VW^\\dagger$. That is, the outer product of an $n \\times 1$ vector and an $m \\times 1$ vector is an $n \\times m$ matrix. If we denote the outer product of $V$ and $W$ as $X$, then $X_{i,j} = V_i \\cdot \\overline{W_j}$."
909
+ }
910
+ ]
911
+ },
912
+ {
913
+ "type": "exercise",
914
+ "id": "linear_algebra__outer_product_ex",
915
+ "title": "Outer Product of Two Vectors",
916
+ "description": {
917
+ "type": "text-content",
918
+ "asHtml": "<p><strong>Input:</strong> None.</p>\n<p><strong>Goal:</strong> Return the outer product $VW^\\dagger$ of the following vectors:</p>\n<p>$$V = \\begin{bmatrix} -3i \\\\ 9 \\end{bmatrix}, W = \\begin{bmatrix} 9i \\\\ 2 \\end{bmatrix}$$</p>\n",
919
+ "asMarkdown": "**Input:** None.\n\n**Goal:** Return the outer product $VW^\\dagger$ of the following vectors:\n\n$$V = \\begin{bmatrix} -3i \\\\\\ 9 \\end{bmatrix}, W = \\begin{bmatrix} 9i \\\\\\ 2 \\end{bmatrix}$$\n"
920
+ },
921
+ "sourceIds": [
922
+ "linear_algebra__outer_product__Verification.qs",
923
+ "linear_algebra__Common.qs"
924
+ ],
925
+ "placeholderCode": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function OuterProduct() : Complex[][] {\n // Replace the return value with correct answer.\n return [[Complex(0., 0.), Complex(0., 0.)],\n [Complex(0., 0.), Complex(0., 0.)]];\n }\n}\n",
926
+ "explainedSolution": {
927
+ "type": "explained-solution",
928
+ "items": [
929
+ {
930
+ "type": "text-content",
931
+ "asHtml": "<p>$$\\begin{bmatrix} -3i \\\\ 9 \\end{bmatrix}\n\\begin{bmatrix} 9i \\\\ 2 \\end{bmatrix}^\\dagger =\n\\begin{bmatrix} -3i \\\\ 9 \\end{bmatrix}\n\\begin{bmatrix} -9i &amp; 2 \\end{bmatrix} =\n\\begin{bmatrix}\n (-3i) \\cdot (-9i) &amp; (-3i) \\cdot 2 \\\\\n 9 \\cdot (-9i) &amp; 9 \\cdot 2\n\\end{bmatrix} =\n\\begin{bmatrix}\n -27 &amp; -6i \\\\\n -81i &amp; 18\n\\end{bmatrix}$$</p>\n",
932
+ "asMarkdown": "\n$$\\begin{bmatrix} -3i \\\\\\ 9 \\end{bmatrix}\n\\begin{bmatrix} 9i \\\\\\ 2 \\end{bmatrix}^\\dagger =\n\\begin{bmatrix} -3i \\\\\\ 9 \\end{bmatrix}\n\\begin{bmatrix} -9i & 2 \\end{bmatrix} =\n\\begin{bmatrix}\n (-3i) \\cdot (-9i) & (-3i) \\cdot 2 \\\\\\\\\n 9 \\cdot (-9i) & 9 \\cdot 2\n\\end{bmatrix} =\n\\begin{bmatrix}\n -27 & -6i \\\\\\\\\n -81i & 18\n\\end{bmatrix}$$"
933
+ },
934
+ {
935
+ "type": "solution",
936
+ "id": "linear_algebra__outer_product_solution",
937
+ "code": "namespace Kata {\n open Microsoft.Quantum.Math;\n\n function OuterProduct() : Complex[][] {\n return [[Complex(-27., 0.), Complex(0., -6.)],\n [Complex(0., -81.), Complex(18., 0.)]];\n }\n}\n"
938
+ }
939
+ ]
940
+ }
941
+ },
942
+ {
943
+ "type": "lesson",
944
+ "id": "linear_algebra__tensor_product",
945
+ "title": "Tensor Product",
946
+ "items": [
947
+ {
948
+ "type": "text-content",
949
+ "asHtml": "<p>The <strong>tensor product</strong> is a different way of multiplying matrices. Rather than multiplying rows by columns, the tensor product multiplies the second matrix by every element of the first matrix.</p>\n<p>Given $n \\times m$ matrix $A$ and $k \\times l$ matrix $B$, their tensor product $A \\otimes B$ is an $(n \\cdot k) \\times (m \\cdot l)$ matrix defined as follows:</p>\n<p>$$A \\otimes B =\n\\begin{bmatrix}\n A_{0,0} \\cdot B &amp; A_{0,1} \\cdot B &amp; \\dotsb &amp; A_{0,m-1} \\cdot B \\\\\n A_{1,0} \\cdot B &amp; A_{1,1} \\cdot B &amp; \\dotsb &amp; A_{1,m-1} \\cdot B \\\\\n \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n A_{n-1,0} \\cdot B &amp; A_{n-1,1} \\cdot B &amp; \\dotsb &amp; A_{n-1,m-1} \\cdot B\n\\end{bmatrix} =$$\n$$= \\begin{bmatrix}\n A_{0,0} \\cdot \\begin{bmatrix}B_{0,0} &amp; \\dotsb &amp; B_{0,l-1} \\\\ \\vdots &amp; \\ddots &amp; \\vdots \\\\ B_{k-1,0} &amp; \\dotsb &amp; b_{k-1,l-1} \\end{bmatrix} &amp; \\dotsb &amp;\n A_{0,m-1} \\cdot \\begin{bmatrix}B_{0,0} &amp; \\dotsb &amp; B_{0,l-1} \\\\ \\vdots &amp; \\ddots &amp; \\vdots \\\\ B_{k-1,0} &amp; \\dotsb &amp; B_{k-1,l-1} \\end{bmatrix} \\\\\n \\vdots &amp; \\ddots &amp; \\vdots \\\\\n A_{n-1,0} \\cdot \\begin{bmatrix}B_{0,0} &amp; \\dotsb &amp; B_{0,l-1} \\\\ \\vdots &amp; \\ddots &amp; \\vdots \\\\ B_{k-1,0} &amp; \\dotsb &amp; B_{k-1,l-1} \\end{bmatrix} &amp; \\dotsb &amp;\n A_{n-1,m-1} \\cdot \\begin{bmatrix}B_{0,0} &amp; \\dotsb &amp; B_{0,l-1} \\\\ \\vdots &amp; \\ddots &amp; \\vdots \\\\ B_{k-1,0} &amp; \\dotsb &amp; B_{k-1,l-1} \\end{bmatrix}\n\\end{bmatrix} =$$\n$$= \\begin{bmatrix}\n A_{0,0} \\cdot B_{0,0} &amp; \\dotsb &amp; A_{0,0} \\cdot B_{0,l-1} &amp; \\dotsb &amp; A_{0,m-1} \\cdot B_{0,0} &amp; \\dotsb &amp; A_{0,m-1} \\cdot B_{0,l-1} \\\\\n \\vdots &amp; \\ddots &amp; \\vdots &amp; \\dotsb &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n A_{0,0} \\cdot B_{k-1,0} &amp; \\dotsb &amp; A_{0,0} \\cdot B_{k-1,l-1} &amp; \\dotsb &amp; A_{0,m-1} \\cdot B_{k-1,0} &amp; \\dotsb &amp; A_{0,m-1} \\cdot B_{k-1,l-1} \\\\\n \\vdots &amp; \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots &amp; \\vdots &amp; \\vdots \\\\\n A_{n-1,0} \\cdot B_{0,0} &amp; \\dotsb &amp; A_{n-1,0} \\cdot B_{0,l-1} &amp; \\dotsb &amp; A_{n-1,m-1} \\cdot B_{0,0} &amp; \\dotsb &amp; A_{n-1,m-1} \\cdot B_{0,l-1} \\\\\n \\vdots &amp; \\ddots &amp; \\vdots &amp; \\dotsb &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\n A_{n-1,0} \\cdot B_{k-1,0} &amp; \\dotsb &amp; A_{n-1,0} \\cdot B_{k-1,l-1} &amp; \\dotsb &amp; A_{n-1,m-1} \\cdot B_{k-1,0} &amp; \\dotsb &amp; A_{n-1,m-1} \\cdot B_{k-1,l-1}\n\\end{bmatrix}$$</p>\n<p>Notice that the tensor product of two vectors is another vector: if $V$ is an $n \\times 1$ vector, and $W$ is an $m \\times 1$ vector, $V \\otimes W$ is an $(n \\cdot m) \\times 1$ vector.</p>\n<p>The tensor product has the following properties:</p>\n<ul>\n<li>Distributivity over addition: $(A + B) \\otimes C = A \\otimes C + B \\otimes C$, $A \\otimes (B + C) = A \\otimes B + A \\otimes C$</li>\n<li>Associativity with scalar multiplication: $x(A \\otimes B) = (xA) \\otimes B = A \\otimes (xB)$</li>\n<li>Mixed-product property (relation with matrix multiplication): $(A \\otimes B) (C \\otimes D) = (AC) \\otimes (BD)$</li>\n</ul>\n",
950
+ "asMarkdown": "\nThe **tensor product** is a different way of multiplying matrices. Rather than multiplying rows by columns, the tensor product multiplies the second matrix by every element of the first matrix.\n\nGiven $n \\times m$ matrix $A$ and $k \\times l$ matrix $B$, their tensor product $A \\otimes B$ is an $(n \\cdot k) \\times (m \\cdot l)$ matrix defined as follows:\n\n$$A \\otimes B =\n\\begin{bmatrix}\n A_{0,0} \\cdot B & A_{0,1} \\cdot B & \\dotsb & A_{0,m-1} \\cdot B \\\\\\\\\n A_{1,0} \\cdot B & A_{1,1} \\cdot B & \\dotsb & A_{1,m-1} \\cdot B \\\\\\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n A_{n-1,0} \\cdot B & A_{n-1,1} \\cdot B & \\dotsb & A_{n-1,m-1} \\cdot B\n\\end{bmatrix} =$$\n$$= \\begin{bmatrix}\n A_{0,0} \\cdot \\begin{bmatrix}B_{0,0} & \\dotsb & B_{0,l-1} \\\\\\ \\vdots & \\ddots & \\vdots \\\\\\ B_{k-1,0} & \\dotsb & b_{k-1,l-1} \\end{bmatrix} & \\dotsb &\n A_{0,m-1} \\cdot \\begin{bmatrix}B_{0,0} & \\dotsb & B_{0,l-1} \\\\\\ \\vdots & \\ddots & \\vdots \\\\\\ B_{k-1,0} & \\dotsb & B_{k-1,l-1} \\end{bmatrix} \\\\\\\\\n \\vdots & \\ddots & \\vdots \\\\\\\\\n A_{n-1,0} \\cdot \\begin{bmatrix}B_{0,0} & \\dotsb & B_{0,l-1} \\\\\\ \\vdots & \\ddots & \\vdots \\\\\\ B_{k-1,0} & \\dotsb & B_{k-1,l-1} \\end{bmatrix} & \\dotsb &\n A_{n-1,m-1} \\cdot \\begin{bmatrix}B_{0,0} & \\dotsb & B_{0,l-1} \\\\\\ \\vdots & \\ddots & \\vdots \\\\\\ B_{k-1,0} & \\dotsb & B_{k-1,l-1} \\end{bmatrix}\n\\end{bmatrix} =$$\n$$= \\begin{bmatrix}\n A_{0,0} \\cdot B_{0,0} & \\dotsb & A_{0,0} \\cdot B_{0,l-1} & \\dotsb & A_{0,m-1} \\cdot B_{0,0} & \\dotsb & A_{0,m-1} \\cdot B_{0,l-1} \\\\\\\\\n \\vdots & \\ddots & \\vdots & \\dotsb & \\vdots & \\ddots & \\vdots \\\\\\\\\n A_{0,0} \\cdot B_{k-1,0} & \\dotsb & A_{0,0} \\cdot B_{k-1,l-1} & \\dotsb & A_{0,m-1} \\cdot B_{k-1,0} & \\dotsb & A_{0,m-1} \\cdot B_{k-1,l-1} \\\\\\\\\n \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots & \\vdots \\\\\\\\\n A_{n-1,0} \\cdot B_{0,0} & \\dotsb & A_{n-1,0} \\cdot B_{0,l-1} & \\dotsb & A_{n-1,m-1} \\cdot B_{0,0} & \\dotsb & A_{n-1,m-1} \\cdot B_{0,l-1} \\\\\\\\\n \\vdots & \\ddots & \\vdots & \\dotsb & \\vdots & \\ddots & \\vdots \\\\\\\\\n A_{n-1,0} \\cdot B_{k-1,0} & \\dotsb & A_{n-1,0} \\cdot B_{k-1,l-1} & \\dotsb & A_{n-1,m-1} \\cdot B_{k-1,0} & \\dotsb & A_{n-1,m-1} \\cdot B_{k-1,l-1}\n\\end{bmatrix}$$\n\nNotice that the tensor product of two vectors is another vector: if $V$ is an $n \\times 1$ vector, and $W$ is an $m \\times 1$ vector, $V \\otimes W$ is an $(n \\cdot m) \\times 1$ vector.\n\nThe tensor product has the following properties:\n\n* Distributivity over addition: $(A + B) \\otimes C = A \\otimes C + B \\otimes C$, $A \\otimes (B + C) = A \\otimes B + A \\otimes C$\n* Associativity with scalar multiplication: $x(A \\otimes B) = (xA) \\otimes B = A \\otimes (xB)$\n* Mixed-product property (relation with matrix multiplication): $(A \\otimes B) (C \\otimes D) = (AC) \\otimes (BD)$"
951
+ }
952
+ ]
953
+ },
954
+ {
955
+ "type": "exercise",
956
+ "id": "linear_algebra__tensor_product_ex",
957
+ "title": "Tensor Product of Two Matrices",
958
+ "description": {
959
+ "type": "text-content",
960
+ "asHtml": "<p><strong>Input:</strong> None.</p>\n<p><strong>Goal:</strong> Return the tensor product of the following two matrices:</p>\n<p>$$\\begin{bmatrix} 1 &amp; 2 \\\\ 3 &amp; 4 \\end{bmatrix} \\otimes \\begin{bmatrix} 5 &amp; 6 \\\\ 7 &amp; 8 \\end{bmatrix}$$</p>\n<blockquote>\n<p>In this task we&#39;re using real-valued matrices represented as Q# <code>Double[][]</code> type again for simplicity.</p>\n</blockquote>\n",
961
+ "asMarkdown": "**Input:** None.\n\n**Goal:** Return the tensor product of the following two matrices:\n\n$$\\begin{bmatrix} 1 & 2 \\\\\\ 3 & 4 \\end{bmatrix} \\otimes \\begin{bmatrix} 5 & 6 \\\\\\ 7 & 8 \\end{bmatrix}$$\n\n> In this task we're using real-valued matrices represented as Q# `Double[][]` type again for simplicity.\n"
962
+ },
963
+ "sourceIds": [
964
+ "linear_algebra__tensor_product__Verification.qs",
965
+ "linear_algebra__Common.qs"
966
+ ],
967
+ "placeholderCode": "namespace Kata {\n function TensorProduct() : Double[][] {\n // Replace the return value with correct answer.\n return [[0., 0., 0., 0.],\n [0., 0., 0., 0.],\n [0., 0., 0., 0.],\n [0., 0., 0., 0.]];\n }\n}\n",
968
+ "explainedSolution": {
969
+ "type": "explained-solution",
970
+ "items": [
971
+ {
972
+ "type": "text-content",
973
+ "asHtml": "<p>$$\\begin{bmatrix} 1 &amp; 2 \\\\ 3 &amp; 4 \\end{bmatrix} \\otimes \\begin{bmatrix} 5 &amp; 6 \\\\ 7 &amp; 8 \\end{bmatrix} =\n\\begin{bmatrix}\n 1 \\cdot \\begin{bmatrix} 5 &amp; 6 \\\\ 7 &amp; 8 \\end{bmatrix} &amp; 2 \\cdot \\begin{bmatrix} 5 &amp; 6 \\\\ 7 &amp; 8 \\end{bmatrix} \\\\\n 3 \\cdot \\begin{bmatrix} 5 &amp; 6 \\\\ 7 &amp; 8 \\end{bmatrix} &amp; 4 \\cdot \\begin{bmatrix} 5 &amp; 6 \\\\ 7 &amp; 8 \\end{bmatrix}\n\\end{bmatrix} =$$\n$$=\\begin{bmatrix}\n 1 \\cdot 5 &amp; 1 \\cdot 6 &amp; 2 \\cdot 5 &amp; 2 \\cdot 6 \\\\\n 1 \\cdot 7 &amp; 1 \\cdot 8 &amp; 2 \\cdot 7 &amp; 2 \\cdot 8 \\\\\n 3 \\cdot 5 &amp; 3 \\cdot 6 &amp; 4 \\cdot 5 &amp; 4 \\cdot 6 \\\\\n 3 \\cdot 7 &amp; 3 \\cdot 8 &amp; 4 \\cdot 7 &amp; 4 \\cdot 8\n\\end{bmatrix} =\n\\begin{bmatrix}\n 5 &amp; 6 &amp; 10 &amp; 12 \\\\\n 7 &amp; 8 &amp; 14 &amp; 16 \\\\\n 15 &amp; 18 &amp; 20 &amp; 24 \\\\\n 21 &amp; 24 &amp; 28 &amp; 32\n\\end{bmatrix}$$</p>\n",
974
+ "asMarkdown": "\n$$\\begin{bmatrix} 1 & 2 \\\\\\ 3 & 4 \\end{bmatrix} \\otimes \\begin{bmatrix} 5 & 6 \\\\\\ 7 & 8 \\end{bmatrix} =\n\\begin{bmatrix}\n 1 \\cdot \\begin{bmatrix} 5 & 6 \\\\\\ 7 & 8 \\end{bmatrix} & 2 \\cdot \\begin{bmatrix} 5 & 6 \\\\\\ 7 & 8 \\end{bmatrix} \\\\\\\\\n 3 \\cdot \\begin{bmatrix} 5 & 6 \\\\\\ 7 & 8 \\end{bmatrix} & 4 \\cdot \\begin{bmatrix} 5 & 6 \\\\\\ 7 & 8 \\end{bmatrix}\n\\end{bmatrix} =$$\n$$=\\begin{bmatrix}\n 1 \\cdot 5 & 1 \\cdot 6 & 2 \\cdot 5 & 2 \\cdot 6 \\\\\\\\\n 1 \\cdot 7 & 1 \\cdot 8 & 2 \\cdot 7 & 2 \\cdot 8 \\\\\\\\\n 3 \\cdot 5 & 3 \\cdot 6 & 4 \\cdot 5 & 4 \\cdot 6 \\\\\\\\\n 3 \\cdot 7 & 3 \\cdot 8 & 4 \\cdot 7 & 4 \\cdot 8\n\\end{bmatrix} =\n\\begin{bmatrix}\n 5 & 6 & 10 & 12 \\\\\\\\\n 7 & 8 & 14 & 16 \\\\\\\\\n 15 & 18 & 20 & 24 \\\\\\\\\n 21 & 24 & 28 & 32\n\\end{bmatrix}$$"
975
+ },
976
+ {
977
+ "type": "solution",
978
+ "id": "linear_algebra__tensor_product_solution",
979
+ "code": "namespace Kata {\n function TensorProduct() : Double[][] {\n return [[5., 6., 10., 12.],\n [7., 8., 14., 16.],\n [15., 18., 20., 24.],\n [21., 24., 28., 32.]];\n }\n}\n"
980
+ }
981
+ ]
982
+ }
983
+ },
984
+ {
985
+ "type": "lesson",
986
+ "id": "linear_algebra__conclusion",
987
+ "title": "Conclusion",
988
+ "items": [
989
+ {
990
+ "type": "text-content",
991
+ "asHtml": "<p>Congratulations! Now you know enough linear algebra to get started with quantum computing!</p>\n",
992
+ "asMarkdown": "\nCongratulations! Now you know enough linear algebra to get started with quantum computing!"
993
+ }
994
+ ]
995
+ }
996
+ ]
997
+ },
494
998
  {
495
999
  "id": "qubit",
496
1000
  "title": "The Qubit",
@@ -3203,7 +3707,7 @@ export default {
3203
3707
  },
3204
3708
  {
3205
3709
  "id": "complex_arithmetic__Common.qs",
3206
- "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Random; \n open Microsoft.Quantum.Convert;\n\n operation DrawRandomComplex() : Complex {\n // Generates a random complex number. \n let real = DrawRandomDouble(-10., 10.);\n let imag = DrawRandomDouble(-10., 10.);\n return Complex(real, imag);\n }\n\n operation ComplexAsString(x : Complex) : String {\n if x::Imag < 0.0 {\n $\"{x::Real} - {AbsD(x::Imag)}i\"\n } else {\n $\"{x::Real} + {x::Imag}i\"\n }\n }\n\n operation ComplexPolarAsString(x : ComplexPolar) : String {\n $\"{x::Magnitude} * exp({x::Argument}i)\"\n }\n\n operation CheckTwoComplexOpsAreSame(sol : (Complex, Complex) -> Complex, ref : (Complex, Complex) -> Complex) : Bool {\n for _ in 0 .. 24 {\n let x = DrawRandomComplex();\n let y = DrawRandomComplex();\n\n let expected = ref(x, y);\n let actual = sol(x, y);\n \n if not ComplexEqual(expected, actual) {\n Message(\"Incorrect\");\n Message($\"For x = {ComplexAsString(x)}, y = {ComplexAsString(y)} expected return {ComplexAsString(expected)}, actual return {ComplexAsString(actual)}.\");\n return false;\n }\n }\n\n Message(\"Correct!\");\n return true;\n }\n\n function ComplexEqual(x : Complex, y : Complex) : Bool { \n // Tests two complex numbers for equality.\n AbsD(x::Real - y::Real) <= 0.001 and AbsD(x::Imag - y::Imag) <= 0.001\n }\n\n function ComplexPolarEqual(x : ComplexPolar, y : ComplexPolar) : Bool { \n // Tests two complex polar numbers for equality.\n AbsD(x::Magnitude - y::Magnitude) <= 0.001 and AbsD(x::Argument - y::Argument) <= 0.001\n }\n}\n"
3710
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Random; \n open Microsoft.Quantum.Convert;\n\n operation DrawRandomComplex() : Complex {\n // Generates a random complex number. \n let real = DrawRandomDouble(-10., 10.);\n let imag = DrawRandomDouble(-10., 10.);\n return Complex(real, imag);\n }\n\n function ComplexAsString(x : Complex) : String {\n if x::Imag < 0.0 {\n $\"{x::Real} - {AbsD(x::Imag)}i\"\n } else {\n $\"{x::Real} + {x::Imag}i\"\n }\n }\n\n function ComplexPolarAsString(x : ComplexPolar) : String {\n $\"{x::Magnitude} * exp({x::Argument}i)\"\n }\n\n operation CheckTwoComplexOpsAreSame(sol : (Complex, Complex) -> Complex, ref : (Complex, Complex) -> Complex) : Bool {\n for _ in 0 .. 24 {\n let x = DrawRandomComplex();\n let y = DrawRandomComplex();\n\n let expected = ref(x, y);\n let actual = sol(x, y);\n \n if not ComplexEqual(expected, actual) {\n Message(\"Incorrect\");\n Message($\"For x = {ComplexAsString(x)}, y = {ComplexAsString(y)} expected return {ComplexAsString(expected)}, actual return {ComplexAsString(actual)}.\");\n return false;\n }\n }\n\n Message(\"Correct!\");\n return true;\n }\n\n function ComplexEqual(x : Complex, y : Complex) : Bool { \n // Tests two complex numbers for equality.\n AbsD(x::Real - y::Real) <= 0.001 and AbsD(x::Imag - y::Imag) <= 0.001\n }\n\n function ComplexPolarEqual(x : ComplexPolar, y : ComplexPolar) : Bool { \n // Tests two complex polar numbers for equality.\n AbsD(x::Magnitude - y::Magnitude) <= 0.001 and AbsD(x::Argument - y::Argument) <= 0.001\n }\n}\n"
3207
3711
  },
3208
3712
  {
3209
3713
  "id": "complex_arithmetic__complex_multiplication__Verification.qs",
@@ -3241,6 +3745,54 @@ export default {
3241
3745
  "id": "complex_arithmetic__polar_multiplication__Verification.qs",
3242
3746
  "code": "namespace Kata.Verification { \n open Microsoft.Quantum.Convert;\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n for _ in 0 .. 24 {\n let x = DrawRandomComplex();\n let y = DrawRandomComplex();\n let xp = ComplexAsComplexPolar(x);\n let yp = ComplexAsComplexPolar(y);\n\n let expected = ComplexAsComplexPolar(TimesC(x, y));\n let actual = Kata.ComplexPolarMult(xp, yp);\n \n if not ComplexPolarEqual(expected, actual) {\n Message(\"Incorrect\");\n Message($\"For x = {ComplexPolarAsString(xp)}, y = {ComplexPolarAsString(yp)} \" + \n $\"expected return {ComplexPolarAsString(expected)}, actual return {ComplexPolarAsString(actual)}.\");\n return false;\n }\n }\n\n Message(\"Correct!\");\n return true;\n }\n}"
3243
3747
  },
3748
+ {
3749
+ "id": "linear_algebra__addition__Verification.qs",
3750
+ "code": "namespace Kata.Verification {\n function Addition_Reference() : Double[][] {\n return [[6., 8.], \n [10., 12.]];\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n ArraysEqualD(Kata.Addition(), Addition_Reference())\n }\n}\n"
3751
+ },
3752
+ {
3753
+ "id": "linear_algebra__Common.qs",
3754
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n\n function ArraysEqualD(actual : Double[][], expected : Double[][]) : Bool {\n if Length(actual) != Length(expected) {\n Message(\"Incorrect\");\n Message($\"Expected number of rows {Length(expected)}, actual {Length(actual)}\");\n return false;\n }\n for i in 0 .. Length(actual) - 1 {\n if Length(actual[i]) != Length(expected[i]) {\n Message(\"Incorrect\");\n Message($\"For row {i}, expected number of columns {Length(expected[i])}, actual {Length(actual[i])}\");\n return false;\n }\n\n for j in 0 .. Length(actual[i]) - 1 {\n if AbsD(actual[i][j] - expected[i][j]) > 1e-9 {\n Message(\"Incorrect\");\n Message($\"For element in row {i}, column {j}, expected {expected[i][j]}, actual {actual[i][j]}\");\n return false;\n }\n }\n }\n \n Message(\"Correct!\");\n return true;\n }\n\n function ComplexAsString(x : Complex) : String {\n if x::Imag < 0.0 {\n $\"{x::Real} - {AbsD(x::Imag)}i\"\n } else {\n $\"{x::Real} + {x::Imag}i\"\n }\n }\n\n function ArraysEqualC(actual : Complex[][], expected : Complex[][]) : Bool {\n if Length(actual) != Length(expected) {\n Message(\"Incorrect\");\n Message($\"Expected number of rows {Length(expected)}, actual {Length(actual)}\");\n return false;\n }\n for i in 0 .. Length(actual) - 1 {\n if Length(actual[i]) != Length(expected[i]) {\n Message(\"Incorrect\");\n Message($\"For row {i}, expected number of columns {Length(expected[i])}, actual {Length(actual[i])}\");\n return false;\n }\n\n for j in 0 .. Length(actual[i]) - 1 {\n if AbsComplex(MinusC(actual[i][j], expected[i][j])) > 1e-9 {\n Message(\"Incorrect\");\n Message($\"For element in row {i}, column {j}, expected {ComplexAsString(expected[i][j])}, actual {ComplexAsString(actual[i][j])}\");\n return false;\n }\n }\n }\n \n Message(\"Correct!\");\n return true;\n }\n}\n"
3755
+ },
3756
+ {
3757
+ "id": "linear_algebra__scalar_multiplication__Verification.qs",
3758
+ "code": "namespace Kata.Verification {\n function ScalarMultiplication_Reference() : Double[][] {\n return [[0.5, 1.], \n [1.5, 2.]];\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n ArraysEqualD(Kata.ScalarMultiplication(), ScalarMultiplication_Reference())\n }\n}\n"
3759
+ },
3760
+ {
3761
+ "id": "linear_algebra__multiplication__Verification.qs",
3762
+ "code": "namespace Kata.Verification {\n function Multiplication_Reference() : Double[][] {\n return [[19., 22.], \n [43., 50.]];\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n ArraysEqualD(Kata.Multiplication(), Multiplication_Reference())\n }\n}\n"
3763
+ },
3764
+ {
3765
+ "id": "linear_algebra__inverse__Verification.qs",
3766
+ "code": "namespace Kata.Verification {\n function Inverse_Reference() : Double[][] {\n return [[-2., 1.], \n [1.5, -0.5]];\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n ArraysEqualD(Kata.Inverse(), Inverse_Reference())\n }\n}\n"
3767
+ },
3768
+ {
3769
+ "id": "linear_algebra__transpose__Verification.qs",
3770
+ "code": "namespace Kata.Verification {\n function Transpose_Reference() : Double[][] {\n return [[1., 3.], \n [2., 4.]];\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n ArraysEqualD(Kata.Transpose(), Transpose_Reference())\n }\n}\n"
3771
+ },
3772
+ {
3773
+ "id": "linear_algebra__conjugate__Verification.qs",
3774
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n\n function Conjugate_Reference() : Complex[][] {\n return [[Complex(1., -5.), Complex(2., 0.)],\n [Complex(3., 6.), Complex(0., -4.)]];\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n ArraysEqualC(Kata.Conjugate(), Conjugate_Reference())\n }\n}\n"
3775
+ },
3776
+ {
3777
+ "id": "linear_algebra__adjoint__Verification.qs",
3778
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n\n function MatrixAdjoint_Reference() : Complex[][] {\n return [[Complex(1., -5.), Complex(3., 6.)],\n [Complex(2., 0.), Complex(0., -4.)]];\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n ArraysEqualC(Kata.MatrixAdjoint(), MatrixAdjoint_Reference())\n }\n}\n"
3779
+ },
3780
+ {
3781
+ "id": "linear_algebra__inner_product__Verification.qs",
3782
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n\n function InnerProduct_Reference() : Complex {\n return Complex(-18., 72.);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n let actual = Kata.InnerProduct();\n let expected = InnerProduct_Reference();\n if AbsComplex(MinusC(actual, expected)) > 1e-9 {\n Message(\"Incorrect\");\n Message($\"Expected {ComplexAsString(expected)}, actual {ComplexAsString(actual)}\");\n return false;\n }\n \n Message(\"Correct!\");\n return true;\n }\n}\n"
3783
+ },
3784
+ {
3785
+ "id": "linear_algebra__normalized_vector__Verification.qs",
3786
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n\n function NormalizedVector_Reference() : Complex[][] {\n return [[Complex(-0.6, 0.)],\n [Complex(0., 0.8)]];\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n ArraysEqualC(Kata.NormalizedVector(), NormalizedVector_Reference())\n }\n}\n"
3787
+ },
3788
+ {
3789
+ "id": "linear_algebra__outer_product__Verification.qs",
3790
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n\n function OuterProduct_Reference() : Complex[][] {\n return [[Complex(-27., 0.), Complex(0., -6.)],\n [Complex(0., -81.), Complex(18., 0.)]];\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n ArraysEqualC(Kata.OuterProduct(), OuterProduct_Reference())\n }\n}\n"
3791
+ },
3792
+ {
3793
+ "id": "linear_algebra__tensor_product__Verification.qs",
3794
+ "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Math;\n\n function TensorProduct_Reference() : Double[][] {\n return [[5., 6., 10., 12.],\n [7., 8., 14., 16.],\n [15., 18., 20., 24.],\n [21., 24., 28., 32.]];\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n ArraysEqualD(Kata.TensorProduct(), TensorProduct_Reference())\n }\n}\n"
3795
+ },
3244
3796
  {
3245
3797
  "id": "qubit__learn_single_qubit_state__Verification.qs",
3246
3798
  "code": "namespace Kata.Verification {\n open Microsoft.Quantum.Intrinsic;\n open Microsoft.Quantum.Math;\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n use q = Qubit();\n\n // Prepare the state that will be passed to the solution.\n let angle = 0.5;\n Ry(angle, q);\n\n // Call the solution and get the answer.\n let (a, b) = Kata.LearnSingleQubitState(q);\n\n // Calculate the expected values based on the rotation angle.\n let (a_exp, b_exp) = (Cos(0.5 * angle), Sin(0.5 * angle));\n\n Reset(q);\n\n let isCorrect =\n (AbsD(a - a_exp) <= 0.001) and\n (AbsD(b - b_exp) <= 0.001);\n\n // Output different feedback to the user depending on whether the exercise was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"At least one of the amplitudes was too far from the expected value.\");\n }\n\n isCorrect\n }\n}\n"