TheoremExplainAgent: Multimodal Theorem Explanations
- TheoremExplainAgent is an agentic system that automatically generates long-form, multimodal explanations for mathematical theorems using LLMs, code generation, and animated visualizations.
- It decomposes proofs into coherent scenes by planning pedagogical goals, scripting Manim-based animations, and synchronizing narration with graphics.
- TEA demonstrates measurable gains in knowledge transfer and exposes reasoning flaws through automated debugging and evaluation on TheoremExplainBench.
TheoremExplainAgent (TEA) is an agentic system designed to automate the generation of multimodal explanations for mathematical theorems, integrating LLMs, code generation, and vector-graphics animation via Manim. TEA offers structured, long-form video explanations with synchronized narration and dynamic visualizations. It is both a technical framework for proof explanation and a case study in modular skill extraction for agentic AI systems in STEM education domains (Ku et al., 26 Feb 2025, Bi et al., 12 Mar 2026).
1. Motivation and Challenges of Multimodal Theorem Explanation
Mathematical understanding is inherently multimodal: text-only reasoning frequently obscures subtle flaws and often fails to instill geometric or physical intuition. Video explanations with synchronized narration, symbolic derivations, and dynamic animations have been shown to concretize abstract concepts, elucidate hidden proof relationships, and reveal reasoning failures that static text cannot expose. However, fully automated generation of long-form (≥1 minute) theorem explanation videos poses several open challenges:
- Conceptual Planning: Decomposing a theorem proof into coherent scenes with distinct pedagogical foci.
- Animation Scripting: Translating these scene specifications into executable Python code using Manim for vector-graphics animation.
- Narration–Animation Synchronization: Aligning voiceover, on-screen equations, and animated primitives temporally.
- Automated Debugging: Diagnosing and correcting errors including API hallucinations and LaTeX rendering failures.
- Evaluation: Defining metrics that jointly quantify factual accuracy and perceptual quality of the multimodal output (Ku et al., 26 Feb 2025).
2. Architectural Overview: The Two-Agent Agentic Pipeline
TheoremExplainAgent implements a dual-agent architecture, partitioning the pipeline into discrete planning and coding responsibilities:
- Planner Agent receives as input a theorem name in LaTeX and contextual description. Employing Chain-of-Thought (CoT) prompting and optional retrieval from Manim documentation, it generates:
- A high-level scene plan with titles, pedagogical purposes, and spatial sketches.
- Detailed scene breakdowns specifying visual elements (shapes, equations, text) and animation timings.
Coding Agent consumes the detailed specifications and emits Manim Community Edition scripts. It operates within a self-debugging loop: if an animation script fails, it analyzes the stack trace and proposes LLM-guided patches, with up to 5 retries per scene allowed for recoverable errors.
- Retrieval-Augmented Generation (RAG) is used at all phases: agents make embedding-based queries against the Manim API documentation to retrieve function signatures and code snippets.
- Voiceover Integration is accomplished with the
manim-voiceoverextension, aligning synthesized audio with animation events. - Final Rendering is orchestrated by the Manim engine, compositing scenes and transitions into a coherent, narrated video exceeding one minute (Bi et al., 12 Mar 2026).
3. Manim Integration and Procedural Workflow
TEA's visual component is built on Manim's declarative scene specification. Geometric primitives such as Circle, Polygon, Square, combined with text (MathTex, Tex) and animation commands (Create, Transform, FadeIn) enable expressive theorem presentations. Layout constraints including buffer spacing and alignment (next_to, to_edge) are planned by the agent and enforced in code.
A representative pedagogical workflow in pseudocode is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
def explain_theorem_with_animation(theorem_tex, output_dir): # 1. Planner phase storyboard = Planner.generate_scene_plan(theorem_tex) # 2. Coding phase attempts = 0 while attempts < MAX_ATTEMPTS: manim_script = CodingAgent.render_script(storyboard) try: run_manim(manim_script, output=output_dir) break # success except ExecutionError as e: fix_patch = CodingAgent.debug_patch(e.stack_trace) manim_script = apply_patch(manim_script, fix_patch) attempts += 1 if attempts == MAX_ATTEMPTS: raise RuntimeError("Animation failed after self-debugging.") return collect_video_files(output_dir) |
This procedural loop embodies agentic modularity, RAG for code retrieval, and error correction until a valid animation sequence is produced (Bi et al., 12 Mar 2026).
4. Evaluation: TheoremExplainBench and Multidimensional Metrics
TEA is systematically evaluated on TheoremExplainBench, a benchmark spanning 240 theorems from mathematics, physics, chemistry, and computer science, balanced across three difficulty levels (high school, undergraduate, graduate). The evaluation protocol requires automated generation of ≥1-minute video explanations for each theorem, incorporating stepwise animations and narration.
TEA's output is scored in five dimensions, each mapped to [0,1]:
- Accuracy & Depth (): Mean LLM-assigned correctness scores per transcript statement.
- Visual Relevance (): Vision–LLM scoring of the congruence between key frames and their corresponding proof steps.
- Logical Flow (): Evaluation of scene coherence and proof ordering.
- Element Layout (): Fraction of frames penalized for overlaps or spatial misalignment.
- Visual Consistency (): Assessment of animation smoothness and stylistic uniformity, including motion coherence.
The geometric mean is used as the primary metric. Empirically, TEA using the o3-mini model achieves a 93.8% video generation success rate and a 0.77 overall metric score on the benchmark (Ku et al., 26 Feb 2025, Bi et al., 12 Mar 2026).
5. Findings: Strengths, Limitations, and Insights
Quantitative and qualitative analysis provides several key findings:
- Pedagogical Impact: Multimodal explanations generated by TEA produce a 40% gain in knowledge transfer efficiency relative to text-only LLM baselines, as measured by TeachQuiz scores and validated against human-rated tutorial controls. Human-crafted videos slightly outperform TEA on visual relevance and layout, but TEA matches or exceeds humans in logical flow (Bi et al., 12 Mar 2026).
- Deeper Error Diagnosis: Multimodal outputs reveal reasoning pathologies (e.g., misapplied proof steps, incorrect visual correspondences) that would not be exposed by textual output alone.
- Layout Issues: Residual problems include overlapping text labels, scale inconsistencies, and shape misalignments, particularly in chemistry- and labware-heavy scenes.
- Code Hallucinations and RAG Failures: Occasionally, RAG retrieves irrelevant or generic snippets, resulting in incorrect API calls or non-existent function invocations.
- Evaluation Subjectivity: Metrics for visual consistency correlate only weakly with human judgment, suggesting the need for more holistic evaluators (Ku et al., 26 Feb 2025).
6. TheoremExplainAgent as Modular Skill and Broader Implications
TEA's architecture was extracted into a reusable skill artifact (visual-theorem-walkthrough) employing the SKILL.md format. This encapsulates both frontmatter (triggers, dependencies) and hierarchical instructions (parsing, storyboard generation, coding, error-correction, validation), accompanied by reusable Manim script templates and schema references.
Activation is determined via a similarity threshold between user queries and the declared triggers, enabling runtime composition and reuse across agentic platforms. Notably, the procedural rigor and error-correction loop are generalizable, facilitating scalable acquisition and deployment of procedural capabilities without model retraining (Bi et al., 12 Mar 2026).
7. Relation to Mathematical Explanation Theory
A parallel development considers TEA from the standpoint of formal explanation frameworks. Standard causal models (Halpern–Pearl) are extended with Impossible Possible Worlds (IPWs) to enable explanations of mathematical facts that are necessarily true across all classical models. TEA modules construct a knowledge base encoding axioms and candidate explanations, generate IPWs by varying truth assignments (even to mathematical impossibilities), and formally test candidate explanations for causal sufficiency, non-vacuity, and minimality. Ranking is performed via conditional prior probabilities or partial-explanation scores. This paradigm directly informs TEA's internal logic for justifying proof steps and selecting explanatory features (Halpern, 2023).
References
- [TheoremExplainAgent: Towards Video-based Multimodal Explanations for LLM Theorem Understanding, (Ku et al., 26 Feb 2025)]
- [Automating Skill Acquisition through Large-Scale Mining of Open-Source Agentic Repositories, (Bi et al., 12 Mar 2026)]
- [Mathematical Explanations, (Halpern, 2023)]