arXiv:1702.01653v1 [math.NT] 6 Feb 2017 iat vrabtayrns[ rings deter fact, arbitrary computing In over for algorithm minants coefficients. division-free and its known trace from best the and the extracted eigenvalues, be the give can roots determinant its : a of INTRODUCTION 1. value Algorithms, Keywords • Concepts CCS iea give inwe h rtro sntstse,adgv examples give and than larger satisfied, is not is the criterion when the when sion O ihprecision with iinmtosdvlpdpeiul.When previously. developed methods cision h unn ieo h loih u loteacrc of accuracy the also but only algorithm not result. the analyze the of must time one running matrices the such for algorithms ing eoyipista h nre a nyb approximated be precision only finite may some entries at the that implies memory eaayetepeiino h hrceitcpolynomial characteristic the of precision χ the analyze We ABSTRACT r w suswt hs ehd.Frt hyaeslower are they First, requiring division, methods. allow that these alternatives with than issues two are Over polynomial. teristic xaso rvrosdvso reagrtm [ algorithms free division various or expansion polynomia characteristic the of computing for approach plest onigpit fvreisoe nt ed se[ for (see algorithms fields finite in over ingredient varieties key of points a counting is polynomial acteristic erdc hsatce rt lo test os,frGover for so, do to others allow to or royal nonexclusive, article, a this affili retains reproduce Government or the contractor t such, employee, As that an ment. acknowledges by ACM co-authored ACM. or authored to licensed rights Publication DOI: SA 1,Jl 52,21,Kiesatr,Germany Kaiserslautern, 2017, 25-28, July '17, ISSAC c optn methodologies Computing ( ˜( h hrceitcplnma safnaetlinvariant fundamental a is polynomial characteristic The Let hncmuigwith computing When A 07AM SN*****-**01/7 $15.00 . . ***-*-****-****-0/17/07. ISBN ACM. 2017 M n http://dx.doi.org/10.1145/*******.******* fan of ) ω st opt det( compute to is )for )) M O ˜( ∈ n M 3 [email protected] χ p n loih o eemnn h pia preci- optimal the determining for algorithm ) ai rcso,caatrsi oyoil eigen- polynomial, characteristic precision, -adic ( n hrceitcplnmaso -dcmatrices p-adic of polynomials Characteristic A × O nvriéRne 1 Rennes Université ( Q ohv rcso exactly precision have to ) ( airCaruso Xavier p n p p N ekona precision at known be ) ,w ieaciein(hcal ntime in (checkable criterion a give we ), ai matrix -adic O X p ( p p ai arcs h ako infinite of lack the matrices, -adic ai ed,cmuigtechar- the computing fields, -adic − N .A osqec,i design- in consequence, a As ). M 10 → ihruigrcrierow recursive using either ) oss sn h charac- the using so does ] O A leri algorithms; Algebraic ( p sn ieeta pre- differential using N ). mn upssonly. purposes nment yfe ih opbihor publish to right ty-free t fantoa govern- national a of ate O O ( i otiuinwas contribution his p ( 10 p N A O N , .Tesim- The ). ( 14 .W also We ). n sintegral is 7 nvriyo Pittsburg of University !), , .There ]. 8 , O 11 ( ai Roe David [email protected] ]. n 4 ) - l ie oepeiinon precision some Given M isnra omof form normal nius xmls opeiinrmisa h n ftecalcula- the of of end many the In at precision. remains tion. of precision losses no catastrophic examples, to leads quently O inipista h euti cuaemodulo accurate is result the that implies sion ini h ujc fmc fti ae.Wt hsprecision this With of calculation paper. this actual of the much known, of subject the is for sion precision possible best and χ [ sin any on localized of not coefficient is that gle precision precision: diffuse uaino hrceitcplnmasover polynomials characteristic of putation oihs o xml,[ example, al- counting-points For many in ingredient gorithms. crucial a become has ic h ecito fKdaasagrtmi [ in algorithm Kedlaya’s of description the Since contributions. Previous auto ftececetof coefficient the of valuation eitcplnma f1+ 1 of polynomial teristic − ≤ · · · sn atcs e Section see phenomenon this lattices; formalize We using coefficient. individual any on ( than inl tbeagrtm(e Remark (see algorithm stable ciently M h osattr of term constant the cee.Hwvr h optto ftercharacteristic their of computation ( the point-count matrices However, the the in involved obtain schemes. are to that Frobenius) how of action on of details great with deals zeta curves. compute hyperelliptic to of Frobenius functions of polynomial characteristic the in precision solution extra The the equivalent. that be is should polynomials two these of O n if and 2 p M ˜( , modulo 1 ( α atrapoc vrafil st opt h Frobe- the compute to is field a over approach faster A nta,w eaaetecmuaino h precision the of computation the separate we Instead, sln snn fteegnausof eigenvalues the of none as long As for account may we that is approach this of benefit One nms fteeppr,tepeiinaayi usually analysis precision the papers, these of most In p χ ∈ § oatmoaiyhge rcso n hnuigasuffi- a using then and precision higher temporarily a to 1 n N ..]fraseiceapeo h eainhpbetween relationship the of example specific a for 3.2.2] and M p , . . . , O ω M O .But ). α ˜( [ ) α ( n rmtecmuaino napoiainto approximation an of computation the from n n n p osdradaoa matrix diagonal a consider , χ ( 15 − N 2+ Z 1+ 1 α se[ (see ) p .Hwvr h atta tue iiinfre- division uses it that fact the However, ]. ω/ n > ,te tl ontyedteotmlprecision. optimal the yield not do still they ), χ M p ,let ), hnnn ftececet ftecharac- the of coefficients the of none then , 1+ 2 . and 0 prtos eod hl h ako divi- of lack the while Second, operations. ) M 4 χ ( ,Q P, rp 3.2]). Prop. , X M M M χ = ) nvriéd Limoges de Université o xml,lt0 let example, For . [email protected] M hc saheal nrnigtime running in achievable is which , ∈ rsa Vaccon Tristan skonwt precision with known is M ilb nw ihpeiinlarger precision with known be will χ GL M M 7 2.1 eue[ use we , χ , ( M 8 n χ ilhv rcso agrthan larger precision have will X X use ] ( 1+ h nlsso hspreci- this of analysis The . o ute xlnto,and explanation, further for Z − n p M χ − ) otepeiincontent precision the so 1), n set and ) M k sdffs n o visible not and diffuse is p 3 D in a rce ylifting by proceed may ai ooooyand cohomology -adic e.34 ofidthe find to 3.4] Lem. , 5.3 ihdaoa entries diagonal with χ M M ). M r ogun to congruent are ilbe will p ≤ ai numbers -adic = p 11 α N O DQ P 1 ,tecom- the ], ( sln as long as p P ≤ N i k then ) =1 The . α χ 2 e.g. α M ing ≤ i - . , polynomials is often a little bit less thoroughly studied: some and χ the characteristic polynomial map, χM ∈ K[X] for the refer to fast algorithms (using division), while others apply characteristic polynomial of M and dχM for the differential division-free algorithms. of χ at M, as a linear map from Mn(K) to the space of In [4], the authors have begun the application of the the- polynomials of degree less than n. Wefixan ω ∈ R such that ory of differential precision of [3] to the stable computation the multiplication of two matrices over a ring is in O(nω ) of characteristic polynomials. They have obtained a way to operations in the ring. Currently, the smallest known ω is express the optimal precision on the characteristic polyno- less than 2.3728639 thanks to [13]. We will denote by In mial, but have not given practical algorithms to attain this the of rank n in Mn(K). When there is no optimal precision. ambiguity, we will drop this In for scalar matrices, e.g. for λ ∈ K and M ∈ Mn(K), λ − M denotes λIn − M. Finally, The contribution of this paper. we write σ1(M),...,σn(M) for the elementary divisors of Thanks to the application the framework of differential pre- M, sorted in increasing order of valuation. cision of [3] in [4], we know that the precision of the char- acteristic polynomial χM of a matrix M ∈ Mn(Qp) is de- 2. THEORETICAL STUDY termined by the comatrix Com(X − M). In this article, we provide: 2.1 The theory of p-adic precision 1. Proposition 2.7: a factorization of Com(X − M) as a We recall some of the definitions and results of [3] as a product of two rank-1 matrices (when M has a cyclic foundation for our discussion of the precision for the charac- vector), computable in O˜(nω) operations by Theorem teristic polynomial of a matrix. We will be concerned with 4.1 two K-manifolds in what follows: the space Mn(K) of n × n matrices with entries in K and the space Kn[X] of monic 2. Corollary 2.4: a simple, O˜(nω) criterion to decide degree n polynomials over K. Given a matrix M ∈ Mn(K), whether χM is defined at precision higher than the the most general kind of precision structure we may attach precision of M (when M ∈ Mn(Zp)). to M is a lattice H in the tangent space at M. However, rep- 3. Theorem 3.11: a O˜(n3) algorithm with operations in resenting an arbitrary lattice requires n2 basis vectors, each 2 Zp to compute the optimal precision on each coefficient with n entries. We therefore frequently work with certain of χM (when M is given with uniform precision on its classes of lattices, either jagged lattices where we specify a entries). precision for each matrix entry or flat lattices where every N ω entry is known to a fixed precision O(p ). Similarly, pre- 4. Proposition 5.6: a O˜(n ) algorithm to compute the cision for monic polynomials can be specified by giving a optimal precision on each eigenvalue of M lattice in the tangent space at f(X) ∈ Kn[X], or restricted Organization of the article. to jagged or flat precision in the interest of simplicity. Let χ : Mn(K) → Kn[X] be the characteristic polynomial In Section 2, we review the differential theory of precision map. Our analysis of the precision behavior of χ rests upon developed in [3] and apply it to the specific case of the char- the computation of its derivative dχ, using [3, Lem. 3.4]. For acteristic polynomial, giving conditions under which the dif- a matrix M ∈ Mn(K), we identify the tangent space V at ferential will be surjective (and thus provide a good measure M with Mn(K) itself, and the tangent space W at χM with of precision). We also give a condition based on reduction the space K

Corollary 2.4. Suppose that M ∈ GLn(OK ) is known with precision O(πm). Then the characteristic polynomial of M Proposition 2.7 shows that Com(X−M) can be encoded has precision lattice strictly contained in O(πm) if and only by the datum of the quadruple (α,P,Q,χM ) whose total 2 if the reduction of M modulo π does not have a cyclic vector. size stays within O(n ) : the polynomials α and χM are determined by 2n coefficients while we need 2n2 entries to Note that this criterion is checkable using O˜(nω) opera- write down the matrices P and Q. We shall see moreover tions in the residue field [15]. in Section 4 that interesting information can be read off of this short form (α,P,Q,χM ). 2.2 Stability under multiplication by X

By definition, the codomain of dχM is K

i C e = (0,..., 0, −a0,⋆,...,⋆) where P lies in GLn(OK ). Moreover, the latter condition −1 implies that P dMP runs over Mn(OK ) when P runs over C i ′ with n−i starting zeros. Therefore the e’s form a basis of Mn(OK ). As a consequence, the integer Nk giving the op- Kn, i.e. e is always a cyclic vector of C . Once R has been timal precision on the k-th coefficient of M is also equal to t H H computed, we recover Q using the relation Q = PinvR. N +min1≤i,j≤n val(πk(Ci,j )) where Ci,j is the (i, j) entry of It remains to compute the factor α. For this, we Com(X−H), where H is the Hessenberg form of M. Remark 5.3. As a consequence of the previous discussion, Average loss of accuracy once the optimal jagged precision is known, it is possible to Optimal CR FP lift the entries of M to a sufficiently large precision, rescale 0 them to have entries in O and then use Algorithm 2 to X 3.17 196 189 K (det.) dev: 1.76 dev: 240 dev: 226 compute the characteristic polynomial. The output might 1 then need to be rescaled and truncated at the optimal pre- X 2.98 161 156 3 dev: 1.69 dev: 204 dev: 195 cision. This requires O˜(n ) operations in OK and unfortu- nately, for several instances, may require to increase a lot X2 2.75 129 126 the precision. dev: 1.57 dev: 164 dev: 164 X3 2.74 108 105 Numerical experiments. We have made numerical ex- dev: 1.73 dev: 144 dev: 143 periments in SageMath [6] in order to compare the opti- X4 2.57 63.2 60.6 mal precision obtained with the methods explained above dev: 1.70 dev: 85.9 dev: 85.8 with the actual precision obtained by the software. For do- X5 2.29 51.6 49.7 ing so, we picked a sample of 1000 random matrices M in dev: 1.66 dev: 75.3 dev: 74.9 Q M9( 2) where all the entries are given at the same relative X6 2.07 9.04 8.59 precision. We recall that, in SageMath, random elements dev: 1.70 dev: 26.9 dev: 26.4 x ∈ Q are generated as follows. We fix an integer N — the p X7 1.64 5.70 5.38 so-called relative precision — and generate elements of Qp dev: 1.65 dev: 15.3 dev: 14.7 of the shape X8 0.99 0.99 0.99 x = pv · a + O pN+vp(a) (trace) dev: 1.37 dev: 1.37 dev: 1.37 where v is a random integer generated according to the dis- Results for a sample of 1000 instances tribution: 1 2 Figure 1: Average loss of accuracy on the coefficients P[v =0]= ; P[v = n]= for |n|≥ 1 of the characteristic polynomial of a random 9 × 9 5 5 · |n| · (|n| + 1) matrix over Q2 and a is an integer in the range [0,pN ), selected uniformly at random. Once this sample has been generated, we computed, for • the column “FP” is the average of the quatities (FPk−v)− each k ∈ {0, 1,..., 8}, the three following quantities: N where FPk is the first position of an incorrect digit on • the optimal precision on the k-th coefficient of the char- the k-th coefficient of χM . acteristic polynomial of M given by Eq. (6) We observe that the loss of relative accuracy stays under 2 • in the capped relative model , the precision gotten on control in the “Optimal”column whereas it has a very erratic the k-th coefficient of the characteristic polynomial of M behavior — very large values and very large deviation as computed via the call: well — in the two other columns. These experiments thus M.charpoly(algorithm="df") demonstrate the utility of the methods developed in this • in the model of floating-point arithmetic (see [2, §2.3]), paper. the number of correct digits of the k-th coefficient of the 5.2 On eigenvalues characteristic polynomial of M. 3 Let M ∈ Mn(K) and λ ∈ K be a simple eigenvalue of Remark 5.4. The keyword algorithm="df" forces Sage- M. We are interesting in quantifying the optimal precision Math to use the division free algorithm of [14]. It is likely on λ when M is given with some uncertainty. that, proceeding so, we limit the loss of precision. To do so, we fix an approximation Mapp ∈ Mn(K) of M and suppose that the uncertainty of M is “jagged” in The table of Figure 1 summarizes the results obtained. It the sense that each entry of M is given at some precision should be read as follows. First, the acronyms CR and FP Ni,j O(π ). Let λapp be the relevant eigenvalue of Mapp. We refers to “capped relative” and “floating-point” respectively. remark that it is possible to follow the eigenvalue λapp on a The numbers displayed in the table are the average loss of small neighborhood U of M. More precisely, there exists a relative precision. More precisely, if N is the relative preci- unique continuous function f : U → K such that: sion at which the entries of the input M have been generated and v is the valuation of the k-th coefficient • f(Mapp)= λapp, and of χ , then: ′ ′ ′ M • f(M ) is an eigenvalue of M for all M ∈U. • the column “Optimal” is the average of the quantities ′ ′ ′ (Nk−v) − N (where Nk is defined by Eq. (6)): Nk−v Lemma 5.5. The function f is strictly differentiable on a is the optimal relative precision, so that the difference neighborhood of Mapp. The differential of f at M is the ′ (Nk−v) − N is the loss of relative precision; linear mapping: • the column“CR”is the average of the quatities (CRk−v)− Tr(Com(λ − M) · dM) dM 7→ dλ = − N where CRk is the computed (absolute) precision on the ′ χM (λ) k-th coefficient of χM ; where χ′ is the usual derivative of χ . 2Each coefficient carries its own precision which is updated M M after each elementary arithmetical operation. 3the corresponding generalized eigenspace has dimension 1 t Proof. The first assertion follows from the implicit func- the V (λ)Qj are computed for the same cost. The first as- tion Theorem. Differentiating the relation χM (λ) = 0, we sertion of Proposition 5.6 follows. The second assertion is ′ get χM (λ) · dλ + Tr(Com(X − M) · dM)(λ) = 0, from which now proved similarly to the case of a unique eigenvalue. the Lemma follows. References Lemma 3.4 of [3] now implies that, if the Ni,j ’s are large enough and sufficiently well balanced, the optimal precision [1] Xavier Caruso, Resultants and subresultants of p-adic ′ polynomials, arxiv:1507.06502 (2015). on the eigenvalue λ is O(πN ) with: [2] , Computations with p-adic numbers, ′ ′ N = min Nj,i + val(Ci,j (λ)) − val(χM (λ)) arxiv:1701.06794 (2017). ≤ ≤ 1 i,j n [3] Xavier Caruso, David Roe, and Tristan Vaccon, Track-  where Ci,j denotes as above the (i, j) entry of Com(X−M). ing p-adic precision, LMS J. Comput. Math. 17 (2014), t t no. suppl. A, 274–294. MR3240809 Writing Com(X−M)= α · PV · VQ mod χM as in Propo- sition 2.7, we find: [4] , p-Adic Stability In Linear Algebra, Proceedings of the 2015 ACM on International Symposium on Sym- ′ ′ N = val(α(λ)) − val(χM (λ)) bolic and Algebraic Computation, ISSAC 2015, Bath, t t United Kingdom, July 06 - 09, 2015 (2015), 101–108. + min Nj,i + val(PiV (λ) ) + val(V (λ)Qj ) (7) 1≤i,j≤n [5] Henri Cohen, A course in computational algebraic num-  ber theory, Vol. 138, Springer Science & Business Media, where Pi denotes the i-th row of P and, similarly, Qj denotes 2013. the j-th row of Q. Note moreover that V (λ) is the row vector n−1 [6] The Sage Developpers, Sage Mathematics Software (1,λ,...,λ ). By the discussion of §4, the exact value of (Version 7.5), 2017. http://www.sagemath.org. N ′ can be determined for a cost of O˜(nω) operations in K and O(n2) operations on integers. [7] David Harvey, Kedlaya’s algorithm in larger character- istic, International Mathematics Research Notices 2007 When M is given at flat precision, i.e. the Ni,j ’s are all (2007), rnm095. equal to some N, the formula for N ′ may be rewritten: [8] , Counting points on hyperelliptic curves in av- ′ ′ 179 N = N + val(α(λ)) − val(χM (λ)) erage polynomial time, Annals of Mathematics t t (2014), no. 2, 783–803. + min val(PiV (λ) )+ min val(V (λ)Qj ) (8) 1≤i≤n 1≤j≤n [9] Kenneth Hoffman and Ray Kunze, Linear algebra, 2nd  ed., Prentice-Hall, Englewood Cliffs, New Jersey, 1971. and can therefore now be evaluated for a cost of O˜(nω) [10] Erich Kaltofen, On computing determinants of matrices operations in K and only O(n) operations with integers. without division, Proc. 1992 Internat. Symp. Symbolic Algebraic Computation. (ISSAC’92), 1992, pp. 342– To conclude, let us briefly discuss the situation where we 349. want to figure out the optimal jagged precision on a tuple (λ ,...,λ ) of simple eigenvalues. Applying (7), we find [11] Kiran S. Kedlaya, Counting points on hyperelliptic 1 s curves using monsky–washnitzer cohomology, J. Ra- that the optimal precision on λk is manujan Math. Soc. 16 (2001), 323–338. ′ ′ Nk = val(α(λk)) − val(χM (λk)) [12] Walter Keller-Gehrig, Fast algorithms for the charac- t t teristics polynomial, Theoretical Computer Science 36 + min Nj,i + val(PiV (λk) ) + val(V (λk)Qj ) . 1≤i,j≤n (1985), 309 –317. [13] Fran¸cois Le Gall, Powers of tensors and fast matrix ′  ω Proposition 5.6. The Nk’s can be all computed in O˜(n ) multiplication, Proceedings of the 39th international operations in K and O(n2s) operations with integers. symposium on symbolic and algebraic computation, If the Ni,j ’s are all equal, the above complexity can be 2014, pp. 296–303. lowered to O˜(nω) operations in K and O(ns) operations [14] T. R. Seifullin, Computation of determinants, adjoint with integers. matrices, and characteristic polynomials without divi- sion, Cybernetics and Systems Analysis 38 (2002), Proof. ′ The α(λk)’s and the χM (λk)’s can be computed no. 5, 650–672. for a cost of O˜(ns) operations in K using fast multipoint [15] Arne Storjohann, Deterministic computation of the evaluation methods (see 10.7 of [17]). On the other hand, Frobenius form, Proceedings of the 42nd IEEE sympo- t we observe that PiV (λk) is nothing but the (i, k) entry of sium on foundations of computer science, 2001, pp. 368– the matrix: 377.

λ1 · · · λs [16] Tristan Vaccon, p-adic precision, Theses, 2015. 2 2 λ1 · · · λs [17] Joachim Von Zur Gathen and Jurgen¨ Gerhard, Modern P ·  . .  . computer algebra, Cambridge university press, 2013. . .   λn−1 · · · λn−1  1 s    The latter product can be computed in O˜(nω) operations 4 t in K . Therefore all the PiV (λk) ’s (for i and k varying) can be determined with the same complexity. Similarly all 4It turns out that O˜(n2) is also possible because the right factor is a structured matrix (a truncated Vandermonde): computing the above product reduces to evaluating a poly- nomial at the points λ1,...,λs.