/* * * 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 scaff_module Swap (qbit q1[1], qbit q2[1]){ CNOT ( q1[0],q2[0]); CNOT ( q2[0],q1[0]); CNOT ( q1[0],q2[0]); } /*------------------Some helper functions borrowed from GSE implementation--------------------------*/ scaff_module controlledRz(qbit target[1], qbit control[1], double theta){ Rz(target[0],-1*theta/2); CNOT(control[0],target[0]); Rz(target[0],theta/2); CNOT(control[0],target[0]); } scaff_module ctrlH(qbit *target, qbit *ctrl) { S(*ctrl); Rz(*target,pi); Rz(*target,-pi/4); CNOT( *ctrl,*target); Rz(*target,pi/4); Rz(*target,-pi/2); CNOT( *ctrl,*target); Rz(*target,-pi/2); } scaff_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)); } scaff_module inverseQFT (qbit* topregister, int length_topregister){ int i,j; for (i =0;i2 scaff_module nToffoli( int length_in, qbit* in,qbit target[1]){ //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 ( ancilla[0], in[1],in[0]); for(i=2; i=2; i--){ //forall Toffoli ( ancilla[i-1], ancilla[i-2],in[i]); } } scaff_module AND(qbit target[1], qbit* in, int length_in){ PrepZ(target[0],0); if (length_in == 1){ CNOT( in[0],target[0]); }else if (length_in == 2){ Toffoli( target[0], in[1],in[0]); }else{ nToffoli( length_in, target,in); } } scaff_module NAND(qbit target[1], qbit* in, int length_in){ AND (&target[0], in, length_in); X(target[0]); } scaff_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( stale[0],ctrl[0]); } } */ /* IARPA - GFI Algorithm 11 */ /* Progress status: done */ /* Classical implementation: No */ /*scaff_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], ctrl[0],register1[index0-m]); Toffoli( register1[index0-m], ctrl[0],register1[index0]); } } */ /* IARPA - GFI Algorithm 8 */ /* Progress status: done */ /*scaff_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; qubitval){ counter6 = (int)pow(2, power%val); power = power - (power%val); }else{ counter6=1; } val = 5*31; if (power>val){ counter5 = (int)pow(2, power%val); power = power - (power%val); }else{ counter5=1; } val = 4*31; if (power>val){ counter4 = (int)pow(2, power%val); power = power - (power%val); }else{ counter4=1; } val = 3*31; if (power>val){ counter3 = (int)pow(2, power%val); power = power - (power%val); }else{ counter3=1; } val = 2*31; if (power>val){ counter2 = (int)pow(2, power%val); power = power - (power%val); }else{ counter2=1; } val = 31; if (power>val){ counter1 = (int)pow(2, power%val); power = power - (power%val); }else{ counter1=1; } counter0 = (int)pow(2, power); power = 0; for(loop0=0; loop0Qbits--- */ /* ---Boolean Formula Fix: June 17 2018: CNOT/Toffoli ordering--- */ qbit red_input[12]; qbit blue_input[12]; PrepZ(red_input[0],0); PrepZ(red_input[1],1); PrepZ(red_input[2],0); PrepZ(red_input[3],0); PrepZ(blue_input[0],0); PrepZ(blue_input[1],1); PrepZ(blue_input[2],0); PrepZ(blue_input[3],1); //|a> =0 for (loop_counter=0; loop_counter