microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.3.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/oracles/examples/MarkingOracleAltBit.qs

27lines · modecode

1namespace Kata {
2 open Microsoft.Quantum.Diagnostics;
3
4 // This operation implements the oracle; we will learn how to implement oracles later in the kata
5 operation AlternatingBitPattern_MarkingOracle(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {
6 ApplyControlledOnBitString([false, true, false], X, x, y);
7 ApplyControlledOnBitString([true, false, true], X, x, y);
8 }
9
10 @EntryPoint()
11 operation MarkingOracle_Demo() : Unit {
12 use (x, y) = (Qubit[3], Qubit());
13 ApplyToEachA(H, x);
14
15 Message("Starting state (equal superposition of all basis states ⊗ |0⟩):");
16 DumpMachine();
17
18 // Apply the oracle
19 AlternatingBitPattern_MarkingOracle(x, y);
20
21 // Print the resulting state; notice which amplitudes changed
22 Message("State after applying the marking oracle:");
23 DumpMachine();
24
25 ResetAll(x + [y]);
26 }
27}