Renaissance Labs · Mathematics
11Number theory

Definitions from words

definitions

Turn a number-theoretic definition written in words into a computable Lean function that agrees with it on hidden inputs.

What the agent does

The agent gets a working directory with a Lean file, Solution.lean, and a problem in words. It edits the file until it compiles and is correct. Tasks are generated from a seed and a difficulty from 1 to 3, so the supply is unlimited and every task is new.

An example task

Instruction, as the agent sees it

Define a function from its description

Define the function ff from the natural numbers (including 0) to the natural numbers as follows.

f(n)f(n) is the number of positive divisors dd of nn such that the decimal digits of dd read the same forwards and backwards. Take f(0)=0f(0) = 0.

What to do

Solution.lean in the working directory declares f with sorry as its body. Replace each sorry with a definition that matches the description above.

  • Keep the name and the type exactly as given. You may add helper definitions.
  • The definition must be computable: it is checked by running it on hidden inputs, so do not use noncomputable or classical choice.
  • Check that the file compiles with lake env lean Solution.lean (run it inside /opt/arena/lean, giving the full path to the file), and test your definition with #eval.
  • The reward is 1 if the definition agrees with the description on every hidden input, and 0 otherwise.
Examples
  • f(3)=2f(3) = 2
  • f(10)=3f(10) = 3
  • f(17)=1f(17) = 1
  • f(24)=6f(24) = 6
Solution.leanthe file the agent starts from
import Mathlib

def f (n : ℕ) : ℕ := sorry
Show a reference solution
import Mathlib

def f (n : ℕ) : ℕ := ((Nat.divisors n).filter (fun d => Nat.digits 10 d = (Nat.digits 10 d).reverse)).card

Reference solutions are never shown to the agent. They are compiled in the environment's self-test, so every task has at least one proof that passes.

The families

Each task belongs to one family: a different piece of the area's work.

count

f(n)f(n) is the number of integers kk with 1≤k≤n1 \le k \le n such that kk leaves remainder 6 on division by 7 or kk is prime (or both).

divisors

f(n)f(n) is the sum of the values τ(d)\tau(d), where τ(m)\tau(m) is the number of positive divisors of mm, over all positive divisors dd of nn such that dd is divisible by 3. An empty sum is 0, and f(0)=0f(0) = 0.

extremum

f(n)f(n) is the largest integer kk with 1≤k≤n1 \le k \le n such that kk is divisible by 2 or kk is coprime to 12 (or both). If there is no such kk, then f(n)=0f(n) = 0.

pairs

f(n)f(n) is the number of ordered pairs (a,b)(a, b) of integers with 1≤a≤n1 \le a \le n and 1≤b≤n1 \le b \le n such that a+ba + b is divisible by 3 and a<ba < b.

sequence

Let a(0)=0a(0) = 0, a(1)=1a(1) = 1 and, for n≥0n \ge 0, let a(n+2)a(n+2) be the remainder of 2 a(n+1)+3 a(n)+12\,a(n+1) + 3\,a(n) + 1 on division by 100. Then f(n)=a(0)+a(1)+⋯+a(n)f(n) = a(0) + a(1) + \dots + a(n).

sum

f(n)f(n) is the sum of k2k^2 over all integers kk with 1≤k≤n1 \le k \le n such that the decimal digits of kk read the same forwards and backwards. An empty sum is 0.

Reward

Range
0 to 1
Checked by
Lean kernel
Deterministic
yes

Your definition is run on hidden inputs: the grader proves a statement about f by evaluation and compares with the reference values. The reward is 1 if every value agrees, 0 otherwise. A file that does not compile scores 0. The submission is also re-checked by a second kernel run. Read how checking works.

How to run it

1. Set up the Lean projectLean 4.29.1 with Mathlib 5e932f97dd
git clone https://github.com/RenaissanceLabs-EU/lean-arena && cd lean-arena
cd lean && lake exe cache get
2. Generate a taskseed and difficulty pick the task
python3 tools/make_task.py definitions --seed 7 --difficulty 2 --out /tmp/task
3. Grade a solutionprints the reward
python3 arena/grade.py --spec /tmp/task/spec.json --solution /tmp/task/Solution.lean

Tasks are also exported as Harbor task folders (instruction.md, task.toml, tests/), the format used by several RL frameworks, with the image built from the Lean project.

Good for

  • autoformalization
  • reading a specification exactly
  • boundary cases