Use the whole alphabet and Greek alphabet for variables (#14)

Variables are now x/y (45%), any lowercase letter except e and d (35%), any lowercase Greek letter except pi and omicron (15%), or a common uppercase letter like N, F, A (5%). e stays a constant and d is kept for dx and future derivatives.

Hand-test exact 41.2% -> 56.9% (trained without #2), variables category 0% -> 87.5%.

Fixes #4

Co-authored-by: Paul Tal <[email protected]>
This commit was merged in pull request #14.
This commit is contained in:
paultal authored and paultal committed 2026-11-27 02:40:48 +02:00
1 parent c661773c30
commit 4fb7726e4b
3 files changed
+50 -4

No files matched your search

+30 -3
View File
@@ -16,7 +16,28 @@ import pathlib
import random
from typing import ClassVar
from .ast import FUNCS, GREEK, Add, Eq, Frac, Func, Integral, Lim, Mul, Neg, Node, Num, Pow, Sqrt, Sub, Sum, Var, walk
from .ast import (
FUNCS,
GREEK,
LATIN,
UPPER,
Add,
Eq,
Frac,
Func,
Integral,
Lim,
Mul,
Neg,
Node,
Num,
Pow,
Sqrt,
Sub,
Sum,
Var,
walk,
)
from .render import to_english, to_typst
from .validate import compiles_many
@@ -31,8 +52,14 @@ class TreeGen:
def var(self, prefer: str | None = None) -> Var:
if prefer and self.rng.random() < 0.6: # inside "integral ... dx", mostly use x
return Var(prefer)
pool = ["x"] * 12 + ["y"] * 4 + ["z", "t", "a", "b", "c", "n", "k", "u", "r", "s", "m", "p"] + GREEK
return Var(self.rng.choice(pool))
r = self.rng.random()
if r < 0.45: # x and y stay the most common, as in real maths
return Var("x" if r < 0.33 else "y")
if r < 0.80:
return Var(self.rng.choice(LATIN))
if r < 0.95:
return Var(self.rng.choice(GREEK))
return Var(self.rng.choice(UPPER))
def num(self) -> Num:
r = self.rng.random()