shinka-backup / ccevolve /tx_workspace /ac1 /reverse_engineer.py
JustinTX's picture
Add files using upload-large-folder tool
2facf1f verified
"""
Reverse-engineer the alphaevolve benchmark value.
The value 1.5052939684401607 must come from a specific step function
evaluated at a specific N. Let's try to find what N and function
give exactly this C1.
If it's from a step function with K steps on N points,
then C1 = max(autoconv) / (sum(f)*dx)^2.
Key: the value might be EXACTLY representable as a ratio of integers
(for a step function on a specific grid).
"""
import numpy as np
from scipy.optimize import minimize
target = 1.5052939684401607
# For step functions with integer heights on N grid points:
# integral = sum(f) * dx = S * 0.5/N where S = sum of heights
# autoconv = sum of products * dx = P * 0.5/N
# C1 = P * 0.5/N / (S * 0.5/N)^2 = P * N / (0.5 * S^2) = 2*P*N / S^2
# So target = 2*P*N / S^2
# P * N = target * S^2 / 2
# For small N, let's search for integer P, S, N that give exactly the target
print("Searching for exact representation 2*P*N/S^2 = target")
for N in range(50, 5001):
for S in range(1, 2*N):
P_exact = target * S**2 / (2 * N)
P_int = round(P_exact)
if abs(P_int - P_exact) < 1e-6 and P_int > 0:
c1 = 2 * P_int * N / S**2
if abs(c1 - target) < 1e-10:
print(f" N={N}, S={S}, P={P_int}: C1 = {c1:.16f}, error = {c1-target:.2e}")
# Also try: the function might have non-integer heights but with specific structure
# For a binary (0/1) step function:
# S = k (number of ones), integral = k * dx
# autoconv[t] = |{(i,j): f[i]=1, f[j]=1, i+j=t}| * dx
# max autoconv ≈ r_max * dx where r_max = max number of representations
# C1 = r_max * dx / (k * dx)^2 = r_max / (k^2 * dx) = 2*N*r_max / k^2
print("\n\nSearching for binary function: 2*N*r_max/k^2 = target")
for N in [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1500, 2000, 3000, 5000]:
for k in range(max(1, N//5), 4*N//5):
r_max = target * k**2 / (2*N)
r_int = round(r_max)
if abs(r_int - r_max) < 0.001 and r_int > 0:
c1 = 2 * N * r_int / k**2
if abs(c1 - target) < 1e-8:
print(f" N={N}, k={k}, r_max={r_int}: C1 = {c1:.16f}")
# Try to find if target has a simple rational form
# target = 1.5052939684401607
# target * 2 = 3.0105879368803214
# target * 100 = 150.52939684401607
# target * 1000 = 1505.2939684401607
# Let's check if target * M is close to integer for small M
print("\n\nChecking if target * M is close to integer:")
for M in range(1, 100000):
val = target * M
frac = val - round(val)
if abs(frac) < 1e-8:
print(f" target * {M} = {round(val)} (frac = {frac:.2e})")
if abs(frac) < 1e-12:
break