-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update samples to reflect latest 1.7 changes; Update katas and stdlib…
… to use structs (#1797) This PR: - Updates katas to use structs instead of newtypes - Performs some minor katas formatting updates (consistency on spacing; removing trailing whitespace; etc) - Checks our samples for lint warnings or errors in the CI - updates our samples to use the latest style from Q# 1.7 - imports instead of opens - implicit entrypoint via `Main` - implicit namespaces - Adds stricter lint configs to projects within this repo Closes #1709 Thanks @ScottCarda-MS and @swernli for collaborating on this PR! --------- Co-authored-by: Scott Carda <[email protected]> Co-authored-by: Scott Carda <[email protected]> Co-authored-by: Stefan J. Wernli <[email protected]> Co-authored-by: Mariia Mykhailova <[email protected]>
- Loading branch information
1 parent
b2f7ddd
commit ce8303b
Showing
79 changed files
with
1,512 additions
and
1,585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
katas/content/complex_arithmetic/cartesian_to_polar/Solution.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
namespace Kata { | ||
open Microsoft.Quantum.Math; | ||
|
||
function ComplexToComplexPolar(x : Complex) : ComplexPolar { | ||
let (a, b) = x!; | ||
let (a, b) = (x.Real, x.Imag); | ||
return ComplexPolar(Sqrt(a * a + b * b), ArcTan2(b, a)); | ||
} | ||
} |
9 changes: 4 additions & 5 deletions
9
katas/content/complex_arithmetic/complex_addition/Placeholder.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
katas/content/complex_arithmetic/complex_addition/Solution.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
namespace Kata { | ||
namespace Kata { | ||
open Microsoft.Quantum.Math; | ||
|
||
function ComplexAdd(x : Complex, y: Complex) : Complex { | ||
let (a, b) = x!; | ||
let (c, d) = y!; | ||
return Complex(a + c, b + d); | ||
|
||
function ComplexAdd(x : Complex, y : Complex) : Complex { | ||
Complex(x.Real + y.Real, x.Imag + y.Imag) | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
katas/content/complex_arithmetic/complex_conjugate/Placeholder.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
katas/content/complex_arithmetic/complex_conjugate/Solution.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
namespace Kata { | ||
open Microsoft.Quantum.Math; | ||
namespace Kata { | ||
open Microsoft.Quantum.Math; | ||
|
||
operation ComplexConjugate(x : Complex) : Complex { | ||
return Complex(x::Real, -x::Imag); | ||
function ComplexConjugate(x : Complex) : Complex { | ||
Complex(x.Real, -x.Imag) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
katas/content/complex_arithmetic/complex_division/Placeholder.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
katas/content/complex_arithmetic/complex_division/Solution.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
namespace Kata { | ||
namespace Kata { | ||
open Microsoft.Quantum.Math; | ||
function ComplexDiv(x : Complex, y: Complex) : Complex { | ||
let (a, b) = x!; | ||
let (c, d) = y!; | ||
|
||
function ComplexDiv(x : Complex, y : Complex) : Complex { | ||
let (a, b) = (x.Real, x.Imag); | ||
let (c, d) = (y.Real, y.Imag); | ||
let denominator = c * c + d * d; | ||
let real = (a * c + b * d) / denominator; | ||
let imag = (- a * d + b * c) / denominator; | ||
return Complex(real, imag); | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
katas/content/complex_arithmetic/complex_exponents/Placeholder.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
namespace Kata { | ||
open Microsoft.Quantum.Math; | ||
|
||
function ComplexExponent(x : Complex) : Complex { | ||
// Implement your solution here... | ||
return Complex(0.0, 0.0); | ||
return Complex(0., 0.); | ||
} | ||
} |
7 changes: 3 additions & 4 deletions
7
katas/content/complex_arithmetic/complex_exponents/Solution.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
namespace Kata { | ||
namespace Kata { | ||
open Microsoft.Quantum.Math; | ||
|
||
function ComplexExponent (x : Complex) : Complex { | ||
let (a, b) = x!; | ||
return Complex(E()^a * Cos(b), E()^a * Sin(b)); | ||
function ComplexExponent(x : Complex) : Complex { | ||
Complex(E()^x.Real * Cos(x.Imag), E()^x.Real * Sin(x.Imag)) | ||
} | ||
} |
12 changes: 6 additions & 6 deletions
12
katas/content/complex_arithmetic/complex_exponents/Verification.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
namespace Kata { | ||
namespace Kata { | ||
open Microsoft.Quantum.Math; | ||
|
||
function ComplexModulus(x : Complex) : Double { | ||
let (a, b) = x!; | ||
let (a, b) = (x.Real, x.Imag); | ||
return Sqrt(a * a + b * b); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
katas/content/complex_arithmetic/complex_multiplication/Placeholder.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
katas/content/complex_arithmetic/complex_multiplication/Solution.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
namespace Kata { | ||
namespace Kata { | ||
open Microsoft.Quantum.Math; | ||
function ComplexMult(x : Complex, y: Complex) : Complex { | ||
let (a, b) = x!; | ||
let (c, d) = y!; | ||
|
||
function ComplexMult(x : Complex, y : Complex) : Complex { | ||
let (a, b) = (x.Real, x.Imag); | ||
let (c, d) = (y.Real, y.Imag); | ||
return Complex(a * c - b * d, a * d + b * c); | ||
} | ||
} |
11 changes: 5 additions & 6 deletions
11
katas/content/complex_arithmetic/complex_powers_real/Solution.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
namespace Kata { | ||
namespace Kata { | ||
open Microsoft.Quantum.Math; | ||
|
||
function ComplexExpReal(r : Double, x : Complex) : Complex { | ||
if AbsD(r) < 1e-9 { | ||
return Complex(0.0, 0.0); | ||
return Complex(0., 0.); | ||
} | ||
|
||
let (a, b) = x!; | ||
let ra = r ^ a; | ||
|
||
let ra = r^x.Real; | ||
let lnr = Log(r); | ||
return Complex(ra * Cos(b * lnr), ra * Sin(b * lnr)); | ||
return Complex(ra * Cos(x.Imag * lnr), ra * Sin(x.Imag * lnr)); | ||
} | ||
} |
26 changes: 13 additions & 13 deletions
26
katas/content/complex_arithmetic/complex_powers_real/Verification.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
namespace Kata.Verification { | ||
open Microsoft.Quantum.Math; | ||
open Microsoft.Quantum.Random; | ||
open Microsoft.Quantum.Random; | ||
|
||
function ComplexExpReal_Reference(r : Double, x : Complex) : Complex { | ||
if AbsD(r) < 1e-9 { | ||
return Complex(0.0, 0.0); | ||
return Complex(0., 0.); | ||
} | ||
let real = r ^ x::Real * Cos(x::Imag * Log(r)); | ||
let imaginary = r ^ x::Real * Sin(x::Imag * Log(r)); | ||
let real = r^x.Real * Cos(x.Imag * Log(r)); | ||
let imaginary = r^x.Real * Sin(x.Imag * Log(r)); | ||
return Complex(real, imaginary); | ||
} | ||
|
||
@EntryPoint() | ||
operation CheckSolution() : Bool { | ||
for ind in 0 .. 24 { | ||
for ind in 0..24 { | ||
let x = DrawRandomComplex(); | ||
let r = ind == 0 ? 0.0 | DrawRandomDouble(0., 10.); | ||
let r = ind == 0 ? 0.0 | DrawRandomDouble(0., 10.); | ||
|
||
let expected = ComplexExpReal_Reference(r, x); | ||
let actual = Kata.ComplexExpReal(r, x); | ||
|
||
let expected = ComplexExpReal_Reference(r, x); | ||
let actual = Kata.ComplexExpReal(r, x); | ||
|
||
if not ComplexEqual(expected, actual) { | ||
Message("Incorrect"); | ||
Message($"For x = {ComplexAsString(x)} and r = {r} expected return {ComplexAsString(expected)}, actual return {ComplexAsString(actual)}."); | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
|
||
Message("Correct!"); | ||
return true; | ||
return true; | ||
} | ||
} |
Oops, something went wrong.