Mathly Engine
Prism
A language for interactive math lessons.
Prism compiles to the IR that powers Mathly's interactive lesson engine. The compiler runs at seed-time or on the server, and its output is validated data — it never executes code, so it is safe to compile AI-generated source.
The guide
Lessons & Slides
A Prism file is either a bare scene { ... } (one visualization) or a lesson { ... } (a full multi-slide lesson). A slide is a composition: any prose, at most one scene, at most one exercise, and any number of goals — in any order. There is no "text slide" vs "quiz slide"; you just include the parts you need.
Exercises
An exercise is the checkable part of a slide — the thing the learner answers. Every exercise shares four optional lines: ask "..." (the prompt), hint "..." (repeatable — a hint ladder), ! "..." (the explanation shown after checking), and skill: "..." (the skill it tests).
Scene & State
A Prism file is exactly one scene <type> { ... } block. Everything else — space config, state, objects, controls, timeline — lives inside it.
Objects
Objects are the visual elements of a scene. Properties go in a trailing { key: value } block — omit it entirely if the object needs no configuration. All objects accept: color, style (solid/dashed/dotted), show:<expr>, width:<number>. Note: curve, line, rect, circle, polygon, vector, arc, image require plane scenes; only point and label work on numberline scenes.
Three dimensions
A scene space3 draws in 3D. It needs a z: [min, max] alongside x and y, and it projects orthographically the way a textbook draws a solid — no perspective, so parallel edges stay parallel and lengths along an axis stay comparable. Axes, arrowheads and unit ticks are drawn for you. Point the camera: at a param and the learner can spin the figure, which is the only reliable way to resolve what is in front of what. The 3D objects below are only legal inside a space3 scene, and the 2D ones (curve, rect, circle, ...) are not.
Controls
Controls are the interactive widgets the learner uses. They write to state variables, which re-evaluates all object expressions.
5 keywords07Timeline
A timeline is a sequence of steps the learner plays through in order. Each step can narrate, set state instantly, or animate to new values. Great for walkthroughs and guided reveals.
1 keywords08Loops & Logic
Prism has compile-time loops and conditionals that unroll before the scene is built. They use brace blocks, same as everything else. Generates static objects — the scene structure is always fixed at runtime.
6 keywords09Expressions & Math
Expressions appear in object properties (like the expr in curve f = <expr>), control bounds, and ${...} label interpolations. They're evaluated at runtime against the current state.
All keywords