The straight line complexity of small factorials and primorials
aa r X i v : . [ c s . CC ] D ec THE STRAIGHT LINE COMPLEXITY OF SMALL FACTORIALSAND PRIMORIALSKlas Markstr¨om
Department of Mathematics and Mathematical Statistics, Ume˚a University,SE-901 87 Ume˚a, Sweden
Received: , Revised: , Accepted: , Published:
Abstract
In this paper we determine the straight-line complexity of n ! for n ≤
22 and givebounds for the complexities up to n = 46. In the same way we determine thestraight-line complexity of the product of the first primes up to p = 23 and givebounds for p ≤
1. Introduction
In [10] Shub and Smale studied the complexity of a number of different algebraicproblems in terms of the number of ring operations needed to compute a given ringelement by a straight line program . A straight line program for an integer y can bedescribed as a sequence of tuples x k = ( x i ◦ x j ), where i ≤ j < k , x = 1, ◦ canbe any of + , − , × , and the final element x f is equal to y . The smallest integer f such that there exists a straight line program of length f is called the straight linecomplexity, or cost, of y and is denoted by τ ( y ).In [2] a general complexity theory for computation over rings was introduced, seealso [1], and here the ultimate complexity of n ! turned out to be of great interest.For an integer x the ultimate complexity τ ′ ( x ) is defined as the minimum τ ( y ) forall y which are integer multiples of x . In particular, if there exists a constant c such that τ ′ ( n !) is less than (log n ) c then this would lead to a fast algorithm forfactoring integers, see the discussion in [5, 4]. The non-existence of such a constant c would imply that P = N P over the complex numbers [10] and provide stronglower bounds for several important problems in complexity theory, see [3] and [8].The results of [10, 7, 6] provide upper and lower bounds for the straight line com-plexity of general integers and imply that for most integers τ ( n ) is not O ( p (log log n )) NTEGERS: 14 (2014) p . In [9] similar bounds were derived for functions over finitefields. The known bounds for a general integer n arelog (log n ) + 1 ≤ τ ( n ) ≤ n (1)The lower bound is optimal since τ (2 k ) = k + 1. The upper bound is achieved byfirst computing the necessary powers of 2 and then adding them according to thebinary expansion of n .For specific integers, such as n !, there are few results which strengthen the generalbounds. However for n ! Cheng derived an improved algorithm, conditional on aconjecture regarding the distribution of smooth integers, and earlier [11] a weaker,unconditional, bound was derived by Strassen.The purpose of this short note is to report the exact values of τ ′ ( n !) for smallvalues of n and likewise for τ ′ ( p p p . It is easy to see that given a short straightline program for p n ! by using repeated squaring. Ourresults were obtained by first doing an exhaustive computer search of all straightline program up to a given length, followed by an extended search adapted to findingprogram for n ! and p
2. Searching for optimal straight line programs
Our bounds have been found by doing an exhaustive search of the set of all straightline programs of a given length. In Appendix A we give a more detailed descriptionof how the search was performed. In Figure 1 we display some statistics for thestraight line programs. We say that an integer y has been reached if there is astraight line program of length at most k which computes y , and that y has beencovered if y is a divisor of x j for some j ≤ k . We also include the length of thelongest interval of the form [1 , . . . , x ] in which all integers have been reached andcovered respectively.Full data from the search were saved up to k = 9, after that the space require-ments for the full set of programs became prohibitive. For larger k we instead NTEGERS: 14 (2014) k Size of reached set Initial interval Covered interval Covered set1 2 2 2 22 4 4 4 43 9 6 6 84 26 12 12 275 102 40 43 1256 562 112 138 9707 4363 310 705 133848 46154 1820 3546 3370969 652227 10266 26686 19040788Figure 1: Statistics for straight line programs of length at most 9extended the search to higher values of k for specific target integers, in particu-lar the different factorials, primorials and multiples of them. A complete searchof this type was made up to k = 11, thereby finding the optimal program for thecases where the length is at most 11 and providing a lower bound of 12 for theremaining target integers. For certain target integers the complete search couldbe extended further thanks to the efficiency in pruning the search tree for largertargets, as described in Appendix A. We also performed searches to extend someheuristically chosen straight line programs, hoping to find improved upper boundsfor some cases.In Figure 2 we show the exact values for τ ′ ( n !) for n ≤
28 and for each such n an example of an optimal straight line program. For larger n we display the bestmethod found by our partial search. The final columns states whether the methodis optimal or not, and otherwise the lowest possible value. In Figure 3 we showthe exact values for τ ( n !) for n ≤
14, and upper and lower bounds for some largervalues of n .Similarly Figure 4 and 5 give exact values and bounds for the small primorials,and multiples of them.The optimal methods are noticeably better than the upper bound for τ ( n !) givenin inequality (1). The method of Strassen [11] gives a bound τ ( n !) = O ( √ n log n ),which seems to deviate more and more from the optimal methods for larger n . Theconditional method of Cheng [5] has a complexity of the form O ( exp ( c √ log n log log n )),which certainly seems compatible with the results for small n , but is so sensitive tothe value of the constant c that very little can be said based on small values of n .The function τ ′ ( n !) is a monotone increasing function however it is not obviousthat τ ( n !) is. We end this note with an open problem. Problem 2.1. Is τ ( n !) a monotone function? For small n Table 2 shows that τ ( n !) is monotone, but we would not find itsurprising if this fails for larger n . NTEGERS: 14 (2014) n f Program Lowerbound2 1 { , , + } Opt3 3 { , , + } , { , , + } , { , , ∗} Opt4 4 { , , + } , { , , + } , { , , + } , { , , ∗} Opt5 5 { , , + } , { , , + } , { , , ∗} , { , , −} , { , , ∗} Opt6-7 6 { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} Opt8-10 7 { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} Opt11-14 9 { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , + } , { , , ∗} , { , , −} , { , , ∗} , { , , ∗} Opt15-17 10 { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} , { , , −} , { , , ∗} Opt18-19 11 { , , + } , { , , + } , { , , ∗} , { , , + } , { , , ∗} , { , , −} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} , { , , ∗} Opt20-22 12 { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , + } , { , , ∗} , { , , −} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} , { , , ∗} Opt23-28 14 { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} , { , , −} , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , Opt29-34 16 { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} , { , , −} , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { } , { , , ∗} { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗}{ , , ∗} , { , , ∗} , { , , −} , { , , ∗}{ , , −} , { , , + } , { , , ∗} , { , , −}{ , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} n ! Acknowledgements
This research was conducted using the resources of High Performance ComputingCenter North (HPC2N). The author would like to thank Charles R Greathouse andRich Schroeppel for pointing out an error in the first version of the paper, and theanonymous referee for constructive criticism.
NTEGERS: 14 (2014) References [1] Lenore Blum, Felipe Cucker, Michael Shub, and Steve Smale.
Complexityand real computation . Springer-Verlag, New York, 1998. With a foreword byRichard M. Karp.[2] Lenore Blum, Mike Shub, and Steve Smale. On a theory of computation andcomplexity over the real numbers: NP-completeness, recursive functions anduniversal machines.
Bull. Amer. Math. Soc. (N.S.) , 21(1):1–46, 1989.[3] Peter B¨urgisser. On defining integers and proving arithmetic circuit lowerbounds.
Comput. Complexity , 18(1):81–103, 2009.[4] Qi Cheng. Straight-line programs and torsion points on elliptic curves.
Comput.Complexity , 12(3-4):150–161, 2003.[5] Qi Cheng. On the ultimate complexity of factorials.
Theoret. Comput. Sci. ,326(1-3):419–429, 2004.[6] Carlos Gustavo T. de A. Moreira. On asymptotic estimates for arithmetic costfunctions.
Proc. Amer. Math. Soc. , 125(2):347–353, 1997.[7] W. de Melo and B. F. Svaiter. The cost of computing integers.
Proc. Amer.Math. Soc. , 124(5):1377–1378, 1996.[8] Pascal Koiran. Valiant’s model and the cost of computing integers.
Comput.Complexity , 13(3-4):131–146, 2004.[9] Abraham Lempel, Gadiel Seroussi, and Jacob Ziv. On the power of straight-line computations in finite fields.
IEEE Trans. Inform. Theory , 28(6):875–880,1982.[10] Michael Shub and Steve Smale. On the intractability of Hilbert’s Nullstellensatzand an algebraic version of “NP = P?”. Duke Math. J. , 81(1):47–54 (1996),1995. A celebration of John F. Nash, Jr.[11] Volker Strassen. Einige Resultate ¨uber Berechnungskomplexit¨at.
Jber. Deutsch.Math.-Verein. , 78(1):1–8, 1976/77.
NTEGERS: 14 (2014) Appendix A
Our bounds have been found by doing a two stage search of the set of all straightline programs of a given length.
Definition 2.2.
A straight line program is normalized if1. x i = x j if i = j x i > i It is easy to see that an optimal straight line program for an integer n mustsatisfy 1, and that every n has an optimal straight line program which satisfies 2.Further we say that two straight line programs p and p , both of length k , are range-isomorphic if the sequence of number computed by p is a permutation of thesequence computed by p . It is easy to see that this is an equivalence relation onthe set of straight line programs.Our search for optimal straight line programs was performed in two stages. Firstwe found one representative for each range-isomorphism equivalence class of thenormalized straight line programs of length up to k = 9. Second, a search targetedat specific integers was performed.The first stage was done as follows, starting from the initial straight line programjust containing the number 1.1. Increase k by 1 and continue.2. Extend all programs of length k − k by only keeping one representativefor each range-isomorphism equivalence class.4. Repeat from 1.Step 3 is done since if one replaces an initial segment p , of length t , of a straightline program p by a range-isomorphic straight line program p ′ then we can modify,by changing some of the indices, the resulting program to a new program p ′ whichcomputes the same set of numbers as p . So, if p was an optimal program for someinteger N then p ′ is also optimal for N .After stage 1 is done we have found optimal programs for all integers N with τ ( N ) ≤
9, and have shown that τ ( N ) ≥
10 for all other integers.After the set of programs of length 9 had been found in this way we went onwith the second stage search. For each target integer N , such that τ ( N ) ≥
10 eachprogram of length 9 was extended in a depth first search.
NTEGERS: 14 (2014) N , each straight line program of length 9, found in the firststage search, was recursively extended by one operation, up to a specified maximumlength K , with the following pruning criteria.1. If the current program p computes the target N then save the program anddo not extend it further.2. If the current program p is not normalized then do not extend it further.3. If the current program has length k and the maximum integer x which it hascomputed satisfies x ( K − k ) < N then do not extend it further.The third condition is included since if a program p of this type is extended by K − k steps then the resulting program cannot compute an integer as large as thetarget N , if k ≥ k = 11 for each of our target integers. For the larger target integers the search couldbe completed for larger values of k as well, thanks to the more restrictive boundin the third pruning criterion, thus providing larger lower bounds for the optimalstraight line programs, and proving the optimality of the some of the programsfound. NTEGERS: 14 (2014) n f Program Lowerbound2 1 { , , + } Opt3 3 { , , + } , { , , + } , { , , ∗} Opt4 4 { , , + } , { , , + } , { , , + } , { , , ∗} Opt5 6 { , , + } , { , , + } , { , , + } , { , , ∗} , { , , −} , { , , ∗} Opt6 6 { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} Opt7 7 { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} Opt8 8 { , , + } , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} , { , , −} Opt9 8 { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} , { , , ∗} Opt10 9 { , , + } , { , , + } , { , , + } , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} Opt11 9 { , , + } , { , , + } , { , , ∗} , { , , + } , { , , ∗} , { , , + } , { , , ∗} , { , , −} , { , , ∗} Opt12 10 { , , + } , { , , + } , { , , ∗} , { , , + } , { , , ∗} , { , , + } , { , , ∗} , { , , −} , { , , ∗} , { , , ∗} Opt13 11 { , , + } , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} Opt14 11 { , , + } , { , , ∗} , { , , ∗} , { , , + } , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} Opt15 12 { , , + } , { , , ∗} , { , , ∗} , { , , + } , { , , ∗} , { , , −} , { , , ∗} , { , , −} , { , , ∗} , { , , + } , { , , ∗} , { , , ∗} Opt16 12 { , , + } , { , , ∗} , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , + } , { , , ∗} , { , , −} , { , , ∗} , { , , ∗} , { , , ∗} Opt17 12 { , , + } , { , , ∗} , { , , + } , { , , ∗} , { , , ∗} , { , , −} , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} Opt18 13 { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , + } , { , , ∗} , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} Opt19 13 { , , + } , { , , + } , { , , ∗} , { , , −} , { , , + } , { , , ∗} , { , , −} , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} , { , , ∗} Opt20 14 { , , + } , { , , + } , { , , ∗} , { , , + } , { , , ∗} , { , , −} , { , , ∗} , { , , −} , { , , −} , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} n ! NTEGERS: 14 (2014) p f Program lowerbound2 1 { , , + } Opt3 3 { , , + } , { , , + } , { , , ∗} Opt5 5 { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} Opt7 6 { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} Opt11 7 { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , + } , { , , ∗} , { , , −} Opt13 8 { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} Opt17 9 { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} Opt19-23 10 { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} Opt29-31 11 { , , + } , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , + } , { , , + } , { , , + } , { , , ∗} , { , , ∗} Opt37-43 14 { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , ∗}{ , , ∗} , { , , ∗} , { , , −} , { , , ∗} , { , , −} , { , , + } , { , , ∗} , { , , −} , { , , ∗} p NTEGERS: 14 (2014) p f Program lowerbound2 1 { , , + } Opt3 3 { , , + } , { , , + } , { , , ∗} Opt5 5 { , , + } , { , , + } , { , , + } , { , , ∗} , { , , ∗} Opt7 6 { , , + } , { , , + } , { , , + } , { , , ∗} , { , , −} , { , , ∗} Opt11 7 { , , + } , { , , + } , { , , ∗} , { , , + } , { , , ∗} , { , , ∗} , { , , + } Opt13 8 { , , + } , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , + } , { , , ∗} Opt17 9 { , , + } , { , , ∗} , { , , ∗} , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , + } , { , , ∗} Opt19 10 { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , −} , { , , ∗} , { , , −} , { , , ∗} Opt23 11 { , , + } , { , , + } , { , , + } , { , , ∗} , { , , + } , { , , ∗} , { , , ∗} , { , , + } , { , , ∗} , { , , − } , { , , ∗} Opt29 13 { , , + } , { , , + } , { , , ∗} , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , + } , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} { , , + } , { , , + } , { , , ∗} , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , + } , { , , + } , { , , + } , { , , ∗} , { , , ∗} , { , , ∗} , { , , −} , { , , ∗} pp