/* * * Quantum Boolean Formula * Author: Mohammad Javad Dousti * University of Southern California (USC) * Code is written based on GFI 1.2 * */ //Quantum primitive gates //#include "gates.h" #include #include //Definition of given constants #define t 12 //size of the phase estimation register #define m 6 //size of the direction register (!!!NEED TO UPDATE HEX() IF CHANGING THIS VALUE!!!) #define x_max 2 //size of hex board in x direction #define y_max 2 //size of hex board in y direction #define s x_max*y_max //# of remaining moves; height of the tree #define width (m*s)+2 #define pi 3.14159 /*-------------------------------------My helper functions-----------------------------------*/ const double PI = 3.141592654; // Swaps 2 qubit states module Swap (qbit q1[1], qbit q2[1]){ CNOT (q2[0], q1[0]); CNOT (q1[0], q2[0]); CNOT (q2[0], q1[0]); } /*------------------Some helper functions borrowed from GSE implementation--------------------------*/ module controlledRz(qbit target[1], qbit control[1], double theta){ Rz(target[0],-1*theta/2); CNOT(target[0],control[0]); Rz(target[0],theta/2); CNOT(target[0],control[0]); } module ctrlH(qbit *target, qbit *ctrl) { S(*ctrl); Rz(*target,pi); Rz(*target,-pi/4); CNOT(*target, *ctrl); Rz(*target,pi/4); Rz(*target,-pi/2); CNOT(*target, *ctrl); Rz(*target,-pi/2); } module ControlledRotationPiMinus (qbit target[1], qbit control[1], int j){ int k; double power =1.0; power=pow(2, j); controlledRz (target, control, - (3*PI) / (2*power)); } module inverseQFT (qbit* topregister, int length_topregister){ int i,j; for (i =0;i2 module nToffoli(qbit target[1], qbit* in, int length_in){ //This should not lead to a compile error as long as the values are set in compile time. qbit ancilla[length_in-2]; int i; Toffoli (in[0], in[1], ancilla[0]); for(i=2; i=2; i--){ //forall Toffoli (in[i], ancilla[i-2], ancilla[i-1]); } } module AND(qbit target[1], qbit* in, int length_in){ PrepZ(target[0],0); if (length_in == 1){ CNOT(target[0], in[0]); }else if (length_in == 2){ Toffoli(in[0], in[1], target[0]); }else{ nToffoli(in, target, length_in); } } module NAND(qbit target[1], qbit* in, int length_in){ AND (&target[0], in, length_in); X(target[0]); } module NOR(qbit target[1], qbit* in, int length_in){ int i; for(i=0; i=0){ C_TESTPOS(&nctrl[0], index0-x_max, maskmap, bitmap, newmap); } if (index0 % x_max >0){ if (index0 -1 >= 0){ C_TESTPOS(&nctrl[0], index0-1, maskmap, bitmap, newmap); } if (index0 + x_max - 1 = 0){ C_TESTPOS(&nctrl[0], index0 - x_max + 1, maskmap, bitmap, newmap); } } Fredkin_decomp(ancilla[2], newmap[index0], nctrl[0]); Fredkin_decomp(ancilla[3], stale[0], nctrl[0]); } CNOT(ctrl[0], stale[0]); } } */ /* IARPA - GFI Algorithm 11 */ /* Progress status: done */ /* Classical implementation: No */ /*module CHECKWIN_RED(qbit redboard[s], qbit outcome[1]){ int index0; qbit blueboard[s]; //qbit outcome[1]; //initializing blueboard to 0 for(index0=0; index0>shift) & (pow(2,m) -1); // Address is a window into the position qbit register; // we'll just swap the bits we want into the address ancilla bits for (i=0; i=m; index0--){ //forall Toffoli(register1[index0-m], ctrl[0], register1[index0]); Toffoli(register1[index0], ctrl[0], register1[index0-m]); } } */ /* IARPA - GFI Algorithm 8 */ /* Progress status: done */ /*module C_TOCHILD(qbit ctrl[1], qbit pos[width], qbit dir[m], int w){ C_SHIFT_PLUS_M(&ctrl[0], pos, m); int qubit; for(qubit=0; qubit