@@ -138,9 +138,9 @@ operation HalfAdderForInc(x : Qubit, y : Qubit, carryOut : Qubit) : Unit is Adj
138
138
use helper = Qubit ();
139
139
140
140
within {
141
- ApplyAndAssuming0Target (x , y , helper );
141
+ AND (x , y , helper );
142
142
} apply {
143
- ApplyAndAssuming0Target (ctl , helper , carryOut );
143
+ AND (ctl , helper , carryOut );
144
144
}
145
145
CCNOT (ctl , x , y );
146
146
}
@@ -178,7 +178,7 @@ operation FullAdderForInc(carryIn : Qubit, x : Qubit, y : Qubit, carryOut : Qubi
178
178
operation FullAdder (carryIn : Qubit , x : Qubit , y : Qubit , carryOut : Qubit ) : Unit is Adj {
179
179
CNOT (x , y );
180
180
CNOT (x , carryIn );
181
- ApplyAndAssuming0Target (y , carryIn , carryOut );
181
+ AND (y , carryIn , carryOut );
182
182
CNOT (x , y );
183
183
CNOT (x , carryOut );
184
184
CNOT (y , carryIn );
@@ -190,7 +190,7 @@ operation CarryForInc(carryIn : Qubit, x : Qubit, y : Qubit, carryOut : Qubit) :
190
190
body (... ) {
191
191
CNOT (carryIn , x );
192
192
CNOT (carryIn , y );
193
- ApplyAndAssuming0Target (x , y , carryOut );
193
+ AND (x , y , carryOut );
194
194
CNOT (carryIn , carryOut );
195
195
}
196
196
adjoint auto ;
@@ -209,7 +209,7 @@ operation CarryForInc(carryIn : Qubit, x : Qubit, y : Qubit, carryOut : Qubit) :
209
209
operation UncarryForInc (carryIn : Qubit , x : Qubit , y : Qubit , carryOut : Qubit ) : Unit is Adj + Ctl {
210
210
body (... ) {
211
211
CNOT (carryIn , carryOut );
212
- Adjoint ApplyAndAssuming0Target (x , y , carryOut );
212
+ Adjoint AND (x , y , carryOut );
213
213
CNOT (carryIn , x );
214
214
CNOT (x , y );
215
215
}
@@ -220,92 +220,24 @@ operation UncarryForInc(carryIn : Qubit, x : Qubit, y : Qubit, carryOut : Qubit)
220
220
let ctl = ctls [0 ];
221
221
222
222
CNOT (carryIn , carryOut );
223
- Adjoint ApplyAndAssuming0Target (x , y , carryOut );
223
+ Adjoint AND (x , y , carryOut );
224
224
CCNOT (ctl , x , y ); // Controlled X(ctls + [x], y);
225
225
CNOT (carryIn , x );
226
226
CNOT (carryIn , y );
227
227
}
228
228
controlled adjoint auto ;
229
229
}
230
230
231
- /// # Summary
232
- /// Applies AND gate between `control1` and `control2` and stores the result
233
- /// in `target` assuming `target` is in |0> state.
234
- ///
235
- /// # Description
236
- /// Inverts `target` if and only if both controls are 1, but assumes that
237
- /// `target` is in state 0. The operation has T-count 4, T-depth 2 and
238
- /// requires no helper qubit, and may therefore be preferable to a CCNOT
239
- /// operation, if `target` is known to be 0.
240
- /// The adjoint of this operation is measurement based and requires no T
241
- /// gates (but requires target to support branching on measurements).
242
- /// Although the Toffoli gate (CCNOT) will perform faster in simulations,
243
- /// this version has lower T gate requirements.
244
- /// # References
245
- /// - Cody Jones: "Novel constructions for the fault-tolerant Toffoli gate",
246
- /// Phys. Rev. A 87, 022328, 2013
247
- /// [arXiv:1212.5069](https://arxiv.org/abs/1212.5069)
248
- /// doi:10.1103/PhysRevA.87.022328
249
- @Config(Adaptive )
250
- operation ApplyAndAssuming0Target (control1 : Qubit , control2 : Qubit , target : Qubit ) : Unit is Adj {
251
- // NOTE: Eventually this operation will be public and intrinsic.
252
- body (... ) {
253
- CCNOT (control1 , control2 , target );
254
- }
255
- adjoint (... ) {
256
- H (target );
257
- if M (target ) == One {
258
- Reset (target );
259
- CZ (control1 , control2 );
260
- }
261
- }
262
- }
263
-
264
231
operation ApplyOrAssuming0Target (control1 : Qubit , control2 : Qubit , target : Qubit ) : Unit is Adj {
265
232
within {
266
233
X (control1 );
267
234
X (control2 );
268
235
} apply {
269
- ApplyAndAssuming0Target (control1 , control2 , target );
236
+ AND (control1 , control2 , target );
270
237
X (target );
271
238
}
272
239
}
273
240
274
- /// # Summary
275
- /// Applies AND gate between `control1` and `control2` and stores the result
276
- /// in `target` assuming `target` is in |0> state.
277
- ///
278
- /// # Description
279
- /// Inverts `target` if and only if both controls are 1, but assumes that
280
- /// `target` is in state 0. The operation has T-count 4, T-depth 2 and
281
- /// requires no helper qubit, and may therefore be preferable to a CCNOT
282
- /// operation, if `target` is known to be 0.
283
- /// This version is suitable for Base profile.
284
- /// Although the Toffoli gate (CCNOT) will perform faster in simulations,
285
- /// this version has lower T gate requirements.
286
- /// # References
287
- /// - Cody Jones: "Novel constructions for the fault-tolerant Toffoli gate",
288
- /// Phys. Rev. A 87, 022328, 2013
289
- /// [arXiv:1212.5069](https://arxiv.org/abs/1212.5069)
290
- /// doi:10.1103/PhysRevA.87.022328
291
- @Config(not Adaptive )
292
- operation ApplyAndAssuming0Target (control1 : Qubit , control2 : Qubit , target : Qubit ) : Unit is Adj {
293
- H (target );
294
- T (target );
295
- CNOT (control1 , target );
296
- CNOT (control2 , target );
297
- within {
298
- CNOT (target , control1 );
299
- CNOT (target , control2 );
300
- } apply {
301
- Adjoint T (control1 );
302
- Adjoint T (control2 );
303
- T (target );
304
- }
305
- H (target );
306
- S (target );
307
- }
308
-
309
241
/// # Summary
310
242
/// Computes carries for the look-ahead adder
311
243
operation ComputeCarries (ps : Qubit [], gs : Qubit []) : Unit is Adj {
@@ -318,8 +250,8 @@ operation ComputeCarries(ps : Qubit[], gs : Qubit[]) : Unit is Adj {
318
250
let registerPartition = MappedOverRange (t -> Floor (IntAsDouble (n ) / IntAsDouble (2 ^ t )) - 1 , 1 .. T - 1 );
319
251
let pWorkspace = [ps ] + Partitioned (registerPartition , qs );
320
252
321
- // Note that we cannot use ApplyAndAssuming0Target targeting gs[0]
322
- // as it may not be in the 0 state. We use regular CCNOT in GRounds and CRounds.
253
+ // Note that we cannot use AND gate targeting gs[0] as it may not be in the 0 state.
254
+ // We use regular CCNOT in GRounds and CRounds.
323
255
within {
324
256
PRounds (pWorkspace );
325
257
} apply {
@@ -354,7 +286,7 @@ operation PRounds(pWorkspace : Qubit[][]) : Unit is Adj {
354
286
let (current , next ) = (Rest (ws [0 ]), ws [1 ]);
355
287
356
288
for m in IndexRange (next ) {
357
- ApplyAndAssuming0Target (current [2 * m ], current [2 * m + 1 ], next [m ]);
289
+ AND (current [2 * m ], current [2 * m + 1 ], next [m ]);
358
290
}
359
291
}
360
292
}
@@ -447,7 +379,7 @@ operation ApplyActionIfGreaterThanOrEqualConstant<'T>(
447
379
448
380
within {
449
381
for i in 0 .. Length (cs1 ) - 1 {
450
- let op = cNormalized &&& (1L <<< (i + 1 )) != 0L ? ApplyAndAssuming0Target | ApplyOrAssuming0Target ;
382
+ let op = cNormalized &&& (1L <<< (i + 1 )) != 0L ? AND | ApplyOrAssuming0Target ;
451
383
op (cs1 [i ], xNormalized [i + 1 ], qs [i ]);
452
384
}
453
385
} apply {
@@ -510,7 +442,7 @@ operation CarryWith1CarryIn(
510
442
body (... ) {
511
443
X (x );
512
444
X (y );
513
- ApplyAndAssuming0Target (x , y , carryOut );
445
+ AND (x , y , carryOut );
514
446
X (carryOut );
515
447
}
516
448
@@ -568,10 +500,10 @@ operation LogDepthAndChain(ctls : Qubit[], tgts : Qubit[]) : Unit is Adj {
568
500
Fact (lc == lt + 1 , $"There must be exactly one more control qubit than target qubits (got {lc}, {lt})" );
569
501
570
502
if lt == 1 {
571
- ApplyAndAssuming0Target (ctls [0 ], ctls [1 ], tgts [0 ]);
503
+ AND (ctls [0 ], ctls [1 ], tgts [0 ]);
572
504
} elif lt == 2 {
573
- ApplyAndAssuming0Target (ctls [0 ], ctls [1 ], tgts [0 ]);
574
- ApplyAndAssuming0Target (ctls [2 ], tgts [0 ], tgts [1 ]);
505
+ AND (ctls [0 ], ctls [1 ], tgts [0 ]);
506
+ AND (ctls [2 ], tgts [0 ], tgts [1 ]);
575
507
} else {
576
508
let left = lc / 2 ;
577
509
let right = lc - left ;
@@ -584,6 +516,6 @@ operation LogDepthAndChain(ctls : Qubit[], tgts : Qubit[]) : Unit is Adj {
584
516
585
517
LogDepthAndChain (ctlsLeft , tgtsLeft );
586
518
LogDepthAndChain (ctlsRight , tgtsRight );
587
- ApplyAndAssuming0Target (Tail (tgtsLeft ), Tail (tgtsRight ), Tail (tgts ));
519
+ AND (Tail (tgtsLeft ), Tail (tgtsRight ), Tail (tgts ));
588
520
}
589
521
}
0 commit comments