# Mental Math — rules and recipes > Reference and cookbook for authoring mental-math rules and recipes: the rule expression language, the canonical rule catalog, and how recipes turn rules into generated exercises. A rule is one expression deciding whether a candidate value is allowed at a step. A recipe collects rules, gives each a job, and generates concrete exercises from them. ## Pages - [Mental Math rules and recipes](/): Start here — what a rule is, what a recipe is, and where to go depending on whether you are writing an expression or configuring an exercise generator. - [What is a rule?](/guide/what-is-a-rule): A rule is one expression that decides whether a candidate value is allowed at a step, evaluating to Passed, Failed, or Skipped. - [Your first rule](/guide/getting-started): Write a working rule expression, and learn the two top-level forms a rule can take — a plain condition and a guarded IF…THEN. - [Variables](/guide/variables): The six base variables automatically in scope when a rule is evaluated — prev_sum, current_value, current_sum, step_index, last_step_index, and isLastStep. - [Operators](/guide/operators): Comparison and arithmetic operators, the AND/OR/NOT combinators and their precedence, guarded IF…THEN rules, and IN / NOT IN membership tests. - [Decimal places](/guide/decimal-places): How place, formula and digitBefore let one expression describe a technique at every decimal place at once — and what happens when a value touches more than one place. - [Digit functions](/guide/digit-functions): The five built-in functions — digits, highest_digit, lowest_digit, number_of_digits and digitAt — that let a rule inspect the individual digits of a number. - [Quantifiers](/guide/quantifiers): EVERY and SOME apply a condition to each digit of a number, and the ALL_DIGITS / SOME_DIGITS shorthands cover the most common shape of that. - [Common patterns](/guide/patterns): A lookup table of ready-made rule expressions for the constraints authors ask for most often, grouped by what they constrain. - [Common mistakes](/guide/mistakes): The syntax traps that catch new rule authors most often, each with the wrong form and the right one side by side. - [Context variables](/reference/context): Exact definitions and evaluation semantics for every variable in scope when a rule is evaluated, including the null contract for place, formula and digitBefore. - [Built-in functions](/reference/functions): Complete reference for the five built-in functions available in rule expressions, with argument counts, return types and worked examples. - [Language reference](/reference/language): Formal reference for the rule expression language — top-level forms, operator precedence, keywords, literal and identifier syntax, and what the grammar does not accept. - [Rule Catalog](/reference/rule-catalog): Every canonical mental-math rule with its exact expression — Rule 5, Rule 10, Combo, Plain, the global constraint rules, and the consolidated "(any)" family rules. - [Recipe concepts](/recipes/concepts): What a recipe is, how it attaches rules through RecipeRule, the five usage categories, count quotas, minStepsCount, and sumMax. - [Sum range](/recipes/sum-range): sumMax as the inclusive running-sum ceiling with a hard floor of 0, why it is a recipe field rather than a rule, and how to confine sums to a narrower window. - [Restricting places](/recipes/places): How to limit which decimal places a recipe's steps may touch, restrict operands to a specific set, condition on digitBefore, and pin the opening value. - [Multi-place combo steps](/recipes/combo-steps): How place-channels let a recipe generate steps that move several decimal places at once, such as +47 or -89, by curating each place independently. - [Worked examples](/recipes/cookbook): Complete, copy-pasteable recipe configurations — a single-technique recipe, a bounded-sum recipe, and two multi-place combo recipes. - [Troubleshooting](/recipes/troubleshooting): Diagnosing a recipe that will not generate — infeasibility, misspelled variables, place constraints on channel recipes, and the pattern-rule ceiling.