Author SHA1 Message Date
paultal 5641d89b27 Merge remote-tracking branch 'origin/main' into issue-2-equation-lhs 2026-11-27 01:29:30 +02:00
paultal bce9647990 Generate equations with long left sides
Eq left sides were only y, f, x or a depth-0/1 expression, so x^2 + y^2 = r^2
never appeared in training and the model dropped everything after "=".
Left sides are now a single variable (35%), a flat sum of 2-3 textbook terms
like x^2, 3 x, sin(x)^2 (30%), or a random expression up to depth 3 (35%).
The overall length limit still applies.

The hand-test sentences for this live with the eval changes in #3.

Fixes #2
2026-11-27 01:22:36 +02:00
3 changed files with 4 additions and 50 deletions

No files matched your search

+1 -8
View File
@@ -106,14 +106,7 @@ class Eq(Node):
right: Node right: Node
# lowercase Greek letters usable as variables; pi is a constant, and omicron is left out because it looks like o GREEK = ["alpha", "beta", "gamma", "delta", "theta", "lambda", "mu", "sigma", "phi", "omega"]
GREEK = [
"alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota", "kappa", "lambda", "mu",
"nu", "xi", "rho", "sigma", "tau", "upsilon", "phi", "chi", "psi", "omega",
] # fmt: skip
# e is a constant (e^x), and d is kept free for "dx" and later derivatives (#8)
LATIN = [c for c in "abcdefghijklmnopqrstuvwxyz" if c not in "de"]
UPPER = list("ABCFGHKLMNPQRSTVXY")
FUNCS = ["sin", "cos", "tan", "ln", "log", "exp"] FUNCS = ["sin", "cos", "tan", "ln", "log", "exp"]
BIG_OPS = (Integral, Sum, Lim) BIG_OPS = (Integral, Sum, Lim)
+3 -30
View File
@@ -16,28 +16,7 @@ import pathlib
import random import random
from typing import ClassVar from typing import ClassVar
from .ast import ( from .ast import FUNCS, GREEK, Add, Eq, Frac, Func, Integral, Lim, Mul, Neg, Node, Num, Pow, Sqrt, Sub, Sum, Var, walk
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 .render import to_english, to_typst
from .validate import compiles_many from .validate import compiles_many
@@ -52,14 +31,8 @@ class TreeGen:
def var(self, prefer: str | None = None) -> Var: def var(self, prefer: str | None = None) -> Var:
if prefer and self.rng.random() < 0.6: # inside "integral ... dx", mostly use x if prefer and self.rng.random() < 0.6: # inside "integral ... dx", mostly use x
return Var(prefer) return Var(prefer)
r = self.rng.random() pool = ["x"] * 12 + ["y"] * 4 + ["z", "t", "a", "b", "c", "n", "k", "u", "r", "s", "m", "p"] + GREEK
if r < 0.45: # x and y stay the most common, as in real maths return Var(self.rng.choice(pool))
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: def num(self) -> Num:
r = self.rng.random() r = self.rng.random()
-12
View File
@@ -1,12 +0,0 @@
import random
from isotope_typst.ast import GREEK, LATIN, UPPER
from isotope_typst.generate import TreeGen
def test_variable_pool_covers_alphabet():
"""#4: any letter the model never saw gets spelled out letter by letter, so all of them must show up."""
gen = TreeGen(random.Random(0))
seen = {gen.var().name for _ in range(20000)}
assert set(LATIN) | set(GREEK) | set(UPPER) <= seen
assert "d" not in seen and "e" not in seen