Add a math concept - create lesson, update library, document usage
Create a new math lesson and update the math library (common/math/forge_math.h).
When to use this skill:
forge_math.h yetSmart behavior:
forge_math.hThe user (or you) can provide:
If any are missing, infer from context or ask.
common/math/forge_math.h: Does this math already exist?lessons/math/NN-concept-name/
main.c)A small, focused C program that demonstrates the math concept visually or numerically.
Requirements:
#include "math/forge_math.h"Examples:
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:
-, =, *, |, ->, [OK], [!], "degrees", "in", "+/-"─, ═, •, ↓, →, ✓, ⚠, °, ∈, ± (may render as garbled text on Windows)CMakeLists.txtadd_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>
)
README.mdStructure:
# 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
```bash
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:**
```text
[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]
common/math/forge_math.hAdd the new math functions following the library's conventions:
typeN_verb (e.g., vec3_dot, mat4_rotate_x)static inline for header-only functionsExample:
/* 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.
CMakeLists.txt (root): Add add_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 relevantcmake -B build
cmake --build build --config Debug
./build/lessons/math/NN-concept-name/NN-concept-name
Verify the demo runs and produces expected output.
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:
main.c actually 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.What to flag:
How to fix flagged issues:
main.c or remove/revise
the key topic to match what the lesson actually teachesThe lesson is not complete until every key topic passes all three checks.
Use the /dev-markdown-lint skill to check all markdown files:
npx markdownlint-cli2 "**/*.md"
If errors are found:
npx markdownlint-cli2 --fix "**/*.md"npx markdownlint-cli2 "**/*.md"Common fixes needed:
```text, ```c, ```bash)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:
See .claude/large-file-strategy.md
for the full strategy.
v' = M * vC = A * B means "apply B first, then A"vec2, vec3, vec4, mat4 — typesvec3_add, mat4_rotate_z — functionsEvery function needs:
Scenario: Lesson 02 needs vec2 and vec3 for vertex positions and colors.
vec2 and vec3 types exist, basic ops existlessons/math/01-vectors/vec2_create and vec3_createScenario: You're reviewing Lesson 03 and notice it has bespoke rotation math.
mat4_rotate_z exists!mat4_rotate_zFind opportunities to create compelling diagrams and visualizations via the
matplotlib scripts — they increase reader engagement and help learners
understand the topics being taught. Use the /dev-create-diagram skill to add
diagrams following the project's visual identity and quality standards.
For geometric or mathematical visuals (vector diagrams, interpolation grids,
frustum views), add a diagram function to
scripts/forge_diagrams/math/lesson_NN.py (create the file if it doesn't
exist):
setup_axes,
draw_vector, save helpers from _common.py)scripts/forge_diagrams/math/__init__.pyDIAGRAMS dict in __main__.py with the lesson keypython scripts/forge_diagrams --lesson math/NN to generate the PNGOutput goes to each lesson's assets/ directory at 200 DPI (PNG only).
For flow/pipeline diagrams (transformation pipelines, data flow), use inline mermaid blocks. GitHub renders these natively:
```mermaid
flowchart LR
A[Step 1] --> B[Step 2] --> C[Step 3]
```
Use mermaid for sequential flows.
For formulas, use inline $...$ and display $$...$$ math notation.
GitHub renders these via KaTeX:
$\vec{a} \cdot \vec{b} = a_x b_x + a_y b_y$$$
\text{lerp}(a, b, t) = a + t \cdot (b - a)
$$
Keep worked-examples-with-numbers in ```text blocks — only convert
symbolic/algebraic formulas to KaTeX.
In these cases, just update documentation or plan for later.