microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
billti/kata-preview

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

katas/content/complex_arithmetic/complex_exponents/Verification.qs

28lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Math;
3 open Microsoft.Quantum.Random;
4
5 function ComplexExponent_Reference(x : Complex) : Complex {
6 let expa = E() ^ x::Real;
7 return Complex(expa * Cos(x::Imag), expa * Sin(x::Imag));
8 }
9
10 @EntryPoint()
11 operation CheckSolution() : Bool {
12 for _ in 0 .. 24 {
13 let x = DrawRandomComplex();
14
15 let expected = ComplexExponent_Reference(x);
16 let actual = Kata.ComplexExponent(x);
17
18 if not ComplexEqual(expected, actual) {
19 Message("Incorrect");
20 Message($"For x = {ComplexAsString(x)} expected return {ComplexAsString(expected)}, actual return {ComplexAsString(actual)}.");
21 return false;
22 }
23 }
24
25 Message("Correct!");
26 return true;
27 }
28}
29