amphora commited on
Commit
7f243db
·
verified ·
1 Parent(s): 20f2984

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. tasks/construct-ae-p38-factorial-factors-l3-s2/environment/Dockerfile +7 -0
  2. tasks/construct-ae-p38-factorial-factors-l3-s2/environment/instance.json +1 -0
  3. tasks/construct-ae-p38-factorial-factors-l3-s2/solution/solve.sh +5 -0
  4. tasks/construct-ae-p38-factorial-factors-l3-s2/tests/check.py +12 -0
  5. tasks/construct-ae-p38-factorial-factors-l3-s2/tests/instance.json +1 -0
  6. tasks/construct-ae-p38-factorial-factors-l3-s2/tests/run.py +127 -0
  7. tasks/construct-ae-p38-factorial-factors-l3-s2/tests/test.sh +9 -0
  8. tasks/construct-ae-p38-factorial-factors-l3-s5/environment/Dockerfile +7 -0
  9. tasks/construct-ae-p38-factorial-factors-l3-s5/environment/instance.json +1 -0
  10. tasks/construct-ae-p38-factorial-factors-l3-s5/solution/solve.sh +5 -0
  11. tasks/construct-ae-p38-factorial-factors-l3-s5/tests/check.py +12 -0
  12. tasks/construct-ae-p38-factorial-factors-l3-s5/tests/instance.json +1 -0
  13. tasks/construct-ae-p38-factorial-factors-l3-s5/tests/run.py +127 -0
  14. tasks/construct-ae-p38-factorial-factors-l3-s5/tests/test.sh +9 -0
  15. tasks/construct-ae-p52-erdos-squarefree-l3-s0/environment/Dockerfile +7 -0
  16. tasks/construct-ae-p52-erdos-squarefree-l3-s0/environment/instance.json +1 -0
  17. tasks/construct-ae-p52-erdos-squarefree-l3-s0/solution/solve.sh +5 -0
  18. tasks/construct-ae-p52-erdos-squarefree-l3-s0/tests/check.py +38 -0
  19. tasks/construct-ae-p52-erdos-squarefree-l3-s0/tests/instance.json +1 -0
  20. tasks/construct-ae-p52-erdos-squarefree-l3-s0/tests/run.py +127 -0
  21. tasks/construct-ae-p52-erdos-squarefree-l3-s0/tests/test.sh +9 -0
  22. tasks/construct-ae-p52-erdos-squarefree-l3-s7/environment/Dockerfile +7 -0
  23. tasks/construct-ae-p52-erdos-squarefree-l3-s7/environment/instance.json +1 -0
  24. tasks/construct-ae-p52-erdos-squarefree-l3-s7/solution/solve.sh +5 -0
  25. tasks/construct-ae-p52-erdos-squarefree-l3-s7/tests/check.py +38 -0
  26. tasks/construct-ae-p52-erdos-squarefree-l3-s7/tests/instance.json +1 -0
  27. tasks/construct-ae-p52-erdos-squarefree-l3-s7/tests/run.py +127 -0
  28. tasks/construct-ae-p52-erdos-squarefree-l3-s7/tests/test.sh +9 -0
  29. tasks/construct-ae-p52-erdos-squarefree-l3-s9/environment/Dockerfile +7 -0
  30. tasks/construct-ae-p52-erdos-squarefree-l3-s9/environment/instance.json +1 -0
  31. tasks/construct-ae-p52-erdos-squarefree-l3-s9/solution/solve.sh +5 -0
  32. tasks/construct-ae-p52-erdos-squarefree-l3-s9/tests/check.py +38 -0
  33. tasks/construct-ae-p52-erdos-squarefree-l3-s9/tests/instance.json +1 -0
  34. tasks/construct-ae-p52-erdos-squarefree-l3-s9/tests/run.py +127 -0
  35. tasks/construct-ae-p52-erdos-squarefree-l3-s9/tests/test.sh +9 -0
  36. tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/environment/Dockerfile +7 -0
  37. tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/environment/instance.json +1 -0
  38. tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/solution/solve.sh +5 -0
  39. tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/tests/check.py +24 -0
  40. tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/tests/instance.json +1 -0
  41. tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/tests/run.py +127 -0
  42. tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/tests/test.sh +9 -0
  43. tasks/construct-mc-all-interval-l3-s2/environment/Dockerfile +7 -0
  44. tasks/construct-mc-all-interval-l3-s2/environment/instance.json +1 -0
  45. tasks/construct-mc-all-interval-l3-s2/solution/solve.sh +5 -0
  46. tasks/construct-mc-all-interval-l3-s2/tests/check.py +17 -0
  47. tasks/construct-mc-all-interval-l3-s2/tests/instance.json +1 -0
  48. tasks/construct-mc-all-interval-l3-s2/tests/run.py +127 -0
  49. tasks/construct-mc-all-interval-l3-s2/tests/test.sh +9 -0
  50. tasks/construct-mc-antimagic-square-l3-s0/environment/Dockerfile +7 -0
tasks/construct-ae-p38-factorial-factors-l3-s2/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-ae-p38-factorial-factors-l3-s2/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 252, "t": 75, "family": "ae_p38_factorial_factors", "subset": "construct"}
tasks/construct-ae-p38-factorial-factors-l3-s2/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"factors": [750, 75, 75, 75, 75, 75, 75, 75, 75, 75, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, 83, 83, 83, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 89, 89, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 93, 93, 93, 93, 93, 93, 93, 93, 94, 94, 94, 94, 94, 97, 97, 101, 101, 103, 103, 106, 106, 106, 106, 107, 107, 109, 109, 111, 111, 111, 111, 111, 111, 113, 113, 118, 118, 118, 118, 122, 122, 122, 122, 127, 131, 134, 134, 134, 137, 139, 142, 142, 142, 146, 146, 146, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251]}
5
+ RLMATH_EOF
tasks/construct-ae-p38-factorial-factors-l3-s2/tests/check.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check."""
2
+ import math
3
+
4
+ from run import Invalid, int_list
5
+
6
+
7
+ def check(inst, ans):
8
+ n, t = inst["N"], inst["t"]
9
+ f = int_list(ans.get("factors"), n, t, None, "factors")
10
+ if math.prod(f) != math.factorial(n):
11
+ raise Invalid(f"the product of the factors is not {n}!")
12
+ return None, {"min_factor": min(f)}
tasks/construct-ae-p38-factorial-factors-l3-s2/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 252, "t": 75, "family": "ae_p38_factorial_factors", "subset": "construct"}
tasks/construct-ae-p38-factorial-factors-l3-s2/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-ae-p38-factorial-factors-l3-s2/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-ae-p38-factorial-factors-l3-s5/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-ae-p38-factorial-factors-l3-s5/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 313, "t": 93, "family": "ae_p38_factorial_factors", "subset": "construct"}
tasks/construct-ae-p38-factorial-factors-l3-s5/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"factors": [930, 93, 93, 93, 93, 93, 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 97, 97, 97, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 101, 101, 101, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 103, 103, 103, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 106, 106, 106, 106, 106, 107, 107, 109, 109, 111, 111, 111, 111, 111, 111, 111, 111, 113, 113, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 118, 118, 118, 118, 118, 122, 122, 122, 122, 122, 123, 123, 123, 123, 123, 123, 123, 127, 127, 129, 129, 129, 129, 129, 129, 129, 131, 131, 134, 134, 134, 134, 137, 137, 139, 139, 142, 142, 142, 142, 146, 146, 146, 146, 149, 149, 151, 151, 157, 158, 158, 158, 163, 166, 166, 166, 167, 173, 178, 178, 178, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313]}
5
+ RLMATH_EOF
tasks/construct-ae-p38-factorial-factors-l3-s5/tests/check.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check."""
2
+ import math
3
+
4
+ from run import Invalid, int_list
5
+
6
+
7
+ def check(inst, ans):
8
+ n, t = inst["N"], inst["t"]
9
+ f = int_list(ans.get("factors"), n, t, None, "factors")
10
+ if math.prod(f) != math.factorial(n):
11
+ raise Invalid(f"the product of the factors is not {n}!")
12
+ return None, {"min_factor": min(f)}
tasks/construct-ae-p38-factorial-factors-l3-s5/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 313, "t": 93, "family": "ae_p38_factorial_factors", "subset": "construct"}
tasks/construct-ae-p38-factorial-factors-l3-s5/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-ae-p38-factorial-factors-l3-s5/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-ae-p52-erdos-squarefree-l3-s0/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-ae-p52-erdos-squarefree-l3-s0/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 718, "t": 29, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
tasks/construct-ae-p52-erdos-squarefree-l3-s0/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682, 707]}
5
+ RLMATH_EOF
tasks/construct-ae-p52-erdos-squarefree-l3-s0/tests/check.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A
2
+ (a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for
3
+ "never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1."""
4
+ import numpy as np
5
+
6
+ from run import Invalid, int_list
7
+
8
+
9
+ def _primes(n):
10
+ s = np.ones(n + 1, dtype=bool)
11
+ s[:2] = False
12
+ for i in range(2, int(n ** .5) + 1):
13
+ if s[i]:
14
+ s[i * i::i] = False
15
+ return np.nonzero(s)[0]
16
+
17
+
18
+ def check(inst, ans):
19
+ n, t = inst["N"], inst["t"]
20
+ a = ans.get("A")
21
+ if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20):
22
+ raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers")
23
+ int_list(a, None, 1, n, "A")
24
+ if len(set(a)) != len(a):
25
+ raise Invalid("A must consist of distinct integers")
26
+ x = np.array(sorted(a), dtype=np.int64)
27
+ iu, ju = np.triu_indices(len(x))
28
+ va, vb = x[iu], x[ju]
29
+ left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet
30
+ for p in _primes(int((n * n + 1) ** .5) + 1):
31
+ q = int(p) * int(p)
32
+ idx = np.nonzero(left)[0]
33
+ hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0
34
+ left[idx[hit]] = False
35
+ if not left.any():
36
+ return None, {"size": len(a)}
37
+ k = int(np.nonzero(left)[0][0])
38
+ raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree")
tasks/construct-ae-p52-erdos-squarefree-l3-s0/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 718, "t": 29, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
tasks/construct-ae-p52-erdos-squarefree-l3-s0/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-ae-p52-erdos-squarefree-l3-s0/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-ae-p52-erdos-squarefree-l3-s7/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-ae-p52-erdos-squarefree-l3-s7/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 1212, "t": 49, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
tasks/construct-ae-p52-erdos-squarefree-l3-s7/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682, 707, 732, 757, 782, 807, 832, 857, 882, 907, 932, 957, 982, 1007, 1032, 1057, 1082, 1107, 1132, 1157, 1182, 1207]}
5
+ RLMATH_EOF
tasks/construct-ae-p52-erdos-squarefree-l3-s7/tests/check.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A
2
+ (a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for
3
+ "never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1."""
4
+ import numpy as np
5
+
6
+ from run import Invalid, int_list
7
+
8
+
9
+ def _primes(n):
10
+ s = np.ones(n + 1, dtype=bool)
11
+ s[:2] = False
12
+ for i in range(2, int(n ** .5) + 1):
13
+ if s[i]:
14
+ s[i * i::i] = False
15
+ return np.nonzero(s)[0]
16
+
17
+
18
+ def check(inst, ans):
19
+ n, t = inst["N"], inst["t"]
20
+ a = ans.get("A")
21
+ if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20):
22
+ raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers")
23
+ int_list(a, None, 1, n, "A")
24
+ if len(set(a)) != len(a):
25
+ raise Invalid("A must consist of distinct integers")
26
+ x = np.array(sorted(a), dtype=np.int64)
27
+ iu, ju = np.triu_indices(len(x))
28
+ va, vb = x[iu], x[ju]
29
+ left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet
30
+ for p in _primes(int((n * n + 1) ** .5) + 1):
31
+ q = int(p) * int(p)
32
+ idx = np.nonzero(left)[0]
33
+ hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0
34
+ left[idx[hit]] = False
35
+ if not left.any():
36
+ return None, {"size": len(a)}
37
+ k = int(np.nonzero(left)[0][0])
38
+ raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree")
tasks/construct-ae-p52-erdos-squarefree-l3-s7/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 1212, "t": 49, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
tasks/construct-ae-p52-erdos-squarefree-l3-s7/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-ae-p52-erdos-squarefree-l3-s7/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-ae-p52-erdos-squarefree-l3-s9/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-ae-p52-erdos-squarefree-l3-s9/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 694, "t": 28, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
tasks/construct-ae-p52-erdos-squarefree-l3-s9/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682]}
5
+ RLMATH_EOF
tasks/construct-ae-p52-erdos-squarefree-l3-s9/tests/check.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A
2
+ (a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for
3
+ "never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1."""
4
+ import numpy as np
5
+
6
+ from run import Invalid, int_list
7
+
8
+
9
+ def _primes(n):
10
+ s = np.ones(n + 1, dtype=bool)
11
+ s[:2] = False
12
+ for i in range(2, int(n ** .5) + 1):
13
+ if s[i]:
14
+ s[i * i::i] = False
15
+ return np.nonzero(s)[0]
16
+
17
+
18
+ def check(inst, ans):
19
+ n, t = inst["N"], inst["t"]
20
+ a = ans.get("A")
21
+ if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20):
22
+ raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers")
23
+ int_list(a, None, 1, n, "A")
24
+ if len(set(a)) != len(a):
25
+ raise Invalid("A must consist of distinct integers")
26
+ x = np.array(sorted(a), dtype=np.int64)
27
+ iu, ju = np.triu_indices(len(x))
28
+ va, vb = x[iu], x[ju]
29
+ left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet
30
+ for p in _primes(int((n * n + 1) ** .5) + 1):
31
+ q = int(p) * int(p)
32
+ idx = np.nonzero(left)[0]
33
+ hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0
34
+ left[idx[hit]] = False
35
+ if not left.any():
36
+ return None, {"size": len(a)}
37
+ k = int(np.nonzero(left)[0][0])
38
+ raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree")
tasks/construct-ae-p52-erdos-squarefree-l3-s9/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 694, "t": 28, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
tasks/construct-ae-p52-erdos-squarefree-l3-s9/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-ae-p52-erdos-squarefree-l3-s9/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 225, "max_tiles": 252, "family": "ae_p65_imo2025_p6_tiling", "subset": "construct"}
tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"tiles": [[0, 0, 15, 14], [0, 15, 1, 210], [1, 14, 15, 15], [1, 30, 1, 195], [2, 29, 15, 15], [2, 45, 1, 180], [3, 44, 15, 15], [3, 60, 1, 165], [4, 59, 15, 15], [4, 75, 1, 150], [5, 74, 15, 15], [5, 90, 1, 135], [6, 89, 15, 15], [6, 105, 1, 120], [7, 104, 15, 15], [7, 120, 1, 105], [8, 119, 15, 15], [8, 135, 1, 90], [9, 134, 15, 15], [9, 150, 1, 75], [10, 149, 15, 15], [10, 165, 1, 60], [11, 164, 15, 15], [11, 180, 1, 45], [12, 179, 15, 15], [12, 195, 1, 30], [13, 194, 15, 15], [13, 210, 1, 15], [14, 209, 15, 15], [15, 0, 15, 13], [15, 224, 210, 1], [16, 13, 15, 15], [17, 28, 15, 15], [18, 43, 15, 15], [19, 58, 15, 15], [20, 73, 15, 15], [21, 88, 15, 15], [22, 103, 15, 15], [23, 118, 15, 15], [24, 133, 15, 15], [25, 148, 15, 15], [26, 163, 15, 15], [27, 178, 15, 15], [28, 193, 15, 15], [29, 208, 15, 15], [30, 0, 15, 12], [30, 223, 195, 1], [31, 12, 15, 15], [32, 27, 15, 15], [33, 42, 15, 15], [34, 57, 15, 15], [35, 72, 15, 15], [36, 87, 15, 15], [37, 102, 15, 15], [38, 117, 15, 15], [39, 132, 15, 15], [40, 147, 15, 15], [41, 162, 15, 15], [42, 177, 15, 15], [43, 192, 15, 15], [44, 207, 15, 15], [45, 0, 15, 11], [45, 222, 180, 1], [46, 11, 15, 15], [47, 26, 15, 15], [48, 41, 15, 15], [49, 56, 15, 15], [50, 71, 15, 15], [51, 86, 15, 15], [52, 101, 15, 15], [53, 116, 15, 15], [54, 131, 15, 15], [55, 146, 15, 15], [56, 161, 15, 15], [57, 176, 15, 15], [58, 191, 15, 15], [59, 206, 15, 15], [60, 0, 15, 10], [60, 221, 165, 1], [61, 10, 15, 15], [62, 25, 15, 15], [63, 40, 15, 15], [64, 55, 15, 15], [65, 70, 15, 15], [66, 85, 15, 15], [67, 100, 15, 15], [68, 115, 15, 15], [69, 130, 15, 15], [70, 145, 15, 15], [71, 160, 15, 15], [72, 175, 15, 15], [73, 190, 15, 15], [74, 205, 15, 15], [75, 0, 15, 9], [75, 220, 150, 1], [76, 9, 15, 15], [77, 24, 15, 15], [78, 39, 15, 15], [79, 54, 15, 15], [80, 69, 15, 15], [81, 84, 15, 15], [82, 99, 15, 15], [83, 114, 15, 15], [84, 129, 15, 15], [85, 144, 15, 15], [86, 159, 15, 15], [87, 174, 15, 15], [88, 189, 15, 15], [89, 204, 15, 15], [90, 0, 15, 8], [90, 219, 135, 1], [91, 8, 15, 15], [92, 23, 15, 15], [93, 38, 15, 15], [94, 53, 15, 15], [95, 68, 15, 15], [96, 83, 15, 15], [97, 98, 15, 15], [98, 113, 15, 15], [99, 128, 15, 15], [100, 143, 15, 15], [101, 158, 15, 15], [102, 173, 15, 15], [103, 188, 15, 15], [104, 203, 15, 15], [105, 0, 15, 7], [105, 218, 120, 1], [106, 7, 15, 15], [107, 22, 15, 15], [108, 37, 15, 15], [109, 52, 15, 15], [110, 67, 15, 15], [111, 82, 15, 15], [112, 97, 15, 15], [113, 112, 15, 15], [114, 127, 15, 15], [115, 142, 15, 15], [116, 157, 15, 15], [117, 172, 15, 15], [118, 187, 15, 15], [119, 202, 15, 15], [120, 0, 15, 6], [120, 217, 105, 1], [121, 6, 15, 15], [122, 21, 15, 15], [123, 36, 15, 15], [124, 51, 15, 15], [125, 66, 15, 15], [126, 81, 15, 15], [127, 96, 15, 15], [128, 111, 15, 15], [129, 126, 15, 15], [130, 141, 15, 15], [131, 156, 15, 15], [132, 171, 15, 15], [133, 186, 15, 15], [134, 201, 15, 15], [135, 0, 15, 5], [135, 216, 90, 1], [136, 5, 15, 15], [137, 20, 15, 15], [138, 35, 15, 15], [139, 50, 15, 15], [140, 65, 15, 15], [141, 80, 15, 15], [142, 95, 15, 15], [143, 110, 15, 15], [144, 125, 15, 15], [145, 140, 15, 15], [146, 155, 15, 15], [147, 170, 15, 15], [148, 185, 15, 15], [149, 200, 15, 15], [150, 0, 15, 4], [150, 215, 75, 1], [151, 4, 15, 15], [152, 19, 15, 15], [153, 34, 15, 15], [154, 49, 15, 15], [155, 64, 15, 15], [156, 79, 15, 15], [157, 94, 15, 15], [158, 109, 15, 15], [159, 124, 15, 15], [160, 139, 15, 15], [161, 154, 15, 15], [162, 169, 15, 15], [163, 184, 15, 15], [164, 199, 15, 15], [165, 0, 15, 3], [165, 214, 60, 1], [166, 3, 15, 15], [167, 18, 15, 15], [168, 33, 15, 15], [169, 48, 15, 15], [170, 63, 15, 15], [171, 78, 15, 15], [172, 93, 15, 15], [173, 108, 15, 15], [174, 123, 15, 15], [175, 138, 15, 15], [176, 153, 15, 15], [177, 168, 15, 15], [178, 183, 15, 15], [179, 198, 15, 15], [180, 0, 15, 2], [180, 213, 45, 1], [181, 2, 15, 15], [182, 17, 15, 15], [183, 32, 15, 15], [184, 47, 15, 15], [185, 62, 15, 15], [186, 77, 15, 15], [187, 92, 15, 15], [188, 107, 15, 15], [189, 122, 15, 15], [190, 137, 15, 15], [191, 152, 15, 15], [192, 167, 15, 15], [193, 182, 15, 15], [194, 197, 15, 15], [195, 0, 15, 1], [195, 212, 30, 1], [196, 1, 15, 15], [197, 16, 15, 15], [198, 31, 15, 15], [199, 46, 15, 15], [200, 61, 15, 15], [201, 76, 15, 15], [202, 91, 15, 15], [203, 106, 15, 15], [204, 121, 15, 15], [205, 136, 15, 15], [206, 151, 15, 15], [207, 166, 15, 15], [208, 181, 15, 15], [209, 196, 15, 15], [210, 211, 15, 1], [211, 0, 14, 15], [212, 15, 13, 15], [213, 30, 12, 15], [214, 45, 11, 15], [215, 60, 10, 15], [216, 75, 9, 15], [217, 90, 8, 15], [218, 105, 7, 15], [219, 120, 6, 15], [220, 135, 5, 15], [221, 150, 4, 15], [222, 165, 3, 15], [223, 180, 2, 15], [224, 195, 1, 15]]}
5
+ RLMATH_EOF
tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/tests/check.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """IMO 2025 Problem 6 variant (AlphaEvolve problem 65): at most T rectangular tiles on an n x n grid, no overlaps,
2
+ every row and every column has exactly one uncovered unit square."""
3
+ import numpy as np
4
+
5
+ from run import Invalid, int_list
6
+
7
+
8
+ def check(inst, ans):
9
+ n, cap = inst["n"], inst["max_tiles"]
10
+ tiles = ans.get("tiles")
11
+ if not isinstance(tiles, list) or not (1 <= len(tiles) <= cap):
12
+ raise Invalid(f"tiles must be a list of 1..{cap} [row, col, height, width] entries")
13
+ cover = np.zeros((n, n), dtype=np.int32)
14
+ for t in tiles:
15
+ r, c, h, w = int_list(t, 4, 0, n, "tile")
16
+ if h < 1 or w < 1 or r + h > n or c + w > n:
17
+ raise Invalid(f"tile {t} is empty or leaves the grid")
18
+ cover[r:r + h, c:c + w] += 1
19
+ if cover.max() > 1:
20
+ raise Invalid("tiles overlap")
21
+ free = cover == 0
22
+ if not (free.sum(axis=1) == 1).all() or not (free.sum(axis=0) == 1).all():
23
+ raise Invalid("some row or column does not have exactly one uncovered square")
24
+ return None, {"tiles": len(tiles)}
tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 225, "max_tiles": 252, "family": "ae_p65_imo2025_p6_tiling", "subset": "construct"}
tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-ae-p65-imo2025-p6-tiling-l4-s0/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-mc-all-interval-l3-s2/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-mc-all-interval-l3-s2/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 12, "fixed": [], "family": "mc_all_interval", "subset": "construct"}
tasks/construct-mc-all-interval-l3-s2/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"x": [0, 11, 1, 10, 2, 9, 3, 8, 4, 7, 5, 6]}
5
+ RLMATH_EOF
tasks/construct-mc-all-interval-l3-s2/tests/check.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series."""
2
+ from run import Invalid, int_list
3
+
4
+
5
+ def check(inst, ans):
6
+ n = inst["n"]
7
+ x = int_list(ans.get("x"), n, 0, n - 1, "x")
8
+ if sorted(x) != list(range(n)):
9
+ raise Invalid("x is not a permutation of 0..n-1")
10
+ d = [abs(x[i + 1] - x[i]) for i in range(n - 1)]
11
+ if sorted(d) != list(range(1, n)):
12
+ raise Invalid("consecutive differences are not a permutation of 1..n-1")
13
+ seqs = {"x": x, "d": d}
14
+ for name, i, v in inst.get("fixed", []):
15
+ if seqs[name][i] != v:
16
+ raise Invalid(f"fixed value {name}[{i}] = {v} not respected")
17
+ return None, {}
tasks/construct-mc-all-interval-l3-s2/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 12, "fixed": [], "family": "mc_all_interval", "subset": "construct"}
tasks/construct-mc-all-interval-l3-s2/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-mc-all-interval-l3-s2/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-mc-antimagic-square-l3-s0/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json