Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Commit 77cb481

Browse files
Remove parenthesis around the condition in the if block (p3) (#862)
1 parent 370b382 commit 77cb481

18 files changed

+68
-68
lines changed

Diff for: Superposition/Tests.qs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ namespace Quantum.Kata.Superposition {
266266
for i in 0 .. 3 {
267267
set numbers w/= i <- DrawRandomInt(0, 1 <<< N - 1);
268268
for j in 0 .. i - 1 {
269-
if (numbers[i] == numbers[j]) {
269+
if numbers[i] == numbers[j] {
270270
set ok = false;
271271
}
272272
}

Diff for: UnitaryPatterns/ReferenceImplementation.qs

+9-9
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace Quantum.Kata.UnitaryPatterns {
8080

8181
let N = Length(qs);
8282
// for N = 1, we need an identity
83-
if (N > 1) {
83+
if N > 1 {
8484
// do the bottom-right quarter
8585
ApplyToEachCA(Controlled H([Tail(qs)], _), Most(qs));
8686
// do the top-left quarter by calling the same operation recursively
@@ -151,7 +151,7 @@ namespace Quantum.Kata.UnitaryPatterns {
151151
// Helper function for Embedding_Perm: finds first location where bit strings differ.
152152
function FirstDiff (bits1 : Bool[], bits2 : Bool[]) : Int {
153153
for i in 0 .. Length(bits1)-1 {
154-
if (bits1[i] != bits2[i]) {
154+
if bits1[i] != bits2[i] {
155155
return i;
156156
}
157157
}
@@ -171,32 +171,32 @@ namespace Quantum.Kata.UnitaryPatterns {
171171
// we care only about 2 inputs: basis state of bits1 and bits2
172172

173173
// make sure that the state corresponding to bits1 has qs[diff] set to |0⟩
174-
if (bits1[diff]) {
174+
if bits1[diff] {
175175
X(qs[diff]);
176176
}
177177

178178
// iterate through the bit strings again, setting the final state of qubits
179179
for i in 0..n-1 {
180-
if (bits1[i] == bits2[i]) {
180+
if bits1[i] == bits2[i] {
181181
// if two bits are the same, set both to 1 using X or nothing
182-
if (not bits1[i]) {
182+
if not bits1[i] {
183183
X(qs[i]);
184184
}
185185
} else {
186186
// if two bits are different, set both to 1 using CNOT
187-
if (i > diff) {
188-
if (not bits1[i]) {
187+
if i > diff {
188+
if not bits1[i] {
189189
(ControlledOnInt(0,X))([qs[diff]], qs[i]);
190190
}
191-
if (not bits2[i]) {
191+
if not bits2[i] {
192192
CNOT(qs[diff], qs[i]);
193193
}
194194
}
195195
}
196196
}
197197

198198
// move the differing bit to the last qubit
199-
if (diff < n-1) {
199+
if diff < n-1 {
200200
SWAP(qs[n-1], qs[diff]);
201201
}
202202
}

Diff for: UnitaryPatterns/Tests.qs

+5-5
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ namespace Quantum.Kata.UnitaryPatterns {
178178
function TwoPatterns_Pattern (size : Int, row : Int, col : Int) : Bool {
179179
// top right and bottom left quarters are all 0
180180
let s2 = size / 2;
181-
if (row / s2 != col / s2) {
181+
if row / s2 != col / s2 {
182182
return false;
183183
}
184-
if (row / s2 == 0) {
184+
if row / s2 == 0 {
185185
// top left quarter is an anti-diagonal
186186
return row % s2 + col % s2 == s2 - 1;
187187
}
@@ -201,12 +201,12 @@ namespace Quantum.Kata.UnitaryPatterns {
201201
function IncreasingBlocks_Pattern (size : Int, row : Int, col : Int) : Bool {
202202
// top right and bottom left quarters are all 0
203203
let s2 = size / 2;
204-
if (row / s2 != col / s2) {
204+
if row / s2 != col / s2 {
205205
return false;
206206
}
207-
if (row / s2 == 0) {
207+
if row / s2 == 0 {
208208
// top left quarter is the same pattern for s2, except for the start of the recursion
209-
if (s2 == 1) {
209+
if s2 == 1 {
210210
return true;
211211
}
212212
return IncreasingBlocks_Pattern(s2, row, col);

Diff for: UnitaryPatterns/Workbook_UnitaryPatterns.ipynb

+7-7
Original file line numberDiff line numberDiff line change
@@ -1416,29 +1416,29 @@
14161416
" let diff = 0; // The index of the first bit at which the bit strings are different is 0 (successive indexes)\n",
14171417
" // we care only about 2 inputs: basis state of bits1 and bits2\n",
14181418
" // make sure that the state corresponding to bits1 has qs[diff] set to 0\n",
1419-
" if (bits1[diff]){\n",
1419+
" if bits1[diff] {\n",
14201420
" X(qs[diff]);\n",
14211421
" }\n",
14221422
" // iterate through the bit strings again, setting the final state of qubits\n",
14231423
" for i in 0 .. n-1 {\n",
1424-
" if (bits1[i] == bits2[i]) { // if two bits are the same, set both to 1 using X or nothing\n",
1425-
" if (not bits1[i]) {\n",
1424+
" if bits1[i] == bits2[i] { // if two bits are the same, set both to 1 using X or nothing\n",
1425+
" if not bits1[i] {\n",
14261426
" X(qs[i]);\n",
14271427
" }\n",
14281428
" } else { // if two bits are different, set both to 1 using CNOT\n",
1429-
" if (i > diff) {\n",
1430-
" if (not bits1[i]) {\n",
1429+
" if i > diff {\n",
1430+
" if not bits1[i] {\n",
14311431
" X(qs[diff]);\n",
14321432
" CNOT(qs[diff], qs[i]);\n",
14331433
" X(qs[diff]);\n",
14341434
" }\n",
1435-
" if (not bits2[i]){\n",
1435+
" if not bits2[i] {\n",
14361436
" CNOT(qs[diff], qs[i]);\n",
14371437
" }\n",
14381438
" }\n",
14391439
" }\n",
14401440
" }\n",
1441-
" if (diff < n-1) {\n",
1441+
" if diff < n-1 {\n",
14421442
" SWAP(qs[n-1], qs[diff]); // move the differing bit to the last qubit\n",
14431443
" }\n",
14441444
"}"

Diff for: tutorials/ExploringDeutschJozsaAlgorithm/BlackBoxes.qs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Quantum.Kata.DeutschJozsaAlgorithm {
4040
mutable nOnes = 0;
4141
mutable xBits = x;
4242
while (xBits > 0) {
43-
if (xBits % 2 > 0) {
43+
if xBits % 2 > 0 {
4444
set nOnes += 1;
4545
}
4646
set xBits /= 2;

Diff for: tutorials/ExploringDeutschJozsaAlgorithm/DeutschJozsaAlgorithmTutorial_P1.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
" mutable nOnes = 0;\n",
8787
" mutable xBits = x;\n",
8888
" while (xBits > 0) {\n",
89-
" if (xBits % 2 > 0) {\n",
89+
" if xBits % 2 > 0 {\n",
9090
" set nOnes += 1;\n",
9191
" }\n",
9292
" set xBits /= 2;\n",

Diff for: tutorials/ExploringDeutschJozsaAlgorithm/ReferenceImplementation.qs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace Quantum.Kata.DeutschJozsaAlgorithm {
3434
// Try all the following inputs to see if any of the values differ; should be run 2ᴺ⁻¹ times
3535
for input in 1 .. 2 ^ (N - 1) {
3636
let nextValue = f(input);
37-
if (nextValue != firstValue) {
37+
if nextValue != firstValue {
3838
// Got two different values - the function is balanced
3939
return false;
4040
}
@@ -83,7 +83,7 @@ namespace Quantum.Kata.DeutschJozsaAlgorithm {
8383
oracle(x);
8484
ApplyToEach(H, x);
8585
for q in x {
86-
if (M(q) == One) {
86+
if M(q) == One {
8787
set isConstantFunction = false;
8888
}
8989
}

Diff for: tutorials/ExploringDeutschJozsaAlgorithm/Tests.qs

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace Quantum.Kata.DeutschJozsaAlgorithm {
4848
let actual = IsFunctionConstant_Classical(N, f);
4949

5050
// check that the return value is correct
51-
if (actual != expected) {
51+
if actual != expected {
5252
let actualStr = ConstantOrBalanced(actual);
5353
let expectedStr = ConstantOrBalanced(expected);
5454
fail $" identified as {actualStr} but it is {expectedStr}.";
@@ -87,14 +87,14 @@ namespace Quantum.Kata.DeutschJozsaAlgorithm {
8787
let actual = DeutschAlgorithm(oracle);
8888

8989
// check that the return value is correct
90-
if (actual != expected) {
90+
if actual != expected {
9191
let actualStr = ConstantOrBalanced(actual);
9292
let expectedStr = ConstantOrBalanced(expected);
9393
fail $" identified as {actualStr} but it is {expectedStr}.";
9494
}
9595

9696
let nu = GetOracleCallsCount(oracle);
97-
if (nu > 1) {
97+
if nu > 1 {
9898
fail $" took {nu} oracle calls to decide; you are only allowed to call the oracle once";
9999
}
100100

@@ -137,14 +137,14 @@ namespace Quantum.Kata.DeutschJozsaAlgorithm {
137137
let actual = DeutschJozsaAlgorithm(N, oracle);
138138

139139
// check that the return value is correct
140-
if (actual != expected) {
140+
if actual != expected {
141141
let actualStr = ConstantOrBalanced(actual);
142142
let expectedStr = ConstantOrBalanced(expected);
143143
fail $" identified as {actualStr} but it is {expectedStr}.";
144144
}
145145

146146
let nu = GetOracleCallsCount(oracle);
147-
if (nu > 1) {
147+
if nu > 1 {
148148
fail $" took {nu} oracle calls to decide; you are only allowed to call the oracle once";
149149
}
150150

Diff for: tutorials/ExploringGroversAlgorithm/Code.qs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ namespace Quantum.Kata.ExploringGroversAlgorithm
177177
GroversAlgorithm_Loop(register, oracle, iter);
178178
let res = MultiM(register);
179179
oracle(register, answer);
180-
if (MResetZ(answer) == One) {
180+
if MResetZ(answer) == One {
181181
set correct += 1;
182182
}
183183
ResetAll(register);
@@ -205,7 +205,7 @@ namespace Quantum.Kata.ExploringGroversAlgorithm
205205
GroversAlgorithm_Loop(register, oracle, iter);
206206
let res = MultiM(register);
207207
oracle(register, answer);
208-
if (MResetZ(answer) == One) {
208+
if MResetZ(answer) == One {
209209
set correct += 1;
210210
}
211211
ResetAll(register);

Diff for: tutorials/ExploringGroversAlgorithm/ExploringGroversAlgorithmTutorial.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@
311311
" // One means the algorithm returned correct answer, Zero - incorrect.\n",
312312
" // You can measure the qubit and reset it immediately using MResetZ operation, \n",
313313
" // and compare the measurement result to the constants Zero or One using \"==\" operator.\n",
314-
" if (...) {\n",
314+
" if ... {\n",
315315
" // Report the correct/incorrect result using Message function.\n",
316316
" Message(...);\n",
317317
" } else {\n",
@@ -343,7 +343,7 @@
343343
" <summary><b>Click here for the complete answer validation code</b></summary>\n",
344344
"<code> use y = Qubit() {\n",
345345
" oracle(register, y);\n",
346-
" if (MResetZ(y) == One) {\n",
346+
" if MResetZ(y) == One {\n",
347347
" Message(\"Correct!\");\n",
348348
" } else {\n",
349349
" Message(\"Incorrect\");\n",
@@ -552,7 +552,7 @@
552552
" let answer = ResultArrayAsBoolArray(MultiM(register));\n",
553553
" use y = Qubit() {\n",
554554
" oracle(register, y);\n",
555-
" if (MResetZ(y) == One) {\n",
555+
" if MResetZ(y) == One {\n",
556556
" set successCount += 1;\n",
557557
" }\n",
558558
" }\n",

Diff for: tutorials/MultiQubitGates/Workbook_MultiQubitGates.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,15 @@
305305
"\n",
306306
"operation MultiControls (controls : Qubit[], target : Qubit, controlBits : Bool[]) : Unit is Adj {\n",
307307
" for (index in 0 .. Length(controls) - 1) {\n",
308-
" if (controlBits[index] == false) {\n",
308+
" if controlBits[index] == false {\n",
309309
" X(controls[index]); \n",
310310
" }\n",
311311
" }\n",
312312
" \n",
313313
" Controlled X(controls,target);\n",
314314
"\n",
315315
" for (index in 0 .. Length(controls) - 1) {\n",
316-
" if (controlBits[index] == false) {\n",
316+
" if controlBits[index] == false {\n",
317317
" X(controls[index]); \n",
318318
" }\n",
319319
" }\n",
@@ -338,7 +338,7 @@
338338
"operation MultiControls (controls : Qubit[], target : Qubit, controlBits : Bool[]) : Unit is Adj {\n",
339339
" within {\n",
340340
" for (index in 0 .. Length(controls) - 1) {\n",
341-
" if (controlBits[index] == false) {\n",
341+
" if controlBits[index] == false {\n",
342342
" X(controls[index]); \n",
343343
" }\n",
344344
" }\n",

Diff for: tutorials/MultiQubitSystemMeasurements/MultiQubitSystemMeasurements.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
" let register = LittleEndian(qs);\n",
147147
" // Prepare the state using PrepareArbitraryStateD library operation:\n",
148148
" PrepareArbitraryStateD(coefficients, register);\n",
149-
" if (i == 1) {\n",
149+
" if i == 1 {\n",
150150
" Message(\"The state |𝜓❭ of the system before measurement is:\");\n",
151151
" DumpMachine();\n",
152152
" } \n",
@@ -331,7 +331,7 @@
331331
" PrepareArbitraryStateD(coefficients, LittleEndian(qs));\n",
332332
" \n",
333333
" // Display the state of the qubits.\n",
334-
" if (i == 1) {\n",
334+
" if i == 1 {\n",
335335
" Message(\"The state |𝜓❭ of the system before measurement is:\");\n",
336336
" DumpMachine();\n",
337337
" Message(divider);\n",
@@ -341,7 +341,7 @@
341341
" let outcome = M(qs[0]) == Zero ? 0 | 1;\n",
342342
" set countArray w/= outcome <- countArray[outcome] + 1;\n",
343343
" \n",
344-
" if (countArray[outcome] == 1) { \n",
344+
" if countArray[outcome] == 1 { \n",
345345
" // The first time the outcome is 0/1, print the system state afterwards.\n",
346346
" Message(\"For outcome {outcome}, the post-measurement state of the system is:\");\n",
347347
" DumpMachine();\n",

Diff for: tutorials/MultiQubitSystemMeasurements/ReferenceImplementation.qs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ namespace Quantum.Kata.MultiQubitSystemMeasurements {
2828

2929
// Exercise 7. State selection using partial measurements
3030
operation StateSelction_Reference(qs : Qubit[], i : Int) : Unit {
31-
if (i == 0) {
32-
if (M(qs[0]) == One){
31+
if i == 0 {
32+
if M(qs[0]) == One {
3333
// apply the X gate to the second qubit
3434
X(qs[1]);
3535
}
3636
} else {
37-
if (M(qs[0]) == Zero){
37+
if M(qs[0]) == Zero {
3838
// apply the X gate to the second qubit only
3939
X(qs[1]);
4040
}

0 commit comments

Comments
 (0)