Download graders/ea_flat_polynomials_70/check.py from amphora/MathConstructOptimize-Envs: direct link, hf CLI and curl.
- Browser
- Download file 814 Bytes
-
https://huggingface.co/datasets/amphora/MathConstructOptimize-Envs/resolve/main/graders/ea_flat_polynomials_70/check.py
- Command line
-
hf download hf://datasets/amphora/MathConstructOptimize-Envs/graders/ea_flat_polynomials_70/check.py
-
curl -L -o check.py https://huggingface.co/datasets/amphora/MathConstructOptimize-Envs/resolve/main/graders/ea_flat_polynomials_70/check.py
814 Bytes
| """Flat Littlewood polynomial of degree 69 (EinsteinArena flat-polynomials, MIT). | |
| Score = max_{z in grid} |g(z)| / sqrt(71) over 10^6 equally spaced points of the unit circle (minimize), | |
| exactly as the upstream verifier (np.poly1d, np.linspace(0, 2pi, 10^6)). Change: coefficients must be the | |
| JSON integers 1/-1 (upstream cast to float first, so 1.0 and true were accepted).""" | |
| import numpy as np | |
| from run import Invalid, int_list | |
| def check(inst, ans): | |
| n = inst["n_coeffs"] | |
| c = int_list(ans.get("coefficients"), n, -1, 1, "coefficients") | |
| if any(x == 0 for x in c): | |
| raise Invalid("coefficients must be +1 or -1") | |
| zs = np.exp(1j * np.linspace(0, 2 * np.pi, inst["grid"])) | |
| vals = np.abs(np.poly1d(np.array(c, dtype=np.float64))(zs)) | |
| return float(np.max(vals) / np.sqrt(n + 1)), {} | |