# Math-To-Manim **Repository Path**: codehole/Math-To-Manim ## Basic Information - **Project Name**: Math-To-Manim - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-01 - **Last Updated**: 2026-06-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
Star History Chart # Math to Manim ### Ask a question -> get a freakin' movie [![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-3b82f6)](https://www.python.org/) [![Manim CE](https://img.shields.io/badge/Manim-CE-f59e0b)](https://www.manim.community/) [![OpenAI Agents SDK](https://img.shields.io/badge/OpenAI-Agents%20SDK-111827)](https://openai.github.io/openai-agents-python/) [![Hermes assisted](https://img.shields.io/badge/Hermes-agent%20assisted-8b5cf6)](#hermes-agent) [![License: MIT](https://img.shields.io/badge/License-MIT-22c55e)](LICENSE) [Motion showcase](docs/showcase/README.md) · [Architecture](docs/ARCHITECTURE.md) · [Prime RL](docs/PRIME_INTELLECT_RL.md) · [Roadmap](docs/ROADMAP.md) · [Agent guide](AGENTS.md)

GRPO semantic manifold: sibling completions become a geometric policy update across the full scene QED and Minkowski spacetime: light cones, electromagnetic waves, gauge symmetry, and renormalization flow on an off-white 3D stage


3D circle area derivation from annuli to unwrapped triangle Rhombicosidodecahedron animation Cosmic gravity 3D animation Full GRPO semantic manifold animation

Derivative visualization animation ProLIP animation Lorenz attractor animation Hopf fibration animation

Fourier epicycles animation Teaching Hopf animation Brownian finance animation Radius of convergence animation Whiskering exchange animation

**Math-To-Manim turns serious math and physics prompts into Manim explainer videos and the reusable artifacts that produced them: intent, prerequisite graphs, lesson plans, math packets, storyboards, scene specs, generated code, validation reports, render evidence, review notes, and stage traces.**
--- ## What this is **Math-To-Manim** started on the morning of Donald Trump's inauguration. I do not think it was an accident that the Chinese decided to release the R1 model on that day. I was awake, saw the model hit Hugging Face, and quickly built a `.ipynb` to load the model and run it. I created this repo at `2025-01-20T11:04:50Z` / `04:04:50 MST`. Within a couple of minutes I realized what this meant. If the Chinese, via GRPO, had reasoning on a chip, recursive reasoning was not far behind. In my tweet I wrote "Wrap it up, its over" and I still believe it. ```text 09a2f22 2025-01-20T04:24:50-07:00 updated A DeepSeek_R1_zero.ipynb A Readme.md ``` Three hours later, the first Manim file landed: `pythagorean.py` at `2025-01-20T07:18:12-07:00`.

The original R1 Pythagorean theorem Manim animation from the viral January 20, 2025 tweet

> "I asked #R1 to visually explain to me the Pythagorean theorem. This was done in one shot with no errors in less than 30 seconds. Wrap it up, its over: #DeepSeek #R1" > > — [Christian H. Cooper, January 20, 2025](https://x.com/christiancooper/status/1881335734256492605?s=20) What I saw with R1 is that the model was already good with Manim code out of the box. What actually runs under the hood with Math-To-Manim is a series of six planning agents that recursively reason over the prompt you gave it before code generation, validation, rendering, and review. This all runs on Codex 5.5. However, since Prime Intellect rolled out hosted evals, and since I understand Recursive Learning Models better now, I am using the reasoning traces for RL training. But this will always just work. If you are a teacher or a parent, you can always ask for an explanation and just get an MP4 back. You never have to see or worry about the reasoning training. For the curious, follow along here: [Prime Intellect M2M hub: `harleycooper/math-to-manim`](docs/PRIME_INTELLECT_RL.md). -christian --- ## "Hey man, I just want to see a demo, I don't need a calculus lecture" Fair. The whole point is that the pipeline should turn a one-sentence idea into something moving on screen before you have to read the architecture docs.

A generated Manim movie unwrapping circle annuli into a triangle

WSL quickstart: ```bash cd /mnt/c/Users/$USER git clone https://github.com/HarleyCoops/Math-To-Manim.git cd Math-To-Manim python3 -m venv .venv source .venv/bin/activate python -m pip install -U pip python -m pip install -e ".[dev,render]" ./scripts/bootstrap-render.sh # Debian/Ubuntu/WSL system deps for real MP4 output m2m2 generate \ "Show why the quantum harmonic oscillator only allows discrete energies: start with a springy potential well, zoom into the wavefunctions, then reveal the ladder of allowed energy levels." \ --codegen-provider codex-cli \ --codex-full-auto \ --style cinematic \ --quality l \ --runs-dir runs ``` Generated bundles and videos stay in repo-local `runs//` by default; the `--runs-dir runs` flag above is intentionally explicit so agent-driven runs do not disappear into `/tmp`. If you want Hermes to run the harness like an operator instead of driving the CLI by hand: ```bash hermes --skills manim-video,systematic-debugging,codebase-inspection \ -z "Run the M2M2 pipeline on the quantum harmonic oscillator demo prompt with --runs-dir runs, inspect the repo-local run bundle, try a low-quality render, and report the generated movie path or the exact blocker. Do not put user-visible outputs in /tmp." ``` That gives you the practical loop: ask for the movie, inspect the run bundle, then tell the agent what to fix. --- ## Hermes Agent

Hermes Learns Manim: an agent surrounded by equations, turning recursive reasoning into animation code

Hermes is the contributor/operator agent around this repository. It is not imported by Math-To-Manim and is not a runtime dependency; it uses the repo the way a developer would: read files, search code, patch docs and code, run terminal checks, inspect generated artifacts, review frames or GIFs, track todos, delegate larger work, and preserve stable context through skills. That makes Hermes useful for maintaining the reverse-reasoning pipeline without becoming part of it. A Hermes session can inspect `AGENTS.md`, `pyproject.toml`, schemas, tests, and `runs//` bundles; run `pytest`, CLI smoke commands, Manim, FFmpeg, and git checks; then verify that docs, code, and showcase media still match the artifact contracts. Repo-local Hermes skills live under [`hermes/skills/`](hermes/skills/). The old Claude `./skill` path is historical; current contributor guidance is in [`AGENTS.md`](AGENTS.md), with launch notes in [`docs/HERMES_LEARNS_MANIM.md`](docs/HERMES_LEARNS_MANIM.md). --- ## Reverse reasoning pipeline A normal text-to-code demo jumps from request to Python. Math-To-Manim takes the long way on purpose: it reasons backward from the final concept to the prerequisites, then walks forward through a teachable visual sequence. The code path is explicit in [`math_to_manim/pipeline/runner.py`](math_to_manim/pipeline/runner.py). `AnimationPipeline.generate()` runs a fixed stage chain: `IntentAgent`, `PrerequisiteGraphAgent`, `CurriculumAgent`, `MathAgent`, `StoryboardAgent`, `SceneSpecAgent`, `ManimCodeAgent`, `StaticReviewAgent`, `RenderAgent`, `VideoReviewAgent`, and `PublisherAgent`. | Stage | Why it exists | Artifact | | --- | --- | --- | | Intent | Clarify what the learner is really asking. | `intent.json` | | Reverse prerequisites | Build the knowledge graph needed before the target idea. | `knowledge_graph.json` | | Curriculum | Turn the graph into a teachable order. | `curriculum.json` | | Math packet | Select definitions, equations, assumptions, and examples. | `math_packet.json` | | Storyboard | Decide the screen beats before code exists. | `storyboard.json` | | Scene spec | Compile the visual plan into Manim objects, animations, timing, and camera notes. | `scene_spec.json` | | Code, validation, render, review | Generate runnable Manim, gate it with static checks, render when allowed, and package the evidence. | `generated_scene.py`, reports, manifest |

Render validation and bounded repair loop diagram showing static review, render skip, Manim subprocess, repair from frozen scene spec, video review, and publisher package

That gives every run a memory: JSON contracts, generated code, render results, review notes, and a manifest. The output is not just a video; it is an inspectable path from **question** to **understanding** to **animation**. For current editable-video status and the planned prompt/spec/code edit loop, see the [roadmap](docs/ROADMAP.md). --- ## Prime Intellect RL repair loop Math-To-Manim is also becoming a Prime Intellect reinforcement-learning environment. The first RL target is not "make the whole video in one shot." It is the edit move that matters after a base model produces a plausible but flawed scene: text overlaps formulas, equations are too small, the camera angle hides the point, or the zoom never lands on the symbol the learner needs to read. A concrete target is the quantum-physics homepage-style failure mode: a beautiful Manim pass that still has text/formula collisions. The experiment is to give the model the typed scene plan, the generated Python, validation/render evidence, and a human request such as "fix the overlap," "change the POV angle," or "zoom into the formulas before the narration moves on." The policy should return a sparse code edit that preserves the scene while making the movie more readable.

Prime Intellect logo

Diagram of the Math-To-Manim Prime Intellect RL repair loop from generated Manim code through static reward checks back to corrected renderable Manim Python

Prime Intellect lab field visual, used here to represent the environment task space Prime Intellect reward hacking visual, used here to represent reward design pressure Prime Intellect compute corridor visual, used here to represent hosted training and inference
Run bundle as environment Reward function as critic Policy update as repair engine
The current hub environment is `harleycooper/math-to-manim`. A repair task carries the original prompt, typed `scene_spec`, generated Manim Python, static-validation report, and render/recovery evidence when available. The model must return one strict `GeneratedCode` JSON block. The Verifiers reward checks whether the proposed code parses, defines the expected Manim scene, avoids unsafe imports and calls, preserves expected math terms, and reduces obvious text/layout crowding hazards. ```text generated_scene.py + scene_spec + validation/render evidence -> Prime Intellect Verifiers environment -> model proposes corrected GeneratedCode JSON -> static reward checks parseability, scene shape, safety, terms, layout -> hosted RL updates the repair policy -> corrected, renderable Manim Python flows back into M2M2 recovery ``` That keeps the fast RL loop text-and-AST based while the slower Manim renderer remains the audit gate. The intended result is a model that learns the house style of this repo: cinematic but readable scenes, sparse formulas, staged captions, safe Manim code, and edits that can respond to text or voice change requests without throwing away the whole movie. Current hosted-training status: the environment action passes on Prime, the hub package is published as `harleycooper/math-to-manim@0.1.1`, a 1-step smoke completed, and a 25-step W&B-enabled pilot has been launched on `Qwen/Qwen3.5-35B-A3B`. See the full integration notes in [`docs/PRIME_INTELLECT_RL.md`](docs/PRIME_INTELLECT_RL.md). --- ## Clone and run ### 1. Clone Windows PowerShell: ```powershell git clone https://github.com/HarleyCoops/Math-To-Manim.git cd Math-To-Manim python -m venv .venv .\.venv\Scripts\Activate.ps1 python -m pip install -U pip python -m pip install -e ".[dev]" python -m pytest ``` macOS / Linux / WSL: ```bash git clone https://github.com/HarleyCoops/Math-To-Manim.git cd Math-To-Manim python3 -m venv .venv source .venv/bin/activate python -m pip install -U pip python -m pip install -e ".[dev]" python -m pytest ``` ### 2. Run a no-API smoke test This proves the CLI, artifact contracts, and validators are wired before you spend model or render time: ```bash math-to-manim generate "Explain why derivatives are slopes" --deterministic --no-render ``` Equivalent module form: ```bash python -m math_to_manim.cli generate "Explain why derivatives are slopes" --deterministic --no-render ``` ### 3. Generate with model calls Set an OpenAI key and choose a model if desired: ```bash export OPENAI_API_KEY="sk-..." export OPENAI_MODEL="gpt-4.1" math-to-manim generate "Explain Fourier epicycles as rotating vectors" --no-render ``` PowerShell: ```powershell $env:OPENAI_API_KEY = "sk-..." $env:OPENAI_MODEL = "gpt-4.1" math-to-manim generate "Explain Fourier epicycles as rotating vectors" --no-render ``` ### 4. Install render extras when you want MP4 output Python render dependency: ```bash python -m pip install -e ".[dev,render]" ``` System render dependencies are also needed for real Manim output, especially FFmpeg and LaTeX for `MathTex`. On Debian/Ubuntu/WSL: ```bash ./scripts/bootstrap-render.sh ``` The package list lives in [`requirements-system.txt`](requirements-system.txt). --- ## Codex CLI codegen path Math-To-Manim can keep the typed planning pipeline while sending the Manim codegen and repair loop through a locally authenticated Codex CLI session. Check Codex first: ```bash codex --version codex exec "Say ready from inside this repo" ``` Then route codegen through Codex: ```bash math-to-manim generate "Explain derivatives as slopes with a cinematic tangent-line reveal" \ --codegen-provider codex-cli \ --codex-full-auto \ --style cinematic \ --quality l ``` Earlier planning stages remain on the typed adapters; only the generated-code and repair stages move first. That makes the migration incremental instead of all-or-nothing. --- ## What lands on disk A generation writes a self-contained run bundle: ```text runs// request.json intent.json knowledge_graph.json curriculum.json math_packet.json storyboard.json scene_spec.json generated_code.json generated_scene.py validation_report.json render_result.json review_report.json trace.jsonl # stage-boundary events when tracing is enabled recovery_manifest.json # after recover-render draft_review/ draft_review.md contact_sheet.png frames/ animation_package.json manifest.json ``` After editing `generated_scene.py` inside a run bundle, rerun the recovery path: ```bash math-to-manim recover-render runs/ --quality l ``` That command refreshes validation, render, review, draft-review assets, and `recovery_manifest.json` without regenerating upstream planning artifacts. Package layout: ```text math_to_manim/ agents/ # stage adapters schemas/ # versioned artifact contracts tools/ # graph, validation, rendering, video, artifact helpers pipeline/ # orchestration, tracing, repair loop rendering/ # Manim and FFmpeg wrappers review/ # static and visual review scoring ``` --- ## Motion showcase Sixteen curated GIFs are tracked under [`docs/showcase/assets/`](docs/showcase/assets/) as the **art direction target** for Math-To-Manim's visual explanations.
Rhombicosidodecahedron Hopf fibration Lorenz attractor
Geometry as spectacle Topology as choreography Chaos as intuition
See the full gallery with descriptions: **[`docs/showcase/README.md`](docs/showcase/README.md)**. ### Make a README-sized GIF from a render ```bash MP4="media/videos/your_scene/480p15/YourScene.mp4" ffmpeg -y -ss 95 -t 24 -i "$MP4" \ -vf "fps=12,scale=720:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=96[p];[s1][p]paletteuse=dither=bayer:bayer_scale=5" \ docs/showcase/assets/your-clip.gif ``` Adjust `-ss` and `-t` to capture the teaching beat you want. --- ## License MIT.