9 Complex(); //Default constructor~Complex();//Default destructor.
10 void Set(double new_real
,double new_imaginary
); //Set data members.
11 double Real(); //Return the real part.
12 double Imaginary();//Return the imaginary part.
13 Complex
operator+(Complex
);//Overloaded+operator
14 Complex
operator*(Complex
);//Overloaded*operator
15 Complex
operator=(Complex
);//Overloaded=operator
16 int operator==(Complex
);//Overloaded==operator
25 Qubit();//Default constructor.
26 ~Qubit();//Default destructor.
27 int Measure();//Returns zero_state=0 or one_state=1 in accordanc
28 //with the probabilities of zero_state and one_state
29 void Dump();//Prints our zero_state,and one_state,without
30 //disturbing anything,this operation has no physic
31 //realization,it is only for information and debugin
32 //It should never be used in an algorithm for
34 void SetState(Complex zero_prob
,Complex one_prob
);
35 //Takes two complex numbers and sets the states t
37 void SetAverage();//Sets the state to 2^(1/2)zero_state,2^(1/2)
38 //one_state.No imaginary/phase component.
39 double MCC(int state
);//Multiply the zero or one state by its complex
40 //conjugate,and return the value.This valu
41 //will always be a real number,with no imagi
45 //The probability of finding the Qubit in the zero or all imarinary
46 //state.I currently use only the real portion.
48 //The probability of finding the Qubit in the one or all real state.//I currently use only the real portion.
49 //|zero_state|^2+|one_state|^2 should always be 1.
50 //This notation means z_s*ComplexConjugate(z_s)+o_s*
51 //ComplexConjugate(o_s)=1.
57 QuReg();//Default Constructor
58 QuReg(const QuReg
&);//Copy constructor
59 ~QuReg();//Default destructor.
60 int DecMeasure();//Measures our quantum register,and returns the
61 void Dump(int verbose
);
62 void SetState(Complex new_state
[]);
63 void SetAverage(int number
);
65 Complex
GetProb(int state
);
66 //Return the size of the register.
75 int power
=8;//265 is the smallest q ever is.
76 while(pow(2,power
)<pow(n
,2))
80 return((int)pow(2,power
));
85 int modexp(int x
,int a
,int n
)
140 void DFT(QuReg
*reg
,int q
)
142 Complex
*init
=new Complex
[q
];
149 for(int a
=0;a
<q
;a
++){
150 if((pow(reg
->GetProb(a
).Real(),2)+pow(reg
->GetProb(a
).Imaginary(),2))>pow(10,-14))
154 tmpcomp
.Set(pow(q
,-.5)*cos(2*PI
*a
*c
/q
),pow(q
,-.5)*sin(2*PI
*a
*c
/q
));
155 init
[c
]=init
[c
]+(reg
->GetProb(a
)*tmpcomp
);
163 cout
<<"Making progress in Fourier transform,"<<100*((double)a
/(double)(q
-1))
164 <<"%done!"<<endl
<<flush
;