"""Exact height-4 counts and decimal logarithms for 041. The count is an integer; logarithms and pi use 80-digit decimal arithmetic. Adapted from the heightfour.py check supplied by Claude with report-4. Only Python's standard library is needed. """ from decimal import Decimal, localcontext from math import factorial from pathlib import Path import json PI = Decimal('3.14159265358979323846264338327950288419716939937510582097494459230781640628620899') def height_four(width): assert width > 0 and width % 4 == 0 a = width // 4 f = [factorial(j) for j in range(width + 1)] total = sum(f[width] // (f[j]**4 * f[a-j]**4) for j in range(a+1)) count = 2**width * total with localcontext() as ctx: ctx.prec = 80 log_count = Decimal(count).ln() log_main = ((4*width+9)*Decimal(2).ln() -3*(2*PI*width).ln()-Decimal(7)/(2*width)) scaled = width**2 * (log_count-log_main) return {'width': width, 'exact_count': str(count), 'scaled_log_ratio': str(scaled)} if __name__ == '__main__': rows = [height_four(width) for width in [160, 320, 640, 1280]] for row in rows: print(row['width'], row['scaled_log_ratio'][:24]) Path(__file__).with_name('heightfour.json').write_text( json.dumps(rows, indent=2)+'\n')