Benchmarks for quantum computers from Shor’s algorithm
Abstract
Properties of Shor’s algorithm and the related period-finding algorithm could serve as benchmarks for the operation of a quantum computer. Distinctive universal behaviour is expected for the probability for success of the period-finding algorithm as the input quantum register is increased through its critical size of qubits (where is the period sought). Use of quadratic non-residues permits unequivocal predictions to be made about the outcome of the factoring algorithm.
1 Introduction
The rapid development of quantum technologies over the last decade has prompted much research on techniques for checking that the carefully engineered quantum devices are, in fact, functioning properly [1, 2, 3]. In the survey of the field presented in [2], a distinction is drawn between certification (or verification) and benchmarking. Certification is taken to be confined to the assessment the accuracy of the output, whereas benchmarking protocols are any more general measures of performance. Clearly, in this parlance, Shor’s factoring algorithm and the associated period-finding algorithm can be used for verification as the validity of their output is easily checked, but the ancillary properties mentioned in the abstract and discussed below could serve as the basis for benchmarks that test circuits as a whole.
In Shor’s version of his factoring algorithm [4], a square-free semiprime is factored by first using a quantum computer to determine the order of an arbitrary element , or, more colloquially, the period of , and then using a classical computer to calculate the candidate for a non-trivial factor of . (Unless specified otherwise, the notation of [5] is adopted.)

It is the dependence on the period of the probability for success of the period-finding algorithm which is relevant to benchmarking. The nature of this dependence can be established by considering the sequence of input register sizes , where is the smallest positive integer such that
(1) |
and is any integer consistent with the requirement that the input register is large enough for the quantum Fourier transform of its state to yield information on , i.e. from the version of the first inequality in (5), or .
A systematic asymptotic analysis implies that, when , a useful approximation to the probability of finding a divisor of (or itself) with an input register of qubits is
(2) |
( is the sine integral of Eq. 6.2.9 in [6]). The monotonically increasing sequence is depicted in Fig. 1. The interpolating curve is obtained with the same function used to evaluate the ’s. As the derivation of section 2 and (28) make clear, the result in (2) pertains to the determination of the period of any function of the integers provided it is one-to-one within a period, and the period is not a divisor of . When is a power of two (and, hence, a divisor of ), the probability of success is independent of [see (28)].
The register of qubits is distinguished by the fact that it is, generically, the smallest for which exceeds 50%. Among the inferences that one can draw from Fig. 1 is that the magnitude of the probability of success for the period-finding algorithm amounts to a fingerprint of the critical input register. Statistics on the success or failure of runs for qubits would permit empirical determination of the corresponding probability of success of the period-finding algorithm; unambiguous comparison of the probability found with should be possible in view of its clear separation in value from the other ’s: this comparison constitutes the first benchmark, applicable whenever is not a divisor of (as is typically the case).
Corrections to , considered in section 3, do not invalidate any of the observations above. In fact, it is found that, for , these corrections are negligible (see (30), (31) and Table 2). The clear difference between the success probability for the critical input register and input registers of other sizes also survives (see Fig. 3).
Another opportunity for benchmarking is provided by the choice of the element . Leander has pointed out [7] that if is selected so that the Jacobi symbol (“Choice L”), then, not only is the order of guaranteed to be even, but also the probability that is a non-trivial factor of is enhanced; for even, is the desired factor provided : the conditional probability
(3) |
where the positive integer powers are related to the square-free semiprime by the parametrisation , it being understood that and are, by definition, odd. The success rate of the prescription for is at least 75% as compared with 50% if is chosen at random from , but this observation does not do justice to the full implications of (1).
The crux to building on Leander’s criterion for is to recognise that, in principle, it can only fail to generate a factor of if . When it is known that , then should be a quadratic non-residue modulo for which (“Choice ”); the corresponding probability that is a prime factor of is : if , must then be a non-trivial factor of . (As for choice L, the fact that is a quadratic non-residue ensures that its order is even.)
There are two clear-cut complementary benchmarking schemes and : scheme () entails determination of the probability that -choices (L-choices) for do actually yield a prime factor of given that (). Identification of whether or requires successful factorization of , which can be achieved with a suitable sequence of initial runs, beginning with a few L-choices, and converting to -choices if these runs fail. For both and , the empirical probability is to be compared with a predicted value of unity. The overhead placed on classical computer resources by the selection of appropriate values of is acceptable: calculation of the Jacobi symbols is efficient, as is checking that a given is a quadratic non-residue.
Application of the benchmarking procedures and should be preceded by determination of and . Provided and 2 are quadratic non-residues modulo , the values of these two Jacobi symbols permit one to infer whether or for all semiprimes such that — see Table 1. The import of Table 1 is that, for these semiprimes, the choice between and can be made before the order-finding algorithm is run. Blum integers are among the semiprimes to which the results of Table 1 apply.
Interpretation | Scheme | |
---|---|---|
It remains to justify the assertions made in this introduction. The exact reduction of the success probability associated with the period-finding algorithm to a form in (2.3) suitable for controlled approximation is presented in section 2, followed by its asymptotic analysis for large using the Euler-Maclaurin summation formula in section 3. Properties of choices L and are proven in section 4, and some closing comments are made in section 5. Appendices A, B and C contain technical results required in sections 2 and 3.
2 Period-finding: success probability
After the usual preparatory steps (outlined, for example, in Algorithm 5 of Ref. [5]), an -qubit input register is left in the superposition of computational basis states
(4) |
where is unknown (and unknowable), and the constraint on that
(5) |
guarantees that the superposition contains more than one term and, hence, that in (7) can manifest dependence on . Since
(6) |
where is a non-negative integer, an implication of (5) found useful below is that .
Interpretation of the quantum Fourier transform of the one-dimensional “array” of uniformly spaced “atoms” in (4) is possible via its “structure factor”
(7) |
which is related to the conditional probability that the transform is detected in the state by . Central to the standard analysis of is the observation that, for non-zero integers , is large () when the rational number , which must lie in the closed interval , is close to one of the integers in this interval, i.e.
(8) |
Thus, the “frequencies” most likely to be returned by measurement are drawn from the set of integers closest to the first members of the harmonic series with fundamental “frequency” :
(9) |
where the inequality is strict because can never be a half-integer. The solution of (9) is
(10) |
as inspection of Fig. 2 confirms.

Equation (9) acquires additional significance if viewed from the perspective of rational approximation with continued fractions. Provided the input register size is such that , then one of the finite number of convergents to coincides with the ratio reduced to lowest terms; if , then the only observed values of from which information of this nature can be inferred are precisely those belonging to the set : the total probability for success of the period-finding algorithm is
(11) |
More generally, when , the restriction on useful values of reads
(12) |
When , there are or solutions of (12) dependent on whether divides or not (); if , then the solutions are a subset of the ’s.
2.1 The case
Simplification of in (11) for arbitrary prepares the ground for analysis of the general case when (12) applies. The -fold invocation of the periodicity property permits substitution of by , where
(13) | ||||
which, significantly, is periodic in with period . As a result, the partition of into congruence classes modulo serves to identify the summands for different in (11) which are identical. For , the congruence classes in all contain elements, but the congruence class has only elements (because ); for , all elements of trivially belong to the single congruence class : thus,
(14) |
where the sum over now includes .
As shown in appendix A, the properties of least non-negative residues modulo imply that the distinct values of are equal to , where the ’s are the absolute least residues modulo :
(15) |
The change of summation variable in (14) from to is indicated. The argument is replaced by and
(16) |
which suffices to analyse the case .
2.2 Generalization to
The result in (16) is easily adapted to accommodate all cases in which . Solutions of (12) are those members of for which . In terms of the index introduced in connection with (15), this inequality specifies that or, as is odd,
(17) |
It follows that (16) is replaced by
(18) |
Unfortunately, the generalization to is not so immediate.
2.3 Generalization to
If , then (12) amounts to the inequality which has the integer solutions with
(19) |
For members of the remaining congruence classes summed over in (16), (12) can be recast in terms of the congruence class label of (15) as Now, the set of integer solutions depends on via its sign: takes on all values in the set
(20) |
where denotes the sign of the non-zero in (20).
Ostensibly, the summation in Eq, (16) is replaced by the double summation
(21) |
but it can be more usefully rewritten in terms of a single summation formally like that in (18) as
(22) |
provided the endpoint “correction”
(23) |
is included. A simpler substitution is that of the coefficient of in (16) by
(24) |
Together, (22) and (24) imply that the generalisation to positive of (16) is
(25) |
The choice of appropriate to (2.3) (namely, ) has been made for the overall multiplicative factor; it has also to be adopted in the expression for in (7). With the extended definition of in terms of the Heaviside function ([6], Eq. 1.16.13) as
(26) |
(2.3) continues to hold when .
Equation (2.3) is the goal of this section. It is a generalization and refinement of results in [8], which, in addition to the features mentioned in the introduction, includes a more careful treatment of endpoint corrections. The derivation has invoked only the periodicity of and is independent of its precise form, which, in (2.3), happens to be
(27) |
where and is the normalized sinc function [for , ].
The endpoint correction term in (2.3) does not influence the approximate estimates of considered next. Terms involving non-zero are suppressed by at least three powers of relative to the dominate large contribution.
3 Asymptotic analysis of
If is a power of two (i.e. ), then , (for integer ), and (2.3) reduces without approximation to
(28) |
The first summation in (2.3) is dominant, and the remaining terms are suppressed by one power of or more. The same pattern is also evident in an expansion of (2.3) for large which embraces the cases in which is not a power of two. If the negligible terms of order and higher are discarded, then the following approximation to emerges:
(29) |
The expansions in support of (29) are given in appendix B. Like (28), (29) is independent of , but, when specialized to , yields .
0 | 1 | 2 | |
---|---|---|---|
3 | 0.7893 | 0.90326 | 0.949999 |
5 | 0.7792 | 0.90288 | 0.949946 |
7 | 0.7765 | 0.902837 | 0.9499411 |
9 | 0.7754 | 0.902828 | 0.9499400 |
11 | 0.7748 | 0.902826 | 0.9499396 |
13 | 0.7745 | 0.9028245 | 0.94993949 |
15 | 0.7743 | 0.9028240 | 0.94993942 |
0.7737 | 0.9028233 | 0.94993934 |
Simple as the expression for is, it would seem of little utility because of its reliance on the factor of the unknown (but large) period . However, the numerical data in Table 2 suggests that is a monotonically decreasing function of when . This trend can be confirmed for large with the aid of the Euler-Maclaurin summation formula, which, for , implies straightforwardly that
(30) |
The calculation is trickier for ; application of the Euler-Maclaurin summation formula has to be followed by an expansion in inverse powers of (details are given in appendix C): the outcome of these manipulations is
(31) |
The results in (30), (31) and Table 2 justify the claim that, provided is negligible, in (2) is always an excellent approximation to in (2.3) when is non-negative.
3 | 0.263 | 5 | 0.229 | 7 | 0.720 | ||
9 | 0.708 | 11 | 0.243 | 13 | 0.234 | 15 | 0.716 |
17 | 0.7098 | 19 | 0.240 | 21 | 0.235 | 23 | 0.7144 |
25 | 0.7105 | 27 | 0.239 | 29 | 0.236 | 31 | 0.7138 |
0.7122 | 0.237 | 0.237 | 0.7122 |
The behaviour of for is quite different. Now, the expansion in inverse powers of , which is obtained along the same lines as (31), reads
(32) | ||||
where is the least non-negative residue of modulo . The correction to the leading term is of either sign and, being of order (see Table 3), can be substantial for small – see Fig. 3. Despite the scatter about in the values of for , none are close to .

The leading term in all of the above expansions in (30), (31) and (32) is found by evaluation of
(33) |
for integer . The integral in (33) defines an entire function of . In the limit , when , the lower limit on the integers of ; the values of then belong to a set with an accumulation point, and the identity theorem for holomorphic functions can be invoked to assert that the integral representation in (33) is the unique analytic continuation of to all values of , real and complex: thus, the right-hand side of (2), which is obtained from (33) for arbitrary by integration by parts, is a natural choice of interpolation function in Fig. 1.
4 Foundations for choices L and
Insight into good choices of for the factorization of square-free odd semiprimes is gained through the isomorphism between and the direct product of the cyclic groups and . The Jacobi symbol permits some consequences of this isomorphism to be recast in a manner which does not require any knowledge of the odd primes and .
4.1 Use of
The two simultaneous congruence relations
(34) |
establish (via the Chinese Remainder theorem) a bijection between elements and ordered pairs , and there is a one-to-one correspondence between and for any positive integer power . Hence, the order of to be used in is determined by the orders and of and , respectively, via
(35) |
and the conditions for the failure of as a factor of find neat expression as a property of and : the powers of two in the prime factorizations of and are equal ([5], Lemma 2).
The appeal of this characterisation is that the distribution of the powers of two associated with either of the orders or is easily constructed. For odd primes (, odd), the group comprises elements which are powers (modulo ) of a generator of order . As a result, the element (where ) has order
(36) |
For the odd values of , (36) simplifies to , where the odd number ; the corresponding result for the equal number of even values of () is
(37) |
which resembles (36) with the factor of replaced by : on the basis of the recursive pattern implied by the similarity of (37) to (36), there are elements of with the even orders () for each , and only elements with the odd orders (). Altogether, there are different powers of two: for the even choices of in (36), and exclusively for the odd choices.
An element has the representation in terms of generators and of and , respectively. Consistent with the earlier parametrization of in connection with (1), the primes and are taken to be and , where are odd and . The results of the previous paragraph can be used to determine the number of pairs for which the powers of two in the prime factorizations of the corresponding orders and are identical. By way of example, whenever both indices and are odd, the respective powers of two are and ; as there are odd values of and odd values of , the corresponding number of pairs with orders sharing the same power of two is
(38) |
Table 4 contains a summary of all the findings on the numbers of pairs with such matching powers of two. No match is possible when is odd and is even because . The entry for even and excludes the pair since it corresponds to a choice of () that cannot yield non-trivial factors of ().
even | odd | |
---|---|---|
even | ||
odd | 0 |
4.2 Role of the Jacobi symbol
Quadratic residues modulo are those elements of for which both of the indices and are even. Table 4 exhibits a partition of into the subgroup comprising its quadratic residues and the three cosets of this subgroup, all elements of which are quadratic non-residues modulo . The Jacobi symbol distinguishes two of these cosets from the subgroup of quadratic residues.
For odd primes , it is the Legendre symbol which differentiates between quadratic residues and non-residues modulo : is () if is a quadratic residue (non-residue), and 0 if is a divisor of . A consequence of Fermat’s little theorem is that must have one of , or 0 as its least absolute residue. As a result ([9], Theorem 83), it is possible to express in terms of least absolute residues as
(39) |
Furthermore, as the values and 0 are inadmissible for any generator of because they are incompatible with the requirement that it be of even order , it is necessarily the case that , and
(40) | ||||
in accord with the expectation that even (odd) powers of a generator are quadratic residues (non-residues).
For an integer relatively prime to the square-free semiprime , the Jacobi symbol
(41) |
where the right-hand side is the product of the two Legendre symbols and , which, in view of the congruences in (34), can be substituted by and , respectively. Use of the further congruences and as well as (40) imply finally that
(42) |
which is the basis for the observation exploited in [7] that, when , belongs to the union of the ( odd, even) and ( even, odd) cosets in .
According to Table 4, of the members in this union are unsuitable for the purposes of factoring the semiprime . The result for the conditional probability in (1) follows immediately. Another inference from Table 4, which forms the basis for choice , is that, when it is known , then all quadratic non-residues for which [i.e. the whole of the ( odd, odd) coset] are good candidates for factoring .
4.3 Value of : special cases
Specialization to the square-free semiprime of the standard formulae for the Jacobi symbols and ([6], §27.9) proves serendipitously fruitful. To begin with, on the basis of
(43) | ||||
it is possible to interpret the value of as follows: if , then, without further ado, ; if, instead, , then when is a quadratic non-residue modulo , and otherwise it can be deduced that . In the latter case, it is appropriate to move onto . Under the assumption that ,
(44) | ||||
the implications of which parallel those of (43): if , then ; if , then when is a quadratic non-residue modulo , and, by the exclusion above of other options, when is a quadratic residue. All of these findings are summarized in Table 1.
Larger values of can be identified if it is known that (because choice L has failed) by the elementary expedient of evaluating
(45) |
for . As for , the sequence of evaluations is to be terminated when the value is encountered; is the corresponding value of .
4.4 Properties of orders
With the substitutions and ( odd), (35) becomes
(46) |
The properties of the indices and established in subsection 4.1 imply that, for choice L,
(47) |
whereas, for choice ,
(48) |
For both choices, the order is even as asserted in the introduction.
Lagrange’s theorem for finite groups and the isomorphism imply that an order modulo the square-free semiprime is a divisor of the value
(49) |
of the Carmichael -function. Thus, substituting for in terms of ,
(50) |
since . In all cases of practical interest, and the right-hand side of (50) can be replaced by
(51) |
Information gleaned from the analysis of the Jacobi symbols and or the ad hoc construct can be used to fix a suitable lower limit to . The upper bound can be used to improve on Shor’s recommendation that the input quantum register contain at least qubits. In terms of ,
(52) |
where is a non-negative integer.
5 Discussion
As a tool for factoring RSA integers , Shor’s algorithm has been displaced by an approach which computes discrete logarithms [10, 11]. Nevertheless, the present paper suggests that there may remain an alternative use for Shor’s algorithm as a context for testing the operation of quantum computers. The benchmarks involving quadratic non-residues (schemes and above) derive from structural properties of , and group-theoretical considerations pertinent to other algorithms may also imply similar benchmarks. The benchmark arising from the period-finding algorithm is fortuitous.
Further studies may yet show that the benchmarks identified in this paper are toothless. However, the findings on the period-finding algorithm should still be of interest in view of their generality. According to the results in section 3, the approximation has the merit of being a lower bound to the probability of success when and is negligible.
References
- [1] A. Gheorghiu, T. Kapourniotis and E. Kashefi, “Verification of quantum computation: an overview of existing approaches,” Theory Comput. Syst. 63, 715–808 (2019).
- [2] J. Eisert, D. Hangleiter, N. Walk, I. Roth, D. Markham, R. Parekh, U. Chabaud and E. Kashefi, “Quantum certification and benchmarking,” Nat. Rev. Phys. 2, 382–90 (2020).
- [3] M. Kliesch and I. Roth, “Theory of quantum system verification,” PRX Quantum 2, 010201 (2021).
- [4] P. W. Shor, “Polynomial time algorithms for prime factorization and discrete logarithms on a quantum computer,” SIAM J. Comput. 26(5), 1484–509 (1997).
- [5] A. M. Childs and W. van Dam, “Quantum algorithms for algebraic problems,” Rev. Mod. Phys. 82(1), 1–52 (2010).
- [6] NIST Digital Library of Mathematical Functions (Release 1.1.3 of 2021-09-15), F. W. J. Olver, A. B. Olde Daalhuis, D. W. Lozier, B. I. Schneider, R. F. Boisvert, C. W. Clark, B. R. Miller, B. V. Saunders, H. S. Cohl, and M. A. McClain (eds.).
- [7] G. Leander, “Improving the success probability of Shor’s factoring algorithm,” arXiv: quant-ph/0208183.
- [8] P. S. Bourdon and H. T. Williams, “Sharp probability estimates for Shor’s order-finding algorithm,” Quantum Information & Computation 7(5&6), 522–50 (2007).
- [9] G. H. Hardy and E. M. Wright, “An introduction to the theory of numbers,” Oxford University Press, Oxford, UK, 6th ed., 2008.
- [10] C. Gidney and M. Ekerå, “How to factor 2048 bit RSA integers in 8 hours using 20 million noisy qubits,” Quantum 5, 433 (2021).
- [11] É Gouzien and N. Sangouard, “Factoring 2048-bit RSA integers in 177 days with 13436 qubits and a multimode memory,” Phys. Rev. Lett. 127, 140503 (2021).
Appendix A Reduction in (13)
With the substitution of in (13) by
(53) |
where it is understood that is the least non-negative residue of modulo (and, hence, an element of ), can be rewritten as
(54) | ||||
Since is odd, it is coprime to , and, just as the integers form a complete set of residues modulo , so do the integers (see, for example, Theorem 56 in [9]). The corresponding least non-negative residues must then be identical to . By an appropriate change of the dummy variable of summation in (14), it can be arranged that
(55) |
Evaluation of (55) yields the following non-zero values for :
(56) |
and
(57) |
for . As (55) also trivially implies that , the values of in (55) clearly coincide with those given in connection with (15).
Appendix B Large expansion of
For large , the obvious expansion parameter is , but there are others which are more convenient for the treatment of . Paralleling the derivation of (54) for in appendix A, the difference
(58) |
where is the least non-negative residue of modulo . Inspection of the values that can be attained by the right-hand side of (58) leads to the conclusion that . (The upper bound is attained when , and the lower bound when .) If is parametrised as
(59) |
then the small parameter is such that
(60) |
where the last inequality relies on relation (1) defining . In turn,
(61) |
from the reciprocal of (59) and the inequalities and which can be read off from (60).
On the basis of the expansions
(62) | ||||
(63) | ||||
in and , respectively, and the identity , the leading-order contribution to is given by (29), corrections being of order .
Appendix C Expansion of for
The Euler-Maclaurin summation formula ([6], Eq. 2.10.1) implies that
(64) |
where , , and use has been of its evenness and the oddness of its odd derivatives. For , (C) is an expansion in inverse powers of as it stands because is independent of . However,
(65) |
and
(66) | ||||
(67) | ||||
(68) |
After substitution of (66) into (C), appears in the combination that has the expansion
(69) |
in which terms linear in are absent. Equation (31) is obtained when (69) is coupled with use of the expansion
(70) |
and replacement of by in (C).