mini challenge: find the smallest cosine of an integer
|
10-23-2021, 05:10 PM
(This post was last modified: 10-24-2021 04:39 AM by Albert Chan.)
Post: #12
|
|||
|
|||
RE: mini challenge: find the smallest cosine of an integer
(10-23-2021 06:53 AM)EdS2 Wrote: Is it certain, though, that there is no calculator input of a positive integer which causes the calculator to Let's explore what condition needed to have calculator return |cos(x)| of 0.0 Assumed correct angle-reduction code, and no small-differences-incorrectly-set-to-zero “feature" Again, using 12-digits calculator, and integer x of 14 digits as example. Instead of convergents of pi/200, we do 200/pi Valid convergent/semi-convergent must have odd numerator, and denominator of 12 digits. c:> spigot -d20 -c -l 200/pi 63;1,1,1,23,36,1,1,1,8,2,1,52,13,4,2,6,1,20,4,63 These are convergents of last 3 CF coefs: 20: p0/q0 = 13103161651197/205823981911 04: p1/q1 = 53040623087527/833160159168 63: p2/q2 = 3354662416165398/52694914009495 gap = |p1/q1 - p2/q2| = |p1*q2-p2*q1| / (q1*q2) = 1/(q1*q2) We expected next convergent much better than current convergent. Rough estimate, |200/pi - p1/q1| < gap = 1/(q1*q2) But, gap error is really shared between 2 convergents. Perhaps we increase q2 a bit: q2 = q0 + q1*CF < q1 * (CF+1) |200/pi - 53040623087527/833160159168| ≈ 2.250E-26 1/(833160159168^2 * (63+1)) ≈ 2.251E-26 |cos(x)| // x = 100*q1, with odd p1 ≈ |x - p1*(pi/2)| = (100*q1) * |1 - (p1/q1)/(200/pi)| ≈ (100*q1) * 1/(q1^2*(CF+1)) / (200/pi) = (pi/2) / (q1*(CF+1)) ≈ 2.946E-14 // |cos(833160159168E2)| ≈ 2.945E-14, estimate not too bad Note that factor 100 get cancelled. We can generalize, for big x, with valid convergent p1/q1 (*) |cos(x)| ≈ (pi/2) / (q1*(CF+1)) ≈ (pi/2) / q2 To have |cos(x)| underflow to 0.0, q1*(CF+1) overflowed For a 12-digits calculator that overflow if decimal exponent reached 500 (CF+1) > 10^(500-12) = 10^488 --- 12-digits calculator, x all the way to 500 digits, x of 395 digits has smallest |cos(x)| Free-42 Decimal: 0.700035629422e395 COS ABS → 2.056399907114786850992546180602331e-15 For this number, CF = 1090, estimate formula is pretty close (pi/2) / (700035629422 * (1090+1)) ≈ 2.057e-15 (*) if p1/q1, p2/q2 are not neighboring convergents, we need another estimate formula. Let pm/qm and p2/q2 be neighboring convergents. p1*q2 - p2*q1 = (p2-k*pm)*q2 - p2*(q2-k*qm) = k*(p2*qm - pm*q2) = ±k gap = |p1/q1 - p2/q2| = k / (q1*q2) → |cos(x)| ≈ (pi/2) / (q2/k) Example, x of 137 digits had a higher CF = 2573, yet |cos(x)| is not small Note: we reduced numerator of (2e125/pi), without disturbing its parity. c:\> spigot -d28 -C "2e125/pi mod 2" | tail -3 17206041685/23300343711 202744600696/274555819883 521679063632493/706455424902670 Convergent with 12-digits denominator has even numerator. Best we could use is semi-convergent, with k = 2570 706455424902670 - 274555819883 * 2570 = 846967803360 Estimated |cos(x)| = (pi/2) / (706455424902670/2570) ≈ 5.714e-12 Free42-Decimal: 846967803360e125 COS ABS → 5.714370521060907484280466201567459e-12 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)