Created
December 6, 2020 09:31
-
-
Save bpatra/6848499c79dacee27553d94bd0c305eb to your computer and use it in GitHub Desktop.
Operation in QSharp
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
operation TwoBitstringSuperposition (qs : Qubit[], bits1 : Bool[], bits2 : Bool[]) : Unit { | |
mutable i0 = Length(qs); | |
for (i in 0..Length(qs)-1){ | |
if(bits1[i] == bits2[i]){ | |
if(bits1[i]){ | |
X(qs[i]); | |
} | |
}else{ | |
if(i > i0){ | |
if(bits1[i] == bits1[i0]){ | |
CNOT(qs[i0], qs[i]); | |
}else{ | |
X(qs[i0]); | |
CNOT(qs[i0], qs[i]); | |
X(qs[i0]); | |
} | |
}else{ | |
H(qs[i]); | |
set i0 = i; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment