prompt
list | data_source
string | ability
string | answer
string | raw_problem
string | level
int64 | type
string | reward_model
dict | extra_info
dict |
|---|---|---|---|---|---|---|---|---|
[
{
"content": "Write Python 3.10+ code and output ONLY code (no prose, no markdown).\n\nImplement a search function that proposes a non-negative step-uniform candidate minimizing the bound the verifier computes.\nIt is an upper bound on an autocorrelation inequality.\nThe search function will have minutes to run. You should make sure to spend as much time as possible within your limits and search as in depth as possible.\n\nWe will run the below evaluation function (read-only, you do not get to modify this):\n```python\nimport numpy as np\nimport os\ndef verify_C3_upper_bound(candidate, support=(-0.25, 0.25), verbose=False):\n \"\"\"\n Exact verifier for step-uniform candidates on the given support.\n\n Input:\n candidate : dict with keys {\"family\":\"step_uniform\",\"support\":[-1/4,1/4],\"N\":N,\"heights\":[...]}\n OR a 1D list/np.ndarray of heights (interpreted as uniform bins on 'support').\n support : tuple (a, b), default (-1/4, 1/4)\n\n Returns:\n C_upper_bound : float, a valid witnessed upper bound for C3.\n\n Formula (proved above):\n Let Δ = (b-a)/N, s = sum(heights), and c = np.convolve(heights, heights, mode=\"full\").\n Then sup_t |f*f(t)| = Δ * max|c| and ∫ f = Δ*s, hence\n C3 ≤ max|c| / (Δ * s^2).\n\n Raises:\n ValueError on malformed input or zero integral.\n \"\"\"\n # Parse heights\n if isinstance(candidate, dict):\n if candidate.get(\"family\") != \"step_uniform\":\n raise ValueError(\"Only 'step_uniform' family is supported for exact verification.\")\n heights = np.asarray(candidate.get(\"heights\", []), dtype=float)\n N = int(candidate.get(\"N\", len(heights)))\n if N != len(heights):\n raise ValueError(\"N does not match length of 'heights'.\")\n if \"support\" in candidate:\n sup_cand = tuple(candidate[\"support\"])\n if tuple(np.round(sup_cand, 12)) != tuple(np.round(support, 12)):\n raise ValueError(f\"Support mismatch: expected {support}, got {sup_cand}.\")\n else:\n heights = np.asarray(candidate, dtype=float)\n N = heights.size\n\n if N <= 0:\n raise ValueError(\"Empty height sequence.\")\n\n a, b = map(float, support)\n L = b - a\n if not np.isfinite(L) or L <= 0:\n raise ValueError(\"Invalid support.\")\n Δ = L / N\n\n s = float(np.sum(heights))\n if not np.isfinite(s) or np.isclose(s, 0.0):\n raise ValueError(\"Integral is zero or non-finite; the bound would be undefined/infinite.\")\n\n assert np.all(heights >= 0), \"Each height must be non-negative.\"\n # Discrete autoconvolution (index-sum)\n conv = np.convolve(heights, heights, mode=\"full\")\n max_abs_conv = float(np.max(np.abs(conv)))\n\n # Exact bound for step-uniform candidates\n C_upper_bound = max_abs_conv / (Δ * (s ** 2))\n\n if verbose:\n print(f\"The discovered step function shows C3 <= {C_upper_bound}\")\n\n return C_upper_bound\n\n```\n\n**IMPORTANT: A previous SOTA sequence is available as `height_sequence_1`.**\nThis is a numpy array of 1319 floats that achieves C3 ~ 1.5032. You can use it directly:\n- As a starting point for further optimization\n- To study its structure and derive insights\n- To warm-start your search algorithm\n\nExpected API:\nPlease create at least these 2 top level functions:\n- def propose_candidate(seed=42, budget_s=300, hyperparameters=dict()) -> list[float]\n Return a list of non-negative heights [h_0, ..., h_{N-1}] for a step-uniform function on support [-0.25, 0.25].\n Implementation requirements:\n - Maintain and update a best_so_far candidate and its score throughout the search.\n - Implement an internal timer using time.time(). If 'budget_s' is provided in kwargs, honor it; otherwise assume 300 seconds.\n - Before the deadline (leave a 5-10s safety margin), immediately return best_so_far.\n\n- def create_hyperparameters() -> dict[str, tuple]:\n Return a dict of hyperparameters you will want to sweep over, with the keys corresponding to the name of the hyperparameter and the value being a tuple of possible values for that hyperparameter.\n - We will launch a sweep over these hyperparameters by passing in the different combinations in multiple calls to propose_candidate.\n - You are only allowed to have up to 8 total combinations so choose your hyperparameters wisely.\n\nExample program that uses height_sequence_1 with hyperparameters:\n```python\n\nimport numpy as np\nimport time\nfrom scipy import optimize\nlinprog = optimize.linprog\n\n\ndef create_hyperparameters() -> dict[str, tuple]:\n return {\n 't_step': (0.005, 0.01, 0.02),\n 'perturb_scale': (0.005, 0.01),\n }\n\n\ndef get_good_direction_to_move_into(sequence, t_step):\n \"\"\"Returns the direction to move into the sequence.\"\"\"\n n = len(sequence)\n sum_sequence = np.sum(sequence)\n normalized_sequence = [x * np.sqrt(2 * n) / sum_sequence for x in sequence]\n rhs = np.max(np.convolve(normalized_sequence, normalized_sequence))\n g_fun = solve_convolution_lp(normalized_sequence, rhs)\n if g_fun is None:\n return None\n sum_sequence = np.sum(g_fun)\n normalized_g_fun = [x * np.sqrt(2 * n) / sum_sequence for x in g_fun]\n new_sequence = [(1 - t_step) * x + t_step * y for x, y in zip(sequence, normalized_g_fun)]\n return new_sequence\n\n\ndef solve_convolution_lp(f_sequence, rhs):\n \"\"\"Solves the convolution LP for a given sequence and RHS.\"\"\"\n n = len(f_sequence)\n c = -np.ones(n)\n a_ub = []\n b_ub = []\n for k in range(2 * n - 1):\n row = np.zeros(n)\n for i in range(n):\n j = k - i\n if 0 <= j < n:\n row[j] = f_sequence[i]\n a_ub.append(row)\n b_ub.append(rhs)\n a_ub_nonneg = -np.eye(n)\n b_ub_nonneg = np.zeros(n)\n a_ub = np.vstack([a_ub, a_ub_nonneg])\n b_ub = np.hstack([b_ub, b_ub_nonneg])\n result = linprog(c, A_ub=a_ub, b_ub=b_ub)\n if result.success:\n return result.x\n return None\n\n\ndef propose_candidate(seed=42, budget_s=300, hyperparameters=dict()):\n np.random.seed(seed)\n deadline = time.time() + budget_s - 10\n \n t_step = hyperparameters.get('t_step', 0.01)\n \n if np.random.rand() < 0.5:\n best_sequence = list(height_sequence_1)\n else:\n best_sequence = [np.random.random()] * np.random.randint(100, 1000)\n curr_sequence = best_sequence.copy()\n best_score = verify_C3_upper_bound(best_sequence)\n \n while time.time() < deadline:\n h_function = get_good_direction_to_move_into(curr_sequence, t_step)\n if h_function is None:\n curr_sequence[1] = (curr_sequence[1] + np.random.rand()) % 1\n else:\n curr_sequence = h_function\n \n curr_score = verify_C3_upper_bound(curr_sequence)\n if curr_score < best_score:\n best_score = curr_score\n best_sequence = curr_sequence\n \n return best_sequence\n\n```\n\n\nRules:\n- You can use scientific libraries like scipy, numpy, cvxpy[CBC,CVXOPT,GLOP,GLPK,GUROBI,MOSEK,PDLP,SCIP,XPRESS,ECOS], math.\n- Each height must be non-negative.\n- You can use any N (the SOTA uses N=1319, but you can try others).\n- You can use up to 1 CPUs per hyperparameter combination.\n- Make all helper functions top level and have no closures from function nesting. Don't use any lambda functions.\n- No filesystem or network IO.\n- Do not import verify_C3_upper_bound or height_sequence_1 yourself. Assume they are already available in the global scope.\n- You can retrieve your specified hyperparameters by using the passed in hyperparameters as hyperparameters[\"<insert your hyperparam name here>\"].\n- The code must be wrapped by ```python and ```.\n\nThe previous state of the art used the following approach:\n```latex\nWhile we can only search for \\emph{local} minima numerically, using the ``Mathematica 6'' software we have been able to find examples of step functions with $\\|f * f\\|_{\\infty} < 1.522$, much lower than $\\pi/2$. Subsequently, better examples were produced with the LOQO solver (Student version for Linux and on the NEOS server$^{2}$), reaching the value $\\|f * f\\|_{\\infty} = 1.51237\\ldots$ The best example we are currently aware of has been produced by an iterative algorithm designed by M.~N.~Kolountzakis and the first author. The idea is as follows: take any step function $f = (a_0, a_1, \\ldots, a_{n-1})$ as a starting point, normalized so that $\\sum a_j = \\sqrt{2n}$. By means of linear programming it is easy (and quick) to find the step function $g_0 = (b_0, b_1, \\ldots, b_{n-1})$ which maximizes $\\sum b_j$ while keeping $\\|f * g_0\\|_{\\infty} \\le \\|f * f\\|_{\\infty}$ (obviously, $\\sum b_j \\ge \\sqrt{2n}$ because the choice $g_0 = f$ is legitimate). We then re-normalize $g_0$ as $g = \frac{\\sqrt{2n} g_0}{\\sum b_j}$. Then $\\|f * g\\|_{\\infty} \\le \\|f * f\\|_{\\infty}$ by construction. If the inequality is strict then it is easy to see that for small $t > 0$ the function $h = (1-t)f + tg$ will be better than our original $f$, i.e. $\\|h * h\\|_{\\infty} \\le \\|f * f\\|_{\\infty}$. And we iterate this procedure until a fix-point function is reached.\n```\n\nYou can build on this algorithm or explore other approaches. Try to improve upon the previous state of the art, be creative, find diverse solutions and algorithms, think about interesting insights about the optimization or search of step functions and the problem.\nNotes:\n- The objective minimized by the verifier is implicit in the code above; lower return value is better.\nMake sure to /think and return the code between ```python and ```",
"role": "user"
}
] |
alphaevolve
|
code
|
Write Python 3.10+ code and output ONLY code (no prose, no markdown).
Implement a search function that proposes a non-negative step-uniform candidate minimizing the bound the verifier computes.
It is an upper bound on an autocorrelation inequality.
The search function will have minutes to run. You should make sure to spend as much time as possible within your limits and search as in depth as possible.
We will run the below evaluation function (read-only, you do not get to modify this):
```python
import numpy as np
import os
def verify_C3_upper_bound(candidate, support=(-0.25, 0.25), verbose=False):
"""
Exact verifier for step-uniform candidates on the given support.
Input:
candidate : dict with keys {"family":"step_uniform","support":[-1/4,1/4],"N":N,"heights":[...]}
OR a 1D list/np.ndarray of heights (interpreted as uniform bins on 'support').
support : tuple (a, b), default (-1/4, 1/4)
Returns:
C_upper_bound : float, a valid witnessed upper bound for C3.
Formula (proved above):
Let Δ = (b-a)/N, s = sum(heights), and c = np.convolve(heights, heights, mode="full").
Then sup_t |f*f(t)| = Δ * max|c| and ∫ f = Δ*s, hence
C3 ≤ max|c| / (Δ * s^2).
Raises:
ValueError on malformed input or zero integral.
"""
# Parse heights
if isinstance(candidate, dict):
if candidate.get("family") != "step_uniform":
raise ValueError("Only 'step_uniform' family is supported for exact verification.")
heights = np.asarray(candidate.get("heights", []), dtype=float)
N = int(candidate.get("N", len(heights)))
if N != len(heights):
raise ValueError("N does not match length of 'heights'.")
if "support" in candidate:
sup_cand = tuple(candidate["support"])
if tuple(np.round(sup_cand, 12)) != tuple(np.round(support, 12)):
raise ValueError(f"Support mismatch: expected {support}, got {sup_cand}.")
else:
heights = np.asarray(candidate, dtype=float)
N = heights.size
if N <= 0:
raise ValueError("Empty height sequence.")
a, b = map(float, support)
L = b - a
if not np.isfinite(L) or L <= 0:
raise ValueError("Invalid support.")
Δ = L / N
s = float(np.sum(heights))
if not np.isfinite(s) or np.isclose(s, 0.0):
raise ValueError("Integral is zero or non-finite; the bound would be undefined/infinite.")
assert np.all(heights >= 0), "Each height must be non-negative."
# Discrete autoconvolution (index-sum)
conv = np.convolve(heights, heights, mode="full")
max_abs_conv = float(np.max(np.abs(conv)))
# Exact bound for step-uniform candidates
C_upper_bound = max_abs_conv / (Δ * (s ** 2))
if verbose:
print(f"The discovered step function shows C3 <= {C_upper_bound}")
return C_upper_bound
```
**IMPORTANT: A previous SOTA sequence is available as `height_sequence_1`.**
This is a numpy array of 1319 floats that achieves C3 ~ 1.5032. You can use it directly:
- As a starting point for further optimization
- To study its structure and derive insights
- To warm-start your search algorithm
Expected API:
Please create at least these 2 top level functions:
- def propose_candidate(seed=42, budget_s=300, hyperparameters=dict()) -> list[float]
Return a list of non-negative heights [h_0, ..., h_{N-1}] for a step-uniform function on support [-0.25, 0.25].
Implementation requirements:
- Maintain and update a best_so_far candidate and its score throughout the search.
- Implement an internal timer using time.time(). If 'budget_s' is provided in kwargs, honor it; otherwise assume 300 seconds.
- Before the deadline (leave a 5-10s safety margin), immediately return best_so_far.
- def create_hyperparameters() -> dict[str, tuple]:
Return a dict of hyperparameters you will want to sweep over, with the keys corresponding to the name of the hyperparameter and the value being a tuple of possible values for that hyperparameter.
- We will launch a sweep over these hyperparameters by passing in the different combinations in multiple calls to propose_candidate.
- You are only allowed to have up to 8 total combinations so choose your hyperparameters wisely.
Example program that uses height_sequence_1 with hyperparameters:
```python
import numpy as np
import time
from scipy import optimize
linprog = optimize.linprog
def create_hyperparameters() -> dict[str, tuple]:
return {
't_step': (0.005, 0.01, 0.02),
'perturb_scale': (0.005, 0.01),
}
def get_good_direction_to_move_into(sequence, t_step):
"""Returns the direction to move into the sequence."""
n = len(sequence)
sum_sequence = np.sum(sequence)
normalized_sequence = [x * np.sqrt(2 * n) / sum_sequence for x in sequence]
rhs = np.max(np.convolve(normalized_sequence, normalized_sequence))
g_fun = solve_convolution_lp(normalized_sequence, rhs)
if g_fun is None:
return None
sum_sequence = np.sum(g_fun)
normalized_g_fun = [x * np.sqrt(2 * n) / sum_sequence for x in g_fun]
new_sequence = [(1 - t_step) * x + t_step * y for x, y in zip(sequence, normalized_g_fun)]
return new_sequence
def solve_convolution_lp(f_sequence, rhs):
"""Solves the convolution LP for a given sequence and RHS."""
n = len(f_sequence)
c = -np.ones(n)
a_ub = []
b_ub = []
for k in range(2 * n - 1):
row = np.zeros(n)
for i in range(n):
j = k - i
if 0 <= j < n:
row[j] = f_sequence[i]
a_ub.append(row)
b_ub.append(rhs)
a_ub_nonneg = -np.eye(n)
b_ub_nonneg = np.zeros(n)
a_ub = np.vstack([a_ub, a_ub_nonneg])
b_ub = np.hstack([b_ub, b_ub_nonneg])
result = linprog(c, A_ub=a_ub, b_ub=b_ub)
if result.success:
return result.x
return None
def propose_candidate(seed=42, budget_s=300, hyperparameters=dict()):
np.random.seed(seed)
deadline = time.time() + budget_s - 10
t_step = hyperparameters.get('t_step', 0.01)
if np.random.rand() < 0.5:
best_sequence = list(height_sequence_1)
else:
best_sequence = [np.random.random()] * np.random.randint(100, 1000)
curr_sequence = best_sequence.copy()
best_score = verify_C3_upper_bound(best_sequence)
while time.time() < deadline:
h_function = get_good_direction_to_move_into(curr_sequence, t_step)
if h_function is None:
curr_sequence[1] = (curr_sequence[1] + np.random.rand()) % 1
else:
curr_sequence = h_function
curr_score = verify_C3_upper_bound(curr_sequence)
if curr_score < best_score:
best_score = curr_score
best_sequence = curr_sequence
return best_sequence
```
Rules:
- You can use scientific libraries like scipy, numpy, cvxpy[CBC,CVXOPT,GLOP,GLPK,GUROBI,MOSEK,PDLP,SCIP,XPRESS,ECOS], math.
- Each height must be non-negative.
- You can use any N (the SOTA uses N=1319, but you can try others).
- You can use up to 1 CPUs per hyperparameter combination.
- Make all helper functions top level and have no closures from function nesting. Don't use any lambda functions.
- No filesystem or network IO.
- Do not import verify_C3_upper_bound or height_sequence_1 yourself. Assume they are already available in the global scope.
- You can retrieve your specified hyperparameters by using the passed in hyperparameters as hyperparameters["<insert your hyperparam name here>"].
- The code must be wrapped by ```python and ```.
The previous state of the art used the following approach:
```latex
While we can only search for \emph{local} minima numerically, using the ``Mathematica 6'' software we have been able to find examples of step functions with $\|f * f\|_{\infty} < 1.522$, much lower than $\pi/2$. Subsequently, better examples were produced with the LOQO solver (Student version for Linux and on the NEOS server$^{2}$), reaching the value $\|f * f\|_{\infty} = 1.51237\ldots$ The best example we are currently aware of has been produced by an iterative algorithm designed by M.~N.~Kolountzakis and the first author. The idea is as follows: take any step function $f = (a_0, a_1, \ldots, a_{n-1})$ as a starting point, normalized so that $\sum a_j = \sqrt{2n}$. By means of linear programming it is easy (and quick) to find the step function $g_0 = (b_0, b_1, \ldots, b_{n-1})$ which maximizes $\sum b_j$ while keeping $\|f * g_0\|_{\infty} \le \|f * f\|_{\infty}$ (obviously, $\sum b_j \ge \sqrt{2n}$ because the choice $g_0 = f$ is legitimate). We then re-normalize $g_0$ as $g = rac{\sqrt{2n} g_0}{\sum b_j}$. Then $\|f * g\|_{\infty} \le \|f * f\|_{\infty}$ by construction. If the inequality is strict then it is easy to see that for small $t > 0$ the function $h = (1-t)f + tg$ will be better than our original $f$, i.e. $\|h * h\|_{\infty} \le \|f * f\|_{\infty}$. And we iterate this procedure until a fix-point function is reached.
```
You can build on this algorithm or explore other approaches. Try to improve upon the previous state of the art, be creative, find diverse solutions and algorithms, think about interesting insights about the optimization or search of step functions and the problem.
Notes:
- The objective minimized by the verifier is implicit in the code above; lower return value is better.
Make sure to /think and return the code between ```python and ```
| -1
|
{
"ground_truth": "n/a",
"style": "numpy"
}
|
{
"problem_id": "ac_ineq"
}
|
README.md exists but content is empty.
- Downloads last month
- 5