static double QfindOrder(long x, long y, int th) { double SdivR = 0; double t = 1.0; int tbit = 7; using (var sim = new QuantumSimulator()) { var res = OrderFinding.Run(sim, x, y).Result; for (int i = 0; i < tbit; i++) { t = t * 2.0; if (res[i] == 1) { SdivR = SdivR * 2 + 1; } else { SdivR = SdivR * 2; } } SdivR = SdivR / t; //Show the result Qubits Console.Write($"Thread {th} --- Result Qubits: "); for (int i = 0; i < tbit; i++) { Console.Write($"{res[i]}"); } Console.WriteLine($""); } return(SdivR); }
/// <summary> /// The quantum estimation calls the quantum algorithm in the Q# file which computes the permutation /// πⁱ(input) where i is a superposition of all values from 0 to 7. The algorithm then uses QFT to /// find a period in the resulting state. The result needs to be post-processed to find the estimate. /// <summary> private int GuessOrderQuantumOne(int index) { var result = OrderFinding.Run(_sim, new QArray <long>(_p.ConvertAll(x => (long)x)), (long)index).Result; if (result == 0) { var guess = _rnd.NextDouble(); // the probability distribution is extracted from the second // column (m = 0) in Fig. 2's table on the right-hand side, // in the original and referenced paper. if (guess <= 0.5505) { return(1); } else if (guess <= 0.5505 + 0.1009) { return(2); } else if (guess <= 0.5505 + 0.1009 + 0.1468) { return(3); } else { return(4); } } else if (result % 2 == 1) { return(3); } else if (result == 2 || result == 6) { return(4); } else /* result == 4 */ { return(2); } }