Create a new math lesson and update the math library (common/math/forge_math.h).
When to use this skill:
- You need math functionality that doesn't exist in
forge_math.hyet - A GPU lesson requires new math operations
- You want to teach a foundational math concept
Smart behavior:
- Before creating a lesson, check if the math already exists in
forge_math.h - If it exists, just document it better or create a lesson for existing code
- If creating from a GPU lesson's needs, extract only the math (not GPU-specific code)
Arguments
The user (or you) can provide:
- Number: two-digit lesson number (e.g. 01, 02)
- Concept name: kebab-case (e.g. vectors, matrices, quaternions)
- Description: what this teaches (e.g. "Vectors, dot product, normalization")
If any are missing, infer from context or ask.
Steps
1. Analyze what's needed
- Check
common/math/forge_math.h: Does this math already exist? - Check existing math lessons: Is there already a lesson for this?
- Identify the scope: What specific operations/concepts are needed?
2. Create the lesson directory
lessons/math/NN-concept-name/
3. Create a demo program (`main.c`)
A small, focused C program that demonstrates the math concept visually or numerically.
Requirements:
- Standalone — Can run without GPU (uses SDL for window/input if visual, or just printf if not)
- Clear output — Shows the math in action (visualization or printed results)
- Well-commented — Explains what's happening and why
- Uses the math library —
#include "math/forge_math.h"
Examples:
- Vectors: print dot products, show perpendicular/parallel cases
- Matrices: print a rotation matrix, show before/after transformation
- Visual: use SDL to draw vectors, show transformations in a window
Template structure:
/*
* Math Lesson NN — Concept Name
*
* Demonstrates: [what this shows]
*
* SPDX-License-Identifier: Zlib
*/
#include <SDL3/SDL.h>
#include "math/forge_math.h"
int main(int argc, char *argv[])
{
(void)argc;
(void)argv;
if (!SDL_Init(SDL_INIT_VIDEO)) {
SDL_Log("SDL_Init failed: %s", SDL_GetError());
return 1;
}
/* Demonstrate the math concept here */
SDL_Quit();
return 0;
}
Console output formatting:
- Use ASCII-only characters for console output (cross-platform compatibility)
- Avoid Unicode box-drawing, symbols, or special characters that may not render on Windows Terminal
- Good:
-,=,*,|,->,[OK],[!], "degrees", "in", "+/-" - Bad:
─,═,•,↓,→,✓,⚠,°,∈,±(may render as garbled text on Windows)
4. Create `CMakeLists.txt`
add_executable(NN-concept-name main.c)
target_include_directories(NN-concept-name PRIVATE ${FORGE_COMMON_DIR})
target_link_libraries(NN-concept-name PRIVATE SDL3::SDL3)
add_custom_command(TARGET NN-concept-name POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:SDL3::SDL3-shared>
$<TARGET_FILE_DIR:NN-concept-name>
)
5. Create `README.md`
Structure:
# Math Lesson NN — Concept Name
[Brief subtitle explaining what this teaches]
## What you'll learn
[Bullet list of math concepts covered]
## Key concepts
[Bullet list of core takeaways:]
- **Concept 1** — Brief explanation
- **Concept 2** — Brief explanation
- **Formula/operation** — What it does and when to use it
## The Math
[Explain the concept clearly, with intuition before formulas]
### [Subconcept 1]
[Explanation, formula, geometric meaning]
### [Subconcept 2]
[Explanation, formula, geometric meaning]
## Where it's used
Graphics and game programming uses this for:
- [Use case 1]
- [Use case 2]
**In forge-gpu lessons:**
- [Link to GPU lesson] uses `function_name()` for [purpose]
- [Link to GPU lesson] uses `function_name()` for [purpose]
## Building
cmake -B build
cmake --build build --config Debug
Windows
build\lessons\math\NN-concept-name\Debug\NN-concept-name.exe
Linux / macOS
./build/lessons/math/NN-concept-name/NN-concept-name
[Brief note on what the demo shows]
## Result
[Brief description of expected demo output or what the program demonstrates]
**Example output:**
[Copy actual program output here]
**Important:** Copy output directly from running the program—don't manually type it.
## Exercises
1. [Exercise extending the concept]
2. [Exercise applying it differently]
3. [Exercise combining with other concepts]
## Further reading
- [Relevant math lesson that builds on this]
- [External resource if helpful]
6. Update `common/math/forge_math.h`
Add the new math functions following the library's conventions:
- Documentation: Summary, parameters, returns, usage example, geometric intuition
- Naming:
typeN_verb(e.g.,vec3_dot,mat4_rotate_x) - Implementation: Clear, readable, matches textbook descriptions
- Inline: Use
static inlinefor header-only functions - Comments: Explain the math, not just the code
Example:
/* Compute the dot product of two 3D vectors.
*
* The dot product measures how much two vectors point in the same direction.
* Result = |a| * |b| * cos(θ), where θ is the angle between them.
*
* If the result is:
* - Positive: vectors point somewhat in the same direction
* - Zero: vectors are perpendicular
* - Negative: vectors point in opposite directions
*
* Usage:
* vec3 a = vec3_create(1.0f, 0.0f, 0.0f);
* vec3 b = vec3_create(0.0f, 1.0f, 0.0f);
* float d = vec3_dot(a, b); // 0.0 — perpendicular
*
* See: lessons/math/01-vectors
*/
static inline float vec3_dot(vec3 a, vec3 b)
{
return a.x * b.x + a.y * b.y + a.z * b.z;
}
If the function already exists, improve documentation or skip this step.
7. Update project files
CMakeLists.txt(root): Addadd_subdirectory(lessons/math/NN-concept-name)lessons/math/README.md: Add link to the new lesson (create this file if it doesn't exist)PLAN.md: Note the math lesson if relevant
8. Cross-reference GPU lessons
- Find GPU lessons using this math: Search for where these functions are (or should be) used
- Update GPU lesson READMEs: Add references to the math lesson
- Update math lesson README: List GPU lessons that use this math
9. Build and test
cmake -B build
cmake --build build --config Debug
./build/lessons/math/NN-concept-name/NN-concept-name
Verify the demo runs and produces expected output.
10. Verify key topics are fully explained
Before finalizing, launch a verification agent (Task agent) that audits every
key topic in the README for completeness. This catches cases where a key topic
name-drops a term (like "similar triangles") but the lesson never actually
explains what that term means — leaving readers confused.
For each key topic / "What you'll learn" bullet, the agent must check:
- Explained in the README — Is the concept described clearly enough that a
reader encountering it for the first time could understand it? Look in "The
Math" section, key concepts, and any subsections.
- Demonstrated in the C program — Does
main.cactually exercise this
concept with code and output? A key topic that's only mentioned in the README
but never shown in the demo is incomplete.
- All referenced terms are defined — Read the exact wording of each key
topic and identify every math term, technical term, or concept it references
(e.g., "similar triangles", "homogeneous coordinates", "affine transformation",
"orthonormal basis"). For each referenced term, confirm it is explained
somewhere in the lesson — either inline where first used, in its own
subsection, or with a cross-reference to another lesson that covers it.
What to flag:
- A key topic references a term that is never defined or explained anywhere in
the README
- A key topic is listed in "What you'll learn" but has no corresponding section
in "The Math" or the demo program
- A term is used as though the reader already knows it, but no prior math lesson
in the curriculum covers it either
- The C program prints results for a concept but the README doesn't explain how
to interpret those results (or vice versa)
How to fix flagged issues:
- Add a brief, plain-language explanation where the term is first used (1-3
sentences is usually enough — not a full derivation, just enough for the reader
to follow along)
- If the term deserves a deeper treatment, add a focused subsection under "The
Math" and link to it from the key topic
- If a prior lesson already covers the term, add an explicit cross-reference:
"See Lesson NN — Name for an explanation of [term]"
- If a key topic has no demo coverage, either add it to
main.cor remove/revise
the key topic to match what the lesson actually teaches
The lesson is not complete until every key topic passes all three checks.
11. Run markdown linting
Use the /dev-markdown-lint skill to check all markdown files:
npx markdownlint-cli2 "**/*.md"
If errors are found:
- Try auto-fix:
npx markdownlint-cli2 --fix "**/*.md" - Manually fix remaining errors (especially MD040 - missing language tags)
- Verify:
npx markdownlint-cli2 "**/*.md"
Common fixes needed:
- Add language tags to code blocks (`
`text,`c,`bash`) - Use 4 backticks for nested code blocks (when showing markdown in markdown)
MANDATORY: Chunked writes for large files
Task agents have a 32K output token limit per Write call. **Any file over ~800
lines** MUST be written in chunks — split into parts, write each to /tmp/,
then concatenate.
Recovery rule — if a writing agent fails with a token limit error:
- NEVER write a fallback or simplified version. STOP and report the failure.
- Re-run the write using the chunked approach.