next up previous contents
Next: modarith.qcl Up: The Shor Algorithm in Previous: qufunct.qcl   Contents


operator dft(qureg q) { // main operator
  const n=#q;           // set n to length of input
  int i; int j;         // declare loop counters
  for i=0 to n-1 {
    for j=0 to i-1 {    // apply conditional phase gates
      CPhase(2*pi/2^(i-j+1),q[n-i-1] & q[n-j-1]);
    Mix(q[n-i-1]);      // qubit rotation
  flip(q);              // swap bit order of the output

(c) Bernhard Ömer - -