// gates class implementation file

#include <stdafx.h>

#include "gates.h"

#include <math.h>
#include <string.h>

#define OOR2 0.7071067812
#define PI 3.141592654

// one bit gates

CButterfly::CButterfly() : CGate(1, "butterfly")
{
	garray[0].set(OOR2,0);
	garray[1].set(OOR2,0);
	garray[2].set(OOR2,0);
	garray[3].set(-OOR2,0);
}

CNot::CNot() : CGate(1, "not")
{
	garray[0].set(0,0);
	garray[1].set(1,0);
	garray[2].set(1,0);
	garray[3].set(0,0);
}

// two bit gates

CTwiddle::CTwiddle(int j, int k) : CGate(2, "twiddle")
{
	garray[0].set(1,0);
	garray[5].set(1,0);
	garray[10].set(1,0);
	garray[15].set(cos(PI/pow(2,k-j)), sin(PI/pow(2,k-j)));
}


CCnot2::CCnot2() : CGate(2, "2 bit cnot")
{
	garray[0].set(1,0);
	garray[5].set(1,0);
	garray[11].set(1,0);
	garray[14].set(1,0);
}

// three bit gates

CCnot3::CCnot3() : CGate(3, "3 bit cnot")
{
	garray[0].set(1,0);
	garray[9].set(1,0);
	garray[18].set(1,0);
	garray[27].set(1,0);
	garray[36].set(1,0);
	garray[45].set(1,0);
	garray[55].set(1,0);
	garray[62].set(1,0);
}

