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
Define a function from its description
Define the function from the natural numbers (including 0) to the natural numbers as follows.
is the number of positive divisors of such that the decimal digits of read the same forwards and backwards. Take .
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
noncomputableor 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
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 | is the number of integers with such that leaves remainder 6 on division by 7 or is prime (or both). |
| divisors | is the sum of the values , where is the number of positive divisors of , over all positive divisors of such that is divisible by 3. An empty sum is 0, and . |
| extremum | is the largest integer with such that is divisible by 2 or is coprime to 12 (or both). If there is no such , then . |
| pairs | is the number of ordered pairs of integers with and such that is divisible by 3 and . |
| sequence | Let , and, for , let be the remainder of on division by 100. Then . |
| sum | is the sum of over all integers with such that the decimal digits of 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
git clone https://github.com/RenaissanceLabs-EU/lean-arena && cd lean-arena cd lean && lake exe cache get
python3 tools/make_task.py definitions --seed 7 --difficulty 2 --out /tmp/task
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
