#!/usr/bin/env python3 """ Numerical companion to the paper "Explicit linear bounds in Waring's problem" (version 2). Usage python3 verify_explicit_waring.py run all checks (about eight hours, and about 8 GB of memory) python3 verify_explicit_waring.py --appendix run the checks for Appendix A only (Part 14, about eight hours) python3 verify_explicit_waring.py --appendix-c run the checks for Appendix C only (Part 15, about two minutes) python3 verify_explicit_waring.py --appendix-d run the checks for Appendix D only (Part 16, a few seconds) python3 verify_explicit_waring.py --list print the bound of Theorem 2.3, the number of k-th powers of Theorem 2.4 and the number E^sharp(k) of Section 11.3 for every 37 <= k <= 5000 python3 verify_explicit_waring.py --list-appendix print the numbers of Appendix A: n, c_n, Y^flat(k), G^flat(k) and l^flat(k) for 6 <= k <= 5000 (Section A.7, first case); T_k, n, c_n, Y^VW(k), G^VW(k) and l^VW(k) for 7 <= k <= 20 (second case); Theta^nat(k), B^nat(k), k B^nat(k), 2 s_0^nat(k), b^nat(k) and E^nat(k) for 37 <= k <= 5000 (Section A.8); and the tables of [VW2000] for 7 <= k <= 20 and of [VW1995] for k = 5, 6 as they are used (about an hour) (in Python) import verify_explicit_waring as V; V.bound(k, Theta) evaluates B(k, Theta); G(k) <= floor(k B) V.A_rec_std([k]) for k >= 6: the recursion of Theorem A.36 in the first case (entries 'Y', 'n', 'c'); G(k) <= floor(Y) + 1; V.A_rec_vw(k) for 7 <= k <= 20: the same in the second case, with the tables of [VW2000] (entries 'Y', 'G', 'n', 'c', and the truth values of the hypotheses in 'checks') V.A_bound_rig(k) returns (B^nat(k), Theta^nat(k)) of Section A.8, computed with directed rounding V.frac_exponent(k, Theta, b) returns (E, s_0, y) for Theorem 2.7, where E = 2 s_0 + (1 + b) 4.5139505 k: min ||alpha n^k|| < N^(-rho) for rho < 1/E What the proofs in the paper use from this file Part 5 only: the evaluation of the closed expression B(k, Theta) = C(h_k) - 2T(Theta) + 2R_k(Theta) + W_k(Theta) + 1/k of Theorem 2.3 at Theta = Theta^sharp(k) for 37 <= k <= 5000 (Proposition 10.5, Table 3), and the elementary numerical inequalities quoted in the proofs of Theorems 1.3 and 2.3, of Corollary 2.6 and of Propositions 10.6, 10.7 and 11.7. Part 5 also evaluates the least number l of k-th powers that is admissible in Theorem 2.4, and the numbers E^sharp(k) of Section 11.3 (Proposition 11.7, Table 4), which are simple functions of B. All quantities are given by the closed formulae of Lemmas 10.1-10.4; the only infinite series is truncated at D = 10^6 with the rigorous tail bounds of Lemma 10.2(i). Part 5 ends with a second, independently written implementation of B(k, Theta^sharp(k)) in 40-digit decimal arithmetic (function decimal_bounds, with the series truncated at D = 2 10^5), which is compared with the double precision values. It uses the same closed formulae, so it guards against programming and rounding errors; the formulae themselves are compared with the definitions in Parts 1, 2 and 5. Part 14, for Appendix A. The proofs depend on the following computations. (1) The constants Lambda^star and C_0^star of (A.1): the series is summed up to D = 10^6, and the remainder is bounded by means of 2/D^2 - 13/(3D^3) <= Lambda_D^dagger <= 2/D^2 (A_LAMBDA_R, A_C0_R; the intervals are confirmed in decimal arithmetic with a correctly rounded logarithm, A_const_certify). The exponent pairs (kappa_w, lambda_w) and the constants E_w, c_w, vartheta_w of (A.14) for the 133 words of W, the admissibility of the words for each k, and the comparison in the proof of Lemma A.26(ii), are computed in exact rational arithmetic (_A_pair_exact, _A_word_consts, A_word_ok, A_limit_envelope_exact). (2) The sequences c_0 < c_1 < ... < c_n of Theorem A.36 (Sections A.6 and A.7) for 6 <= k <= 5000 in the first case and for 7 <= k <= 20 in the second case (Propositions A.37 and A.38, Tables 8 and 9; functions A_theta_hat_lo, A_rec_step_lo, A_rec_std, A_rec_vw). Here c_0 is a floating point number below tau_k (below 1/T_k in the second case), and c_j is a floating point number below a rigorous lower bound for inf{ v/(1 - theta_k(2v)/k) : c_(j-1) <= v < c_j }. The range of 2v is divided at the points of division 1/(D(D+1)) (3 <= D <= D_k) and 2^(-J-1) (1 <= J <= 40); on a piece [s, b] the chains of Lemma A.28(iii) that are admissible at b (greedy unions I_0, ..., I_J' with 2^(J'+1) b <= 1, or the interval of a word of W that is admissible for k, possibly followed by tents T_D1, ..., T_D2 with b <= 1/(D2(D2+1)), and the same chains with intervals of Definition A.25(e) between two tents, at their end, or after the greedy union, or with an interval Q_{D,iota} of Definition A.25(f) after the last tent T_D) are defined throughout, and by Lemma A.28(iv), (v) the number (s/2)/(1 - theta^(s)/k) is a lower bound there. The values of the chains are rounded downwards; these steps use the four basic operations only. In the first case condition (R3) is tested with the logarithm rounded downwards, and Y^flat(k) is an upper bound for k Psi(c_n) + 2n; both are verified a second time in decimal arithmetic with 40 digits and a correctly rounded logarithm (A_rec_certify), so that they do not depend on the accuracy of the logarithm of the floating point library. In the second case the tables of permissible exponents of Vaughan and Wooley [VW2000, Sections 9-22] for 7 <= k <= 20 are part of the program (A_VW4, with the column phi_1 of the same tables in A_VW4_PHI); everything that depends on the tables is computed in exact rational arithmetic, including (V1)-(V3), (R3) and the numbers Y^VW(k). The transcription of the tables is tested by means of the relation lambda_s = lambda_(s-1)(1 - phi_1) + 1 + (2s - 2) phi_1 [VW2000, (4.10)], which involves every entry except one (lambda_20 for k = 8, which comes from the process D_s), and by means of the numbers tau(k) that are printed below the tables. The inequalities of Proposition A.37 are decided in exact rational arithmetic. (3) The numbers B^nat(k) and Theta^nat(k) of Section A.8 for 37 <= k <= 5000 (Proposition A.39(i), Table 10). B^nat(k) is obtained from an upper bound for an integral over [2 tau_k, 2 z_k], from which the term (1/k) log(z_k/tau_k) is subtracted; the integral is bounded by means of the chains of Lemma A.28, each of which yields a concave minorant of theta_k, by replacing the minorant by its chord on each cell of a subdivision (functions A_grid_rig, A_band_values_lo, A_cell_sum_up, A_bound_rig). These computations use directed rounding as well, and in them the logarithm of the library is allowed an error of four units in the last place; so they are rigorous under IEEE 754 arithmetic if the library logarithm is accurate to that extent on the arguments that occur (on 60000 sample arguments its error is below one unit). The numbers E^nat(k) are formed from these bounds with directed rounding (A_values_rig), and the inequalities of Proposition A.39(i) are then decided in exact rational arithmetic. Directed rounding means that every floating point operation whose result enters a bound is followed by a step to the adjacent floating point number in the safe direction (numpy.nextafter), and that constants are rounded from exact fractions. The hypotheses on which the rigour of a bound depends (for instance, that every tent of a chain is defined at the level at which the chain is evaluated) are enforced by the function _require, which raises an exception, and not by assert statements. The elementary numerical inequalities in the proofs of Lemma A.32 and of Propositions A.33 and A.39(ii), which can be checked by hand, are confirmed as well. Part 15, for Appendix C. The verification of Section C.7 (Lemma C.15, Table 15, Corollary C.14): for 7 <= k <= 10 and the tables of [VW2000], the cells [zeta_i, zeta_(i+1)) (class AC_Cells), the lower bounds check-theta for theta_k from the chains of Lemma A.28 (AC_theta_lo, rounded downwards), the numbers hat-S_i and their suffix minima (rounded downwards), and the potential of Lemma C.4 at the cells (rounded upwards); condition (C.2), the number hat-E and the inequality (1 - omega) hat-E < omega are then decided in exact rational arithmetic (AC_Cells.evaluate, AC_check). Propositions C.17 and C.18: Theorem A.36 in the second case with the tables of Appendix C for k = 13 and k = 7 (A_rec_vw with the argument Dl), with (V1)-(V3), T_k, (R1), (R3) and Y in exact rational arithmetic and (R2) from the chains, as for Proposition A.38. The tables AC_TAB13 and AC_TAB7 are taken as given. The certificates of AC_TAB13 (Section C.8) are in the file k13_certificates.json, which the separate program check_k13_certificates.py verifies; six of its entries (s = 10, 11, 12, 16, 18, 23) are 1e-7 larger than in the first version of the table. Everything else is a consistency check that is not needed for the proofs; Section 10.4 of the paper summarises them. 1. Definition 2.1 / Lemma 10.1: varsigma, its running minimum sigma and the inverse theta*, against the tables of Lemma 10.1. The minimum over z_0 of Psi(z_0) + 2 int_0^z_0 du/(u theta*(2u)), computed from Definition 2.1 on a grid, is 6.3132, attained at z_0 = 0.1 (cf. Section 2.2). 2. Lemma 10.2: the integral I and the constant C_0 (closed form against numerical quadrature); Lemma 10.3. 3. Lemma 4.5 / Table 2: the exponents delivered by Lemmas 4.3 and 4.4 at 5.4e5 parameter sets (k, Theta, theta, U, vartheta) with 37 <= k <= 1e9, chosen at random and at the boundary of the admissible region. In every case the exponent of the row of Table 2 is at least (1 - eta_k(theta)) varsigma(U), and the side conditions hold; equality occurs, for example, for k = 100 and U = theta = Theta = 7/2. 4. Section 8: the potential Phi for thirteen pairs (k, Theta) between (40, 5/2) and (1e9, 28400): (8.1)-(8.3), Lemma 8.1(ii)-(iv), Lemma 8.2 (for random delta and for delta = 0, 1/3, 1/2), Case 2 of the proof of Lemma 8.4, and the inequality (8.10) of Corollary 8.5 for the value of b of the proof of Theorem 2.3 and for seven further values, at random points or on a grid (in four of the cases a_* is negative). The tabulated value of calG(u_Theta) is smaller than the bound of Lemma 8.1(i) by at most 0.007, and the number (9.3), computed from a table with delta_0 = eps_2 = 1e-8, does not exceed the number calY of the proof of Theorem 2.3. Part 5 also compares the closed form of R_k (Lemma 10.4) with Riemann-Stieltjes sums of its definition. 6. The recursion behind Proposition 8.3, solved by dynamic programming without the potential, for (k, Theta) = (40, 5/2), (100, 5) and (250, 25/2): with b as in the proof of Theorem 2.3, the least r/k with sup_lambda (Phi~(1, lambda) - r lambda) <= b (Phi~ the solution of the recursion displayed in Section 10.4) is 6.385, 6.357 and 6.319, against the upper bounds 6.470, 6.393 and 6.332 for calG(u_Theta) + a_* on which Theorem 2.3 rests. 7. The exponents of Lemmas 4.3 and 4.4 on 400 exponential sums calS, with k in {9, 11, 13}, prime power and composite moduli 1e4 < q < 1e16 and 250 <= X <= 6e4: the largest observed value of |calS|/X^(1 - varsigma(U)) is 0.59. At these sizes the savings are small, so that this is a test of the exponent arithmetic rather than of the lemmas themselves. 8. Section 12: bounds on each residue class with an intermediate coefficient, (12.1) and (12.2), compared with Lemma 4.4; the constants quoted at the end of Section 12.1 (with (12.1) in place of Lemma 4.4, with one progression for each residue class, and with translates), the fact that varsigma is the largest saving that Lemmas 4.3 and 4.4 give when the rounding of moduli is ignored, and the constant 6.226 of Section 12.2(1). 9. Section 12.3: the constant in the paper of Chow and Dietmann as written. 10. Section 3 and Lemma 6.1: Lemma 3.1 on random squarefree smooth numbers; Lemma 3.2 on small examples with artificial p_0 and R, and the numerical constants of its proof; the two identities of Lemma 3.3, coefficient by coefficient, in exact rational arithmetic; and the elementary inequalities (6.2) and (6.3) and the pigeonhole step (6.5) of the proof of Lemma 6.1. 11. Section 11: the numbers quoted at the end of Section 11.1, in (11.2) and in Remark 11.5; the largest value 1/9.026725 of (1 - 2 frak_d(vk))/v^2; Proposition 11.6 on a grid, and the numbers quoted after it; and the elementary inequalities in the proof of Lemma 11.4. 12. Section 9.3: the k-th power residues modulo 4k and 8k for k = 4, 8, ..., 128 (Lemma 9.6), and the least number of k-th powers whose sum lies in a given residue class modulo 8k, for k = 8 and 16: it is j for the class of j when 1 <= j < 4k, and 4k for the class of 4k. 13. Section 9.4 and Theorem 2.5: the lower bound for |f| in the proof of Theorem 2.5 on random sets, and the statements about rho^dagger after Theorem 2.5, in Section 9.4 and in Corollary 2.6. 14. Appendix A (in addition to what is listed above): the exponent pairs of the 133 words of W and the constants of (A.14), in exact rational arithmetic; the function (A.45) against Definition A.25 with vartheta = 0 (Lemma A.26), also as the exact upper envelope of the lines of (a), (b), (c), (e), (f), (g) and of the 133 words, and the constant 6.2196 (with the change of regime at z = 41/382) from the definition on a grid, and the continuity, the jumps and the slopes of theta^star, its pieces (Table 7) and the inequalities for D >= 15 (the remarks after Lemma A.26); the statements that follow Corollaries A.18 and A.24; the local sums of the proof of Lemma A.17 on seven configurations (A_local_sums); Lemmas A.7 and A.8 by exact counts, on seven configurations of the kind that occurs in Lemma A.9 and on 200 random ones (A_pairs_test), and the last step of the proof of Lemma A.9 in exact arithmetic; a falsification test of Lemma A.27(i) on 60 explicit sums; the chains of Lemma A.28 against Definition A.25 at random points, the coefficients in the proof of Lemma A.28(iv), and the constants of the intervals Q_{D,iota} and N_{D,iota}; the lower bounds of Lemma A.32 against Definition A.25; the numbers quoted in Remarks A.40-A.42 and A.44. By Lemma A.28(i), theta_k(t) can be computed directly from Definition A.25, without chains (A_theta_direct, and A_theta_upper with directed rounding): this gives Theta^nat(k) = Theta_k at eight values of k between 37 and 1e6, confirms Lemma A.32 at 4950 points, and gives rigorous lower Riemann sums for the optimal value Y_k(Theta_k) + 1 of Theorem A.31(i) (A_Y_lower). For the recursion: the inequality of (R2) for single steps, with theta_k from Definition A.25 on a grid; the whole recursion in plain double precision with theta_k from Definition A.25 instead of chains (A_rec_plain), for nine values of k and for 7 <= k <= 20 with the tables, and, for Remark A.41, with the numbers rho_j(U) - vartheta/2 of Lemma 4.3(ii) in place of those of Lemma A.14 (oldb=True), without the numbers (d) of Definition A.25 (A_PAIRS_ON = False), without the numbers (g) (A_MCANCEL_ON = False; this reproduces the bounds of the previous version), without the numbers (f) and (g) (A_CANCEL_ON = A_MCANCEL_ON = False; the version before that), and without the numbers (e), (f) and (g) (A_MULT_ON = A_CANCEL_ON = A_MCANCEL_ON = False, with c_n < 1/10, as in the version before that); and the potential of the proof of Theorem A.36 on a grid, for k = 6, 21, 37 and 100 (A_rec_potential). For Section A.8: a second implementation in 40-digit decimal arithmetic (A_exact), in which the conditions on a chain are derived mechanically from the end points of the intervals of Lemma A.28 instead of being taken from solved formulae. 15. Appendix C (in addition to what is listed above): the column 'lambda_s of [VW2000]' of Table 16 against the tables in the program; the thresholds of Corollary C.5 at the switch points of Remark C.6; and, for Remark C.20, the largest value of k(Psi(z_0) - Psi(underline-hat-S)) for k = 6 on a grid of switch points. 16. Appendix D (nothing in the other parts depends on it): the parts of C_0^star in Table 18, in decimal arithmetic from the linear pieces of theta^star and the interval for Lambda^star; the expansions (D.1) of Lambda_D, Lambda_D^star, Lambda_D^sharp and Lambda_D^dagger in powers of 1/D, by exact arithmetic with power series (class _DSer); the sums of Table 19, with the remainders bounded as in Part 14; the bound (D.2); and the comparison of Section D.3(a) for further differencing steps. The hypothetical values of Section D.4 are not computed here. Notation as in the paper: calG is the potential of Section 8, frak_g(z) = -z calG'(z), c_Theta = 2(1+eps_2)/Theta its slope (8.4), calG_inf its limit as k -> infinity, and chi_0 = 1 + log 2 the constant of Section 11.3. Only numpy is required. """ import sys import random import numpy as np from fractions import Fraction from math import log, log1p, log2, exp, ceil, floor, gcd, sqrt, pi, e as E # ===================================================================================================================== # Definitions (Sections 1, 2 and 10 of the paper) # ===================================================================================================================== def sD(D): """the value 1/(D(D+1)) of varsigma on its intervals of constancy (Definition 2.1)""" return 1.0/(D*(D+1)) def lD(D): """the left end point D - 1/D of the interval on which varsigma(U) = (D+1-U)/(D+1)^2 (D >= 4)""" return D - 1.0/D def rD(D): """the right end point (D+1)^2/(D+2) of that interval; varsigma is constant on [rD(D), lD(D+1)]""" return (D+1)**2/(D+2) def degree(U): """for U >= 15/4: the integer D >= 4 with D - 1/D <= U < D + 1 - 1/(D+1)""" D = max(4, int(floor(U)) + 1) while U < lD(D) and D > 4: D -= 1 while U >= lD(D+1): D += 1 return D def varsigma(U): """the saving function of Definition 2.1""" if U <= 1.5: return (2-U)/2 if U <= 9/4: return (3-U)/6 if U <= 25/8: return (4-U)/14 if U <= 7/2: return (5-U)/30 if U <= 15/4: return 1/20 D = degree(U) return (D+1-U)/(D+1)**2 if U <= rD(D) else sD(D+1) def branch(U): """the row of Table 2: ('V', j) = Lemma 4.3 with j (j = 0: part (i)); ('M', D) = Lemma 4.4 with D""" if U <= 1.5: return ('V', 0) if U <= 9/4: return ('V', 1) if U <= 25/8: return ('V', 2) if U <= 7/2: return ('V', 3) if U <= 15/4: return ('M', 4) D = degree(U) if U == lD(D): D -= 1 # U = D - 1/D belongs to the last row with D - 1 (half-open ranges) return ('M', D) if U <= rD(D) else ('M', D+1) def sigma(th): """sigma(theta) = min_{1<=U<=theta} varsigma(U) = varsigma(theta), as varsigma is nonincreasing (Lemma 10.1(i))""" return varsigma(th) def theta_star(s): """theta*(s) = max{theta: sigma(theta) >= s}, by Lemma 10.1(ii)""" if s >= 1/4: return 2-2*s if s >= 1/8: return 3-6*s if s >= 1/16: return 4-14*s if s > 1/20: return 5-30*s D = max(4, int(floor((-1+sqrt(1+4/s))/2))) while sD(D) < s: D -= 1 while sD(D+1) >= s: D += 1 # 1/((D+1)(D+2)) < s <= 1/(D(D+1)) return D+1-(D+1)**2*s # ---- the integral I(s) = int_0^s dt/(t theta*(t)) (Definition 2.1, Lemma 10.2) DMAX = 10**6 _Darr = np.arange(4, DMAX, dtype=np.float64) _suffix = np.cumsum((np.log1p(2.0/(_Darr-1.0))/(_Darr+1.0))[::-1])[::-1] # _suffix[i] = sum_{D=4+i}^{DMAX-1} log((D+1)/(D-1))/(D+1) def tail_sum(N, upper=True): """sum_{D>=N} log((D+1)/(D-1))/(D+1) = I(1/(N(N+1))) for N >= 4. The part beyond DMAX lies in [2/DMAX, 1/(DMAX-1) + 1/DMAX] (Lemma 10.2(i)); upper=True adds the upper bound for it, upper=False the lower bound.""" if N >= DMAX: return (1.0/(N-1) + 1.0/N) if upper else 2.0/N return float(_suffix[N-4]) + ((1.0/(DMAX-1) + 1.0/DMAX) if upper else 2.0/DMAX) PIECES = [(1/3)*log(2), (1/4)*log(25/9), (1/5)*log(7/5)] LAMBDA_LO = sum(PIECES) + tail_sum(4, False) LAMBDA = sum(PIECES) + tail_sum(4, True) # upper value of Lambda, (1.2) C0_LO = 2 + log(9) + 2*LAMBDA_LO C0 = 2 + log(9) + 2*LAMBDA # upper value of C_0, (1.3) def I(s, upper=True): """I(s) for 0 < s <= 1/4, from Lemma 10.2 (upper/lower refers to the truncation of the series only)""" prim = lambda A, B, x: log(x/(A-B*x))/A # a primitive of 1/(x(A-Bx)) if s > 1/20: tot = tail_sum(4, upper) for lo, hi, A, B in [(1/20, 1/16, 5, 30), (1/16, 1/8, 4, 14), (1/8, 1/4, 3, 6)]: if s > lo: tot += prim(A, B, min(s, hi)) - prim(A, B, lo) return tot D = max(4, int(floor((-1+sqrt(1+4/s))/2))) while sD(D) < s: D -= 1 while sD(D+1) >= s: D += 1 # 1/((D+1)(D+2)) < s <= 1/(D(D+1)) return prim(D+1, (D+1)**2, s) - prim(D+1, (D+1)**2, sD(D+1)) + tail_sum(D+1, upper) def T(Th): """T(Theta) = I(sigma(Theta)); the lower value is returned, because T enters Theorem 2.3 with a minus sign""" return I(sigma(Th), upper=False) # ---- Definition 2.2 def kappa(th): if th <= 9/4: return 4.0 if th <= 25/8: return 8.0 return max(10.0, th+4.0) def varpi(th): return 1/16 if th <= 25/8 else 1/20 def eta_k(th, k): return th*kappa(th)/k def admissible(k, Th): """Definition 2.2 (the relative tolerance 1e-12 only guards the case Theta = varpi(Theta) k against rounding)""" return k >= 37 and Th >= 9/4 and Th <= varpi(Th)*k*(1+1e-12) and Th*(Th+4) < k def a_k(k): """the positive root a of a(a+4) = k (Lemma 10.4); Theta(Theta+4) < k iff Theta < a_k""" return k/(sqrt(k+4.0)+2.0) def R_k(k, Th, d0=0.0): """Lemma 10.4: the Riemann-Stieltjes integral of 1/theta against -log(1 - d0 - eta_k(theta)) over [9/5, Theta]""" kk = k*(1-d0) pts = [1.8, 9/4, 25/8, 6.0]; ks = [4.0, 8.0, 10.0] tot = 0.0 for i, kap in enumerate(ks): a, b = pts[i], min(Th, pts[i+1]) if b > a: tot += (kap/kk)*(log(b/a) + log1p(kap*(b-a)/(kk-kap*b))) # (kap/k) log( b(k-kap a) / (a(k-kap b)) ) if Th <= pts[i+1]: return tot if i < 2: t = pts[i+1]; tot += (1/t)*log1p((ks[i+1]-kap)*t/(kk-ks[i+1]*t)) # jump (1/t) log((k-kap t)/(k-kap' t)) a = a_k(kk) # int_6^Theta (2t+4) dt / (t (k - t^2 - 4t)), Lemma 10.4 return tot + (4.0/kk)*log(Th/6.0) + log1p((Th-6.0)/(a-Th))/a + log1p((Th-6.0)/(a+10.0))/(a+4.0) TAU_INV = 9.027901 # tau_k = 1/(9.027901 k) (2.3) def tau_k(k): return 1.0/(TAU_INV*k) def y_k(k, Th): """y_k(Theta) = (1 - eta_k(Theta)) sigma(Theta) / (2 tau_k) (2.3)""" return 0.5*(1-eta_k(Th, k))*sigma(Th)*TAU_INV*k def W_k(k, Th): """W_k(Theta) = (2/Theta) log y_k(Theta) (2.3); it is negative when y_k(Theta) < 1""" return (2/Th)*log(y_k(k, Th)) def a_star(k, c, uTh, b): """a_*(b) = c_Theta log(k c_Theta u_Theta/(e b)) (8.11), with c = c_Theta; it is negative when b > k c_Theta u_Theta/e""" return c*log(k*c*uTh/(E*b)) def b_choice(k, c): """the choice b = k c_Theta tau_k in the proof of Theorem 2.3 (c = c_Theta): it minimises k a_*(b) + b/tau_k""" return k*c*tau_k(k) def Cfun(eta): """C(eta) of Section 2 (upper value)""" return 2 + 2*LAMBDA + log((45+6*eta-eta*eta)/((1-eta)*(5-eta))) - (2/3)*log((15+2*eta)/(15-3*eta)) def h_k(k): return 36/(5*(k-1)) def bound(k, Th): """B(k, Theta) of Section 10.2. Theorem 2.3: G(k) <= floor(k * bound(k, Theta)) for admissible Theta (None if Theta is not admissible)""" if not admissible(k, Th): return None return Cfun(h_k(k)) - 2*T(Th) + 2*R_k(k, Th) + W_k(k, Th) + 1/k def Theta_max(k): """the largest Theta with Theta <= varpi(Theta) k (Section 10.2)""" if k >= 63: return k/20 return min(k/16, 25/8) def Theta_sharp(k): """Theta^sharp(k) = min{Theta_max(k), (9/10) a_k} (Section 10.2)""" return min(Theta_max(k), 0.9*a_k(k)) KNUM = 5000 # Proposition 10.5 covers 37 <= k <= KNUM CHI0 = 1 + log(2) # chi_0 = 1 + log 2 = 1.69314... (Section 11.3) def s0_floor(k): """the least natural number s_0 with s_0 >= 5k/2 (hypothesis of Theorem 2.7)""" return -(-5*int(k)//2) if float(k).is_integer() else ceil(2.5*k) def frac_exponent(k, Th, b): """Theorem 2.7. Returns (E, s_0, y), where y = Y - (2k/Theta)(1 + log(9.027901 Theta b/2)) with Y = k B(k,Theta) - 1, s_0 >= 5k/2 is the least natural number with 2 s_0 > y, and E = 2 s_0 + (1 + b) 4.5139505 k. Then min_{1 <= n <= N} ||alpha n^k|| < N^(-rho) for every rho < 1/E, all real alpha and all large N.""" y = k*bound(k, Th) - 1 - (2*k/Th)*(1 + log(TAU_INV*Th*b/2)) s0 = max(s0_floor(k), floor(y/2) + 1) return 2*s0 + (1 + b)*0.5*TAU_INV*k, s0, y def b_sharp(Th): """b = 4/(9.027901 Theta), so that 9.027901 Theta b/2 = 2 and b 4.5139505 k = 2k/Theta (Section 11.3)""" return 4/(TAU_INV*Th) def E_sharp(k): """E^sharp(k) of Section 11.3: Theta = Theta^sharp(k) and b = 4/(9.027901 Theta)""" Th = Theta_sharp(k) return frac_exponent(k, Th, b_sharp(Th))[0] def phi_as(lam): """phi(lambda) of Proposition 10.7: with Theta = lambda sqrt(k) the bound is C_0 k + phi(lambda) sqrt(k) + 5 log k + O(1)""" return -4/lam + 2*log((1+lam)/(1-lam)) + (2/lam)*log(TAU_INV*(1-lam*lam)/(2*lam*lam)) def BW(k): """the bound (1.1) of Bruedern and Wooley""" return ceil(k*(log(k)+4.20032)) # ===================================================================================================================== # Checks # ===================================================================================================================== OK = True def check(cond, msg): global OK print((" [ok] " if cond else " [FAIL] ") + msg) OK = OK and bool(cond) def part1(rng): print("1. Definition 2.1 and Lemma 10.1: varsigma, sigma, theta*") Ugrid = np.exp(np.linspace(log(1+1e-9), log(3000.0), 1_000_001)) vs = np.array([varsigma(u) for u in Ugrid]) sig = np.minimum.accumulate(vs) # the branches agree at their common end points, in exact arithmetic Fr = Fraction def br(U): # the branches of Definition 2.1 that contain U (exact values) out = [] for lo, hi, f in [(Fr(1), Fr(3, 2), lambda u: (2-u)/2), (Fr(3, 2), Fr(9, 4), lambda u: (3-u)/6), (Fr(9, 4), Fr(25, 8), lambda u: (4-u)/14), (Fr(25, 8), Fr(7, 2), lambda u: (5-u)/30), (Fr(7, 2), Fr(15, 4), lambda u: Fr(1, 20))]: if lo <= U <= hi: out.append(f(U)) for D in range(4, 400): if D - Fr(1, D) <= U <= Fr((D+1)**2, D+2): out.append((D+1-U)/Fr((D+1)**2)) if Fr((D+1)**2, D+2) <= U <= D+1-Fr(1, D+1): out.append(Fr(1, (D+1)*(D+2))) return out ends = [Fr(3, 2), Fr(9, 4), Fr(25, 8), Fr(7, 2), Fr(15, 4)] + [x for D in range(4, 300) for x in (D - Fr(1, D), Fr((D+1)**2, D+2))] oke = all(len(set(br(x))) == 1 and len(br(x)) >= 2 for x in ends) okcov = all(len(br(Fr(int(n), 1000))) >= 1 for n in range(1000, 300000, 7)) check(oke and okcov and np.max(np.abs(np.diff(vs))) < 1e-3, "Definition 2.1: consecutive branches agree at their common end points (exact arithmetic, D < 300), the ranges cover [1, 300]," " and varsigma is continuous (no jumps on a grid of 10^6 points up to U = 3000)") dec = all(br(x)[0] > br(y)[0] for D in range(4, 300) for x, y in [(D - Fr(1, D), Fr((D+1)**2, D+2))]) \ and br(Fr(1))[0] > br(Fr(7, 2))[0] and all(br(Fr((D+1)**2, D+2))[-1] == br(D+1-Fr(1, D+1))[-1] for D in range(4, 300)) check(bool(np.all(np.diff(vs) <= 1e-15)) and np.max(np.abs(sig - vs)) == 0 and dec, "Lemma 10.1(i): varsigma is nonincreasing (grid), so that sigma = varsigma; it is strictly decreasing on [1, 7/2] and on each" " [D - 1/D, (D+1)^2/(D+2)], and constant on [7/2, 15/4] and on each [(D+1)^2/(D+2), D + 1 - 1/(D+1)] (D >= 4)") mm = lambda U: max(min(sD(D), (D+1-U)/(D+1)**2) for D in range(4, int(U)+3)) Um = np.concatenate([np.linspace(3.5, 60, 20001), np.exp(rng.uniform(log(3.5), log(3000), 3000))]) check(max(abs(mm(float(u)) - varsigma(float(u))) for u in Um) < 1e-15, "for U >= 7/2: varsigma(U) = max_{D >= 4} min{1/(D(D+1)), (D+1-U)/(D+1)^2} (after Definition 2.1)") bad = 0 for s_ in np.exp(rng.uniform(log(2e-7), log(0.4999), 4000)): th = theta_star(s_) if not (sigma(th) >= s_*(1-1e-12) and sigma(th*(1+1e-9)+1e-9) <= s_*(1+1e-6)): bad += 1 flat = all(abs(theta_star(sD(D)) - (lD(D) if D >= 5 else 15/4)) < 1e-12 for D in range(4, 2000)) check(bad == 0 and flat and abs(theta_star(1/20) - 15/4) < 1e-15, "table of theta* (Lemma 10.1(ii)) is the generalised inverse of sigma (4000 random s); theta*(1/(D(D+1))) = D - 1/D for D >= 5" " and theta*(1/20) = 15/4 (the right end points of the intervals of constancy)") return Ugrid, vs, sig def part2(rng, Ugrid, vs, sig): print("2. Lemma 10.2 (the integral I, the constant C_0) and Lemma 10.3") print(f" Lambda in [{LAMBDA_LO:.9f}, {LAMBDA:.9f}], C_0 in [{C0_LO:.9f}, {C0:.9f}]") check(abs(tail_sum(4)-0.504248) < 1e-6 and abs(LAMBDA-1.058004) < 1e-6 and abs(C0-6.313234) < 1e-6, "sum_{D>=4} log((D+1)/(D-1))/(D+1) = 0.504248..., Lambda = 1.058004..., C_0 = 6.313234...") # brute force: min over z0 of Psi(z0) + 2 int_0^{z0} du/(u theta*(2u)), computed from varsigma alone logs = np.log(sig); dl = -(logs[1:]-logs[:-1]); mid = np.sqrt(Ugrid[1:]*Ugrid[:-1]) suffix = np.concatenate([np.cumsum((dl/mid)[::-1])[::-1], [0.0]]) + 2/3000.0 z = sig/2 val = 2 + np.log((1-z)/z) + 2*suffix i = int(np.argmin(val)) check(abs(val[i]-C0) < 2e-4 and abs(z[i]-0.1) < 1e-3, f"brute-force optimisation over the switching point (Section 2.2): min = {val[i]:.5f} at z = {z[i]:.5f}; closed form C_0 = {C0:.5f} at z = 1/10") check(abs(I(0.2)-LAMBDA) < 1e-12, "I(1/5) = Lambda (2.1)") check(all(abs(I(2*w)-(LAMBDA-log((3-12*w)/(18*w))/3)) < 1e-12 for w in np.linspace(1/16, 0.1, 50)), "I(2w) = Lambda - (1/3) log((3-12w)/(18w)) for 1/16 <= w <= 1/10 (Lemma 10.2(iii))") sg = np.exp(np.linspace(log(1e-6), log(0.2), 2_000_001)); fg = np.array([1/theta_star(x) for x in sg]) quad = float(np.sum(0.5*(fg[1:]+fg[:-1])*np.diff(np.log(sg)))) check(abs(quad-(I(0.2)-I(1e-6))) < 1e-6, f"closed form of I against quadrature of 1/(t theta*(t)): {quad:.7f} vs {I(0.2)-I(1e-6):.7f}") Ns = list(range(4, 2000)) + [10**4, 10**5, DMAX-1] check(all(2/N <= tail_sum(N, False) and tail_sum(N, True) <= 1/(N-1) + 1/N for N in Ns) and all(abs(I(sD(N)) - tail_sum(N)) < 1e-15 for N in range(4, 500)), "2/N <= I(1/(N(N+1))) <= 1/(N-1) + 1/N for N >= 4 (Lemma 10.2(i))") ths = np.concatenate([np.linspace(3.5, 60, 20001), np.exp(rng.uniform(log(3.5), log(3000), 5000)), [x for D in range(4, 200) for x in (lD(D), rD(D))]]) check(all(sigma(t) <= 1/(t*(t+1))+1e-15 for t in ths), "sigma(Theta) <= 1/(Theta(Theta+1)) for Theta >= 7/2 (Lemma 10.3)") check(all(T(t) >= 2/(t+1.25) for t in ths), "T(Theta) >= 2/(Theta+5/4) for Theta >= 7/2 (Lemma 10.3)") def rounded_exponent(U, vth): """exponent delivered by the row of Table 2 for (U, vartheta), and whether the side conditions of the lemma hold""" kind, par = branch(U) if kind == 'V': j = par if j == 0: return 1-U/2, True rho = (j+2-U)/(2**(j+2)-2) return rho - vth/2, (rho >= vth*(1-1e-12) and U >= j+2.0**(-j)-1e-12) # rho = vartheta occurs (e.g. k = 37, U = 9/4, theta = 37/16) D = par val = min(2*U/(D+1) - 2*D*vth, 1 - D*vth, D*(1-U/(D+1)) - D*vth)/(D*(D+1)) # Lemma 4.4 return val, (U/(D+1)+vth < 1 and D >= 4) def top_admissible(k): """supremum of the admissible Theta""" return min(Theta_max(k), a_k(k)*(1-1e-12)) def part3(rng): print("3. Lemma 4.5 and Table 2: exponents after rounding") worst = 1e9; side = True; degok = True; ntest = 0 klist = [37, 40, 50, 52, 62, 63, 78, 100, 120, 150, 200, 285, 400, 1000, 10**4, 10**5, 10**6, 10**9] special = [1.5, 9/4, 25/8, 7/2, 15/4] + [x for D in range(4, 12) for x in (lD(D), rD(D))] for k in klist: Thmax = top_admissible(k) for it in range(30000): Th = Thmax if it % 10 == 0 else rng.uniform(9/4, Thmax) # every tenth test at the largest admissible Theta if not admissible(k, Th): continue th = Th if it % 20 == 0 else rng.uniform(1.0000002, Th) U = rng.uniform(1.0000001, th) r = rng.random() if r < 0.3: U = min(th, special[int(rng.integers(len(special)))]) elif r < 0.4: U = th vth = max(U/k, th/k*(1.0 if rng.random() < 0.5 else rng.uniform(0, 1))) # U <= k*vartheta <= theta ex, sc = rounded_exponent(U, vth) side &= sc degok &= (branch(U)[1] <= k-2) worst = min(worst, ex - (1-eta_k(th, k))*varsigma(U)); ntest += 1 check(worst >= -1e-12 and side and degok, f"{ntest} parameter sets (k, Theta, theta, U, vartheta), k from {klist[0]} to {klist[-1]:g}, including Theta = largest admissible value," f" U = theta and the end points of the ranges: min[(exponent of Table 2) - (1-eta_k(theta)) varsigma(U)] = {worst:.1e}" f" (zero up to rounding: equality occurs, e.g. for k = 100, U = theta = Theta = 7/2); side conditions hold") # the facts used in the proof of Lemma 4.5: rows 2-4: kappa(theta) varsigma(U) >= 1/2; rows 5-7: (4.9), V >= D'/(D'+2), # D'(D'+1) varsigma(U) = min{1, V}, and, with kappa = U + 4 <= kappa(theta): kappa > D' + 2, kappa U >= D'(D'+1), 1 - U/(D'+1) >= 1/(D'+2) okr = True; okm = True Ug = np.concatenate([np.linspace(1.000001, 60, 600001), special, [x*(1+1e-12) for x in special]]) for U in Ug: U = float(U); kind, par = branch(U); v = varsigma(U) if kind == 'V': if par >= 1: okr &= {1: 4.0, 2: 8.0, 3: 10.0}[par]*v >= 0.5 - 1e-15 continue Dp = par; V = Dp*(1 - U/(Dp+1)); kap = U + 4 okm &= (max(3.5, Dp*Dp/(Dp+1)) < U <= (Dp+1)**2/(Dp+2)*(1+1e-15) and V >= Dp/(Dp+2)*(1-1e-15) and abs(Dp*(Dp+1)*v - min(1.0, V)) < 1e-12 and kap > Dp+2 and kap*U >= Dp*(Dp+1) and 1 - U/(Dp+1) >= 1/(Dp+2) - 1e-15) okk = all(kappa(t) >= t + 4 - 1e-12 for t in np.linspace(3.5, 100, 10001)) and all(Dp*(Dp+2)**2 >= (Dp+1)**3 for Dp in range(1, 1000)) check(okr and okm and okk, "proof of Lemma 4.5: kappa(theta) varsigma(U) >= 1/2 in rows 2-4; in rows 5-7 (4.9) holds, V >= D'/(D'+2), D'(D'+1) varsigma(U) = min{1, V}," " kappa(theta) >= theta + 4 >= U + 4 > D' + 2, (U + 4) U >= D'(D'+1) and 1 - U/(D'+1) >= 1/(D'+2) (grid of U up to 60)") class Pot: """the potential of Section 8 for given (k, Theta), with d0 = delta_0 and eps2 = eps_2 small. the potential calG is tabulated along the curve u = M(theta) (exact up to second order in the mesh).""" def __init__(s, k, Theta, eps2=1e-6, d0=1e-6, n=400001): assert admissible(k, Theta) s.k = k; s.Th = Theta; s.eps2 = eps2; s.d0 = d0 s.gamma = 1/(100*k*(log(k)+9)**2); s.L = log(1/s.gamma) s.etac = 2*d0 + h_k(k); s.wc = 0.1 - s.etac/50 - eps2/4; s.zc = (1-s.etac)*s.wc s.c = 2*(1+eps2)/Theta s.uTh = s.M(Theta) s.thc = s._theta_bisect(s.zc, 1.0, Theta) special = [9/4, 25/8, 7/2, 15/4, s.thc] special += [x*(1+1e-13) for x in (9/4, 25/8)] D = 4 while lD(D) <= Theta: special.append(lD(D)); special.append(rD(D)); D += 1 tg = np.unique(np.concatenate([np.exp(np.linspace(log(s.thc), log(Theta), n)), [x for x in special if s.thc <= x <= Theta], [Theta]])) s.tg = tg s.Mg = np.array([s.M(float(t)) for t in tg]) assert np.all(np.diff(s.Mg) <= 0) and abs(s.Mg[0]-s.zc) < 1e-12 s.Gzc = 2+log((1-s.zc)/s.zc) inc = 2*(1+eps2)*np.log(s.Mg[:-1]/s.Mg[1:])/np.sqrt(tg[:-1]*tg[1:]) s.Ghat = s.Gzc + np.concatenate([[0.0], np.cumsum(inc)]) # Ghat[i] = calG(M(tg[i])) s.G0 = float(s.Ghat[-1]) # calG(u_Theta) s.Ggamma = s.G0 + s.c*s.L # calG_gamma = calG(u_Theta) + c_Theta log(1/gamma) s.b = b_choice(k, s.c) # the choice of b in the proof of Theorem 2.3 s.astar = a_star(k, s.c, s.uTh, s.b) # = c_Theta (log(u_Theta/tau_k) - 1); it may be negative s.r = k*(s.G0+s.astar) s.t = s.b/tau_k(k) # s = r + t with t tau_k = b (in the limit) def M(s, t): return 0.5*(1-s.d0-eta_k(t, s.k))*sigma(t) def _theta_bisect(s, z, lo, hi): if s.M(hi) >= z: return hi for _ in range(70): mid = 0.5*(lo+hi) if s.M(mid) >= z: lo = mid else: hi = mid return lo def theta(s, z): """theta(z) = max{theta in [1,Theta]: M(theta) >= z}""" if z <= s.uTh: return s.Th if z >= s.zc: return s._theta_bisect(z, 1.0, s.Th) i = len(s.Mg) - int(np.searchsorted(s.Mg[::-1], z, side='left')) - 1 # largest i with Mg[i] >= z return s._theta_bisect(z, float(s.tg[i]), float(s.tg[min(i+1, len(s.tg)-1)])) def G(s, z): if z >= 0.5: return 1/z if z >= s.zc: return 2+log((1-z)/z) if z <= s.uTh: return s.G0 + s.c*log(s.uTh/z) i = len(s.Mg) - int(np.searchsorted(s.Mg[::-1], z, side='left')) - 1 th = s._theta_bisect(z, float(s.tg[i]), float(s.tg[min(i+1, len(s.tg)-1)])) return float(s.Ghat[i]) + 2*(1+s.eps2)*log(float(s.Mg[i])/z)/sqrt(float(s.tg[i])*th) def Phi(s, x, lam): return 0.0 if lam <= 0 else s.k*lam*s.G(max(lam, s.gamma*s.uTh)/x) POT_CASES = [(40, 2.5), (67, 3.125), (100, 5.0), (150, 7.5), (211, 5.23), (1000, 14.27), (1000, 24.79), (10**4, 36.5), (10**4, 87.7), (10**6, 197.0), (10**6, 897.0), (10**9, 2190.0), (10**9, 28400.0)] def part4(rng): print("4. Section 8: the potential Phi") for (k, Th) in POT_CASES: P = Pot(k, Th); g = P.gamma thc = P.thc hyp = thc >= 2*(1+P.eps2)*(1-P.zc) and thc >= 3-12*P.wc and P.uTh < 1/16 < P.zc < 0.1 # (8.2), (8.3) w = dict(adm=1e9, iii=1e9, mono=1e9, path=1e9, lip=-1e9, a=1e9) zlo = g*P.uTh*1e-3 for _ in range(2500): x = float(np.exp(rng.uniform(log(4*g), 0))) zz = float(np.exp(rng.uniform(log(zlo), log(P.zc))))*(1-1e-9); lam = zz*x th = P.theta(zz) # (8.1): (1-eta_k(theta)) sigma(theta) >= 2z + delta_0 sigma(Theta) w['adm'] = min(w['adm'], ((1-eta_k(th, k))*sigma(th) - 2*zz - P.d0*sigma(Th))/sigma(Th) + 1e-9) for d in (th*x/k/(1+P.eps2), th*x/k): w['iii'] = min(w['iii'], (P.Phi(x, lam)-P.Phi(x-d, lam))/lam - 2 + 1e-5) # Lemma 8.1(iii) mus = np.sort(rng.uniform(0, lam*(1+1e-6), 5)) # Lemma 8.1(ii): slope >= 2k for lambda <= x/5 vals = np.array([P.Phi(x-d, m) for m in mus]) w['mono'] = min(w['mono'], float(np.min(np.diff(vals) - 2*k*np.diff(mus)))/(k*lam) + 1e-6) # Lemma 8.2 (shallow paths): Phi(x - t, lambda - (1 - delta) t) <= Phi(x, lambda) - 2 (1 - delta) k t for delta in (float(rng.uniform(0, 0.5)), 1/3, 0.0, 0.5): lb = lam if rng.random() < 0.5 else float(rng.uniform(0, 0.2))*x # lambda <= x/5 t = float(rng.uniform(0, min(lb/(1-delta), x-g))) w['path'] = min(w['path'], (P.Phi(x, lb)-P.Phi(x-t, max(lb-(1-delta)*t, 0.0))-2*(1-delta)*k*t)/max(k*t, 1e-300) + 1e-6) l2 = lam*rng.uniform(0.5, 1.5) w['lip'] = max(w['lip'], (P.Phi(x, max(lam, l2))-P.Phi(x, min(lam, l2)))/max(abs(lam-l2), 1e-300)/k - P.Ggamma) z2 = float(rng.uniform(P.zc, 3.0)); lam2 = z2*x # Case 2 of the proof of Lemma 8.4 ap = k*x if z2 >= 0.5 else min(k*x, k*lam2*(2+log((1-z2)/z2))) w['a'] = min(w['a'], (P.Phi(x, lam2)-ap)/(k*x) + 1e-9) lams = np.exp(np.linspace(log(zlo), 0, 40001)) beta = max(P.Phi(1.0, float(l)) - P.r*float(l) for l in lams) # Corollary 8.5 for x = 1 for _ in range(40): # ... and for gamma <= x <= 1 x = float(np.exp(rng.uniform(log(g), 0))) beta = max(beta, max((P.Phi(x, float(l)*x) - P.r*float(l)*x)/x for l in lams[::50])) closed = 2+log((1-P.zc)/P.zc) + 2*(1+P.eps2)*(I(2*P.wc) - T(Th) + R_k(k, Th, P.d0)) # Lemma 8.1(i) # Lemma 8.1(iv): calG(z) <= calG(u_Theta) + c_Theta log(u_Theta/z) for 0 < z <= 1, and z calG(z) is concave zs = np.unique(np.concatenate([np.exp(np.linspace(log(1e-12), 0.0, 3001)), P.uTh*np.exp(np.linspace(-3, 3, 401)), [P.zc, 0.5]])) zs = zs[zs <= 1.0] Gz = np.array([P.G(float(z)) for z in zs]) line = float(np.max(Gz - (P.G0 + P.c*np.log(P.uTh/zs)))) sl = np.diff(zs*Gz)/np.diff(zs) conc = float(np.max(np.diff(sl))) # Corollary 8.5 for other b: a_*(b) = -c_Theta w for b = (k c_Theta u_Theta/e) e^w; then k z (calG(z) - calG(u_Theta) - a_*) <= b cor = max(float(np.max(k*zs*(Gz - P.G0 + P.c*wv)))/(k*P.c*P.uTh/E*np.exp(wv)) for wv in (3.0, 1.3, 1.0, 0.5, 0.0, -1.0, -5.0)) good = hyp and all(v >= -1e-9 for kk, v in w.items() if kk != 'lip') and w['lip'] <= 1e-6 and beta <= P.b*(1+1e-6) \ and line <= 1e-7 and conc <= 1e-6 and cor <= 1+1e-7 and P.r >= k+1 if not good: print(" details:", hyp, {kk: float(v) for kk, v in w.items()}, beta, P.b, line, conc, cor) check(good and P.G0 <= closed + 1e-4, f"k={k:g}, Theta={Th:.4f}: (8.1)-(8.3), Lemma 8.1(ii)-(iv), Lemma 8.2 (four values of delta), Case 2 of the proof of Lemma 8.4 at 2500 random states; " f"a_* = {P.astar:+.4f}, sup[(Phi(x,l)-r l)/x] = {beta:.4f} <= b = {P.b:.4f}; Cor. 8.5 for seven further b (ratio {cor:.4f}); " f"calG(u_Theta) = {P.G0:.5f} <= bound of Lemma 8.1(i) = {closed:.5f}") def print_list(): """the bound of Theorem 2.3 at Theta^sharp(k) for every 37 <= k <= KNUM (Proposition 10.5), the least l that is admissible in Theorem 2.4, and the number E^sharp(k) of Section 11.3 with the bound k(log k + 8.02113) of [BW2025]""" print("# k Theta^sharp(k) B(k,Theta^sharp(k)) floor(k B) ceil(k(log k+4.20032)) l (Thm 2.4) E^sharp(k) k(log k+8.02113)") for k in range(37, KNUM+1): Th = Theta_sharp(k); v = bound(k, Th) print(f"{k:5d} {Th:12.6f} {v:.6f} {floor(k*v):6d} {BW(k):6d} {(floor(k*v)+1)//2:6d} {E_sharp(k):11.3f} {k*(log(k)+8.02113):11.3f}") # the inequalities of Proposition 10.6 (k >= KNUM, Theta = (9/10) a_k); the constants are those of the paper C_T, C_R, C_W = -2.48, -1.84, 2.60 C3 = 2*log(19) - 40/9 + (20/9)*log(19*TAU_INV/162) # the coefficient of sqrt(k) in Proposition 10.6; C3 = phi(9/10) CF = 10.8272 # a rounded-up value of C_0 + 4.5139505 (Theorem 1.5) TAB3_K = [37, 38, 39, 40, 41, 50, 62, 63, 76, 100, 132, 150, 200, 215, 243, 252, 500, 806, 1000, 2000, 5000] def part5(): print("5. Theorem 2.3, Propositions 10.5-10.7, Table 3, Theorems 1.1 and 1.2") # --- C(eta) def f_top(eta): w = 0.1-eta/50; zz = (1-eta)*w return 2 + log((1-zz)/zz) + 2*I(2*w) et = np.linspace(0, 0.2, 2001); cv = np.array([Cfun(x) for x in et]); sl = np.diff(cv)/np.diff(et) check(max(abs(Cfun(x)-f_top(x)) for x in et) < 1e-12 and abs(Cfun(0)-C0) < 1e-13, "C(h) = Psi(z) + 2 I(2w) with w = 1/10 - h/50, z = (1-h) w; C(0) = C_0") check(0 < sl.min() and sl.max() < 1.4 and all(k*Cfun(h_k(k)) <= C0_LO*k + 11 for k in range(37, 100000)), f"0 < C' < 7/5 on [0, 1/5] (slopes between {sl.min():.3f} and {sl.max():.3f}); k C(h_k) <= C_0 k + 11 for k >= 37") # --- the Weyl exponent tau_k d = 0.3 for _ in range(60): d -= (d+log(d)+1)/(1+1/d) check(abs(d-0.2784645428) < 1e-9 and 0 < TAU_INV - 4/(1-2*d) < 1e-6, f"delta_* + log delta_* + 1 = 0 for delta_* = {d:.10f}; 4/(1-2 delta_*) = {4/(1-2*d):.7f} < {TAU_INV} (11.1)") # --- the choice of b (Section 9.1 and the proof of Theorem 2.3): k a_*(b) + b/tau_k >= k c_Theta log(u_Theta/tau_k), with equality for b = k c_Theta tau_k okb = True for (k, Th) in [(37, 37/16), (100, 5.0), (1000, 0.9*a_k(1000)), (5000, 0.9*a_k(5000)), (10**6, 0.9*a_k(10**6))]: c = 2/Th; u = y_k(k, Th)*tau_k(k) # the limits of c_Theta and u_Theta as delta_0, eps_2 -> 0 target = k*c*log(u/tau_k(k)); tol = 1e-9*(1+abs(target)) vals = np.array([k*a_star(k, c, u, float(b)) + float(b)/tau_k(k) for b in b_choice(k, c)*np.exp(np.linspace(-6, 6, 2401))]) okb = okb and bool(np.all(vals >= target - tol)) and abs(k*a_star(k, c, u, b_choice(k, c)) + b_choice(k, c)/tau_k(k) - target) < tol \ and abs(k*W_k(k, Th) - target) < tol and abs(a_star(k, c, u, b_choice(k, c)) - c*(log(y_k(k, Th)) - 1)) < 1e-12 check(okb and all(4.19*k >= 4*k+1 for k in range(37, 10**5)) and 2+log(9) > 4.19 and 2+log(9)-1 > 3, "k a_*(b) + b/tau_k >= k c_Theta log(u_Theta/tau_k) for all b > 0, with equality at b = k c_Theta tau_k, where a_* = c_Theta(log(u_Theta/tau_k) - 1);" " Psi(1/10) > 4.19, 4.19 k >= 4k+1 (Section 9.1)") # --- worked example of Section 10.2 k, Th = 37, 37/16 print(f" example k = 37, Theta = 37/16: C(h_k) = {Cfun(h_k(k)):.5f}, T = {T(Th):.5f}, R_k = {R_k(k, Th):.5f}, y_k = {y_k(k, Th):.5f}," f" W_k = {W_k(k, Th):.5f}, B = {bound(k, Th):.5f}, floor(37 B) = {floor(k*bound(k, Th))}") check(abs(Cfun(h_k(37)) - 6.557891) < 5e-7 and abs(T(Th) - 0.811014) < 5e-6 and abs(R_k(37, Th) - 0.214889) < 5e-6 and abs(y_k(37, Th) - 10.0657) < 5e-5 and abs(W_k(37, Th) - 1.997088) < 5e-6 and floor(37*bound(37, Th)) == 273 and abs(T(Th) - (LAMBDA_LO - log(2)/3 - log(25/9)/4 + log(50*sigma(Th)/(4-14*sigma(Th)))/4)) < 1e-12 and abs(sigma(Th) - 27/224) < 1e-15 and abs(R_k(37, Th) - (4/37*log(149/112) + 4/9*log(28/19) + 8/37*log(19/18))) < 1e-12, "the example k = 37 of Section 10.2: C(1/5) = 6.55789, T = 0.81101, R_k = 0.21489, y_k = 10.0657, W_k = 1.99709, floor(37 B) = 273") # --- Proposition 10.5 and Table 3 tab = {} for k in range(37, KNUM+1): Th = Theta_sharp(k); v = bound(k, Th) assert v is not None, (k, Th) tab[k] = (Th, v) G = {k: floor(k*tab[k][1]) for k in tab} # G(k) <= G[k] frac_hi = min(1 - (k*tab[k][1] - G[k]) for k in tab); frac_lo = min(k*tab[k][1] - G[k] for k in tab) check(all(admissible(k, Theta_sharp(k)) for k in range(37, KNUM+1)) and frac_hi > 1e-6 and frac_lo > 1e-6, f"Theta^sharp(k) is admissible for 37 <= k <= {KNUM}; the distance of k B^sharp(k) from the nearest integer is at least {min(frac_hi, frac_lo):.1e} in all cases") print(" Table 3: k Theta B floor(kB) (1.1)") for k in TAB3_K: print(f" {k:8d} {tab[k][0]:8.4f} {tab[k][1]:.4f} {G[k]:8d} {BW(k):9d}") big = {} for k in [10**4, 10**5, 10**6]: Th = Theta_sharp(k); v = bound(k, Th); big[k] = v print(f" {k:8d} {Th:8.3f} {v:.4f} {floor(k*v):8d} {BW(k):9d} (Theta = Theta^sharp(k) = (9/10) a_k; fractional part of kB: {k*v-floor(k*v):.4f})") check((floor(10**4*big[10**4]), floor(10**5*big[10**5]), floor(10**6*big[10**6])) == (63324, 631864, 6314859), "Table 3 for k = 10^4, 10^5, 10^6: 63324, 631864, 6314859") def last_fail(pred, lo=37): bad = [k for k in range(lo, KNUM+1) if not pred(k)] return (bad[-1]+1) if bad else lo kmax = max(tab, key=lambda j: tab[j][1]) check(kmax == 37 and tab[37][1] < 7.3898 and all(tab[k][1] < 7.3567 for k in range(38, KNUM+1)), f"Proposition 10.5(i): max of B^sharp over 37 <= k <= {KNUM} is {tab[37][1]:.5f} (k = 37) < 7.3898; B^sharp(k) <= {max(tab[k][1] for k in range(38, KNUM+1)):.5f} < 7.3567 for k >= 38") k7 = last_fail(lambda k: tab[k][1] < 7); k65 = last_fail(lambda k: G[k] < 6.5*k); k64 = last_fail(lambda k: G[k] < 6.4*k) k65B = last_fail(lambda k: tab[k][1] < 6.5) check(k7 == 76 and k65 == 243 and k64 == 806 and max(tab[k][1] for k in range(76, KNUM+1)) < 6.9895 and min(6.5*k - G[k] for k in range(243, KNUM+1)) >= 0.5 and min(6.4*k - G[k] for k in range(806, KNUM+1)) >= 0.2 - 1e-9, f"Proposition 10.5(ii): B^sharp(k) < 7 for {k7} <= k <= {KNUM} (max {max(tab[k][1] for k in range(76, KNUM+1)):.5f}, at k = 76), not for k = {k7-1};" f" floor(k B^sharp(k)) < 6.5 k for {k65} <= k <= {KNUM}, not for k = {k65-1}; < 6.4 k for {k64} <= k <= {KNUM}, not for k = {k64-1}" f" (B^sharp < 6.5 from k = {k65B})") ex = {k: (G[k]-C0_LO*k)/sqrt(k) for k in tab} kex = max(ex, key=lambda j: ex[j]) k4 = last_fail(lambda k: ex[k] < 4); k3 = last_fail(lambda k: ex[k] < 3) kex4 = max(range(132, KNUM+1), key=lambda j: ex[j]); kex3 = max(range(215, KNUM+1), key=lambda j: ex[j]) check(kex == 63 and ex[kex] < 6.585 and G[63] == 450 and k4 == 132 and ex[kex4] < 3.9736 and k3 == 215 and ex[kex3] < 2.9889, f"Proposition 10.5(iii): max of (floor(k B^sharp) - C_0 k)/sqrt(k) over 37 <= k <= {KNUM} is {ex[kex]:.4f} (k = {kex}) < 6.585" f" [C_0 k + 7 sqrt k - floor(k B^sharp) >= {min(C0_LO*k+7*sqrt(k)-G[k] for k in tab):.3f}];" f" it is < 4 for {k4} <= k <= {KNUM} (max {ex[kex4]:.4f} at k = {kex4}), not for k = {k4-1};" f" it is < 3 for {k3} <= k <= {KNUM} (max {ex[kex3]:.4f} at k = {kex3}), not for k = {k3-1}; value at k = {KNUM}: {ex[KNUM]:.4f}") m4 = min(C0_LO*k+4*sqrt(k)-G[k] for k in range(132, KNUM+1)); m65 = min(6.5*k-G[k] for k in range(243, KNUM+1)) m7 = min(C0_LO*k+7*sqrt(k)-G[k] for k in tab); m3 = min(C0_LO*k+3*sqrt(k)-G[k] for k in range(215, KNUM+1)) m64 = min(6.4*k-G[k] for k in range(806, KNUM+1)) mB = min(7.3898 - tab[37][1], min(7.3567 - tab[k][1] for k in range(38, KNUM+1)), min(7 - tab[k][1] for k in range(76, KNUM+1))) check(min(m4, m65, m7, m3, m64) >= 0.16 and mB >= 4e-5 and all(Theta_sharp(k) == 0.9*a_k(k) for k in range(252, 20000)) and all(Theta_sharp(k) == Theta_max(k) <= 0.9*a_k(k) for k in range(37, 253)) and abs(0.9*a_k(252) - 12.6) < 1e-12, f"margins: the bounds for B^sharp in Proposition 10.5(i), (ii) hold with a margin of at least {mB:.1e}; C_0 k + 7 sqrt k - G >= {m7:.3f}," f" C_0 k + 4 sqrt k - G >= {m4:.3f} (k >= 132), C_0 k + 3 sqrt k - G >= {m3:.3f} (k >= 215), 6.5 k - G >= {m65:.1f} (k >= 243)," f" 6.4 k - G >= {m64:.1f} (k >= 806); Theta^sharp(k) = Theta_max(k) = k/20 for 63 <= k <= 252 and = (9/10) a_k for k >= 252 (both 12.6 at k = 252)") check(all(Theta_max(k) >= 37/16 for k in range(37, 20000)) and 0.9*a_k(37) > 9/4 and all(abs(a_k(k)*(a_k(k)+4) - k) < 1e-9*k for k in range(37, 20000)), "Theta_max(k) >= 37/16, (9/10) a_37 > 9/4, a_k (a_k + 4) = k (admissibility of Theta^sharp, Section 10.2)") bw36 = max(BW(k)/k for k in range(1, 37)); k36 = max(range(1, 37), key=lambda k: BW(k)/k) check(bw36 < 7.806 and k36 == 36 and BW(36) == 281, f"Theorem 1.2 for k <= 36: max of ceil(k(log k+4.20032))/k = {bw36:.4f} (k = {k36}, bound 281) < 7.81") kbw = last_fail(lambda k: BW(k)-G[k] > k) check(all(G[k] < BW(k) for k in range(37, KNUM+1)) and BW(37)-G[37] == 17 and kbw == 49, f"the bound is smaller than (1.1) for every 37 <= k <= {KNUM}: by 17 at k = 37, by more than k for k >= {kbw}") check((G[37], G[50], G[100], G[1000]) == (273, 353, 680, 6389) and (BW(37), BW(50), BW(100), BW(1000)) == (290, 406, 881, 11109), "examples of Section 1: G(37) <= 273, G(50) <= 353, G(100) <= 680, G(1000) <= 6389; (1.1) gives 290, 406, 881, 11109") # how far is Theta^sharp from the optimum? gap = 0.0; gapN = 0 for k in list(range(37, 1001, 3)) + list(range(1000, KNUM+1, 40)): top = top_admissible(k) best = min(bound(k, float(t)) for t in np.linspace(9/4, top, 1500)) gap = max(gap, tab[k][1]-best); gapN = max(gapN, G[k]-floor(k*best)) check(gap < 1e-4 and gapN <= 1, f"optimising Theta numerically instead of using Theta^sharp lowers B by at most {gap:.1e}, and floor(kB) by at most {gapN}, for 37 <= k <= {KNUM} (sample)") # the derivative of B(k, Theta) with respect to Theta is -(2/Theta^2) log y_k(Theta), and B is continuous in Theta (Remark 10.8) devB = 0.0; jumpB = 0.0; rs = np.random.default_rng(7) for k in (37, 60, 100, 150, 300, 1000, 5000, 10**5): top = top_admissible(k) for Th in rs.uniform(9/4, top, 60): Th = float(Th); hh = 1e-6*Th if any(abs(Th - x) < 3*hh for x in (9/4, 25/8, 7/2, 15/4, 6.0)) or Th + hh > top or Th - hh < 9/4: continue if any(abs(Th - x) < 3*hh for D in range(4, int(Th)+3) for x in (lD(D), rD(D))): continue fdv = (bound(k, Th+hh) - bound(k, Th-hh))/(2*hh) devB = max(devB, abs(fdv + (2/Th**2)*log(y_k(k, Th)))*Th) for x in (9/4, 25/8): if 9/4 <= x*(1-1e-9) and x*(1+1e-9) <= top: jumpB = max(jumpB, abs(bound(k, x*(1+1e-9)) - bound(k, x*(1-1e-9)))) def opt_theta(k): lo, hi = 9/4, top_admissible(k) if y_k(k, hi) >= 1: return hi for _ in range(200): mid = 0.5*(lo+hi) if y_k(k, mid) >= 1: lo = mid else: hi = mid return lo nlow = sum(1 for k in range(37, KNUM+1) if floor(k*bound(k, opt_theta(k))) == G[k]-1) gapo = max(tab[k][1] - bound(k, opt_theta(k)) for k in range(37, KNUM+1)) oko = all(G[k]-1 <= floor(k*bound(k, opt_theta(k))) <= G[k] for k in range(37, KNUM+1)) t6 = opt_theta(10**6) nab = sum(1 for k in range(258, KNUM+1) if y_k(k, Theta_sharp(k)) > 1) # the solution of y_k = 1 exceeds Theta^sharp(k) okab = all(y_k(k, Theta_sharp(k)) > 1 for k in range(391, KNUM+1)) and not y_k(390, Theta_sharp(390)) > 1 oky = all((y_k(k, top_admissible(k)) >= 1) == (k <= 257) for k in range(37, KNUM+1)) and all(top_admissible(k) == Theta_sharp(k) for k in range(37, 253)) check(devB < 1e-5 and jumpB < 1e-7 and oko and oky and nab == 4733 and okab and nlow == 80 and 0 <= gapo < 7.4e-5 and abs(t6 - 903.00) < 5e-3 and floor(10**6*bound(10**6, t6)) == 6314859, f"Remark 10.8: dB/dTheta = -(2/Theta^2) log y_k(Theta) (finite differences, deviation {devB:.1e}), B is continuous in Theta (jumps {jumpB:.1e});" f" the least value of B(k,.) is attained at the largest admissible Theta for k <= 257 (it is Theta^sharp(k) for k <= 252) and where y_k = 1 for k >= 258" f" (for 258 <= k <= {KNUM} this point exceeds Theta^sharp(k) for {nab} of the {KNUM-257} values of k, among them all k >= 391):" f" it is smaller than B^sharp(k) by at most {gapo:.1e}," f" and the integer is floor(k B^sharp) - 1 for {nlow} values of k <= {KNUM}, floor(k B^sharp) otherwise; k = 10^6: Theta = {t6:.2f} gives the same integer") # --- Proposition 10.6: k >= KNUM, Theta = (9/10) a_k Lc = log(19*TAU_INV/162) ks = np.unique(np.concatenate([np.arange(KNUM, 30001), np.exp(np.linspace(log(3e4), log(1e12), 20000))])) ok = True; slack = [1e9, 1e9, 1e9] for k in ks: k = float(k); K = sqrt(k); a = a_k(k); Th = 0.9*a if not (admissible(k, Th) and Th > 6 and K-2 < a < K-1.9717 and a > 68.71): ok = False; print(' fails at', k); break s1 = (-(40/9)*K + C_T) - (-2*k*T(Th)) s2 = (2*K*log(19) + 4*log(k) + C_R) - 2*k*R_k(k, Th) yp = (19*TAU_INV/162)*(1 + (170/171)/(a + 10/9)) s3 = ((20/9)*Lc*K + C_W) - k*W_k(k, Th) e1 = abs((1-eta_k(Th, k)) - (19*a+40)/(100*(a+4))) # 1 - eta_k(Theta) = (19a+40)/(100(a+4)) e2 = abs(4*k/(Th+1.25) - (40/9)*(a + 47/18 - (1175/324)/(a + 25/18)))/k # 4k/(Theta+5/4) e3 = abs(2*k*R_k(k, Th) - (2*k*R_k(k, 6.0) + 8*log(Th/6) + 2*(a+4)*log(10*(1-6/a)) + 2*a*log(1.9*(1-(150/19)/(a+10)))))/k if not (min(s1, s2, s3) >= 0 and y_k(k, Th) <= yp*(1+1e-12) and max(e1, e2, e3) < 1e-11): ok = False; print(' fails at', k, s1, s2, s3, e1, e2, e3); break slack = [min(slack[0], s1), min(slack[1], s2), min(slack[2], s3)] tot = 12 + C_T + C_R + C_W elem = (80/9 - 1880/162 + 0.23 < C_T and (47000/2916)/(68.71 + 25/18) < 0.23 and 2*KNUM*R_k(KNUM, 6.0) < 32.28 and 8*log(0.15) < -15.17 and 8*log(10) - 12 < 6.43 and (300/19)*68.71/78.71 > 13.78 and 3.94*log(19) > 11.60 and 32.28 - 15.17 + 6.43 - 13.78 - 11.60 <= C_R + 1e-12 and (20/9)*(Lc*(4 - 1.9717) + 170/171 + (680/171)/68.71) < C_W and sqrt(KNUM) - 2 > 68.71 and 2 - 2/sqrt(KNUM) > 1.9717) check(ok and elem and tot < 11 and abs(C3-1.57146) < 1e-5 and C3 < 1.572, f"Proposition 10.6: for k >= {KNUM} and Theta = (9/10) a_k: -2kT <= -(40/9) sqrt k {C_T:+}, 2k R_k <= 2 sqrt k log 19 + 4 log k {C_R:+}," f" k W_k <= (20/9) log(19 D/162) sqrt k + {C_W} ({len(ks)} values of k up to 1e12, least slacks {slack[0]:.3f}, {slack[1]:.3f}, {slack[2]:.3f});" f" the elementary inequalities of the proof hold; constants add up to {tot:.3f} < 11; coefficient of sqrt k: c_3 = {C3:.5f} < 1.572") Kg = np.exp(np.linspace(log(sqrt(KNUM)), log(1e15), 200001)) check(bool(np.all(1.572*Kg + 8*np.log(Kg) + 11 < 2.5*Kg)) and 0.928 - 8/sqrt(KNUM) > 0 and C0 + 2.5/sqrt(KNUM) < 6.36, f"1.572 sqrt k + 4 log k + 11 < 2.5 sqrt k for k >= {KNUM} (hence G(k) < C_0 k + 2.5 sqrt k < 6.36 k there)") kR6 = [k*R_k(k, 6.0) for k in np.exp(np.linspace(log(KNUM), log(1e12), 2001))] kR6s = [k*R_k(k, 6.0) for k in 60 + np.exp(np.linspace(log(1e-6), log(KNUM - 60), 4001))] # 60 < k <= KNUM check(max(kR6) < 16.14 and kR6[0] == max(kR6) and all(np.diff(kR6) < 1e-9) and all(np.diff(kR6s) < 1e-9) and kR6s[-1] >= kR6[0] - 1e-9, f"k R_k(6) <= {max(kR6):.4f} < 16.14 for k >= {KNUM}, and k R_k(6) is decreasing in k for k > 60 (grid; at k = 60 + 1e-6 it is {kR6s[0]:.1f}) (Lemma 10.4)") # --- Theorem 1.3 (almost all natural numbers). For Theta = Theta^sharp(k) the number Y of the proof of Theorem 2.3 is # k B^sharp(k) - 1, and the least integer l with 2l > Y is admissible in Theorem 2.4 Yv = {k: k*tab[k][1] - 1 for k in tab} Gp = {k: floor(Yv[k]/2) + 1 for k in tab} BWp = lambda k: ceil(0.5*k*(log(k) + 4.20032)) # the bound of [BW2023, Theorem 9.1] exq = max((Gp[k] - C0_LO*k/2)/sqrt(k) for k in tab) pw2 = [k for k in tab if k & (k-1) == 0] check(all(Gp[k] == (G[k]+1)//2 for k in tab) and all(Yv[k] < 7.39*k for k in tab) and all(G[k] <= C0_LO*k + 6.59*sqrt(k) for k in tab) and all(2.09*k < Gp[k] < 4*k for k in tab) and 0.205*sqrt(37) > 0.5 and exq < 3.34 and min(C0_LO*k/2 + 3.5*sqrt(k) - Gp[k] for k in tab) > 1.08, f"Theorem 1.3 for 37 <= k <= {KNUM}: the least l with 2l > Y is ceil(floor(k B^sharp)/2); Y < 7.39 k; 2.09 k < l < 4k;" f" l < C_0 k/2 + 3.5 sqrt k (largest value of (l - C_0 k/2)/sqrt k: {exq:.4f})") check((Gp[37], Gp[50], Gp[100], Gp[1000]) == (137, 177, 340, 3195) and (BWp(37), BWp(50), BWp(100), BWp(1000)) == (145, 203, 441, 5555) and pw2 == [64, 128, 256, 512, 1024, 2048, 4096] and [Gp[k] for k in pw2] == [228, 427, 831, 1646, 3271, 6515, 12996] and all(Gp[k] < BWp(k) for k in tab), "Theorem 1.3, examples: G^+(37) <= 137, G^+(50) <= 177, G^+(100) <= 340, G^+(1000) <= 3195, where [BW2023, Theorem 9.1] gives" " 145, 203, 441, 5555; powers of 2: l = 228, 427, 831, 1646, 3271, 6515, 12996 for k = 64, 128, ..., 4096 (to be compared with 4k)") totp = 11 + C_T + C_R + C_W okp = all(floor((float(k)*bound(float(k), 0.9*a_k(float(k))) - 1)/2) + 1 <= C0_LO*float(k)/2 + 0.786*sqrt(float(k)) + 2*log(float(k)) + 6 for k in ks[::25]) check(totp < 10 and C3/2 < 0.786 and 10/2 + 1 <= 6 and okp and bool(np.all(0.786*Kg + 4*np.log(Kg) + 6 < 3.5*Kg)) and bool(np.all(C0*Kg*Kg + 2.5*Kg < 8*Kg*Kg)), f"Theorem 1.3 for k >= {KNUM}: Y <= C_0 k + c_3 sqrt k + 4 log k + 10 (constants add up to {totp:.2f});" f" floor(Y/2) + 1 <= C_0 k/2 + 0.786 sqrt k + 2 log k + 6 < C_0 k/2 + 3.5 sqrt k (also compared with the exact values" f" at {len(ks[::25])} values of k); Y < C_0 k + 2.5 sqrt k < 8k") small = {k: BWp(k) for k in range(1, 37)} check(all(small[k] < 4*k for k in small) and max(small[k]/k for k in small) == 141/36 == 47/12 and all(Gp[k] <= (7.39*k + 1)/2 < 4*k for k in tab) and C0/2 + 3.5/sqrt(KNUM) < 4, f"G^+(k) <= 4k for every k that is not a power of 2: ceil(k(log k + 4.20032)/2) < 4k for k <= 36 (largest ratio 47/12, at k = 36);" f" l <= (7.39 k + 1)/2 < 4k for 37 <= k <= {KNUM}; C_0 k/2 + 3.5 sqrt k < 4k for k >= {KNUM}") # --- Corollary 2.6 (the mean value estimate of Theorem 2.5 with s_1 = A_1 k + A_2 sqrt k for k >= k_1): what is needed is s_1 > Y cols = [(37, 7.39, 0), (37, C0_LO, 7), (76, 7, 0), (132, C0_LO, 4), (215, C0_LO, 3), (243, 6.5, 0)] okc = all(Yv[k] < A1*k + A2*sqrt(k) for (k1, A1, A2) in cols for k in tab if k >= k1) Kh = np.exp(np.linspace(log(sqrt(12500)), log(1e15), 100001)) check(okc and C0 + 2.5/sqrt(KNUM) < 6.36 and C3 < 1.572 and bool(np.all(1.572*Kh + 8*np.log(Kh) + 10 < 2*Kh)) and 0.428*sqrt(12000) < 4*log(12000) + 10 and phi_as(0.90478) < 1.5712, f"Corollary 2.6: Y < A_1 k + A_2 sqrt k for k_1 <= k <= {KNUM} and (k_1, A_1, A_2) = (37, 7.39, 0), (37, C_0, 7), (76, 7, 0), (132, C_0, 4)," f" (215, C_0, 3), (243, 6.5, 0); for k >= {KNUM}: Y <= C_0 k + 1.572 sqrt k + 4 log k + 10 < C_0 k + 2.5 sqrt k < 6.36 k," f" and < C_0 k + 2 sqrt k for k >= 12500 (the analytic bound does not give this for k = 12000); phi(0.90478) = {phi_as(0.90478):.6f} < 1.5712") # --- Theorems 1.5 and 2.7, Proposition 11.7 (fractional parts). E^sharp(k) = 2 s_0 + (1 + b) 4.5139505 k with Theta = Theta^sharp(k), # b = 4/(9.027901 Theta), and s_0 >= 5k/2 least with 2 s_0 > Y - 2 chi_0 k/Theta; thus E^sharp(k) = 2 s_0 + 4.5139505 k + 2k/Theta fr = {k: frac_exponent(k, tab[k][0], b_sharp(tab[k][0])) for k in tab} Es = {k: fr[k][0] for k in tab} BW25 = lambda k: k*(log(k) + 8.02113) # [BW2025, Theorem 1.2] dist = min(min(fr[k][2]/2 - floor(fr[k][2]/2), floor(fr[k][2]/2) + 1 - fr[k][2]/2) for k in tab) check(abs(CHI0 - 1.6931472) < 1e-7 and C0 + TAU_INV/2 < CF and abs(C0 + TAU_INV/2 - 10.827185) < 1e-6 and all(abs(fr[k][2] - (Yv[k] - 2*CHI0*k/tab[k][0])) < 1e-9 for k in tab) and all(fr[k][1] == floor(fr[k][2]/2) + 1 > 2.5*k for k in tab) and all(abs(Es[k] - (2*fr[k][1] + 4.5139505*k + 2*k/tab[k][0])) < 1e-8 for k in tab) and all(abs(Es[k] - E_sharp(k)) < 1e-12 for k in (37, 100, 1000, 5000)) and dist > 1e-6, f"Section 11.3: chi_0 = 1 + log 2 = {CHI0:.7f}, C_0 + 4.5139505 = {C0 + TAU_INV/2:.6f} < {CF}; for 37 <= k <= {KNUM} the number s_0^sharp(k)" f" is floor(y/2) + 1 > 5k/2, where y = Y - 2 chi_0 k/Theta^sharp, and y/2 has distance at least {dist:.1e} from the integers;" f" E^sharp(k) = 2 s_0^sharp(k) + 4.5139505 k + 2k/Theta^sharp(k)") exf = {k: (Es[k] - CF*k)/sqrt(k) for k in tab} kxf = max(exf, key=lambda j: exf[j]) k2f = last_fail(lambda k: exf[k] < 2); k11 = last_fail(lambda k: Es[k] < 11*k) m35 = min(CF*k + 3.5*sqrt(k) - Es[k] for k in tab); m2 = min(CF*k + 2*sqrt(k) - Es[k] for k in tab if k >= 112) m1133 = min(11.33*k - Es[k] for k in tab); m11 = min(11*k - Es[k] for k in tab if k >= 116) mbw = min((BW25(k) - 11 - Es[k], k) for k in tab) x112 = max((exf[k], k) for k in tab if k >= 112); r1133 = max((Es[k]/k, k) for k in tab) check(kxf == 65 and 3.1800 < exf[65] < 3.1801 and k2f == 112 and k11 == 116 and Es[115] > 11*115 and m35 > 2 and m2 > 0 and m1133 > 0.18 and m11 > 0 and mbw[0] > 0.36 and mbw[1] == 37 and r1133[1] == 37 and 11.3247 < r1133[0] < 11.3248, f"Proposition 11.7(i): the largest value of (E^sharp(k) - {CF} k)/sqrt k for 37 <= k <= {KNUM} is {exf[kxf]:.5f} (k = {kxf}) < 3.5;" f" for 112 <= k <= {KNUM} it is {x112[0]:.5f} (k = {x112[1]}) < 2, but not for k = 111; the largest E^sharp(k)/k is {r1133[0]:.5f} (k = {r1133[1]}) < 11.33;" f" E^sharp(k) < 11k for k >= {k11}, and E^sharp(115) > 11*115; k(log k + 8.02113) - 11 - E^sharp(k) >= {mbw[0]:.3f} (k = {mbw[1]});" f" margins: {m35:.2f}, {m2:.2f}, {m1133:.2f}, {m11:.2f}") print(" Table 4: k Theta^sharp b^sharp 2 s_0^sharp E^sharp(k) k(log k+8.02113) 9.028 k") t4 = {} for k in [37, 46, 50, 100, 200, 500, 1000, 2000, 5000, 10**4, 10**5, 10**6]: Th = Theta_sharp(k); e = frac_exponent(k, Th, b_sharp(Th)); t4[k] = e print(f" {k:8d} {Th:9.4f} {b_sharp(Th):.5f} {2*e[1]:10d} {e[0]:13.2f} {BW25(k):13.2f} {9.028*k:11.1f}") check([2*t4[k][1] for k in (37, 46, 50, 100, 200, 500, 1000, 2000, 5000, 10**4, 10**5, 10**6)] == [220, 274, 298, 612, 1238, 3124, 6262, 12550, 31436, 62940, 630668, 6311090] and [round(t4[k][0], 2) for k in (37, 46, 50, 100, 200, 500, 1000, 2000, 5000)] == [419.02, 513.64, 555.70, 1103.40, 2180.79, 5435.31, 10850.81, 21681.83, 54167.39] and [round(t4[k][0], 2) for k in (10**4, 10**5, 10**6)] == [108306.22, 1082770.24, 10827267.17] and t4[100][0] < 1104 and t4[1000][0] < 10851 and 1262.6 < BW25(100) < 1262.7 and 14928.8 < BW25(1000) < 14928.9 and abs(TAU_INV/2 - 4.5139505) < 1e-12, "Table 4 and the examples of Section 1: E^sharp(100) < 1104, E^sharp(1000) < 10851; 100(log 100 + 8.02113) = 1262.6...," " 1000(log 1000 + 8.02113) = 14928.8...") # Proposition 11.7(ii), k >= KNUM: the elementary inequalities of the proof, and the bound compared with the exact values Kq = sqrt(KNUM) el = (C0 - 5 > 1.31 and 2*CHI0*(10/9) < 3.77 and 3.77*(Kq + 2.03) < 0.06*KNUM and C0*KNUM - 0.06*KNUM > 5*KNUM + 1 and (20/9)*log(2) > 1.5403 and 1.5403*2 > 3.08 and C3 - 1.5403 < 0.04 and 12 - 3.08 < 9 and all(sqrt(k) - 2 < a_k(k) < sqrt(k) - 1.9717 and 0.9*a_k(k) == Theta_sharp(k) for k in (5000, 10**4, 10**6, 10**9)) and bool(np.all(0.04*Kg + 8*np.log(Kg) + 9 < 2*Kg)) and CF + 2/Kq < 11 and log(KNUM) + 8.02113 > 16) slk = [CF*k + 0.04*sqrt(k) + 4*log(k) + 9 - E_sharp(float(k)) for k in ks] check(el and min(slk) > 0, f"Proposition 11.7(ii): the elementary inequalities of the proof; E^sharp(k) < {CF} k + 0.04 sqrt k + 4 log k + 9 at {len(ks)} values of k" f" between {KNUM} and 1e12 (least slack {min(slk):.1f}); 0.04 sqrt k + 4 log k + 9 < 2 sqrt k, {CF} k + 2 sqrt k < 11 k and" f" < k(log k + 8.02113) for k >= {KNUM}") # --- Proposition 10.7: the function phi lg = np.linspace(0.3, 0.995, 139001); pv = np.array([phi_as(float(l)) for l in lg]); i0 = int(np.argmin(pv)) lam0 = sqrt(TAU_INV/(TAU_INV+2)); c2 = -4/lam0 + 2*log((1+lam0)/(1-lam0)) dphi = lambda l: -(2/(l*l))*log(TAU_INV*(1-l*l)/(2*l*l)) # the derivative of phi devd = max(abs((phi_as(l+1e-6)-phi_as(l-1e-6))/2e-6 - dphi(l)) for l in np.linspace(0.31, 0.99, 69)) check(abs(pv[i0]-c2) < 1e-9 and abs(lg[i0]-lam0) < 1e-4 and abs(c2-1.57112) < 1e-5 and abs(lam0-0.90478) < 1e-5 and abs(phi_as(lam0)-c2) < 1e-12 and abs(phi_as(0.9)-C3) < 1e-12 and devd < 1e-6 and all(dphi(l) < 0 for l in lg if l < lam0-1e-9) and all(dphi(l) > 0 for l in lg if l > lam0+1e-9), f"Proposition 10.7: phi' = -(2/lambda^2) log(D(1-lambda^2)/(2 lambda^2)); min of phi = {pv[i0]:.5f} at lambda_0 = sqrt(D/(D+2)) = {lam0:.5f};" f" phi(9/10) = c_3 = {phi_as(0.9):.5f} < 1.572") rows = [] for lam in (0.5, 0.75, 0.9, lam0, 0.95): vals = [k*bound(k, lam*sqrt(k)) - C0*k - phi_as(lam)*sqrt(k) - 4*log(k) for k in (1e6, 1e8, 1e10)] rows.append((lam, vals)) check(all(-200 < v < 200 for lam, vals in rows for v in vals) and all(abs(vals[2] - vals[1]) < 1 for lam, vals in rows), "k B(k, lambda sqrt k) - C_0 k - phi(lambda) sqrt k - 4 log k stays bounded: " + "; ".join(f"lambda = {lam:.4f}: " + ", ".join(f"{v:.1f}" for v in vals) for lam, vals in rows) + " (k = 1e6, 1e8, 1e10)") # the tabulated potentials of part 4 agree with the closed formula in the limit delta_0, eps_2 -> 0 dvs = []; dvf = [] for (k, Th) in [(40, 2.5), (67, 3.125), (100, 5.0), (150, 7.5), (211, 5.23), (1000, 14.27), (1000, 24.79), (10**4, 87.7)]: P = Pot(k, Th, eps2=1e-8, d0=1e-8, n=200001) dvs.append(((k*bound(k, Th) - 1) - (P.r + P.t))/k) # Y = k B - 1 for b in (b_sharp(Th), 0.01, 0.5, 0.99): # Theorem 2.7: k(calG(u_Theta) + a_*(b)) against its limit dvf.append((frac_exponent(k, Th, b)[2] - k*(P.G0 + a_star(k, P.c, P.uTh, b)))/k) check(min(dvs) >= 0 and max(dvs) < 1e-2, f"the number (9.3), r + t = k(calG(u_Theta)+a_*) + b/tau_k, from the potential tabulated with delta_0 = eps_2 = 1e-8 is at most the number Y" f" in the proof of Theorem 2.3 (slack/k between {min(dvs):.1e} and {max(dvs):.1e})") check(min(dvf) >= 0 and max(dvf) < 1e-2, f"likewise k(calG(u_Theta) + a_*(b)) is at most Y - (2k/Theta)(1 + log(9.027901 Theta b/2)), the number in Theorem 2.7, for b = 4/(9.027901 Theta)," f" 0.01, 0.5, 0.99 (slack/k between {min(dvf):.1e} and {max(dvf):.1e})") # --- R_k: closed form of Lemma 10.4 against Riemann-Stieltjes sums of the definition devR = 0.0 for (k, Th) in [(37, 37/16), (50, 25/8), (61, 3.0), (100, 5.0), (175, 8.75), (400, 9.0), (1000, 23.7), (5000, 53.0), (5000, 61.8), (10**4, 75.0), (10**6, 812.5), (10**6, 898.2)]: tg = np.unique(np.concatenate([np.linspace(1.8, Th, 400001), [x for x in (9/4, 25/8, 6.0) if x < Th], [x*(1+1e-13) for x in (9/4, 25/8) if x*(1+1e-13) < Th]])) psi = np.array([-log1p(-eta_k(float(t), k)) for t in tg]) rs_ = float(np.sum(np.diff(psi)/np.sqrt(tg[:-1]*tg[1:]))) devR = max(devR, abs(rs_-R_k(k, Th))/R_k(k, Th)) check(devR < 1e-6, f"Lemma 10.4: closed form of R_k agrees with Riemann-Stieltjes sums of its definition, also for Theta > 6 (max rel. deviation {devR:.1e})") # --- independent implementation in decimal arithmetic dec = decimal_bounds(list(range(37, KNUM+1)) + [10**4, 10**5, 10**6]) dev = max(abs(float(dec[k]) - tab[k][1]) for k in range(37, KNUM+1)) same = all(int((dec[k]*k).to_integral_value(rounding='ROUND_FLOOR')) == G[k] for k in range(37, KNUM+1)) devbig = max(abs(float(dec[k]) - big[k]) for k in big) samebig = all(int((dec[k]*k).to_integral_value(rounding='ROUND_FLOOR')) == floor(k*big[k]) for k in big) check(dev < 1e-9 and same and devbig < 1e-9 and samebig, f"independent 40-digit implementation of B(k,Theta^sharp(k)), 37 <= k <= {KNUM}: max deviation from double precision {dev:.1e};" f" the integers floor(k B) agree for every k (also for k = 10^4, 10^5, 10^6: deviation {devbig:.1e})") from decimal import Decimal as Dc def s0_dec(k): # s_0^sharp(k) from the decimal values of B tf = Fraction(k, 20) if k >= 63 else min(Fraction(k, 16), Fraction(25, 8)) Thd = min(Dc(tf.numerator)/Dc(tf.denominator), Dc(9)/Dc(10)*((Dc(k+4)).sqrt() - 2)) y = dec[k]*k - 1 - 2*(1 + Dc(2).ln())*k/Thd # chi_0 = 1 + log 2 return max(-((-5*k)//2), int((y/2).to_integral_value(rounding='ROUND_FLOOR')) + 1) check(all(s0_dec(k) == fr[k][1] for k in range(37, KNUM+1)), f"the integers s_0^sharp(k) of Section 11.3 computed from the 40-digit values agree with those above for 37 <= k <= {KNUM}") return tab def decimal_bounds(klist, prec=40, NT=200000): """B(k, Theta^sharp(k)) for the k in klist, written independently of the functions above, directly from Definitions 2.1, 2.2, Theorem 2.3 and Lemmas 10.1-10.4, in decimal arithmetic with `prec` digits. Upper bounds: the series of Lemma 10.2(i) is summed to NT and its tail bounded from the right side.""" from decimal import Decimal as Dc, getcontext from fractions import Fraction as Fr getcontext().prec = prec ln = lambda x: Dc(x).ln() q = lambda a, b: Dc(a)/Dc(b) tau_inv = Dc('9.027901') def sig(th): # Definition 2.1 (sigma = varsigma, Lemma 10.1) if th <= q(3, 2): return (2-th)/2 if th <= q(9, 4): return (3-th)/6 if th <= q(25, 8): return (4-th)/14 if th <= q(7, 2): return (5-th)/30 if th <= q(15, 4): return q(1, 20) n = 4 while not (Dc(n) - q(1, n) <= th < Dc(n+1) - q(1, n+1)): n += 1 return (Dc(n+1)-th)/(Dc(n+1)**2) if th <= q((n+1)**2, n+2) else q(1, (n+1)*(n+2)) terms = [ln(q(n+1, n-1))/Dc(n+1) for n in range(4, NT)] part = sum(terms) prefix = [Dc(0)] for t in terms[:4000]: prefix.append(prefix[-1]+t) # prefix[j] = sum of the terms with 4 <= D < 4+j lo4, hi4 = part + q(2, NT), part + q(1, NT-1) + q(1, NT) # bounds for sum_{D>=4} lam_hi = ln(2)/3 + ln(q(25, 9))/4 + ln(q(7, 5))/5 + hi4 def I_lo(s): # Lemma 10.2, lower bound inc = lambda A, B, s1, s2: ln(s2*(A-B*s1)/(s1*(A-B*s2)))/A if s <= q(1, 20): n = 4 while not (q(1, (n+1)*(n+2)) < s <= q(1, n*(n+1))): n += 1 return lo4 - prefix[n+1-4] + inc(Dc(n+1), Dc(n+1)**2, q(1, (n+1)*(n+2)), s) val = lo4 for (s1, s2, A, B) in [(q(1, 20), q(1, 16), 5, 30), (q(1, 16), q(1, 8), 4, 14), (q(1, 8), q(1, 4), 3, 6)]: if s > s1: val += inc(Dc(A), Dc(B), s1, min(s, s2)) return val def kap(th): if th <= q(9, 4): return Dc(4) if th <= q(25, 8): return Dc(8) return max(Dc(10), th+4) def Rk(k, Th): # Lemma 10.4 t = [q(9, 5), q(9, 4), q(25, 8), Dc(6)]; kp = [Dc(4), Dc(8), Dc(10)] tot = Dc(0) for i in range(1, 4): if t[i-1] < Th: tp = min(t[i], Th) tot += kp[i-1]/k*ln(tp*(k-kp[i-1]*t[i-1])/(t[i-1]*(k-kp[i-1]*tp))) for i in range(1, 3): if t[i] < Th: tot += ln((k-kp[i-1]*t[i])/(k-kp[i]*t[i]))/t[i] if Th > 6: a = (k+4).sqrt()-2 tot += 4/k*ln(Th/6) + ln((a-6)/(a-Th))/a + ln((a+4+Th)/(a+10))/(a+4) return tot out = {} for k in klist: kd = Dc(k) tf = Fr(k, 20) if k >= 63 else min(Fr(k, 16), Fr(25, 8)) # Theta_max(k) wf = Fr(1, 16) if tf <= Fr(25, 8) else Fr(1, 20) assert tf >= Fr(9, 4) and tf <= wf*k # Theta_max(k) <= varpi(Theta_max(k)) k, exactly Th = min(q(tf.numerator, tf.denominator), q(9, 10)*((kd+4).sqrt()-2)) # Theta^sharp(k) assert Th >= q(9, 4) and Th*(Th+4) < kd h = q(36, 5)/(kd-1) C = 2 + 2*lam_hi + ln((45+6*h-h*h)/((1-h)*(5-h))) - q(2, 3)*ln((15+2*h)/(15-3*h)) sg = sig(Th); eta = Th*kap(Th)/kd y = (1-eta)*sg*tau_inv*kd/2 W = (2/Th)*ln(y) out[k] = C - 2*I_lo(sg) + 2*Rk(kd, Th) + W + 1/kd return out def dp(k, Th, h, b, xmin_log=16.0, NL=500, lam_min=1e-11): """V(x,l) = min{ k x, k l Psi(l/x), min_theta max_{mu<=l} [3 l - mu + V(x(1-theta/k), mu)] } on a grid x = exp(-j h), l log-spaced; a step theta = k(1-exp(-n h)) in [9/5, Theta] is allowed iff (1-eta_k(theta)) sigma(theta) >= 2 l/x. Returns min{ r : sup_l V(1,l) - r l <= b } / k.""" lam = np.exp(np.linspace(log(lam_min), 0.0, NL)) steps = [n for n in range(1, 10**6) if 1.8 <= k*(1-np.exp(-n*h)) <= Th] levels = [(1-eta_k(k*(1-np.exp(-n*h)), k))*sigma(k*(1-np.exp(-n*h)))/2 for n in steps] nmax = max(steps); Jx = int(xmin_log/h) buf = np.zeros((nmax+1, NL)) # buf[j] = cummax_{mu<=l} (V_j(mu) - mu) for j in range(Jx+nmax, Jx, -1): buf[j % (nmax+1)] = np.maximum.accumulate(k*np.exp(-j*h)-lam) for j in range(Jx, -1, -1): x = np.exp(-j*h); zz = lam/x with np.errstate(divide='ignore', invalid='ignore'): apr = np.where(zz <= 0.5, k*lam*(2+np.log((1-np.minimum(zz, 0.5))/zz)), np.inf) bestv = np.minimum(k*x, apr) for n, lev in zip(steps, levels): bestv = np.where(zz <= lev, np.minimum(bestv, 3*lam + buf[(j+n) % (nmax+1)]), bestv) bestv = np.minimum.accumulate(bestv[::-1])[::-1] # D_S(X,W) is nondecreasing in W buf[j % (nmax+1)] = np.maximum.accumulate(bestv-lam) return float(np.max((bestv-b)/lam))/k def part6(): print("6. the recursion behind Proposition 8.3 (Section 10.4) solved by dynamic programming, independently of the potential") for (k, Th, h) in [(40, 2.5, 0.0006), (100, 5.0, 0.0005), (250, 12.5, 0.0002)]: b = b_choice(k, 2/Th) rdp = dp(k, Th, h, b); rth = (k*bound(k, Th) - 1 - b/tau_k(k))/k check(rdp <= rth, f"k={k}, Theta={Th:.4f} (mesh {h}), b = {b:.4f}: least r/k admitted by the recursion = {rdp:.4f} <= {rth:.4f} = r/k of Theorem 2.3" f" (t/k = b/(k tau_k) = {b/tau_k(k)/k:.4f})") def part7(): print("7. Section 4: the exponents of Lemmas 4.3 and 4.4 on actual sums (|S| / X^(1-varsigma(U))), a test of the exponent arithmetic") random.seed(5) def expsum(q, m, k, X, a): ns = [n for n in range(1, X+1) if gcd(n, m) == 1] r = np.array([(a*pow(n, k, q)) % q for n in ns], dtype=np.float64)/q return abs(np.exp(2j*np.pi*r).sum()) worst = 0.0; ntests = 0; nkind = {'V': 0, 'M': 0} plist = [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61] while ntests < 400: k = random.choice([9, 11, 13]) primes = [p for p in random.sample(plist, random.choice([1, 2, 3, 4])) if p > k] if not primes: continue m = 1 for p in primes: m *= p es = [random.randint(0, k) for _ in primes] q = 1 for p, ee in zip(primes, es): q *= p**ee if not (10**4 < q < 10**16): continue U = random.choice([1.2, 1.5, 1.8, 2.0, 2.3, 2.7, 3.0, 3.4, 3.9, 4.2, 4.4, 4.8, 5.3, 6.2]) X = int(round(q**(1/U))) if X < 250 or X > 60000: continue Ue = log(q)/log(X) kind, par = branch(Ue) if (kind == 'V' and par > k-2) or (kind == 'M' and par > k-1): continue a = random.randrange(1, q) while gcd(a, q) != 1: a = random.randrange(1, q) ratio = expsum(q, m, k, X, a)/X**(1-varsigma(Ue)) worst = max(worst, ratio); ntests += 1; nkind[kind] += 1 check(worst < 1.0, f"{ntests} sums with k in {{9, 11, 13}}, 250 <= X <= 60000 and 1e4 < q < 1e16 ({nkind['V']} in the range of a part of Lemma 4.3, " f"{nkind['M']} in that of Lemma 4.4): largest |S|/X^(1-varsigma(U)) = {worst:.3f}. At these sizes the savings are small, so that this " "tests the exponent arithmetic rather than the lemmas") def part8(): print("8. Section 12.1: bounds on each residue class with an intermediate coefficient") def per_class(Ug, third=True): """max over D >= 2 and integers r in (U, D] of min{ (D+1-U)/(D+1), U(D+1-r)/(D+1), r-U } / (D(D-1)); third=False drops the term q_r Y^-r""" out = np.zeros_like(Ug) for D in range(2, int(2*Ug.max())+9): lo = np.searchsorted(Ug, max(1.0, (D-8)/2.0)); hi = np.searchsorted(Ug, D+1.0) if hi <= lo: continue U = Ug[lo:hi]; cap = (D+1-U)/(D+1) if third: rstar = 2*U*(D+1)/(D+1+U); v = np.zeros_like(U) for r in (np.floor(U)+1, np.floor(rstar), np.ceil(rstar)): okr = (r > U) & (r <= D) & (r >= 2) v = np.maximum(v, np.where(okr, np.minimum(np.minimum(cap, U*(D+1-r)/(D+1)), r-U), 0.0)) else: v = np.minimum(cap, U*(D-1)/(D+1)) out[lo:hi] = np.maximum(out[lo:hi], v/(D*(D-1))) return out U8 = np.exp(np.linspace(log(1+1e-9), log(600.0), 200001)) vs8 = np.array([varsigma(u) for u in U8]) pp = per_class(U8); pp0 = per_class(U8, third=False) def slow(U): return max(min((D+1-U)/(D+1), U*(D+1-r)/(D+1), r-U)/(D*(D-1)) for D in range(2, int(3*U)+8) for r in range(2, D+1) if r > U) check(all(abs(slow(float(U8[i]))-pp[i]) < 1e-14 for i in np.searchsorted(U8, [1.3, 1.5, 2.2, 3.7, 4.46, 5.345, 8.5, 20.3, 77.7])), "vectorised evaluation agrees with the direct maximum over all (D, r)") rat = pp/vs8 check(not np.any(pp > vs8*(1+1e-12)) and not np.any(pp0 > vs8*(1+1e-9)), f"the saving (12.2) never exceeds varsigma(U) for 1 < U <= 600 (max ratio {rat.max():.4f} at U = {U8[int(np.argmax(rat))]:.3f}); nor when the term q_r Y^-r is dropped") check(rat[U8 >= 2].max() < 0.59 and rat[U8 >= 3.5].max() <= 0.5 and abs(rat[-1]-4/27) < 2e-3, f"ratio <= {rat[U8 >= 2].max():.4f} for U >= 2, <= {rat[U8 >= 3.5].max():.4f} for U >= 7/2, {rat[-1]:.4f} at U = 600 (4/27 = {4/27:.4f})") def const_from(v, U, tail): sg = np.minimum.accumulate(v); lg = np.log(sg) suf = np.concatenate([np.cumsum((-(lg[1:]-lg[:-1])/np.sqrt(U[1:]*U[:-1]))[::-1])[::-1], [0.0]]) + tail zz = sg/2; return float(np.min(2 + np.log((1-zz)/zz) + 2*suf)) def vdc_all(U): b = (2-U)/2 if U < 2 else 0.0; j = 1 while j + 2.0**(-j) <= U: if U < j+2: b = max(b, (j+2-U)/(2**(j+2)-2)) j += 1 return b vdc8 = np.array([vdc_all(float(u)) for u in U8]) # the savings of the two ways of using all residue classes together (Section 12.1), without the rounding of moduli one_prog = lambda U: max([min(U/(D+1), D*(1-U/(D+1)))/(D*(D+1)) for D in range(4, int(U)+3) if U < D+1] + [0.0]) transl = lambda U: max([min(2*U/(D+1), 1.0, D*(1-U/(D+1)))/(D*(D+1)) for D in range(4, int(U)+3) if U < D+1] + [0.0]) v_one = np.maximum(vdc8, np.array([one_prog(float(u)) for u in U8])); v_tr = np.maximum(vdc8, np.array([transl(float(u)) for u in U8])) c_cur = const_from(vs8, U8, 2/600); c_max = const_from(np.maximum(vs8, pp), U8, 2/600) c_rep = const_from(np.maximum(vdc8, pp), U8, 2/600) c_bou = const_from(np.maximum(np.where(U8 < 2, (2-U8)/2, 0.0), pp), U8, 2/600) c_one = const_from(v_one, U8, 2/600) check(abs(c_cur-C0) < 2e-4 and abs(c_max-c_cur) < 1e-12 and abs(c_rep-6.916) < 1e-3 and abs(c_bou-7.404) < 1e-3 and abs(c_one-6.3895) < 2e-4 and float(np.max(np.abs(v_tr - vs8))) < 1e-15, f"constant: {c_cur:.4f} with varsigma; unchanged if (12.1) is added; {c_rep:.4f} if (12.1) replaces Lemma 4.4; {c_bou:.4f} if it also replaces" f" Lemma 4.3(ii); {c_one:.4f} with one progression for each residue class (the first version); varsigma is exactly the largest saving that" " Lemmas 4.3 and 4.4 give when the rounding of moduli is ignored (1 < U <= 600)") def p112(U, D): return max([min(1-U/(D+1), U*(D+1-r)/(D+1), r-U)/(D*(D-1)) for r in range(2, D+1) if r > U] + [0.0]) def l44(U, D): return min(2*U/(D+1), 1.0, D*(1-U/(D+1)))/(D*(D+1)) w3 = min(p112(float(U), D) - l44(float(U), D) for U in np.linspace(1.01, 40, 400) for D in range(int(np.ceil(3*U)), int(3*U)+40)) w2 = min(p112(float(U), D) - l44(float(U), D) for U in np.linspace(1.01, 40, 400) for D in range(max(2, int(np.ceil(2*U))), int(np.ceil(3*U)))) check(w3 > 0 and w2 < 0, f"for a fixed degree D >= 3U the saving (12.2) with the best r exceeds that of Lemma 4.4 with the same D (least difference {w3:.1e}, grid of U <= 40);" f" for 2U <= D < 3U this fails in some cases (least difference {w2:.1e})") def hyp(U): b = varsigma(U) for D in range(4, int(U)+3): if U < D+1: b = max(b, min(1/(D*(D+1)), 0.5*(1-U/(D+1)))) return b c_hyp = const_from(np.array([hyp(float(u)) for u in U8]), U8, 2/600) check(abs(c_hyp - 6.226) < 1e-3, f"(Section 12.2) if the count N in Lemma 4.4 were as small as the pigeonhole principle allows, the constant would be {c_hyp:.4f}") # the constant with the saving of Chow and Dietmann, Lemma 3.1: sigma(theta) = c/theta^2, c = 1/1000 cc = 1e-3 val = min(2 + log((1-z0)/z0) + 4*sqrt(2*z0/cc) for z0 in np.exp(np.linspace(log(1e-9), log(0.4), 200001))) print(f" (with the saving X^(-c/theta^2), c = 1/1000, the constant would be {val:.3f} = 4 + log(8000) = {4+log(8000):.3f})") def part9(): print("9. Section 12.3: the constant in the paper of Chow and Dietmann as written") A0 = 4_000_001; b = A0**-0.5 check(b < 1/2000 and A0 >= 100/b and A0 >= b**-2 - 1e-6, f"A_0 = {A0}, b = A_0^(-1/2) < c/2 = 1/2000; s = 2k + 3 A_0 k + 1 = {2+3*A0} k + 1") def cd_ok(k): L = 3*log(k); U = np.linspace(1.0000001, L, 200001); Dd = np.ceil(4*U) return bool(np.all(U/(2*Dd+1) - Dd*L/k >= 1/12)) and 12*log(k)+2 <= k lo, hi = 10**3, 10**7 while hi-lo > 1: midk = (lo+hi)//2 if cd_ok(midk): hi = midk else: lo = midk check(hi == 122878, f"inequality (3.5) of Chow and Dietmann holds for all U in (1, 3 log k] exactly when k >= {hi}") check(max(BW(k)/k for k in range(1, 67)) <= 8.4 < BW(67)/67, "ceil(k(log k+4.20032)) <= 8.4 k exactly for k <= 66") def _factor(n): """the prime factorisation of a natural number n, as a dict p -> v_p(n) (trial division; n is small here)""" f = {}; p = 2 while p*p <= n: while n % p == 0: f[p] = f.get(p, 0) + 1; n //= p p += 1 if p == 2 else 2 if n > 1: f[n] = f.get(n, 0) + 1 return f def part10(rng): print("10. Section 3: Lemmas 3.1-3.3 on small examples, and the elementary inequalities of their proofs and of (6.1)-(6.3)") from itertools import combinations # --- Lemma 3.1 (divisors in a window): random squarefree R-smooth v >= A_2, with A_2 >= R A_1 ok1 = True; nt = 0 for _ in range(3000): R = int(rng.integers(3, 60)); pr = [p for p in range(2, R+1) if all(p % q for q in range(2, int(p**0.5)+1))] t = int(rng.integers(1, len(pr)+1)); ps = sorted(rng.choice(pr, size=t, replace=False).tolist()) v = 1 for p in ps: v *= p A1 = float(np.exp(rng.uniform(0.01, max(0.02, log(v))))) A2 = R*A1*float(np.exp(rng.uniform(0, 1))) if v < A2: continue divs = [1] for p in ps: divs += [d*p for d in divs] ok1 &= any(A1 <= d <= A2 for d in divs); nt += 1 check(ok1 and nt > 500, f"Lemma 3.1: every squarefree R-smooth v >= A_2 has a divisor in [A_1, A_2] when A_2 >= R A_1 ({nt} random cases)") # --- Lemma 3.2: the constants of the proof, and the bound on small examples with artificial p_0 and R zeta32 = 2.6123753486854883 c = (2**-0.75 < 0.6 and all(-log(1 - x) <= 2.5*x for x in np.linspace(0, 0.6, 6001)) and 1/(1 - 2**-0.75) < 2.5 and exp(2.5*(zeta32 - 1)) < 57 and 57*4 == 228 and all(sum(l**-0.75 for l in range(2, p0+1)) <= 4*p0**0.25 for p0 in range(2, 3000)) and all(sum(w**-0.75 for w in range(1, A)) <= 4*A**0.25 for A in range(1, 3000))) worst = 0.0; nx = 0 for (p0, R, X) in ((3, 30, 3000), (5, 60, 20000), (7, 100, 50000), (2, 13, 10000), (11, 200, 60000)): usable = [p for p in range(p0+1, R+1) if all(p % q for q in range(2, int(p**0.5)+1))] u = np.ones(X+1, dtype=np.int64); smooth = np.ones(X+1, dtype=bool); smooth[0] = False for n in range(2, X+1): f = _factor(n) if max(f) > R: smooth[n] = False; continue for p, e in f.items(): if p in usable and e == 1: u[n] *= p for A in (2, 10, 100, 1000, 10**4): cnt = int(np.sum(smooth[1:] & (u[1:] < A))) bnd = 228*exp(10*p0**0.25)*X**0.75*A**0.25 worst = max(worst, cnt/bnd); nx += 1 check(c and worst < 1, "Lemma 3.2: 2^(-3/4) < 0.6, -log(1-t) <= 2.5t on [0,0.6], 1/(1-2^(-3/4)) < 2.5, e^(2.5(zeta(3/2)-1)) < 57," " sum_{2<=l<=p_0} l^(-3/4) <= 4 p_0^(1/4) and sum_{w R: continue un = 1 for p, e in f.items(): if p in usable and e == 1: un *= p a = Fraction(int(rng.integers(-5, 6)), int(rng.integers(1, 6))) Dn = [d for d in Dset if un % d == 0] if un >= A2: okne &= len(Dn) > 0 coef[n] = (a, un, Dn) # (a): sum over d in D of the coefficient of a_d^* at y = n/d equals a_1(n) for n, (a, un, Dn) in coef.items(): rhs = Fraction(0) for d in Dset: if n % d == 0: y = n//d if gcd(y, d) == 1 and un >= A2: rhs += a/len(coef[n][2]) ok3a &= rhs == (a if un >= A2 else 0); n3 += 1 # (b): 1_{(n,d)>1} = -sum_{e | (n,d), e > 1} mu(e), for squarefree d for _ in range(300): d = 1 for p in rng.choice(usable, size=int(rng.integers(1, 5)), replace=False).tolist(): d *= p n = int(rng.integers(1, X+1)); g = gcd(n, d); ps = list(_factor(g)) s = 0 for t in range(1, len(ps)+1): for comb in combinations(ps, t): s += -(-1)**t ok3b &= (s == (1 if g > 1 else 0)) check(okne and ok3a and ok3b, f"Lemma 3.3: D(n) is not empty when u(n) >= A_2; identity (a) for the coefficients ({n3} integers n, four examples, " "exact rational arithmetic, random coefficients); identity (b) for 1200 pairs (n, d)") # --- the elementary inequalities in the proof of Lemma 6.1 okL = all((1 + 1/L)**floor(L/(6*log(L))) - 1 <= 1 for L in np.exp(np.linspace(log(3.0), log(1e8), 4001))) okr = all(4*th/(1+e2) >= 3 for th in (1.0, 1.5, 2.0) for e2 in (0.0, 0.005, 0.01)) check(okL and okr, "Lemma 6.1: (1 + 1/L)^floor(L/(6 log L)) - 1 <= 1 for all L >= 3 (6.3), and 4 theta/(1 + eps_2) >= 3 for theta >= 1" " and eps_2 <= 1/100 (6.2)") # --- the pigeonhole step (6.5) of the proof of Lemma 6.1: if 0 <= u_d <= 1 and sum u_d/d >= 3/(4W), and # N_W = max{1, ceil(log_2(4 W S_D))}, then sum_{u_d > 2^(-l-1)} 1/d >= 2^l/(2 W N_W) for some 0 <= l < N_W okp = True; ntp = 0 for _ in range(3000): n = int(rng.integers(1, 60)); ds = sorted(set(int(x) for x in rng.integers(2, int(rng.choice([20, 200, 10**4])), size=n))) S = sum(Fraction(1, d) for d in ds); W = max(Fraction(1), Fraction(3, 4)/S*Fraction(int(rng.integers(100, 4000)), 100)) if W < 1 or S < Fraction(3, 4)/W: continue NW = max(1, ceil(log2(float(4*W*S)) - 1e-12)) while 2**NW < 4*W*S: NW += 1 # N_W = ceil(log_2(4 W S)) exactly while NW > 1 and 2**(NW - 1) >= 4*W*S: NW -= 1 mode = int(rng.integers(0, 4)) if mode == 0: u = [Fraction(int(rng.integers(0, 1001)), 1000) for _ in ds] elif mode == 1: u = [Fraction(1, 2**int(rng.integers(0, NW + 3))) for _ in ds] elif mode == 2: u = [Fraction(1, 2**int(rng.integers(0, NW + 1))) - Fraction(1, 10**6) if rng.random() < 0.7 else Fraction(0) for _ in ds] else: u = [Fraction(1) if rng.random() < 0.2 else Fraction(int(rng.integers(0, 101)), 10**4) for _ in ds] u = [max(Fraction(0), min(Fraction(1), x)) for x in u] tot = sum(x/d for x, d in zip(u, ds)) if tot < Fraction(3, 4)/W: # scale up towards the hypothesis, keeping u_d <= 1 c = Fraction(3, 4)/W/tot if tot > 0 else None if c is None: continue u = [min(Fraction(1), x*c) for x in u]; tot = sum(x/d for x, d in zip(u, ds)) if tot < Fraction(3, 4)/W: continue ntp += 1 okp &= any(sum(Fraction(1, d) for x, d in zip(u, ds) if x > Fraction(1, 2**(l + 1))) >= Fraction(2**l)/(2*W*NW) for l in range(NW)) check(okp and ntp > 1000, f"the pigeonhole step (6.5) in the proof of Lemma 6.1, in exact arithmetic: {ntp} random configurations (d, u_d, W) (holds: {okp})") def G_inf(z): """the limit calG_inf of the potential calG of Section 8 as k -> infinity (Sections 2.2 and 11.2): 1/z for z >= 1/2, Psi(z) = 2 + log((1-z)/z) for 1/10 <= z <= 1/2, Psi(1/10) + 2 (I(1/5) - I(2z)) = C_0 - 2 I(2z) for z < 1/10""" if z >= 0.5: return 1/z if z >= 0.1: return 2 + log((1-z)/z) return 2 + log(9) + 2*(I(0.2) - I(2*z)) def fd(v): """the solution d in (0,1] of d + log d = 1 - v; k d is the exponent (7.1) for the moment of order v k of smooth Weyl sums (this is the number written frak_d(vk) in the paper)""" lo, hi = 1e-300, 1.0 for _ in range(300): mid = sqrt(lo*hi) if mid + log(mid) > 1 - v: hi = mid else: lo = mid return hi def part11(): print("11. Section 11: the numbers quoted in Sections 11.1 and 11.2, Remark 11.5 and Proposition 11.6") D = TAU_INV # (a) the end of Section 11.1: the limit k -> infinity xi1 = 1/(1 + 2*C0/D) check(10.82718 < C0 + D/2 < 10.82719 and C0 + D/2 < CF and 0.4169 < xi1 < 0.4170 and 0.30069 < 1 - C0/D < 0.30070 and 12.626468 < 2*C0 < 12.626469 and 2*C0 > D and all(2*tau_k(k) < k/(k+1) for k in (37, 38, 100, 10**6)) and 37*fd(2) > 2 and 16 > D and (1 - 4/D)/2 > fd(2) and 0.00490 < fd(C0) < 0.00491, f"Section 11.1: C_0 + 4.5139505 = {C0 + D/2:.6f}; xi_1 -> 1/(1 + 2 C_0/9.027901) = {xi1:.5f}; the large sieve exponent exceeds tau_k for " f"xi < 1 - C_0/9.027901 = {1 - C0/D:.5f}; C_0 = {C0:.6f}, 2 C_0 = {2*C0:.7f} > 9.027901; proof of Lemma 11.4: 2 tau_k < k/(k+1), delta_* k > 2, 1/(16k) < tau_k, (1 - 4k tau_k)/2 > delta_*; " f"frak_d(C_0 k) = {fd(C0):.6f} (the numbers 0.0049 k of Section 8.2 and Remark 11.8, and 0.00490 of Appendix B)") # (b) Section 11.2: (11.2) and Remark 11.5 tv = tuple(round(2*C0*x/(1-x), 2) for x in (0.05, 0.1, 0.2, 0.3, 0.414)) gv = tuple(round(G_inf(1/(2*C0*h)), 2) for h in (1, 2, 5, 10, 50)) # arcs of height P^h (Remark 11.5) c2 = lambda DD: -4/sqrt(DD/(DD+2)) + 2*log((1+sqrt(DD/(DD+2)))/(1-sqrt(DD/(DD+2)))) check(tv == (0.66, 1.4, 3.16, 5.41, 8.92) and gv == (4.44, 5.01, 5.53, 5.77, 6.08) and (round(c2(8), 3), round(c2(C0), 3), round(c2(4), 3)) == (1.302, 0.766, -0.314) and abs(c2(D) - 1.57112) < 1e-5, f"(11.2): 2 C_0 xi/(1-xi) = {tv} for xi = 0.05, 0.1, 0.2, 0.3, 0.414 (and 2 C_0 = {2*C0:.2f} in the limit xi -> 1/2); " f"calG_inf(1/(2 C_0 h)) = {gv} for h = 1, 2, 5, 10, 50; c_2(8) = {c2(8):.3f}, c_2(C_0) = {c2(C0):.3f}, c_2(4) = {c2(4):.3f}, " f"c_2(9.027901) = {c2(D):.5f} (Remark 11.5)") # the exponent tau(k) of (B1) with the exponents (7.1): max over v of (1 - 2 frak_d(vk))/v^2, by the parametrisation d = 1/om, v = 1 - 1/om + log om gs = (sqrt(5) - 1)/2; a, b = 2.0, 6.0 h = lambda om: (1 - 2/om)/(1 - 1/om + log(om))**2 for _ in range(200): c, d = b - gs*(b - a), a + gs*(b - a) if h(c) > h(d): b = d else: a = c om = (a + b)/2; vbest = 1 - 1/om + log(om); e2 = (1 - 2*fd(2))/4 check(abs(1/h(om) - 9.026725) < 5e-6 and abs(vbest - 1.98464) < 5e-6 and abs(1/e2 - 9.0279002) < 5e-7 and h(om) > e2 and abs(fd(vbest) - 1/om) < 1e-12, f"max over v > 0 of (1 - 2 frak_d(vk))/v^2 = 1/{1/h(om):.7f}, attained at v = {vbest:.6f}; the value at v = 2 is 1/{1/e2:.7f} ([BW2023, Section 7])") # (c) Proposition 11.6, on a grid zs = np.exp(np.linspace(log(1e-9), 0.0, 60001)) Gz = np.array([G_inf(float(z)) for z in zs]) d_inf = lambda v: max(0.0, float(np.max(zs*(Gz - v)))) vc = 1 - 1/9 + log(9) vs = np.linspace(0.05, 7.0, 1391) dFs = np.array([d_inf(float(v)) for v in vs]); dSs = np.array([fd(float(v)) for v in vs]) check(abs(vc - 3.0861) < 1e-4 and max(abs(dFs[i]-dSs[i]) for i in range(len(vs)) if vs[i] <= vc) < 2e-6 and all(0 < dFs[i] < dSs[i] for i in range(len(vs)) if vc + 0.02 < vs[i] < C0 - 0.01) and d_inf(C0) < 1e-9 and all(dFs[i] == 0 for i in range(len(vs)) if vs[i] >= C0) and bool(np.all(np.diff(Gz) <= 1e-12)) and Gz[0] < C0 and C0 - Gz[0] < 1e-3, f"Proposition 11.6(i) on a grid: d_inf(v) = frak_d(vk) for v <= v_c = {vc:.4f}, 0 < d_inf(v) < frak_d(vk) for v_c < v < C_0, d_inf(v) = 0 for v >= C_0; calG_inf < C_0") rF = (1 - 2*dFs)/vs**2; rS = (1 - 2*dSs)/vs**2; hi = vs >= vc check(bool(np.all(rF >= rS - 4e-6)) and float(np.max(rF[hi])) <= 1/vc**2 and 1/vc**2 < 1/9.52 and float(np.max(rF)) <= h(om) + 1e-12 and abs(vs[int(np.argmax(rF))] - vbest) < 0.006, f"Proposition 11.6(ii) on the grid: (1 - 2 d_inf(v))/v^2 >= (1 - 2 frak_d(vk))/v^2, and <= 1/v_c^2 = 1/{vc**2:.3f} for v >= v_c (grid maximum " f"1/{1/float(np.max(rF[hi])):.3f}); with d_inf in place of frak_d the largest value is still the one at v = {vs[int(np.argmax(rF))]:.3f}") dst = fd(2); zst = dst/(1+dst) check(abs(zst - 0.218) < 5e-4 and abs(theta_star(2*zst) - 1.13) < 5e-3 and 2/theta_star(2*zst) > 1/(1-zst), f"after Proposition 11.6: at z = delta_*/(1+delta_*) = {zst:.4f} the largest permitted step is theta*(2z) = {theta_star(2*zst):.3f}, and 2/theta*(2z) > 1/(1-z)") # Appendix A, Section A.8: the analogue of xi_1 with C_0^star is checked in Part 14 def part12(): print("12. Section 9.3: the congruences of Lemma 9.6") okr = True for k in (4, 8, 16, 32, 64, 128): odd4 = {pow(x, k, 4*k) for x in range(1, 8*k+1, 2)}; even4 = {pow(x, k, 4*k) for x in range(2, 8*k+1, 2)} okr &= (odd4 == {1} and even4 == {0}) even8 = {pow(x, k, 8*k) for x in range(2, 16*k+1, 2)} okr &= (even8 == {0}) if k >= 8 else (even8 == {0, 16}) check(okr, "k = 4, 8, ..., 128: x^k = 1 (mod 4k) for odd x and x^k = 0 (mod 4k) for even x; x^k = 0 (mod 8k) for even x when k >= 8" " (for k = 4 the residue 16 modulo 32 occurs)") okd = True; msg = [] for k in (8, 16): q = 8*k res = sorted({pow(x, k, q) for x in range(q)}) reach = {0}; first = {} # reach: the sums of exactly i k-th powers modulo 8k; first[a]: the least such i for i in range(1, 4*k+1): reach = {(a+b) % q for a in reach for b in res} for a in reach: first.setdefault(a, i) okd &= res == [0, 1, 4*k+1] and first[4*k] == 4*k and all(first[j] == j for j in range(1, 4*k)) msg.append(f"k = {k}: the class of 4k = {4*k} modulo {q} needs {first[4*k]} k-th powers") check(okd, "least number of k-th powers whose sum lies in a given class modulo 8k: it is j for the class of j when 1 <= j < 4k; " + "; ".join(msg)) def part13(rng): print("13. Section 9.4 and Theorem 2.5: the lower bound for |f| in the proof of Theorem 2.5, and the exponent rho^dagger") # |F(alpha)| >= #C/2 for |alpha| <= 1/(4 pi P^k), for any set C of natural numbers n <= P ok = True for trial in range(200): k = int(rng.integers(2, 7)); P = int(rng.integers(20, 400)) Cset = np.unique(rng.integers(1, P+1, size=int(rng.integers(5, P)))).astype(float) al = np.linspace(-1, 1, 41)/(4*np.pi*float(P)**k) Fv = np.abs(np.exp(2j*np.pi*np.outer(al, Cset**k)).sum(axis=1)) ok &= bool(np.all(Fv >= 0.5*len(Cset) - 1e-9)) check(ok, "|sum_{n in C} e(alpha n^k)| >= #C/2 for |alpha| <= 1/(4 pi P^k) (200 random sets C in [1, P], 2 <= k <= 6)") # rho^dagger = min{2, (s_1 - k - 5)/(2k)}: > 1.5 when s_1 > 4.19 k (k >= 27), and = 2 when s_1 >= 5k + 5 (remark after Theorem 2.5); # 0 < rho^dagger <= (s_1 - k - 5)/(2k) < (s_1 - 2 floor(k/2) - 4)/(2k) when s_1 > 4k + 1 (Section 9.4, and Theorem A.36(ii)) rho = lambda s1, k: min(Fraction(2), (s1 - k - 5)/Fraction(2*k)) ok1 = all(rho(Fraction(419*k, 100) + Fraction(1, 10**6), k) > Fraction(3, 2) for k in range(27, 20000)) \ and not rho(Fraction(419*26, 100) + Fraction(1, 10**6), 26) > Fraction(3, 2) ok2 = all(rho(Fraction(5*k + 5), k) == 2 for k in range(1, 20000)) ok3 = all(0 < rho(s1, k) <= (s1 - k - 5)/Fraction(2*k) < (s1 - 2*(k//2) - 4)/Fraction(2*k) for k in range(6, 3000) for s1 in (Fraction(4*k + 1) + Fraction(1, 10**6), Fraction(5*k), Fraction(5*k + 5), Fraction(9*k))) # Corollary 2.6: s_1 = A_1 k + A_2 sqrt k >= 5k + 5 in all columns of the table, for k >= k_1 cols = [(37, 7.39, 0), (37, C0_LO, 7), (76, 7, 0), (132, C0_LO, 4), (215, C0_LO, 3), (243, 6.5, 0), (12500, C0_LO, 2)] ok4 = all(A1*k + A2*sqrt(k) >= 5*k + 5 for (k1, A1, A2) in cols for k in (k1, k1 + 1, 2*k1, 10*k1, 10**7)) check(ok1 and ok2 and ok3 and ok4, "rho^dagger > 3/2 when s_1 > 4.19 k, for every k >= 27 (but not for k = 26); rho^dagger = 2 when s_1 >= 5k + 5; " "0 < rho^dagger <= (s_1 - k - 5)/(2k) < (s_1 - 2 floor(k/2) - 4)/(2k) when s_1 > 4k + 1; s_1 >= 5k + 5 in all columns of Corollary 2.6") # ===================================================================================================================== # Appendix A: the mean value with two coefficients, chains, and the improved bounds # ===================================================================================================================== def _require(cond, msg="a hypothesis on which the rigour of a bound depends is not satisfied"): """the hypotheses on which the rigour of a bound depends are enforced by this function and not by assert statements, so that they are tested also when Python is run with the option -O""" if not cond: raise RuntimeError(msg) A_NT = 10**6 _A_D = np.arange(4, A_NT+1, dtype=np.float64) # Lambda_D^star = log((D^2+D+2)(D+1)(D+2)/D^4)/(2(D+1)) (A.1): the tent T_D and the interval of degree D + 1 (prime multipliers); # Lambda_D = log(1 + 2(D+1)/D^2)/(D+1) is the contribution of the tent alone (Proposition A.33) A_CS = np.concatenate([[0.0], np.cumsum(np.log1p((4*_A_D**3 + 7*_A_D**2 + 8*_A_D + 4)/_A_D**4)/(2*(_A_D+1)))]) # A_CS[i] = sum_{4 <= D < 4+i} Lambda_D^star def A_lamsharp_terms(D): """Lambda_D^sharp of (A.1) for an integer D >= 4, exactly, as a list of (c, a, b) with Lambda_D^sharp = sum c log(a/b): the contribution of (1/((D+1)(D+2)), 1/(D(D+1))] to the integral of dt/(t theta^star(t)), where theta^star is given by the interval Q_{D,iota} of Definition A.25(f) above the level t_2 and by the interval of degree D + 1 (prime multipliers) below; iota = 2 for D <= 6, iota = 1 for D >= 8, and for D = 7 first iota = 2 and then iota = 1""" F = Fraction if D == 7: return [(F(53, 432), 53, 47), (F(11, 90), 321, 301), (F(1, 16), 129, 107)] if D <= 6: return [(F(7*D + 4, (D + 1)*(7*D + 5)), (7*D + 4)*(7*D*D + 5*D + 10), D*(7*D + 3)*(7*D - 2)), (F(1, 2*(D + 1)), (7*D + 3)*(D + 2), 7*D*D + 5*D + 10)] return [(F(2*(3*D + 1), 3*(D + 1)*(2*D + 1)), 2*(3*D + 1)*(2*D*D + D + 2), D*(6*D + 1)*(2*D - 1)), (F(1, 2*(D + 1)), (6*D + 1)*(D + 2), 3*(2*D*D + D + 2))] def _A_lamsharp_array(): """the numbers Lambda_D^sharp, 4 <= D <= A_NT, in floating point (log1p of the exact differences a/b - 1)""" D = _A_D out = (2*(3*D + 1)/(3*(D + 1)*(2*D + 1)))*np.log1p((14*D*D + 15*D + 4)/(D*(6*D + 1)*(2*D - 1))) \ + np.log1p((10*D - 4)/(3*(2*D*D + D + 2)))/(2*(D + 1)) for d in (4, 5, 6, 7): out[d - 4] = sum(float(c)*log1p((a - b)/b) for c, a, b in A_lamsharp_terms(d)) return out _A_LSH = _A_lamsharp_array() A_CSS = np.concatenate([[0.0], np.cumsum(_A_LSH)]) # A_CSS[i] = sum_{4 <= D < 4+i} Lambda_D^sharp _A_DLS = np.log1p((4*_A_D**3 + 7*_A_D**2 + 8*_A_D + 4)/_A_D**4)/(2*(_A_D+1)) - _A_LSH # Lambda_D^star - Lambda_D^sharp, 4 <= D <= A_NT A_CQ = np.concatenate([np.cumsum(_A_DLS[::-1])[::-1], [0.0]]) # A_CQ[i] = sum_{4+i <= D <= A_NT} (Lambda_D^star - Lambda_D^sharp) # --- the numbers Lambda_D^dagger of (A.1): the contribution of (1/((D+1)(D+2)), 1/(D(D+1))] to the integral of dt/(t theta^star(t)) # with the numbers (g) of Definition A.25. For 4 <= D <= 14 they come from the pieces of theta^star in A_BAND_PIECES (Table 7), for # D >= 15 from the closed form with N_5(D) = 12D^5 + 52D^4 + 97D^3 + 111D^2 + 64D + 12 and P_2(D) = 6D^2 + 17D + 4: # Lambda_D^dagger = (3D+4)/(6(D+1)(D+2)) log x_1 + 2(3D+1)/(3(D+1)(2D+1)) log x_2, x_1 = P_2 (D+2)^2 (2D+1)(3D+1)/((3D+4) N_5), # x_2 = N_5/(D(D+1)(2D-1) P_2); here x_1 - 1 = 8(9D^5 + 36D^4 + 38D^3 - 3D^2 - 16D - 4)/((3D+4) N_5) and # x_2 - 1 = 2(6D^4 + 39D^3 + 62D^2 + 34D + 6)/(D(D+1)(2D-1) P_2). from fractions import Fraction as _Fr A_BAND_PIECES = { # theta^star on (1/((D+1)(D+2)), 1/(D(D+1))] for 4 <= D <= 14 (Section A.3, Table 7): pieces (t_lo, t_hi, A, B, origin), theta^star = A - B t 4: [(_Fr(1, 30), _Fr(1081, 31800), _Fr(1263, 125), _Fr(756, 5), ('N', 5, 2, 'E7')), (_Fr(1081, 31800), _Fr(1, 27), _Fr(140, 13), _Fr(2220, 13), ('N', 5, 2, 'E5')), (_Fr(1, 27), _Fr(31, 820), _Fr(10), _Fr(150), ('M', 5)), (_Fr(31, 820), _Fr(1, 20), _Fr(165, 32), _Fr(175, 8), ('phi', 4, 2))], 5: [(_Fr(1, 42), _Fr(131, 5436), _Fr(252, 19), _Fr(5733, 19), ('N', 6, 1, 'E5')), (_Fr(131, 5436), _Fr(649, 26376), _Fr(3535, 292), _Fr(18522, 73), ('N', 6, 2, 'E7')), (_Fr(649, 26376), _Fr(991, 37212), _Fr(294, 23), _Fr(6468, 23), ('N', 6, 2, 'E5')), (_Fr(991, 37212), _Fr(1, 30), _Fr(80, 13), _Fr(420, 13), ('phi', 5, 2))], 6: [(_Fr(1, 56), _Fr(535, 29316), _Fr(168, 11), _Fr(5040, 11), ('N', 7, 1, 'E5')), (_Fr(535, 29316), _Fr(505, 27104), _Fr(2356, 167), _Fr(65856, 167), ('N', 7, 2, 'E7')), (_Fr(505, 27104), _Fr(887, 44854), _Fr(784, 53), _Fr(22848, 53), ('N', 7, 2, 'E5')), (_Fr(887, 44854), _Fr(1, 42), _Fr(329, 46), _Fr(1029, 23), ('phi', 6, 2))], 7: [(_Fr(1, 72), _Fr(1223, 85536), _Fr(432, 25), _Fr(16524, 25), ('N', 8, 1, 'E5')), (_Fr(1223, 85536), _Fr(433, 29664), _Fr(6057, 376), _Fr(27216, 47), ('N', 8, 2, 'E7')), (_Fr(433, 29664), _Fr(79, 5182), _Fr(84, 5), _Fr(3132, 5), ('N', 8, 2, 'E5')), (_Fr(79, 5182), _Fr(9, 560), _Fr(90, 11), _Fr(672, 11), ('phi', 7, 1)), (_Fr(9, 560), _Fr(1, 56), _Fr(432, 53), _Fr(3136, 53), ('phi', 7, 2))], 8: [(_Fr(1, 90), _Fr(688, 59805), _Fr(135, 7), _Fr(12825, 14), ('N', 9, 1, 'E5')), (_Fr(688, 59805), _Fr(1949, 165960), _Fr(3785, 209), _Fr(170100, 209), ('N', 9, 2, 'E7')), (_Fr(1949, 165960), _Fr(3583, 296056), _Fr(1260, 67), _Fr(58500, 67), ('N', 9, 2, 'E5')), (_Fr(3583, 296056), _Fr(1, 72), _Fr(459, 50), _Fr(1944, 25), ('phi', 8, 1))], 9: [(_Fr(1, 110), _Fr(139, 14700), _Fr(660, 31), _Fr(38115, 31), ('N', 10, 1, 'E5')), (_Fr(139, 14700), _Fr(361, 37400), _Fr(9251, 460), _Fr(25410, 23), ('N', 10, 2, 'E7')), (_Fr(361, 37400), _Fr(2203, 223956), _Fr(770, 37), _Fr(43560, 37), ('N', 10, 2, 'E5')), (_Fr(2203, 223956), _Fr(1, 90), _Fr(285, 28), _Fr(675, 7), ('phi', 9, 1))], 10: [(_Fr(1, 132), _Fr(841, 106326), _Fr(396, 17), _Fr(27324, 17), ('N', 11, 1, 'E5')), (_Fr(841, 106326), _Fr(2383, 295152), _Fr(5550, 251), _Fr(365904, 251), ('N', 11, 2, 'E7')), (_Fr(2383, 295152), _Fr(1771, 217284), _Fr(616, 27), _Fr(13904, 9), ('N', 11, 2, 'E5')), (_Fr(1771, 217284), _Fr(1, 110), _Fr(693, 62), _Fr(3630, 31), ('phi', 10, 1))], 11: [(_Fr(1, 156), _Fr(1835, 273312), _Fr(936, 37), _Fr(76050, 37), ('N', 12, 1, 'E5')), (_Fr(1835, 273312), _Fr(25, 3648), _Fr(13117, 544), _Fr(31941, 17), ('N', 12, 2, 'E7')), (_Fr(25, 3648), _Fr(788, 114827), _Fr(273, 11), _Fr(21801, 11), ('N', 12, 2, 'E5')), (_Fr(788, 114827), _Fr(1, 132), _Fr(207, 17), _Fr(2376, 17), ('phi', 11, 1))], 12: [(_Fr(1, 182), _Fr(142, 24609), _Fr(273, 10), _Fr(51597, 20), ('N', 13, 1, 'E5')), (_Fr(142, 24609), _Fr(280499, 47909472), _Fr(7651, 293), _Fr(695604, 293), ('N', 13, 2, 'E7')), (_Fr(280499, 47909472), _Fr(1, 156), _Fr(975, 74), _Fr(6084, 37), ('phi', 12, 1))], 13: [(_Fr(1, 210), _Fr(2141, 427140), _Fr(1260, 43), _Fr(137025, 43), ('N', 14, 1, 'E5')), (_Fr(2141, 427140), _Fr(29177, 5773964), _Fr(17655, 628), _Fr(463050, 157), ('N', 14, 2, 'E7')), (_Fr(29177, 5773964), _Fr(1, 182), _Fr(567, 40), _Fr(1911, 10), ('phi', 13, 1))], 14: [(_Fr(1, 240), _Fr(1147, 261000), _Fr(720, 23), _Fr(89280, 23), ('N', 15, 1, 'E5')), (_Fr(1147, 261000), _Fr(430393, 97694100), _Fr(10088, 335), _Fr(241920, 67), ('N', 15, 2, 'E7')), (_Fr(430393, 97694100), _Fr(1, 210), _Fr(1305, 86), _Fr(9450, 43), ('phi', 14, 1))], } A_DBAND = 14 # theta^star is given by A_BAND_PIECES for 4 <= D <= A_DBAND and by two pieces for D > A_DBAND def A_tN_exact(D): """t_D^N = (6D^2+17D+4)/(6D^4+29D^3+57D^2+48D+12) (D >= 15), the point at which the line of N_{D+1,1} meets phi_{D,1}""" return _Fr(6*D*D + 17*D + 4, 6*D**4 + 29*D**3 + 57*D*D + 48*D + 12) def A_thetaN_line(D): """(A, B) with theta = A - B t: the line of N_{D+1,1} (beta = T' - 1, binding term E_5'), D' = D + 1: theta = 3D'(D'+1)(4 - (D'+1)(2D'+1) t)/(6D'+2)""" d = _Fr(D + 1); return 12*d*(d + 1)/(6*d + 2), 3*d*(d + 1)**2*(2*d + 1)/(6*d + 2) def A_lamdag_terms(D): """Lambda_D^dagger for an integer D >= 4, exactly, as a list of (c, x) with Lambda_D^dagger = sum c log x (x rational)""" if D <= A_DBAND: return [(1/A, h*(A - B*l)/(l*(A - B*h))) for l, h, A, B, _ in A_BAND_PIECES[D]] N5 = 12*D**5 + 52*D**4 + 97*D**3 + 111*D**2 + 64*D + 12; P2 = 6*D*D + 17*D + 4 return [(_Fr(3*D + 4, 6*(D + 1)*(D + 2)), _Fr(P2*(D + 2)**2*(2*D + 1)*(3*D + 1), (3*D + 4)*N5)), (_Fr(2*(3*D + 1), 3*(D + 1)*(2*D + 1)), _Fr(N5, D*(D + 1)*(2*D - 1)*P2))] def A_band_pieces(D): """the pieces (t_lo, t_hi, A, B, origin) of theta^star on (1/((D+1)(D+2)), 1/(D(D+1))], D >= 4""" if D <= A_DBAND: return A_BAND_PIECES[D] tN = A_tN_exact(D); a, b = A_thetaN_line(D); d = _Fr(D) return [(_Fr(1, (D + 1)*(D + 2)), tN, a, b, ('N', D + 1, 1, 'E5')), (tN, _Fr(1, D*(D + 1)), 3*(d + 1)*(2*d + 1)/(2*(3*d + 1)), 3*d*(d + 1)**2/(3*d + 1), ('phi', D, 1))] def _A_lamdag_array(): """the numbers Lambda_D^dagger, 4 <= D <= A_NT, in floating point (log1p of the exact differences x - 1)""" D = _A_D N5 = 12*D**5 + 52*D**4 + 97*D**3 + 111*D**2 + 64*D + 12; P2 = 6*D*D + 17*D + 4 y1 = 8*(9*D**5 + 36*D**4 + 38*D**3 - 3*D**2 - 16*D - 4)/((3*D + 4)*N5) y2 = 2*(6*D**4 + 39*D**3 + 62*D**2 + 34*D + 6)/(D*(D + 1)*(2*D - 1)*P2) out = (3*D + 4)/(6*(D + 1)*(D + 2))*np.log1p(y1) + 2*(3*D + 1)/(3*(D + 1)*(2*D + 1))*np.log1p(y2) for d in range(4, A_DBAND + 1): out[d - 4] = sum(float(c)*log1p(float(x - 1)) for c, x in A_lamdag_terms(d)) return out _A_LDG = _A_lamdag_array() A_CSD = np.concatenate([[0.0], np.cumsum(_A_LDG)]) # A_CSD[i] = sum_{4 <= D < 4+i} Lambda_D^dagger _A_DLD = np.log1p((4*_A_D**3 + 7*_A_D**2 + 8*_A_D + 4)/_A_D**4)/(2*(_A_D+1)) - _A_LDG # Lambda_D^star - Lambda_D^dagger A_CQD = np.concatenate([np.cumsum(_A_DLD[::-1])[::-1], [0.0]]) # A_CQD[i] = sum_{4+i <= D <= A_NT} (Lambda_D^star - Lambda_D^dagger) # for D > A_NT: log(1 + 2/D)/(D + 7/6) <= Lambda_D^dagger <= Lambda_D^sharp <= Lambda_D^star <= 2/D^2 (theta^star < D + 7/6 on the band # of D), and log(1 + 2/D)/(D + 7/6) >= 2/D^2 - 13/(3D^3), so that the remainder of the series of the numbers Lambda_D^dagger lies in # [2/(N+1) - 3/N^2, 2/N], N = A_NT A_S4_LO = float(A_CSD[-1]) + 2/(A_NT+1) - 3/A_NT**2 A_S4_HI = float(A_CSD[-1]) + 2/A_NT # the part of Lambda^star that comes from 1/20 < t <= 41/191, as numbers (c, x) with the term c log x (Lemma A.26, (A.1)): one for # each linear piece of theta^star on this range (the sixteen words from BABAABAAA to ABABAAA, omega_3, the interval Q_{3,2} of # Definition A.25(f) and omega_4), in the order of decreasing t A_PIECES_EXACT = [(Fraction(52, 145), Fraction(6232, 5797)), (Fraction(11, 31), Fraction(1309, 1216)), (Fraction(13, 37), Fraction(5708, 5005)), (Fraction(104, 301), Fraction(141440, 132711)), (Fraction(25, 81), Fraction(14167, 13600)), (Fraction(75, 248), Fraction(5275, 5027)), (Fraction(3, 10), Fraction(231, 211)), (Fraction(13, 44), Fraction(51, 49)), (Fraction(75, 256), Fraction(1505, 1377)), (Fraction(57, 196), Fraction(9207, 8815)), (Fraction(26, 93), Fraction(205, 187)), (Fraction(11, 40), Fraction(34, 31)), (Fraction(13, 48), Fraction(382, 325)), (Fraction(52, 197), Fraction(7085, 6494)), (Fraction(11, 42), Fraction(629, 545)), (Fraction(8, 31), Fraction(660, 629)), (Fraction(1, 6), Fraction(34, 33)), (Fraction(25, 168), Fraction(57, 50)), (Fraction(25, 104), Fraction(275, 171)), (Fraction(1, 8), Fraction(25, 22)), (Fraction(4, 35), Fraction(39, 32))] A_PIECES = [float(c)*log(float(x)) for c, x in A_PIECES_EXACT] A_LAMBDA_LO = sum(A_PIECES) + A_S4_LO A_LAMBDA = sum(A_PIECES) + A_S4_HI # upper value of Lambda^star, (A.1) A_C0_LO = 2 + log(341/41) + 2*A_LAMBDA_LO A_C0 = 2 + log(341/41) + 2*A_LAMBDA # upper value of C_0^star, (A.1) A_ZSEED = Fraction(41, 382) # the seed z_k for k >= 5000 (Lemma A.32), the point of the change of regime of C_0^star def A_lam(D): """Lambda_D = log(1 + 2(D+1)/D^2)/(D+1) (the tent T_D alone)""" return log1p(2*(D+1)/D**2)/(D+1) def A_lams(D): """Lambda_D^star = log((D^2+D+2)(D+1)(D+2)/D^4)/(2(D+1)) = Lambda_D^T + Lambda_D^M""" return log1p((4*D**3 + 7*D**2 + 8*D + 4)/D**4)/(2*(D+1)) def A_lamT(D): """Lambda_D^T = log((D^2+D+2)/D^2)/(D+1) (the tent T_D on (1/(D^2+2D+2), 1/(D(D+1))])""" return log1p((D+2)/D**2)/(D+1) def A_tail_lo(n): """lower bound for sum_{D >= n} Lambda_D^star (n >= 67): >= 2/n - 1/(4n^2) - 2/n^3 (proof of Proposition A.33); for n <= A_NT also the partial sum with the remainder >= 2/(N+1) - 2/N^2, and the larger of the two lower bounds is returned""" N = A_NT; asym = 2/n - 1/(4*n*n) - 2/n**3 return max(float(A_CS[-1] - A_CS[n-4]) + 2/(N+1) - 2/N**2, asym) if n <= A_NT else asym A_JMAX = 40 # the greedy intervals I_j of Lemma A.28 are used for 1 <= j <= min{k - 2, A_JMAX} A_D1F = 8 # in Section A.8 the chains begin with a tent T_D1, 3 <= D1 <= A_D1F, or have no tent def A_sj(U, vt, j): """the number s_j(U, vt) of (A.9): the larger of 0 and the least of (U - j vt)/2^(j+1), (j + 2 - U)/(2^(j+2) - 2), 2^(-j-1) and, for j >= 1, (1 - vt)/2^j""" U = np.asarray(U, float) v = np.minimum(np.minimum((U - j*vt)/2.0**(j+1), (j + 2 - U)/(2.0**(j+2) - 2)), 2.0**(-j-1)) if j >= 1: v = np.minimum(v, (1 - vt)/2.0**j) return np.maximum(v, 0.0) def A_saving(U, vt, k, window=14): """The number varsigma^star(U, vartheta) of Definition A.25, from the definition; U is an array. Only the degrees D with |D - U| <= window, and the numbers s_j with j <= A_JMAX, are used, so that the value returned is a lower bound in general.""" U = np.asarray(U, dtype=np.float64) best = np.maximum(1 - U/2, 0.0) for j in range(1, min(k - 2, A_JMAX) + 1): best = np.maximum(best, A_sj(U, vt, j)) D0 = np.floor(U) for off in range(-3, window+1): D = np.minimum(np.maximum(D0+off, 3), k-1); a0 = U/(D+1) E1 = 2*a0-(D-1)*vt; E2 = D-1-(D-2)*a0-(2*D-1)*vt; E3 = (2*D-2)*(1-a0)-(3*D-1)*vt; E4 = D+1-U-D*vt val = np.minimum.reduce([np.ones_like(U), E1, E2, E3, E4])/(D*(D+1)) best = np.maximum(best, np.where(a0 + vt < 1, val, 0.0)) if A_MULT_ON: for off in range(-3, window+1): D = np.minimum(np.maximum(D0+off, 3), k-1) best = np.maximum(best, A_mult_items(U, vt, D)) if A_CANCEL_ON and k >= 5: for off in range(-3, 3): D = np.minimum(np.maximum(D0+off, 3), k-2) for io in (1, 2): best = np.maximum(best, A_cancel_items(U, vt, D, io)) if A_MCANCEL_ON and k >= 5: for off in range(-2, 4): D = np.minimum(np.maximum(D0+off, 3), k-2) for io in (1, 2): best = np.maximum(best, A_mcancel_items(U, vt, D, io)) return np.maximum(best, A_pair_items(U, vt, k)) A_CANCEL_ON = True # Definition A.25(f) (cancellation in the count of pairs, Corollary A.18) is used A_KAP = {1: 1/6, 2: 1/14} # kappa_iota = 1/(2^(iota+2) - 2) def A_cancel_items(U, vt, D, io): """the number in (f) of Definition A.25 for the degrees D (array, same shape as U) and iota = io, or 0 where it is not admitted: min{1, E_1, E_2, E_5, E_6}/(D(D+1)), admitted when U >= D - 1/2, U/(D+1) + vt < 1 and (D+3) vt <= 1/4""" U = np.asarray(U, float); D = np.asarray(D, float); ka = A_KAP[io]; P = (io+1)*ka U1 = U/(D+1) E1 = 2*U1 - (D-1)*vt; E2 = D-1-(D-2)*U1-(2*D-1)*vt; E6 = (2*D-1)*(1-U1-vt) E5 = D+1-U + ka*((io+1)*(2*U1-1) - 1) - (D+1+2*P*D)*vt val = np.minimum.reduce([np.ones_like(U), E1, E2, E5, E6]) ok = (U >= D - 0.5) & (U1 + vt < 1) & ((D+3)*vt <= 0.25) & (D >= 3) return np.where(ok, np.maximum(val, 0.0)/(D*(D+1)), 0.0) def A_cancel_interval(D, io, t, vt): """the interval [l, r] of the U with (f)(U, vt) >= t for the degree D and iota = io (arrays t, vt; l = inf, r = -inf if it is empty or not defined): l = max{l_D, D - 1/2}, r the least of the bounds that come from E_2, E_6, E_5 >= T""" ka = A_KAP[io]; P = (io+1)*ka; c = D + 1 + 2*P*D T = D*(D+1)*np.asarray(t, float); v = np.asarray(vt, float) l = np.maximum(0.5*(D+1)*(T + (D-1)*v), D - 0.5) r = np.minimum.reduce([(D+1)*(D-1-T-(2*D-1)*v)/(D-2), (D+1)*(1 - v - T/(2*D-1)), (D+1)*(D+1-P-ka-T-c*v)/(D+1-2*P)]) ok = (T <= 1) & ((D+3)*v <= 0.25) & (l <= r) return np.where(ok, l, np.inf), np.where(ok, r, -np.inf) A_MULT_ON = True # Definition A.25(e) (prime multipliers, Corollary A.13) is used def A_mult_items(U, vt, D): """the number in (e) of Definition A.25 for the degrees D (array, same shape as U), or 0 where it is not admitted: the maximum over 0 <= beta <= beta_D^* of min{1 + beta, G_1, G_2, G_3, E_3, E_4}/(D(D+1))""" U = np.asarray(U, float); D = np.asarray(D, float) U1 = U/(D+1); bs = np.minimum((D - U)/D - vt, U1 - D*vt) E3 = 2*(D-1)*(1-U1) - (3*D-1)*vt; E4 = D+1-U-D*vt cinc = np.minimum(1.0, 2*U1 - (D-1)*vt) a1 = (D-1)*(1-U1) + U1 - (3*D-1)*vt; a3 = 1 + (D-1)*(1-U1) - (2*D-1)*vt best = np.full(U.shape, -np.inf) for b in (np.zeros_like(U), bs, (a1 - cinc)/D, (a3 - cinc)/(D-1)): b = np.clip(b, 0.0, np.maximum(bs, 0.0)) G1 = (D-1)*(1-U1-b) + U1 - (3*D-1)*vt; G2 = 2*U1 + b - (D-1)*vt; G3 = 1 + b + (D-1)*(1-U1-b) - (2*D-1)*vt best = np.maximum(best, np.minimum.reduce([1 + b, G1, G2, G3, E3, E4])) return np.where((bs >= 0) & (D >= 3), np.maximum(best, 0.0)/(D*(D+1)), 0.0) def A_mult_interval(D, t, vt): """the interval [l, r] of the U with (e)(U, vt) >= t for the degree D (arrays t, vt; l = inf, r = -inf if empty), from the pairwise conditions between the lower and the upper bounds for beta (Section A.4)""" T = D*(D+1)*np.asarray(t, float); v = np.asarray(vt, float) lo = [T - 1 + D*v, D*v, T - (D-1)/D + (D+1)*v, D*(T - 1 + D*v)/(D-1), (T + (2*D-1)*v)/3] if D >= 4: lo.append(((D-1)*T - D + (D*D-D+1)*v)/(D-3)) up = [(2*(D-1) - D*T - (3*D-1)*v)/(D-2), 2 - T - (2*D-1)*v/(D-1), D*(2 - T - v)/(D+1), (D - 1 - (3*D-1)*v - T)/(D-2), (D - (2*D-1)*v - T)/(D-1), D*(1 - v)/(D+1), 1 - (T + (3*D-1)*v)/(2*(D-1)), (D + 1 - T - D*v)/(D+1)] l = np.maximum.reduce(lo)*(D+1); r = np.minimum.reduce(up)*(D+1) ok = l <= r if D == 3: ok &= 3 - 2*T - 7*v >= 0 return np.where(ok, l, np.inf), np.where(ok, r, -np.inf) # --- p-adic exponent pairs (Section A.3, Proposition A.15, Definition A.25(d)). The words w = w_1 ... w_r of the set W # have length 2 <= r <= 10, contain the letter B, contain no two consecutive letters B, and end in A but not in BA # (a final BA does not change the pair). The pair (kappa_w, lambda_w) is obtained from (1/2, 1/2) by applying the # letters from the right: A(kappa, lambda) = (kappa/(2+2kappa), (kappa+lambda+1)/(2+2kappa)), B(kappa, lambda) = # (lambda - 1/2, kappa + 1/2). E_w = a(w) + 2, where a(w) is the number of letters A, and the constants c_w (for words # that begin with B) and vt_w (for words that begin with A) are those of (A.14). from fractions import Fraction as _Fr A_PAIRS_ON = True # Definition A.25(d) is used (False: the saving function of the previous version) def _A_pair_exact(w): k, l = _Fr(1, 2), _Fr(1, 2) for c in reversed(w): if c == 'A': k, l = k/(2 + 2*k), (k + l + 1)/(2 + 2*k) else: k, l = l - _Fr(1, 2), k + _Fr(1, 2) return k, l def _A_word_consts(w): """(c_w, vt_w) of (A.14): for each letter w_i = A with a_i letters A after it, the length bound Pi_i is the product of the numbers kappa/(1 - lambda) of the pairs of the words that follow the letters B in front of w_i, except the first letter if it is B; the condition is Pi_i >= (3 + a_i) vt if w begins with A, and (U - 1) Pi_i >= (3 + a_i) vt if w begins with B. So c_w = max_i (3 + a_i)/Pi_i for words that begin with B (and vt_w = 1/2), and vt_w = min_i Pi_i/(3 + a_i) for words that begin with A (and c_w = 0).""" cU = _Fr(0); vmax = None; prod = _Fr(1); lead_B = w[0] == 'B' for i, c in enumerate(w): if c == 'B': if i > 0: ka, la = _A_pair_exact(w[i+1:]); prod *= ka/(1 - la) else: need = 3 + w[i+1:].count('A') if lead_B: cU = max(cU, need/prod) else: vmax = prod/need if vmax is None else min(vmax, prod/need) return (cU, _Fr(1, 2)) if lead_B else (_Fr(0), vmax) def _A_words(): from itertools import product as _prod out = [] for r in range(2, 11): for tup in _prod('AB', repeat=r): w = ''.join(tup) if 'B' not in w or 'BB' in w or w[-1] != 'A' or w.endswith('BA'): continue ka, la = _A_pair_exact(w); cU, vm = _A_word_consts(w) out.append(dict(w=w, kap=ka, lam=la, E=w.count('A') + 2, cU=cU, vmax=vm)) return out A_WORDS = _A_words() # Table 6 (Section A.2): the 44 words whose lines 1 - lambda_w - kappa_w (U - 1) are the values of the function (A.45) # on the stated intervals of U A_TABLE5 = [('BAAAAAAAAA', _Fr(11, 10), _Fr(4609, 4097)), ('BAAAAAAAA', _Fr(4609, 4097), _Fr(2049, 1793)), ('BAAAAAAA', _Fr(2049, 1793), _Fr(237, 205)), ('BAAAAAABAA', _Fr(237, 205), _Fr(641, 545)), ('BAAAAAA', _Fr(641, 545), _Fr(513, 433)), ('BAAAAABAA', _Fr(513, 433), _Fr(1605, 1333)), ('BAAAAABAAA', _Fr(1605, 1333), _Fr(5847, 4807)), ('BAAAABABAA', _Fr(5847, 4807), _Fr(165, 133)), ('BAAAABAA', _Fr(165, 133), _Fr(669, 533)), ('BAAAABAAA', _Fr(669, 533), _Fr(771, 607)), ('BAAABABAAA', _Fr(771, 607), _Fr(9, 7)), ('BAAABABAA', _Fr(9, 7), _Fr(67, 51)), ('BAAABAA', _Fr(67, 51), _Fr(179, 135)), ('BAAABAABAA', _Fr(179, 135), _Fr(96, 71)), ('BAAABAAA', _Fr(96, 71), _Fr(307, 225)), ('BAABABAAA', _Fr(307, 225), _Fr(71, 51)), ('BAABABAA', _Fr(71, 51), _Fr(149, 105)), ('BAABABABAA', _Fr(149, 105), _Fr(730, 499)), ('BAABAABAAA', _Fr(730, 499), _Fr(211, 142)), ('BAABAABAA', _Fr(211, 142), _Fr(73, 48)), ('BAABAAA', _Fr(73, 48), _Fr(63, 41)), ('BAABAAABAA', _Fr(63, 41), _Fr(1466, 947)), ('BABABAAA', _Fr(1466, 947), _Fr(74, 47)), ('BABABAABAA', _Fr(74, 47), _Fr(18, 11)), ('BABABAA', _Fr(18, 11), _Fr(5, 3)), ('BABABABAA', _Fr(5, 3), _Fr(155, 89)), ('BABABABAAA', _Fr(155, 89), _Fr(341, 191)), ('BABAABAAA', _Fr(341, 191), _Fr(152, 83)), ('BABAABAA', _Fr(152, 83), _Fr(77, 41)), ('BABAABABAA', _Fr(77, 41), _Fr(1427, 728)), ('BABAAABAAA', _Fr(1427, 728), _Fr(2)), ('ABAAABAAA', _Fr(2), _Fr(457, 225)), ('ABAABABAAA', _Fr(457, 225), _Fr(211, 102)), ('ABAABABAA', _Fr(211, 102), _Fr(77, 36)), ('ABAABAA', _Fr(77, 36), _Fr(102, 47)), ('ABAABAABAA', _Fr(102, 47), _Fr(215, 96)), ('ABAABAAA', _Fr(215, 96), _Fr(341, 150)), ('ABABABAAA', _Fr(341, 150), _Fr(155, 66)), ('ABABABAA', _Fr(155, 66), _Fr(80, 33)), ('ABABABABAA', _Fr(80, 33), _Fr(764, 299)), ('ABABAABAAA', _Fr(764, 299), _Fr(218, 83)), ('ABABAABAA', _Fr(218, 83), _Fr(74, 27)), ('ABABAAA', _Fr(74, 27), _Fr(264, 95))] def _A_theta_star_pieces(): """the linear pieces theta^star(t) = A - B t (exact) on (t_lo, t_hi] for 1/20 < t <= 41/191 (Section A.3, (A.48)): the inverses of the lines of the words of Table 6 whose values meet (1/20, 41/191], of omega_3 (6 - 36t on (3/34, 17/190]), of omega_3^sharp ((168 - 1104t)/25 on (1/12, 3/34], the interval N_{3,2}), of the interval Q_{3,2} ((104 - 336t)/25 on (3/52, 1/12]), of omega_4 (8 - 80t on (3/55, 3/52]) and of omega_4^sharp ((35 - 375t)/4 on (1/20, 3/55], the interval N_{4,2})""" out = [] top = _Fr(41, 191) for w, lo, hi in A_TABLE5: ka, la = _A_pair_exact(w) t_hi = 1 - la - ka*(lo - 1); t_lo = 1 - la - ka*(hi - 1) if t_hi <= _Fr(1, 20) or t_lo >= top: continue out.append((max(t_lo, _Fr(1, 20)), min(t_hi, top), (1 - la + ka)/ka, 1/ka, w)) out.append((_Fr(3, 34), _Fr(17, 190), _Fr(6), _Fr(36), 'M3')) out.append((_Fr(1, 12), _Fr(3, 34), _Fr(168, 25), _Fr(1104, 25), 'N3')) out.append((_Fr(3, 52), _Fr(1, 12), _Fr(104, 25), _Fr(336, 25), 'Q3')) out.append((_Fr(3, 55), _Fr(3, 52), _Fr(8), _Fr(80), 'M4')) out.append((_Fr(1, 20), _Fr(3, 55), _Fr(35, 4), _Fr(375, 4), 'N4')) return sorted(out) A_TS_PIECES = _A_theta_star_pieces() A_WORD_BREAKS = sorted(set(float(x) for p in A_TS_PIECES for x in p[:2])) def A_beta_sharp_exact(D, U): """beta_D^sharp(U) of (A.45): the larger over iota = 1, 2 of the least of the numbers (x0 + xU U - 1)/(1 - xb) over the terms X of Definition A.25(g) with vartheta = 0 (the largest beta with X >= 1 + beta for all X)""" U = _Fr(U) return max(min((x0 + xU*U - 1)/(1 - xb) for _, x0, xU, xb, xv in _A_n_xterms(D, io)) for io in (1, 2)) def A_omega_sharp_exact(D, U): """omega_D^sharp(U) = (1 + beta_D^sharp(U))/(D(D+1)) if (D+1)/2 <= U <= D+1 and beta_D^sharp(U) >= 0, and 0 otherwise""" U = _Fr(U) if D < 3 or not (_Fr(D + 1, 2) <= U <= D + 1): return _Fr(0) b = A_beta_sharp_exact(D, U) return (1 + b)/(D*(D + 1)) if b >= 0 else _Fr(0) def A_limit_closed_exact(U, with_g=True): """the function (A.45) at a rational number U >= 1, exactly (with_g=False: the function of the previous version, without the numbers omega_D^sharp)""" U = _Fr(U) if U <= _Fr(11, 10): return 1 - U/2 for w, lo, hi in A_TABLE5: if lo <= U <= hi: ka, la = _A_pair_exact(w); return 1 - la - ka*(U - 1) if U <= 3: v = (6 - U)/36 else: D = int(U) if U != int(U) else int(U) - 1 # D < U <= D + 1, D >= 3 v = max((2*D + 2 - U)/((D + 1)**2*(D + 2)), min(1, D + 1 - U + max(A_eta_exact(D, 1, U), A_eta_exact(D, 2, U)))/_Fr(D*(D + 1))) if with_g: n = int(U) for Dp in (n, n + 1): v = max(v, A_omega_sharp_exact(Dp, U)) return v def A_eta_exact(D, io, U): """eta_{D,iota}(U) = (iota+1) kappa_iota (2U/(D+1) - 1) - kappa_iota (Corollary A.18): (4U - 3(D+1))/(6(D+1)) for iota = 1 and (3U - 2(D+1))/(7(D+1)) for iota = 2""" ka = _Fr(1, 2**(io + 2) - 2); return (io + 1)*ka*(2*_Fr(U)/(D + 1) - 1) - ka def _A_cancel_pieces(D, io): """the number in (f) of Definition A.25 for vartheta = 0, degree D and iota = io, on [D - 1/2, D + 1]: min{1, E_1, E_2, E_5, E_6}/(D(D+1)) as linear pieces (a, b, lo, hi) with value a - b U (pieces with values <= 0 omitted)""" d = _Fr(D); f = 1/(d*(d + 1)); ka = _Fr(1, 2**(io + 2) - 2); Pp = (io + 1)*ka lines = [(_Fr(1), _Fr(0)), (_Fr(0), -2/(d + 1)), (d - 1, (d - 2)/(d + 1)), (d + 1 - Pp - ka, 1 - 2*Pp/(d + 1)), (2*d - 1, (2*d - 1)/(d + 1))] lo, hi = d - _Fr(1, 2), d + 1 pts = {lo, hi} for i in range(len(lines)): for j in range(i + 1, len(lines)): if lines[i][1] != lines[j][1]: x = (lines[i][0] - lines[j][0])/(lines[i][1] - lines[j][1]) if lo < x < hi: pts.add(x) pts = sorted(pts); out = [] for l, h in zip(pts[:-1], pts[1:]): mid = (l + h)/2 v, a, b = min((x - y*mid, x, y) for x, y in lines) if v > 0: out.append((a*f, b*f, l, h)) return out def _A_mcancel_pieces(D, io): """the number in (g) of Definition A.25 for vartheta = 0, degree D and iota = io, on [(D+1)/2, D+1], as linear pieces (a, b, lo, hi) with value a - b U (pieces with values <= 0 omitted): it is the least over the terms X of the numbers 1 + (x0 + xU U - 1)/(1 - xb) and x0 + xU U, divided by D(D+1)""" f = _Fr(1, D*(D + 1)); lines = [] for _, x0, xU, xb, xv in _A_n_xterms(D, io): lines.append((1 + (x0 - 1)/(1 - xb), -xU/(1 - xb))); lines.append((x0, -xU)) lo, hi = _Fr(D + 1, 2), _Fr(D + 1) pts = {lo, hi} for i in range(len(lines)): for j in range(i + 1, len(lines)): if lines[i][1] != lines[j][1]: x = (lines[i][0] - lines[j][0])/(lines[i][1] - lines[j][1]) if lo < x < hi: pts.add(x) pts = sorted(pts); out = [] for l, h in zip(pts[:-1], pts[1:]): mid = (l + h)/2 v, a, b = min((x - y*mid, x, y) for x, y in lines) if v > 0: if out and out[-1][0] == a*f and out[-1][1] == b*f and out[-1][3] == l: out[-1] = (a*f, b*f, out[-1][2], h) else: out.append((a*f, b*f, l, h)) return out def _A_omega_pieces(D): """omega_D(U) = (1 + beta_D(U))/(D(D+1)) on [(D+1)/2, D] (A.8), beta_D = min{(D-U)/D, (D-2)/D (1 - U/(D+1))}, as linear pieces (a, b, lo, hi) with value a - b U; and omega_D^flat(U) = (2U/(D+1) + (D-U)/D)/(D(D+1)) on [1, (D+1)/2], an upper bound for the number in (e) of Definition A.25 there (proof of Lemma A.26)""" f = _Fr(1, D*(D + 1)); d = _Fr(D) a1, b1 = 2*f, f/d # (1 + (D-U)/D) f a2, b2 = (1 + (d - 2)/d)*f, (d - 2)/(d*(d + 1))*f # (1 + (D-2)/D - (D-2)U/(D(D+1))) f lo, hi = (d + 1)/2, d Uc = (a1 - a2)/(b1 - b2) # = 2(D+1)/3 out = [(a2, b2, lo, Uc), (a1, b1, Uc, hi)] if lo < Uc < hi else ([(a1, b1, lo, hi)] if Uc <= lo else [(a2, b2, lo, hi)]) out.append((f, -(_Fr(2)/(d + 1) - 1/d)*f, _Fr(1), (d + 1)/2)) # omega^flat return out def A_limit_envelope_exact(words, Umax=10, J=12, with_e=True, with_f=True, with_g=True): """the exact upper envelope on [1, Umax] of the numbers in (a), (b), (c) of Definition A.25 for vartheta = 0 (with the degrees D <= Umax + 1 and the numbers s_j with j <= J, which suffice there), of the lines of the given words, and (if with_e) of the pieces of omega_D and omega_D^flat for 3 <= D <= Umax + 1 (item (e)): the breakpoints and a function that evaluates the envelope at rational points""" P = [(_Fr(1), _Fr(1, 2), _Fr(1), _Fr(2))] # 1 - U/2 (a) for j in range(1, J + 1): # (b): min{rho_j, 2^(-j-1)} for vartheta = 0 c = _Fr(2**(j + 2) - 2); x = j + _Fr(1, 2**j) P.append((_Fr(j + 2)/c, 1/c, x, _Fr(j + 2))); P.append((_Fr(1, 2**(j + 1)), _Fr(0), _Fr(1), x)) for D in range(3, Umax + 2): # (c): c_D(U) = min{1, 2U/(D+1), D+1-U}/(D(D+1)) f = _Fr(1, D*(D + 1)) P.append(((D + 1)*f, f, _Fr(D), _Fr(D + 1))); P.append((f, _Fr(0), _Fr(D + 1, 2), _Fr(D))) P.append((_Fr(0), -2*f/(D + 1), _Fr(1), _Fr(D + 1, 2))) if with_e: P.extend(_A_omega_pieces(D)) if with_f: for io in (1, 2): P.extend(_A_cancel_pieces(D, io)) if with_g and D <= Umax + 1: for io in (1, 2): P.extend(_A_mcancel_pieces(D, io)) for w in words: ka, la = _A_pair_exact(w); P.append((1 - la + ka, ka, _Fr(1), _Fr(Umax))) pts = {_Fr(1), _Fr(Umax)} for a, b, lo, hi in P: pts.update(x for x in (lo, hi) if 1 < x < Umax) for i in range(len(P)): for j in range(i + 1, len(P)): if P[i][1] != P[j][1]: x = (P[i][0] - P[j][0])/(P[i][1] - P[j][1]) if 1 < x < Umax: pts.add(x) def ev(U): return max(a - b*U for a, b, lo, hi in P if lo <= U <= hi) return sorted(pts), ev def A_word_ok(w, k): """the condition of Proposition A.15 on w and k: v_0 = k, v_i = v_(i-1) - 1 if w_i = A and v_i = v_(i-1)/(v_(i-1) - 1) if w_i = B; no v_i (0 <= i <= r) is 0 or 1""" v = _Fr(k) for c in w: if v in (0, 1): return False v = v - 1 if c == 'A' else v/(v - 1) return v not in (0, 1) _A_WK = {} def A_words_for(k): """the words of W that satisfy the condition of Proposition A.15 for k, with their variants: a list of tuples (w, kap, lam, E, cU, vmax, variants), where each variant is (gamma, delta) with gamma > 0, so that the pair item with this variant is at least t exactly for U <= R(t, vt) = (P - t - delta vt)/gamma, P = 1 - lambda + kappa: variant 1 is (kappa, 1/2) (the loss vt/2), variant 2 is (kappa - 1/(2c), k/(2c)) with c = k - E + 1 (the loss (k vt - U)/(2c)), used when kappa c >= 1 (so that gamma >= kappa/2)""" if not A_PAIRS_ON: return [] if k not in _A_WK: out = [] for d in A_WORDS: if not A_word_ok(d['w'], k): continue var = [(d['kap'], _Fr(1, 2))]; c = k - d['E'] + 1 if c >= 1 and d['kap']*c >= 1: var.append((d['kap'] - _Fr(1, 2*c), _Fr(k, 2*c))) out.append((d['w'], d['kap'], d['lam'], d['E'], d['cU'], d['vmax'], var)) _A_WK[k] = out return _A_WK[k] def A_pair_items(U, vt, k): """the largest of the numbers in (d) of Definition A.25 that are admitted at (U, vt) (array U), or 0""" U = np.asarray(U, float); best = np.zeros_like(U) for w, ka, la, E, cU, vm, var in A_words_for(k): if vt > float(vm): continue base = (1 - float(la)) - float(ka)*(U - 1) val = base - vt/2 c = k - E + 1 if len(var) > 1: val = np.maximum(val, base - np.maximum(k*vt - U, 0.0)/(2*c)) # the second number of (d) best = np.maximum(best, np.where(U >= 1 + float(cU)*vt, val, 0.0)) return best A_M, A_MTOP, A_MTAIL = 32, 64, 256 # numbers of cells (Section A.8): per band, above 1/12, below the last band def A_zk(k): """the seed z_k of Theorem A.31: 1/10 for k < 5000, 41/382 for k >= 5000 (Lemma A.32)""" return 0.1 if k < 5000 else 41/382 def A_Dlim(k): """the tents used in the recursion and in Section A.8: T_D with D <= min{ceil(1.45 sqrt k) + 7, k - 1}""" return min(int(ceil(1.45*sqrt(k))) + 7, k - 1) def A_frac(k, Y, Th): """(s_0, b, E, x) of Section A.8 for the cap Th, with Th' = Th/(1 - Th/(2k)), so that k/Th' = k/Th - 1/2: x = Y - 2 chi_0 k/Th', 2 s_0 > x, s_0 >= 5k/2, b = 4/(9.027901 Th'), E = 2 s_0 + (1 + b) k/(2 tau_k) = 2 s_0 + 4.5139505 k + 2k/Th'""" x = Y - 2*CHI0*(k/Th - 0.5) s0 = max(s0_floor(k), floor(x/2) + 1); b = 4*(k/Th - 0.5)/(TAU_INV*k) return s0, b, 2*s0 + (TAU_INV/2)*k + 2*(k/Th - 0.5), x # --- large k (Lemma A.32, Proposition A.33) class _RF: """rational functions of D with integer coefficients (numerator, denominator as coefficient lists), for the inequalities of Section A.3 and of Lemma A.32 that are proved for all D >= D_0: s.pos_from(D_0) is True when numerator and denominator, written as polynomials in D - D_0, have coefficients of one sign and a nonzero constant term of that sign""" def __init__(s, num, den=(1,)): num = [_Fr(x) for x in num]; den = [_Fr(x) for x in den] L = 1 for x in num + den: L = L*x.denominator//gcd(L, x.denominator) s.n = _RF._trim([int(x*L) for x in num]); s.d = _RF._trim([int(x*L) for x in den]) @staticmethod def _trim(a): a = list(a) while len(a) > 1 and a[-1] == 0: a.pop() return a @staticmethod def _mul(a, b): r = [0]*(len(a) + len(b) - 1) for i, x in enumerate(a): if x: for j, y in enumerate(b): r[i+j] += x*y return _RF._trim(r) @staticmethod def _add(a, b): r = [0]*max(len(a), len(b)) for i, x in enumerate(a): r[i] += x for i, x in enumerate(b): r[i] += x return _RF._trim(r) @staticmethod def _c(o): return o if isinstance(o, _RF) else _RF([o]) def __add__(s, o): o = _RF._c(o); return _RF(_RF._add(_RF._mul(s.n, o.d), _RF._mul(o.n, s.d)), _RF._mul(s.d, o.d)) __radd__ = __add__ def __neg__(s): return _RF([-x for x in s.n], s.d) def __sub__(s, o): return s + (-_RF._c(o)) def __rsub__(s, o): return (-s) + o def __mul__(s, o): o = _RF._c(o); return _RF(_RF._mul(s.n, o.n), _RF._mul(s.d, o.d)) __rmul__ = __mul__ def __truediv__(s, o): o = _RF._c(o); return _RF(_RF._mul(s.n, o.d), _RF._mul(s.d, o.n)) def __rtruediv__(s, o): return _RF._c(o)/s def __pow__(s, e): r = _RF([1]) for _ in range(e): r = r*s return r def __call__(s, x): x = _Fr(x); return sum(c*x**i for i, c in enumerate(s.n))/sum(c*x**i for i, c in enumerate(s.d)) def is_zero(s): return s.n == [0] def pos_from(s, d0): from math import comb as _mcomb def shift(a): r = [0]*len(a) for e, c in enumerate(a): for j in range(e + 1): r[j] += c*_mcomb(e, j)*d0**(e - j) return r def sgn(v): if all(x >= 0 for x in v) and v[0] > 0: return 1 if all(x <= 0 for x in v) and v[0] < 0: return -1 return 0 return sgn(shift(s.n))*sgn(shift(s.d)) == 1 _RF_D = _RF([0, 1]) def A_gE8_exact(D): """(D+1)(12D+7)/(6D): the coefficient of vt in the term of r^N_{D,2} that comes from E_8 (used for D <= 5)""" return _Fr((D + 1)*(12*D + 7), 6*D) def A_gamma_piece(org): """the number gamma of Lemma A.32 for a linear piece of theta^star with the origin org (A_BAND_PIECES): gamma_{D,iota} for phi_{D,iota} and phi^sharp_{D,iota}, D + 1 for phi_{D,0} (origin ('M', D+1)), gamma_{D,2} for phi^sharp_{D,3} (origin ('N', D, 2, 'E7')), and (D+1)(12D+7)/(6D) for phi^sharp_{D,2} with D <= 5""" if org[0] == 'phi': return A_gamma_exact(org[1], org[2]) if org[0] == 'M': return _Fr(org[1]) Dp, io, b = org[1], org[2], org[3] if io == 2 and b == 'E5' and Dp <= 5: return A_gE8_exact(Dp) return A_gamma_exact(Dp, io) # the pieces of theta^star on (1/20, 17/190] that are not words: (t_lo, t_hi, A, B, origin, gamma) A_TOP3_PIECES = [(_Fr(1, 20), _Fr(3, 55), _Fr(35, 4), _Fr(375, 4), ('N', 4, 2, 'E5'), _Fr(275, 24)), (_Fr(3, 55), _Fr(3, 52), _Fr(8), _Fr(80), ('M', 4), _Fr(4)), (_Fr(3, 52), _Fr(1, 12), _Fr(104, 25), _Fr(336, 25), ('phi', 3, 2), _Fr(148, 25)), (_Fr(1, 12), _Fr(3, 34), _Fr(168, 25), _Fr(1104, 25), ('N', 3, 2, 'E5'), _Fr(86, 9)), (_Fr(3, 34), _Fr(17, 190), _Fr(6), _Fr(36), ('M', 3), _Fr(3))] def A_rho3_terms(): """rho_3 of Proposition A.33 exactly, as a list of (c, x) with rho_3 = sum c log x: the five pieces of A_TOP3_PIECES, each term (1/A) log(...) of Lambda^star multiplied by its gamma""" return [(g/A, h*(A - B*l)/(l*(A - B*h))) for l, h, A, B, _, g in A_TOP3_PIECES] def A_rhodag_terms(D): """rho_D^dagger of Proposition A.33 for 4 <= D, exactly, as a list of (c, x): the terms of Lambda_D^dagger, each multiplied by the number gamma of its piece (A_gamma_piece); for D >= 15 the factors are gamma_{D+1,1} and gamma_{D,1}""" if D <= A_DBAND: return [(A_gamma_piece(o)/A, h*(A - B*l)/(l*(A - B*h))) for l, h, A, B, o in A_BAND_PIECES[D]] (c1, x1), (c2, x2) = A_lamdag_terms(D) return [(c1*A_gamma_exact(D + 1, 1), x1), (c2*A_gamma_exact(D, 1), x2)] def A_rhodag_array(d): """the numbers rho_D^dagger for 4 <= D <= d, in floating point""" D = np.arange(4, d + 1, dtype=np.float64) N5 = 12*D**5 + 52*D**4 + 97*D**3 + 111*D**2 + 64*D + 12; P2 = 6*D*D + 17*D + 4 y1 = 8*(9*D**5 + 36*D**4 + 38*D**3 - 3*D**2 - 16*D - 4)/((3*D + 4)*N5) y2 = 2*(6*D**4 + 39*D**3 + 62*D**2 + 34*D + 6)/(D*(D + 1)*(2*D - 1)*P2) g1 = (D + 2)*(5*D + 8)/(3*D + 4); g2 = (D + 1)*(5*D + 3)/(3*D + 1) out = g1*(3*D + 4)/(6*(D + 1)*(D + 2))*np.log1p(y1) + g2*2*(3*D + 1)/(3*(D + 1)*(2*D + 1))*np.log1p(y2) for dd in range(4, min(d, A_DBAND) + 1): out[dd - 4] = sum(float(c)*log1p(float(x - 1)) for c, x in A_rhodag_terms(dd)) return out def A_gamma_exact(D, io): """gamma_{D,iota} of Lemma A.32: (D+1)(5D+3)/(3D+1) for iota = 1 and (D+1)(10D+7)/(7D+4) for iota = 2""" return _Fr((D + 1)*(5*D + 3), 3*D + 1) if io == 1 else _Fr((D + 1)*(10*D + 7), 7*D + 4) def A_rho_terms(D): """rho_D of Proposition A.33 for an integer D >= 4, exactly, as a list of (c, a, b) with rho_D = sum c log(a/b): the terms of Lambda_D^sharp (A_lamsharp_terms), each multiplied by the number gamma_{D,iota} or D + 1 of its range""" T = A_lamsharp_terms(D) if D == 7: g = [A_gamma_exact(7, 2), A_gamma_exact(7, 1), _Fr(8)] else: g = [A_gamma_exact(D, 2 if D <= 6 else 1), _Fr(D + 1)] return [(c*gg, a, b) for (c, a, b), gg in zip(T, g)] def A_rho_array(d): """the numbers rho_D for 4 <= D <= d, in floating point""" D = np.arange(4, d + 1, dtype=np.float64) out = (2*(5*D + 3)/(3*(2*D + 1)))*np.log1p((14*D*D + 15*D + 4)/(D*(6*D + 1)*(2*D - 1))) + 0.5*np.log1p((10*D - 4)/(3*(2*D*D + D + 2))) for dd in range(4, min(d, 7) + 1): out[dd - 4] = sum(float(c)*log1p((a - b)/b) for c, a, b in A_rho_terms(dd)) return out def A_D0(k): """the largest integer D_star with D_star^2 + 6 D_star + 32 <= k""" n = int(sqrt(k-23)) - 3 while (n+1)**2 + 6*(n+1) + 32 <= k: n += 1 while n*n + 6*n + 32 > k: n -= 1 return n def A_DM(k): """the largest integer D_M with 2 D_M^2 + 11 D_M + 57 <= k (Lemma A.32)""" n = int(sqrt(k/2)) - 3 while 2*(n+1)**2 + 11*(n+1) + 57 <= k: n += 1 while 2*n*n + 11*n + 57 > k: n -= 1 return n def A_DQ(k): """the largest integer D_Q with (2 D_Q + 1)(2 D_Q + 6) <= k (Lemma A.32)""" n = max(int(sqrt(k)/2) - 3, 0) while (2*(n+1) + 1)*(2*(n+1) + 6) <= k: n += 1 while (2*n + 1)*(2*n + 6) > k: n -= 1 return n def A_check_t3(k): """the point check t_3 = (k+18)/(12k+126) of Lemma A.32""" return (k + 18)/(12*k + 126) A_RHO3 = sum(float(c)*log(float(x)) for c, x in A_rho3_terms()) def A_Yreg_terms(k): """the terms of Y^reg(k) - C_0^star k (the first inequality of Proposition A.33), with Theta = D_star/(1 + D_star/k): 2 rho_3, the tail -2k sum_{D >= D_star} Lambda_D^star, the loss 2k sum_{D_M <= D < D_star} (Lambda_D - Lambda_D^star), the sums 2 rho_3 + 2 sum_{4 <= D < D_Q} rho_D^dagger + 2 rho_{D_Q} + 2 sum_{D_Q < D < D_M} (D Lambda_D^T + (D+1) Lambda_D^M) + 2 sum_{D_M <= D < D_star} D Lambda_D, the last term (2k/Theta) log(9.027901 k/(2 D_star (D_star+1))) and -log(z_k/tau_k); then D_star, D_M and Theta; then an upper value for the loss 2k sum_{D >= D_Q} (Lambda_D^sharp - Lambda_D^dagger) + 2k sum_{D > D_Q} (Lambda_D^star - Lambda_D^sharp) (the sums up to D = A_NT, and 11/(60 A_NT^2) for the remainder, since Lambda_D^star - Lambda_D^dagger <= 1/(5 D^3) + 1/(6 D^3) for D >= 15), and D_Q. The first entry (2 rho_3) is also contained in the fourth. Requires 15 < D_Q < D_M <= D_star <= A_NT.""" n = A_D0(k); m = A_DM(k); d = A_DQ(k); Th = n/(1+n/k) _require(16 <= d < m <= n <= A_NT, "A_Yreg_terms: k is too small or too large") D1 = np.arange(d + 1, m, dtype=np.float64); D2 = np.arange(m, n, dtype=np.float64) lamT = np.log1p((D1+2)/D1**2)/(D1+1); lamS = np.log1p((4*D1**3 + 7*D1**2 + 8*D1 + 4)/D1**4)/(2*(D1+1)) lam2 = np.log1p(2*(D2+1)/D2**2)/(D2+1); lamS2 = np.log1p((4*D2**3 + 7*D2**2 + 8*D2 + 4)/D2**4)/(2*(D2+1)) S = float(2*A_RHO3 + 2*A_rhodag_array(d - 1).sum() + 2*A_rho_array(d)[-1] + 2*(D1*lamT + (D1+1)*(lamS - lamT)).sum() + 2*(D2*lam2).sum()) loss = float(2*k*(lam2 - lamS2).sum()) lossQ = 2*k*(float(A_CQD[d-4]) - float(_A_DLS[d-4]) + 11/(60*A_NT**2)) return (2*A_RHO3, -2*k*A_tail_lo(n), loss, S, (2*k/Th)*log(TAU_INV*k/(2*n*(n+1))), -log(TAU_INV*k*A_zk(k)), n, m, Th, lossQ, d) def A_Yreg(k): """Y^reg(k) - C_0^star k: the sum of the terms of A_Yreg_terms(k) (2 rho_3 counted once)""" r = A_Yreg_terms(k); return sum(r[1:6]) + r[9] def A_exact(k, prec=40, grid=None): """A second, independently written evaluation of k B^natural(k) in decimal arithmetic with prec digits. The end points of the intervals of Lemma A.28 are written down as affine functions of vt, directly from the definitions, and the conditions on a chain are solved for vt mechanically; for the condition between the greedy union (1, R_J'(t)] and the first tent the cap min{a_1, 1} of Lemma A.28(iv) is not needed, as J' <= J_c(D1) there, nor for the junctions and ends of tents, where a_1 < 1; for the conditions that involve intervals of Definition A.25(e) the cap is applied: a condition vt <= a_1 - a_2 t is evaluated at t and at 0, and a_1 is replaced by min{a_1, 1}. The levels are the (binary) numbers of A_grid_rig(k), or of grid.""" from decimal import Decimal as Dm, getcontext getcontext().prec = prec kk = Dm(k); one = Dm(1); half = one/2 def solve(L, R): # largest vt with L0 + L1 vt <= R0 + R1 vt (L1 > R1) return (R[0]-L[0])/(L[1]-R[1]) def end(R): # largest vt with k vt <= R0 + R1 vt return R[0]/(kk-R[1]) def T_left(D, t): tau = D*(D+1)*t return ((D+1)*tau/2, Dm((D+1)*(D-1))/2) def T_right(D, t): # E_2, E_3, E_4 >= tau tau = D*(D+1)*t; D = Dm(D) return [((D+1)*(D-1-tau)/(D-2), -(D+1)*(2*D-1)/(D-2)), ((D+1)*(1-tau/(2*D-2)), -(D+1)*(3*D-1)/(2*D-2)), (D+1-tau, -D)] def Q_right(D, io, t): # the interval Q_{D,iota} of Definition A.25(f): E_2, E_6, E_5 >= tau tau = D*(D+1)*t; D = Dm(D); ka = one/Dm(2**(io+2) - 2); P = (io+1)*ka return [((D+1)*(D-1-tau)/(D-2), -(D+1)*(2*D-1)/(D-2)), ((D+1)*(1 - tau/(2*D-1)), -(D+1)), ((D+1)*(D+1-P-ka-tau)/(D+1-2*P), -(D+1)*(D+1+2*P*D)/(D+1-2*P))] def R_J(J, t): # the right end point of the greedy union I_0, ..., I_J (no vt) return (Dm(J+2) - Dm(2**(J+2)-2)*t, Dm(0)) def dfr(x): return Dm(x.numerator)/Dm(x.denominator) def N_left(D): # the left end point (D+1)(1 + (D-1) vt)/2 of N_{D,iota} (Definition A.25(g)) return (Dm(D+1)/2, Dm((D+1)*(D-1))/2) def N_right(D, io, t): # the 14 terms of r^N, from the terms X of (g) with beta = 0 and beta = T - 1 D_ = Dm(D); T = D_*(D_+1)*t; out = [] for _, x0, xU, xb, xv in _A_n_xterms(D, io): x0, xU, xb, xv = dfr(x0), dfr(xU), dfr(xb), dfr(xv) for L in (Dm(0), T - 1): out.append(((x0 + xb*L - T)/(-xU), xv/(-xU))) return out def cap(v, v0): # the condition vt <= a_1 - a_2 t with value v at t and v0 = a_1 at 0: min{a_1, 1} - a_2 t return v - v0 + min(v0, one) def M_ends(Dp, t): """the interval of Definition A.25(e) for the degree Dp at the level t, derived from the definitions: each condition 1 + beta >= tau, G_i >= tau, 0 <= beta <= beta_D^* is written as beta >= or <= p + q U + r vt, and every pair of a lower and an upper condition is solved for U (or, if q is the same, for vt); E_3, E_4 >= tau bound U. Returns (lower bounds for U, upper bounds for U, upper bounds for vt), each an affine function (c0, c1) of vt""" D = Dm(Dp); tau = D*(D+1)*t; u = one/(D+1) lows = [(tau - 1, Dm(0), Dm(0)), (Dm(0), Dm(0), Dm(0)), (tau, -2*u, D - 1)] # beta >= p + q U + r vt ups = [(((D-1) - tau)/(D-1), (-(D-1)*u + u)/(D-1), -(3*D-1)/(D-1)), # G_1 >= tau ((1 + (D-1) - tau)/(D-2), -(D-1)*u/(D-2), -(2*D-1)/(D-2)), # G_3 >= tau (one, -one/D, -one), (Dm(0), u, -D)] # beta <= beta_D^* Lu, Uu, V = [], [], [] for pl, ql, rl in lows: for pu, qu, ru in ups: dq = ql - qu if dq > 0: Uu.append(((pu - pl)/dq, (ru - rl)/dq)) # U <= ... elif dq < 0: Lu.append(((pu - pl)/dq, (ru - rl)/dq)) # U >= ... else: V.append(((pu - pl)/(rl - ru), Dm(0))) # vt <= ... (here rl > ru) Uu.append(((D+1)*(1 - tau/(2*(D-1))), -(D+1)*(3*D-1)/(2*(D-1)))) # E_3 >= tau Uu.append((D + 1 - tau, -D)) # E_4 >= tau return Lu, Uu, V def M_chain(Dp, t, reach, reach0): """largest vt with: every lower bound for U of the interval of degree Dp <= reach (an affine function of vt; reach0 is its value at t = 0), k vt <= every upper bound, and the conditions on vt alone (all capped)""" Lu, Uu, V = M_ends(Dp, t); Lu0, Uu0, V0 = M_ends(Dp, Dm(0)) return min([cap(solve(L, reach), solve(L0, reach0)) for L, L0 in zip(Lu, Lu0)] + [cap(end(R), end(R0)) for R, R0 in zip(Uu, Uu0)] + [cap(c[0], c0[0]) for c, c0 in zip(V, V0)]) JUNC = [{}, {}] def types_at(tf, J, Dband): """dictionary chain -> largest theta = k vt for which the chain works at the level tf, capped at k/2""" t = Dm(tf); out = {('G',): min(R_J(J, t)[0], kk*half)} if Dband < 3: if A_MULT_ON: for Dp in range(3, 9): if Dp <= k - 1: out[('GM', Dp)] = min(kk*M_chain(Dp, t, R_J(J, t), R_J(J, Dm(0))), kk*half) gn_types(t, J, out) return pair_types(tf, J, Dband, out) TL = {D: T_left(D, t) for D in range(3, Dband+1)} TR = {D: T_right(D, t) for D in range(3, Dband+1)} junc = {D: min(solve(TL[D+1], R) for R in TR[D]) for D in range(3, Dband)} ends = {D: min(end(R) for R in TR[D]) for D in range(3, Dband+1)} JUNC[0] = junc; JUNC[1] = ends if A_MULT_ON: mend = {}; bjunc = {}; z0 = Dm(0) TL0 = {D: T_left(D, z0) for D in range(3, Dband+1)}; TR0 = {D: T_right(D, z0) for D in range(3, Dband+1)} for D in range(3, Dband+1): # end in the interval of degree D + 1 after T_D (all three right ends of T_D) if D + 1 <= k - 1: Lu, Uu, V = M_ends(D+1, t); Lu0, Uu0, V0 = M_ends(D+1, z0) mend[D] = min([cap(solve(L, R), solve(L0, R0)) for L, L0 in zip(Lu, Lu0) for R, R0 in zip(TR[D], TR0[D])] + [cap(end(R), end(R0)) for R, R0 in zip(Uu, Uu0)] + [cap(c[0], c0[0]) for c, c0 in zip(V, V0)]) else: mend[D] = Dm(-1) for D in range(3, Dband): # the bridge T_D, interval of degree D + 1, T_{D+1} Lu, Uu, V = M_ends(D+1, t); Lu0, Uu0, V0 = M_ends(D+1, z0) bjunc[D] = min([cap(solve(L, R), solve(L0, R0)) for L, L0 in zip(Lu, Lu0) for R, R0 in zip(TR[D], TR0[D])] + [cap(solve(TL[D+1], R), solve(TL0[D+1], R0)) for R, R0 in zip(Uu, Uu0)] + [cap(c[0], c0[0]) for c, c0 in zip(V, V0)]) qend = {} if A_CANCEL_ON: # end in the interval Q_{D,iota} after T_D: D - 1/2 <= r_D, l_D <= r_D, z0 = Dm(0) # (D+3) vt <= 1/4 and k vt <= r^Q (all capped) TLq = {D: T_left(D, z0) for D in range(3, Dband+1)}; TRq = {D: T_right(D, z0) for D in range(3, Dband+1)} for D in range(3, Dband+1): if D > k - 2: continue low = (Dm(D) - half, Dm(0)) jq = min([cap(solve(low, R), solve(low, R0)) for R, R0 in zip(TR[D], TRq[D])] + [cap(solve(TL[D], R), solve(TLq[D], R0)) for R, R0 in zip(TR[D], TRq[D])] + [one/(4*Dm(D+3))]) for io in (1, 2): qend[(D, io)] = min([jq] + [cap(end(R), end(R0)) for R, R0 in zip(Q_right(D, io, t), Q_right(D, io, z0))]) nend = {} if A_MCANCEL_ON: # end in the interval N_{D+1,iota} after T_D: l^N <= r_D, (D+4) vt <= 1/4, z0 = Dm(0) # k vt <= r^N (all capped) TRn = {D: T_right(D, z0) for D in range(3, Dband+1)} for D in range(3, Dband+1): if D + 1 > k - 2: continue low = N_left(D + 1) jn = min([cap(solve(low, R), solve(low, R0)) for R, R0 in zip(TR[D], TRn[D])] + [one/(4*Dm(D+4))]) nend[D] = min([jn] + [max(min(cap(end(R), end(R0)) for R, R0 in zip(N_right(D + 1, io, t), N_right(D + 1, io, z0))) for io in (1, 2))]) for D1 in range(3, min(Dband, A_D1F)+1): cur = solve(TL[D1], R_J(min(J, (D1*D1-5)//2), t)); curb = cur for D2 in range(D1, Dband+1): if D2 > D1: cur = min(cur, junc[D2-1]) out[(D1, D2)] = min(kk*min(cur, ends[D2]), kk*half) for io in (1, 2): if (D2, io) in qend: out[(D1, D2, 'Q', io)] = min(kk*min(cur, qend[(D2, io)]), kk*half) if D2 in nend: out[(D1, D2, 'N')] = min(kk*min(cur, nend[D2]), kk*half) if A_MULT_ON: if D2 > D1: curb = min(curb, bjunc[D2-1]) out[(D1, D2, 'M')] = min(kk*min(cur, mend[D2]), kk*half) out[(D1, D2, 'b')] = min(kk*min(curb, ends[D2]), kk*half) out[(D1, D2, 'bM')] = min(kk*min(curb, mend[D2]), kk*half) for io in (1, 2): if (D2, io) in qend: out[(D1, D2, 'bQ', io)] = min(kk*min(curb, qend[(D2, io)]), kk*half) if D2 in nend: out[(D1, D2, 'bN')] = min(kk*min(curb, nend[D2]), kk*half) if A_MULT_ON: for Dp in range(3, 9): if Dp <= k - 1: out[('GM', Dp)] = min(kk*M_chain(Dp, t, R_J(J, t), R_J(J, Dm(0))), kk*half) gn_types(t, J, out) return pair_types(tf, J, Dband, out) def gn_types(t, J, out): """the chains (1, R_J(t)], N_{D',iota} for 3 <= D' <= 8 (Definition A.25(g))""" if not A_MCANCEL_ON: return z0 = Dm(0) for Dp in range(3, 9): if Dp > k - 2: continue low = N_left(Dp) v = min(cap(solve(low, R_J(J, t)), solve(low, R_J(J, z0))), one/(4*Dm(Dp+3))) v = min(v, max(min(cap(end(R), end(R0)) for R, R0 in zip(N_right(Dp, io, t), N_right(Dp, io, z0))) for io in (1, 2))) out[('GN', Dp)] = min(kk*v, kk*half) def pair_types(tf, J, Dband, out): """the chains that begin with an interval of Definition A.25(d), written down from the definitions, for all the admissible words (the main implementation leaves out, on a whole piece, the words with R(t, 0) <= R_J(t) at every level of the piece; such a word is never better than the greedy union there)""" t = Dm(tf) for d in (_A_wfam() if A_PAIRS_ON else []): if k < d['kok']: continue P = Dm(d['P'].numerator)/Dm(d['P'].denominator); ka = Dm(d['kap'].numerator)/Dm(d['kap'].denominator) if d['cU'] > 0: c = Dm(d['cU'].numerator)/Dm(d['cU'].denominator) st = (min(Dm(J+1), c) - Dm(2**(J+2)-2)*t)/c else: st = Dm(d['vmax'].numerator)/Dm(d['vmax'].denominator) var = [(ka, half)] if k >= d['k2']: c2 = Dm(k - d['E'] + 1); var.append((ka - 1/(2*c2), kk/(2*c2))) for i, (g, dl) in enumerate(var): out[('P', d['w'], i)] = min(kk*min(st, (P - t)/(kk*g + dl)), kk*half) if Dband < 3: continue for D1 in range(3, min(Dband, A_D1F)+1): D = Dm(D1) cur = min(st, (P - t*(1 + g*D*(D+1)**2/2))/(g*(D*D-1)/2 + dl)) for D2 in range(D1, Dband+1): if D2 > D1: cur = min(cur, JUNC[0][D2-1]) out[('P', d['w'], i, D1, D2)] = min(kk*min(cur, JUNC[1][D2]), kk*half) return out total = Dm(0); Theta = None for e, J, D, _ in (grid if grid is not None else A_grid_rig(k)): vb = types_at(float(e[0]), J, D) # the levels are taken in order, and only two of them are kept in memory if Theta is None: Theta = max(vb.values()) for i in range(len(e)-1): t1, t2 = Dm(float(e[i])), Dm(float(e[i+1])); va, vb = vb, types_at(float(e[i+1]), J, D) keys = [ky for ky in va if ky in vb and va[ky] > one and vb[ky] > one and va[ky] >= vb[ky]] cand = {max(keys, key=lambda ky: va[ky]), max(keys, key=lambda ky: vb[ky]), max(keys, key=lambda ky: va[ky]+vb[ky])} best = None for ky in cand: a, b = va[ky], vb[ky] A = (a*t2 - b*t1)/(t2 - t1) c = (t2*a/(t1*b)).ln()/A best = c if best is None or c < best else best total += best zf = A_zk_exact(k); z = Dm(zf.numerator)/Dm(zf.denominator) B = 2 + ((1-z)/z).ln() + 2*total + one/kk - (Dm('9.027901')*kk*z).ln()/kk # - (1/k) log(z_k/tau_k) return kk*B, Theta # --- theta_k directly from Definition A.25 (Lemma A.28(i)): for t > 0 and vt <= 1/2 the set of U > 1 # with varsigma^star(U, vt) >= t is exactly the union of the intervals I_0, I_j (1 <= j <= k-2, 2^(j+1) t <= 1) and # T_D (3 <= D <= k-1, D(D+1)t <= 1) of Lemma A.28. Hence sigma_k(theta) >= t if and only if these intervals, formed # with vt = theta/k, cover (1, theta]; this condition becomes weaker as theta decreases, and theta_k(t) is found by # bisection. No chain structure is assumed. def _A_intervals(k, t, vt, a=None, b=None, oldb=False): """the end points LO, HI (shape (n, m)) of the intervals of Lemma A.28 at the levels t with the heights vt (arrays); a and b are applied to the left and to the right end points (None: plain floating point). With oldb=True the intervals I_j are replaced by those that belong to the numbers rho_j(U) - vt/2 of Lemma 4.3(ii), as in A_covered4 (for the comparison in Remark A.41; plain floating point only).""" a0 = a a = a or (lambda x: x); b = b or (lambda x: x) n = t.shape[0] LO = [np.ones(n)]; HI = [b(2 - 2*t)] for j in range(1, min(k - 2, A_JMAX) + 1): if oldb: c = 2.0**(j+2) - 2 LO.append(np.full(n, j + 2.0**(-j))); HI.append(np.minimum((j+2) - c*(t + vt/2), (j+2) - c*vt)); continue ok = (2.0**(j+1)*t <= 1) & (2.0**j*t <= 1 - vt) LO.append(np.where(ok, a(a(j*vt) + 2.0**(j+1)*t), np.inf)); HI.append(np.where(ok, b(j + 2 - a((2.0**(j+2) - 2)*t)), -np.inf)) Dmax = 3 while (Dmax+1)*(Dmax+2)*float(t.min()) <= 1.0000001 and Dmax+1 <= k-1: Dmax += 1 if Dmax <= k - 1: D = np.arange(3, Dmax+1, dtype=np.float64)[None, :]; tt = t[:, None]; vv = vt[:, None] tD = a(D*(D+1)*tt) l = a(a(0.5*(D+1))*a(tD + a((D-1)*vv))) r1 = b(b((D+1)*b((D-1) - a(tD + a((2*D-1)*vv))))/(D-2)) r2 = b((D+1)*b(1 - a(a(tD + a((3*D-1)*vv))/(2*D-2)))) r3 = b((D+1) - a(tD + a(D*vv))) r = np.minimum.reduce([r1, r2, r3]); ok = (tD <= 1) & (l <= r) LO = np.hstack([np.array(LO).T, np.where(ok, l, np.inf)]); HI = np.hstack([np.array(HI).T, np.where(ok, r, -np.inf)]) else: LO = np.array(LO).T; HI = np.array(HI).T if A_MULT_ON: # the intervals of the numbers (e), for the degrees D with D(D+1) t <= 2 outer = a0 is not None ml, mh = [], [] D = 3 while D <= k - 1 and D*(D+1)*float(t.min()) <= 2: l, r = A_mult_interval(D, t, vt) if outer: l = l - 1e-11*(D+1); r = r + 1e-11*(D+1) ml.append(l); mh.append(r); D += 1 if ml: LO = np.hstack([LO, np.array(ml).T]); HI = np.hstack([HI, np.array(mh).T]) if A_CANCEL_ON: # the intervals of the numbers (f), for the degrees D <= k - 2 with D(D+1) t <= 1 outer = a0 is not None ql, qh = [], [] D = 3 while D <= k - 2 and D*(D+1)*float(t.min()) <= 1.0000001: for io in (1, 2): l, r = A_cancel_interval(D, io, t, vt) if outer: l = l - 1e-11*(D+1); r = r + 1e-11*(D+1) ql.append(l); qh.append(r) D += 1 if ql: LO = np.hstack([LO, np.array(ql).T]); HI = np.hstack([HI, np.array(qh).T]) if A_MCANCEL_ON: # the intervals of the numbers (g), for the degrees D <= k - 2 with D(D+1) t <= 2 outer = a0 is not None nl, nh = [], [] D = 3 while D <= k - 2 and D*(D+1)*float(t.min()) <= 2: for io in (1, 2): l, r = A_mcancel_interval(D, io, t, vt) if outer: l = l - 1e-11*(D+1); r = r + 1e-11*(D+1) nl.append(l); nh.append(r) D += 1 if nl: LO = np.hstack([LO, np.array(nl).T]); HI = np.hstack([HI, np.array(nh).T]) pw = A_words_for(k) if pw: # the intervals of the numbers (d): [1 + c_w vt, R(t, vt)], R = (P - t - delta vt)/gamma outer = a0 is not None pl, ph = [], [] for w, ka, la, E, cU, vm, var in pw: P = float(1 - la + ka); ok = vt <= float(vm) for g, dl in var: lo = 1 + float(cU)*vt; hi = (P - t - float(dl)*vt)/float(g) if outer: lo = lo - 1e-11; hi = hi + 1e-11 # the float errors are below 1e-12, as gamma >= kappa/2 >= 1/1404 good = ok & (hi >= lo) pl.append(np.where(good, lo, np.inf)); ph.append(np.where(good, hi, -np.inf)) LO = np.hstack([LO, np.array(pl).T]); HI = np.hstack([HI, np.array(ph).T]) return LO, HI def _A_reach(LO, HI): """the right end point of the component of the union of the intervals that begins at 1""" n = LO.shape[0] o = np.argsort(LO, axis=1, kind='stable'); LO = np.take_along_axis(LO, o, 1); HI = np.take_along_axis(HI, o, 1) cm = np.maximum.accumulate(HI, axis=1) gap = LO[:, 1:] > cm[:, :-1]; first = np.argmax(gap, axis=1) return np.where(gap.any(axis=1), cm[np.arange(n), first], cm[:, -1]) def A_covered(k, t, th, oldb=False): """for arrays t, th of equal length: True where the intervals of Lemma A.28 with vt = th/k cover (1, th]""" t = np.asarray(t, float); th = np.asarray(th, float) LO, HI = _A_intervals(k, t, th/k, oldb=oldb) return (th <= 1) | (_A_reach(LO, HI) >= th) def A_theta_direct(k, t, iters=64, oldb=False): """(lo, hi) with lo <= theta_k(t) < hi for an array of levels 0 < t <= 13/60 (bisection on theta in [1, k/2]); oldb: the same for the saving function with the numbers rho_j(U) - vt/2 in (b), for Remark A.41""" t = np.atleast_1d(np.asarray(t, float)) lo = np.ones_like(t); hi = np.full_like(t, k/2.0) top = A_covered(k, t, hi, oldb); lo = np.where(top, hi, lo) for _ in range(iters): mid = 0.5*(lo + hi); c = A_covered(k, t, mid, oldb) | top lo = np.where(c, mid, lo); hi = np.where(c, hi, mid) return lo, np.where(top, lo, hi) def A_check_t(k): """the point (7k + 408)/(110k + 1936) of Section A.8, at which the bound 51/11 - 22t that comes from the word AABABABAA and the bound (4 - 12t)/(1 + 8/k) of the chain with the tent T_3 cross (with the intervals Q_{3,iota} of Definition A.25(f) neither of them is the best one there; the point is kept in the subdivisions)""" return (7*k + 408)/(110*k + 1936) def A_V_quadrature(k, cap=None, sub=8, nodes=12): """Psi(z_k) + 2 int_{2 tau_k}^{2 z_k} dt/(t min{cap, theta_k(t)}) - (1/k) log(z_k/tau_k) + 1/k by Gauss-Legendre quadrature in log t on the ranges between the points 1/(D(D+1)), 2^(-j-1), check t and the points at which the lines of the words of Lemma A.32 meet (not rigorous)""" a0, b0 = 2*tau_k(k), 2*A_zk(k) bps = {a0, b0, A_check_t(k)} | {2.0**(-j-1) for j in range(1, 40)} | set(A_WORD_BREAKS) D = 3 while 1/(D*(D+1)) > a0 and D < k: bps.add(1/(D*(D+1))); D += 1 bps = sorted(x for x in bps if a0 <= x <= b0) x, w = np.polynomial.legendre.leggauss(nodes) S, W = [], [] for a, b in zip(bps[:-1], bps[1:]): e = np.geomspace(a, b, sub+1) for c, d in zip(e[:-1], e[1:]): sa, sb = log(c), log(d) S.append(0.5*(sb-sa)*x + 0.5*(sb+sa)); W.append(0.5*(sb-sa)*w) S = np.concatenate(S); W = np.concatenate(W) th = A_theta_direct(k, np.exp(S))[0] if cap is not None: th = np.minimum(th, cap) z = A_zk(k) return 2 + log((1-z)/z) + 2*float(np.dot(W, 1/th)) + 1/k - log(TAU_INV*k*z)/k def A_pairs_test(seed=1, ntr=200): """Lemma A.8 on random configurations: exact counts against the bound of the lemma and against the intermediate bounds of its proof. A configuration consists of 3 <= k <= 12, 2 <= D <= k-1 (u = k - D), one to three primes exceeding k, moduli r_1 | r_2 composed of these primes (r_1 = 1 and r_1 = r_2 occur), integers b_1, b_2 coprime to them, an interval of L consecutive integers, which may contain negative ones, and rational numbers delta_1, delta_2 of several sizes; the sets V are the largest class of equivalent integers in the interval and one further class. Returns (number of sets V, number of failures, the largest ratio count/bound, the numbers of configurations with r_1 = 1 and with r_1 = r_2, the number of sets V with pairs of the third kind (r_1 does not divide n - n')).""" rnd = random.Random(seed); Fr = Fraction P = [p for p in range(2, 200) if all(p % d for d in range(2, int(p**0.5) + 1))] def classes_mod_p(p, u): Gam = [w for w in range(1, p) if pow(w, u*(u+1), p) == 1]; label = {} for x in range(1, p): if x in label: continue rp = min(x*w % p for w in Gam) for w in Gam: label[rp*w % p] = w return label def dist(num, q): r = num % q return Fr(min(r, q - r), q) nV = nbad = n1 = neq = nthird = done = 0; worst = Fr(0) while done < ntr: k = rnd.randint(3, 12); D = rnd.randint(2, k-1); u = k - D; J = rnd.choice([1, 1, 2, 2, 3]) ps = rnd.sample([x for x in P if x > k][:6], J); m = 1 for p in ps: m *= p e2 = [rnd.randint(0, 4 if J == 1 else 2) for _ in ps]; e1 = [rnd.randint(0, e) for e in e2]; r1 = r2 = 1 for p, a, b in zip(ps, e1, e2): r1 *= p**a; r2 *= p**b if r2 > 3*10**5: continue def unit(q): while True: b = rnd.randint(1, 10*q + 5) if gcd(b, q) == 1: return b b1, b2 = unit(r1), unit(r2) L = rnd.choice([rnd.randint(5, 60), rnd.randint(60, 400), rnd.randint(400, 900)]); start = rnd.randint(-2*L, 10**4) labs = {p: classes_mod_p(p, u) for p in ps}; cls = {} for n in range(start, start + L): if gcd(n, m) == 1: cls.setdefault(tuple(labs[p][n % p] for p in ps), []).append(n) def rdelta(q): t = rnd.random() if t < 0.3: return Fr(rnd.randint(1, 4), max(1, q))*rnd.choice([1, 1, 2, 3]) if t < 0.6: return Fr(1, rnd.randint(2, 50)) if t < 0.8: return Fr(1, rnd.randint(50, 5000)) return Fr(rnd.randint(1, 9), 10) d1, d2 = rdelta(r1), rdelta(r2); dr2 = sum(1 for d in range(1, r2 + 1) if r2 % d == 0) if r2 <= 2000 else None if dr2 is None: dr2 = 1 for e in e2: dr2 *= e + 1 N1 = lambda dl: Fr(2*L*L, r2) + 4*k**J*dr2*dl*(Fr(L*r2, r1*r1) + Fr(L*L, r1)) def N1mid(dl): # the bound before the last step of the proof tot = Fr(2*L*L, r2) for c in range(r1, r2, r1): if r2 % c == 0: tot += Fr(2*L, c)*2*u**J*dl*(Fr(r2, c) + L) return tot done += 1; n1 += r1 == 1; neq += r1 == r2 if not cls: continue keys = sorted(cls, key=lambda t: -len(cls[t]))[:1] + [rnd.choice(list(cls))] for key in keys: V = cls[key]; pu = {n: n**u for n in V}; pu1 = {n: n**(u+1) for n in V} def count_star(dl): return sum(1 for n in V for n2 in V if n != n2 and (n - n2) % r1 == 0 and dist(b2*(pu1[n] - pu1[n2]), r2) <= dl) M = Md = Ma = Mb = 0 for n in V: for n2 in V: if dist(b1*(pu[n] - pu[n2]), r1) <= d1 and dist(b2*(pu1[n] - pu1[n2]), r2) <= d2: M += 1 if n == n2: Md += 1 elif (n - n2) % r1 == 0: Ma += 1 else: Mb += 1 Ns1 = count_star(d2); Ns2 = count_star(2*d2) bound = L + N1(d2) + 2*d1*(r1*L + (r1 + L)*N1(2*d2)) ok = (Ma == Ns1) and (Ns1 <= N1mid(d2) <= N1(d2)) and (Ns2 <= N1mid(2*d2) <= N1(2*d2)) \ and (Mb <= 2*d1*r1*L + 2*d1*(r1 + L)*Ns2) and (M <= bound) and (Md == len(V) <= L) nV += 1; nbad += not ok; nthird += Mb > 0; worst = max(worst, Fr(M)/bound) return nV, nbad, float(worst), n1, neq, nthird # --- Appendix A: the evaluation with outward rounding. Every floating point operation whose result enters a bound is # followed by a step to the adjacent floating point number in the safe direction (np.nextafter), the logarithm is # allowed an error of A_LOG_ULP units in the last place, and all constants are rounded in the safe direction from # exact fractions. With IEEE 754 arithmetic (rounding to nearest) the numbers returned are therefore rigorous # bounds. The algorithm is that of A_bound (chains, chords, the same subdivision), except that the points of # division are the largest floating point numbers not exceeding 1/(D(D+1)), the subdivision covers a range that # contains [2 tau_k, 2 z_k], and the chords are capped at the lower bound Theta' for Theta^nat(k). from fractions import Fraction as _Fr from math import fsum A_LOG_ULP = 4 _U53 = 2.0**-53 def _dn(x): return np.nextafter(x, -np.inf) def _up(x): return np.nextafter(x, np.inf) def _dnk(x, n): for _ in range(n): x = np.nextafter(x, -np.inf) return x def _upk(x, n): for _ in range(n): x = np.nextafter(x, np.inf) return x def _flo(fr): """the largest floating point number <= the fraction fr""" x = float(fr) return x if _Fr(x) <= fr else float(np.nextafter(x, -np.inf)) def _fup(fr): """the smallest floating point number >= the fraction fr""" x = float(fr) return x if _Fr(x) >= fr else float(np.nextafter(x, np.inf)) def _lin_lo(P_lo, Q_up, R_lo, R_up, t): """a lower bound for (P - Q t)/R, where P >= P_lo, 0 <= Q <= Q_up, 0 < R_lo <= R <= R_up and t >= 0 is exact""" num = _dn(P_lo - _up(Q_up*t)) return np.where(num >= 0, _dn(num/R_up), _dn(num/R_lo)) _A_JC, _A_EC = {}, {} def _A_jconst(D): """the junction conditions l_{D+1} <= r_D as (P - Q t)/R: (P_lo, Q_up, R_lo, R_up) for the three terms of r_D""" if D not in _A_JC: d = _Fr(D); lhs = d*(d+2)/2; q2 = (d+2)*(d+1)*(d+2)/2 terms = [(d+1, d*(d+1) + q2, lhs + d), (d+1, (d+1)*d*(d+1)/(2*d-2) + q2, lhs + (d+1)*(3*d-1)/(2*d-2)), ((d+1)*(d-1)/(d-2), (d+1)*d*(d+1)/(d-2) + q2, lhs + (d+1)*(2*d-1)/(d-2))] _A_JC[D] = [(_flo(P), _fup(Q), _flo(R), _fup(R)) for P, Q, R in terms] return _A_JC[D] def _A_econst(D): """the conditions k vt <= r_D as (P - Q t)/(k + c): (P_lo, Q_up, c_lo, c_up) for the three terms of r_D""" if D not in _A_EC: d = _Fr(D) terms = [(d+1, d*(d+1), d), (d+1, d*(d+1)**2/(2*d-2), (d+1)*(3*d-1)/(2*d-2)), ((d+1)*(d-1)/(d-2), d*(d+1)**2/(d-2), (d+1)*(2*d-1)/(d-2))] _A_EC[D] = [(_flo(P), _fup(Q), _flo(c), _fup(c)) for P, Q, c in terms] return _A_EC[D] _A_TAB = dict(n=2) def _A_tables(Dhi): """the constants of _A_jconst and _A_econst for 3 <= D <= Dhi, as arrays of shape (D-3, term, 4)""" if _A_TAB['n'] < Dhi: n = max(Dhi, 2*_A_TAB['n'], 64) _A_TAB.update(n=n, J=np.array([_A_jconst(D) for D in range(3, n+1)]), E=np.array([_A_econst(D) for D in range(3, n+1)])) return _A_TAB['J'], _A_TAB['E'] def A_junctions_lo(t, Dlo, Dhi): """rigorous lower bounds for the largest vt with l_(D+1) <= r_D at the levels t (rows Dlo <= D < Dhi)""" if Dhi <= Dlo: return np.zeros((0, t.shape[0])) C = _A_tables(Dhi)[0][Dlo-3:Dhi-3] P, Q, Rl, Ru = (C[:, :, i][:, :, None] for i in range(4)) num = _dn(P - _up(Q*t[None, None, :])) return np.where(num >= 0, _dn(num/Ru), _dn(num/Rl)).min(axis=1) def A_ends_lo(k, t, Dlo, Dhi): """rigorous lower bounds for the largest vt with k vt <= r_D at the levels t (rows Dlo <= D <= Dhi)""" C = _A_tables(Dhi)[1][Dlo-3:Dhi-2] P, Q, cl, cu = (C[:, :, i][:, :, None] for i in range(4)) num = _dn(P - _up(Q*t[None, None, :])) return np.where(num >= 0, _dn(num/_up(k + cu)), _dn(num/_dn(k + cl))).min(axis=1) # --- the greedy union and the chains (Lemma A.28(ii)-(iv)): the condition l_D <= R_J(t) between the greedy union # (1, R_J(t)] and a first tent T_D reads vt <= a_1 - a_2 t with a_1 = 2(J+2)/(D^2-1) and # a_2 = (2(2^(J+2)-2)/(D+1) + D(D+1))/(D-1); in Lemma A.28(iv) a_1 is replaced by min{a_1, 1}. def _A_gcoef(J, D): """(a_1, a_2) for the condition l_D <= R_J(t), exactly""" d = _Fr(D) return _Fr(2*(J+2))/(d*d - 1), (2*_Fr(2**(J+2) - 2)/(d + 1) + d*(d + 1))/(d - 1) _A_GT = {} def _A_gtab(Dhi): """arrays A1[J, D-3] <= min{a_1, 1} and A2[J, D-3] >= a_2 (0 <= J <= A_JMAX, 3 <= D <= Dhi), rounded from the exact fractions""" if _A_GT.get('n', 0) < Dhi: n = max(Dhi, 2*_A_GT.get('n', 0), 64) A1 = np.empty((A_JMAX + 1, n - 2)); A2 = np.empty((A_JMAX + 1, n - 2)) for J in range(A_JMAX + 1): for D in range(3, n + 1): a1, a2 = _A_gcoef(J, D); A1[J, D-3] = _flo(min(a1, _Fr(1))); A2[J, D-3] = _fup(a2) _A_GT.update(n=n, A1=A1, A2=A2) return _A_GT['A1'], _A_GT['A2'] def A_greedy_lo(t, Jv, Dhi, both=True): """G[D-3, i] (3 <= D <= Dhi): lower bounds for min{a_1, 1} - a_2 t_i in the condition l_D <= R_J'(t_i), for J' = min{J_i, J_c(D)}, where J_c(D) = floor((D^2-5)/2) is the largest J' with a_1 <= 1, and, if both, the larger of this number and the one for J' = min{J_i, J_c(D) + 1}""" A1, A2 = _A_gtab(Dhi) D = np.arange(3, Dhi + 1); Jc = (D*D - 5)//2; col = (D - 3)[:, None] out = None for off in ((0, 1) if both else (0,)): Jp = np.minimum(np.asarray(Jv)[None, :], (Jc + off)[:, None]) v = _dn(A1[Jp, col] - _up(A2[Jp, col]*t[None, :])) out = v if out is None else np.maximum(out, v) return out def A_RJ_lo(t, Jv): """lower bounds for R_J(t) = J + 2 - (2^(J+2) - 2) t, the right end point of the greedy union (Lemma A.28(ii))""" return _dn((np.asarray(Jv) + 2.0) - _up((np.exp2(np.asarray(Jv) + 2.0) - 2)*t)) # --- the intervals of Definition A.25(e) (prime multipliers, Lemma A.28): for the degree D' the interval is # [l, r] with l = max_i (A0_i + A1_i t + A2_i vt) and r = min_j (B0_j - B1_j t - B2_j vt), where the terms come from # the pairwise conditions between the lower and upper bounds for beta (A_mult_interval); for D' = 3 also # 3 - 24 t - 7 vt >= 0. Chains may end with such an interval: after the greedy union (l <= R_J(t)) or after a tent # T_D with D' = D + 1 (l <= r_D). All conditions have the form vt <= (P - Q t)/R. _A_MC = {} def _A_mult_terms(Dp): """exact (A0, A1, A2) of the lower terms and (B0, B1, B2) of the upper terms of the interval of degree Dp""" if Dp not in _A_MC: d = _Fr(Dp); T1 = d*(d+1) # T' = T1 t lo = [(-1, 1, d), (0, 0, d), (-(d-1)/d, 1, d+1), (-d/(d-1), d/(d-1), d*d/(d-1)), (0, _Fr(1, 3), (2*d-1)/3)] if Dp >= 4: lo.append((-d/(d-3), (d-1)/(d-3), (d*d-d+1)/(d-3))) up = [(2*(d-1)/(d-2), d/(d-2), (3*d-1)/(d-2)), (2, 1, (2*d-1)/(d-1)), (2*d/(d+1), d/(d+1), d/(d+1)), ((d-1)/(d-2), 1/(d-2), (3*d-1)/(d-2)), (d/(d-1), 1/(d-1), (2*d-1)/(d-1)), (d/(d+1), 0, d/(d+1)), (1, 1/(2*(d-1)), (3*d-1)/(2*(d-1))), (1, 1/(d+1), d/(d+1))] L = [((d+1)*_Fr(a), (d+1)*T1*_Fr(g), (d+1)*_Fr(e)) for a, g, e in lo] U = [((d+1)*_Fr(a), (d+1)*T1*_Fr(g), (d+1)*_Fr(e)) for a, g, e in up] _A_MC[Dp] = (L, U) return _A_MC[Dp] def _A_tent_terms(D): """exact (C0, C1, C2) with r_D = min_j (C0_j - C1_j t - C2_j vt) for the tent T_D (as in _A_intervals)""" d = _Fr(D) return [((d+1)*(d-1)/(d-2), (d+1)**2*d/(d-2), (d+1)*(2*d-1)/(d-2)), (d+1, (d+1)**2*d/(2*d-2), (d+1)*(3*d-1)/(2*d-2)), (d+1, d*(d+1), d)] def _A_lin_lo(P, Q, Rl, Ru, t): """rigorous lower bounds for (P - Q t)/R, given P (rounded down), Q (rounded up) and R in [Rl, Ru], R > 0""" num = _dn(P - _up(Q*t)) return np.where(num >= 0, _dn(num/Ru), _dn(num/Rl)) def _A_lin_cap_lo(P, Q, Rl, Ru, t): """rigorous lower bounds for (min{P, R} - Q t)/R, that is, for min{a_1, 1} - a_2 t with a_1 = P/R and a_2 = Q/R (the form in which the conditions enter hat-theta in Lemma A.28(iv)); P rounded down, Q rounded up, R in [Rl, Ru]""" return _A_lin_lo(np.minimum(P, Rl), Q, Rl, Ru, t) _A_MCF = {} def _A_mult_floats(Dp): if Dp not in _A_MCF: L, U = _A_mult_terms(Dp) _A_MCF[Dp] = dict(L=[(_fup(a0), _fup(a1), _flo(a2), _fup(a2)) for a0, a1, a2 in L], U=[(_flo(b0), _fup(b1), _flo(b2), _fup(b2)) for b0, b1, b2 in U], J=[(_flo(c0 - a0), _fup(a1 + c1), _flo(a2 + c2), _fup(a2 + c2)) for a0, a1, a2 in L for c0, c1, c2 in (_A_tent_terms(Dp - 1) if Dp >= 4 else [])]) return _A_MCF[Dp] def A_mult_end_lo(k, t, Dp): """rigorous lower bounds for min{a_1, 1} - a_2 t for the conditions k vt <= r (end of a chain in the interval of degree Dp), including the condition 3 - 24t - 7vt >= 0 for Dp = 3""" k = np.asarray(k, float) out = None for b0, b1, b2l, b2u in _A_mult_floats(Dp)['U']: v = _A_lin_cap_lo(b0, b1, _dn(k + b2l), _up(k + b2u), t) out = v if out is None else np.minimum(out, v) if Dp == 3: out = np.minimum(out, _dn(_dn(3 - _up(24*t))/7)) return out def A_mult_greedy_lo(t, Jv, Dp): """rigorous lower bounds for min{a_1, 1} - a_2 t for the conditions l <= R_J(t) = J + 2 - (2^(J+2) - 2) t between the left end point of the interval of degree Dp and the greedy union""" Jv = np.asarray(Jv, float); out = None for a0, a1, a2l, a2u in _A_mult_floats(Dp)['L']: P = _dn(Jv + 2 - a0); Q = _up(a1 + _up(np.exp2(Jv + 2) - 2)) v = _A_lin_cap_lo(P, Q, a2l, a2u, t) out = v if out is None else np.minimum(out, v) return out _A_MTJ = {} def A_mult_tentjunction_lo(t, D): """rigorous lower bounds for the largest vt with l_D <= r, where l_D = (D+1)(D(D+1)t + (D-1)vt)/2 is the left end point of the tent T_D and r the right end point of the interval of degree D (a chain T_{D-1}, interval of degree D, T_D)""" if D not in _A_MTJ: d = _Fr(D); a1 = (d+1)**2*d/2; a2 = (d+1)*(d-1)/2 _A_MTJ[D] = [(_flo(b0), _fup(a1 + b1), _flo(a2 + b2), _fup(a2 + b2)) for b0, b1, b2 in _A_mult_terms(D)[1]] out = None for P, Q, Rl, Ru in _A_MTJ[D]: v = _A_lin_cap_lo(P, Q, Rl, Ru, t) out = v if out is None else np.minimum(out, v) return out def A_mult_junction_lo(t, Dp): """rigorous lower bounds for the largest vt with l <= r_D, D = Dp - 1 (the interval of degree Dp after the tent T_D)""" out = None for P, Q, Rl, Ru in _A_mult_floats(Dp)['J']: v = _A_lin_cap_lo(P, Q, Rl, Ru, t) out = v if out is None else np.minimum(out, v) return out # --- the intervals Q_{D,iota} of Definition A.25(f) (cancellation in the count of pairs): Q = [max{l_D, D - 1/2}, r^Q], where # r^Q is the least of three terms C0 - C1 t - C2 vt (from E_2, E_6, E_5 >= T); it is defined when D(D+1)t <= 1, # (D+3) vt <= 1/4 and D <= k - 2. A chain may end with T_D, Q_{D,iota}. The conditions are # junction: D - 1/2 <= r_D and l_D <= r_D (three terms of r_D each), and vt <= 1/(4(D+3)); # end: k vt <= r^Q. _A_QC = {} def _A_q_terms(D, io): """exact (C0, C1, C2) with r^Q = min_j (C0_j - C1_j t - C2_j vt) for the interval Q_{D,iota}""" d = _Fr(D); ka = _Fr(1, 2**(io+2) - 2); P = (io+1)*ka; c = d + 1 + 2*P*d return [((d+1)*(d-1)/(d-2), (d+1)**2*d/(d-2), (d+1)*(2*d-1)/(d-2)), (d+1, (d+1)**2*d/(2*d-1), d+1), ((d+1)*(d+1-P-ka)/(d+1-2*P), (d+1)**2*d/(d+1-2*P), (d+1)*c/(d+1-2*P))] def _A_q_floats(D): if D not in _A_QC: d = _Fr(D); a1 = (d+1)**2*d/2; a2 = (d+1)*(d-1)/2 J = [(_flo(c0 - (d - _Fr(1, 2))), _fup(c1), _flo(c2), _fup(c2)) for c0, c1, c2 in _A_tent_terms(D)] J += [(_flo(c0), _fup(a1 + c1), _flo(a2 + c2), _fup(a2 + c2)) for c0, c1, c2 in _A_tent_terms(D)] _A_QC[D] = dict(J=J, cap=_flo(_Fr(1, 4*(D+3))), E={io: [(_flo(c0), _fup(c1), _flo(c2), _fup(c2)) for c0, c1, c2 in _A_q_terms(D, io)] for io in (1, 2)}) return _A_QC[D] def A_q_junction_lo(t, D): """rigorous lower bounds for the largest vt with max{l_D, D - 1/2} <= r_D and (D+3) vt <= 1/4 (the interval Q_{D,iota} after the tent T_D), in the form min{a_1, 1} - a_2 t""" C = _A_q_floats(D); out = np.full(np.shape(t), C['cap']) for P, Q, Rl, Ru in C['J']: out = np.minimum(out, _A_lin_cap_lo(P, Q, Rl, Ru, t)) return out def A_q_end_lo(k, t, D, io): """rigorous lower bounds for the largest vt with k vt <= r^Q (end of a chain in the interval Q_{D,iota})""" k = np.asarray(k, float); out = None for c0, c1, c2l, c2u in _A_q_floats(D)['E'][io]: v = _A_lin_cap_lo(c0, c1, _dn(k + c2l), _up(k + c2u), t) out = v if out is None else np.minimum(out, v) return out def A_q_alt_lo(k, t, D): """the better of the two chains that end with T_D, Q_{D,iota}, iota = 1, 2: lower bounds for vt (without the conditions for reaching T_D); -inf where D > k - 2""" k = np.asarray(k, float) v = np.minimum(A_q_junction_lo(t, D), np.maximum(A_q_end_lo(k, t, D, 1), A_q_end_lo(k, t, D, 2))) return np.where(D <= k - 2, v, -np.inf) # --- the intervals N_{D,iota} of Definition A.25(g) (prime multipliers with cancellation, Corollary A.24): for # U >= (D+1)(1 + (D-1)vt)/2, U/(D+1) + vt <= 1 and (D+3) vt <= 1/4 the number in (g) is the maximum over # 0 <= beta <= 1 - U/(D+1) - vt of min{1 + beta, G_1, G_3, E_5', E_6', E_7, E_8, E_9}/(D(D+1)), where each term X other # than 1 + beta has the form x0 + xU U + xb beta + xv vt with xU < 0, xb < 0, xv < 0. The interval of the U with # (g) >= t is N = [(D+1)(1 + (D-1)vt)/2, r^N], where r^N is the least of the 14 terms (x0 + xb L + xv vt - T)/(-xU), # L in {0, T - 1}, T = D(D+1)t (beta = max{0, T - 1} is the best choice); N is empty if (D+3) vt > 1/4. A chain # may end with N_{D+1,iota} after a tent T_D, or with N_{D',iota} directly after the greedy union (1, R_J(t)]. A_MCANCEL_ON = True # Definition A.25(g) (prime multipliers with cancellation, Corollary A.24) is used def _A_n_xterms(D, io): """the terms X of (g) for the degree D and iota = io, exactly: list of (name, x0, xU, xb, xv)""" d = _Fr(D); u = 1/(d + 1); ka = _Fr(1, 2**(io + 2) - 2) X = [('G1', d - 1, -(d - 2)*u, -(d - 1), -(3*d - 1)), ('G3', d, -(d - 1)*u, -(d - 2), -(2*d - 1)), ('E5', d + 1 - (io + 2)*ka, -1 + 2*(io + 1)*ka*u, -(d - 1 + (io + 2)*ka), -(d + 1 + 2*(io + 1)*ka*d)), ('E6', 2*d - 1, -(2*d - 1)*u, -(2*d - 1), -(2*d - 1))] if io == 1: X += [('E7', d + 1, -1 + _Fr(2, 9)*u, -(d - 1), -(_Fr(11, 9)*d + _Fr(7, 6))), ('E8', d + _Fr(1, 2), -1 + u, -(d - _Fr(1, 2)), -(2*d + _Fr(3, 2)))] else: X += [('E7', d + 1 + _Fr(1, 42), -1 + _Fr(1, 21)*u, -(d - 1), -(_Fr(22, 21)*d + _Fr(5, 4))), ('E8', d + _Fr(1, 3), -1 + u, -(d - _Fr(1, 3)), -(2*d + _Fr(7, 6)))] X.append(('E9', d, -1 + 2*u, -d, -2*d)) return X def A_mcancel_items(U, vt, D, io): """the number in (g) of Definition A.25 for the degrees D (array, same shape as U) and iota = io, or 0 where it is not admitted (floating point, from the definition)""" U = np.asarray(U, float); D = np.asarray(D, float); U1 = U/(D + 1) ok = (U >= 0.5*(D + 1)*(1 + (D - 1)*vt)) & (U1 + vt <= 1) & ((D + 3)*vt <= 0.25) & (D >= 3) bmax = np.maximum(1 - U1 - vt, 0.0) out = np.zeros_like(U) for Dv in np.unique(D): sel = D == Dv X = [(float(x0), float(xU), float(xb), float(xv)) for _, x0, xU, xb, xv in _A_n_xterms(int(Dv), io)] Us = U[sel] bstar = np.min([(x0 + xU*Us + xv*vt - 1)/(1 - xb) for x0, xU, xb, xv in X], axis=0) # where 1 + beta meets X b = np.clip(bstar, 0.0, bmax[sel]) val = np.minimum(1 + b, np.min([x0 + xU*Us + xb*b + xv*vt for x0, xU, xb, xv in X], axis=0)) out[sel] = np.maximum(val, 0.0)/(Dv*(Dv + 1)) return np.where(ok, out, 0.0) _A_NC = {} def _A_n_terms(D, io): """exact (C0, C1, C2) with r^N = min_j (C0_j - C1_j t - C2_j vt) for the interval N_{D,iota}""" if (D, io) not in _A_NC: d = _Fr(D); T1 = d*(d + 1); out = [] for _, x0, xU, xb, xv in _A_n_xterms(D, io): out.append((x0/(-xU), T1/(-xU), -xv/(-xU))) # L = 0 out.append(((x0 - xb)/(-xU), T1*(1 - xb)/(-xU), -xv/(-xU))) # L = T - 1 _A_NC[(D, io)] = out return _A_NC[(D, io)] def A_mcancel_interval(D, io, t, vt): """the interval [l, r] of the U with (g)(U, vt) >= t for the degree D and iota = io (arrays t, vt; l = inf, r = -inf if it is empty or not defined), floating point""" t = np.asarray(t, float); v = np.asarray(vt, float) l = 0.5*(D + 1)*(1 + (D - 1)*v) r = np.min([float(c0) - float(c1)*t - float(c2)*v for c0, c1, c2 in _A_n_terms(D, io)], axis=0) ok = ((D + 3)*v <= 0.25) & (l <= r) return np.where(ok, l, np.inf), np.where(ok, r, -np.inf) _A_NCF = {} def _A_n_floats(D): """floating point bounds for the conditions of the chains that end with N_{D,iota}: 'J' the junction with the tent T_{D-1} (l^N <= each term of r_{D-1}), 'E'[io] the end conditions k vt <= each term of r^N, 'cap' 1/(4(D+3))""" if D not in _A_NCF: d = _Fr(D); h0 = (d + 1)/2; h2 = (d + 1)*(d - 1)/2 J = [(_flo(c0 - h0), _fup(c1), _flo(c2 + h2), _fup(c2 + h2)) for c0, c1, c2 in _A_tent_terms(D - 1)] if D >= 4 else [] _A_NCF[D] = dict(J=J, cap=_flo(_Fr(1, 4*(D + 3))), h0=h0, h2lo=_flo(h2), h2up=_fup(h2), E={io: [(_flo(c0), _fup(c1), _flo(c2), _fup(c2)) for c0, c1, c2 in _A_n_terms(D, io)] for io in (1, 2)}) return _A_NCF[D] def A_n_junction_lo(t, D): """rigorous lower bounds for the largest vt with l^N <= r_{D-1} and (D+3) vt <= 1/4 (the interval N_{D,iota} after the tent T_{D-1}), in the form min{a_1, 1} - a_2 t""" C = _A_n_floats(D); out = np.full(np.shape(t), C['cap']) for P, Q, Rl, Ru in C['J']: out = np.minimum(out, _A_lin_cap_lo(P, Q, Rl, Ru, t)) return out def A_n_greedy_lo(t, Jv, D): """rigorous lower bounds for the largest vt with l^N <= R_J(t) and (D+3) vt <= 1/4 (the interval N_{D,iota} directly after the greedy union), in the form min{a_1, 1} - a_2 t""" C = _A_n_floats(D); Jv = np.asarray(Jv, float) P = _dn(Jv + 2 - _fup(C['h0'])); Q = _up(np.exp2(Jv + 2) - 2) return np.minimum(C['cap'], _A_lin_cap_lo(P, Q, C['h2lo'], C['h2up'], t)) def A_n_end_lo(k, t, D, io): """rigorous lower bounds for the largest vt with k vt <= r^N (end of a chain in the interval N_{D,iota})""" k = np.asarray(k, float); out = None for c0, c1, c2l, c2u in _A_n_floats(D)['E'][io]: v = _A_lin_cap_lo(c0, c1, _dn(k + c2l), _up(k + c2u), t) out = v if out is None else np.minimum(out, v) return out def A_n_endbest_lo(k, t, D): """the better of the two ends N_{D,1}, N_{D,2}: lower bounds for vt (without the conditions for reaching N); -inf where D > k - 2""" k = np.asarray(k, float) v = np.maximum(A_n_end_lo(k, t, D, 1), A_n_end_lo(k, t, D, 2)) return np.where(D <= k - 2, v, -np.inf) # --- the chains that begin with an interval of Definition A.25(d) (Lemma A.28(iii), (iv)): for a word w and a variant # (gamma, delta) the interval is [1 + c_w vt, R(t, vt)] with R = (P - t - delta vt)/gamma, P = 1 - lambda_w + kappa_w. # The conditions are (all of the form vt <= a_1 - a_2 t with a_2 >= 0): # start: vt <= vt_w (w begins with A), or 1 + c_w vt <= R_J(t), that is vt <= (J + 1 - (2^(J+2) - 2) t)/c_w, with # J + 1 replaced by min{J + 1, c_w} (w begins with B); # end: k vt <= R(t, vt), that is vt <= (P - t)/(k gamma + delta) (for variant 2, k gamma + delta = k kappa); # first tent T_D: l_D <= R(t, vt), that is vt <= (P - t(1 + gamma D (D+1)^2/2))/(gamma (D^2 - 1)/2 + delta). _A_WFAM = {} def _A_wfam(): """the words of W with their exact data and the least k for which the condition of Proposition A.15 holds for all k' >= k (checked up to 10^4 below) and for which variant 2 is available (kappa (k - E + 1) >= 1)""" if 'x' not in _A_WFAM: out = [] for d in A_WORDS: bad = [k for k in range(2, 200) if not A_word_ok(d['w'], k)] k_ok = max(bad) + 1 if bad else 2 k2 = d['E'] - 1 + int(np.ceil(float(1/d['kap']) - 1e-12)) while d['kap']*(k2 - d['E'] + 1) < 1: k2 += 1 while k2 - 1 >= 1 and d['kap']*(k2 - 1 - d['E'] + 1) >= 1: k2 -= 1 out.append(dict(d, kok=k_ok, k2=k2, P=1 - d['lam'] + d['kap'])) _A_WFAM['x'] = out return _A_WFAM['x'] def _A_word_floats(d, Dtop): """cached floating point bounds for the exact data of a word: P, kappa, c_w, vartheta_w, and for the tents T_D (3 <= D <= Dtop) of variant 1 the numbers Q = 1 + kappa D (D+1)^2/2 (rounded up) and R = kappa (D^2 - 1)/2 + 1/2 (rounded down and up)""" c = d.get('_fl') if c is None: P = d['P']; ka = d['kap'] c = dict(Pf=float(P), kaf=float(ka), Plo=_flo(P), klo=_flo(ka), kup=_fup(ka), D=2, cwlo=_flo(d['cU']) if d['cU'] > 0 else None, cwup=_fup(d['cU']) if d['cU'] > 0 else None, vmlo=_flo(d['vmax']) if d['cU'] == 0 else None, Q1=np.zeros(0), R1lo=np.zeros(0), R1up=np.zeros(0)) d['_fl'] = c if c['D'] < Dtop: ka = d['kap']; D0 = c['D'] + 1; D1 = max(Dtop, 2*c['D']) Q = [_fup(1 + ka*D*(D+1)**2/2) for D in range(D0, D1 + 1)] R = [ka*(D*D - 1)/2 + _Fr(1, 2) for D in range(D0, D1 + 1)] c['Q1'] = np.concatenate([c['Q1'], np.array(Q)]); c['R1lo'] = np.concatenate([c['R1lo'], np.array([_flo(x) for x in R])]) c['R1up'] = np.concatenate([c['R1up'], np.array([_fup(x) for x in R])]); c['D'] = D1 return c def A_pair_conds_lo(kv, tv, Jv, Dtop): """rigorous lower bounds, for each element (k, t, J), for the values min{start, end} of the chains that consist of the greedy union (1, R_J(t)] (only if c_w > 0) and an interval of (d), and, for 3 <= D <= Dtop, for the values min{start, first tent T_D} (row D - 3); the maximum over the words and their variants. -inf where no word is usable. Only the words with R(t, 0) > R_J(t) for some element are considered (the others are never better than the greedy union). The tents are treated for all D at once (two-dimensional arrays).""" kv = np.asarray(kv, float); tv = np.asarray(tv, float); Jv = np.asarray(Jv, int); n = tv.size end_best = np.full(n, -np.inf); m = max(Dtop - 2, 0); tent_best = np.full((m, n), -np.inf) if not A_PAIRS_ON or n == 0: return end_best, tent_best RJ = Jv + 2.0 - (np.exp2(Jv + 2.0) - 2)*tv Ds = np.arange(3, Dtop + 1, dtype=np.float64)[:, None]; fD = Ds*(Ds+1)**2/2.0; g2D = (Ds*Ds - 1)/2.0 t2 = tv[None, :] for d in _A_wfam(): if not np.any(kv >= d['kok']): continue c = _A_word_floats(d, Dtop) if not np.any((c['Pf'] - tv)/c['kaf'] > RJ - 1e-9): continue ok = kv >= d['kok'] if d['cU'] > 0: a1 = np.minimum(Jv + 1.0, c['cwlo']) # a lower bound for min{J + 1, c_w} st = _lin_lo(a1, np.exp2(Jv + 2.0) - 2, c['cwlo'], c['cwup'], tv) else: st = np.full(n, c['vmlo']) st = np.where(ok, st, -np.inf) Plo, klo, kup = c['Plo'], c['klo'], c['kup'] # variant 1: (gamma, delta) = (kappa, 1/2) en = _lin_lo(Plo, 1.0, _dn(_dn(kv*klo) + 0.5), _up(_up(kv*kup) + 0.5), tv) end_best = np.maximum(end_best, np.minimum(st, en)) if m: v1 = _lin_lo(Plo, c['Q1'][:m, None], c['R1lo'][:m, None], c['R1up'][:m, None], t2) tent_best = np.maximum(tent_best, np.minimum(st[None, :], v1)) # variant 2: (gamma, delta) = (kappa - 1/(2c), k/(2c)), c = k - E + 1, when kappa c >= 1 ok2 = ok & (kv >= d['k2']) if np.any(ok2): cc = np.where(ok2, kv - d['E'] + 1.0, 1.0); h = np.where(ok2, 0.5/cc, 0.0); hlo, hup = _dn(h), _up(h) glo = _dn(klo - hup); gup = _up(kup - hlo); dlo = _dn(kv*hlo); dup = _up(kv*hup) en2 = _lin_lo(Plo, 1.0, _dn(kv*klo), _up(kv*kup), tv) end_best = np.maximum(end_best, np.where(ok2, np.minimum(st, en2), -np.inf)) if m: Qup = _up(1 + _up(gup[None, :]*fD)); Rlo = _dn(_dn(glo[None, :]*g2D) + dlo[None, :]) Rup = _up(_up(gup[None, :]*g2D) + dup[None, :]) v2 = _lin_lo(Plo, Qup, Rlo, Rup, t2) tent_best = np.maximum(tent_best, np.where(ok2[None, :], np.minimum(st[None, :], v2), -np.inf)) return end_best, tent_best def A_pair_rows_lo(k, t, J, Dband, Jn=None, E=None): """for Section A.8: rigorous lower bounds for the values (capped at k/2 by the caller) of the chains that begin with an interval of (d): for each relevant word and variant one row for the chain without tents and one row for each chain with the tents T_D1, ..., T_D2, 3 <= D1 <= min{Dband, A_D1F}, D1 <= D2 <= Dband. Each row is the least of finitely many conditions vt <= a_1 - a_2 t with a_2 >= 0, multiplied by k, so it is concave in t.""" rows = [] if not A_PAIRS_ON: return rows n = t.size; kv = np.full(n, float(k)); Jv = np.full(n, J) RJ = J + 2.0 - (2.0**(J+2) - 2)*t D1top = min(Dband, A_D1F) if Dband >= 3 else 2 if Dband >= 3 and Jn is None: Jn = A_junctions_lo(t, 3, Dband) if Dband >= 4 else np.zeros((0, n)) if Dband >= 3 and E is None: E = A_ends_lo(k, t, 3, Dband) for d in _A_wfam(): if k < d['kok']: continue P = d['P']; ka = d['kap']; Pf = float(P) if not np.any((Pf - t)/float(ka) > RJ - 1e-9): continue cf = _A_word_floats(d, max(D1top, 3)) if d['cU'] > 0: st = _lin_lo(min(J + 1.0, cf['cwlo']), 2.0**(J+2) - 2, cf['cwlo'], cf['cwup'], t) else: st = np.full(n, cf['vmlo']) Plo = cf['Plo']; klo, kup = cf['klo'], cf['kup'] variants = [('1', _lin_lo(Plo, 1.0, _dn(_dn(k*klo) + 0.5), _up(_up(k*kup) + 0.5), t), None)] if k >= d['k2']: c = float(k - d['E'] + 1); h = 0.5/c; hlo, hup = _dn(h), _up(h) glo = _dn(klo - hup); gup = _up(kup - hlo); dlo = _dn(k*hlo); dup = _up(k*hup) variants.append(('2', _lin_lo(Plo, 1.0, _dn(k*klo), _up(k*kup), t), (glo, gup, dlo, dup))) for name, en, g in variants: rows.append(_dn(k*np.minimum(st, en))) for D1 in range(3, D1top + 1): if g is None: f1 = _lin_lo(Plo, cf['Q1'][D1 - 3], cf['R1lo'][D1 - 3], cf['R1up'][D1 - 3], t) else: glo, gup, dlo, dup = g; f = D1*(D1+1)**2/2.0; g2 = (D1*D1 - 1)/2.0 f1 = _lin_lo(Plo, _up(1 + _up(gup*f)), _dn(_dn(glo*g2) + dlo), _up(_up(gup*g2) + dup), t) cur = np.minimum(st, f1) for D2 in range(D1, Dband + 1): if D2 > D1: cur = np.minimum(cur, Jn[D2 - 4]) rows.append(_dn(k*np.minimum(cur, E[D2 - 3]))) return rows _A_PT = {} def A_points_table(Dm): """the array of the numbers _A_point(D), 3 <= D <= Dm (index D - 3)""" if _A_PT.get('n', 0) < Dm: n = max(Dm, 2*_A_PT.get('n', 0), 64); _A_PT.update(n=n, p=np.array([_A_point(D) for D in range(3, n + 1)])) return _A_PT['p'] def A_theta_hat_lo(kv, tv, Jv, Dv): """rigorous lower bounds for theta_k(t) (Lemma A.28(iii), (iv)): for each element the largest of the values hat-theta(t) that belong to the choices J' <= J without tents and J' <= J with tents T_D1, ..., T_D2, 3 <= D1 <= D2 <= D (D < 3: no tents), capped at k/2 and at least 1. The value is computed with the recursion best(D) = max{g(D), min{best(D-1), junction(D-1)}} over the first tent. The conditions under which these are lower bounds are enforced: 2^(J+1) t <= 1, 0 <= J <= k - 2, and, for D >= 3, D <= k - 1 and t <= 1/(D(D+1)).""" kv = np.asarray(kv, float); tv = np.asarray(tv, float); Jv = np.asarray(Jv, int); Dv = np.asarray(Dv, int) _require(bool(np.all(Jv >= 0)) and bool(np.all(Jv <= np.minimum(kv - 2, A_JMAX))) and bool(np.all(np.exp2(Jv + 1.0)*tv <= 1)), "A_theta_hat_lo: a greedy interval is not available at some level") th = A_RJ_lo(tv, Jv) Dm = int(Dv.max()) if Dv.size else 0 pend, ptent = A_pair_conds_lo(kv, tv, Jv, min(max(Dm, 2), A_D1F)) th = np.maximum(th, _dn(kv*pend)) # the chains that end in an interval of (d) if Dm >= 3: pts = A_points_table(Dm)[np.maximum(Dv, 3) - 3] _require(bool(np.all((Dv < 3) | ((Dv <= kv - 1) & (tv <= pts)))), "A_theta_hat_lo: a tent is not defined at some level") G = A_greedy_lo(tv, Jv, Dm); E = A_ends_lo(kv, tv, 3, Dm) mt = ptent.shape[0] if mt: G[:mt] = np.maximum(G[:mt], np.where(np.arange(3, mt + 3)[:, None] <= Dv[None, :], ptent, -np.inf)) Jn = A_junctions_lo(tv, 3, Dm) if Dm >= 4 else None if A_MULT_ON: # chains that end with the interval of degree D + 1 after T_D for D in range(3, Dm + 1): okD = (Dv >= D) & (D + 1 <= kv - 1) alt = np.minimum(A_mult_junction_lo(tv, D + 1), A_mult_end_lo(kv, tv, D + 1)) E[D-3] = np.where(okD, np.maximum(E[D-3], alt), E[D-3]) for D in range(4, Dm + 1): # junctions T_{D-1}, interval of degree D, T_D okD = D <= kv - 1 alt = np.minimum(A_mult_junction_lo(tv, D), A_mult_tentjunction_lo(tv, D)) Jn[D-4] = np.where(okD, np.maximum(Jn[D-4], alt), Jn[D-4]) if A_CANCEL_ON: # chains that end with the interval Q_{D,iota} after T_D for D in range(3, Dm + 1): okD = Dv >= D E[D-3] = np.where(okD, np.maximum(E[D-3], A_q_alt_lo(kv, tv, D)), E[D-3]) if A_MCANCEL_ON: # chains that end with the interval N_{D+1,iota} after T_D for D in range(3, Dm + 1): okD = (Dv >= D) & (D + 1 <= kv - 2) alt = np.minimum(A_n_junction_lo(tv, D + 1), A_n_endbest_lo(kv, tv, D + 1)) E[D-3] = np.where(okD, np.maximum(E[D-3], alt), E[D-3]) best = G[0].copy(); val = np.where(Dv >= 3, np.minimum(best, E[0]), -np.inf) for D in range(4, Dm + 1): best = np.maximum(G[D-3], np.minimum(best, Jn[D-4])) val = np.where(Dv >= D, np.maximum(val, np.minimum(best, E[D-3])), val) th = np.maximum(th, _dn(kv*val)) if A_MULT_ON: # chains: greedy union, then the interval of degree D' (3 <= D' <= 8) for Dp in range(3, 9): okD = Dp <= kv - 1 v = np.minimum(A_mult_greedy_lo(tv, Jv, Dp), A_mult_end_lo(kv, tv, Dp)) th = np.maximum(th, np.where(okD, _dn(kv*v), 1.0)) if A_MCANCEL_ON: # chains: greedy union, then N_{D',iota} (3 <= D' <= 8) for Dp in range(3, 9): okD = Dp <= kv - 2 v = np.minimum(A_n_greedy_lo(tv, Jv, Dp), A_n_endbest_lo(kv, tv, Dp)) th = np.maximum(th, np.where(okD, _dn(kv*v), 1.0)) th = np.minimum(th, kv/2) return np.maximum(th, 1.0) def A_band_static_lo(t, J, Dband): """the parts of the chains of Section A.8 that do not depend on k, at the levels t of a piece with the family (J, Dband): the values R_J(t) (no tent), and for each D1 <= A_D1F an array whose row D2 - D1 is the least of the conditions, as numbers vt, for the chain with the tents T_D1, ..., T_D2 other than the condition at its end; the first condition is l_D1 <= R_J'(t) with J' = min{J, J_c(D1)}, so that a_1 <= 1 and each chain is concave in t""" n = t.shape[0]; Jv = np.full(n, J) out = dict(RJ=A_RJ_lo(t, Jv), fams=[]) if Dband >= 3: G = A_greedy_lo(t, Jv, Dband, both=False) Jn = A_junctions_lo(t, 3, Dband) if Dband >= 4 else np.zeros((0, n)) for D1 in range(3, min(Dband, A_D1F) + 1): out['fams'].append((D1, np.minimum.accumulate(np.vstack([G[D1-3][None, :], Jn[D1-3:]]), axis=0))) out['Jn'] = Jn if A_MULT_ON: # the same chains with every junction T_{D-1}, T_D bridged by the interval of degree D (Definition A.25(e)); # the junction is then the least of the two conditions of the bridge, so each row stays concave in t Jb = np.vstack([np.minimum(A_mult_junction_lo(t, D), A_mult_tentjunction_lo(t, D)) for D in range(4, Dband + 1)]) \ if Dband >= 4 else np.zeros((0, n)) out['famsb'] = [(D1, np.minimum.accumulate(np.vstack([G[D1-3][None, :], Jb[D1-3:]]), axis=0)) for D1 in range(3, min(Dband, A_D1F) + 1)] # the junctions T_D, interval of degree D + 1 (for the chains that end in that interval) out['JM'] = np.vstack([A_mult_junction_lo(t, D + 1) for D in range(3, Dband + 1)]) if A_CANCEL_ON: # the junctions T_D, Q_{D,iota} (for the chains that end in Q_{D,iota}) out['JQ'] = np.vstack([A_q_junction_lo(t, D) for D in range(3, Dband + 1)]) if A_MCANCEL_ON: # the junctions T_D, N_{D+1,iota} (for the chains that end in N_{D+1,iota}) out['JN'] = np.vstack([A_n_junction_lo(t, D + 1) for D in range(3, Dband + 1)]) if A_MULT_ON: # the greedy union followed by the interval of degree D' (3 <= D' <= 8) out['GM'] = [(Dp, A_mult_greedy_lo(t, Jv, Dp)) for Dp in range(3, 9)] if A_MCANCEL_ON: # the greedy union followed by N_{D',iota} (3 <= D' <= 8) out['GN'] = [(Dp, A_n_greedy_lo(t, Jv, Dp)) for Dp in range(3, 9)] return out def A_band_values_lo(k, t, J, Dband, static=None): """rigorous lower bounds for the values of the chains of Section A.8 at the levels t, one row for each chain, capped at k/2. Requirements, enforced: 0 <= J <= k - 2 and 2^(J+1) t <= 1; if Dband >= 3, Dband <= k - 1 and t <= 1/(Dband(Dband+1)).""" _require(0 <= J <= min(k - 2, A_JMAX) and bool(np.all(2.0**(J+1)*t <= 1)), "A_band_values_lo: the greedy union is not available") _require(Dband < 3 or (Dband <= k - 1 and bool(np.all(t <= _A_point(Dband)))), "A_band_values_lo: a tent is not defined at some level") if static is None: static = A_band_static_lo(t, J, Dband) rows = [static['RJ'][None, :]]; E = None if Dband >= 3: E = A_ends_lo(k, t, 3, Dband) if A_MULT_ON: EM = np.vstack([A_mult_end_lo(k, t, D + 1) if D + 1 <= k - 1 else np.full(t.size, -np.inf) for D in range(3, Dband + 1)]) EMJ = np.minimum(EM, static['JM']) # end in the interval of degree D + 1, after T_D EQJ = [] if A_CANCEL_ON: # end in the interval Q_{D,iota}, after T_D for io in (1, 2): EQ = np.vstack([A_q_end_lo(k, t, D, io) if D <= k - 2 else np.full(t.size, -np.inf) for D in range(3, Dband + 1)]) EQJ.append(np.minimum(EQ, static['JQ'])) if A_MCANCEL_ON: # end in the interval N_{D+1,iota}, after T_D for io in (1, 2): EN = np.vstack([A_n_end_lo(k, t, D + 1, io) if D + 1 <= k - 2 else np.full(t.size, -np.inf) for D in range(3, Dband + 1)]) EQJ.append(np.minimum(EN, static['JN'])) for D1, c in static['fams']: rows.append(_dn(k*np.minimum(c, E[D1-3:]))) if A_MULT_ON: rows.append(_dn(k*np.minimum(c, EMJ[D1-3:]))) for eq in EQJ: rows.append(_dn(k*np.minimum(c, eq[D1-3:]))) if A_MULT_ON: for D1, c in static['famsb']: rows.append(_dn(k*np.minimum(c, E[D1-3:]))); rows.append(_dn(k*np.minimum(c, EMJ[D1-3:]))) for eq in EQJ: rows.append(_dn(k*np.minimum(c, eq[D1-3:]))) if A_MULT_ON: for Dp, g in static['GM']: if Dp <= k - 1: rows.append(_dn(k*np.minimum(g, A_mult_end_lo(k, t, Dp)))[None, :]) if A_MCANCEL_ON: for Dp, g in static['GN']: if Dp <= k - 2: for io in (1, 2): rows.append(_dn(k*np.minimum(g, A_n_end_lo(k, t, Dp, io)))[None, :]) pr = A_pair_rows_lo(k, t, J, Dband, static.get('Jn'), E) if pr: rows.append(np.vstack(pr)) return np.minimum(np.vstack(rows), k/2.0) def A_cell_sum_up(edges, th, cap): """a rigorous upper bound for the integral of dt/(t min{cap, theta_k(t)}) over [edges[0], edges[-1]], where the rows of th are lower bounds for the values of the chains at the edges (cf. A_cell_sum)""" t1, t2 = edges[:-1], edges[1:] a = np.minimum(th[:, :-1], cap); b = np.minimum(th[:, 1:], cap) a = np.maximum(a, b) # still a lower bound at t1, since each chain value is nonincreasing good = b > 1.0 am = np.where(good, a, 0.0); bm = np.where(good, b, 0.0) cols = np.arange(a.shape[1]); best = np.full(a.shape[1], np.inf) for idx in (am.argmax(axis=0), bm.argmax(axis=0), (am+bm).argmax(axis=0)): aa, bb = am[idx, cols], bm[idx, cols]; ok = bb > 1.0 aa = np.where(ok, aa, 2.0); bb = np.where(ok, bb, 2.0) L = _upk(np.log(_up(_up(t2*aa)/_dn(t1*bb))), A_LOG_ULP) A = _dn(_dn(_dn(aa*t2) - _up(bb*t1))/_up(t2 - t1)) c = _up(L/A) best = np.minimum(best, np.where(ok & (A > 0), c, np.inf)) _require(np.all(np.isfinite(best)), "no chain is usable on some cell") n = best.size return float(_up(float(np.sum(best))*(1 + 4*n*_U53))) _A_PD = {} def _A_point(D): """the largest floating point number <= 1/(D(D+1))""" if D not in _A_PD: _A_PD[D] = _flo(_Fr(1, D*(D+1))) return _A_PD[D] def A_tau2_exact(k): return _Fr(2*10**6, 9027901*k) def A_zk_exact(k): return _Fr(1, 10) if k < 5000 else A_ZSEED _A_DIV = {} def A_divpoints(Dmax): """the points of division, ascending: the floating point numbers _A_point(D) <= 1/(D(D+1)) for 3 <= D <= Dmax, and the numbers 2^(-j-1) for 1 <= j <= A_JMAX""" if Dmax not in _A_DIV: _A_DIV[Dmax] = np.array(sorted(set([_A_point(D) for D in range(3, Dmax + 1)] + [2.0**(-j-1) for j in range(1, A_JMAX + 1)]))) return _A_DIV[Dmax] def A_Jof(b, kv): """J = min{k - 2, A_JMAX, the largest J >= 0 with 2^(J+1) b <= 1}, for arrays b <= 1/2 and kv""" b = np.asarray(b, float) J = np.floor(-np.log2(b)).astype(int) - 1 for _ in range(3): J = np.where(np.exp2(J + 1.0)*b > 1, J - 1, J); J = np.where(np.exp2(J + 2.0)*b <= 1, J + 1, J) _require(bool(np.all(np.exp2(J + 1.0)*b <= 1)) and bool(np.all(np.exp2(J + 2.0)*b > 1)) and bool(np.all(J >= 0))) return np.minimum(np.minimum(J, np.asarray(kv, float).astype(int) - 2), A_JMAX) _A_PDESC = {} def A_Dof(b, Dlimv): """the largest D with 3 <= D <= Dlim and b <= _A_point(D), or 0""" Dm = int(np.max(Dlimv)) if Dm not in _A_PDESC: _A_PDESC[Dm] = np.array([_A_point(D) for D in range(Dm, 2, -1)]) # ascending p = _A_PDESC[Dm] cnt = p.size - np.searchsorted(p, b, side='left') # the number of D in [3, Dm] with b <= _A_point(D) D = np.where(cnt == 0, 0, cnt + 2) return np.where(D > Dlimv, Dlimv, D) def A_family(b, kv, Dlimv): """(J, D) of the piece of a subdivision at the points of A_divpoints whose right end point is b: the chains of this family are defined on the whole piece (D = 0: no tents)""" D = A_Dof(b, Dlimv) return A_Jof(b, kv), np.where(D >= 3, D, 0) def A_kink(k): """the point (7k+408)/(110k+1936), rounded, at which the chain of the word AABABABAA and the chain that ends with the tent T_3 give the same value when k is large (it is kept as a point of the subdivisions; with the intervals Q_{3,iota} of Definition A.25(f) neither of the two chains is the best one there)""" return _flo(_Fr(7*k+408, 110*k+1936)) def A_tQ_exact(D, io): """t_D^(iota) of Section A.3, exactly: the point at which phi_{D,iota}(t) = (D+1)(2 - (D+1)(D+2)t)""" return _Fr(6*D + 1, 2*(D + 1)*(3*D*D + 4*D + 2)) if io == 1 else _Fr(7*D + 3, (D + 1)*(7*D*D + 11*D + 8)) def A_kinks(k, Dl): """the points that are inserted in the subdivision of Section A.8 (rounded), as pairs (point, depends on k): check t_3 of Lemma A.32 and the point A_kink(k); the points 17/190, 3/52, 9/560 and t_D^(iota) (4 <= D < Dl; iota = 2 for D <= 6 and iota = 1 for D >= 7) at which the pieces of theta^star meet (Section A.3); and the points 37/638 and 1/(D^2+2D+2) (4 <= D < Dl), at which they meet when the numbers (f) of Definition A.25 are left out (these matter for the degrees D for which (f) is not available at the level in question)""" pts = [(_flo(_Fr(7*k+408, 110*k+1936)), True), (_flo(_Fr(k+18, 12*k+126)), True), (_flo(_Fr(17, 190)), False), (_flo(_Fr(37, 638)), False), (_flo(_Fr(3, 52)), False), (_flo(_Fr(9, 560)), False)] \ + [(_flo(_Fr(1, D*D+2*D+2)), False) for D in range(4, Dl)] + [(_flo(A_tQ_exact(D, 2 if D <= 6 else 1)), False) for D in range(4, Dl)] if A_MCANCEL_ON: pts += [(_flo(_Fr(3, 34)), False), (_flo(_Fr(3, 55)), False)] for D in range(4, Dl): pts += [(_flo(pc[1]), False) for pc in A_band_pieces(D)[:-1]] return sorted(set(pts)) def A_grid_rig(k, refine=1, rtop=None, rband=None, rtail=None): """the subdivision of a range [t_-, t^+] that contains [2 tau_k, 2 z_k], for Section A.8: a list of quadruples (edges, J, D, std), one for each piece between consecutive points of A_divpoints(A_Dlim(k)); (J, D) is the family of the piece, and std is True when the edges do not depend on k. Above 1/12 there are A_MTOP cells, in the band of each D about A_M cells, and below the last band A_MTAIL cells; the points of A_kinks are inserted where they fall.""" rtop = rtop or refine; rband = rband or refine; rtail = rtail or refine tlo = _flo(A_tau2_exact(k)); thi = _fup(2*A_zk_exact(k)); Dl = A_Dlim(k); kcs = A_kinks(k, Dl); p3 = _A_point(3) pts = [float(x) for x in A_divpoints(Dl) if tlo < x < thi] bnd = [tlo] + pts + [thi]; pDl = _A_point(Dl) out = [] for a, b in zip(bnd[:-1], bnd[1:]): J, D = A_family(np.array([b]), np.array([float(k)]), np.array([Dl])); J = int(J[0]); D = int(D[0]) if a >= p3: m = A_MTOP*rtop*log(b/a)/log(thi/p3) elif b <= pDl: m = A_MTAIL*rtail*log(b/a)/log(pDl/tlo) else: Dn = max(d for d in range(3, Dl + 1) if b <= _A_point(d)) # the band (1/((Dn+1)(Dn+2)), 1/(Dn(Dn+1))] m = A_M*rband*log(b/a)/log((Dn + 2)/Dn) m = max(4, int(round(m))) e = np.geomspace(a, b, m + 1); e[0] = a; e[-1] = b std = a != tlo and b != thi for kc, kdep in kcs: if a < kc < b and kc not in e: e = np.sort(np.append(e, kc)) if kdep: std = False _require(bool(np.all(np.diff(e) > 0)), "the points of a subdivision do not increase") out.append((e, J, D, std)) return out def A_psi_bounds(k): """lower and upper bounds for Psi(z_k) = 2 + log((1 - z_k)/z_k)""" z = A_zk_exact(k); r = (1-z)/z return float(_dn(2 + _dnk(np.log(_flo(r)), A_LOG_ULP))), float(_up(2 + _upk(np.log(_fup(r)), A_LOG_ULP))) def A_step_log(k): """lower and upper bounds for log(z_k/tau_k) = log(9.027901 k z_k), the amount by which the exact length of the steps lowers Y_k (Section A.5)""" r = A_zk_exact(k)*_Fr(9027901*k, 10**6) return float(_dnk(np.log(_flo(r)), A_LOG_ULP)), float(_upk(np.log(_fup(r)), A_LOG_ULP)) _A_RCACHE = {} def A_bound_rig(k, refine=1): """(B, Theta'): Theta' <= Theta_k is a lower bound for theta_k(2 tau_k) given by the chains (so 9/4 <= Theta' is checked), and B is a rigorous upper bound for (Y_k(Theta') + 1)/k, so that (A.68) holds; here Y_k(Theta) = k(Psi(z_k) + 2 int_{2 tau_k}^{2 z_k} dt/(t min{Theta, theta_k(t)})) - log(z_k/tau_k)""" grid = A_grid_rig(k, refine) e0, J0, D0, _ = grid[0] tplus = _fup(A_tau2_exact(k)); _require(e0[0] <= tplus < e0[-1]) Th = float(A_theta_hat_lo(np.array([float(k)]), np.array([tplus]), np.array([J0]), np.array([D0]))[0]) _require(Th >= 2.25, "Theta' < 9/4") total = 0.0 for e, J, D, std in grid: if std: # the k-independent parts are kept for the pieces that recur for many k key = (e.tobytes(), J, D) # the subdivision itself: the same piece may be subdivided differently for different k if key not in _A_RCACHE: _A_RCACHE[key] = (e.copy(), A_band_static_lo(e, J, D)) _require(np.array_equal(_A_RCACHE[key][0], e), "the stored subdivision of a piece differs from the present one") th = A_band_values_lo(k, e, J, D, _A_RCACHE[key][1]) else: th = A_band_values_lo(k, e, J, D) total = float(_up(total + A_cell_sum_up(e, th, Th))) psi_up = A_psi_bounds(k)[1] B = float(_up(_up(psi_up + _up(2*total)) + _fup(_Fr(1, k)))) B = float(_up(B - _dn(A_step_log(k)[0]/k))) return B, Th A_CHI0_LO = float(_dn(1 + _dnk(np.log(2.0), A_LOG_ULP))) # chi_0 = 1 + log 2 >= A_CHI0_LO A_HALF_TAUINV_UP = _fup(_Fr(45139505, 10**7)) # 4.5139505 <= this def A_values_rig(k, B, Th): """the integers and bounds of Section A.8 (Proposition A.39(i), Remark A.42) from an upper bound B and Theta'""" kB = float(_up(k*B)); Y = float(_up(kB - 1)) # Theta'' := Th/(1 - Th/(2k)), so that k/Theta'' = k/Th - 1/2 and 2/(11 Theta'') = 2/(11 Th) - 1/(11 k) x = float(_up(Y - _dn(_dn(2*A_CHI0_LO)*_dn(_dn(k/Th) - 0.5)))) s0 = max(s0_floor(k), floor(x/2) + 1) kT = float(_up(_up(k/Th) - 0.5)) # k/Theta'' <= kT b = float(_up(_up(4*kT)/_dn(TAU_INV*k))) # b = 4/(9.027901 Theta'') <= this (for the table only) E1 = float(_up(_up(2*s0 + _up(A_HALF_TAUINV_UP*k)) + _up(2*kT))) # E = 2 s_0 + 4.5139505 k + 2k/Theta return dict(B=B, Th=Th, kB=kB, Y=Y, G=floor(kB), l=floor(Y/2)+1, x=x, s0=s0, b=b, E=E1) A_REFINE_BELOW = 0.01 def A_table_rig(ks=None): """Section A.8: the values for 37 <= k <= KNUM; when the fractional part of k B is smaller than A_REFINE_BELOW, the subdivision is refined eightfold (and the smaller bound is used)""" out = {} for k in (ks if ks is not None else range(37, KNUM+1)): B, Th = A_bound_rig(k); r = A_values_rig(k, B, Th); r['ref'] = 1 if r['kB'] - floor(r['kB']) < A_REFINE_BELOW: B8, Th8 = A_bound_rig(k, refine=8); _require(Th8 == Th) if B8 < B: r = A_values_rig(k, B8, Th); r['ref'] = 8 out[k] = r return out A_KREC = 6 # the recursion of Section A.7 is carried out, in the first case, for A_KREC <= k <= KNUM def A_previous_plus(k): """the bound ceil(k(log k + 4.20032)/2) for G^+(k) of [BW2023, Theorem 9.1] (for k other than 4, 8, 16 and 32)""" v = _Fr(k, 2)*(_Fr(A_log_lo(k)) + _Fr(420032, 10**5)); w = _Fr(k, 2)*(_Fr(float(_upk(np.log(float(k)), A_LOG_ULP))) + _Fr(420032, 10**5)) _require(floor(v) == floor(w)) # so that the ceiling below is determined return floor(w) + 1 def A_previous(k): """the bound (1.1) for G(k), that is, ceil(k(log k + 4.20032)), for 1 <= k <= 36 (the bound for G(k) that was known before, when 21 <= k <= 36)""" if k == 1: return 5 v = _Fr(k)*(_Fr(A_log_lo(k)) + _Fr(420032, 10**5)); w = _Fr(k)*(_Fr(float(_upk(np.log(float(k)), A_LOG_ULP))) + _Fr(420032, 10**5)) _require(floor(v) == floor(w)) # so that the ceiling below is determined return floor(w) + 1 # --- rigorous bounds for Lambda^star and C_0^star: each term of the partial sum is computed with a relative error of a # few units in the last place, math.fsum adds the computed terms with one rounding, and the absolute allowance # 1e-13 exceeds the accumulated error by a factor of more than 100; the remainder lies between 2/(N+1) - 2/N^2 and 2/N def _A_lambda_bounds(): D = np.arange(4, A_NT+1, dtype=np.float64) S = fsum(_A_LDG.tolist()) + fsum([float(c)*log(float(x)) for c, x in A_PIECES_EXACT]) lo = float(_dn(_dn(S - 1e-13) + _flo(_Fr(2, A_NT+1) - _Fr(3, A_NT**2)))); hi = float(_up(_up(S + 1e-13) + _fup(_Fr(2, A_NT)))) return lo, hi A_LAMBDA_R = _A_lambda_bounds() _A_LOGSEED = (float(_dnk(np.log(_flo(_Fr(341, 41))), A_LOG_ULP)), float(_upk(np.log(_fup(_Fr(341, 41))), A_LOG_ULP))) # log((1-z)/z), z = 41/382 A_C0_R = (float(_dn(_dn(2 + _A_LOGSEED[0]) + 2*A_LAMBDA_R[0])), float(_up(_up(2 + _A_LOGSEED[1]) + 2*A_LAMBDA_R[1]))) def A_lt_sqrt(x, c, k): """exact test of x < c sqrt(k) for rational x and c (Fractions or floats, converted exactly)""" x = _Fr(x); c = _Fr(c) if c >= 0: return x < 0 or x*x < c*c*k return x < 0 and x*x > c*c*k def A_log_lo(k): """a lower bound for log k""" return float(_dnk(np.log(float(k)), A_LOG_ULP)) # --- rigorous upper bounds for theta_k(t) (outer intervals), and lower bounds for Y_k(Theta_k) + 1 def A_covered_outer(k, t, th): """False where it is certain that the intervals of Lemma A.28, formed with vt = th/k, do not cover (1, th], so that theta_k(t) < th: the end points are rounded outwards, and vt is rounded down""" t = np.asarray(t, float); th = np.asarray(th, float) LO, HI = _A_intervals(k, t, _dn(th/k), a=_dn, b=_up) return _A_reach(LO, HI) >= th def A_theta_upper(k, t, start, iters=48): """certified upper bounds hi >= theta_k(t), with hi > theta_k(t) unless theta_k(t) = k/2, starting from lower bounds start <= theta_k(t)""" t = np.asarray(t, float); hi = _up(np.maximum(start, 1.0)*(1 + 1e-12) + 1e-12) cov = A_covered_outer(k, t, hi) if cov.any(): idx = np.where(cov)[0]; lo = hi[idx].copy(); h2 = np.full(idx.size, k/2.0) top = A_covered_outer(k, t[idx], h2) for _ in range(iters): mid = 0.5*(lo + h2); c = A_covered_outer(k, t[idx], mid) lo = np.where(c, mid, lo); h2 = np.where(c, h2, mid) hi[idx] = np.where(top, k/2.0, h2) return hi def A_Y_lower(k, rtop=32, rband=16, rtail=16): """a rigorous lower bound for Y_k(Theta_k) + 1 = k(Psi(z_k) + 2 int_{2 tau_k}^{2 z_k} dt/(t theta_k(t))) - log(z_k/tau_k) + 1, by lower Riemann sums: theta_k is nonincreasing, and theta_k(t_i) <= hi_i on [t_i, t_{i+1}]""" grid = A_grid_rig(k, rtop=rtop, rband=rband, rtail=rtail) t_lo, t_hi = _fup(A_tau2_exact(k)), _flo(2*A_zk_exact(k)) S = [] for e, J, D, _ in grid: e = np.clip(e, t_lo, t_hi); e = np.unique(e) if e.size < 2: continue start = A_band_values_lo(k, e[:-1], J, D).max(axis=0) hi = A_theta_upper(k, e[:-1], start) S.append(_dn(_dnk(np.log(_dn(e[1:]/e[:-1])), A_LOG_ULP)/hi)) S = np.concatenate(S); n = S.size; _require(np.all(S >= 0)) s = float(_dn(float(np.sum(S))*(1 - 4*n*_U53))) V = float(_dn(_dn(A_psi_bounds(k)[0] + _dn(2*s)) + _flo(_Fr(1, k)))) return float(_dn(_dn(k*V) - A_step_log(k)[1])) # --- Remark A.41: Definition A.25 formed with the estimates of Section 4 alone, that is, with (b) for 1 <= j <= k-2 and # with Lemma 4.4 (4 <= D <= k-1) in place of (c). The level sets are I_0, the intervals I_j (j <= k-2) and # T'_D = [(D+1)(D(D+1)t/2 + D vt), (D+1)(1 - vt - (D+1)t)] (empty unless D(D+1)t + D vt <= 1), and theta'_k is computed # by bisection, as in A_theta_upper. def A_covered4(k, t, th, inner): """inner=True: True only where it is certain that these intervals, formed with vt = th/k, cover (1, th] (end points rounded inwards, vt rounded up); inner=False: False only where it is certain that they do not""" t = np.asarray(t, float); th = np.asarray(th, float); n = t.shape[0] a, b = (_up, _dn) if inner else (_dn, _up) # a: for left end points, b: for right end points vt = _up(th/k) if inner else _dn(th/k) jmax = min(k-2, 60) LO = [np.ones(n)]; HI = [b(2 - (2*t if inner else 2*t))] for j in range(1, jmax+1): c = 2.0**(j+2) - 2 LO.append(np.full(n, j + 2.0**(-j))) HI.append(np.minimum(b((j+2) - a(c*a(t + vt/2))), b((j+2) - a(c*vt)))) Dmax = 4 # Lemma 4.4 with D: saving >= t iff the three conditions below hold while (Dmax+1)*(Dmax+2)*float(t.min()) <= 1.0000001 and Dmax+1 <= k-1: Dmax += 1 D = np.arange(4, Dmax+1, dtype=np.float64)[None, :]; tt = t[:, None]; vv = vt[:, None] l = a((D+1)*a(a(0.5*D*(D+1)*tt) + a(D*vv))) # 2U/(D+1) - 2D vt >= D(D+1) t r = b((D+1)*b(1 - a(vv + a((D+1)*tt)))) # D(1 - U/(D+1)) - D vt >= D(D+1) t ok = a(a(D*(D+1)*tt) + a(D*vv)) <= 1 # 1 - D vt >= D(D+1) t l = np.where(ok, l, np.inf); r = np.where(ok, r, -np.inf) LO = np.hstack([np.array(LO).T, l]); HI = np.hstack([np.array(HI).T, r]) o = np.argsort(LO, axis=1, kind='stable'); LO = np.take_along_axis(LO, o, 1); HI = np.take_along_axis(HI, o, 1) cm = np.maximum.accumulate(HI, axis=1) gap = LO[:, 1:] > cm[:, :-1]; first = np.argmax(gap, axis=1) reach = np.where(gap.any(axis=1), cm[np.arange(n), first], cm[:, -1]) return reach >= th def A_theta4(k, t, lower, iters=46, chunk=40000): """rigorous lower (lower=True) or upper bounds for theta'_k(t), by bisection on [1, k/2]""" t = np.asarray(t, float); out = np.empty_like(t) for i0 in range(0, t.size, chunk): tc = t[i0:i0+chunk]; lo = np.ones_like(tc); hi = np.full_like(tc, k/2.0) top = A_covered4(k, tc, hi, inner=lower) for _ in range(iters): mid = 0.5*(lo + hi); c = A_covered4(k, tc, mid, inner=lower) lo = np.where(c, mid, lo); hi = np.where(c, hi, mid) out[i0:i0+chunk] = np.where(top, k/2.0, lo) if lower else np.where(top, k/2.0, hi) return out def A_Y4_bounds(k, n_top, n_low, lower=True, iters=32): """(lower bound for Y'_k(Theta'_k) + 1 or None, upper bound for Y'_k(Theta') + 1, Theta'), by Riemann sums on a geometric subdivision of [2 tau_k, 2 z_k] (n_low cells below 1/12 and n_top above); Theta' <= theta'_k(2 tau_k)""" t0, t1 = _flo(A_tau2_exact(k)), _fup(2*A_zk_exact(k)); p = _A_point(3) e = np.concatenate([np.geomspace(t0, p, n_low+1)[:-1], np.geomspace(p, t1, n_top+1)]); e[0] = t0; e[-1] = t1 _require(np.all(np.diff(e) > 0)) Th = float(A_theta4(k, np.array([_fup(A_tau2_exact(k))]), True, iters=50)[0]); _require(Th >= 2.25) up = _up(_upk(np.log(_up(e[1:]/e[:-1])), A_LOG_ULP)/np.minimum(Th, A_theta4(k, e[1:], True, iters=iters))) n = up.size; ps = A_psi_bounds(k) su = float(_up(float(np.sum(up))*(1 + 4*n*_U53))) slo, shi = A_step_log(k) U = float(_up(_up(k*_up(_up(ps[1] + _up(2*su)) + _fup(_Fr(1, k)))) - slo)) if not lower: return None, U, Th e2 = np.clip(e, _fup(A_tau2_exact(k)), _flo(2*A_zk_exact(k))) lo = _dn(_dnk(np.log(_dn(e2[1:]/e2[:-1])), A_LOG_ULP)/A_theta4(k, e2[:-1], False, iters=iters)) sl = float(_dn(float(np.sum(np.maximum(lo, 0)))*(1 - 4*n*_U53))) L = float(_dn(_dn(k*_dn(_dn(ps[0] + _dn(2*sl)) + _flo(_Fr(1, k)))) - shi)) return L, U, Th # ===================================================================================================================== # The second case of Section A.4: 7 <= k <= 20, with the tables of permissible exponents of Vaughan and Wooley, # Further improvements in Waring's problem, IV: higher powers, Acta Arith. 94 (2000) [VW2000, Sections 9-22]; and, for the # remark on k = 5 and k = 6, the tables of Further improvements in Waring's problem, Acta Math. 174 (1995) [VW1995, Appendix]. # Everything that involves the tables is computed in exact rational arithmetic. The tables record, for each s, the # exponent lambda_s and the parameter phi_1 of the iteration that produces it; the two are related by # lambda_s = lambda_(s-1)(1 - phi_1) + 1 + (2s - 2) phi_1 [VW2000, (4.10)]. Both columns are part of the program, # and the relation is verified for every entry (A_vw_tables_check), as a test of the transcription. For k = 8 the last # entry, lambda_20, is obtained by the process D_s of [VW2000, Section 8] and has no parameter phi_1 ('-'). # ===================================================================================================================== A_VW4 = { # the permissible exponents lambda_s, s = 3, 4, ..., as printed in the tables of [VW2000] for 7 <= k <= 20 7: """3.0639191 4.2641175 5.5891167 7.0143820 8.5410894 10.1526323 11.8469485 13.6055676 15.4242973 17.2932208 19.1925374 21.1139297 23.0528848 25.0105382""", 8: """3.0469787 4.2164889 5.4915710 6.8566563 8.3105992 9.8428621 11.4529104 13.1283069 14.8664781 16.6561197 18.4901012 20.3623532 22.2661078 24.1891161 26.1294925 28.0833353 30.0473193 32.0186056""", 9: """3.0358052 4.1822894 5.4197057 6.7383084 8.1356346 9.6039271 11.1425026 12.7463430 14.4105835 16.1292111 17.8959526 19.7055987 21.5507274 23.4269614 25.3292029 27.2520471 29.1901860 31.1420569 33.1033373 35.0727119""", 10: """3.0281105 4.1568114 5.3659530 6.6465971 7.9967162 9.4143540 10.8945712 12.4375675 14.0371956 15.6914013 17.3943657 19.1426918 20.9303709 22.7537459 24.6071999 26.4867878 28.3886784 30.3094873 32.2449884 34.1926960 36.1509648 38.1169804 40.0895832 42.0677228""", 11: """3.0221905 4.1346363 5.3216133 6.5727501 7.8855603 9.2614256 10.6937742 12.1849727 13.7292224 15.3262982 16.9712740 18.6621448 20.3940119 22.1640483 23.9674841 25.8009828 27.6607360 29.5431019 31.4450976 33.3638548 35.2968576 37.2413126 39.1958837 41.1582991 43.1274069 45.1020502 47.0818525""", 12: """3.0173811 4.1139674 5.2806367 6.5078011 7.7910496 9.1322748 10.5253191 11.9729266 13.4700805 15.0174771 16.6110110 18.2496682 19.9296021 21.6486622 23.4028589 25.1895563 27.0053277 28.8470137 30.7117485 32.5965148 34.4988383 36.4163328 38.3468951 40.2885464 42.2395410 44.1986746 46.1643984 48.1357634 50.1118679 52.0919461""", 13: """3.0139128 4.0980713 5.2480334 6.4550068 7.7136017 9.0257224 10.3855801 11.7953083 13.2521623 14.7557170 16.3039366 17.8953488 19.5276970 21.1988910 22.9062626 24.6473038 26.4190897 28.2190701 30.0445818 31.8929000 33.7616279 35.6483904 37.5510006 39.4675269 41.3961543 43.3352806 45.2834077 47.2392765 49.2018815 51.1701090 53.1431803 55.1203776 57.1010835 59.0849135""", 14: """3.0113494 4.0856057 5.2216967 6.4118310 7.6492691 8.9350975 10.2671180 11.6442024 13.0662900 14.5316795 16.0399382 17.5892784 19.1785686 20.8058286 22.4692736 24.1667258 25.8960050 27.6547883 29.4407200 31.2515093 33.0849211 34.9387022 36.8107871 38.6992193 40.6021475 42.5178927 44.4449274 46.3818646 48.3274553 50.2805449 52.2401670 54.2054937 56.1756866 58.1501035 60.1281620 62.1093556 64.0933213 66.0795485""", 15: """3.0092359 4.0742295 5.1987873 6.3738989 7.5936427 8.8571841 10.1649995 11.5141981 12.9059619 14.3381411 15.8111209 17.3230870 18.8736139 20.4609219 22.0838491 23.7405373 25.4293639 27.1483206 28.8955107 30.6688816 32.4664265 34.2861492 36.1261310 37.9844896 39.8594364 41.7493055 43.6525286 45.5676489 47.4933457 49.4284091 51.3717431 53.3223547 55.2793490 57.2419678 59.2094705 61.1812515 63.1567645 65.1355287 67.1171222 69.1012148 71.0874163""", 16: """3.0074816 4.0638321 5.1787385 6.3412246 7.5457229 8.7902441 10.0769155 11.4019639 12.7671799 14.1702162 15.6119303 17.0906280 18.6062852 20.1573791 21.7431712 23.3621148 25.0129891 26.6941169 28.4039654 30.1407641 31.9028113 33.6883143 35.4955330 37.3227332 39.1682523 41.0304795 42.9078717 44.7989875 46.7024729 48.6170673 50.5416092 52.4750359 54.4163771 56.3647518 58.3193587 60.2794807 62.2444892 64.2137908 66.1868812 68.1633061 70.1426626 72.1245941 74.1088058 76.0949856 78.0829008""", 17: """3.0061404 4.0554335 5.1619828 6.3136071 7.5040992 8.7323022 10.0004288 11.3043577 12.6459140 14.0233197 15.4369512 16.8860867 18.3702735 19.8886761 21.4405373 23.0247863 24.6403737 26.2860071 27.9604002 29.6620874 31.3896134 33.1414245 34.9159903 36.7117441 38.5271601 40.3607211 42.2109803 44.0765377 45.9560566 47.8482757 49.7520144 51.6661665 53.5897087 55.5216990 57.4612719 59.4076368 61.3600741 63.3179278 65.2806096 67.2475940 69.2183942 71.1925852 73.1697840 75.1496484 77.1318848 79.1162028 81.1023673 83.0901643""", 18: """3.0050870 4.0484489 5.1469671 6.2893077 7.4676627 8.6816032 9.9332381 11.2185989 12.5388988 13.8936352 15.2823305 16.7049932 18.1609021 19.6497248 21.1706906 22.7231221 24.3060925 25.9186447 27.5596769 29.2280189 30.9224199 32.6415685 34.3841221 36.1487034 37.9339369 39.7384452 41.5608774 43.3999089 45.2542644 47.1227175 49.0040975 50.8972954 52.8012695 54.7150443 56.6377106 58.5684269 60.5064172 62.4509681 64.4014262 66.3571950 68.3177304 70.2825406 72.2511825 74.2232486 76.1983771 78.1762412 80.1565468 82.1390360 84.1234628 86.1096189 88.0973151 90.0863822""", 19: """3.0042273 4.0423620 5.1333114 6.2663273 7.4343072 8.6357245 9.8725415 11.1414574 12.4430359 13.7775620 15.1440547 16.5429734 17.9734687 19.4355306 20.9284296 22.4517574 24.0047167 25.5866021 27.1964861 28.8334329 30.4963841 32.1842434 33.8958472 35.6300014 37.3854842 39.1610622 40.9555027 42.7675849 44.5961098 46.4399090 48.2978543 50.1688626 52.0518997 53.9459843 55.8501910 57.7636509 59.6855524 61.6151397 63.5517128 65.4946250 67.4432807 69.3971334 71.3556823 73.3184698 75.2850793 77.2551336 79.2282862 81.2042263 83.1826716 85.1633672 87.1460856 89.1306147 91.1167691 93.1043803 95.0932973 97.0833838""", 20: """3.0035377 4.0372112 5.1214726 6.2457501 7.4042791 8.5946271 9.8176862 11.0720258 12.3569582 13.6733507 15.0199527 16.3974554 17.8050250 19.2428091 20.7101660 22.2068593 23.7322237 25.2857385 26.8666319 28.4741610 30.1074344 31.7655438 33.4474901 35.1522491 36.8787481 38.6258968 40.3925867 42.1777082 43.9801557 45.7988398 47.6326920 49.4806744 51.3417836 53.2150565 55.0995728 56.9944581 58.8988854 60.8120763 62.7333008 64.6618772 66.5971707 68.5385926 70.4855980 72.4376841 74.3943883 76.3552854 78.3199857 80.2881335 82.2594024 84.2334960 86.2101439 88.1891004 90.1701423 92.1530669 94.1376919 96.1238487 98.1113875 100.1001722 102.0900795 104.0809983""", } A_VW4_PHI = { # the parameters phi_1 that are printed next to lambda_s in the same tables (8 decimals) 7: """0.03195955 0.06818557 0.08699398 0.09641272 0.10564538 0.11202654 0.11873997 0.12329153 0.12803790 0.13214156 0.13409068 0.13535033 0.13635572 0.13784908""", 8: """0.02348931 0.05740233 0.07270549 0.08097841 0.08825831 0.09355343 0.09907986 0.10315980 0.10742204 0.11069450 0.11356143 0.11614698 0.11832893 0.11934590 0.12039309 0.12119204 0.12176644 -""", 9: """0.01790259 0.04941786 0.06218814 0.06955946 0.07551302 0.07985390 0.08420410 0.08805551 0.09157319 0.09468812 0.09741610 0.09990639 0.10189148 0.10370526 0.10524175 0.10643130 0.10724097 0.10804665 0.10852186 0.10895936""", 10: """0.01405522 0.04330611 0.05441877 0.06056135 0.06540123 0.06956822 0.07291878 0.07641992 0.07929039 0.08215771 0.08460686 0.08695770 0.08892986 0.09078376 0.09230268 0.09364492 0.09480400 0.09580462 0.09653784 0.09715085 0.09770971 0.09808226 0.09841150 0.09869813""", 11: """0.01109521 0.03776126 0.04837243 0.05368021 0.05763697 0.06147175 0.06416025 0.06723014 0.06964143 0.07219102 0.07435992 0.07651920 0.07837637 0.08016212 0.08168359 0.08307973 0.08429767 0.08534127 0.08625844 0.08704554 0.08772003 0.08824091 0.08872562 0.08907859 0.08938707 0.08964222 0.08990704""", 12: """0.00869053 0.03238304 0.04288933 0.04813455 0.05157287 0.05495699 0.05723065 0.05988316 0.06193465 0.06417372 0.06607653 0.06802194 0.06973444 0.07140335 0.07285983 0.07423677 0.07546142 0.07655400 0.07753392 0.07837940 0.07912700 0.07977408 0.08033400 0.08080691 0.08120210 0.08155581 0.08183181 0.08207146 0.08227285 0.08244173""", 13: """0.00695637 0.02818356 0.03843282 0.04355532 0.04663575 0.04965016 0.05159785 0.05380951 0.05568206 0.05756333 0.05930365 0.06099508 0.06257992 0.06409230 0.06549065 0.06679816 0.06798261 0.06907751 0.07007187 0.07095680 0.07175359 0.07245756 0.07307633 0.07362249 0.07409771 0.07451110 0.07486365 0.07516706 0.07543499 0.07565390 0.07584409 0.07600614 0.07614400 0.07627230""", 14: """0.00567466 0.02484611 0.03476683 0.03979118 0.04248943 0.04500717 0.04699577 0.04876376 0.05051435 0.05209364 0.05367993 0.05515430 0.05660418 0.05796461 0.05926701 0.06048642 0.06162954 0.06268866 0.06366289 0.06455699 0.06537338 0.06610731 0.06676863 0.06736052 0.06788535 0.06835016 0.06876037 0.06912079 0.06943614 0.06970829 0.06994609 0.07015541 0.07033184 0.07048574 0.07061847 0.07073278 0.07083658 0.07091753""", 15: """0.00461792 0.02173146 0.03172823 0.03647237 0.03905794 0.04113748 0.04309441 0.04456907 0.04616698 0.04752336 0.04895330 0.05024754 0.05156238 0.05278515 0.05398415 0.05510909 0.05618735 0.05719334 0.05813950 0.05901573 0.05982581 0.06056957 0.06125062 0.06186873 0.06242704 0.06293025 0.06338099 0.06378269 0.06414041 0.06445755 0.06473789 0.06498462 0.06520081 0.06539241 0.06555771 0.06570293 0.06582965 0.06594009 0.06603623 0.06612247 0.06619342""", 16: """0.00374079 0.01883046 0.02919246 0.03370200 0.03613827 0.03788514 0.03976160 0.04102548 0.04247669 0.04365257 0.04493631 0.04608149 0.04726736 0.04836825 0.04946474 0.05049786 0.05150184 0.05244686 0.05334847 0.05419218 0.05498480 0.05572055 0.05640278 0.05703073 0.05760740 0.05813390 0.05861191 0.05904508 0.05943588 0.05978708 0.06010180 0.06038318 0.06063404 0.06085714 0.06105480 0.06122977 0.06138528 0.06152144 0.06164181 0.06174778 0.06184097 0.06192285 0.06199601 0.06205826 0.06211345""", 17: """0.00307019 0.01646473 0.02701166 0.03134018 0.03349964 0.03513032 0.03689292 0.03799316 0.03927903 0.04034662 0.04145984 0.04251950 0.04356583 0.04457565 0.04556572 0.04651864 0.04744334 0.04832721 0.04917555 0.04997915 0.05074142 0.05145731 0.05212921 0.05275480 0.05333611 0.05387253 0.05436691 0.05482022 0.05523415 0.05561097 0.05595308 0.05626250 0.05654168 0.05679304 0.05701880 0.05722114 0.05740216 0.05756359 0.05770757 0.05783611 0.05794990 0.05805112 0.05814094 0.05822056 0.05829175 0.05835376 0.05840894 0.05845772""", 18: """0.00254346 0.01447855 0.02493153 0.02933022 0.03123178 0.03275099 0.03438389 0.03537489 0.03647482 0.03749420 0.03846045 0.03943607 0.04036376 0.04128885 0.04218253 0.04306012 0.04390870 0.04473174 0.04552348 0.04628304 0.04700798 0.04769656 0.04834828 0.04896179 0.04953749 0.05007502 0.05057526 0.05103871 0.05146692 0.05186115 0.05222287 0.05255372 0.05285563 0.05313037 0.05337974 0.05360563 0.05380985 0.05399414 0.05416015 0.05430945 0.05444347 0.05456372 0.05467161 0.05476794 0.05485415 0.05493118 0.05499994 0.05506161 0.05511611 0.05516484 0.05520823 0.05524686""", 19: """0.00211363 0.01272951 0.02298073 0.02733191 0.02929710 0.03067723 0.03215755 0.03308734 0.03404381 0.03500339 0.03585180 0.03674656 0.03757479 0.03842022 0.03922960 0.04003558 0.04081410 0.04157726 0.04231369 0.04302673 0.04371136 0.04436768 0.04499335 0.04558788 0.04615045 0.04668075 0.04717878 0.04764484 0.04807945 0.04848337 0.04885769 0.04920355 0.04952220 0.04981500 0.05008342 0.05032891 0.05055296 0.05075705 0.05094263 0.05111110 0.05126380 0.05140202 0.05152695 0.05163973 0.05174146 0.05183320 0.05191569 0.05198993 0.05205667 0.05211663 0.05217061 0.05221882 0.05226214 0.05230098 0.05233578 0.05236696""", 20: """0.00176883 0.01123775 0.02126317 0.02547440 0.02754990 0.02885933 0.03012126 0.03108406 0.03191458 0.03281045 0.03356385 0.03438079 0.03512761 0.03589874 0.03663479 0.03737393 0.03808882 0.03879475 0.03947826 0.04014501 0.04078835 0.04140990 0.04200611 0.04257718 0.04312142 0.04363868 0.04412832 0.04459040 0.04502494 0.04543236 0.04581314 0.04616803 0.04649788 0.04680367 0.04708646 0.04734736 0.04758756 0.04780826 0.04801065 0.04819593 0.04836528 0.04851983 0.04866069 0.04878890 0.04890547 0.04901133 0.04910737 0.04919448 0.04927331 0.04934469 0.04940924 0.04946760 0.04952031 0.04956792 0.04961094 0.04964967 0.04968462 0.04971613 0.04974452 0.04977011""", } A_VW_T = {7: '48.47', 8: '58.01', 9: '67.51', 10: '76.95', 11: '86.40', 12: '95.66', 13: '104.95', 14: '114.19', 15: '123.40', 16: '132.60', 17: '141.78', 18: '150.95', 19: '160.07', 20: '169.18'} # the numbers T_k of Section A.4; tau_k^VW = 1/T_k A_VW95 = { # the tables of [VW1995, Appendix] for k = 5 and k = 6: (lambda_s, phi_1), s = 3, 4, ... 5: ("3.1362571 4.4386563 5.9250797 7.5417546 9.2727289 11.0773627", "0.06812854 0.10559577 0.13658426 0.15133422 0.16396009 0.17021105"), 6: ("3.0909091 4.3333334 5.7246965 7.2315633 8.8505716 10.5604127 12.3536709 14.2030055 16.0860412 18.0000000", "0.04545455 0.08333334 0.10673541 0.11855692 0.12981369 0.13784851 0.14583058 0.15042244 0.15232648 0.15454265"), } A_VW95_T = {5: '30.16', 6: '39.21'} # 4u^2/(k - 2 Delta_u), u = k - 1, rounded up (as T_k) A_BW_GPLUS = {14: 45, 15: 49, 16: 53, 17: 57, 18: 61, 19: 65, 20: 69, 32: 123} # [BW2023, Theorem 9.1 and Table 3]; for k = 16 # and 32 the numbers of [BW2023, Theorem 9.2] (residue classes modulo 4k) def A_gplus_before(k): """the bound for G^+(k) recorded in [BW2023, Section 9], 6 <= k <= 36: Table 3 of Theorem 9.1 for 14 <= k <= 20, the number of Theorem 9.2 for k = 16 and k = 32 (an admissible number of k-th powers in the residue classes modulo 4k), None for k = 8 (where G^+(8) = 32 = 4k), and ceil(k(log k + 4.20032)/2) otherwise""" if k == 8: return None return A_BW_GPLUS[k] if k in A_BW_GPLUS else A_previous_plus(k) A_VW_PREVIOUS = {7: 31, 8: 39, 9: 47, 10: 55, 11: 63, 12: 72, 13: 81, 14: 89, 15: 97, 16: 105, 17: 113, 18: 121, 19: 129, 20: 137} # [Woo2016, Theorem 1.1] for k <= 13, [BW2023, Theorem 1.3] for k >= 14 A_VW_FOOTER = {7: (20777, 6), 8: (17327, 7), 9: (14871, 8), 10: (13036, 9), 11: (11604, 10), 12: (10475, 11), 13: (9545, 12), 14: (8770, 13), 15: (8114, 14), 16: (7549, 15), 17: (7060, 16), 18: (6630, 17), 19: (6252, 18), 20: (5915, 19)} # the numbers 10^6 tau(k), and the values of s to which they belong, that are printed below the tables of [VW2000] def A_vw_delta(k): """the admissible exponents Delta_s = lambda_s - 2s + k (0 <= s <= S_k) as exact fractions; lambda_0 = 0, lambda_1 = 1 and lambda_2 = 2 (the trivial bounds and Hua's lemma), and lambda_s for s >= 3 from the table for k""" lam = [_Fr(0), _Fr(1), _Fr(2)] + [_Fr(x) for x in A_VW4[k].split()] return [lam[s] - 2*s + k for s in range(len(lam))] def A_vw95_delta(k): """the same for the tables of [VW1995, Appendix], k = 5 and k = 6""" lam = [_Fr(0), _Fr(1), _Fr(2)] + [_Fr(x) for x in A_VW95[k][0].split()] return [lam[s] - 2*s + k for s in range(len(lam))] def A_vw95_check(k): """the relation (4.10) for the tables of [VW1995] (the largest deviation, as a fraction), and the numbers of decimals""" ls, ps = A_VW95[k][0].split(), A_VW95[k][1].split() lam = [_Fr(0), _Fr(1), _Fr(2)] + [_Fr(x) for x in ls] dev = max(abs(lam[s] - lam[s-1]*(1 - _Fr(p)) - 1 - (2*s - 2)*_Fr(p)) for s, p in zip(range(3, len(lam)), ps)) return dev, len(ls) == len(ps) and all(len(x.split('.')[1]) == 7 for x in ls) and all(len(x.split('.')[1]) == 8 for x in ps) def A_vw_zeta(Dl, s): """z^(s) = (Delta_s - Delta_{s+1})/2: for z^(s) <= z <= z^(s-1) the minimum defining Psi^VW(z) is attained at s""" return (Dl[s] - Dl[s+1])/2 def A_vw_psi(k, Dl, z): """Psi^VW(z) = min over s of (2s + Delta_s/z)/k, exactly""" return min((2*s + Dl[s]/z)/k for s in range(len(Dl))) def A_vw_tables_check(k): """tests of the transcription of the table for k: (the largest value of |lambda_s - lambda_(s-1)(1 - phi_1) - 1 - (2s - 2) phi_1| over 3 <= s <= S_k, as an exact fraction; True if every entry has the printed number of decimals; floor(10^6 max_s (k - 2 Delta_s)/(4s^2 - 1)) and the s at which this maximum is attained, to be compared with the footer of the table; the sum of the lambda_s)""" ls = A_VW4[k].split(); ps = A_VW4_PHI[k].split() ok = len(ls) == len(ps) and all(len(x.split('.')[1]) == 7 for x in ls) and all(p == '-' or len(p.split('.')[1]) == 8 for p in ps) ok &= all(p != '-' for p in ps[:-1]) and (ps[-1] != '-' or k == 8) lam = [_Fr(0), _Fr(1), _Fr(2)] + [_Fr(x) for x in ls] dev = max(abs(lam[s] - lam[s-1]*(1 - _Fr(p)) - 1 - (2*s - 2)*_Fr(p)) for s, p in zip(range(3, len(lam)), ps) if p != '-') Dl = A_vw_delta(k); S = len(Dl) - 1 v, q = max(((k - 2*Dl[q])/(4*q*q - 1), q) for q in range(1, S+1)) return dev, ok, (floor(v*10**6), q), sum(lam[3:]) # --- Appendix A, Sections A.6 and A.7: the potential defined by a recursion (Theorem A.36), with directed rounding. The range of # 2v is divided at the points of A_divpoints; on a piece [s, b] the chains of the family of b are defined # throughout, and by Lemma A.28(iv), (v) the function v -> v/(1 - theta-hat(2v)/k) is nondecreasing there, so that # v/(1 - theta_k(2v)/k) >= (s/2)/(1 - theta-hat(s)/k) for s <= 2v <= b. Starting from c_0 below tau, the program # puts c_j := a floating point number below the least of these bounds, taken over the pieces that the step meets, # and evaluates k Psi(c_n) + 2n. A_REC_CAP = 0.12 # steps are cut off here (any number beyond 13/120 would do) def A_rec_step_lo(kv, c, Dlimv, cap=A_REC_CAP): """one step of the recursion, for all elements: floating point numbers c' > c with v/(1 - theta_k(2v)/k) > c' for c <= v < c', and the lower bounds for theta_k(2c) that were used; c' is at most cap.""" kv = np.asarray(kv, float); c = np.asarray(c, float); Dlimv = np.asarray(Dlimv, int) div = A_divpoints(int(Dlimv.max())) _require(2*cap < div[-1] and bool(np.all(c < cap))) start = 2*c; cand = np.full(c.size, cap); th0 = None; act = np.arange(c.size) while act.size: s = start[act] ib = np.searchsorted(div, s, side='right'); _require(bool(np.all(ib < div.size))) b = div[ib] J, D = A_family(b, kv[act], Dlimv[act]) th = A_theta_hat_lo(kv[act], s, J, D) if th0 is None: th0 = th x = _dn(_dn((s/2)/_up(1 - _dn(th/kv[act])))) cand[act] = np.minimum(cand[act], x) cont = 2*cand[act] > b # the range of v continues beyond b/2 start[act[cont]] = b[cont]; act = act[cont] _require(bool(np.all(cand > c)), "A_rec_step_lo: a step does not advance") return cand, th0 A_REC_CMAX = float(_dn(_flo(_Fr(13, 120)))) # the points c_n are kept below zeta/2 = 13/120 (first case, (R1)) A_REC_CMAX_VW = float(_dn(_flo(_Fr(1, 10)))) # and below zeta/2 = 1/10 in the second case def A_rec_seq(ks, c0s): """the sequences of the recursion for the exponents ks with the starting points c0s: arrays c_0 < c_1 < ... in which every point except the last is at most A_REC_CMAX""" kv = np.asarray(ks, float); c = np.asarray(c0s, float); Dl = np.array([A_Dlim(int(k)) for k in ks]) seqs = [[x] for x in c]; act = np.arange(c.size) while act.size: cn, _ = A_rec_step_lo(kv[act], c[act], Dl[act]) for i, x in zip(act, cn): seqs[i].append(float(x)) c[act] = cn; act = act[cn <= A_REC_CMAX] return [np.array(q) for q in seqs] def A_psi_up(c): """an upper bound for Psi(c) = 2 + log((1-c)/c)""" return _up(2 + _upk(np.log(_up(_up(1 - c)/c)), A_LOG_ULP)) def A_rec_std(ks): """Theorem A.36 in the first case, that is, with (Psi, tau_k), for the exponents in ks (k >= 6): arrays Y, n, c, with Y >= k Psi(c_n) + 2n for a sequence c_0 < ... < c_n that satisfies (R1)-(R3); further cp = c_{n-1}, Th (the lower bound for theta_k(2 c_0) that was used) and steps (the number of points below 1/10). (R1): c_0 < tau_k and c_n < 13/120 (and theta_k(2 c_n) >= 3/2 by Lemma A.27(iii)); (R2): by A_rec_step_lo; (R3): Psi(c_{n-1}) - Psi(c_n) >= 2/k is verified with the logarithm rounded downwards. Among the n with (R3), the one with the smallest bound Y is taken. (The two uses of the logarithm are verified a second time by A_rec_certify.)""" ks = np.array(sorted(int(k) for k in ks)); _require(ks[0] >= 6, "A_rec_std requires k >= 6") kv = ks.astype(float); N = ks.size c = np.array([float(_dn(_flo(A_tau2_exact(int(k))/2))) for k in ks]) _require(all(_Fr(float(x))*2 < A_tau2_exact(int(k)) for x, k in zip(c, ks)), "c_0 >= tau_k") Dl = np.array([A_Dlim(int(k)) for k in ks]) n = np.zeros(N, int); best = np.full(N, np.inf); nbest = np.zeros(N, int); cbest = np.zeros(N); cprev = np.zeros(N); th0 = np.zeros(N) two_k = _up(2.0/kv); act = np.arange(N); first = True while act.size: cand, th = A_rec_step_lo(kv[act], c[act], Dl[act]) if first: th0[act] = th; first = False go = act[cand <= A_REC_CMAX]; cn = cand[cand <= A_REC_CMAX]; co = c[go] if go.size: num = _dn(_dn(1 - co)*cn); den = _up(_up(1 - cn)*co) worth = _dnk(np.log(_dn(num/den)), A_LOG_ULP) >= two_k[go] n[go] += 1; c[go] = cn Yup = _up(_up(kv[go]*A_psi_up(cn)) + 2.0*n[go]) better = worth & (Yup < best[go]); bi = go[better] best[bi] = Yup[better]; nbest[bi] = n[bi]; cbest[bi] = cn[better]; cprev[bi] = co[better] act = go _require(np.all(np.isfinite(best)) and np.all(nbest >= 1) and np.all(cbest <= A_REC_CMAX) and np.all(cprev < cbest)) return dict(k=ks, Y=best, n=nbest, c=cbest, cp=cprev, Th=th0, steps=n) _A_REC = {} def A_rec_table(): """the numbers of Section A.7 for A_KREC <= k <= KNUM (first case): k -> dict(Y, G, l, n, c, cp, Th) with Y = Y^flat(k) (an upper bound for k Psi(c_n) + 2n), G = G^flat(k) = floor(Y) + 1, l = l^flat(k) = floor(Y/2) + 1, c = c_n and cp = c_(n-1)""" if 'tab' not in _A_REC: r = A_rec_std(range(A_KREC, KNUM+1)) _A_REC['tab'] = {int(k): dict(Y=float(y), G=floor(y) + 1, l=floor(_Fr(float(y))/2) + 1, n=int(n), c=float(c), cp=float(cp), Th=float(t)) for k, y, n, c, cp, t in zip(r['k'], r['Y'], r['n'], r['c'], r['cp'], r['Th'])} return _A_REC['tab'] def A_rec_certify(rec, prec=40): """a second verification, in decimal arithmetic with prec digits, of the two places at which the recursion uses logarithms in the first case: (R3), that is, log((1 - c_(n-1)) c_n/((1 - c_n) c_(n-1))) >= 2/k, and Y >= k(2 + log((1 - c_n)/c_n)) + 2n. The floating point numbers c_(n-1), c_n and Y are used exactly (as fractions); the arguments of the logarithms are rounded in the safe direction to prec digits; the method ln of the module decimal is correctly rounded, and an error of 10^(3-prec) is allowed for it; the remaining operations are rounded in the safe direction. Returns (True if both inequalities hold for every k, the least value of the left hand side of (R3) minus 2/k, the least and the largest value of Y minus the right hand side).""" from decimal import Decimal as Dm, localcontext, ROUND_FLOOR, ROUND_CEILING ok = True; m3 = mY = xY = None with localcontext() as ctx: ctx.prec = prec; eps = Dm(10)**(3 - prec) for k, r in rec.items(): c = _Fr(r['c']); cp = _Fr(r['cp']); a3 = (1 - cp)*c/((1 - c)*cp); aY = (1 - c)/c ctx.rounding = ROUND_FLOOR l3 = (Dm(a3.numerator)/Dm(a3.denominator)).ln() - eps # a lower bound for the logarithm in (R3) ctx.rounding = ROUND_CEILING lY = (Dm(aY.numerator)/Dm(aY.denominator)).ln() + eps # an upper bound for log((1 - c_n)/c_n) d3 = l3 - Dm(2)/Dm(k) # rounded upwards: the comparison below is exact rhs = Dm(k)*(2 + lY) + 2*r['n'] Yf = _Fr(r['Y']); ctx.rounding = ROUND_FLOOR dY = Dm(Yf.numerator)/Dm(Yf.denominator) - rhs ok &= (l3 >= Dm(2)/Dm(k)) and (dY >= 0) and 0 < cp < c < _Fr(13, 120) m3 = d3 if m3 is None or d3 < m3 else m3; mY = dY if mY is None or dY < mY else mY; xY = dY if xY is None or dY > xY else xY return ok, float(m3), float(mY), float(xY) def A_rec_vw(k, T=None, vw95=False, Dl=None): """Theorem A.36 in the second case, that is, with (Psi^VW, tau^VW), for 7 <= k <= 20 (vw95: the tables of [VW1995] for k = 5, 6, for the remark on these k): a dictionary with the exact rational number Y = k Psi^VW(c_n) + 2n (or None, if no n satisfies (R3)), the integer G = floor(Y) + 1, n, c_n, a lower bound th for theta_k(2 c_n), the list 'hist' of the triples (j, c_j, k Psi^VW(c_j) + 2j, (R3) holds for n = j), the least value of k(Psi^VW(c_(j-1)) - Psi^VW(c_j)) - 2 over the steps ('gap'), and the truth values of the hypotheses: (V1), (V2), (V3) of Section A.4, (R1): c_0 < 1/T_k, c_n < 1/10 and theta_k(2 c_n) >= 3/2, (R3), Y >= 4k + 1, and Y >= 4.19 k (for part (ii) of Theorem A.36, through Theorem 2.4); and l = floor(Y/2) + 1. The points c_j are floating point numbers, and Psi^VW is evaluated at them exactly.""" if Dl is None: Dl = A_vw95_delta(k) if vw95 else A_vw_delta(k) # Dl: another table (Appendix C), with T given S = len(Dl) - 1; u = k - 1 tau = 1/_Fr((A_VW95_T if vw95 else A_VW_T)[k] if T is None else T) c0 = float(_dn(_flo(tau))) seq = A_rec_seq([k], [c0])[0] kv = np.array([float(k)]); n = 0; best = None; hist = []; gap = None psi_old = A_vw_psi(k, Dl, _Fr(c0)) for j in range(1, len(seq)): cn = float(seq[j]) if cn > A_REC_CMAX_VW: break psi_new = A_vw_psi(k, Dl, _Fr(cn)); Y = k*psi_new + 2*j d = k*(psi_old - psi_new) - 2; gap = d if gap is None or d > gap else gap worth = d >= 0 b = np.array([2*cn]); J, D = A_family(A_divpoints(A_Dlim(k))[np.searchsorted(A_divpoints(A_Dlim(k)), b, side='right')], kv, np.array([A_Dlim(k)])) thn = float(A_theta_hat_lo(kv, b, J, D)[0]) hist.append((j, cn, Y, worth)) if worth and thn >= 1.5 and (best is None or Y < best[0]): best = (Y, j, cn, thn) psi_old = psi_new d2 = [Dl[s+1] - 2*Dl[s] + Dl[s-1] for s in range(1, S)] tex = (k - 2*Dl[u])/(4*u*u) out = dict(k=k, tau=tau, hist=hist, gap=gap, Y=None, G=None, l=None, n=None, c=None, th=None) checks = { 'V1': all(x >= 0 for x in d2) and all(Dl[s+1] < Dl[s] for s in range(S)) and Dl[S] > 0, 'V2': A_vw_zeta(Dl, k-1) >= _Fr(1, 5), 'V3': tau < tex and 8*u*u >= 9*k and _Fr(1, 8)*(1 + Dl[u]/(2*u*u)) + _Fr(k, 4*u*u) < _Fr(1, 4), } if best is not None: Y, nb, cb, thb = best checks.update({'R1': _Fr(c0) < tau and _Fr(cb) < _Fr(1, 10) and _Fr(thb) >= _Fr(3, 2), 'R3': hist[nb-1][3] and hist[nb-1][0] == nb, 'Y': Y >= 4*k + 1, 'Y419': Y >= _Fr(419, 100)*k}) out.update(Y=Y, G=floor(Y) + 1, l=floor(Y/2) + 1, n=nb, c=cb, th=thb) out.update(checks=checks, ok=all(checks.values()) and best is not None) return out def A_rec_plain(k, vw=False, oldb=False, cap=None): """a plain double precision version of the recursion, in which theta_k is computed directly from Definition A.25 (A_theta_direct) instead of chains: the least value of k Psi(c_n) + 2n, where c_0 = tau and c_j = inf{ v/(1 - theta_k(2v)/k) : v >= c_{j-1} } (the infimum is examined at c_{j-1} and just beyond the points 1/(2D(D+1)), 1/(2(D^2+2D+2)) and 2^(-j-2)), over the n with c_n < cap and Psi(c_{n-1}) - Psi(c_n) >= 2/k; cap is zeta/2, that is, 13/120 in the first case and 1/10 in the second. A cross-check, not rigorous.""" if vw: Dl = [float(x) for x in A_vw_delta(k)]; tau = 1/float(A_VW_T[k]) psi = lambda z: min((2*s + Dl[s]/z)/k for s in range(len(Dl))) else: tau = 1/(TAU_INV*k); psi = lambda z: 2 + log((1-z)/z) if cap is None: cap = 0.1 if vw else 13/120 th = lambda t: float(A_theta_direct(k, np.array([t]), oldb=oldb)[0][0]) pts = sorted([1.0/(D*(D+1)) for D in range(3, A_Dlim(k) + 1)] + [1.0/(D*D+2*D+2) for D in range(3, A_Dlim(k) + 1)] + [2.0**(-j-1) for j in range(1, 30)]) c = tau; n = 0; best = None while True: cn = c/(1 - th(2*c)/k) for e in pts: if 2*c < e < 2*cn: cn = min(cn, (e/2)/(1 - th(e*(1 + 1e-13))/k)) if cn >= cap: break n += 1 if psi(c) - psi(cn) >= 2.0/k: Y = k*psi(cn) + 2*n if best is None or Y < best[0]: best = (Y, n, cn) c = cn return best def A_rec_potential(k, npts=40000): """the potential of the proof of Theorem A.36 in the limit delta_0 = eps_2 = 0, on a grid (plain double precision, theta_k from Definition A.25; a cross-check, not rigorous): G = Psi on [z_0, 1/5], where Psi(z_0) = Psi(c_n) + 2/k, and G(z) = max{Psi(z_0), 2/k + G(S_(z))} for z < z_0, where S_(z) is the infimum of v/(1 - theta_k(2v)/k) over v >= z, and G is interpolated linearly in log z. Returns (the largest increase of G between neighbouring grid points, the largest value of g - (G - 2) with g = -dG/dlog z, the least value of G(z) - G(z/(1 - theta_k(2z)/k)) - 2/k for z < z_0, and k G(c_0) - Y^flat(k)).""" tau = tau_k(k); z = np.exp(np.linspace(log(tau/3), log(0.2), npts)); lz = np.log(z) S = z/(1 - A_theta_direct(k, 2*z)[0]/k); Slow = np.minimum.accumulate(S[::-1])[::-1] r = A_rec_std([k]); cn = float(r['c'][0]); psi = lambda v: 2 + np.log((1 - v)/v) z0 = 1/(1 + float(np.exp(2.0/k))*(1 - cn)/cn); p0 = float(psi(z0)) G = np.empty(npts); top = z >= z0; G[top] = psi(z[top]); i0 = int(np.argmax(top)) wdw = int(log(2.05)/(lz[1] - lz[0])) + 2 # a step multiplies z by at most 1/(1 - 1/2) = 2 for i in range(i0 - 1, -1, -1): G[i] = max(p0, 2.0/k + float(np.interp(log(Slow[i]), lz[i+1:i+wdw], G[i+1:i+wdw]))) slope = -np.diff(G)/np.diff(lz); below = z < z0 c0 = float(_dn(_flo(A_tau2_exact(k)/2))) return (float(np.max(np.diff(G))), float(np.max(slope - (0.5*(G[1:] + G[:-1]) - 2))), float(np.min(G[below] - np.interp(np.log(S[below]), lz, G)) - 2.0/k), k*float(np.interp(log(c0), lz, G)) - float(r['Y'][0])) def A_const_certify(prec=30): """enclosures for Lambda^star and C_0^star of (A.1) in decimal arithmetic with prec digits, independent of the logarithm of the floating point library: the method ln of the module decimal is correctly rounded, an error of 10^(3-prec) is allowed for each of its values, and all other operations are rounded in the safe direction. The series of the numbers Lambda_D^dagger is summed up to D = A_NT, and the remainder lies between 2/(A_NT+1) - 3/A_NT^2 and 2/A_NT, because log(1+2/D)/(D+7/6) <= Lambda_D^dagger <= 2/D^2 and log(1+2/D)/(D+7/6) >= 2/D^2 - 13/(3D^3) for D > A_NT. Returns (lo, hi) for Lambda^star and (lo, hi) for C_0^star, as fractions.""" from decimal import Decimal as Dm, localcontext, ROUND_FLOOR, ROUND_CEILING res = [] with localcontext() as ctx: ctx.prec = prec; eps = Dm(10)**(3 - prec) for mode, sg in ((ROUND_FLOOR, -1), (ROUND_CEILING, 1)): ctx.rounding = mode ln = lambda a, b: (Dm(a)/Dm(b)).ln() + sg*eps # a bound for log(a/b), in the direction of sg s = sum((Dm(c.numerator)/Dm(c.denominator))*ln(x.numerator, x.denominator) for c, x in A_PIECES_EXACT) for D in range(4, A_NT + 1): for c, x in A_lamdag_terms(D): s += (Dm(c.numerator)/Dm(c.denominator))*ln(x.numerator, x.denominator) s += (Dm(2)/Dm(A_NT + 1) - Dm(3)/Dm(A_NT)**2) if sg < 0 else Dm(2)/Dm(A_NT) c = 2 + ln(341, 41) + 2*s res.append((_Fr(str(s)), _Fr(str(c)))) return (res[0][0], res[1][0]), (res[0][1], res[1][1]) def A_previous_plus_certify(prec=30): """the numbers ceil(k(log k + 4.20032)/2), 6 <= k <= 36, of [BW2023, Theorem 9.1], in decimal arithmetic with prec digits: True if they agree with A_previous_plus(k) and the integer parts of the two bounds agree""" from decimal import Decimal as Dm, localcontext, ROUND_FLOOR, ROUND_CEILING ok = True with localcontext() as ctx: ctx.prec = prec; eps = Dm(10)**(3 - prec) for k in range(6, 37): ctx.rounding = ROUND_FLOOR; lo = Dm(k)*(Dm(k).ln() - eps + Dm('4.20032'))/2 ctx.rounding = ROUND_CEILING; hi = Dm(k)*(Dm(k).ln() + eps + Dm('4.20032'))/2 ok &= floor(lo) == floor(hi) and floor(lo) + 1 == A_previous_plus(k) and lo != floor(lo) return ok def A_previous_certify(prec=30): """the numbers ceil(k(log k + 4.20032)), 1 <= k <= 36, of (1.1), in decimal arithmetic with prec digits (as in A_const_certify): True if for every k the lower and the upper bound for k(log k + 4.20032) have the same integer part, and this integer part plus 1 is A_previous(k)""" from decimal import Decimal as Dm, localcontext, ROUND_FLOOR, ROUND_CEILING ok = True with localcontext() as ctx: ctx.prec = prec; eps = Dm(10)**(3 - prec) for k in range(1, 37): ctx.rounding = ROUND_FLOOR; lo = Dm(k)*(Dm(k).ln() - eps + Dm('4.20032')) ctx.rounding = ROUND_CEILING; hi = Dm(k)*(Dm(k).ln() + eps + Dm('4.20032')) ok &= floor(lo) == floor(hi) and floor(lo) + 1 == A_previous(k) and lo != floor(lo) return ok A_SQ = 4 - 2*log(TAU_INV/2) # c_star = 0.98565..., the coefficient of sqrt(k) in Proposition A.33 OB_EXPECT = [228, 615, 6186] # the bounds with the numbers of Lemma 4.3(ii) in (b), for k = 37, 100, 1000 NPR_EXPECT = [224, 618, 6208, 31124] # the bounds without the numbers (d) of Definition A.25, for k = 37, 100, 1000, 5000 G5_EXPECT = 31060 # the bound for G(5000) of Theorem A.1 (Proposition A.33) REC5000_EXPECT = 31014 # G^flat(5000) REC_G_EXPECT = [224, 615, 6186, 31014] # G^flat(k) for k = 37, 100, 1000, 5000 NNK_LO, NNK_HI, CNMIN_EXPECT = 0.94, 1.05, "0.1036" # the range of n/k and the least c_n for 37 <= k <= 5000 def A_table(): """the numbers of Section A.8 (Proposition A.39(i)) for 37 <= k <= KNUM (directed rounding): k -> dict(B, Th, kB, Y, G, l, x, s0, b, E, ref), where ref = 8 when the subdivision has been refined eightfold""" return A_table_rig() def A_exactlog_gain(k, sub=8, nodes=12): """the amount by which Y_k(Theta_k) would decrease if the integrand 2/theta - 1/k were replaced by 2/(-k log(1 - theta/k)), with theta = theta_k(2v) (the remark after the proof of Theorem A.31): the integral of k(2/theta - 1/k + 2/(k log(1 - theta/k))) dv/v over [tau_k, z_k], by Gauss-Legendre quadrature in log v, with theta_k computed directly from Definition A.25 (not rigorous)""" a0, b0 = 2*tau_k(k), 2*A_zk(k) bps = {a0, b0, A_check_t(k)} | {2.0**(-j-1) for j in range(1, 40)} D = 3 while 1/(D*(D+1)) > a0 and D < k: bps.add(1/(D*(D+1))); D += 1 bps = sorted(x for x in bps if a0 <= x <= b0) x, w = np.polynomial.legendre.leggauss(nodes); S, W = [], [] for a, b in zip(bps[:-1], bps[1:]): e = np.geomspace(a, b, sub+1) for c, d in zip(e[:-1], e[1:]): sa, sb = log(c), log(d) S.append(0.5*(sb-sa)*x + 0.5*(sb+sa)); W.append(0.5*(sb-sa)*w) S = np.concatenate(S); W = np.concatenate(W) th = A_theta_direct(k, np.exp(S))[0] return float(np.dot(W, k*(2/th - 1/k) + 2/np.log1p(-th/k))) A_REC_SELECT = (41, 50, 57, 64, 100, 128, 200, 256, 470, 471, 500, 638, 639, 872, 873, 1000, 2000, 3000, 4985, 5000) # the right half of Table 8 def A_before(k): """the bound for G(k) that was known before, as it is shown in Table 8: (1.1) for k <= 36, and the number floor(k B(k, Theta^sharp(k))) of Table 3 for k >= 37""" return A_previous(k) if k <= 36 else floor(k*bound(k, Theta_sharp(k))) def print_list_appendix(): """the numbers of Sections A.7 and A.8 of Appendix A, and the tables of [VW2000] as they are used""" rec = A_rec_table() print("# Section A.7, first case (Proposition A.37): k n c_n Y^flat(k) G^flat(k) l^flat(k) the bound for G(k) known before ((1.1) for k <= 36, Table 3 for k >= 37)") for k in range(A_KREC, KNUM+1): r = rec[k] print(f"{k:5d} {r['n']:5d} {r['c']:.6f} {r['Y']:13.6f} {r['G']:6d} {r['l']:6d} {A_before(k):6d}") print("# Section A.7, second case (Proposition A.38): k T_k n c_n Y^VW(k) G^VW(k) the bound for G(k) known before" " l^VW(k) the bound for G^+(k) of [BW2023, Theorems 9.1, 9.2] (- for k = 8)") for k in sorted(A_VW_T): r = A_rec_vw(k); gb = A_gplus_before(k) print(f"{k:5d} {A_VW_T[k]} {r['n']:3d} {r['c']:.6f} {float(r['Y']):11.6f} {r['G']:6d} {A_VW_PREVIOUS[k]:6d}" f" {r['l']:6d} {'-' if gb is None else gb:>6}") tab = A_table() print("# Section A.8 (Proposition A.39): k Theta^nat(k) B^nat(k) k B^nat(k) 2 s_0^nat(k) b^nat(k) E^nat(k) E^sharp(k) refinement of the subdivision") for k in range(37, KNUM+1): r = tab[k] print(f"{k:5d} {r['Th']:12.6f} {r['B']:.6f} {r['kB']:13.6f} {2*r['s0']:6d} {r['b']:.6f} {r['E']:11.3f} {E_sharp(k):11.3f} {r['ref']}") print("# the tables of [VW2000] for 7 <= k <= 20 as they are used: k s lambda_s phi_1") for k in sorted(A_VW4): for s, (l, p) in enumerate(zip(A_VW4[k].split(), A_VW4_PHI[k].split()), start=3): print(f"{k:5d} {s:3d} {l:>11s} {p}") print("# the tables of [VW1995] for k = 5 and 6 (Remark A.44): k s lambda_s phi_1") for k in sorted(A_VW95): for s, (l, p) in enumerate(zip(*(x.split() for x in A_VW95[k])), start=3): print(f"{k:5d} {s:3d} {l:>11s} {p}") def A_local_sums(p, s, j, u, D, g, r, b1=1): """The sums of the proof of Lemma A.17 for m = p, from their definitions (floating point; a plausibility check). Here A = p^s, q_D = p^(s-j), q_(D-1) = p^(2s-j), frak_j = p^j, b_2 = D b_1/(u+1) modulo q_(D-1) (as in (A.20)), X is the union of the classes of Lemma A.6 modulo p that are represented by the least elements of the cosets of the group of the E-th roots of unity, E = (u-1)u(u+1)(2u-1)(3u-1), and psi_c(n) = 1_X(n) 1[b_1 n^u = c mod q_D] e(g b_2 n^(u+1)/q_(D-1)) (n modulo A^2). With the transforms psi_c^(l) = A^(-2) sum_n psi_c(n) e(-l n/A^2), the function Omega(l) of (A.23) is A^2 times the sum over c of psi_c^(l) conj(psi_(c-r)^(l - l_0)), l_0 = frak_j D g r. Returns: whether each psi_c^ is supported on the frequencies l = frak_j g D c mod A ('line'); whether Omega(l) = 0 unless p^min(gamma,s) | l ('div'); the largest |Omega(l)| ('max') and the bound p^(min(gamma,s)+min(j,s)) of (A.24); whether p is a core prime ('core'); and then also p^gamma, the largest modulus of the complete sums of Omega(p^gamma l')/p^gamma e(h l'/p^eps) over the l' modulo p^eps in one residue class modulo p ('complete'), p^((eps+rho)/2) ('sqrt') and the number p^(eps-1) of terms ('trivial'); and whether the maps x -> x^i, i in {u-1, u, u+1, 2u-1, 3u-1}, are injective on the representatives ('classes').""" A = p**s; qD = p**(s - j); qD1 = p**(2*s - j); j0 = A//qD; A2 = A*A b2 = (D*b1*pow(u + 1, -1, qD1)) % qD1 E_ = (u - 1)*u*(u + 1)*(2*u - 1)*(3*u - 1) Gam = [w for w in range(1, p) if pow(w, E_, p) == 1]; seen = set(); Xc = [] for x in range(1, p): if x not in seen: Xc.append(x) for w in Gam: seen.add(x*w % p) okcl = all(len({pow(x, i, p) for x in Xc}) == len(Xc) for i in (u - 1, u, u + 1, 2*u - 1, 3*u - 1)) n = np.arange(A2, dtype=np.int64); inX = np.isin(n % p, Xc) def powmod(base, ex, mod): res = np.ones_like(base); bb = base % mod; e = ex while e: if e & 1: res = res*bb % mod bb = bb*bb % mod; e >>= 1 return res nu = powmod(n, u, qD); nu1 = powmod(n, u + 1, qD1) phase = np.exp(2j*np.pi*((g*b2*nu1) % qD1)/qD1); cval = (b1*nu) % qD l0 = (j0*D*g*r) % A2 def vp(x, cap): v = 0 while x % p == 0 and v < cap: v += 1; x //= p return v tau = vp(g, 99); rho = vp(r, s); gam = tau + j; core = s > gam and s > rho + j hat = {}; line = True for c in range(qD): sel = inX & (cval == c) if not sel.any(): continue h = np.fft.fft(np.where(sel, phase, 0))/A2 nz = np.nonzero(np.abs(h) > 1e-10)[0] line &= bool(np.all((nz - j0*g*D*c) % A == 0)); hat[c] = (nz, h[nz]) S = np.zeros(A2, dtype=complex) for c, (nz, hv) in hat.items(): c2 = (c - r) % qD if c2 not in hat: continue nz2, hv2 = hat[c2]; full2 = np.zeros(A2, dtype=complex); full2[nz2] = hv2 S[nz] += hv*np.conj(full2[(nz - l0) % A2]) Om = A2*S; mod = np.abs(Om); supp = np.nonzero(mod > 1e-7)[0] res = dict(line=line, div=bool(np.all(supp % p**min(gam, s) == 0)), max=float(mod.max()), bound=float(p**(min(gam, s) + min(j, s))), core=core, classes=okcl, nonzero=int(supp.size)) if core: e = 2*s - gam; z = Om[::p**gam]/p**gam; best = 0.0 for lam in range(p): idx = np.arange(lam, p**e, p) if np.abs(z[idx]).max() < 1e-7: continue w = np.zeros(p**e, dtype=complex); w[idx] = z[idx]; best = max(best, float(np.abs(np.fft.fft(w)).max())) res.update(pgamma=float(p**gam), complete=best, sqrt=float(p**((e + rho)/2)), trivial=float(p**(e - 1))) return res def A_omega_sharp_np(U, Dp): """omega_{D'}^sharp(U) of (A.45) in floating point, for arrays U and D' (D' >= 3 where it matters; 0 elsewhere)""" U = np.asarray(U, float); Dp = np.asarray(Dp, float) + np.zeros_like(U) out = np.zeros_like(U) for d in np.unique(Dp): if d < 3: continue sel = Dp == d; Us = U[sel]; best = np.full(Us.shape, -np.inf) for io in (1, 2): X = [(float(x0), float(xU), float(xb)) for _, x0, xU, xb, xv in _A_n_xterms(int(d), io)] best = np.maximum(best, np.min([(x0 + xU*Us - 1)/(1 - xb) for x0, xU, xb in X], axis=0)) ok = (Us >= (d + 1)/2) & (Us <= d + 1) & (best >= 0) out[sel] = np.where(ok, (1 + best)/(d*(d + 1)), 0.0) return out A_FRAC_C = 107336 # 10^4 times the rounded-up value 10.7336 of C_0^star + 9.027901/2 (Theorem A.5) A_FRACE_CONST = 8.2 # the constant in E^nat(k) < 10.7336 k - 2.37 sqrt k + (7/3) log k + 8.2 for k >= 5000 (Proposition A.39 (ii)) A_LAMDAG_TAB = {4: '0.093377852675', 5: '0.062960622165', 6: '0.045325327436', 7: '0.034191925112', 8: '0.026711284764', 9: '0.021444283625', 10: '0.017596748713', 11: '0.014700317437', 12: '0.012465096843', 13: '0.010703841143', 14: '0.009291352789'} # the values in Table 7, truncated def A_theta_bands_check(): """the pieces of theta^star on (p_(D+1), p_D] for 3 <= D <= 60 (Table 7, the top pieces of A_TOP3_PIECES for D = 3, and (A.51)) against the definition: at the end points and the midpoint of each piece the value theta = A - B t satisfies varsigma^star(theta) = t and varsigma^star(theta + 1e-9) < t, exactly (A_limit_closed_exact); the pieces fit together; theta^star is continuous at p_D for 3 <= D <= 60 except D = 5, 6, 7 (jumps 21/1625, 7/874, 2/583); the values of Table 7""" F = _Fr; ok = True; eps = F(1, 10**9) def pieces(D): if D == 3: return [(l, h, A, B) for l, h, A, B, o, g in A_TOP3_PIECES if h <= F(1, 12)] return [(l, h, A, B) for l, h, A, B, o in A_band_pieces(D)] for D in range(3, 61): ps = pieces(D); pD, pD1 = F(1, D*(D + 1)), F(1, (D + 1)*(D + 2)) ok &= ps[0][0] == pD1 and ps[-1][1] == pD and all(a[1] == b[0] and a[2] - a[3]*a[1] == b[2] - b[3]*b[0] for a, b in zip(ps, ps[1:])) for l, h, A, B in ps: for t in (h, (l + h)/2, l + (h - l)/1000): th = A - B*t ok &= A_limit_closed_exact(th) == t and A_limit_closed_exact(th + eps) < t jumps = {} for D in range(4, 61): above = pieces(D - 1)[0]; below = pieces(D)[-1]; pD = F(1, D*(D + 1)) jumps[D] = (below[2] - below[3]*pD) - (above[2] - above[3]*pD) ok &= jumps[5] == F(21, 1625) and jumps[6] == F(7, 874) and jumps[7] == F(2, 583) ok &= all(j == 0 for D, j in jumps.items() if D not in (5, 6, 7)) ok &= A_TOP3_PIECES[3][2] - A_TOP3_PIECES[3][3]*F(1, 12) == F(76, 25) == F(104, 25) - F(336, 25)/12 # continuity at p_3 = 1/12 for D, txt in A_LAMDAG_TAB.items(): v = sum(float(c)*log(float(x)) for c, x in A_lamdag_terms(D)) ok &= f"{floor(v*1e12)/1e12:.12f}" == txt and abs(v - float(_A_LDG[D - 4])) < 1e-15 return ok def A_band_large_checks(): """Section A.3 (the remarks after Lemma A.26), for D >= 15: the inequalities that give (A.51) [theta^star = phi^sharp_{D+1,1} on (p_{D+1}, t_D^N], phi_{D,1} on (t_D^N, p_D]], as polynomial inequalities in D (positive coefficients in D - 15); and the failure of one of them for D = 14. Returns (ok, number of polynomial checks)""" D = _RF_D; F = _Fr; KA = {1: F(1, 6), 2: F(1, 14)} def eta(d, io, U): return KA[io]*((io + 1)*(2*U/(d + 1) - 1) - 1) def six(d, io, U): U1 = U/(d + 1); e = 2*U1/9 if io == 1 else (2*U1 + 1)/42; c = F(1, 2) if io == 1 else F(2, 3) return [(d - 2)*(1 - U1)/d, ((2*d - 1)*(1 - U1) - 1)/(2*d), (d - U + eta(d, io, U))/(d + (io + 2)*KA[io]), (d - U + e)/d, (d - c - U + U1)/(d + c), (d - 1 - U + 2*U1)/(d + 1)] def phs(d, io, t): if io == 1: return 3*d*(d + 1)/(3*d + 1)*(2 - (d + F(1, 2))*(d + 1)*t) if io == 2: return d*(d + 1)/(7*d + 4)*(14 - (7*d + 2)*(d + 1)*t) return (d + 1)*(84*d + 1 - 42*d*d*(d + 1)*t)/(42*d + 40) def phi(Dd, io, t): return 3*(Dd + 1)/(3*Dd + 1)*(Dd + F(1, 2) - Dd*(Dd + 1)*t) if io == 1 else 7*(Dd + 1)/(7*Dd + 4)*(Dd + F(5, 7) - Dd*(Dd + 1)*t) pD, pD1 = 1/(D*(D + 1)), 1/((D + 1)*(D + 2)) tN = (6*D*D + 17*D + 4)/(6*D**4 + 29*D**3 + 57*D**2 + 48*D + 12); t1 = (6*D + 1)/(2*(D + 1)*(3*D*D + 4*D + 2)) d = D + 1; ok = (phs(d, 1, tN) - phi(D, 1, tN)).is_zero(); n = 0 Ulo, Uhi = phi(D, 1, tN), phs(d, 1, pD1) ineq = [t1 - pD1, tN - t1, pD - tN, phs(d, 1, pD1) - (D + 1), (d + 1) - Uhi, Ulo - (d + 1)/2] for U in (Ulo, Uhi): sx = six(d, 1, U); ineq += [sx[j] - sx[2] for j in (0, 1, 3, 4, 5)] ineq += [phs(d, 1, pD1) - phs(d, 3, pD1), phs(d, 1, tN) - phs(d, 3, tN), phi(D, 1, pD) - phs(d, 3, pD)] for f in ineq: ok &= f.pos_from(15); n += 1 f = phs(d, 1, tN) - phs(d, 3, tN); ok &= f(14) < 0 and f(15) > 0 # the uses of (eq:Atsharp): the slopes, and theta^star < D + 7/6 ok &= (3*d*(d + 1)/(3*d + 1)*(d + F(1, 2))*(d + 1) - 3*(D + 1)/(3*D + 1)*D*(D + 1)).pos_from(15) ok &= (D + F(7, 6) - Uhi).pos_from(15) and (Uhi - D - 1).pos_from(15) return ok, n def A_large_new_checks(): """the proof of Lemma A.32 for the pieces of theta^star that end with an interval N_{D',iota} (the corner method of the proof: for every k >= 5000), and for D >= 15 (polynomials in D - 15); the bound for rho_D^dagger (Proposition A.33). Returns (ok, details)""" F = _Fr; K0 = 5000; ok = True; det = {} def n_terms(Dp, io): # (r0, r1, r2, name, L) with r^N = min (r0 - r1 t - r2 vt) d = F(Dp); T1 = d*(d + 1); out = [] for nm, x0, xU, xb, xv in _A_n_xterms(Dp, io): out.append((x0/(-xU), T1/(-xU), xv/xU, nm, 0)); out.append(((x0 - xb)/(-xU), T1*(1 - xb)/(-xU), xv/xU, nm, 1)) return out def piece_ok(lo, hi, A, B, org, gam, prev): Dp, io, bnd = org[1], org[2], org[3] R = n_terms(Dp, io) b = [r for r in R if r[3] == bnd and r[4] == 1] good = len(b) == 1 and b[0][0] == A and b[0][1] == B and gam >= b[0][2] for r0, r1, r2, nm, L in R: # theta (1 + r2/k)/(1 + gam/k) <= r0 - r1 t for all k >= K0 for t in (lo, hi): th0 = A - B*t good &= (r0 - r1*t) - th0*(1 + max(r2 - gam, 0)/K0) >= 0 good &= (Dp + 3)*(A - B*lo)/K0 <= F(1, 4) and Dp*(Dp + 1)*lo >= 1 l0, l2 = F(Dp + 1, 2), F((Dp + 1)*(Dp - 1), 2) if prev[0] == 'R': J = prev[1]; terms = [(F(J + 2), F(2**(J + 2) - 2), F(0))]; good &= 2**(J + 1)*hi <= 1 else: terms = _A_tent_terms(prev[1]); good &= prev[1]*(prev[1] + 1)*hi <= 1 for r0, r1, r2 in terms: for t in (lo, hi): for vt in (F(0), (A - B*t)/K0): good &= (r0 - r1*t - r2*vt) - (l0 + l2*vt) >= 0 return good cnt = 0 for lo, hi, A, B, org, gam in A_TOP3_PIECES: if org[0] == 'N': ok &= piece_ok(lo, hi, A, B, org, gam, ('R', 2 if org[1] == 3 else 3)) and gam == A_gamma_piece(org); cnt += 1 for Dd in range(4, A_DBAND + 1): for lo, hi, A, B, org in A_BAND_PIECES[Dd]: if org[0] == 'N': ok &= piece_ok(lo, hi, A, B, org, A_gamma_piece(org), ('T', Dd)); cnt += 1 det['corner'] = cnt # D >= 15: the end conditions at the four corners (t in {p_{D+1}, t_D^N}, vt in {0, vt_D}), vt_D = (D + 7/6)/((2D+3)(2D+8)) D = _RF_D; d = D + 1; T1 = d*(d + 1); u = 1/(d + 1); KA = F(1, 6) pD1 = 1/((D + 1)*(D + 2)); tN = (6*D*D + 17*D + 4)/(6*D**4 + 29*D**3 + 57*D**2 + 48*D + 12) vtD = (D + F(7, 6))/((2*D + 3)*(2*D + 8)) X = [('G1', d - 1, -(d - 2)*u, -(d - 1), -(3*d - 1)), ('G3', d, -(d - 1)*u, -(d - 2), -(2*d - 1)), ('E5', d + 1 - 3*KA, -1 + 4*KA*u, -(d - 1 + 3*KA), -(d + 1 + 4*KA*d)), ('E6', 2*d - 1, -(2*d - 1)*u, -(2*d - 1), -(2*d - 1)), ('E7', d + 1, -1 + F(2, 9)*u, -(d - 1), -(F(11, 9)*d + F(7, 6))), ('E8', d + F(1, 2), -1 + u, -(d - F(1, 2)), -(2*d + F(3, 2))), ('E9', d, -1 + 2*u, -d, -2*d)] ok &= [x[0] for x in X] == [x[0] for x in _A_n_xterms(16, 1)] and all( all(a(15) == b for a, b in zip(x[1:], y[1:])) for x, y in zip(X, _A_n_xterms(16, 1))) R = [] for nm, x0, xU, xb, xv in X: R.append((x0/(-xU), T1/(-xU), xv/xU, nm, 0)); R.append(((x0 - xb)/(-xU), T1*(1 - xb)/(-xU), xv/xU, nm, 1)) b0, b1, b2 = [r[:3] for r in R if r[3] == 'E5' and r[4] == 1][0] ok &= (b2 - (d + 1)*(5*d + 3)/(3*d + 1)).is_zero() ok &= (b0 - 6*d*(d + 1)/(3*d + 1)).is_zero() and (b1 - 3*d*(d + 1)/(3*d + 1)*(d + F(1, 2))*(d + 1)).is_zero() npol = 0 for r0, r1, r2, nm, L in R: for t in (pD1, tN): for vt in (_RF([0]), vtD): f = (r0 - b0) - (r1 - b1)*t - (r2 - b2)*vt ok &= f.is_zero() or f.pos_from(15); npol += 1 ok &= (F(1, 4) - (D + 4)*vtD).pos_from(15) # the junction (5/8)(D+2) <= D - 3/2 (D >= 8) and D + 7/6 < D_Q + 1/6 (trivial); theta(D+7) < k from (D + 7/6)(D + 7) <= (2D+3)(2D+8) ok &= ((2*D + 3)*(2*D + 8) - (D + F(7, 6))*(D + 7)).pos_from(15) det['poly_end'] = npol # rho_D^dagger <= 10/(3D) + 5/(4 D^2) for D >= 15, with log(1+y) <= y - y^2/2 + y^3/3 N5 = 12*D**5 + 52*D**4 + 97*D**3 + 111*D**2 + 64*D + 12; P2 = 6*D*D + 17*D + 4 y1 = 8*(9*D**5 + 36*D**4 + 38*D**3 - 3*D**2 - 16*D - 4)/((3*D + 4)*N5) y2 = 2*(6*D**4 + 39*D**3 + 62*D**2 + 34*D + 6)/(D*(D + 1)*(2*D - 1)*P2) T3 = lambda y: y - y*y/2 + y**3/3 g1 = (D + 2)*(5*D + 8)/(3*D + 4); g2 = (D + 1)*(5*D + 3)/(3*D + 1) c1 = (3*D + 4)/(6*(D + 1)*(D + 2)); c2 = 2*(3*D + 1)/(3*(D + 1)*(2*D + 1)) fr = 10/(3*D) + F(5, 4)/(D*D) - g1*c1*T3(y1) - g2*c2*T3(y2) ok &= fr.pos_from(15) for Dv in (15, 16, 40, 1000): # the closed forms against the definitions (a1, x1), (a2, x2) = A_lamdag_terms(Dv) ok &= a1 == c1(Dv) and a2 == c2(Dv) and x1 - 1 == y1(Dv) and x2 - 1 == y2(Dv) ok &= [(c, x) for c, x in A_rhodag_terms(Dv)] == [(a1*g1(Dv), x1), (a2*g2(Dv), x2)] # Lambda_D^sharp - Lambda_D^dagger <= 1/(6 D^3) for D >= 15: ((D-2)/(6D+8)) (t_D^N/p_{D+1} - 1)/D^2 <= 1/(6D^3) fl = F(1, 6)/D**3 - (D - 2)/((6*D + 8)*D*D)*(tN/pD1 - 1) ok &= fl.pos_from(15) ok &= ((D + 2)*(6*D + 3)/(6*D + 8) - (D + 1) - (D - 2)/(6*D + 8)).is_zero() det['rho_deg'] = len(fr.n) - 1 return ok, det def part14(rng): print("14. Appendix A") Fr = Fraction # ---- (a) the constants (directed rounding), the library logarithm, and the limit of the saving function (Lemma A.26) lam0, lam1 = A_LAMBDA_R; c00, c01 = A_C0_R check(1.0506585 < lam0 < lam1 < 1.0506586 and lam1 - lam0 < 1e-11 and lam0 <= A_LAMBDA_LO and A_LAMBDA <= lam1 + 1e-15, f"Lambda^star lies in [{lam0:.12f}, {lam1:.12f}] (series of the numbers Lambda_D^dagger up to D = 1e6, remainder between " "2/(1e6+1) - 3/1e12 and 2/1e6)") check(6.2196274 < c00 < c01 < 6.2196275 and Fraction(c01) < Fraction(6219628, 10**6) and 0.09360 < C0 - c01 and C0 - c00 < 0.09361, f"C_0^star = 2 + log(341/41) + 2 Lambda^star lies in [{c00:.12f}, {c01:.12f}], so that C_0^star = 6.219627... < 6.219628 " f"(Theorem A.2); C_0 - C_0^star = {C0-A_C0:.6f}") check(Fraction(c01) + Fraction(45139505, 10**7) < Fraction(A_FRAC_C, 10000) and c00 + TAU_INV/2 > (A_FRAC_C - 1)/10000, f"C_0^star + 9.027901/2 = {A_C0+TAU_INV/2:.7f} < {A_FRAC_C/10000} (exact comparison of the upper bound)") (dl0, dl1), (dc0, dc1) = A_const_certify() check(Fr(lam0) <= dl0 <= dl1 <= Fr(lam1) and Fr(c00) <= dc0 <= dc1 <= Fr(c01) and dc1 - dc0 < Fr(1, 10**11) and A_previous_certify() and A_previous_plus_certify(), "the same intervals contain the enclosures for Lambda^star and C_0^star that are obtained in decimal arithmetic with 30 digits and a correctly " f"rounded logarithm (C_0^star lies in [{float(dc0):.13f}, {float(dc1):.13f}]); and the numbers ceil(k(log k + 4.20032)) of (1.1) for k <= 36, " "and ceil(k(log k + 4.20032)/2) of [BW2023, Theorem 9.1] for 6 <= k <= 36, are confirmed in the same way") from decimal import Decimal as _Dm, getcontext as _gc _gc().prec = 40; rl = random.Random(3) xs = np.array([2.0**rl.uniform(-2, 21) for _ in range(30000)] + [1 + 2.0**-rl.uniform(1, 40) for _ in range(30000)]) la = np.log(xs) # the array path, as in the computations same = all(float(np.log(float(x))) == float(y) for x, y in zip(xs[::7], la[::7])) ul = max(abs(_Dm(float(y)) - _Dm(float(x)).ln())/_Dm(float(np.spacing(y))) for x, y in zip(xs, la)) Ds = np.concatenate([np.arange(4, 2004), np.array(sorted(rl.sample(range(2004, A_NT + 1), 18000)))]).astype(float) xa = (4*Ds**3 + 7*Ds**2 + 8*Ds + 4)/Ds**4; l1 = np.log1p(xa) ul1 = max(abs(_Dm(float(y)) - (1 + _Dm(float(x))).ln())/_Dm(float(np.spacing(y))) for x, y in zip(xa, l1)) check(ul <= 1 and same and ul1 <= 1, f"np.log, applied to arrays, on 60000 sample arguments in [1/4, 2^21] and in (1, 3/2] is accurate to {float(ul):.2f} units in the last place, " f"and agrees with its values for single arguments; np.log1p on 20000 of the arguments that occur in the series for Lambda^star is accurate to " f"{float(ul1):.2f} units (the computations allow {A_LOG_ULP} units for the logarithm)") def closed(U): """the function (A.45): 1 - U/2, the lines of the words of Table 6 on their intervals, omega_3 up to U = 3, and for D <= U <= D + 1 with D >= 3 the larger of min{1, D+1-U+eta_D(U)}/(D(D+1)) and (2D+2-U)/((D+1)^2(D+2))""" U = np.asarray(U, float) D = np.floor(U); D = np.where(D == U, D-1, D); D = np.maximum(D, 3) eta = np.maximum((4*U - 3*(D+1))/(6*(D+1)), (3*U - 2*(D+1))/(7*(D+1))) gen = np.maximum(np.minimum(1.0, D+1-U+eta)/(D*(D+1)), (2*D+2-U)/((D+1)**2*(D+2))) conds = [U <= 11/10]; vals = [1 - U/2] for w, lo, hi in A_TABLE5: ka, la = _A_pair_exact(w) conds.append(U <= float(hi)); vals.append(1 - float(la) - float(ka)*(U - 1)) conds += [U <= 3]; vals += [(6 - U)/36] out = np.select(conds, vals, default=gen) Df = np.floor(U) for off in (-1, 0, 1, 2): # the numbers omega_{D'}^sharp, U - 1 < D' <= U + 1, U >= 264/95 Dp = Df + off msk = (Dp >= 3) & (U - 1 < Dp) & (Dp <= U + 1) & (U >= 264/95) out = np.where(msk, np.maximum(out, A_omega_sharp_np(U, Dp)), out) return out Ug = np.arange(1.0, 60.0, 1e-4) sv = A_saving(Ug, 0.0, 10**9, window=70) best = sv.copy() # all estimates of Section 4 as well (Lemma 4.3(ii), j = 1, ..., 5; Lemma 4.4) for j in range(1, 6): best = np.maximum(best, np.where(Ug >= j+2.0**-j, (j+2-Ug)/(2**(j+2)-2), 0)) for D in range(4, 80): a0 = Ug/(D+1); best = np.maximum(best, np.where(a0 < 1, np.minimum(np.minimum(2*a0, 1.0), D*(1-a0))/(D*(D+1)), 0)) check(np.max(np.abs(sv - closed(Ug))) < 1e-12 and np.max(np.abs(best - sv)) < 1e-12 and bool(np.all(np.diff(sv) <= 1e-15)), "Lemma A.26: varsigma^star(U, 0) equals the function (A.45) on [1, 60], is nonincreasing, and is not improved by Lemma 4.3(ii) or by Lemma 4.4") okf = True for kk in (5, 6, 7, 8, 13, 14, 17, 25): # part (ii) for small k: the inequality for every U, with equality for U <= k - 2 Uk = np.arange(1.0005, kk + 3.0, 1e-3); svk = A_saving(Uk, 0.0, kk, window=70); df = closed(Uk) - svk okf &= df.min() > -1e-13 and np.abs(df[Uk <= kk - 2]).max() < 1e-13 and bool(np.all(df[Uk >= kk - 1 + 2e-3] > 1e-9)) okj = all(2**(j+1) >= (j+1)*(j+2) for j in range(4, 200)) check(okf and okj, "Lemma A.26 (ii), (iii): for k = 5, 6, 7, 8, 13, 14, 17, 25 one has varsigma^star(U, 0) <= (A.45) on a grid of U <= k + 3, with equality for " "U <= k - 2 and strict inequality for U > k - 1; and 2^(j+1) >= (j+1)(j+2) for j >= 4") old_vs = np.array([varsigma(float(x)) for x in Ug[::25]]); dv = closed(Ug[::25]) - old_vs; Uc = Ug[::25] strict = Uc > 11/10 + 1e-9 check(dv.min() > -1e-15 and bool(np.all(dv[strict] > 0)) and np.abs(dv[~strict]).max() < 1e-15, "varsigma^star(U) >= varsigma(U) on [1, 60], with equality exactly for U <= 11/10") allw = [d['w'] for d in A_WORDS]; t5 = [w for w, lo, hi in A_TABLE5] pts, ev_all = A_limit_envelope_exact(allw); pts5, ev5 = A_limit_envelope_exact(t5) test = sorted(set(pts) | set(pts5)); test += [(x + y)/2 for x, y in zip(test, test[1:])] okx = all(ev_all(U) == A_limit_closed_exact(U) == ev5(U) for U in test) okx &= all(1 - la - ka*Fraction(17, 2) <= 0 for ka, la in (_A_pair_exact(w) for w in allw)) okx &= len(allw) == 133 and len(set(_A_pair_exact(w) for w in allw)) == 133 and len(t5) == 43 okx &= all(A_limit_closed_exact(hi) == (1 - _A_pair_exact(w)[1] - _A_pair_exact(w)[0]*(hi - 1)) for w, lo, hi in A_TABLE5) okx &= all(A_word_ok(w, k) for w in t5 for k in range(5, 200)) okx &= len(A_TS_PIECES) == 21 and [(Fraction(1)/Aw, (t_hi*(Aw - Bw*t_lo))/(t_lo*(Aw - Bw*t_hi))) for t_lo, t_hi, Aw, Bw, w in A_TS_PIECES[::-1]] == A_PIECES_EXACT pts0, ev0 = A_limit_envelope_exact(t5, with_e=False); ptsf, evf = A_limit_envelope_exact(t5, with_f=False, with_g=False) ptsg, evg = A_limit_envelope_exact(t5, with_g=False) oke = all(ev0(U) <= A_limit_closed_exact(U) for U in test) and any(ev0(U) < A_limit_closed_exact(U) for U in test) def x2(D): # the point up to which the first term in the last line of (A.45) is the larger one io = 2 if D <= 6 else 1; return (D + 1)*(2 - (D + 1)*(D + 2)*A_tQ_exact(D, io)) def Dof(U): return int(U) if U != int(U) else int(U) - 1 oke &= all(evf(U) <= A_limit_closed_exact(U, with_g=False) for U in test) and all((evf(U) < A_limit_closed_exact(U, with_g=False)) == (U > 3 and Dof(U) < U < x2(Dof(U))) for U in test) oke &= all(evg(U) == A_limit_closed_exact(U, with_g=False) <= A_limit_closed_exact(U) for U in test) and any(evg(U) < A_limit_closed_exact(U) for U in test) oke &= x2(3) == Fraction(44, 13) and x2(7) == Fraction(428, 59) and all(D < x2(D) < D + Fraction(1, 2) for D in range(3, 3001)) oke &= all(A_limit_closed_exact(U) == (6 - U)/36 for U in (Fraction(264, 95), Fraction(28, 10), Fraction(48, 17))) oke &= all(A_limit_closed_exact(U) == (168 - 25*U)/1104 for U in (Fraction(48, 17), Fraction(3), Fraction(76, 25))) oke &= all(A_limit_closed_exact(U) == (104 - 25*U)/336 for U in (Fraction(76, 25), Fraction(16, 5), Fraction(44, 13))) oke &= all(A_limit_closed_exact(U) == (8 - U)/80 for U in (Fraction(44, 13), Fraction(36, 10), Fraction(40, 11))) oke &= all(A_limit_closed_exact(U) == (35 - 4*U)/375 for U in (Fraction(40, 11), Fraction(4), Fraction(65, 16))) oke &= all(A_limit_closed_exact(U, with_g=False) == (6 - U)/36 for U in (Fraction(264, 95), Fraction(29, 10), Fraction(3))) oke &= all(A_limit_closed_exact(U, with_g=False) == Fraction(1, 12) for U in (Fraction(3), Fraction(151, 50), Fraction(76, 25))) oke &= all(A_limit_closed_exact(U, with_g=False) == (8 - U)/80 for U in (Fraction(44, 13), Fraction(37, 10), Fraction(4))) # the analytic part for U >= 4 (proof of Lemma A.26): the number in (e) for D' = D + j, j >= 2, is at most 1/((D+1)(D+2)) okan = all((D+2)**2*(D+3) - (D+4)*(D+1)*(D+2) == 2*D + 4 for D in range(4, 300)) okan &= all((D+j+1)**2*(D+j+2) - (D+2*j+2)*(D+1)*(D+2) > (D+j)**2*(D+j+1) - (D+2*j)*(D+1)*(D+2) for D in range(4, 300) for j in range(2, 60)) rnd = random.Random(5) for _ in range(300): # E_3 - 1 - (D'-U)/D' for vartheta = 0 (proof of Lemma A.26) d = rnd.randint(3, 400); U = Fraction(rnd.randint(1, 10**6), 10**6)*d lhs = (2*d-2)*(1 - U/(d+1)) - 1 - (d - U)/d okan &= lhs == (d*d - 3*d + (d - U)*(2*d*d - 3*d - 1))/(d*(d+1)) # the numbers in (f) for vartheta = 0 (proof of Lemma A.26, and the remarks after Corollary A.18) okff = True for d in range(3, 3001): F = Fraction for io in (1, 2): ka = F(1, 2**(io + 2) - 2) for U in (F(d), d + F(1, 4), d + F(1, 2), d + F(3, 4), F(d + 1)): E5 = d + 1 - U + ka*((io + 1)*(2*U/(d + 1) - 1) - 1); E6 = (2*d - 1)*(1 - U/(d + 1)) okff &= E5 == d + 1 - U + A_eta_exact(d, io, U) and E6 - E5 == (d - 2)*(1 - U/(d + 1)) - A_eta_exact(d, io, U) okff &= 2*U/(d + 1) >= 1 and d - 1 - (d - 2)*U/(d + 1) >= 1 # E_1 >= 1 and E_2 >= 1 if U <= d + F(1, 2): okff &= E6 >= E5 and A_eta_exact(d, io, U) <= A_eta_exact(d, io, d + F(1, 2)) <= F(d - 2, 2*(d + 1)) else: okff &= E5/(d*(d + 1)) <= (2*d + 2 - U)/((d + 1)**2*(d + 2)) and U >= F(2*(d + 2), 3) # at most omega_(d+1)(U) okff &= A_eta_exact(d, io, d + 1) == io*ka and io*ka*(d + 2) <= d okff &= A_eta_exact(d, 1, d) == F(d - 3, 6*(d + 1)) and A_eta_exact(d, 1, d + F(1, 2)) == F(d - 1, 6*(d + 1)) and A_eta_exact(d, 2, d + F(1, 2)) == F(2*d - 1, 14*(d + 1)) okff &= (F(1, 2) + A_eta_exact(d, 1, d + F(1, 2)))/(d*(d + 1)) == F(2*d + 1, 3*d*(d + 1)**2) and 2*d*d - d - 4 >= 0 okff &= (F(1, 2) + A_eta_exact(d, 2, d + F(1, 2)))/(d*(d + 1)) == F(3*(3*d + 2), 14*d*(d + 1)**2) and 10*d*d - 6*d - 24 >= 0 okff &= (A_eta_exact(d, 1, U) >= A_eta_exact(d, 2, U)) == (U >= F(9*(d + 1), 10)) okff &= A_eta_exact(3, 2, 3) == Fraction(1, 28) and all(Fraction(1, 6*(d - 1)*d) <= Fraction(1, d*(d + 1)) for d in range(4, 3001)) check(okx and oke and okan and okff, f"Lemma A.26 (ii), exactly (rational arithmetic, {len(test)} points of [1, 10]: the break points and the midpoints): the largest of the " "numbers in (a), (b), (c) of Definition A.25 for vartheta = 0, of the lines of the 133 words of W, of the pieces of omega_D on " "[(D+1)/2, D] and of omega_D^flat on [1, (D+1)/2], and of the pieces of the numbers in (f) on [D-1/2, D+1] (3 <= D <= 11) is the " "function (A.45); the same holds with the 43 words of Table 6 alone; without the numbers of (e) the envelope is smaller at some " "points, and without those of (f) it is smaller exactly on the intervals D < U < theta^star(t_D^(iota)) with D >= 3 (iota = 2 " "for D <= 6 and iota = 1 for D >= 7), which lie in (D, D + 1/2), and without those of (g) it is the function (A.45) without the " "numbers omega^sharp and smaller at some points; the function (A.45) is (6-U)/36 on [264/95, 48/17], (168-25U)/1104 on [48/17, 76/25], " "(104-25U)/336 on [76/25, 44/13], (8-U)/80 on [44/13, 40/11] and (35-4U)/375 on [40/11, 65/16] (without (g): (6-U)/36 on " "[264/95, 3], 1/12 on [3, 76/25], (8-U)/80 on [44/13, 4]); the lines of all words are <= 0 for U >= 19/2, the 133 pairs " "are distinct, and the 43 words are admissible for 5 <= k < 200; the 21 pieces of theta^star on (1/20, 41/191] give the 21 " "logarithmic terms of (A.1); the identities of the proof for U >= 4 ((D+j)^2(D+j+1) - (D+2j)(D+1)(D+2) is 2D+4 for j = 2 and " "increases with j, and the formula for E_3); and, for 3 <= D <= 3000 and iota = 1, 2, the statements on E_1, E_2, E_5, E_6 and " "eta_{D,iota} after Corollary A.18 and in the proof of Lemma A.26 (at U = D, D + 1/4, D + 1/2, D + 3/4, D + 1)") # the remarks after (A.45) on the numbers omega^sharp, and the part of the proof of Lemma A.26 that concerns (g) F = Fraction; okg = True okg &= all(A_omega_sharp_exact(3, U) == (168 - 25*U)/1104 for U in (F(48, 17), F(29, 10), F(3), F(76, 25))) okg &= all(A_omega_sharp_exact(4, U) == (35 - 4*U)/375 for U in (F(40, 11), F(4), F(65, 16))) for d in range(6, 400): okg &= A_beta_sharp_exact(d, F(d)) == F(d - 3, 3*(d + 1)*(2*d + 1)) v = F((d + 1)*(6*d - 3), 6*d + 2) okg &= A_beta_sharp_exact(d, v) == 0 and A_beta_sharp_exact(d, v - F(1, 10**6)) > 0 and A_beta_sharp_exact(d, v + F(1, 10**6)) < 0 okg &= d < v < d + F(1, 6) and v - d == A_eta_exact(d, 1, v) for d in range(3, 400): okg &= A_omega_sharp_exact(d + 1, F(d)) <= (1 + F(7, 6*(d + 1)))/((d + 1)*(d + 2)) < F(1, d*(d + 1)) okg &= A_omega_sharp_exact(d, F(d)) == A_limit_closed_exact(d) and A_beta_sharp_exact(d, F(d + 1)) < 0 for U in (F(d + 1, 2), F(3*d + 2, 4), F(d)): okg &= A_beta_sharp_exact(d, U) > 0 for D in range(4, 300): # degrees D' = D + j, j >= 2, in (g) (proof of Lemma A.26 (ii)) Uc = D + 1 - F(D*(D + 1), D*D + 2*D + 2) okg &= Uc >= D and (D + F(25, 6))*D*(D + 1) <= (D + 2)**2*(D + 3) and (D + F(25, 6))*(D*D + 2*D + 2) <= (D + 2)**2*(D + 3) okg &= (D + F(19, 6))*(D + 1) <= (D + 2)*(D + 3) and (D + 1 - Uc)/(D*(D + 1)) == F(1, D*D + 2*D + 2) okg &= (2*D + 4 - Uc + F(1, 6))*(D*D + 2*D + 2) <= (D + 2)**2*(D + 3) dif = [(D + j)**2*(D + j + 1) - (D + 2*j + F(1, 6))*(D + 1)*(D + 2) for j in range(3, 40)] okg &= dif[0] >= 0 and all(a < b for a, b in zip(dif, dif[1:])) for j in (2, 3, 5): # the bound f for omega^sharp_{D+j} on [D, D+1] (exact, at a few points) Dp = D + j for U in (F(D), Uc, F(D + 1), F(2*D + 1, 2)): okg &= A_omega_sharp_exact(Dp, U) <= (2*Dp - U + F(1, 6))/(Dp*Dp*(Dp + 1)) <= A_limit_closed_exact(U) okg &= all(F(2, d*(d + 1)) < F(1, 20) for d in range(12, 20)) and A_limit_closed_exact(4) >= F(1, 20) check(okg, "the remarks after (A.45): omega_3^sharp = (168-25U)/1104 on [48/17, 76/25], omega_4^sharp = (35-4U)/375 on [40/11, 65/16], " "beta_D^sharp(D) = (D-3)/(3(D+1)(2D+1)) and beta_D^sharp vanishes at (D+1)(6D-3)/(6D+2), where U - D = eta_{D,1}(U) < 1/6 " "(6 <= D < 400); the proof of Lemma A.26: omega_{D+1}^sharp(D) < 1/(D(D+1)), varsigma^star(D) = omega_D^sharp(D), beta_D^sharp > 0 " "on [(D+1)/2, D] and < 0 at D+1 (3 <= D < 400), and the inequalities for the degrees D + j, j >= 2 (exact, 4 <= D < 300)") # the remarks after Lemma A.26: the pieces of theta^star, its slopes, and theta^star(t) > 2 - t exactly for t < 41/191 pcs = [] for w, lo, hi in A_TABLE5: ka, la = _A_pair_exact(w) pcs.append((1 - la - ka*(hi - 1), 1 - la - ka*(lo - 1), (1 - la + ka)/ka, 1/ka)) pcs += [(_Fr(1, 12), _Fr(3, 34), _Fr(168, 25), _Fr(1104, 25)), (_Fr(3, 34), _Fr(17, 190), _Fr(6), _Fr(36)), (_Fr(9, 20), _Fr(1, 2), _Fr(2), _Fr(2))] pcs.sort() okts = pcs[0][0] == _Fr(1, 12) and pcs[-1][1] == _Fr(1, 2) and pcs[0][2] - pcs[0][3]/12 == _Fr(76, 25) okts &= all(a[1] == b[0] and a[2] - a[3]*a[1] == b[2] - b[3]*b[0] for a, b in zip(pcs, pcs[1:])) okts &= all(q[3] > 1 for q in pcs) t0 = _Fr(41, 191) okts &= sum(1 for q in pcs if q[0] < t0 <= q[1] and q[2] - q[3]*t0 == 2 - t0) == 1 def phi(D, io, t): # phi_{D,iota}(t) of (A.47) return _Fr(3*(D + 1), 3*D + 1)*(D + _Fr(1, 2) - D*(D + 1)*t) if io == 1 else _Fr(7*(D + 1), 7*D + 4)*(D + _Fr(5, 7) - D*(D + 1)*t) def mline(D, t): return (D + 1)*(2 - (D + 1)*(D + 2)*t) def tstar(D, t): # the first four lines of (A.48), and the last pD = _Fr(1, D*(D + 1)) if D <= 6: return phi(D, 2, t) if t > A_tQ_exact(D, 2) else mline(D, t) if D == 7: return phi(7, 2, t) if t > _Fr(9, 560) else (phi(7, 1, t) if t > _Fr(43, 2832) else mline(7, t)) return phi(D, 1, t) if t > A_tQ_exact(D, 1) else mline(D, t) rq = random.Random(17) for D in range(3, 1001): pD = _Fr(1, D*(D + 1)); pD1 = _Fr(1, (D + 1)*(D + 2)); tx = _Fr(D + 2, 10*D*(D + 1)) for io in (1, 2): tq = A_tQ_exact(D, io); U = phi(D, io, pD) okts &= pD1 < tq < pD and phi(D, io, tq) == mline(D, tq) okts &= D + 1 - U + A_eta_exact(D, io, U) == 1 and D + 1 - phi(D, io, tq) + A_eta_exact(D, io, phi(D, io, tq)) == D*(D + 1)*tq okts &= phi(D, 1, tx) == phi(D, 2, tx) == _Fr(9*(D + 1), 10) and (tx >= pD) == (D >= 8) and (tx <= A_tQ_exact(D, 2)) == (D <= 6) == (7*D**3 - 45*D*D + 16 <= 0) okts &= phi(D, 1, pD) >= D and mline(D, pD1) == D + 1 and (D == 3 or mline(D - 1, pD) == D) okts &= _Fr(3*D*(D + 1)**2, 3*D + 1) > 1 and _Fr(7*D*(D + 1)**2, 7*D + 4) > 1 and (D + 1)**2*(D + 2) > _Fr(3*D*(D + 1)**2, 3*D + 1) > _Fr(7*D*(D + 1)**2, 7*D + 4) ts = [pD, pD1 + (pD - pD1)*_Fr(1, 10**6)] + [pD1 + (pD - pD1)*_Fr(rq.randint(1, 10**6), 10**6) for _ in range(4)] + [A_tQ_exact(D, 1), A_tQ_exact(D, 2), tx] for t in ts: if pD1 < t <= pD: th = max(phi(D, 1, t), phi(D, 2, t), mline(D, t)) okts &= th == tstar(D, t) and D <= th < D + 1 if D <= 11: okts &= A_limit_closed_exact(th, with_g=False) == t # theta^star_circ(t): largest U with varsigma^star_circ(U) >= t okts &= phi(3, 2, _Fr(1, 12)) == _Fr(76, 25) and A_tQ_exact(3, 2) == _Fr(3, 52) and phi(3, 2, _Fr(3, 52)) == _Fr(44, 13) == 8 - 80*_Fr(3, 52) okts &= all(phi(3, 2, t) == (104 - 336*t)/25 for t in (_Fr(3, 52), _Fr(1, 13), _Fr(1, 12))) okts &= A_tQ_exact(7, 1) == _Fr(43, 2832) < A_tQ_exact(7, 2) < _Fr(9, 560) == _Fr(7 + 2, 10*7*8) and phi(7, 2, _Fr(1, 56)) == _Fr(376, 53) and phi(7, 1, _Fr(9, 560)) == _Fr(36, 5) \ and phi(7, 1, _Fr(43, 2832)) == _Fr(428, 59) # the numbers Lambda_D^sharp are the integrals of 1/(t theta^star(t)) over (p_(D+1), p_D] (exact arguments of the logarithms) def piece_terms(A, B, lo, hi): return (1/A, (hi*(A - B*lo))/(lo*(A - B*hi))) # int_lo^hi dt/(t(A - Bt)) = (1/A) log(...) for D in list(range(4, 60)) + [100, 1000, 12345]: pD = _Fr(1, D*(D + 1)); pD1 = _Fr(1, (D + 1)*(D + 2)) if D == 7: cuts = [(pD1, A_tQ_exact(7, 1), 'M'), (A_tQ_exact(7, 1), _Fr(9, 560), 1), (_Fr(9, 560), pD, 2)] else: io = 2 if D <= 6 else 1; cuts = [(pD1, A_tQ_exact(D, io), 'M'), (A_tQ_exact(D, io), pD, io)] got = [] for lo, hi, kind in cuts[::-1]: if kind == 'M': A, B = _Fr(2*(D + 1)), _Fr((D + 1)**2*(D + 2)) elif kind == 1: A, B = _Fr(3*(D + 1), 3*D + 1)*(D + _Fr(1, 2)), _Fr(3*(D + 1), 3*D + 1)*D*(D + 1) else: A, B = _Fr(7*(D + 1), 7*D + 4)*(D + _Fr(5, 7)), _Fr(7*(D + 1), 7*D + 4)*D*(D + 1) got.append(piece_terms(A, B, lo, hi)) okts &= got == [(c, _Fr(a, b)) for c, a, b in A_lamsharp_terms(D)] check(okts, f"the remarks after Lemma A.26, exactly: above 1/12 the function theta^star is continuous ({len(pcs)} pieces on (1/12, 1/2]: " "omega_3^sharp, omega_3, the lines of the 43 words of Table 6, and 2 - 2t on [9/20, 1/2]), with slopes less than -1, and " "theta^star(41/191) = 341/191 = 2 - 41/191; for 3 <= D <= 1000: p_(D+1) < t_D^(iota) < p_D, phi_{D,iota} is the inverse of " "(D+1-U+eta_{D,iota}(U))/(D(D+1)) and meets the function of (e) at t_D^(iota), phi_{D,1} = phi_{D,2} = 9(D+1)/10 at " "(D+2)/(10D(D+1)), which is >= p_D exactly for D >= 8 and <= t_D^(2) exactly for D <= 6, the formula (A.48) gives the largest of " "the three functions at random points (and for D <= 11 it is the inverse of (A.45) without the numbers omega^sharp, that is, " "theta^star_circ), the slopes are ordered and less " "than -1, and theta^star(p_D) >= D, the limit from above; the special values for D = 3 and D = 7; and the terms of " "Lambda_D^sharp are the integrals of 1/(t theta^star(t)) over the ranges of (A.48) (4 <= D < 60 and three larger D)") def lead(w): return len(w) - len(w.lstrip('A')) okad = all(A_word_ok(w, k) == (lead(w) <= k - 3) for w in allw for k in range(5, 3001)) check(okad and all(lead(w) <= 7 for w in allw), "for 5 <= k <= 3000 a word of W is admissible for k if and only if it does not begin with k - 2 letters A (exact arithmetic); " "no word of W begins with 8 letters A, so that all are admissible for k >= 10") okb3, nb3 = A_band_large_checks(); okb3 &= A_theta_bands_check() check(okb3, f"the remarks after Lemma A.26 for the numbers omega^sharp: Table 7 (the pieces of theta^star on (p_(D+1), p_D], 3 <= D <= 14) " "and (A.51) for 15 <= D <= 60 are the inverse of (A.45) (exact, at the end points and at interior points of the pieces, with a " "check that varsigma^star < t just beyond theta^star(t)); theta^star is continuous at p_D except for D = 5, 6, 7, where it falls " f"by 21/1625, 7/874, 2/583; the values Lambda_D^dagger of Table 7; and, for D >= 15, {nb3} inequalities between rational " "functions of D that give (A.51) (positive coefficients in D - 15), one of which fails for D = 14") inc = np.log(sv[:-1]/sv[1:])/Ug[1:] Dt = np.arange(60, 10**7, dtype=float) N5t = 12*Dt**5 + 52*Dt**4 + 97*Dt**3 + 111*Dt**2 + 64*Dt + 12; P2t = 6*Dt*Dt + 17*Dt + 4 tail = float(np.sum((3*Dt + 4)/(6*(Dt + 1)*(Dt + 2))*np.log1p(8*(9*Dt**5 + 36*Dt**4 + 38*Dt**3 - 3*Dt**2 - 16*Dt - 4)/((3*Dt + 4)*N5t)) + 2*(3*Dt + 1)/(3*(Dt + 1)*(2*Dt + 1))*np.log1p(2*(6*Dt**4 + 39*Dt**3 + 62*Dt**2 + 34*Dt + 6)/(Dt*(Dt + 1)*(2*Dt - 1)*P2t)))) + 2e-7 # sum_{D >= 60} Lambda_D^dagger Iv = tail + np.concatenate([np.cumsum(inc[::-1])[::-1], [0.0]]); z0 = sv/2 msk = (z0 > 0.02) & (z0 < 0.3); Fv = 2 + np.log((1-z0[msk])/z0[msk]) + 2*Iv[msk]; i = int(np.argmin(Fv)) msk2 = (z0 > 0.02) & (z0 <= 0.1); Fv2 = 2 + np.log((1-z0[msk2])/z0[msk2]) + 2*Iv[msk2]; i2 = int(np.argmin(Fv2)) c_ten = 2 + log(9) + 2*(A_LAMBDA - (52/145)*log(6232/5797) - (11/31)*log(1309/1216)) + (22/31)*log(847/816) check(abs(Fv[i] - A_C0) < 2e-4 and abs(z0[msk][i] - 41/382) < 2e-4 and abs(Fv2[i2] - c_ten) < 2e-4 and abs(z0[msk2][i2] - 0.1) < 1e-4 and 6.22080 < c_ten < 6.22081, f"Psi(z_0) + 2 int_0^z_0 du/(u theta(2u)), from the definition on a grid: its least value is {Fv[i]:.5f}, at z_0 = {z0[msk][i]:.4f} " f"(the constant C_0^star, with z_0 = 41/382); for z_0 <= 1/10 it is {Fv2[i2]:.5f}, at z_0 = {z0[msk2][i2]:.4f}, in agreement with " f"2 + log 9 + 2 int_0^(1/5) dt/(t theta^star(t)) = {c_ten:.6f} (Section A.3)") # ---- (b) Lemmas A.7-A.9 on small examples: exact counts of pairs (plausibility checks, not needed for the proofs) def classes_mod_p(p, u): mu = [w for w in range(1, p) if pow(w, u*(u+1), p) == 1] label, seen = {}, set() for x in range(1, p): if x in seen: continue t = min(x*w % p for w in mu) for w in mu: y = t*w % p; label[y] = w; seen.add(y) return label def vp(n, p): if n == 0: return 10**9 v = 0 while n % p == 0: n //= p; v += 1 return v def run(k, D, pe, X, a=1, meanvalue=True): primes = [p for p, _ in pe]; J = len(primes); u = k - D m = int(np.prod(primes)); q = 1 for p, ee in pe: q *= p**ee s = {p: max(1, -(-ee//(D+1))) for p, ee in pe} A = 1; qD = 1; qD1 = 1 for p, ee in pe: A *= p**s[p]; qD *= p**max(ee-D*s[p], 0); qD1 *= p**max(ee-(D-1)*s[p], 0) Y = X//A from math import comb aD = a*comb(k, D)*(A**D//(q//qD)); aD1 = a*comb(k, D-1)*(A**(D-1)//(q//qD1)) assert Y >= 1 and gcd(aD, qD) == 1 and gcd(aD1, qD1) == 1 and qD1 % qD == 0 labs = {p: classes_mod_p(p, u) for p in primes} L = X + A*Y; cls = {} for n in range(-A*Y+1, X+1): if gcd(n, m) == 1: cls.setdefault(tuple(labs[p][n % p] for p in primes), []).append(n) d1, d2 = 2/Y**D, 2/Y**(D-1) ndiv = 1 for p, ee in pe: ndiv *= max(ee-(D-1)*s[p], 0) + 1 N1 = lambda dl: 2*L*L/qD1 + 4*k**J*ndiv*dl*(L*qD1/qD**2 + L*L/qD) rnd = random.Random(1); okP = True; okB = True; worst = 0.0; Rmax = 0.0; w = D*(D+1)//2; nb = 0 for lst in cls.values(): for _ in range(200): n1, n2 = rnd.choice(lst), rnd.choice(lst) for p in primes: v = vp(n1-n2, p) okP &= (vp(n1**u-n2**u, p) == v) and (vp(n1**(u+1)-n2**(u+1), p) == v) nn = np.array(lst, dtype=np.int64) x1 = np.array([aD*pow(n, u, qD) % qD for n in lst], dtype=np.int64) x2 = np.array([aD1*pow(n, u+1, qD1) % qD1 for n in lst], dtype=np.int64) N = len(lst); M = Ma = Mb = 0 for i0 in range(0, N, 300): sl = slice(i0, min(N, i0+300)) r1 = (x1[sl, None]-x1[None, :]) % qD; r1 = np.minimum(r1, qD-r1) r2 = (x2[sl, None]-x2[None, :]) % qD1; r2 = np.minimum(r2, qD1-r2) okm = (r1 <= d1*qD) & (r2 <= d2*qD1); dd = nn[sl, None]-nn[None, :] M += int(okm.sum()); Ma += int((okm & (dd % qD == 0) & (dd != 0)).sum()); Mb += int((okm & (dd % qD != 0)).sum()) bA = N1(d2); bB = (2*d1*qD*L + 2*d1*(qD+L)*N1(2*d2)) if d1*qD >= 1 else 0.0 okB &= (Ma <= bA) and (Mb <= bB) and (M == N + Ma + Mb); nb += Mb worst = max(worst, M/(L+bA+bB)) if meanvalue and Y >= 2: g = np.empty(N) for i, n in enumerate(lst): ph = np.array([a*pow(int(n+A*y), k, q) % q for y in range(Y)], dtype=np.float64)/float(q) g[i] = abs(np.exp(2j*pi*ph).sum()) Rmax = max(Rmax, float((g**w).sum())/(Y**w*M**0.5)) return okP, okB, worst, Rmax, nb, len(cls) okP = okB = True; worst = Rmax = 0.0; ncl = 0; nbs = [] for cfg in [(9, 3, [(11, 8)], 600, True), (9, 3, [(11, 8)], 1500, True), (9, 3, [(11, 7)], 700, True), (11, 4, [(13, 10)], 1000, True), (9, 3, [(11, 8), (13, 4)], 20000, False), (9, 3, [(11, 4), (13, 8)], 9000, False), (13, 3, [(17, 8)], 2000, True)]: r = run(cfg[0], cfg[1], cfg[2], cfg[3], meanvalue=cfg[4]) okP &= r[0]; okB &= r[1]; worst = max(worst, r[2]); Rmax = max(Rmax, r[3]); nbs.append(r[4]); ncl += r[5] check(okP, f"Lemma A.7 (valuations) on random pairs of equivalent integers, {ncl} classes in 7 configurations (k, D, q, X)") check(okB and worst < 1 and sum(1 for x in nbs if x > 0) >= 2, f"Lemma A.8 in the situation of Lemma A.9, 7 configurations: exact counts of the pairs of both kinds against the bounds of the proof; largest ratio count/bound = {worst:.3f}") check(0 < Rmax < 1, "a plausibility check for the proof of Lemma A.9 (the lemma does not assert this inequality): the sum of |g_Y|^w over a class, " f"divided by Y^w M^(1/2), is at most {Rmax:.3f}") nV, nbad, wr, n1, neq, n3 = A_pairs_test(seed=1, ntr=200) check(nbad == 0 and nV >= 300 and n1 >= 30 and neq >= 30 and n3 >= 20 and wr < 1, f"Lemma A.8 on 200 random configurations (3 <= k <= 12, up to three primes, moduli r_1 | r_2 including r_1 = 1 and r_1 = r_2, negative integers, " f"delta_1 and delta_2 of several sizes): {nV} sets V, exact counts against the bound of the lemma and the intermediate bounds of its proof; " f"no failure, largest ratio count/bound = {wr:.3f}; r_1 = 1 in {n1} configurations, r_1 = r_2 in {neq}, pairs with r_1 not dividing n - n' in {n3} sets") C1 = lambda kk, JJ: 4*kk**JJ*(kk+1)**JJ okm = True; rm = random.Random(9) for _ in range(2000): # the last step of the proof of Lemma A.9, with random values of the quantities kk = rm.randint(3, 40); JJ = rm.randint(1, 4); X = Fr(rm.randint(50, 10**7)); Y = Fr(rm.randint(1, int(X))); Dd = rm.randint(2, 6) qD = Fr(rm.randint(1, int(X))); qD1 = qD*rm.randint(1, 10**4); dq = rm.randint(1, (kk+1)**JJ); L = 2*X d1 = 2/Y**Dd; d2 = 2/Y**(Dd-1); N1 = lambda dl: 2*L*L/qD1 + 4*kk**JJ*dq*dl*(L*qD1/qD**2 + L*L/qD) Bq = 1/qD1 + qD1/(Y**(Dd-1)*X*qD**2) + 1/(Y**(Dd-1)*qD) Mb = L + N1(d2) + 2*d1*(qD*L + (qD + L)*N1(2*d2)) okm &= N1(d2) <= 8*C1(kk, JJ)*X*X*Bq and N1(2*d2) <= 16*C1(kk, JJ)*X*X*Bq and Mb/X**2 <= 192*C1(kk, JJ)*(1/X + (1 + X/Y**Dd)*Bq + qD/(Y**Dd*X)) check(okm, "the last step of the proof of Lemma A.9 (exact arithmetic, 2000 random values of the quantities with q_D <= X and d(q_(D-1)) <= (k+1)^J): " "N_1(delta_2) <= 8 C X^2 B, N_1(2 delta_2) <= 16 C X^2 B and M/X^2 <= 192 C times the expression in the lemma, where C = 4 k^J (k+1)^J") # ---- (b') the local sums Omega_p of the proof of Lemma A.17, for m = p (plausibility checks, not needed for the proof) okO = True; nO = 0; ncore = 0; sharp = 0 for cfg in [(17, 2, 0, 2, 3, 1, 3), (17, 2, 0, 2, 3, 1, 17), (17, 2, 1, 2, 3, 1, 5), (17, 2, 0, 2, 3, 17, 5), (17, 2, 1, 2, 3, 17, 5), (13, 3, 1, 2, 4, 13, 13), (23, 2, 0, 3, 4, 2, 7)]: r = A_local_sums(*cfg); nO += 1 okO &= r['line'] and r['div'] and r['max'] <= r['bound']*(1 + 1e-9) and r['classes'] and r['nonzero'] > 0 if r['core']: ncore += 1; okO &= r['max'] <= r['pgamma']*(1 + 1e-9) and r['complete'] <= r['sqrt']*(1 + 1e-9) and r['sqrt'] < r['trivial'] sharp += r['complete'] > 0.99*r['sqrt'] check(okO and ncore == 6 and sharp >= 4, f"the proof of Lemma A.17 on {nO} configurations (p, s, j, u, D, g, r) with m = p in (13, 17, 23) (Fourier transforms modulo A^2 = p^(2s), " "computed from the definitions): the transform of psi_c is supported on the frequencies l = jgDc mod A; (A.24): Omega(l) = 0 unless " f"p^min(gamma,s) | l, and |Omega(l)| <= p^(min(gamma,s)+min(j,s)); for the {ncore} configurations in which p is a core prime, |Omega(l)| <= p^gamma, and " "the complete sums of Omega(p^gamma l') e(h l'/p^eps) over the l' modulo p^eps (eps = 2s - gamma) in a residue class modulo p are at most " f"p^gamma p^((eps+rho)/2) in modulus, for every h (square-root cancellation along the line; equality to within 1 per cent in {sharp} cases)") # ---- (c) falsification test of Lemma A.27(i) on explicit sums def expsum(q, m, k, X, a): r = np.array([(a*pow(n, k, q)) % q for n in range(1, X+1) if gcd(n, m) == 1], dtype=np.float64)/q return abs(np.exp(2j*np.pi*r).sum()) worstS = 0.0; ns = 0; npos = 0; maxsv = 0.0 for (k, m, q, Xs) in [(13, 17, 17**12, [4913, 20000, 83521]), (13, 17, 17**13, [10000, 60000]), (11, 13, 13**11, [3000, 12000, 40000]), (13, 17*19, (17*19)**6, [20000, 104329]), (11, 13*17, 13**10*17**5, [30000, 120000]), (9, 11, 11**9, [900, 2500, 8000])]: for X in Xs: U = log(q)/log(X); vt = log(m)/log(X); sv1 = float(A_saving(np.array([U]), vt, k, window=40)[0]) npos += 4*(sv1 > 0); maxsv = max(maxsv, sv1) for a in (1, 2, 3, 5): worstS = max(worstS, expsum(q, m, k, X, a)/X**(1-sv1)); ns += 1 check(worstS < 0.06 and npos == ns == 60 and 0.11 < maxsv < 0.115, f"{ns} sums with k in {{9, 11, 13}}, 2.4 < U < 4: largest |S|/X^(1-varsigma^star(U,vartheta)) = {worstS:.3f}, that is, the bound holds without the " f"factor X^(omega + eps) of the lemma; the saving varsigma^star is positive for all {npos} sums (it comes from the numbers s_j of Lemma A.14), and at most {maxsv:.4f}") # ---- (d) the chains of Lemma A.28 against Definition A.25, and the coefficients in its proof rnd = random.Random(7); worstm = 0.0; worstd = -1.0; ntr = 0; nfam = set() for _ in range(240): k = rnd.choice([6, 7, 8, 9, 10, 12, 13, 16, 17, 20, 23, 29, 36, 37, 41, 50, 64, 100, 233, 500, 1000, 2000, 5000]) t = E**rnd.uniform(log(2*tau_k(k)), log(0.19)) Dl = A_Dlim(k); div = A_divpoints(Dl); b = div[int(np.searchsorted(div, t, side='left'))] # the least point of division >= t J, D = A_family(np.array([b]), np.array([float(k)]), np.array([Dl])) th = float(A_theta_hat_lo(np.array([float(k)]), np.array([t]), J, D)[0]); nfam.add((int(J[0]), int(D[0]) >= 3)) lo = float(A_theta_direct(k, np.array([t]))[0][0]) worstd = max(worstd, (th - lo)/lo) if th > 1: U = np.linspace(1+1e-9, th, int(3000*th)+2) worstm = min(worstm, (float(A_saving(U, th/k, k, window=40).min()) - t)/t) ntr += 1 check(worstm > -1e-11 and worstd < 1e-12 and len(nfam) >= 12, f"{ntr} random pairs (k, t) with 6 <= k <= 5000, {len(nfam)} different choices of J and of the presence of tents: for the largest theta given " f"by the chains of the family of the next point of division, varsigma^star(U, theta/k) >= t for all U <= theta on a grid (least relative margin " f"{worstm:.1e}), and theta does not exceed theta_k(t) computed directly from Definition A.25 (largest relative excess {worstd:.1e})") okc = True def near_lo(x, ex): return Fr(x) <= ex < Fr(float(_up(x))) # x is the largest floating point number <= ex, or the next one below def near_up(x, ex): return Fr(float(_dn(x))) < ex <= Fr(x) for D in range(3, 3001): d = Fr(D) rho = [((d+1)*(d-1)/(d-2), d*(d+1)**2/(d-2), (d+1)*(2*d-1)/(d-2)), (d+1, d*(d+1)**2/(2*d-2), (d+1)*(3*d-1)/(2*d-2)), (d+1, d*(d+1), d)] # (rho_0, rho_1, rho_2) for the three terms of r_D; the left end point of T_(D+1) is lam1 t + lam2 vartheta lam1 = (d+1)*(d+2)**2/2; lam2 = d*(d+2)/2 okc &= all(r2 >= 3 and r0 <= r2 + 1 for r0, r1, r2 in rho) and (d+1)*(d-1)/2 >= 4 okc &= all(r0 < lam2 + r2 and r0 < D + 1 + r2 for r0, r1, r2 in rho) # a_1 < 1 at the junction T_D, T_(D+1), and at the end (k >= D + 1) if D <= 1600: # the constants that the program uses are these numbers, rounded okc &= all(near_lo(P, r0) and near_up(Q, r1 + lam1) and Fr(Rl) <= lam2 + r2 <= Fr(Ru) and Fr(Ru) - Fr(Rl) <= Fr(float(np.spacing(Ru))) for (P, Q, Rl, Ru), (r0, r1, r2) in zip(_A_jconst(D), (rho[2], rho[1], rho[0]))) okc &= all(near_lo(P, r0) and near_up(Q, r1) and Fr(cl) <= r2 <= Fr(cu) and Fr(cu) - Fr(cl) <= Fr(float(np.spacing(cu))) for (P, Q, cl, cu), (r0, r1, r2) in zip(_A_econst(D), (rho[2], rho[1], rho[0]))) A1, A2 = _A_gtab(600); rq = random.Random(13); okg = True for J in range(A_JMAX + 1): for D in range(3, 601): a1, a2 = _A_gcoef(J, D); d = Fr(D) okg &= near_lo(A1[J, D-3], min(a1, Fr(1))) and near_up(A2[J, D-3], a2) if D <= 60: # l_D <= R_J(t) iff vartheta <= a_1 - a_2 t, at random rational points for _ in range(3): t = Fr(rq.randint(1, 10**6), 10**6*2**(J+1)); vt = Fr(rq.randint(0, 10**6), 2*10**6) l = (d+1)*(d*(d+1)*t + (d-1)*vt)/2; R = J + 2 - (2**(J+2) - 2)*t okg &= (l <= R) == (vt <= a1 - a2*t) okg &= all(2*((D*D-5)//2 + 2) <= D*D - 1 < 2*((D*D-5)//2 + 3) for D in range(3, 3001)) # J_c(D) is the largest J with a_1 <= 1 okg &= all(J*Fr(1, 2) <= J + 1 - (2**(J+2) - 2)*Fr(1, 2**(J+1)) for J in range(1, 200)) # Lemma A.28(ii): I_J begins below R_(J-1)(t) check(okc and okg, "Lemma A.28 (iv): for the tents T_D (3 <= D <= 3000) every term of a right end point has rho_2 >= 3 and rho_0 <= rho_2 + 1, and lambda_2 >= 4, so that " "every junction and end condition has a_1 < 1; for D <= 1600 the three constants of each junction and end condition in the program are the exact " "fractions derived from the end points of Lemma A.28, rounded in the safe direction; for the condition l_D <= R_J(t) (J <= 40, D <= 600) the " "program's constants are min{a_1, 1} and a_2 rounded in the safe direction, and the condition agrees with vartheta <= a_1 - a_2 t at random " "rational points; J_c(D) = floor((D^2-5)/2) is the largest J with a_1 <= 1; and the inequality in the proof of Lemma A.28(ii)") okq = True; rq = random.Random(23) for D in range(3, 1601): d = Fr(D); QC = _A_q_floats(D); tt = _A_tent_terms(D) okq &= tt == [((d+1)*(d-1)/(d-2), d*(d+1)**2/(d-2), (d+1)*(2*d-1)/(d-2)), (d+1, d*(d+1)**2/(2*d-2), (d+1)*(3*d-1)/(2*d-2)), (d+1, d*(d+1), d)] a1 = (d+1)**2*d/2; a2 = (d+1)*(d-1)/2 ex = [(c0 - (d - Fr(1, 2)), c1, c2) for c0, c1, c2 in tt] + [(c0, a1 + c1, a2 + c2) for c0, c1, c2 in tt] okq &= all(near_lo(Pf, e0) and near_up(Qf, e1) and Fr(Rl) <= e2 <= Fr(Ru) and Fr(Ru) - Fr(Rl) <= Fr(float(np.spacing(Ru))) for (Pf, Qf, Rl, Ru), (e0, e1, e2) in zip(QC['J'], ex)) okq &= near_lo(QC['cap'], Fr(1, 4*(D + 3))) for io in (1, 2): ka = Fr(1, 2**(io + 2) - 2); Pq = (io + 1)*ka; cq = d + 1 + 2*Pq*d; qt = _A_q_terms(D, io) okq &= qt == [tt[0], (d+1, (d+1)**2*d/(2*d-1), d+1), ((d+1)*(d+1-Pq-ka)/(d+1-2*Pq), (d+1)**2*d/(d+1-2*Pq), (d+1)*cq/(d+1-2*Pq))] okq &= all(near_lo(Pf, e0) and near_up(Qf, e1) and Fr(Rl) <= e2 <= Fr(Ru) and Fr(Ru) - Fr(Rl) <= Fr(float(np.spacing(Ru))) for (Pf, Qf, Rl, Ru), (e0, e1, e2) in zip(QC['E'][io], qt)) okq &= all(c2 > 0 and c1 >= 0 for c0, c1, c2 in qt) and qt[2][2] == A_gamma_exact(D, io) and (io + 2)*ka == Pq + ka if D <= 40: # the interval Q_{D,iota} against the number in (f) of Definition A.25, at random rational points for _ in range(6): t = Fr(rq.randint(1, 10**6), 10**6)/(D*(D + 1)); vt = Fr(rq.randint(0, 10**6), 10**6)*Fr(3, 8*(D + 3)) U = d - 1 + Fr(rq.randint(0, 2*10**6), 10**6); T = D*(D + 1)*t; U1 = U/(d + 1) E1 = 2*U1 - (d - 1)*vt; E2 = d - 1 - (d - 2)*U1 - (2*d - 1)*vt; E6 = (2*d - 1)*(1 - U1 - vt) E5 = d + 1 - U + ka*((io + 1)*(2*U1 - 1) - 1) - (d + 1 + 2*(io + 1)*ka*d)*vt adm = U >= d - Fr(1, 2) and U1 + vt < 1 and (d + 3)*vt <= Fr(1, 4) inQ = (d + 3)*vt <= Fr(1, 4) and max((d + 1)*(T + (d - 1)*vt)/2, d - Fr(1, 2)) <= U <= min(c0 - c1*t - c2*vt for c0, c1, c2 in qt) okq &= inQ == (adm and min(1, E1, E2, E5, E6) >= T) # the conditions of a chain T_D, Q_{D,iota}, theta = k vt, as conditions vt <= a_1 - a_2 t kk = rq.choice([4*D, 50*D, 10**4]); rD = min(c0 - c1*t - c2*vt for c0, c1, c2 in tt) direct = (d + 3)*vt <= Fr(1, 4) and max((d + 1)*(T + (d - 1)*vt)/2, d - Fr(1, 2)) <= rD and kk*vt <= min(c0 - c1*t - c2*vt for c0, c1, c2 in qt) solved = vt <= Fr(1, 4*(D + 3)) and all(vt <= (e0 - e1*t)/e2 for e0, e1, e2 in ex) and all(vt <= (c0 - c1*t)/(kk + c2) for c0, c1, c2 in qt) okq &= direct == solved check(okq, "the intervals Q_{D,iota} of Lemma A.28 (3 <= D <= 1600, iota = 1, 2; exact arithmetic): the three terms of the right end point are those " "of the lemma, with positive coefficients of vartheta, and gamma_{D,iota} is the coefficient of vartheta in the third; the constants that the " "program uses for the junction T_D, Q_{D,iota} (D - 1/2 <= r_D, l_D <= r_D, and (D+3) vartheta <= 1/4) and for the end condition are these " "numbers, rounded in the safe direction; and for D <= 40, at random rational points, U lies in Q_{D,iota} exactly when the number in (f) of " "Definition A.25 is admitted and at least t, and the conditions of the chain agree with their solved forms vartheta <= a_1 - a_2 t") okn = True; rn = random.Random(29) def g_exact(D, io, U, vt): # the number in (g) times D(D+1), from the definition (None if not admitted) d = Fr(D); U1 = U/(d + 1) if not (2*U >= (d + 1)*(1 + (d - 1)*vt) and U1 + vt <= 1 and (d + 3)*vt <= Fr(1, 4)): return None X = [(x0 + xU*U + xv*vt, xb) for _, x0, xU, xb, xv in _A_n_xterms(D, io)] bmax = 1 - U1 - vt; cands = {Fr(0), bmax} for a0, ab in X: if 1 - ab != 0: cands.add((a0 - 1)/(1 - ab)) for b0, bb in X: if ab != bb: cands.add((b0 - a0)/(ab - bb)) return max(min([1 + b] + [a0 + ab*b for a0, ab in X]) for b in cands if 0 <= b <= bmax) for D in range(3, 1601): d = Fr(D); NC = _A_n_floats(D); nt = _A_n_terms(D, 1) + _A_n_terms(D, 2) okn &= near_lo(NC['cap'], Fr(1, 4*(D + 3))) and NC['h0'] == (d + 1)/2 and Fr(NC['h2lo']) <= (d + 1)*(d - 1)/2 <= Fr(NC['h2up']) if D >= 4: ex = [(c0 - (d + 1)/2, c1, c2 + (d + 1)*(d - 1)/2) for c0, c1, c2 in _A_tent_terms(D - 1)] okn &= all(near_lo(Pf, e0) and near_up(Qf, e1) and Fr(Rl) <= e2 <= Fr(Ru) and Fr(Ru) - Fr(Rl) <= Fr(float(np.spacing(Ru))) for (Pf, Qf, Rl, Ru), (e0, e1, e2) in zip(NC['J'], ex)) for io in (1, 2): okn &= all(near_lo(c0f, c0) and near_up(c1f, c1) and Fr(c2l) <= c2 <= Fr(c2u) for (c0f, c1f, c2l, c2u), (c0, c1, c2) in zip(NC['E'][io], _A_n_terms(D, io))) okn &= all(c1 > 0 and c2 > 0 for c0, c1, c2 in _A_n_terms(D, io)) if D <= 40: # the interval N_{D,iota} against the number in (g), at random rational points for _ in range(6): t = Fr(rn.randint(1, 15*10**5), 10**6)/(D*(D + 1)); vt = Fr(rn.randint(0, 10**6), 10**6)*Fr(3, 8*(D + 3)) U = (d + 1)/3 + Fr(rn.randint(0, 10**6), 10**6)*(d + 1); T = D*(D + 1)*t g = g_exact(D, io, U, vt) inN = (d + 3)*vt <= Fr(1, 4) and (d + 1)*(1 + (d - 1)*vt)/2 <= U <= min(c0 - c1*t - c2*vt for c0, c1, c2 in _A_n_terms(D, io)) okn &= inN == (g is not None and g >= T) check(okn, "the intervals N_{D,iota} of Lemma A.28 (3 <= D <= 1600, iota = 1, 2; exact arithmetic): the constants that the program uses for " "the junction T_(D-1), N_{D,iota} and for the greedy union followed by N_{D,iota}, for (D+3) vartheta <= 1/4 and for the end conditions " "are the exact numbers of the lemma, rounded in the safe direction, and the fourteen terms of the right end point have positive " "coefficients of t and vartheta; and for D <= 40, at random rational points, U lies in N_{D,iota} exactly when the number in (g) of " "Definition A.25, computed from its definition as a maximum over beta, is admitted and at least t") # ---- (e) the second case of Section A.4: the tables of [VW2000] for 7 <= k <= 20, and those of [VW1995] for k = 5, 6 KV = sorted(A_VW_T); tc = {k: A_vw_tables_check(k) for k in KV} check(KV == list(range(7, 21)) and sorted(A_VW4) == KV and all(tc[k][1] for k in KV) and [len(A_vw_delta(k)) - 1 for k in KV] == [16, 20, 22, 26, 29, 32, 36, 40, 43, 47, 50, 54, 58, 62] and sum(len(A_VW4[k].split()) for k in KV) == 507 and max(tc[k][0] for k in KV) < Fr(3, 10**7) and A_VW4_PHI[8].split()[-1] == '-' and sum(A_VW4_PHI[k].split().count('-') for k in KV) == 1, "the tables of [VW2000] for 7 <= k <= 20 (lambda_s for 3 <= s <= S_k, with S_k = 16, 20, 22, ..., 62; 507 rows): the relation " "lambda_s = lambda_(s-1)(1 - phi_1) + 1 + (2s - 2) phi_1 of [VW2000, (4.10)] holds for each of the 506 rows that carry a parameter phi_1 (all " f"except lambda_20 for k = 8, which comes from the process D_s) to within {float(max(tc[k][0] for k in KV)):.1e} (the entries have 7 and 8 decimals)") check(all(tc[k][2][1] == A_VW_FOOTER[k][1] == k - 1 and 0 <= tc[k][2][0] - A_VW_FOOTER[k][0] <= 1 for k in KV) and all(Fr(4*(k-1)**2, 1)/(k - 2*A_vw_delta(k)[k-1]) <= Fr(A_VW_T[k]) < Fr(4*(k-1)**2, 1)/(k - 2*A_vw_delta(k)[k-1]) + Fr(1, 100) for k in KV), "the same tables: the largest value of (k - 2 Delta_s)/(4s^2 - 1) is attained at s = k - 1 and agrees with the number tau(k) printed below each table; " "and T_k is 4u^2/(k - 2 Delta_u) with u = k - 1, rounded up to two decimals") rvw = {k: A_rec_vw(k) for k in KV} check(all(rvw[k]['ok'] for k in KV) and all(rvw[k]['th'] >= 1.85 for k in KV) and all(set(rvw[k]['checks']) == {'V1', 'V2', 'V3', 'R1', 'R3', 'Y', 'Y419'} for k in KV), "Theorem A.36 in the second case, 7 <= k <= 20 (exact arithmetic): (V1), (V2), (V3); (R1): c_0 < 1/T_k and c_n < 1/10 (the chains give " f"theta_k(2 c_n) >= {min(rvw[k]['th'] for k in KV):.4f}); (R3); Y^VW(k) >= 4k + 1; and Y^VW(k) >= 4.19 k, as part (ii) of the theorem requires") dv95 = {k: A_vw95_check(k) for k in (5, 6)}; D95 = {k: A_vw95_delta(k) for k in (5, 6)}; r95 = {k: A_rec_vw(k, vw95=True) for k in (5, 6)} T95 = {k: Fr(4*(k-1)**2, 1)/(k - 2*D95[k][k-1]) for k in (5, 6)} check(all(dv95[k][1] and dv95[k][0] < Fr(1, 10**7) for k in (5, 6)) and len(D95[5]) - 1 == 8 and len(D95[6]) - 1 == 12 and D95[6][12] == 0 and all(T95[k] <= Fr(A_VW95_T[k]) < T95[k] + Fr(1, 100) for k in (5, 6)) and all(r95[k]['Y'] is None for k in (5, 6)) and -0.84 < r95[5]['gap'] < -0.83 and -0.28 < r95[6]['gap'] < -0.27, "Remark A.44: the tables of [VW1995] for k = 5 (s <= 8) and k = 6 (s <= 12): the relation (4.10) holds to within " f"{float(max(dv95[k][0] for k in (5, 6))):.1e}, Delta_12 = 0 for k = 6, and T_5 = 30.16, T_6 = 39.21 are formed as above; with these tables the " "recursion of Section A.7 finds no index n with (R3): the largest decrease of k Psi^VW along a step is " f"{2 + float(r95[5]['gap']):.3f} for k = 5 and {2 + float(r95[6]['gap']):.3f} for k = 6") # ---- (f) the recursion: Theorem A.36 in the first case, Propositions A.37 and A.38, Tables 8 and 9 ks = list(range(37, KNUM+1)); K = np.array(ks); c0lo, c0hi = Fr(A_C0_R[0]), Fr(A_C0_R[1]); kall = list(range(A_KREC, KNUM+1)) # the step of the recursion against theta_k computed directly from Definition A.25 (not rigorous; an independent test of (R2)) rs = random.Random(11); worst = np.inf; ncross = 0; npts = 0 for k in (6, 7, 13, 21, 37, 100, 577, 1000, 5000): Dl = A_Dlim(k); div = A_divpoints(Dl); kv = np.array([float(k)]); tau = tau_k(k) cs = [tau*float(np.exp(rs.uniform(0, log(0.09/tau)))) for _ in range(8)] cs += [0.5*x*(1 - 0.3*rs.random()/sqrt(k)) for x in div if 2*tau < x*(1 - 0.3/sqrt(k)) and x < 0.18][-7:] # just below a point of division for c in cs: cand, th = A_rec_step_lo(kv, np.array([c]), np.array([Dl])); cn = float(cand[0]) if cn > A_REC_CMAX: continue v = np.concatenate([np.linspace(c, cn, 201), [0.5*x*(1 + 1e-12) for x in div if c < 0.5*x < cn]]) lo = A_theta_direct(k, 2*v)[0] worst = min(worst, float(np.min(v/(1 - lo/k))/cn)); npts += 1; ncross += int(any(2*c < x < 2*cn for x in div)) check(worst > 1 - 1e-9 and npts >= 100 and ncross >= 40, f"(R2) for single steps: at {npts} starting points c ({ncross} of the steps cross a point of division), the least value of v/(1 - theta_k(2v)/k) " f"over 201 points v in [c, c'] and just beyond each point of division, with theta_k from Definition A.25, is at least c' (least ratio - 1: {worst-1:.1e})") rec = A_rec_table() Yf = np.array([rec[k]['Y'] for k in ks]); Gf = np.array([rec[k]['G'] for k in ks]); Lf = np.array([rec[k]['l'] for k in ks]) nn = np.array([rec[k]['n'] for k in ks]); cn = np.array([rec[k]['c'] for k in ks]) check(sorted(rec) == kall and A_KREC == 6 and all(rec[k]['G'] == floor(Fr(rec[k]['Y'])) + 1 and rec[k]['l'] == floor(Fr(rec[k]['Y'])/2) + 1 and 2*rec[k]['l'] > Fr(rec[k]['Y']) and rec[k]['c'] <= A_REC_CMAX and Fr(rec[k]['c']) < Fr(13, 120) and rec[k]['n'] >= 1 and Fr(rec[k]['Y']) > Fr(419, 100)*k and rec[k]['Th'] >= 1.5 for k in kall) and NNK_LO < (nn/K).min() and (nn/K).max() < NNK_HI and f"{cn.min():.4f}" == CNMIN_EXPECT and cn.max() < 13/120, f"Theorem A.36 in the first case for 6 <= k <= {KNUM}: sequences with (R1)-(R3) and upper bounds Y^flat(k) for k Psi(c_n) + 2n (directed rounding), " f"all larger than 4.19 k; for k >= 37 the number n of steps lies between {(nn/K).min():.4f} k and {(nn/K).max():.4f} k, and c_n between {cn.min():.4f} and {cn.max():.6f}") okc, m3, mY, xY = A_rec_certify(rec) check(okc and m3 > 0 and 0 <= mY <= xY < 1e-6, f"the same sequences, in decimal arithmetic with 40 digits and a correctly rounded logarithm: (R3) holds (least value of " f"Psi(c_(n-1)) - Psi(c_n) - 2/k: {m3:.1e}), and Y^flat(k) >= k Psi(c_n) + 2n (the difference lies between {mY:.1e} and {xY:.1e})") def thr(holds, fails, lo=A_KREC): """the least k0 >= lo such that holds(k) for k0 <= k <= KNUM, and whether fails(k0 - 1) (both decided exactly)""" bad = [k for k in range(lo, KNUM+1) if not holds(k)]; k0 = (max(bad) + 1) if bad else lo return k0, (k0 == lo or fails(k0 - 1)) Ga = {k: Fr(rec[k]['G']) for k in kall}; Ya = {k: Fr(rec[k]['Y']) for k in kall}; La = {k: Fr(rec[k]['l']) for k in kall} kG1, fG1 = thr(lambda k: A_lt_sqrt(Ga[k] - c0lo*k, Fr(-1), k), lambda k: not A_lt_sqrt(Ga[k] - c0hi*k, Fr(-1), k)) kY1, fY1 = thr(lambda k: A_lt_sqrt(Ya[k] - c0lo*k, Fr(-1), k), lambda k: not A_lt_sqrt(Ya[k] - c0hi*k, Fr(-1), k)) kL1, fL1 = thr(lambda k: A_lt_sqrt(La[k] - c0lo*k/2, Fr(-1, 2), k), lambda k: not A_lt_sqrt(La[k] - c0hi*k/2, Fr(-1, 2), k)) rG = np.array([(rec[k]['G'] - A_C0*k)/sqrt(k) for k in kall]); rY = np.array([(rec[k]['Y'] - A_C0*k)/sqrt(k) for k in kall]) rL = np.array([(rec[k]['l'] - A_C0*k/2)/sqrt(k) for k in kall]) kGm = kall[int(rG.argmax())]; kYm = kall[int(rY.argmax())] check(all(A_lt_sqrt(Ga[k] - c0lo*k, Fr(-46, 100), k) and A_lt_sqrt(Ya[k] - c0lo*k, Fr(-59, 100), k) for k in kall) and kGm == 57 and -0.4661 < rG.max() < -0.4660 and Ga[57] == 351 and kYm == 57 and -0.5943 < rY.max() < -0.5942 and (kG1, kY1) == (639, 471) and fG1 and fY1, f"Proposition A.37 (ii): for 6 <= k <= {KNUM} one has G^flat(k) < C_0^star k - 0.46 sqrt k (largest value of (G^flat(k) - C_0^star k)/sqrt k: " f"{rG.max():.6f}, at k = {kGm}, where G^flat = {rec[kGm]['G']}) and Y^flat(k) < C_0^star k - 0.59 sqrt k (largest value {rY.max():.7f}, at k = {kYm}); " f"G^flat(k) < C_0^star k - sqrt k for k >= {kG1} and Y^flat(k) < C_0^star k - sqrt k for k >= {kY1}; the computed inequalities fail for k = {kG1-1}, {kY1-1}") kLm = kall[int(rL.argmax())] check(all(A_lt_sqrt(La[k] - c0lo*k/2, Fr(-16, 100), k) for k in kall) and kLm == 57 and -0.1669 < rL.max() < -0.1668 and La[57] == 176 and kL1 == 873 and fL1, f"Proposition A.37 (iii): l^flat(k) < C_0^star k/2 - 0.16 sqrt k for 6 <= k <= {KNUM} (largest value of (l^flat(k) - C_0^star k/2)/sqrt k: " f"{rL.max():.5f}, at k = {kLm}, where l^flat = {rec[kLm]['l']}); l^flat(k) < C_0^star k/2 - sqrt(k)/2 for k >= {kL1}, but not for k = {kL1-1}") gk = {k: Fr(rec[k]['G'], k) for k in kall}; kgm = max(gk, key=gk.get); gmax = gk[kgm] check(gmax == Fr(30921, 4985) and kgm == 4985 and gmax < c0lo and gmax < Fr(62197, 10000) and all(Fr(A_previous(k), k) <= 6 for k in range(1, 6)), f"Theorem A.2: G(k) < C_0^star k for k <= {KNUM}: by (1.1) for k <= 5 (where the ratio is at most 6), and by Proposition A.37(i) for " f"6 <= k <= {KNUM}, where the largest value of G^flat(k)/k is {gmax} = {float(gmax):.5f}, at k = {kgm}") check([rec[k]['l'] for k in (64, 128, 256, 512, 1024, 2048, 4096)] == [197, 394, 789, 1581, 3168, 6344, 12700] and [rec[k]['l'] for k in (37, 50, 100, 1000)] == [112, 154, 308, 3093] and rec[32]['l'] == 96 and [rec[k]['G'] for k in (21, 37, 50, 100, 1000, 2000, 5000)] == [122, 224, 307, 615, 6186, 12389, 31014] and (rec[6]['G'], rec[6]['l'], f"{rec[6]['Y']:.4f}") == (32, 16, "31.2470"), "l^flat = 197, 394, 789, 1581, 3168, 6344, 12700 for k = 64, ..., 4096, 96 for k = 32, and 112, 154, 308, 3093 for k = 37, 50, 100, 1000; " "G^flat = 122, 224, 307, 615, 6186, 12389, 31014 for k = 21, 37, 50, 100, 1000, 2000, 5000; Y^flat(6) = 31.2470..., G^flat(6) = 32 and " "l^flat(6) = 16") old = np.array([floor(k*bound(k, Theta_sharp(k))) for k in ks]); pc = 100*(1 - Gf/old) check((old-Gf).min() == 46 and ks[int((old-Gf).argmin())] == 47 and (old-Gf)[-1] == 695 and 2.19 < pc.min() < 2.20 and 17.94 < pc.max() < 17.95 and ks[int(pc.argmax())] == 37 and [int(old[k-37]) for k in (37, 50, 100, 1000)] == [273, 353, 680, 6389], f"G^flat(k) is smaller than G^sharp(k) by at least {(old-Gf).min()} (k = {ks[int((old-Gf).argmin())]}) and by {(old-Gf)[-1]} for k = {KNUM}; " f"by {pc.min():.2f} per cent (k = {ks[int(pc.argmin())]}) to {pc.max():.2f} per cent (k = {ks[int(pc.argmax())]}); G^sharp = 273, 353, 680, 6389 for k = 37, 50, 100, 1000") fr = Yf - np.floor(Yf); hi = [k for k, f in zip(ks, fr) if f > 0.999]; lo = [k for k, f in zip(ks, fr) if f < 0.001] msm = min(rec[k]['G'] - rec[k]['Y'] for k in range(6, 37)) check(hi == [917, 2591, 4199] and 0.99989 < fr.max() < 0.99990 and ks[int(fr.argmax())] == 917 and lo == [2242, 2731, 2895, 3227, 3831] and ks[int(fr.argmin())] == 3227 and 0.00024 < fr.min() < 0.00025 and msm > 0.048, f"for 37 <= k <= {KNUM} the fractional part of Y^flat(k) exceeds 0.999 for k = {', '.join(map(str, hi))} (largest: {fr.max():.6f}, at k = {ks[int(fr.argmax())]}), and it is " f"smaller than 0.001 for {len(lo)} values of k (smallest: {fr.min():.5f}, at k = {ks[int(fr.argmin())]}); for 6 <= k <= 36 the numbers Y^flat(k) lie below the next " f"integer by at least {msm:.3f}") # Table 8: 21 <= k <= 40 and selected k > 40 TB = {21: (17, '121.6761', 122, 61, 153), 22: (18, '128.0010', 129, 65, 161), 23: (19, '134.3320', 135, 68, 169), 24: (21, '140.6089', 141, 71, 178), 25: (22, '146.9290', 147, 74, 186), 26: (23, '153.2301', 154, 77, 194), 27: (24, '159.5223', 160, 80, 203), 28: (25, '165.7901', 166, 83, 211), 29: (26, '172.1266', 173, 87, 220), 30: (27, '178.4739', 179, 90, 229), 31: (28, '184.8712', 185, 93, 237), 32: (29, '191.2973', 192, 96, 246), 33: (31, '197.6174', 198, 99, 254), 34: (32, '204.0533', 205, 103, 263), 35: (33, '210.5121', 211, 106, 272), 36: (34, '216.9282', 217, 109, 281), 37: (35, '223.3367', 224, 112, 273), 38: (36, '229.7112', 230, 115, 279), 39: (37, '236.1359', 237, 119, 285), 40: (39, '242.4291', 243, 122, 291), 41: (40, '248.8133', 249, 125, 297), 50: (50, '306.0160', 307, 154, 353), 57: (57, '350.0322', 351, 176, 405), 64: (65, '393.1624', 394, 197, 456), 100: (101, '614.7822', 615, 308, 680), 128: (130, '787.0870', 788, 394, 854), 200: (204, '1231.2630', 1232, 616, 1306), 256: (262, '1577.3910', 1578, 789, 1662), 470: (485, '2901.5824', 2902, 1451, 3024), 471: (486, '2907.6987', 2908, 1454, 3030), 500: (516, '3087.3875', 3088, 1544, 3215), 638: (659, '3942.0152', 3943, 1972, 4091), 639: (660, '3948.1574', 3949, 1975, 4098), 872: (902, '5392.0269', 5393, 2697, 5577), 873: (903, '5398.2360', 5399, 2700, 5583), 1000: (1036, '6185.5549', 6186, 3093, 6389), 2000: (2078, '12388.2484', 12389, 6195, 12725), 3000: (3122, '18594.7947', 18595, 9298, 19056), 4985: (5197, '30920.0283', 30921, 15461, 31614), 5000: (5213, '31013.1898', 31014, 15507, 31709)} okB = list(TB) == list(range(21, 41)) + list(A_REC_SELECT) print(" Table 8: k n Y^flat G^flat l^flat before") for k, want in TB.items(): r = rec[k]; got = (r['n'], f"{r['Y']:.4f}", r['G'], r['l'], A_before(k)); okB &= got == want print(f" {k:8d} {got[0]:5d} {got[1]:>10s} {got[2]:6d} {got[3]:6d} {got[4]:6d}") sm = list(range(21, 37)); dbw = [A_previous(k) - rec[k]['G'] for k in sm]; csm = [rec[k]['c'] for k in range(6, 37)] check(okB and min(dbw) == 31 and max(dbw) == 64 and max(Fr(rec[k]['G'], k) for k in sm) == Fr(205, 34) == Fr(rec[34]['G'], 34) and [A_previous(k) for k in (21, 30, 36)] == [153, 229, 281] and [rec[k]['G'] for k in (30, 36)] == [179, 217], f"the entries of Table 8; for 21 <= k <= 36 the numbers G^flat(k) are smaller than the bounds of (1.1) by {min(dbw)} to {max(dbw)}, " f"G^flat(k)/k <= 205/34 (k = 34), and for 6 <= k <= 36 the end points c_n lie between {min(csm):.4f} and {max(csm):.4f}") flatsmall = [rec[k]['G'] for k in KV]; dfl = [rec[k]['G'] - rvw[k]['G'] for k in KV]; dll = [rec[k]['l'] - rvw[k]['l'] for k in KV] check(flatsmall == [37, 42, 48, 54, 60, 66, 72, 78, 85, 91, 97, 103, 110, 116] and min(dfl) == 2 and max(dfl) == 4 and set(dll) == {1, 2}, "without the tables of [VW2000] the recursion gives G^flat = " + ", ".join(map(str, flatsmall)) + " for 7 <= k <= 20; these exceed G^VW(k) " "by 2 to 4, and l^flat(k) exceeds l^VW(k) by 1 or 2") # Table 9: 7 <= k <= 20 with the tables of [VW2000] TA = {7: ('48.47', 2, '0.0695', '32.1041', 33, 31, 17, 22), 8: ('58.01', 3, '0.0796', '38.1574', 39, 39, 20, None), 9: ('67.51', 4, '0.0844', '44.3605', 45, 47, 23, 29), 10: ('76.95', 5, '0.0886', '50.5027', 51, 55, 26, 33), 11: ('86.40', 6, '0.0906', '56.6732', 57, 63, 29, 37), 12: ('95.66', 7, '0.0922', '62.9089', 63, 72, 32, 41), 13: ('104.95', 8, '0.0930', '69.1032', 70, 81, 35, 44), 14: ('114.19', 9, '0.0941', '75.2936', 76, 89, 38, 45), 15: ('123.40', 10, '0.0944', '81.5382', 82, 97, 41, 49), 16: ('132.60', 11, '0.0946', '87.8039', 88, 105, 44, 53), 17: ('141.78', 12, '0.0949', '94.0387', 95, 113, 48, 57), 18: ('150.95', 13, '0.0950', '100.2900', 101, 121, 51, 61), 19: ('160.07', 14, '0.0949', '106.6127', 107, 129, 54, 65), 20: ('169.18', 15, '0.0948', '112.8939', 113, 137, 57, 69)} okA = True print(" Table 9: k T_k n c_n Y^VW G^VW before l^VW before") for k in KV: r = rvw[k]; got = (A_VW_T[k], r['n'], f"{r['c']:.4f}", f"{float(r['Y']):.4f}", r['G'], A_VW_PREVIOUS[k], r['l'], A_gplus_before(k)) okA &= got == TA[k] print(f" {k:8d} {got[0]:>6s} {got[1]:2d} {got[2]} {got[3]:>8s} {got[4]:5d} {got[5]:5d} {got[6]:5d} {'-' if got[7] is None else got[7]:>5}") mvw = min(rvw[k]['G'] - rvw[k]['Y'] for k in KV) check(okA and [rvw[k]['G'] for k in KV] == [33, 39, 45, 51, 57, 63, 70, 76, 82, 88, 95, 101, 107, 113] and [rvw[k]['G'] < A_VW_PREVIOUS[k] for k in KV] == [False, False] + [True]*12 and mvw > Fr(9, 100) and max(Fr(rvw[k]['G'], k) for k in KV) == Fr(113, 20), "the entries of Table 9: G(k) <= 45, 51, 57, 63, 70, 76, 82, 88, 95, 101, 107, 113 for k = 9, ..., 20 (previously 47, 55, 63, 72, 81, 89, 97, " f"105, 113, 121, 129, 137), and G^VW = 33, 39 for k = 7, 8 (previously 31, 39); the numbers Y^VW(k) lie below the next integer by at least {float(mvw):.3f}") # Theorem A.3(ii), the comparison with [BW2023, Theorems 9.1 and 9.2] and with the tables of [VW2000] that follows Theorem A.3, and [Dav2026] lv = {k: rvw[k]['l'] for k in KV}; odd = [k for k in KV if k not in (8, 16)]; mid = [k for k in range(21, 37) if k != 32] gs = [A_gplus_before(k) - lv[k] for k in odd]; gm = [A_gplus_before(k) - rec[k]['l'] for k in mid]; bm = [A_gplus_before(k) for k in mid] def classical(k): """min over s of s + floor(Delta_s/(2 tau(k))) + 1, with the tables of [VW2000] and tau(k) as printed below them (exact)""" Dl = A_vw_delta(k); tau = Fr(A_VW_FOOTER[k][0], 10**6) return min(s + floor(Dl[s]/(2*tau)) + 1 for s in range(1, len(Dl))) cl = {k: classical(k) for k in KV} check([lv[k] for k in KV] == [17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 48, 51, 54, 57] and all(2*lv[k] > rvw[k]['Y'] for k in KV) and [A_gplus_before(k) for k in odd] == [22, 29, 33, 37, 41, 44, 45, 49, 57, 61, 65, 69] and A_gplus_before(13) == A_previous_plus(13) and min(gs) == 5 and max(gs) == 12 and A_gplus_before(6) == 18 and rec[6]['l'] == 16 and min(gm) == 16 and max(gm) == 32 and min(bm) == 77 and max(bm) == 141 and min(rec[k]['l'] for k in mid) == 61 and max(rec[k]['l'] for k in mid) == 109 and rec[32]['l'] == 96 and A_gplus_before(32) == 123 and lv[16] == 44 and A_gplus_before(16) == 53 and lv[8] == 20, "Theorem A.3(ii): l^VW(k) = 17, 20, 23, ..., 57 for 7 <= k <= 20; the bounds for G^+(k) of [BW2023, Theorem 9.1] are 22, 29, 33, 37, 41, 44 for " f"k = 7, 9, ..., 13, 45, 49, 57, 61, 65, 69 (Table 3 there) for k = 14, 15, 17, ..., 20, and between {min(bm)} and {max(bm)} for 21 <= k <= 36, " f"k != 32; the new bounds are smaller by {min(gs)} to {max(gs)} for 7 <= k <= 20 and by {min(gm)} to {max(gm)} for 21 <= k <= 36 (l^flat(k) between " "61 and 109 there); for k = 8, 16 and 32 the admissible numbers are 20, 44 and 96 (53 and 123 in [BW2023, Theorem 9.2] for k = 16, 32)") check([cl[k] for k in KV] == [17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69] and all(cl[k] == A_BW_GPLUS[k] for k in range(14, 21) if k in A_BW_GPLUS) and cl[16] == A_gplus_before(16) and [cl[k] - lv[k] for k in KV] == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 11, 12], "the numbers min_s (s + floor(Delta_s/(2 tau(k))) + 1), formed with the tables of [VW2000] and the numbers tau(k) printed below them, are " + ", ".join(str(cl[k]) for k in KV) + " for 7 <= k <= 20; for 14 <= k <= 20 they agree with [BW2023, Table 3] (and 53 for k = 16 with " "[BW2023, Theorem 9.2]); they exceed l^VW(k) by " + ", ".join(str(cl[k] - lv[k]) for k in KV)) DAV_G = {8: 38, 9: 44, 10: 51, 11: 57, 12: 64, 13: 70, 14: 77, 15: 83, 16: 90, 17: 97, 18: 104, 19: 110, 20: 117} # [Dav2026, Table 1] DAV_T = {8: 20, 9: 23, 10: 26, 11: 29, 12: 33, 13: 36, 14: 39, 15: 42, 16: 46, 17: 49, 18: 52, 19: 56, 20: 59} dG = [DAV_G[k] - rvw[k]['G'] for k in range(8, 21)]; dT = [DAV_T[k] - lv[k] for k in range(8, 21)] check(dG == [-1, -1, 0, 0, 1, 0, 1, 1, 2, 2, 3, 3, 4] and dT == [0, 0, 0, 0, 1, 1, 1, 1, 2, 1, 1, 2, 2], "the comparison with [Dav2026, Table 1] for 8 <= k <= 20: his bounds for G(k) minus G^VW(k) are " + ", ".join(map(str, dG)) + ", and his numbers of summands t minus l^VW(k) are " + ", ".join(map(str, dT))) # the plain double precision version with theta_k from Definition A.25 (no chains), and with the numbers rho_j - vt/2 in (b) dd = []; dl = [] for k in (6, 7, 13, 21, 37): p = A_rec_plain(k); dd.append(abs(rec[k]['Y'] - p[0])); _require(p[1] == rec[k]['n']) for k in KV: p = A_rec_plain(k, vw=True); dd.append(abs(float(rvw[k]['Y']) - p[0])); _require(p[1] == rvw[k]['n']) for k in (100, 577, 1000, 5000): p = A_rec_plain(k); dl.append((k, rec[k]['Y'] - p[0])); _require(p[1] == rec[k]['n']) check(max(dd) < 2e-8 and all(-2e-8 < x < 2.5e-3 for k, x in dl), f"the recursion in plain double precision, with theta_k computed from Definition A.25 by bisection instead of chains, gives the same n, and " f"the same value of k Psi(c_n) + 2n to within {max(dd):.1e} for k = 6, 7, 13, 21, 37 and for 7 <= k <= 20 with the tables; for k = 100, 577, " "1000, 5000 the value with chains is larger by " + ", ".join(f"{x:.1e}" for k, x in dl) + " (for some t between 0.205 and 0.215 the " "chains of Lemma A.28 fall slightly short of theta_k)") ob = {k: A_rec_plain(k, oldb=True) for k in (37, 100, 1000)} check([floor(ob[k][0]) + 1 for k in ob] == OB_EXPECT and [rec[k]['G'] for k in ob] == REC_G_EXPECT[:3], "Remark A.41: with the numbers rho_j(U) - vartheta/2 of Lemma 4.3(ii) in place of s_j(U, vartheta) in Definition A.25 the plain recursion gives " + ", ".join(f"{ob[k][0]:.4f}" for k in ob) + " for k = 37, 100, 1000, hence the bounds " + ", ".join(str(floor(ob[k][0]) + 1) for k in ob) + ", against " + ", ".join(str(x) for x in REC_G_EXPECT[:3])) globals()['A_PAIRS_ON'] = False # Definition A.25 without (d) try: npr = {k: A_rec_plain(k) for k in (37, 100, 1000, 5000)} finally: globals()['A_PAIRS_ON'] = True check([floor(npr[k][0]) + 1 for k in npr] == NPR_EXPECT and [rec[k]['G'] for k in npr] == REC_G_EXPECT, "Remark A.41 and the introduction to Appendix A: without the numbers (d) of Definition A.25 the plain recursion gives " + ", ".join(f"{npr[k][0]:.4f}" for k in npr) + " for k = 37, 100, 1000, 5000, hence the bounds " + ", ".join(str(floor(npr[k][0]) + 1) for k in npr) + ", against " + ", ".join(str(x) for x in REC_G_EXPECT) + " with them") globals()['A_MCANCEL_ON'] = False # Definition A.25 without (g): the saving function of the previous version try: nog = {k: A_rec_plain(k) for k in (37, 100, 1000, 5000)} finally: globals()['A_MCANCEL_ON'] = True check([floor(nog[k][0]) + 1 for k in nog] == [224, 615, 6187, 31025], "Remark A.41 and the introduction to Appendix A: without the numbers (g) of Definition A.25 (prime multipliers with cancellation) the " "plain recursion gives " + ", ".join(f"{nog[k][0]:.4f}" for k in nog) + " for k = 37, 100, 1000, 5000, hence the bounds 224, 615, 6187, " "31025 of the previous version, against " + ", ".join(str(rec[k]['G']) for k in nog) + " now") globals()['A_CANCEL_ON'] = False; globals()['A_MCANCEL_ON'] = False # without (f) and (g): the version before that try: noq = {k: A_rec_plain(k) for k in (37, 100, 1000, 5000)} finally: globals()['A_CANCEL_ON'] = True; globals()['A_MCANCEL_ON'] = True check([floor(noq[k][0]) + 1 for k in noq] == [224, 615, 6196, 31077], "Remark A.41 and the introduction to Appendix A: without the numbers (f) and (g) of Definition A.25 (cancellation in the count of " "pairs) the plain recursion gives " + ", ".join(f"{noq[k][0]:.4f}" for k in noq) + " for k = 37, 100, 1000, 5000, hence the bounds " "224, 615, 6196, 31077 of the version before the previous one") globals()['A_MULT_ON'] = False; globals()['A_CANCEL_ON'] = False; globals()['A_MCANCEL_ON'] = False # without (e), (f), (g), c_n < 1/10 try: nom = {k: A_rec_plain(k, cap=0.1) for k in (37, 100, 1000, 5000)} finally: globals()['A_MULT_ON'] = True; globals()['A_CANCEL_ON'] = True; globals()['A_MCANCEL_ON'] = True check([floor(nom[k][0]) + 1 for k in nom] == [224, 616, 6219, 31199], "the introduction to Appendix A: without the numbers (e), (f) and (g) of Definition A.25 (prime multipliers, and cancellation in the " "count of pairs), and with the recursion stopped below 1/10, the plain recursion gives " + ", ".join(f"{nom[k][0]:.4f}" for k in nom) + " for k = 37, 100, 1000, 5000, hence the bounds 224, 616, 6219, 31199") pc = [A_rec_potential(k) for k in (6, 21, 37, 100)] check(all(m <= 0 and sl < -0.1 and st > -1e-12 and abs(dv) < 0.013 for m, sl, st, dv in pc), "the potential in the proof of Theorem A.36 for k = 6, 21, 37, 100, on a grid of 40000 points (plain double precision, delta_0 = eps_2 = 0): " "it is nonincreasing, g <= G - 2.1 on (0, 1/5], G(z) - G(z/(1 - theta_k(2z)/k)) >= 2/k below z_0 (least value of the difference minus 2/k: " f"{min(p[2] for p in pc):.1e}), and k G(c_0) agrees with Y^flat(k) to within {max(abs(p[3]) for p in pc):.4f}") # ---- (g) Section A.8: the numbers B^nat(k), Theta^nat(k) for 37 <= k <= KNUM (directed rounding), and Proposition A.39 (i) tab = A_table() B = np.array([tab[k]['B'] for k in ks]); Th = np.array([tab[k]['Th'] for k in ks]); kB = np.array([tab[k]['kB'] for k in ks]) Ev = np.array([tab[k]['E'] for k in ks]); refd = [k for k in ks if tab[k]['ref'] == 8] check(len(refd) == 53 and all(tab[k]['Th'] >= 2.25 and Fr(tab[k]['Y']) >= Fr(tab[k]['kB']) - 1 and 2*tab[k]['s0'] > Fr(tab[k]['x']) for k in ks) and 6.4791 < Th.min() < 6.4792 and int(Th.argmin()) == 0, f"(A.68) for 37 <= k <= {KNUM}: Theta^nat(k) >= 9/4 (least value {floor(1e4*Th.min())/1e4:.4f}..., at k = 37), and upper bounds Y^nat(k) = k B^nat(k) - 1; the subdivision is " f"refined eightfold for the {len(refd)} values of k at which k B^nat(k) has fractional part < {A_REFINE_BELOW}") check(all(tab[k]['s0'] == floor(Fr(tab[k]['x'])/2) + 1 and 2*tab[k]['s0'] > 5*k for k in ks), f"Section A.8: s_0^nat(k) = floor(x/2) + 1 > 5k/2 for 37 <= k <= {KNUM}, where x is the upper bound for Y^nat(k) - 2 chi_0 k/Theta'; " f"least value of 2 s_0^nat(k) - 5k: {min(2*tab[k]['s0'] - 5*k for k in ks)}") tenk = Fr(A_FRAC_C, 10000) rE = (Ev - A_FRAC_C/10**4*K)/np.sqrt(K) k2s, f2s = thr(lambda k: A_lt_sqrt(Fr(tab[k]['E']) - tenk*k, Fr(-197, 100), k), lambda k: not A_lt_sqrt(Fr(tab[k]['E']) - tenk*k, Fr(-197, 100), k), lo=37) m108 = min(Fr(108, 10)*k - Fr(tab[k]['E']) for k in ks) check(all(A_lt_sqrt(Fr(tab[k]['E']) - tenk*k, Fr(-151, 100), k) for k in ks) and ks[int(rE.argmax())] == 85 and -1.5106 < rE.max() < -1.5105 and k2s == 699 and f2s and m108 > 14, f"Proposition A.39 (i): E^nat(k) < {A_FRAC_C/10**4} k - 1.51 sqrt k (largest value of (E^nat(k) - {A_FRAC_C/10**4} k)/sqrt k: {rE.max():.5f}, at k = {ks[int(rE.argmax())]}); " f"E^nat(k) < {A_FRAC_C/10**4} k - 1.97 sqrt k for {k2s} <= k <= {KNUM}, and the computed value of E^nat({k2s-1}) exceeds {A_FRAC_C/10**4} k - 1.97 sqrt k there; " f"10.8 k - E^nat(k) > 14 for all k (least value {float(m108):.2f})") mlog = min(Fr(k)*(Fr(A_log_lo(k)) + Fr(802113, 100000)) - Fr(tab[k]['E']) for k in ks) check(mlog > Fr(449, 10) and 10.7032 < (Ev/K).max() < 10.7033 and ks[int((Ev/K).argmax())] == 4982, f"Proposition A.39 (i): k(log k + 8.02113) - E^nat(k) > 44.9 for all k (least value {float(mlog):.2f}); E^nat(k) <= {(Ev/K).max():.5f} k, " f"the maximum being at k = {ks[int((Ev/K).argmax())]}") # the second implementation in 40-digit decimal arithmetic (A_exact) for k in (37, 577, 1201): kBe, The = A_exact(k, grid=A_grid_rig(k)); kr = k*A_bound_rig(k)[0] check(abs(float(kBe) - kr) < 1e-9 and float(kBe) <= kr and abs(float(The) - tab[k]['Th']) < 1e-9, f"k = {k}: the second implementation gives k B^nat = {str(kBe)[:len(str(floor(kBe)))+13]} on the same subdivision (directed rounding: {kr:.9f})") rk = [k for k in refd if 600 <= k <= 1300] # two of the values of k for which the subdivision is refined for k in (rk[0], rk[-1]): kBe, The = A_exact(k, grid=A_grid_rig(k, refine=8)); kr = tab[k]['kB'] check(abs(float(kBe) - kr) < 5e-9 and float(kBe) <= kr and tab[k]['ref'] == 8, f"k = {k}, refined subdivision: the second implementation gives k B^nat = {str(kBe)[:len(str(floor(kBe)))+13]} (directed rounding: {kr:.9f})") # Table 10 big = {k: A_values_rig(k, *A_bound_rig(k)) for k in (10**4, 10**5, 10**6)} def row(k): r = tab[k] if k in tab else big[k]; return r['Th'], r['B'], r['G'], 2*r['s0'], r['b'], r['E'] T6 = {37: ('6.479', '0.0624', 208, '385.44', '419.02'), 46: ('6.777', '0.0606', 262, '482.22', '513.64'), 50: ('6.875', '0.0600', 286, '525.24', '555.70'), 100: ('10.560', '0.0397', 588, '1057.33', '1103.40'), 200: ('15.614', '0.0273', 1194, '2121.41', '2180.79'), 500: ('26.006', '0.0166', 3028, '5322.43', '5435.31'), 1000: ('37.615', '0.0116', 6102, '10668.12', '10850.81'), 2000: ('54.460', '0.0080', 12272, '21372.35', '21681.83'), 5000: ('87.573', '0.0050', 30826, '53508.94', '54167.39'), 10**4: ('125.397', '0.0035', 61810, '107108.00', '108306.22'), 10**5: ('401.897', '0.0011', 620710, '1072601.69', '1082770.24'), 10**6: ('1276.717', '0.0003', 6215630, '10731146.02', '10827267.17')} ok6 = True print(" Table 10: k Theta^nat b^nat 2 s_0^nat E^nat Table 4") for k, want in T6.items(): Thv, Bv, Gv, s2, b, E1 = row(k); got = (f"{Thv:.3f}", f"{b:.4f}", s2, f"{E1:.2f}", f"{E_sharp(k):.2f}") ok6 &= got == want print(f" {k:8d} {got[0]:>8s} {got[1]} {got[2]:8d} {got[3]:>12s} {got[4]:>12s}") check(ok6 and floor(tab[100]['E']) + 1 == 1058 and floor(tab[1000]['E']) + 1 == 10669 and all(2*big[k]['s0'] > 5*k for k in big), "the entries of Table 10 (for k = 1e4, 1e5, 1e6 also 2 s_0^nat(k) > 5k); the exponents 1/1058 and 1/10669 for k = 100 and k = 1000 (after Theorem A.5)") # ---- (h) large k: Lemma A.32 and Proposition A.33, and Proposition A.39 (ii) L1 = log(TAU_INV/2) def claimed(k, t): """the lower bound for theta_k(t) of Lemma A.32 (the largest of the lines that apply at t)""" n = A_D0(k); m = A_DM(k); dq = A_DQ(k) if t > 17/190: # the first line: theta^star, given by the words of Table 6 for t_lo, t_hi, Aw, Bw, w in A_TS_PIECES: if len(w) > 2 and float(t_lo) <= t <= float(t_hi): return float(Aw) - float(Bw)*t D = 3 while (D+1)*(D+2)*t <= 1: D += 1 if D >= n: return n/(1+n/k) best = 0.0 if D < dq: # the second line: theta^star(t)/(1 + gamma^star(t)/k), p_(D_Q) < t <= 17/190 pcs = [(lo, hi, A, B, g) for lo, hi, A, B, org, g in A_TOP3_PIECES] if D == 3 else \ [(lo, hi, A, B, A_gamma_piece(org)) for lo, hi, A, B, org in A_band_pieces(D)] for lo, hi, A, B, g in pcs: if float(lo) < t <= float(hi): best = max(best, (float(A) - float(B)*t)/(1 + float(g)/k)) if D <= dq and t <= 1/(D*(D+1)): # the third line, for iota = 1 and iota = 2 (t_D^(iota) < t <= p_D) for io in (1, 2): if t > float(A_tQ_exact(D, io)): ph = (3*(D+1)/(3*D+1))*(D + 0.5 - D*(D+1)*t) if io == 1 else (7*(D+1)/(7*D+4))*(D + 5/7 - D*(D+1)*t) best = max(best, ph/(1 + float(A_gamma_exact(D, io))/k)) qD = 3/52 if D == 3 else (1/(D*D + 2*D + 2) if D < m else 1/((D+1)*(D+2))) if D < m and t <= qD: best = max(best, (D+1)*(2 - (D+1)*(D+2)*t)/(1 + (D+1)/k)) # the fifth line if D >= 4 and t > qD: best = max(best, (D+1)*(1-D*t)/(1+D/k)) # the fourth line return best def chains_at(k, t): Dl = A_Dlim(k); div = A_divpoints(Dl); b = div[int(np.searchsorted(div, t, side='left'))] J, D = A_family(np.array([b]), np.array([float(k)]), np.array([Dl])) return float(A_theta_hat_lo(np.array([float(k)]), np.array([t]), J, D)[0]) rnd = random.Random(11); okc = True; nt = 0 for _ in range(2400): k = int(5000*E**rnd.uniform(0, log(2e5))); n = A_D0(k); m = A_DM(k); dq = A_DQ(k) Dq = rnd.randint(4, max(4, m - 1)); eps = rnd.choice([1e-9, 1e-7, 1e-5]); Dc = rnd.randint(3, dq); tq1, tq2 = float(A_tQ_exact(Dc, 1)), float(A_tQ_exact(Dc, 2)) Db = rnd.randint(4, min(dq - 1, 200)) t = rnd.choice([E**rnd.uniform(log(0.3/(n*(n+1))), log(0.214)), (1 - 1e-9)/(rnd.randint(4, n)*(rnd.randint(4, n)+1)), A_check_t(k), A_check_t3(k)*(1 + eps), A_check_t3(k)*(1 - eps), 17/190*(1 + eps), 17/190*(1 - eps), 37/638*(1 + eps), 37/638*(1 - eps), (1 + 1e-9)/8, (1 - 1e-9)/12, (1 + 1e-9)/12, (1 - 1e-9)/16, (1 + 1e-9)/16, (1 + 1e-9)/20, (1 - eps)/(Dq*Dq + 2*Dq + 2), (1 + eps)/(Dq*Dq + 2*Dq + 2), (1 + 1e-9)/((Dq+1)*(Dq+2)), 41/191, tq1*(1 + eps), tq1*(1 - eps), tq2*(1 + eps), tq2*(1 - eps), (1 - eps)/(Dc*(Dc+1)), 3/52*(1 + eps), 3/52*(1 - eps), 9/560*(1 + eps), 9/560*(1 - eps), E**rnd.uniform(log(tq1), log(1/(Dc*(Dc+1)))), 3/55*(1 + eps), 3/55*(1 - eps), 3/34*(1 + eps), 3/34*(1 - eps), float(rnd.choice(A_band_pieces(Db))[rnd.randint(0, 1)])*(1 + rnd.choice([-1, 1])*eps)] + [x for x in A_WORD_BREAKS if x not in (1/12, 1/20)]) # points of division are avoided: theta_k jumps there okc &= chains_at(k, t) >= claimed(k, t)*(1-1e-12); nt += 1 okt = all(1/12 < A_check_t3(k) < 17/190 for k in (92, 5000, 10**4, 10**9)) and A_check_t3(91) >= 17/190 okt &= all(A_DM(k) >= 47 and A_DM(k) <= A_D0(k) and 2*A_DM(k)**2 + 11*A_DM(k) + 57 <= k < 2*(A_DM(k)+1)**2 + 11*(A_DM(k)+1) + 57 and 33 <= A_DQ(k) < A_DM(k) and (2*A_DQ(k) + 1)*(2*A_DQ(k) + 6) <= k < (2*A_DQ(k) + 3)*(2*A_DQ(k) + 8) and 2*A_DQ(k) <= A_D0(k) for k in list(range(5000, 6000)) + [10**4, 10**6, 10**9, 10**12]) okt &= all(2*(D+1)**2 + 11*(D+1) + 57 <= (2*D+1)*(2*D+6) for D in range(6, 10**5)) and A_DQ(5000) == 33 check(okc and okt, f"Lemma A.32 at {nt} random points (k, t) with 5000 <= k <= 1e9, among them points next to the end points of the pieces of theta^star: the chains " "give at least the stated lower bound for theta_k(t); 1/12 < check t_3 < 17/190 (for k >= 92); 33 <= D_Q < D_M <= D_star, and 2 D_Q <= D_star") # the fourth line of Lemma A.32: the identities and inequalities of its proof (exact arithmetic) okQ = True; rq = random.Random(29) for D in range(3, 3001): d = Fr(D) for io in (1, 2): ka = Fr(1, 2**(io + 2) - 2); Pq = (io + 1)*ka; cq = d + 1 + 2*Pq*d; gam = A_gamma_exact(D, io); tq = A_tQ_exact(D, io) phi_ = lambda t: (d + 1)*(d + 1 - Pq - ka - D*(D + 1)*t)/(d + 1 - 2*Pq) okQ &= gam == (d + 1)*cq/(d + 1 - 2*Pq) and D*(D + 1)*tq >= Fr(1, 2) and Pq - ka == Fr(1, 5 + io) okQ &= phi_(tq) == (d + (d + 2)*(d + 3)/(2*(3*d*d + 4*d + 2)) if io == 1 else d + (d + 2)*(d + 5)/(7*d*d + 11*d + 8)) and phi_(tq) <= d + Fr(1, 2) okQ &= phi_(Fr(1, D*(D + 1))) == (Fr(3*(D + 1), 3*D + 1)*(d - Fr(1, 2)) if io == 1 else Fr(7*(D + 1), 7*D + 4)*(d - Fr(2, 7))) okQ &= (Pq - ka)*(2*d - 1) <= (d - 2 + 2*Pq)/2 for _ in range(2): T = Fr(1, 2) + Fr(rq.randint(0, 10**6), 2*10**6); t = T/(D*(D + 1)); vt = Fr(rq.randint(0, 10**6), 10**6)/(4*(D + 3)); qt = _A_q_terms(D, io) v = [c0 - c1*t - c2*vt for c0, c1, c2 in qt] okQ &= v[1] - v[2] == (d + 1)*((d - 2 + 2*Pq)*T - (Pq - ka)*(2*d - 1))/((2*d - 1)*(d + 1 - 2*Pq)) + 2*Pq*(d + 1)**2/(d + 1 - 2*Pq)*vt okQ &= v[0] - v[2] == (d + 1)*(d + 1 - (Pq - ka)*d - 2*ka - (3 - 2*Pq)*T)/((d - 2)*(d + 1 - 2*Pq)) - ((d + 1)*(2*d - 1)/(d - 2) - gam)*vt okQ &= v[1] >= v[2] and v[0] >= v[2] rD = [c0 - c1*t - c2*vt for c0, c1, c2 in _A_tent_terms(D)] okQ &= (d + 1)*(T + (d - 1)*vt)/2 <= d - Fr(1, 2) <= min(rD) okQ &= (d + 1)*(d + 1 - (Pq - ka)*d - 2*ka - (3 - 2*Pq))/((d - 2)*(d + 1 - 2*Pq)) == (Fr(5*(D + 1), 2*(3*D + 1)) if io == 1 else Fr(6*(D + 1), 7*D + 4)) okQ &= (d + 1)*(2*d - 1)/(d - 2) - gam == ((d + 1)**2*(d + 5)/((d - 2)*(3*d + 1)) if io == 1 else 2*(d + 1)**2*(2*d + 5)/((d - 2)*(7*d + 4))) okQ &= Fr(1, 4*(D + 3)) <= min(Fr(3*(D - 2), 2*(D + 1)*(2*D - 1)), Fr(2*(D - 2), (D + 1)*(3*D - 1)), Fr(1, 2*D), Fr(5*(D - 2), 2*(D + 1)*(D + 5)), Fr(3*(D - 2), (D + 1)*(2*D + 5)), Fr(D - 2, D*D - 1), Fr(1, D + 7)) okQ &= 4*D*D + 5*D - 35 >= 0 and 5*D*D + 6*D - 47 >= 0 and 9*D*D + 4*D - 65 >= 0 and 10*D*D + 5*D - 77 >= 0 and D*D - 1 <= 4*(D + 3)*(D - 2) okQ &= 3*D*D - 3*D - 2 >= 0 and 7*D*D - 5*D - 8 >= 0 and D*D - 2*D + 2 >= 0 and D*D - D + 2 >= 0 okQ &= A_tQ_exact(D, 1) <= Fr(1, D*D + 2*D + 2) and A_tQ_exact(D, 2) <= Fr(1, D*D + 2*D + 2) okQ &= (d + 1)*(Fr(2*D - 3, 2*D - 2)) == d + Fr(1, 2) - Fr(1, D - 1) okQ &= A_gamma_exact(3, 2) == Fr(148, 25) and Fr(3, 52) < Fr(37, 638) and Fr(15, 13) < Fr(370, 319) and Fr(38, 12) + 4*Fr(8, 10**4) <= 4 check(okQ, "the proof of the fourth line of Lemma A.32 (3 <= D <= 3000, iota = 1, 2; exact arithmetic, the differences at random rational points with " "1/2 <= T <= 1 and (D+3) vartheta <= 1/4): phi_{D,iota} and gamma_{D,iota} in terms of P and c; D(D+1) t_D^(iota) >= 1/2; the value " "phi_{D,iota}(t_D^(iota)) <= D + 1/2; l_D <= D - 1/2 <= r_D; the differences between the terms of the right end point of Q_{D,iota}, which are " "nonnegative; the lower bounds for the first of them and the coefficients of vartheta; the bounds for vartheta, all at least 1/(4(D+3)), with " "their polynomial equivalents; and t_D^(iota) <= 1/(D^2+2D+2)") def jbounds(D): """the three bounds for vartheta in the junction condition l_(D+1) <= r_D at t_(D+1) = 1, t_D = D/(D+2), derived from the end points""" d = Fr(D); tD = d/(d+2); out = [] terms = [((d+1)*(d-1-tD)/(d-2), (d+1)*(2*d-1)/(d-2)), ((d+1)*(1 - tD/(2*d-2)), (d+1)*(3*d-1)/(2*d-2)), (d+1-tD, d)] # r = c0 - c2 vartheta for c0, c2 in terms: # (d+2)(1 + d vartheta)/2 <= c0 - c2 vartheta out.append((c0 - (d+2)/2)/(c2 + d*(d+2)/2)) return out okJ = True for D in range(4, 3001): d = Fr(D); jb = jbounds(D) okJ &= jb == [(d**3+4)/((d+2)*(d**3+4*d*d-2*d-2)), d*(d*d-3)/((d+2)*(d**3+4*d*d-1)), d/((d+2)*(d+4))] okJ &= (min(jb) > Fr(66, 1000)) if D <= 7 else (min(jb) >= 1/(d+8)) okJ &= (jb[0] >= 1/(d+8)) == (2*D**3-6*D**2+10*D+36 >= 0) and (jb[1] >= 1/(d+8)) == (2*D**3-11*D**2-23*D+2 >= 0) and (jb[2] >= 1/(d+8)) == (D >= 4) okJ &= all(2*D**3-6*D**2+10*D+36 >= 0 and 2*D**3-11*D**2-23*D+2 >= 0 for D in range(8, 10**5)) check(okJ, "the junction condition l_(D+1) <= r_D at the level 1/((D+1)(D+2)) (4 <= D <= 3000, exact arithmetic): the three bounds for vartheta " "are those stated in the proof of Lemma A.32; their minimum exceeds 0.066 for 4 <= D <= 7 and is at least 1/(D+8) for D >= 8, with the " "stated polynomial equivalents") okD = all(Fr(D*(D*D+4*D-1), D-3) - D == D*D + 6*D + 20 + Fr(60, D-3) and Fr(D*(D*D+3*D-1), D-2) - D == D*D + 4*D + 9 + Fr(18, D-2) and 2*D + 6 - Fr(60, (D-3)**2) > 0 and 2*D + 4 - Fr(18, (D-2)**2) > 0 for D in range(5, 3000)) \ and 16 + 24 + 20 + 60 == 120 and 16 + 16 + 9 + 9 == 50 and all(Fr(60, n-3) <= 12 and Fr(18, n-2) <= 23 + 2*n for n in range(67, 3000)) check(okD, "the proof of Lemma A.32: D(D^2+4D-1)/(D-3) - D = D^2+6D+20+60/(D-3) and D(D^2+3D-1)/(D-2) - D = D^2+4D+9+18/(D-2); these increase for D >= 5, " "they are 120 and 50 for D = 4, and they are at most D^2+6D+32 for D >= 67") # the pieces of omega_3 and omega_4 (the second and the third line of Lemma A.32, and the sixth for D = 3), exactly at the extreme values okM = True for D, Tmax, J, f in ((3, Fr(102, 95), 2, 4), (4, Fr(370, 319), 3, 5)): _, Uterms = _A_mult_terms(D); Lterms = _A_mult_terms(D)[0] for T in (Fr(1), Tmax): t = T/(D*(D+1)) for v in (Fr(0), Fr(8, 10**4)): lo = max((a0 + a1*t + a2*v)/(D+1) for a0, a1, a2 in Lterms) rho = [(b0 - b1*t - b2*v)/(D+1) for b0, b1, b2 in Uterms] okM &= (D+1)*lo < Fr(17, 10) if D == 3 else (D+1)*lo < Fr(21, 10) okM &= (D+1)*lo < J + 2 - (2**(J+2) - 2)*t if D == 4: okM &= all(r >= rho[2] for r in rho) and 2*T + 0 <= 3 else: okM &= rho[0] - rho[2] == (10 - 9*T - 29*v)/4 and rho[1] - rho[2] == (2 - T - 7*v)/4 and rho[3] - rho[2] == (2 - T - 29*v)/4 okM &= rho[4] - rho[2] == (T - 7*v)/4 and rho[5] - rho[2] == 3*(T - 1)/4 and rho[7] - rho[6] == 5*v/4 and 2*T + 7*v < 3 okM &= min(rho[0], rho[1], rho[3], rho[4], rho[5]) >= rho[2] and rho[7] >= rho[6] if D == 4: T = Tmax; v = Fr(8, 10**4) okM &= 12*T < Fr(1392, 100) and all(x > 0 for x in (14 - 12*T - 47*v, 6 - 3*T - 23*v, 3*T - 1 - 47*v, 7*T - 4 - 23*v, 19*T - 18 - 31*v)) okM &= Fr(41, 191) - Fr(17, 83) > Fr(1, 102) and (Fr(145, 243) - Fr(41, 191))/Fr(52, 243) == Fr(341, 191) okM &= A_check_t3(10**6) > 1/12 and Fr(12*(5000+18) - (12*5000+126)) > 0 # the sixth line for D >= 4: the terms rho_i of the interval of degree D' and the conditions of the proof def eps_(d): return Fr(220*d*d - 182*d + 102, d**3 - 5*d*d + 4*d - 2) rnd = random.Random(13) for d in list(range(5, 80)) + [rnd.randint(80, 10**5) for _ in range(200)]: dd = Fr(d) for _ in range(3): T = 1 + Fr(rnd.randint(0, 10**6), 10**6)*(dd - 1)/(dd*dd + 1); v = Fr(rnd.randint(0, 10**6), 10**8) _, Uterms = _A_mult_terms(d); rho = [(b0 - b1*T/(dd*(dd+1)) - b2*v)/(dd+1) for b0, b1, b2 in Uterms] okM &= rho[5] - rho[2] == dd*(T - 1)/(dd + 1) and rho[7] - rho[2] == (dd - 1)*(T - 1)/(dd + 1) and rho[3] - rho[0] == (dd - 1)*(T - 1)/(dd - 2) okM &= (dd*dd - 1)*(rho[4] - rho[2]) == (dd*dd - 2*dd - 1)*(T - 1) + dd - 1 - (dd*dd + 2*dd - 1)*v okM &= (dd*dd - 1)*(rho[1] - rho[2]) == (dd - 1)*(2 - T) - (dd*dd + 2*dd - 1)*v okM &= 2*(dd*dd - 1)*(rho[6] - rho[2]) == (2*dd*dd - 3*dd - 1)*(T - 1) + dd - 3 - (dd*dd + 4*dd - 1)*v okM &= (dd - 2)*(dd + 1)*(rho[0] - rho[2]) == 4*dd - 2 - 3*dd*T - (2*dd*dd + 4*dd - 1)*v okM &= (dd - 1)*(dd*dd - dd + 2) >= (dd - 3)*(dd*dd + 1) okM &= dd*(2*dd*dd + 4*dd - 1)/(dd - 2) - dd == 2*dd*dd + 7*dd + 15 + Fr(30, d - 2) and 2*dd*dd + 7*dd + 15 + Fr(30, d - 2) <= 2*dd*dd + 11*dd + 57 Tm = dd*(dd + 1)/(dd*dd + 1) okM &= dd*(dd*dd - dd + 2)*(2*dd*dd + 4*dd - 1)/(dd**3 - 5*dd*dd + 4*dd - 2) - dd == 2*dd*dd + 11*dd + 51 + eps_(d) okM &= (4*dd - 2 - 3*dd*Tm) == (dd**3 - 5*dd*dd + 4*dd - 2)/(dd*dd + 1) and 2 - Tm == (dd*dd - dd + 2)/(dd*dd + 1) okM &= (eps_(d) <= 6) if d >= 42 else (eps_(d) < 261) okM &= (6*d**3 - 250*d*d + 206*d - 114 > 0) == (d >= 42) or d < 42 okM &= 2*41*41 + 11*41 + 51 + 261 < 4200 # the junction: the six bounds for D' >= 14, and the cruder estimates for 5 <= D' <= 13 (k >= 5000) okM &= all(max(Fr(1, 2) + Fr(1, d), Fr(d + 5, 2*d), Fr(d + 2, 2*(d - 1)), (2 + Fr(1, d))/3, Fr(d, 2*(d - 3))) <= Fr(7, 10) for d in range(14, 3000)) okM &= all(D - Fr(3, D - 2) >= D - Fr(3, 2) and D + 1 - Fr(5, 4)*Fr(D + 1, D - 1) > D - Fr(3, 2) for D in range(4, 3000)) okM &= all(Fr(7, 10)*(D + 2) < D - Fr(3, 2) for D in range(13, 3000)) and Fr(13, 5013) < Fr(26, 10**4) for d in range(5, 14): # exact junction check at both ends of the piece, for k = 5000 (the conditions weaken as k grows) D = d - 1; k = 5000 for T in (Fr(1), Fr(d*(d+1), d*d+1)): t = T/(d*(d+1)); v = d*(2 - T)/(k + d) lo = max((a0 + a1*t + a2*v) for a0, a1, a2 in _A_mult_terms(d)[0]) tD = D*(D+1)*t; rD = min((D+1)*(D-1-tD-(2*D-1)*v)/(D-2), (D+1)*(1-(tD+(3*D-1)*v)/(2*D-2)), D+1-tD-D*v) okM &= lo <= Fr(44, 100)*(D + 2) < Fr(82, 100)*D <= rD check(okM, "the proof of Lemma A.32, exactly: the bounds for the terms of the intervals of degree 3 and 4 (the second and the third line, and the " "sixth line for D = 3) at the extreme values of T and vartheta; the seed (41/191 - 17/83 > 1/102, and the line of BABAABAAA passes " "through (41/191, 341/191)); the identities for the terms rho_i in the sixth line (rational arithmetic at random points, for D' <= 1e5), the thresholds " "2D'^2+7D'+15+30/(D'-2) and 2D'^2+11D'+51+eps(D'), eps(D') <= 6 for D' >= 42 and < 261 for D' >= 5; and the junction estimates") okL, detL = A_large_new_checks() check(okL, f"Lemma A.32, the second line: for the {detL['corner']} pieces of theta^star in (p_16, 17/190] that come from intervals " "N_{D',iota}, the junction, the end conditions with the factors gamma^star (for all k >= 5000, at the end points of the pieces " "with vt = 0 and vt = (A - Bt)/5000) and (D'+3) vt <= 1/4 (exact); for 15 <= D < D_Q, the end conditions at the four corners " f"({detL['poly_end']} rational functions of D, nonnegative for D >= 15), (D+4) vt_D <= 1/4 and (D + 7/6)(D + 7) <= (2D+3)(2D+8); " f"in Proposition A.33: rho_D^dagger <= 10/(3D) + 5/(4D^2) for D >= 15 (degree {detL['rho_deg']}, positive coefficients in D - 15), " "the closed forms of Lambda_D^dagger and rho_D^dagger against their pieces, and Lambda_D^sharp - Lambda_D^dagger <= 1/(6D^3) (D >= 15)") # Proposition A.33 kl = sorted(set([5000+i for i in range(0, 20001)] + [int(5000*1.0005**i) for i in range(0, 38300)])); kl = [k for k in kl if k <= 10**12] w1 = w2 = w3 = w4 = w5 = w6 = w7 = w8 = wE = -1e99; wEk = 0; okA25 = True; wmax = None for k in kl: cC, cT, cL, cR, cW, cS, n, m, Thr, cQ, dq = A_Yreg_terms(k); sq = sqrt(k) w1 = max(w1, cC); w2 = max(w2, cT + cW - (-A_SQ*n + 0.64 + 11.635)); w3 = max(w3, -A_SQ*n - (-A_SQ*sq + 4.105)) w4 = max(w4, cR - ((10/3)*log(k) - 7.91)); w6 = max(w6, cS + log(k)); w7 = max(w7, cL); w8 = max(w8, cQ) tot = cT + cL + cR + cW + cS + cQ; w5 = max(w5, tot - (-A_SQ*sq + (7/3)*log(k))) Y = A_C0*k + tot; s0, b, E1, x = A_frac(k, Y, Thr) fE = A_FRAC_C/10**4*k - 2.37*sq + (7/3)*log(k) if E1 - fE > wE: wE = E1 - fE; wEk = k okA25 &= (k/Thr < sq + 6.59) and (k/Thr - 0.5 > sq + 3.5) and 2*s0 > 5*k and (k/(5*(dq + 0.5)**2) < (2*dq + 3)*(2*dq + 8)/(5*(dq + 0.5)**2) <= 0.91) okA25 &= k/(6*(dq - 0.5)**2) < (2*dq + 3)*(2*dq + 8)/(6*(dq - 0.5)**2) <= 0.81 check(w1 < 2.41 and w2 < 0 and w3 < 0 and w4 < 0 and w6 < 0.0316 and w7 < 0.71 and w8 < 1.72 and w5 < 11, f"Proposition A.33 at {len(kl)} values of k between 5000 and 1e12: 2 rho_3 = {w1:.4f}; the estimates of the proof " f"hold (the loss for D_M <= D < D_star is at most {w7:.3f}, and the loss for D >= D_Q is at most {w8:.3f} < 0.91 + 0.81); the sums are " f"smaller than (10/3) log k - 7.91; -log(z_k/tau_k) <= -log k + {w6:.4f}; Y - C_0^star k + c_star sqrt k - (7/3) log k <= {w5:.3f}") r14 = 2*sum(float(c)*log(float(x)) for D in range(4, 15) for c, x in A_rhodag_terms(D)) okb = 2*A_RHO3 + r14 < 11.416 - 1e-6 and 11.416 + 5/29 + 0.1722 - (20/3)*log(14.5) - (8/3)*log(2) < -7.91 okb &= A_rho3_terms() == [(Fr(4, 35)*Fr(275, 24), Fr(39, 32)), (Fr(1, 8)*4, Fr(25, 22)), (Fr(25, 104)*Fr(148, 25), Fr(275, 171)), (Fr(25, 168)*Fr(86, 9), Fr(57, 50)), (Fr(1, 6)*3, Fr(34, 33))] okb &= Fr(4, 35)*Fr(275, 24) == Fr(55, 42) and Fr(25, 168)*Fr(86, 9) == Fr(1075, 756) and Fr(25, 104)*Fr(148, 25) == Fr(37, 26) okb &= all(Fr(50, 9*d) + Fr(1, d*d) + Fr(13, 4)/(d + Fr(1, 2))**2 < Fr(1722, 10**4) for d in range(33, 10**4)) okb &= all((2*d + 3)*(2*d + 8)/(6*(d - 0.5)**2) <= 0.81 for d in range(33, 10**5)) okb &= 0.64 + 0.71 + 0.91 + 0.81 - 7.91 + 11.635 + 4.105 + 0.0316 < 11 # the summands of the sums: the polynomial 37 s^4 + 507 s^3 + 2340 s^2 + 3776 s + 640 (s = D - 4) def pmul(a, b): r = [Fr(0)]*(len(a) + len(b) - 1) for i, x in enumerate(a): for j, y in enumerate(b): r[i+j] += x*y return r def padd(a, b, sg=1): r = [Fr(0)]*max(len(a), len(b)) for i, x in enumerate(a): r[i] += x for i, x in enumerate(b): r[i] += sg*x return r Dp = [Fr(0), Fr(1)] def t3d6(num): # D^6 T3(num/D^2), T3(y) = y - y^2/2 + y^3/3 D4 = pmul(pmul(Dp, Dp), pmul(Dp, Dp)) return padd(padd(pmul(num, D4), pmul(pmul(num, num), [Fr(0), Fr(0), Fr(-1, 2)])), [x/3 for x in pmul(pmul(num, num), num)]) Lp = padd(pmul([Fr(6), Fr(6)], t3d6([Fr(2), Fr(3)])), pmul([Fr(-6), Fr(6)], t3d6([Fr(2), Fr(1)]))) Rp = pmul([Fr(12), Fr(12)], [Fr(0), Fr(0), Fr(0), Fr(13, 4), Fr(-3, 2), Fr(2)]) Pp = padd(Rp, Lp, -1) while Pp and Pp[-1] == 0: Pp.pop() from math import comb as _comb Qp = [Fr(0)]*len(Pp) for e, c in enumerate(Pp): for j in range(e + 1): Qp[j] += c*_comb(e, j)*4**(e - j) okb &= Qp == [640, 3776, 2340, 507, 37] okb &= all(D*A_lam(D) <= 2/D - 1.5/D**2 + 3.25/D**3 for D in range(4, 10**5)) and all(2/3 + 16/(3*D) + 8/(3*D*D) < 3.25 for D in (4, 5)) n = 67; xi = n + 8 + 39/n okb &= xi/(2*n) + 4*xi/n**2 < 0.64 and (17*47 + 69.5)/(2*46.5**2) + 1 - 0.5 < 0.71 and -39*A_SQ/n + (190*n*n + 1248*n + 3042)/(n*n*(n+1)) < 2.505 okb &= 8*A_SQ > 7.885 and 2*L1 < 3.015 and 4.164*A_SQ < 4.105 okb &= -log(TAU_INV*41/382) < 0.0316 okb &= sqrt(5000) - sqrt(5000-23) < 0.164 and A_D0(5000) == 67 and A_DM(5000) == 47 and A_DQ(5000) == 33 # the numbers rho_D: the polynomial of degree 16 in s = D - 8 (exact), and the bound 25/(9D) + 1/(2D^2) def ipmul(a, b): r = [0]*(len(a) + len(b) - 1) for i, x in enumerate(a): for j, y in enumerate(b): r[i+j] += x*y return r def ipadd(a, b, sg=1): r = [0]*max(len(a), len(b)) for i, x in enumerate(a): r[i] += x for i, x in enumerate(b): r[i] += sg*x return r def ippow(a, e): r = [1] for _ in range(e): r = ipmul(r, a) return r N3 = [4, 15, 14]; M3 = ipmul([0, 1], ipmul([1, 6], [-1, 2])); N4 = [-4, 10]; M4 = [6, 3, 6] # y_3 = N3/M3, y_4 = N4/M4 T3n = lambda N, M: ipadd(ipadd([6*x for x in ipmul(N, ipmul(M, M))], [3*x for x in ipmul(ipmul(N, N), M)], -1), [2*x for x in ippow(N, 3)]) # 6 M^3 T3(N/M) M33, M43 = ippow(M3, 3), ippow(M4, 3) # 72 D^2 (2D+1) M3^3 M4^3 (25/(9D) + 1/(2D^2) - 2(5D+3)/(3(2D+1)) T3(y_3) - T3(y_4)/2), T3(y) = y - y^2/2 + y^3/3 PR = ipadd(ipmul(ipmul([36, 200], [1, 2]), ipmul(M33, M43)), ipadd([8*x for x in ipmul(ipmul([3, 5], T3n(N3, M3)), ipmul(M43, [0, 0, 1]))], [6*x for x in ipmul(ipmul(T3n(N4, M4), [1, 2]), ipmul(M33, [0, 0, 1]))]), -1) while PR and PR[-1] == 0: PR.pop() QR = [0]; for cf in reversed(PR): QR = ipadd(ipmul(QR, [8, 1]), [cf]) # the coefficients in s = D - 8 while QR and QR[-1] == 0: QR.pop() okb &= len(QR) == 17 and all(x > 0 for x in QR) T3f = lambda y: y - y*y/2 + y**3/3 for D in (8, 9, 20, 1000): # the polynomial against its definition d = Fr(D); y3 = Fr(14*D*D + 15*D + 4, D*(6*D + 1)*(2*D - 1)); y4 = Fr(10*D - 4, 3*(2*D*D + D + 2)) val = Fr(25, 9*D) + Fr(1, 2*D*D) - Fr(2*(5*D + 3), 3*(2*D + 1))*T3f(y3) - T3f(y4)/2 okb &= val*72*D*D*(2*D + 1)*(D*(6*D + 1)*(2*D - 1))**3*(3*(2*D*D + D + 2))**3 == sum(cf*D**i for i, cf in enumerate(PR)) okb &= [(c, Fr(a, b)) for c, a, b in A_rho_terms(D)] == [(Fr(2*(5*D + 3), 3*(2*D + 1)), 1 + y3), (Fr(1, 2), 1 + y4)] Dr = np.arange(8, 10**6, dtype=float); rhoa = A_rho_array(10**6 - 1)[4:] okb &= bool(np.all(rhoa <= 25/(9*Dr) + 0.5/Dr**2)) Dr2 = np.arange(15, 10**6, dtype=float); rhod = A_rhodag_array(10**6 - 1)[11:] okb &= bool(np.all(rhod <= 10/(3*Dr2) + 1.25/Dr2**2)) okb &= all(6*d*d > 19*d + 13 and Fr(-3, d + 1) + Fr(3, 2*d) + Fr(13, 4*d*d) < 0 for d in range(33, 10**4)) # Lambda_D^star - Lambda_D^sharp <= 1/(5 D^3) for D >= 14 Da = _A_D[10:]; dls = _A_DLS[10:] okb &= Da[0] == 14 and bool(np.all(dls >= 0)) and bool(np.all(dls <= 1/(5*Da**3))) and bool(np.all(_A_DLS >= 0)) okb &= all(Fr(7*D + 4, 6*D**3*(6*D + 1)) <= Fr(1, 5*D**3) and Fr(2*(3*D*D + 4*D + 2), D*(6*D + 1)) == 1 + Fr(7*D + 4, D*(6*D + 1)) and Fr(2*D, 3*D + 1) - Fr(1, 2) == Fr(D - 1, 2*(3*D + 1)) < Fr(1, 6) for D in range(14, 3000)) okb &= Fr(4*5106, 22445) <= Fr(91, 100) and 4*5*33.5**2 == 22445 and (2*33 + 3)*(2*33 + 8) == 5106 and all((2*d + 3)*(2*d + 8)*(d - 0.5)**2 <= (2*d + 1)*(2*d + 6)*(d + 0.5)**2 for d in range(34, 10**4)) check(okb, "the numerical constants in the proof of Proposition A.33: 2 rho_3 + 2 (rho_4^dagger + ... + rho_14^dagger) = " f"{2*A_RHO3 + r14:.6f} < 11.416, rho_3 as stated, 11.416 + 5/29 + 0.1722 - (20/3) log 14.5 - (8/3) log 2 < -7.91, the bounds 0.1722 and 0.81 " "for d >= 33, the polynomial " "37 s^4 + 507 s^3 + 2340 s^2 + 3776 s + 640 (exact), D Lambda_D <= 2/D - 3/(2D^2) + 13/(4D^3) (4 <= D < 1e5), the constants for n = 67, " "D_M = 47 and D_Q = 33; for the numbers rho_D: the polynomial of degree 16 in s = D - 8 has positive coefficients (exact), " "rho_D <= 25/(9D) + 1/(2D^2) for 8 <= D < 1e6, and rho_D^dagger <= 10/(3D) + 5/(4D^2) for 15 <= D < 1e6 (floating point); " "Lambda_D^star - Lambda_D^sharp lies in [0, 1/(5D^3)] for 14 <= D <= 1e6, with the inequalities of the proof; and the sum of " "the constants is 10.9316 < 11") check(wE < A_FRACE_CONST and okA25, f"Proposition A.39 (ii) at the same values of k, with the upper bound for Y_k(Theta) of Proposition A.33: " f"E - {A_FRAC_C/10**4} k + 2.37 sqrt k - (7/3) log k <= {wE:.3f} (k = {wEk}); Y - C_0^star k + c_star sqrt k - (7/3) log k <= {w5:.3f}; " "sqrt k + 3.5 < k/Theta' < k/Theta < sqrt k + 6.59, and 2 s_0 > 5k") sq5 = sqrt(5000) l73 = Fr(7, 3)*Fr(float(_upk(np.log(5000.0), A_LOG_ULP))) # (7/3) log 5000, rounded up sq5f = Fr(float(_dn(np.sqrt(5000.0)))) check(A_C0_R[1] + TAU_INV/2 < A_FRAC_C/10**4 and 2*log(2) > 1.3862 and 1.3862*3.5 > 4.85 and A_SQ + 1.3862 > 2.37 and Fr(11) + 2 - Fr(485, 100) < Fr(82, 10) and -3 + 9 + 39/n < 6.59 and 5 + TAU_INV/2 < 9.52 and 1 + 2*6.59 < 15 and Fr(A_FRAC_C, 10**4) - Fr(952, 100) > Fr(12, 10) and 1.2*5000 > 4.37*sq5 + 7 and Fr(15) - Fr(82, 10) < 7 and Fr(5256, 10**4)*sq5f > l73 + 12 and Fr(3328, 10**4)*sq5f > l73/2 + 7 and Fr(4456, 10**4)*sq5f > l73 + 11 and Fr(40, 100)*sq5f > l73 + Fr(82, 10) and Fr(9856, 10**4) - Fr(46, 100) >= Fr(5256, 10**4) and Fr(4928, 10**4) - Fr(16, 100) >= Fr(3328, 10**4) and Fr(9856, 10**4) - Fr(54, 100) >= Fr(4456, 10**4) and Fr(237, 100) - Fr(197, 100) >= Fr(40, 100) and A_SQ/2 > 0.4928 and Fr(11, 2) + 1 < 7 and A_SQ > 0.9856 and all(c/(2*sq5) > Fr(7, 3)/5000 for c in (0.5256, 2*0.3328, 0.4456, 0.40)) and all(A_FRAC_C/10**4 < log(k) + 8.02113 for k in (5000, 5001)), f"the numerical constants in the proof of Proposition A.39 (ii): C_0^star + 4.5139505 = {A_C0 + TAU_INV/2:.6f} < {A_FRAC_C/10**4}, 2 log 2 > 1.3862, " "1.3862 * 3.5 > 4.85, c_star + 1.3862 > 2.37, 13 - 4.85 < 8.2, k/Theta < sqrt k + 6.59 (n >= 67), 9.5139505 k + 2 sqrt k + 14.18 < 9.52 k + 2 sqrt k + 15, " "1.2 k > 4.37 sqrt k + 7 for k >= 5000; in the proofs of Theorems A.1, A.3, A.4, A.5, for k = 5000 (exact; the differences increase with k): " "0.5256 sqrt k > (7/3) log k + 12, 0.3328 sqrt k > (7/6) log k + 7, 0.4456 sqrt k > (7/3) log k + 11, 0.40 sqrt k > (7/3) log k + 8.2, " f"c_star/2 > 0.4928 and 11/2 + 1 < 7; {A_FRAC_C/10**4} < log k + 8.02113 for k >= 5000") okc2 = all(D*D + 9*D + 36 + (114*D-2)/(D*(D-3)) < 2000 for D in range(4, 41)) and all((114*D-2)/(D*(D-3)) < 3 for D in range(41, 10**5)) check(okc2 and 1/(1+2*A_C0_R[1]/TAU_INV) > 0.4205 and 1/(1+2*A_C0_R[0]/TAU_INV) < 0.4206, f"the two cases at the end of the tents in the proof of Lemma A.32; 1/(1 + 2 C_0^star/9.027901) = {1/(1+2*A_C0/TAU_INV):.5f} (Section A.8)") yr = A_Yreg(5000) + A_C0*5000 g5 = floor(Fr(A_C0_R[1])*5000 - Fr(9856, 10**4)*Fr(float(_dn(np.sqrt(5000.0)))) + Fr(7, 3)*Fr(float(_upk(np.log(5000.0), A_LOG_ULP))) + 12) check(tab[5000]['Y'] < yr and all(tab[k]['Y'] < A_Yreg(k) + A_C0*k for k in range(4400, 5001, 3)) and g5 == G5_EXPECT and rec[5000]['G'] == REC5000_EXPECT, f"for k = 5000 the first bound of Proposition A.33 is Y <= {yr:.2f}, against Y^nat = {tab[5000]['Y']:.2f} from the chains; the bound for G(5000) in " f"Theorem A.1 is {g5}, against G^flat(5000) = {rec[5000]['G']}") # ---- (i) the remarks # the remark after the proof of Theorem A.31: the exact logarithm of the step eg = {k: A_exactlog_gain(k) for k in (37, 100, 1000, 5000)}; egs = [A_exactlog_gain(k) for k in range(38, 301, 7)] SUBST = {'EXACTLOG': '$0.068$, $0.046$, $0.018$ and $0.008$ for $k=37$, $100$, $1000$ and $5000$', 'CNRANGE': '$0.0730$ and $0.1083$'} check(SUBST['EXACTLOG'] == ", ".join(f"${eg[k]:.3f}$" for k in (37, 100, 1000)) + f" and ${eg[5000]:.3f}$ for $k=37$, $100$, $1000$ and $5000$" and all(0 < x < eg[37] for x in egs) and eg[37] < 0.07, "with the integrand 2/(-k log(1 - theta/k)) in place of 2/theta - 1/k, Y_k(Theta_k) would be smaller by " + ", ".join(f"{eg[k]:.4f}" for k in eg) + " for k = 37, 100, 1000, 5000 (quadrature, theta_k from Definition A.25)") check(SUBST['CNRANGE'] == f"${min(csm):.4f}$ and ${max(csm):.4f}$" and floor(rec[37]['c']*10**4) == 1048 and floor(cn.min()*10**4) == 1036 and cn.max() < 13/120, "the numbers that are inserted in the text of Sections A.6 and A.7 agree with the computation (c_n between 0.0730 and 0.1083 for 6 <= k <= 36; " "c_n = 0.1048... for k = 37; 0.1036 <= c_n < 13/120 for 37 <= k <= 5000)") # Remark A.40: the term of order sqrt k rr = (kB - A_C0_LO*K)/np.sqrt(K); rt = Th/np.sqrt(K) ups = [(ks[i+1], rr[i+1] - rr[i]) for i in range(20, len(ks) - 1) if rr[i+1] >= rr[i]] check(-0.7025 < rr[0] < -0.7024 and -1.1312 < rr[-1] < -1.1311 and -1.0472 < rr[-2] < -1.0471 and ks[int(rr.argmax())] == 57 and -0.2519 < rr.max() < -0.2518 and bool(np.all(np.diff(rr[:21]) > 0)) and bool(np.all(np.diff(Th) > 0)) and max(d for k, d in ups) < 0.0015 and min(rr[:-1]) > -1.0477, f"Remark A.40: (k B^nat(k) - C_0^star k)/sqrt k increases from {rr[0]:.4f} at k = 37 to {rr.max():.4f} at k = {ks[int(rr.argmax())]}, and then decreases, up to " f"{len(ups)} rises by less than 0.0015, to {rr[-2]:.4f} at k = {KNUM-1} (seed 1/10), and it is {rr[-1]:.4f} at k = {KNUM} (seed 41/382); " "Theta^nat(k) increases with k") check(0.94 < rt.min() and rt.max() < 1.25 and [round(float(rt[k-37]), 2) for k in (100, 1000, 5000)] == [1.06, 1.19, 1.24], f"Remark A.40: Theta^nat(k)/sqrt k lies between {rt.min():.3f} and {rt.max():.3f}; it is " + ", ".join(f"{rt[k-37]:.2f}" for k in (100, 1000, 5000)) + " for k = 100, 1000, 5000") ratb = {k: (big[k]['kB'] - A_C0*k)/sqrt(k) for k in big} check([big[k]['G'] for k in (10**4, 10**5, 10**6)] == [62077, 621551, 6218281] and [f"{ratb[k]:.2f}" for k in (10**4, 10**5, 10**6)] == ['-1.19', '-1.30', '-1.35'] and all(big[k]['Th'] >= 2.25 for k in big), "Remark A.40: for k = 1e4, 1e5, 1e6 the same computation (directed rounding) gives floor(k B^nat(k)) = 62077, 621551, 6218281, and " "(k B^nat(k) - C_0^star k)/sqrt k = -1.19, -1.30, -1.35") rnd = random.Random(5); worst = 1e9; neq = 0; npt = 0; nab = 0; neqab = 0 for _ in range(150): k = int(5000*E**rnd.uniform(0, log(200))); n = A_D0(k) m = A_DM(k); Dq = rnd.randint(4, max(4, m - 1)) ts = [E**rnd.uniform(log(2*tau_k(k)), log(2*A_zk(k))) for _ in range(5)] + [1/(rnd.randint(4, n)*(rnd.randint(4, n)+1)), A_check_t(k), A_check_t3(k)*(1 + 1e-9), (1 + 1e-9)/8, (1 - 1e-9)/12, (1 - 1e-9)/16, (1 + 1e-9)/16, (1 - 1e-9)/(Dq*Dq + 2*Dq + 2)] \ + [x for x in A_WORD_BREAKS if x not in (1/12, 1/20)] ts = [t for t in ts if 2*tau_k(k) <= t <= 2*A_zk(k)] lo = A_theta_direct(k, np.array(ts))[0] for t, l in zip(ts, lo): c = claimed(k, t); worst = min(worst, (l - c)/c); npt += 1; eq = abs(l - c) < 1e-9*c; neq += eq if t > (1 + 1e-9)/(n*(n+1)): nab += 1; neqab += eq check(worst > -1e-12 and npt == 4950 and nab >= 800 and neqab >= 0.88*nab, f"Lemma A.32 against theta_k computed directly from Definition A.25 at {npt} points (k, t) with 5000 <= k <= 1e6: least relative margin {worst:.1e}; " f"equality (to 1e-9) at {neqab} of the {nab} points with t > 1/(D_star(D_star+1)), and at {neq - neqab} of the others") n5 = A_D0(5000); Th5 = n5/(1+n5/5000) Yq = 5000*A_V_quadrature(5000, cap=Th5) - 1 check(1.47 < yr - Yq < 1.48 and 31055.33 < yr < 31055.34 and 31017.15 < tab[5000]['Y'] < 31017.16, f"Remark A.40: for k = 5000 and Theta as in Lemma A.32, Y_k(Theta) = {Yq:.3f} by quadrature, against {yr:.3f} for the first bound of Proposition A.33; Y^nat(5000) = {tab[5000]['Y']:.2f}") xs = np.linspace(2/TAU_INV, 1.0, 200001); f = np.sqrt(1+xs)/xs integ = float(((f[:-1]+f[1:])/2*np.diff(xs)).sum()) check(abs(-4 + sqrt(2)*integ + 1.382) < 5e-4, f"Remark A.40: -4 + sqrt(2) int_(2/9.027901)^1 sqrt(1+x) dx/x = {-4+sqrt(2)*integ:.4f}") # Remark A.41: Definition A.25 formed with the estimates of Section 4 alone (functions A_covered4, A_theta4, # A_Y4_bounds; directed rounding, Riemann sums with theta'_k from the level sets by bisection) got = {37: A_Y4_bounds(37, 4000, 4000), 100: A_Y4_bounds(100, 20000, 30000), 1000: A_Y4_bounds(1000, 40000, 160000)} check(floor(got[37][0]) == floor(got[37][1]) == 246 and floor(got[100][0]) == floor(got[100][1]) == 643 and floor(got[1000][0]) == floor(got[1000][1]) == 6358 and [round(got[k][2], 2) for k in got] == [4.03, 8.09, 28.0], f"Remark A.41, with the estimates of Section 4 alone: Y + 1 lies in [{got[37][0]:.3f}, {got[37][1]:.3f}], [{got[100][0]:.3f}, {got[100][1]:.3f}] and " f"[{got[1000][0]:.3f}, {got[1000][1]:.3f}] for k = 37, 100, 1000, so that G(k) <= 246, 643, 6358, and no smaller bound follows; the largest steps are " + ", ".join(f"{got[k][2]:.2f}" for k in got)) # Remark A.42: the two potentials compared Gn = np.array([tab[k]['G'] for k in ks]); Ln = np.array([tab[k]['l'] for k in ks]); Yn = np.array([tab[k]['Y'] for k in ks]) dY = Yn - Yf; dG = Gn - Gf; dL = Ln - Lf check(1.491 < dY.min() < 1.492 and 9.923 < dY.max() < 9.924 and ks[int(dY.argmin())] == 45 and ks[int(dY.argmax())] == 4974 and dG.min() == 1 and dG.max() == 10 and dL.min() == 0 and dL.max() == 5 and all(tab[k]['G'] == v for k, v in [(37, 225), (50, 308), (100, 617), (1000, 6190), (5000, 31018)]) and all(tab[k]['G'] == floor(Fr(tab[k]['kB'])) and tab[k]['l'] == floor(Fr(tab[k]['Y'])/2) + 1 for k in ks), f"Remark A.42: G^nat = 225, 308, 617, 6190, 31018 for k = 37, 50, 100, 1000, 5000; Y^nat(k) - Y^flat(k) lies between {dY.min():.4f} (k = {ks[int(dY.argmin())]}) and " f"{dY.max():.4f} (k = {ks[int(dY.argmax())]}); G^nat(k) - G^flat(k) lies between {dG.min()} and {dG.max()}; l^nat(k) - l^flat(k) lies between {dL.min()} and {dL.max()}") rel = [] for k in (37, 100, 1000, 3109, 5000, 10**4, 10**5, 10**6): lo, hi = A_theta_direct(k, np.array([2*tau_k(k)])); Thn = A_bound_rig(k)[1] rel.append(max(abs(lo[0] - Thn), abs(hi[0] - Thn))/Thn) check(max(rel) < 1e-12, f"Remark A.42: Theta_k = theta_k(2 tau_k) computed directly from Definition A.25 equals Theta^nat(k) for k = 37, 100, 1000, 3109, 5000, 1e4, 1e5, 1e6 (largest relative difference {max(rel):.1e})") lows = {} for k, r in ((37, 16), (100, 16), (1000, 128), (5000, 128)): lows[k] = A_Y_lower(k, rtop=2*r, rband=r, rtail=r) LOWS = ["225.84", "617.79", "6190.80", "31017.89"] check(all(lows[k] >= tab[k]['G'] for k in (37, 100, 1000)) and tab[5000]['G'] - 1 < lows[5000] < tab[5000]['G'] and 0 < tab[5000]['kB'] - lows[5000] < 0.26 and [f"{floor(100*lows[k])/100:.2f}" for k in lows] == LOWS, "Remark A.42: rigorous lower Riemann sums for Y_k(Theta_k) + 1 (theta_k from Definition A.25 by bisection): " + ", ".join(f"{floor(100*lows[k])/100:.2f}" for k in lows) + f" for k = 37, 100, 1000, 5000; hence G^nat(k) = floor(Y_k(Theta_k)) + 1 for k = 37, 100, 1000, and G^nat(5000) exceeds " f"floor(Y_k(Theta_k)) + 1 by at most one: the sum lies below k B^nat(k) = {tab[5000]['kB']:.2f} by {tab[5000]['kB'] - lows[5000]:.2f}") return tab # ---- Appendix C: classical Weyl sums on the minor arcs (Part 15) ------------------------------------------------------- # Tables C.16 and C.17 of Appendix C: permissible exponents lambda_s for k = 13 (3 <= s <= 29; for 30 <= s <= 36 those of # [VW2000] are kept) and for k = 7 (3 <= s <= 16), as supplied with Appendix C. Their certificates are not part of this # program; the program takes the numbers as given (for k = 13 see check_k13_certificates.py). AC_TAB13 = """3.0138372 4.0975313 5.2456738 6.4531257 7.7113553 9.0229313 10.3818683 11.7900148 13.2456964 14.7478586 16.2949559 17.8853235 19.5168810 21.1874102 22.8944072 24.6352157 26.4070578 28.2072765 30.0331387 31.8819665 33.7512815 35.6386952 37.5420136 39.4592631 41.3886270 43.3284769 45.2781827""" AC_TAB13_OLD = """3.0139128 4.0980713 5.2480334 6.4550068 7.7136017 9.0257224 10.3855801 11.7953083 13.2521623 14.7557170 16.3039366 17.8953488 19.5276970 21.1988910 22.9062626 24.6473038 26.4190897 28.2190701 30.0445818 31.8929000 33.7616279 35.6483904 37.5510006 39.4675269 41.3961543 43.3352806 45.2834077""" # the column 'lambda_s of [VW2000]' AC_TAB13_DIFF = """0.0000756 0.0005400 0.0023596 0.0018811 0.0022464 0.0027911 0.0037118 0.0052935 0.0064659 0.0078584 0.0089807 0.0100253 0.0108160 0.0114808 0.0118554 0.0120881 0.0120319 0.0117936 0.0114431 0.0109335 0.0103464 0.0096952 0.0089870 0.0082638 0.0075273 0.0068037 0.0052250""" # the column 'difference' AC_TAB7 = """3.0639191 4.2641175 5.5883714 7.0112877 8.5354945 10.1452619 11.8378097 13.5967835 15.4160566 17.2838314 19.1816084 21.1034170 23.0452117 25.0034270""" AC_SIGMA = _Fr(1, 10**6) # sigma of Section C.7 AC_H = 4e-6 # the cells grow by the factor 1 + H (approximately) def AC_delta(k): """Delta_s = lambda_s - 2s + k (0 <= s <= S) for the tables of Appendix C: k = 13 (Table 16 for s <= 29, [VW2000] for s >= 30) and k = 7 (Table 17)""" if k == 13: vw = A_VW4[13].split() _require(" ".join(vw[:27]) == " ".join(AC_TAB13_OLD.split()), "Table 16: the column of [VW2000]") lam = [_Fr(0), _Fr(1), _Fr(2)] + [_Fr(x) for x in AC_TAB13.split()] + [_Fr(x) for x in vw[27:]] elif k == 7: lam = [_Fr(0), _Fr(1), _Fr(2)] + [_Fr(x) for x in AC_TAB7.split()] else: raise ValueError(k) return [lam[s] - 2*s + k for s in range(len(lam))] def AC_T(Dl, k): """T_k: 4u^2/(k - 2 Delta_u), u = k - 1, rounded up to two decimals (as a string)""" u = k - 1; x = _Fr(4*u*u)/(k - 2*Dl[u]); c = -((-x*100)//1) return f"{c//100}.{c % 100:02d}" def AC_theta_lo(k, t): """check-theta(t) of Section C.7: the larger of 1 and the value at t of the chain that is used at the least point of division b >= t (Lemma A.28(iv)), rounded downwards; 1 beyond the last point of division (1/4)""" t = np.asarray(t, float); Dl = A_Dlim(k); div = A_divpoints(Dl) _require(abs(div[-1] - 0.25) < 1e-15) out = np.ones_like(t); ok = t <= div[-1] if np.any(ok): b = div[np.searchsorted(div, t[ok], side='left')]; kv = np.full(b.size, float(k)) J, D = A_family(b, kv, np.full(b.size, Dl)) out[ok] = np.maximum(A_theta_hat_lo(kv, t[ok], J, D), 1.0) return out def AC_psi_up(Dl, k, z): """upper bounds for Psi(z) = min_s (2s + Delta_s/z)/k at an array z of positive floating point numbers""" z = np.asarray(z, float); best = None for s, d in enumerate(Dl): val = _up(_up(2.0*s + _up(_fup(d)/z))/k) best = val if best is None else np.minimum(best, val) return best def AC_psi_exact(Dl, k, z): return min((2*s + d/z)/k for s, d in enumerate(Dl)) class AC_Cells: """the cells [zeta_i, zeta_(i+1)) of Section C.7 for the table Dl and the number T = T_k, with the numbers hat-S_i and their suffix minima underline-hat-S_i, rounded downwards""" def __init__(self, k, Dl, T): self.k, self.Dl = k, Dl tau = 1/_Fr(T); self.tau = tau c0 = float(_dn(_flo(tau*(1 - _Fr(1, 10**7))))) n = int(np.ceil(np.log(0.2/c0)/np.log1p(AC_H))) + 2 z = c0*np.exp(np.arange(n + 1)*np.log1p(AC_H)); z[0] = c0 _require(bool(np.all(np.diff(z) > 0)) and z[-1] > 0.2, "the cells of Section C.7") iend = int(np.searchsorted(z, 0.2, side='right')) # z[iend] is the first point beyond 1/5 self.z = z[:iend + 1] one_ms = float(_dn(_flo(1 - AC_SIGMA))); one_ps = float(_up(_fup(1 + AC_SIGMA))); f9 = float(_dn(_flo(1 - _Fr(1, 10**9)))) _require(_Fr(one_ms) <= 1 - AC_SIGMA and _Fr(one_ps) >= 1 + AC_SIGMA and _Fr(f9) <= 1 - _Fr(1, 10**9)) t = _up(_up(2*self.z[1:])*one_ps) # 2 zeta_(i+1) (1 + sigma), rounded upwards _require(bool(np.all(t < 0.5))) th = AC_theta_lo(k, t) th = _dn(_dn(th*one_ms)*f9) S = _dn(self.z[:-1]/_up(1 - _dn(th/k))) self.S = S; self.Sbar = np.minimum.accumulate(S[::-1])[::-1] self.c0 = c0 def evaluate(self, z0, v): """for the switch point zeta_(i0), the largest cell point not exceeding z0: a dictionary with i0, z0, an upper bound kG0 for k hat-G_0, an upper bound E for hat-E (exact fraction), and c3 = Psi(z0) - Psi(underline-hat-S_(i0)) - 2/k (exact); the potential is formed as in Section C.7 (the expression of Lemma C.4 with the points hat-x_j)""" k, Dl, z, Sb = self.k, self.Dl, self.z, self.Sbar N = z.size - 1 i0 = int(np.searchsorted(z, z0, side='right')) - 1; z0 = float(z[i0]) _require(i0 >= 1 and z0 < 0.1) G = np.empty(N); G[i0:] = AC_psi_up(Dl, k, z[i0:N]) p0 = float(AC_psi_up(Dl, k, np.array([z0]))[0]) x = Sb[:i0].copy(); m = np.ones(i0, int); act = x < z0 while np.any(act): idx = np.searchsorted(z, x[act], side='right') - 1 x[act] = Sb[idx]; m[act] += 1; act = x < z0 psix = AC_psi_up(Dl, k, x) two = float(_fup(_Fr(2, k))) G[:i0] = _up(_up((m - 1)*two) + np.maximum(p0, _up(two + psix))) kG = _up(k*G) vf = float(_flo(_Fr(v))) # v rounded downwards d = _up(kG - vf) vals = np.where(d > 0, _up(z[1:N+1]*d), _up(z[:N]*d)) E = _Fr(float(np.max(vals))) lam_end = _Fr(float(z[N])); vv = _Fr(v) def conc(lam): return min((2*s - vv)*lam + d_ for s, d_ in enumerate(Dl)) tail = [conc(lam_end)] + [conc((Dl[s] - Dl[s+1])/2) for s in range(len(Dl) - 1) if (Dl[s] - Dl[s+1])/2 >= lam_end] E = max(E, max(tail)) c3 = AC_psi_exact(Dl, k, _Fr(z0)) - AC_psi_exact(Dl, k, _Fr(float(Sb[i0]))) - _Fr(2, k) return dict(i0=i0, z0=z0, kG0=float(kG[0]), E=E, c3=c3) def AC_check(cells, t, s, z0): """(C.2) and (C.6) for (t, s) at the switch point z0: the evaluation, omega, v, and the margin omega - (1 - omega) hat-E""" k = cells.k; om = _Fr(t, k*(k+1)); v = _Fr(s)/(1 - om) r = cells.evaluate(z0, v) return dict(r, om=om, v=v, margin=om - (1 - om)*r['E']) # the cases of Corollary C.14: (k, t, s, z0, kind), kind 'all' for Theorem C.12 and 'almost' for Theorem C.13 with # (t, s) = (2t', 2s'); the switch points z0 were found by a search over a geometric grid in [0.05, 1/10) AC_CASES = ((7, 8, 23, 0.071045, 'all'), (7, 8, 24, 0.071045, 'almost'), (8, 6, 31, 0.07819, 'all'), (8, 6, 32, 0.07819, 'almost'), (9, 8, 36, 0.08507, 'both'), (10, 6, 44, 0.08248, 'both')) AC_VERIF_EXPECT = [ # the rows of Table 15 as printed '7 & 8 & 23 & 0.07104 & 32.0165 & 0.133624 & 0.142857 & 0.028322 & 0.00905', '7 & 8 & 24 & 0.07104 & 32.0165 & 0.092595 & 0.142857 & 0.063490 & 0.00905', '8 & 6 & 31 & 0.07819 & 38.1574 & 0.081238 & 0.083333 & 0.008865 & 0.00528', '8 & 6 & 32 & 0.07819 & 38.1574 & 0.057051 & 0.083333 & 0.031036 & 0.00528', '9 & 8 & 36 & 0.08507 & 44.2944 & 0.077981 & 0.088888 & 0.017840 & 0.00871', '10 & 6 & 44 & 0.08248 & 50.5028 & 0.052455 & 0.054545 & 0.004952 & 0.01261', ] AC_THRESH = ((7, 0.07076, "32.017"), (8, 0.0804, "38.104"), (13, 0.09358, "69.044")) # Remark C.6: switch point, bound for k hat-G_0 def part15(): from time import time as _now print("15. Appendix C") t0 = _now() # ---- (a) the tables of Section C.8 D13 = AC_delta(13); D7 = AC_delta(7) old13 = [_Fr(x) for x in AC_TAB13_OLD.split()]; new13 = [_Fr(x) for x in AC_TAB13.split()] check(len(new13) == 27 and all(o - n_ == _Fr(d) for o, n_, d in zip(old13, new13, AC_TAB13_DIFF.split())) and all(n_ < o for o, n_ in zip(old13, new13)) and len(D13) - 1 == 36 and D13[12] == _Fr('3.7478586') and AC_T(D13, 13) == '104.65', "Table 16 (k = 13): the column of [VW2000] agrees with the table in the program, the column 'difference' is the " "difference of the two columns, every new entry is smaller, Delta_12 = 3.7478586 and T_13 = 104.65") new7 = [_Fr(x) for x in AC_TAB7.split()]; old7 = [_Fr(x) for x in A_VW4[7].split()] check(len(new7) == len(old7) == 14 and all(n_ <= o for o, n_ in zip(old7, new7)) and new7[:2] == old7[:2] and AC_T(D7, 7) == '48.37', "Table 17 (k = 7): no entry exceeds that of [VW2000], the entries for s = 3, 4 are those of [VW2000], and T_7 = 48.37") # ---- (b) Propositions C.17 and C.18: Theorem A.36 with these tables (exact arithmetic, chains with directed rounding) r13 = A_rec_vw(13, T=AC_T(D13, 13), Dl=D13); r7 = A_rec_vw(7, T=AC_T(D7, 7), Dl=D7) check(r13['ok'] and r13['n'] == 8 and r13['G'] == 69 and r13['l'] == 35 and f"{float(r13['Y']):.5f}" == "68.96516" and f"{r13['c']:.7f}" == "0.0931170", f"Proposition C.17: with Table 16, (V1)-(V3), (R1) and (R3) hold, n = 8, c_8 = {r13['c']:.10f}, " f"Y = 13 Psi(c_8) + 16 = {float(r13['Y']):.8f}, so G(13) <= 69 and l = 35") check(r7['ok'] and r7['n'] == 2 and r7['G'] == 32 and r7['l'] == 16 and f"{float(r7['Y']):.5f}" == "31.97665" and f"{r7['c']:.7f}" == "0.0696136", f"Proposition C.18: with Table 17, (V1)-(V3), (R1) and (R3) hold, n = 2, c_2 = {r7['c']:.10f}, " f"Y = 7 Psi(c_2) + 4 = {float(r7['Y']):.8f}, so G(7) <= 32 and l = 16") # ---- (c) Section C.7: the cases of Corollary C.14 with the tables of [VW2000] cells = {k: AC_Cells(k, A_vw_delta(k), A_VW_T[k]) for k in (7, 8, 9, 10)} ncells = [cells[k].z.size - 1 for k in (7, 8, 9, 10)] rows = []; allok = True for k, t, s, z0, kind in AC_CASES: r = AC_check(cells[k], t, s, z0) ok = r['margin'] > 0 and r['c3'] >= 0 and r['v'] > 2*k and 1 <= t < k*(k+1) and r['z0'] < 0.1 if kind in ('all', 'both'): ok &= s > 2*(k//2) + 4 and t + s >= 4*k + 1 if kind in ('almost', 'both'): ok &= t % 2 == 0 and s % 2 == 0 and s//2 > 2*(k//2) + 4 and (t + s)//2 > 2*k allok &= bool(ok) up = lambda x, d: f"{ceil(_Fr(x)*10**d)/10**d:.{d}f}"; dn = lambda x, d: f"{floor(_Fr(x)*10**d)/10**d:.{d}f}" rows.append(f"{k} & {t} & {s} & {r['z0']:.5f} & {up(r['kG0'], 4)} & {up(r['E'], 6)} & {dn(r['om'], 6)} & " f"{dn(r['margin'], 6)} & {dn(r['c3'], 5)}") print(f" k = {k}, (t, s) = ({t}, {s}), z0 = {r['z0']:.8f}: k hat-G_0 <= {r['kG0']:.6f}, hat-E <= {float(r['E']):.8f}, " f"omega = {float(r['om']):.8f}, margin {float(r['margin']):.8f}, (C.2) margin {float(r['c3']):.8f}") for row in rows: print(" Table 15: " + row) check(allok and rows == AC_VERIF_EXPECT, "Corollary C.14 (Table 15): (C.2) and (C.6) hold at the stated switch points for (k, t, s) = (7, 8, 23), (8, 6, 31), " "(9, 8, 36), (10, 6, 44) (Theorem C.12) and for (2t', 2s') = (8, 24), (6, 32), (8, 36), (6, 44) (Theorem C.13), with " f"{min(ncells)} to {max(ncells)} cells for 7 <= k <= 10; the rows of Table 15 are reproduced") # ---- (d) Remark C.6: thresholds of Corollary C.5 at the stated switch points th_ok = [] for k, z0, bound in AC_THRESH: c = cells[k] if k in cells else AC_Cells(k, A_vw_delta(k), A_VW_T[k]) r = c.evaluate(z0, 0) th_ok.append(r['c3'] >= 0 and _Fr(r['kG0']) < _Fr(bound)) print(f" k = {k}: z0 = {r['z0']:.6f}, k G_(z0)(c_0) <= {r['kG0']:.6f}, (C.2) margin {float(r['c3']):.6f}") check(all(th_ok), "Remark C.6: (C.2) holds and k G_(z0)(c_0) lies below " + ", ".join(f"{b} for k = {k} (z0 = {z})" for k, z, b in AC_THRESH)) # ---- (e) Remark C.20, k = 6: the table of [VW1995] truncated at S = 11; (C.2) fails on a grid in [c_0, 1/10) D6 = A_vw95_delta(6)[:12] c6 = AC_Cells(6, D6, A_VW95_T[6]); z0 = c6.c0; worst = None; npts = 0 while z0 < 0.1: i0 = int(np.searchsorted(c6.z, z0, side='right')) - 1 val = 6*(AC_psi_exact(D6, 6, _Fr(float(c6.z[i0]))) - AC_psi_exact(D6, 6, _Fr(float(c6.Sbar[i0])))) worst = val if worst is None or val > worst else worst; npts += 1 z0 *= 1 + 5e-4 check(f"{float(worst):.3f}" == "1.854" and worst < 2, f"Remark C.20: for k = 6 (table of [VW1995] up to S = 11) the largest value of k(Psi(z0) - Psi(underline-hat-S)) " f"at {npts} switch points of relative step 5e-4 in [c_0, 1/10) is {float(worst):.4f} < 2") print(f" (Part 15: {_now() - t0:.0f} seconds)") # ====================================================================================================================== # Part 16: Appendix D (the parts of C_0^star, the bands of large D, further differencing steps) # ====================================================================================================================== class _DSer: """Laurent series in eps = 1/D with rational coefficients, kept to _DSer.NT terms: c[i] is the coefficient of eps^(v+i) (used for the expansions of Lambda_D, Lambda_D^star, Lambda_D^sharp and Lambda_D^dagger in Appendix D)""" NT = 10 def __init__(self, v, c): c = [Fraction(x) for x in c] while c and c[0] == 0: c = c[1:]; v += 1 self.v = v; self.c = (c + [Fraction(0)]*self.NT)[:self.NT] @classmethod def poly(cls, a): """the polynomial a[0] + a[1] D + ... in D = 1/eps""" return cls(-(len(a) - 1), list(reversed(a))) def __mul__(s, o): return _DSer(s.v + o.v, [sum(s.c[j]*o.c[i - j] for j in range(i + 1)) for i in range(s.NT)]) def inv(s): b = [1/s.c[0]] for m in range(1, s.NT): b.append(-sum(s.c[j]*b[m - j] for j in range(1, m + 1))/s.c[0]) return _DSer(-s.v, b) def __truediv__(s, o): return s*o.inv() def __add__(s, o): v = min(s.v, o.v); c = [Fraction(0)]*s.NT for t in (s, o): for i, x in enumerate(t.c): if 0 <= t.v + i - v < s.NT: c[t.v + i - v] += x return _DSer(v, c) def log(s): """log of a series 1 + O(eps)""" assert s.v == 0 and s.c[0] == 1 u = _DSer(1, s.c[1:]); out = _DSer(1, [0]); p = _DSer(0, [1]) for k in range(1, s.NT + 1): p = p*u; out = out + _DSer(p.v, [x*Fraction((-1)**(k + 1), k) for x in p.c]) return out def coef(s, j): return s.c[j - s.v] if 0 <= j - s.v < s.NT else Fraction(0) def _D_ratfun(*factors): """the product of the polynomials in D given by their coefficient lists (ascending), as a series in 1/D""" r = _DSer(0, [1]) for a in factors: r = r*_DSer.poly(a) return r def part16(): from time import time as _now from decimal import Decimal, getcontext print("16. Appendix D") t0 = _now() Fr = Fraction getcontext().prec = 50 def dec(x): x = Fr(x); return Decimal(x.numerator)/Decimal(x.denominator) def dln(x): return dec(x).ln() # correctly rounded to 50 digits by the decimal module # ---- (a) Table 18: the parts of C_0^star pieces = sorted(((Fr(a), Fr(b), Fr(A), Fr(B), w) for a, b, A, B, w in A_TS_PIECES), key=lambda p: -p[0]) terms = [(1/A, b*(A - B*a)/(a*(A - B*b))) for a, b, A, B, w in pieces] okp = (len(pieces) == 21 and terms == [(Fr(c), Fr(x)) for c, x in A_PIECES_EXACT] and pieces[0][1] == Fr(41, 191) and pieces[-1][0] == Fr(1, 20) and all(pieces[i][0] == pieces[i+1][1] for i in range(20))) def part(lo, hi): return 2*sum(dec(c)*dln(x) for (a, b, A, B, w), (c, x) in zip(pieces, terms) if lo <= a and b <= hi) pw = part(Fr(17, 190), Fr(41, 191)); p3 = part(Fr(1, 12), Fr(17, 190)); pD3 = part(Fr(1, 20), Fr(1, 12)) p414 = 2*sum(dec(c)*dln(x) for D in range(4, 15) for c, x in A_lamdag_terms(D)) lam_lo, lam_hi = A_LAMBDA_R werr = dec(Fr(lam_hi) - Fr(lam_lo)) + Decimal('1e-40') rest = dec(Fr(lam_lo)) + dec(Fr(lam_hi)) - pw - p3 - pD3 - p414 # 2 Lambda^star minus the four parts above T18 = [('4.118310', 2 + dln(Fr(341, 41))), ('0.785898', pw), ('0.048947', p3), ('0.305593', pD3), ('0.697537', p414), ('0.263342', rest)] okv = all(abs(v - Decimal(s)) < Decimal('0.0000005') - werr for s, v in T18) and sum(Decimal(s) for s, v in T18) == Decimal('6.219627') check(okp and okv, "Table 18: C_0^star = 2 + log(341/41) + 2 Lambda^star, with 2 + log(341/41) = %.6f and 2 x the integral of dt/(t theta^star(t)) " "over (17/190, 41/191] = %.6f (the words), over (1/12, 17/190] = %.6f, over (1/20, 1/12] = %.6f (D = 3), over (p_15, 1/20] = " "%.6f (4 <= D <= 14) and over (0, p_15] = %.6f (D >= 15; from the interval for Lambda^star); the linear pieces of theta^star " "above 1/20 give the logarithmic terms of (A.1)" % tuple(float(v) for s, v in T18)) # ---- (b) the bands of large D: the expansions of Lambda_D, Lambda_D^star, Lambda_D^sharp (D >= 8), Lambda_D^dagger (D >= 15) S = _D_ratfun; one = _DSer(0, [1]) lamD = one/S([0, 1])*(S([2, 1])/S([0, 1])).log() # theta = D on the band lam_t = one/S([1, 1])*(S([2, 2, 1])/S([0, 0, 1])).log() lam_s = one/S([2, 2])*(S([2, 1, 1], [1, 1], [2, 1])/S([0, 0, 0, 0, 1])).log() lam_h = S([2, 6])/S([3, 3], [1, 2])*(S([2, 6], [2, 1, 2])/S([0, 1], [1, 6], [-1, 2])).log() \ + one/S([2, 2])*(S([1, 6], [2, 1])/S([6, 3, 6])).log() N5 = [12, 64, 111, 97, 52, 12]; P2 = [4, 17, 6] lam_d = S([4, 3])/S([6, 6], [2, 1])*(S(P2, [2, 1], [2, 1], [1, 2], [1, 3])/S([4, 3], N5)).log() \ + S([2, 6])/S([3, 3], [1, 2])*(S(N5)/S([0, 1], [1, 1], [-1, 2], P2)).log() # the series agree with the closed forms of the program (Lambda_D^sharp: A_lamsharp_terms, Lambda_D^dagger: A_lamdag_terms) def at(D, terms): return sum(float(c)*log(float(x)) for c, x in terms) oks = all(abs(at(D, [(c, Fr(a, b)) for c, a, b in A_lamsharp_terms(D)]) - at(D, [(Fr(2*(3*D + 1), 3*(D + 1)*(2*D + 1)), Fr(2*(3*D + 1)*(2*D*D + D + 2), D*(6*D + 1)*(2*D - 1))), (Fr(1, 2*(D + 1)), Fr((6*D + 1)*(D + 2), 3*(2*D*D + D + 2)))])) < 1e-15 for D in (8, 9, 50)) oks &= all(abs(at(D, A_lamdag_terms(D)) - at(D, [(Fr(3*D + 4, 6*(D + 1)*(D + 2)), Fr((6*D*D + 17*D + 4)*(D + 2)**2*(2*D + 1)*(3*D + 1), (3*D + 4)*(12*D**5 + 52*D**4 + 97*D**3 + 111*D**2 + 64*D + 12))), (Fr(2*(3*D + 1), 3*(D + 1)*(2*D + 1)), Fr(12*D**5 + 52*D**4 + 97*D**3 + 111*D**2 + 64*D + 12, D*(D + 1)*(2*D - 1)*(6*D*D + 17*D + 4)))])) < 1e-15 for D in (15, 16, 99)) co = [(s.coef(1), s.coef(2), s.coef(3)) for s in (lamD, lam_t, lam_s, lam_h, lam_d)] okb = co == [(0, 2, -2), (0, 2, -2), (0, 2, Fr(-5, 2)), (0, 2, Fr(-193, 72)), (0, 2, Fr(-17, 6))] check(okb and oks, "(D.1): as D tends to infinity, (1/D) log(1 + 2/D) and Lambda_D are 2/D^2 - 2/D^3 + O(1/D^4), Lambda_D^star = 2/D^2 - (5/2)/D^3 + " "O(1/D^4), Lambda_D^sharp = 2/D^2 - (193/72)/D^3 + O(1/D^4) and Lambda_D^dagger = 2/D^2 - (17/6)/D^3 + O(1/D^4) (exact expansion " "of the closed forms in powers of 1/D; the next coefficients are 2/3, 19/6, 1631/432 and 65/12)") check(lam_t.coef(4) == Fr(2, 3) and lam_s.coef(4) == Fr(19, 6) and lam_h.coef(4) == Fr(1631, 432) and lam_d.coef(4) == Fr(65, 12), "(D.1): the coefficients of 1/D^4 quoted in the message above") # Table 19: sums over D >= 4 and D >= 15 (floating point up to D = 10^6, then the remainders: 0 <= Lambda_D - Lambda_D^dagger # <= 13/(3D^3) since D <= theta^star < D + 7/6, so that each difference of consecutive columns has a remainder in [0, 13/(6N^2)]; # 2/D^2 - 3/D^3 <= Lambda_D <= 2/D^2 and 2/D^2 - 13/(3D^3) <= Lambda_D^dagger <= 2/D^2) D = _A_D; N = A_NT tent = np.log1p(2*(D + 1)/D**2)/(D + 1) star = np.log1p((4*D**3 + 7*D**2 + 8*D + 4)/D**4)/(2*(D + 1)) cols = [('tent', tent, (2/(N + 1) - 3/(2*N**2), 2/N)), ('e', tent - star, (0.0, 13/(6*N**2))), ('f', star - _A_LSH, (0.0, 13/(6*N**2))), ('g', _A_LSH - _A_LDG, (0.0, 13/(6*N**2))), ('dagger', _A_LDG, (2/(N + 1) - 13/(6*N**2), 2/N))] T19 = {'tent': ('0.98774', '0.26641'), 'e': ('0.01720', '0.00190'), 'f': ('0.00751', '0.00073'), 'g': ('0.00215', '0.00044'), 'dagger': ('0.96088', '0.26334')} ok19 = bool(np.all(tent - star >= 0) and np.all(star - _A_LSH >= 0) and np.all(_A_LSH - _A_LDG >= -1e-18)) vals = {} for name, arr, (rlo, rhi) in cols: for i, d0 in enumerate((4, 15)): s = float(arr[d0 - 4:].sum()); lo, hi = 2*(s + rlo) - 1e-12, 2*(s + rhi) + 1e-12 st = float(T19[name][i]); vals[(name, d0)] = 2*s + rlo + rhi ok19 &= st - 0.000005 < lo and hi < st + 0.000005 check(ok19, "Table 19: 2 x the sums over D >= 4 and over D >= 15 of Lambda_D (%.6f, %.6f), of Lambda_D - Lambda_D^star (%.6f, %.6f), of Lambda_D^star - " "Lambda_D^sharp (%.6f, %.6f), of Lambda_D^sharp - Lambda_D^dagger (%.6f, %.6f) and of Lambda_D^dagger (%.6f, %.6f); the differences are " "nonnegative" % tuple(vals[(n, d0)] for n in ('tent', 'e', 'f', 'g', 'dagger') for d0 in (4, 15))) # ---- (c) an increase of theta^star by delta on the bands D >= D_0 lowers C_0^star by at most 2 delta sum D^(-2) log(1 + 2/D) w4 = 2*float(np.sum(np.log1p(2/D)/D**2)) + 4/N**2; w15 = 2*float(np.sum(np.log1p(2/D[11:])/D[11:]**2)) + 4/N**2 check(w4 < 0.1365 and w15 < 0.0091, "(D.2): 2 sum_{D >= D_0} D^(-2) log(1 + 2/D) is %.5f for D_0 = 4 and %.5f for D_0 = 15 (less than 0.1365 and 0.0091)" % (w4, w15)) # ---- (d) further differencing steps along the line: the pairs A^j(1/2, 1/2) and the numbers eta of (A.29) p = (Fr(1, 2), Fr(1, 2)); okd = True; pairs = {} for j in range(1, 61): p = (p[0]/(2 + 2*p[0]), (p[0] + p[1] + 1)/(2 + 2*p[0])); pairs[j] = p # the process A applied j times to (1/2, 1/2) kj = Fr(1, 2**(j + 2) - 2); okd &= p == (kj, 1 - (j + 1)*kj) def eta(j, x): return (1 - pairs[j][1])*(2*x - 1) - pairs[j][0] # x = U/(D+1) for x in (Fr(3, 4), Fr(1)): okd &= all(eta(j, x) == Fr(1, 2**(j + 2) - 2)*(2*(j + 1)*x - j - 2) for j in (1, 2)) okd &= all(eta(j, x) < max(eta(1, x), eta(2, x)) for j in range(3, 61)) okd &= 61*Fr(1, 2**62 - 2) < Fr(1, 10**15) check(okd, "Section D.3(a): A^j(1/2, 1/2) = (kappa_j, 1 - (j+1) kappa_j) with kappa_j = 1/(2^(j+2) - 2), and (1 - lambda)(2U/(D+1) - 1) - kappa is " "eta_(D,j)(U) of (A.29) for j = 1, 2; for 3 <= j <= 60 it is smaller than max{eta_(D,1)(U), eta_(D,2)(U)} at U/(D+1) = 3/4 and 1, " "hence (being linear) for 3/4 <= U/(D+1) <= 1, in particular for D <= U <= D + 1/2; for j > 60 it is less than " "(j+1) kappa_j < 10^-15") print(" (Part 16: %.0f seconds)" % (_now() - t0)) def main(): if '--list' in sys.argv: print_list(); return if '--list-appendix' in sys.argv: print_list_appendix(); return rng = np.random.default_rng(20261124) if '--appendix' in sys.argv: part14(rng) print("\nALL CHECKS PASSED" if OK else "\nSOME CHECK FAILED"); return if '--appendix-c' in sys.argv: part15() print("\nALL CHECKS PASSED" if OK else "\nSOME CHECK FAILED"); return if '--appendix-d' in sys.argv: part16() print("\nALL CHECKS PASSED" if OK else "\nSOME CHECK FAILED"); return Ugrid, vs, sig = part1(rng) part2(rng, Ugrid, vs, sig) part3(rng) part4(rng) part5() part6() part7() part8() part9() part10(rng) part11() part12() part13(rng) part14(rng) part15() part16() print("\nALL CHECKS PASSED" if OK else "\nSOME CHECK FAILED") if __name__ == "__main__": main()