- Core contract:
ProblemGenerator.generate() -> dict(inbase_generator.py) returnsproblem_id,operation, human-readableproblem,steps(list of pipe-delimited op-code strings), andfinal_answer. The last step must be exactlyZ|<final_answer>. The pipeline then stampsgrade_levelanddifficultyfromcurriculum.py(generator-emitted values win). - Generators: One class per skill in
generators/(e.g.,long_division_generator.py). Each is independent, seeded viarandominquixi_math_datagen.py, and responsible for validating its own outputs before returning. - Data flow:
quixi_math_datagen.pyseeds RNG, samples a skill (equal weight per class by default,--weightsto override) then an instance within it, callsgenerate(), stamps metadata, runsvalidate_example(), dedups on(operation, problem), then writes JSONL viawrite_jsonl.--sampleprints one example per generator;-n/-o/-sbuilds datasets. - Step encoding: Steps are pipe-delimited strings built with
helpers.step()andDELIM="|". Opcodes capture atomic reasoning moves (divide, multiply, bring-down, etc.) and end withZholding the formatted answer string. - Extensibility: To add a skill, create a new generator implementing
ProblemGenerator, emit well-formed steps (includingZ|), add it toALL_GENERATORSinquixi_math_datagen.py, add acurriculum.CURRICULUMentry, regenerateOPCODES.md, and mirror tests intests/.
- Philosophy: the scratchpad ultimately belongs to the model — it may invent its own op-codes. The op-code vocabulary is therefore organic: no fixed registry, no vocabulary enforcement.
OPCODES.mdis a generated, descriptive legend (tools/gen_opcode_legend.py, AST-scan ofstep()call sites plus sampled examples). One rule of hygiene is enforced socially, not mechanically: one op-code = one meaning (don't reuse an existing code with different field semantics). - Validation (
validate_example): structure only — required keys, non-emptystepsof non-empty strings, op-code present, at most 4 payload fields per step, final stepZ|<final_answer>(string-coerced),grade_levelin {elementary, middle, high, college, graduate},difficultyan int in 1–5 (read relative to the band). - Metadata:
curriculum.pymaps every registered class tograde_level/difficulty;stamp_metadata()fills the keys post-generate()with setdefault semantics so generators can override per-instance. Test-enforced invariant: everyALL_GENERATORSclass has a valid entry. - Sampling: instances group into skills by class name; each skill draws with equal probability (or its
--weightsoverride), then one instance uniformly within the skill.MixedNumberOperationsRandomis excluded from the default pool as a duplicate of the fourMixedNumberOperationGeneratorvariants. - Dedup & budget: exact
(operation, problem)repeats are skipped (unless--allow-duplicates); the attempt budget isn*10 + 1000with an early stop aftermax(2000, n)consecutive rejects (exhausted problem space). A per-generator stats table (emitted / duplicates skipped / errors) prints after every build, andbuild_datasetreturns the same summary programmatically. - Reproducibility: with
-s/--seed, builds are byte-for-byte deterministic (helpers.jid()draws UUIDs from the seededrandommodule); without a seed, natural randomness.
Validation requires steps[-1] == "Z|" + final_answer exactly, and RL graders
need one canonical form. These conventions are the contract; extend this
section (don't fork it) when a new tier introduces new answer shapes.
- Integers: plain:
-4,366 R4(division with remainder). - Money:
$20.06— dollar sign, two decimals, cents always exact. - Percentages:
15%. - Fractions: lowest terms,
5/2; mixed numbers space-separated8 1/2; final answers in mixed-number contexts convert improper → mixed. - Decimals: exact only, minimal digits (
11.4, not11.40). - π-forms: coefficient then π then unit:
36π cubic units; fractional coefficient keeps π before the slash's denominator:500π/3 cubic units. - Units: appended when the problem has them:
cubic units,square units. - Powers:
x^5; negative exponents rewritten:1/x^3; fraction bases reciprocal-flipped:(3/2)^2; exponent 1 and 0 simplified away (x,1). - Single solutions: bare value
7. Inequalities:x ≤ 9(relation symbols < > ≤ ≥). Systems:x=-2, y=-3. Special solutions:No solution,All real numbers. - Interval notation: use
(-∞, -3) ∪ [2, 5)with reduced rational endpoints; infinities are always open and excluded points such as rational function poles stay open even when the inequality is non-strict. - Asymptotic bounds: use
Θ(...)with a composite method/case label when the label is part of the skill, e.g.case 1; Θ(n^2)orsubtract; Θ(n^5). - Factored forms (Algebra 1 tier): ASCII signs inside factors,
GCF first, binomial factors ordered by ascending constant term:
3(x - 4)(x + 2). - Multiple roots: ascending, joined with " or ":
x = -3 or x = 2. - Radicals: coefficient then radical
6√2; variables inside the radical parenthesized when compound:5x√(2x); denominators rationalized. - Expressions: terms in descending power order:
2x^2 + 3x - 5.
CHECK|method|lhs_work|rhs_work— two independent routes to the same value; the two work strings MUST agree. Methods so far:cross_products,split,tip_two_ways,substitute,boundary_equality,multiply_back. Emitted on roughly half of examples (both habits — with and without an explicit check — should appear in training).CHECK_POINT|point|lhs_work|rhs_work— evaluate both sides at a test point; agreement NOT required (a contradiction's check point deliberately disagrees; an identity's check points agree).TRY|candidate|test_work/REJECT|candidate|reason/ACCEPT|candidate|confirmation(A2, reserved) — candidate testing for factoring, rational-root search, and radical simplification. Real scratchpads contain dead ends; emit the tried-and-rejected candidates, not just the winner.
Format decision: no schema change. A given (worked or partial)
scratchpad embeds in the problem text as numbered lines in the normal
pipe dialect — the model reads its own step language as input. The output
is ordinary steps. Step fields never contain pipes: given lines are
referenced by their 1-indexed number.
- Error-spotting (
error_spotting_*operations): the problem shows a worked solution with exactly one arithmetic mistake; every given line after the mistake is consistent with it (real erring-student work — the error propagates). Output:VERIFY|k|oksweeps each given line in order;FLAG|k|<true arithmetic, pipe-free>marks the wrong line; then the work is REDONE from line k in ordinary op-codes (lines after k are implicitly invalidated), ending with a CHECK where natural andZ.final_answeris composite (Principle 8):step <k>; <correct answer>— re-solving without locating the error earns nothing. - Fill-in-the-missing-step: one given line is replaced by
____;final_answeris the missing step verbatim (pipe format). - Estimate-then-compute: not a new record shape — a variant where steps
open with
ESTIMATE|<rounding work>|<estimate>and close withESTIMATE_CHECK|<estimate>|<exact>|<verdict>beforeZ. (Its own code, notCHECK: an estimate and the exact value agree only approximately, andCHECK's contract requires exact agreement.)
- Long Division: Integers 2–99 divisors; includes bring-down (
B), divide (D), multiply (M), subtract (S), remainder (R), and finalZ. - Multi-digit Addition (integers): Column alignment (
INT_ALIGN), per-column sums with carry (ADD_COL), final carry (CARRY_FINAL), and finalZ. - Multi-digit Subtraction (integers): Column alignment (
INT_ALIGN), per-column differences with borrow (SUB_COL), explicit borrow steps (BORROW), finalZ. - Multi-digit Multiplication (integers): Multiplication setup (
MUL_SETUP), digit-by-digit partials (MUL_PARTIAL), summing partials (ADD_PARTIALS), finalZ. - *Mixed Number Operations (+, -, , /): Convert to improper (
MIX_IMPROPER), align denominators (L,C), invert for division (I), operate on numerators (A/S/M), simplify (F), convert back to mixed (IMPROPER_TO_MIX), finalZ. - Fraction Comparison: LCD (
L,C), compare converted fractions (CMP), finalZ. - Fraction/Decimal/Percent Conversions: Conversions across forms (
FRAC_TO_DEC,DEC_TO_FRAC,PERCENT_TO_DEC,DEC_TO_PERCENT), simplify where needed, finalZ. - Factors & Multiples: Factor listing via trial division (
FACT_CHECK,FACT_PAIR), prime factorization via repeated division (PF_STEP,PF_PRIME), GCF via Euclid (GCD_START,GCD_STEP,GCD_RESULT), LCM via product/gcd (LCM_FROM_GCD), finalZ. - Order of Operations: Precedence steps with arithmetic ops and rewrites (
REWRITE), finalZ. - Geometry (Perimeter/Area/Volume): Compute perimeters (
PERIM), areas (AREA), and volumes (VOLUMEfor rectangular prisms) using explicit arithmetic steps and rewrites where needed, finalZ. - Place Value & Rounding / Number Comparison: Digit inspection (
ROUND_CHECK), rounded result (ROUND_RESULT), alignment/comparison (ALIGN_NUM,CMP_NUM), finalZ. - Divisibility & Classification: Divisibility checks (
DIV_CHECK), prime/composite markers (PRIME,COMPOSITE_FACTOR), finalZ. - Unit Conversions: Factor-label conversion (
CONV_FACTOR,CONV_RESULT), explicit multiply, finalZ. - Basic Data/Statistics/Probability: Sort (
SORT), arithmetic sums/divides for mean (MEAN_DIV), median selection (MEDIAN_PICK/MEDIAN_PAIR), mode counting (MODE_COUNT/MODE), simple probability setup (PROB_SETUP) with division/simplify, finalZ. - Decimal Multiplication: Partial products (
MUL_PARTIAL), decimal placement (COUNT_DP,PLACE_DP), partial sums (ADD_PARTIALS). - Decimal Addition/Subtraction: Column alignment (
DEC_ALIGN), column operations (DEC_ADD_COL,DEC_SUB_COL), carries (DEC_CARRY_FINAL), finalZ. - Decimal Division: Decimal shifting (
DEC_SHIFT), setup (DIV_SETUP), quotient decimal placement (PLACE_DP_Q), reuse ofB/D/M/S. - *Fraction Operations (+, -, , /): LCD and conversions (
L,C), simplification (F), inversion (I), arithmetic (A,M,D,Sreused contextually), finalZ. - Linear Equations (Simple/Complex): Move terms (
MOVE_TERM), combine like terms (COMB_X,COMB_CONST), divide coefficients (DIV_COEFF), rewrite (REWRITE), finalZ. - Quadratic Equations: Discriminant (
DISC), root extraction (ROOT), quadratic formula branches (Q1,Q2), finalZ. - Simplify Algebraic Expressions: Distribution (
DIST), combining terms, rewrites, finalZ. - Evaluate Expressions: Substitution (
SUBST), arithmetic steps as needed, finalZ. - Proportional Relationships: Proportion setup (
PROP_SETUP), solving via algebraic steps, finalZ. - Pythagorean Hypotenuse: Exponents (
E), square root (ROOT), finalZ. - Percent Problems (find part/percent/whole): Percent-to-decimal (
PERCENT_TO_DEC), equation setup/rearrange (SETUP_PERCENT_EQ,REARRANGE_EQ), calculation (PERCENT_CALC_PART), convert back (DEC_TO_PERCENT), finalZ. - Abacus-Style Addition: Initial set (
AB_SET), informational notes (AB_INFO), column adds (AB_ADD_DGT), carry propagation (AB_CARRY,AB_CARRY_FINAL), finalZ. - Graph Interpretation (Bar/Line/Pictograph): Graph data recording (
GRAPH_DATA), value reading (GRAPH_READ), comparisons (CMP), min/max identification (GRAPH_MIN,GRAPH_MAX), change tracking (GRAPH_CHANGE,GRAPH_MAX_CHANGE), pictograph key (PICTO_KEY) and symbol counting (PICTO_COUNT), arithmetic steps reused (A,S,M), finalZ.