diff --git a/research/pr4554-roots-recovery-check/.gitattributes b/research/pr4554-roots-recovery-check/.gitattributes new file mode 100644 index 0000000000..cf808dabba --- /dev/null +++ b/research/pr4554-roots-recovery-check/.gitattributes @@ -0,0 +1 @@ +PR4554-ROOTS-RECOVERY.md -text diff --git a/research/pr4554-roots-recovery-check/PR4554-ROOTS-RECOVERY.md b/research/pr4554-roots-recovery-check/PR4554-ROOTS-RECOVERY.md new file mode 100644 index 0000000000..5791526c61 --- /dev/null +++ b/research/pr4554-roots-recovery-check/PR4554-ROOTS-RECOVERY.md @@ -0,0 +1,223 @@ +# Native root seeds and exact product recovery + +Prepared by Dugongue with substantial OpenAI Codex assistance. Apache-2.0. +Every algorithm here acts directly on bounded words, arrays and arithmetic. +There is no Turing-machine primitive, simulator, conversion or multiplication +black box on an entire variable-length input. Ordinary MUL/DIV on word-sized +operands are allowed, with explicit sufficient width below. + +## 1. A generated primitive-root seed with certified precision + +For every integer D>=1 and requested p>=1, root_seed.py constructs Gaussian +dyadic coordinates x/2^p,y/2^p satisfying + + max(|x/2^p - cos(2pi/D)|, |y/2^p - sin(2pi/D)|) < 2^-p. + +Take P=8(p+16), S=2^P, K=128(p+1). It suffices that every word has at least +2P+20 bits and that D and all array/control addresses fit in one word. Signed +integers are a sign bit and an unsigned magnitude; signed arithmetic expands +to bounded comparisons, ordinary ADD/SUB and word MUL/DIV. This is a uniform +finite loop algorithm, not a stored transcendental constant or root oracle. +For p=Theta(log N) and D<=N^C with fixed C, the sufficient word width remains +Theta(log N). Constants are deliberately conservative. + +### Construct pi rather than assuming it + +Use Machin's identity pi=16 arctan(1/5)-4 arctan(1/239). Its identity can be +verified without a numerical pi supplier: tan(2 arctan(1/5))=5/12 and + tan(4 arctan(1/5))=120/119. The tangent subtraction formula then gives + tan(4 arctan(1/5)-arctan(1/239))=1; the angle is in (0,pi/2), so it is pi/4. + +For q=5 and 239, sum the alternating terms + + (-1)^j floor(S / ((2j+1) q^(2j+1))) + +while q^(2j+1)<=S. Generate successive powers by multiplication by the fixed +integer q^2. There are at most P+1 terms. Each floored term differs from its +exact scaled term by less than 1, and the alternating remainder after stopping +is at most 1/S. Consequently the constructed integer A obeys + + |A/S - pi| <= 20(P+2)/S. + +Every denominator is at most S(2P+3); the next q-power is at most 239^2 S. +These are bounded O(P)-bit integers. Compute the integer angle t=floor(2A/D). +Then 0<=t<=8S and + + |t/S - 2pi/D| <= [40(P+2)+1]/S. + +No search for a prime or primitive root is involved. + +### Fixed-point complex Taylor evaluation + +Start the Taylor term and sum at (S,0). For k=1,...,K, replace the current +term (a,b) by + + (trunc(-b*t/(S*k)), trunc(a*t/(S*k))), + +and add it to the sum. Truncation is toward zero, implemented on sign/magnitude +words. Let theta=t/S. Each coordinate's rounding error in term k satisfies +E_k <= (8/k) E_(k-1)+1/S. Expanding this recurrence and using +j!/k!<=1/(k-j)! yields E_k=1. The cosine and sine +functions are 1-Lipschitz on the real line. Combining the angle, rounding and +tail errors gives the explicit coordinate bound + + E_internal <= [40(P+2)+1+4096K+32]/S. + +The displayed numerator times 2^(p+1) is strictly less than S. Finally round +the two fixed-point sums to nearest at p fractional bits. This adds at most +2^(-p-1), proving the stated strict 2^-p error. + +Term and partial-sum magnitudes are below 2^14 S: the exact absolute Taylor +mass is below exp(8), and the accumulated rounding envelope is smaller than S. +Products with t are below 2^(2P+17), denominators and all Machin intermediates +are smaller still. Thus 2P+20 bits is a sufficient native arithmetic bound. +The implementation charges a conservative + + 100(P+1)+40(K+1) + +word-operation envelope. Both P and K are O(p), so setup is O(p) word +operations and O(1) live arithmetic words, besides caller storage. It is not +necessary to form factorials or unbounded exact rational denominators. + +## 2. Rounding and CRT recover exact convolution coefficients + +Let two nonnegative base-beta digit arrays have lengths a,b, beta=2^h>=2. +Every digit is below beta. Their ordinary linear convolution has length +a+b-1 and coefficients + + c_j = sum_(i+k=j) u_i v_k, + 0 <= c_j <= C=min(a,b)(beta-1)^2. + +**Rounded numerical route.** If a computed dyadic real value Y_j/2^P satisfies +|Y_j/2^P-c_j|<1/2 for every j, nearest-integer rounding recovers every c_j +exactly. Range-checking 0<=c_j<=C is useful, but does not itself prove the +error premise. The numerical transform must establish that premise from its +actual precision and prefix-norm bounds; it cannot be inferred from good +sample outputs. The recovery loop costs O(a+b) word operations. Its input +integers fit when 2^P(C+1), plus fixed rounding slack, fits in a word. + +**Exact modular route.** For distinct certified primes p_1,...,p_s, let +Q=product p_i. If Q>C, the canonical residue in [0,Q) is c_j itself. For +signed coefficients |c_j|<=C, use Q>2C and the representative in (-Q/2,Q/2). + +The supplied CRT constructor checks each prime by literal trial division and +constructs inverses of preceding products by modular repeated squaring with +exponent p_i-2. Primality and inverse work is charged setup. Trial division +costs O(sum sqrt(p_i)) word operations; modular inversion costs +O(sum log p_i). This is a constructive positive algorithm, but these setup +costs are not asserted to fit a fast FFT bound. A fast application must provide +its own fully costed modulus construction or choose the numerical route above. + +For each coefficient maintain its reconstructed x in [0,M), initially x=0, +M=1. The precomputed next modulus data give + + t = ((r_i - (x mod p_i)) mod p_i) * inv(M mod p_i) mod p_i, + x <- x + M*t, M <- M*p_i. + +Compute the subtraction as r_i+p_i-(x mod p_i), then reduce; it is nonnegative. +Induction proves all processed congruences and 0<=x> h. + +If carry<=min(a,b)(beta-1), then + + t <= min(a,b) beta(beta-1), + +and the next carry obeys the same bound. Thus this quantity, together with +buffer addresses, is a sufficient word bound. No large input-sized integer +is ever multiplied by the algorithm. + +The induction invariant is + + sum_(j