Prefix writes each operator first, postfix last. Neither needs parentheses.
Symbolic Physical Laws DiscoveryFoundations
Module 2Mathematical languages for symbolic models
Before any search begins, someone chooses a language. We follow mathematical notation from words to symbols to computation, then store one formula as a tree, as prefix and postfix strings, as a graph with sharing, as a token sequence and as a grammar derivation, and see what each makes easy, hard or invalid. Grammars and unit rules decide what may be written; our exact count shows how much of the space units remove. The second video turns to constants (fitting, redundancy, and whether 6.296 is really 2π), to the many disguises of one formula, and to complexity measures that disagree. It ends by designing a language for a pendulum with air drag, before touching any data.
Key ideas, one per video
- Video 4With six operators, our tiny language has about 8.9 billion formulas and fewer than 4% pass the unit check; units are a filter, not a validation.
- Video 5Least squares reached the noise level in 6 evaluations where 1,000 random guesses did not; and the bell curve is simpler than a quadratic by node count, more complex by depth, and tied by weight.
Book: Chapter 2 of Computational Methods for Symbolic Physical Laws Discovery by Teddy Lazebnik (coming soon). The videos and slides follow the chapter’s topics in our own words, figures and simulations; nothing is copied from the book.
Watch
2 videos for this module, each about 8 to 15 minutes. Pick one from the list, and open the transcript to read along: each timestamp plays the video from there. The narration is generated with a voice clone of Teddy, used with his permission.
Video 4 · 9:53
Expressions as computational objects
One formula, six objects: a computer never searches mathematics itself, only the language someone chose.
With six operators, our tiny language has about 8.9 billion formulas and fewer than 4% pass the unit check; units are a filter, not a validation.
TranscriptVideo 4
One formula, six objects. Here's one formula: a cup cooling in a room, with a small heater switching on and off. c times the room temperature minus T, plus q times the sine of omega t. Now here it is again, five more times. As a tree. As prefix and postfix strings. As a graph. And as a derivation from a grammar. Which one is the formula? All of them, and none of them. A computer never searches mathematics itself. It searches one of these objects, and each object changes what the search can see, reach and break. Welcome to Module two. This video has three parts: a short history of mathematical notation, the main ways a computer stores a formula, and grammars with units, the rules that decide which sentences are allowed.
From words to symbols. Before equations, there were marks: notches on a stick, tokens for grain, counts of animals and days. Algebra itself is older than its symbols. For centuries, problems were solved in words. Symbols arrived slowly. In 1557, Robert Recorde introduced the equals sign: two parallel lines, because no two things could be more equal. Around 1591, François Viète used letters for both known and unknown quantities, so whole families of problems could share one form. In 1637, Descartes tied algebra to curves. Calculus made change itself writable. Leibniz published his notation for differentials in 1684, and Newton wrote about fluxions, quantities flowing in time. Now the unknown could be a whole trajectory, not a number. The idea of a function grew too. Euler treated functions as analytic expressions. Later, mathematicians accepted any rule that gives each input one output, with or without a formula. So a formula, a table, a graph and a program can carry the same mathematical content, and still be different objects. In the 1930s, Church and Turing made computation itself mathematical: symbols manipulated by finite rules. That's the bridge to us. An expression tree, a token sequence, a grammar: each is a modern encoding of choices that mathematicians made over centuries. A symbolic regression system never searches mathematics in general. It searches a language that someone chose.
What an expression language is. So what is an expression language? It's the primitive symbols, the rules for combining them, the type or unit rules, and the way candidates are stored. It defines the hypothesis space before any optimization begins. If the language has multiplication but no powers, a power law is still expressible, but only as a long product. If it allows unrestricted division and logarithms, it contains short formulas that break on part of your data. A language is an inductive bias. It changes how likely a useful equation is to be short, reachable and valid. Often it matters as much as the search algorithm.
Formulas as computational objects. Part two: formulas as computational objects. Start with the tree. For our heater formula, the root is a plus. On one side, c times the room temperature minus T. On the other, q times the sine of omega t. The tree makes dependencies explicit: to evaluate the root, first evaluate its children. Depth measures nesting. Node count gives one notion of size. And any subtree is a complete piece that can be cut out and replaced. Now mutate one branch. Replace the sine of omega t by omega t squared. One small edit in the tree. But a bounded wiggle has become a term that grows without limit. Computational distance and mathematical distance are different things. Two trees one edit apart can behave completely differently, and two very different trees can be the same function. The search moves through a geometry made by the representation. A tree can also be flattened. Take x minus two, times y. In prefix form, each operator comes first: times, minus, x, two, y. In postfix form, it comes last: x, two, minus, y, times. No parentheses are needed, as long as you know how many arguments each operator takes. Prefix strings are great for generators. Write plus, sine, x. The sine is complete, but the plus still has one open slot. Keep counting open slots, and when the count reaches zero, the formula is done. If it can't reach zero within the length limit, reject it early. Flat sequences store compactly, hash quickly and evaluate fast, which matters when you test millions of candidates. But edits get harder. A subtree becomes an interval that you can only find by counting arguments. And swapping a sine for a plus suddenly demands an extra argument, so the rest of the string has to be repaired or rejected. And remember, well formed is not meaningful. The log of minus three is a perfectly formed string. So is x divided by x minus x. Both are valid syntax, and useless. Tree-based genetic programming loves a property called closure. Every operator accepts whatever the others return, so any subtree can be attached anywhere. That's convenient: variation rarely creates broken formulas. Science often wants less freedom. A vector shouldn't go where a number belongs. Seconds shouldn't be added to meters. And the logarithm of a length makes no sense. Types and units bring those distinctions back. Trees also repeat themselves. In e to the minus t, times the cosine of t, plus e to the minus t, the exponential appears twice. A tree stores both copies: ten nodes. A graph with sharing stores it once: six nodes. Sharing changes mutation too. Change the shared node, and both uses change at once. Copy it first, and the two uses drift apart. The same nominal move does different mathematics. It even changes what complexity means. Count stored nodes, and you measure computing cost. Count visible symbols, and you measure what a reader has to parse. Neural generators use yet another object: a sequence of tokens, usually in prefix order. A transformer writes a formula symbol by symbol, like a sentence, and a parser turns it back into a tree. Validity and equivalence then need explicit care: masks that forbid impossible next tokens, and checks that catch the same formula written twice.
Grammars and units. Part three: grammars. A list of operators says what exists. A grammar says where it may appear. Here's a small grammar of our own. An expression is a sum of terms. A term is a product of factors. A factor is x, a constant, or e to the power of minus a constant times x. This grammar can't build the exponential of an exponential, or the exponential of x plus one. It allows decay terms under the exponential, and nothing else. The grammar has quietly encoded a physical expectation. Here's a question for you. Two grammars produce exactly the same set of formulas. Can they still lead to different discoveries? Pause and think. They can. We generated random formulas from one language with two sets of production weights. With the sine chosen five percent of the time, about thirty one percent of the formulas contained a sine. At twenty percent, sixty one percent did. Same language, same reachable formulas, very different search. Under a finite budget, whatever is easy to say gets said more often. Some methods go one step further, as in grammatical evolution: they evolve a code of numbers, and the grammar decodes it into a formula. The object being varied and the formula you read are now different things. One changed number can redirect a whole derivation and rewrite an entire subtree. And many different codes can decode to the same formula. Syntax alone happily builds x plus t. To catch that, attach units to every expression: the powers of length and of time that it carries. Multiply, and the powers add. Divide, and they subtract. Add or subtract, and they must match. Exponentials, logarithms and sines need a pure number inside. Now bad formulas are rejected while they're being built. They never get evaluated, and never enter the population. How much does that remove? We counted a tiny language: plus, minus, times and divide, with four leaves: a length x, a time t, a speed v, and a pure number c. With two operators there are 2,048 formulas, and only 744 pass the unit check. With four operators there are about 3.7 million, and about 430,000 pass, roughly twelve percent. With six operators, about 8.9 billion formulas, and fewer than four percent survive. Require the answer to be a speed, and only about a quarter of one percent remain. That's not only a speed up. The search spends its effort on formulas that could mean something. But a valid formula can still be wrong. Units don't prove causality, conservation, or the right behavior at the extremes. Units are a filter, not a validation.
Recap. Let's recap. A formula on paper becomes a computational object: a tree, a flat sequence, a graph, a token stream, or a grammar derivation. Each one decides what is close, what is valid, and what is cheap. Grammars and units decide which sentences can even be written. They are scientific assumptions, so write them down. In this module's lab, you'll build trees, see their prefix and postfix forms, mutate branches, and count how many formulas survive the unit rules. Next video: constants, equivalence, and why complexity depends on your language.
Is 6.296 really 2π?. A search returns a constant: 6.296. Is that two pi? Or just a number that happened to fit? Today: the numbers inside formulas, the many disguises of a single formula, and why simple depends on who is counting. At the end, we'll design a language for a pendulum, before touching any data.
Constants: the continuous unknowns. Part one: constants. A formula has two kinds of unknowns. Its structure is discrete. Its constants are continuous. Take y equals a times x over b plus x, a curve that rises and levels off. Once that shape is chosen, finding a and b is ordinary curve fitting. Searching for them with the same machinery that searches structure is usually a waste. Here's our example: twenty five simulated noisy points from that curve. The true values are 2.5 for a, and 0.8 for b. Strategy one: guess random constants. With ten guesses, the best typical error is 0.21. With a hundred guesses, 0.10. With a thousand guesses, 0.062. Strategy two: nonlinear least squares, starting from one and one. Six evaluations later, the error is 0.031, right at the noise level. It finds a at 2.47, and b at 0.74. Between these extremes there's a whole menu. A small fixed set of numbers, like one, two and pi. Linear least squares, when the constants enter linearly. Gradient methods, through formulas that can be differentiated. Or neural networks that predict constants from the data, followed by polishing. Each has a weakness. A fixed set can't fit arbitrary scales. Local methods depend on where they start. And predicted constants usually need refinement. Constants can also be redundant. Write the same curve as c one times c two times x, over b plus x. Now one times 2.47 gives exactly the same fit as two times 1.23. So does five times 0.49. The data can only pin down the product. Redundant constants create flat valleys, slow down the optimizer, and produce numbers that mean nothing on their own. Then comes the tempting question: is a fitted constant secretly famous? We simulated a pendulum at eight lengths, with a hundredth of a second of timing noise, and fitted T equals c times the square root of L over g. The fit gives c equal to 6.296, give or take 0.013. Two pi is 6.283, within about one standard error. So two pi is consistent with the data. But so are many nearby numbers. Replacing the fit by two pi is a claim. Show the evidence, or keep the fitted number.
Equivalence: one formula, many disguises. Part two: equivalence. Symbolic spaces are full of disguises. x plus x, two times x, and x times one plus one are the same function, and three different trees. x squared minus one, over x minus one, equals x plus one everywhere except at one, where the first is undefined. And the square root of x squared is the absolute value of x, not x. So same equation needs a definition. Here are four levels of sameness. Syntactic: the same string. Algebraic: one can be rewritten into the other by accepted rules. Numerical: the same values, within a tolerance, on the domain you care about. And scientific: the same predictions that matter for the application, including limits, symmetries, and what happens under an intervention. How much redundancy is out there? We grew ten thousand random trees, up to depth three, from plus, minus, times, x, one and two. There were 6,298 different trees. But evaluated at a few points, they formed only 872 different functions. And a single function made up twelve percent of everything we drew. Tools fight this. A canonicalizer rewrites formulas into one standard form: sort the arguments of plus and times, collect the numbers, drop times one and plus zero. Hashing finds identical subtrees fast. Equality graphs, or e-graphs for short, store many equivalent forms at once, so a search can recognize a formula it has already seen in another costume. But simplification carries assumptions. Rewriting e to the log of x as x assumes x is positive. Cancelling x over x assumes x is never zero, and a pendulum passes through zero twice in every swing. And computers don't do exact arithmetic. Add one to ten to the sixteen, then subtract ten to the sixteen, and you get zero. Do the subtraction first, then add one, and you get one. Same algebra, different answer.
Complexity depends on the language. Part three: complexity. Model selection trades error against complexity. But what is complexity, exactly? Node count is easy, but it treats a sine like a plus. Depth measures nesting. Weighted counts charge more for exponentials and powers. Description length asks how many bits it takes to write the formula down. Other measures count nonlinearity, or the cost of evaluating, or how hard the formula is for a person to use. Quick test. Which is simpler: a x squared plus b x plus c, or a times e to the minus b x squared? Pause and decide. By node count, the bell curve wins: nine nodes against eleven. By depth, the polynomial wins: four levels against five. And with heavier weights for exponentials and powers, they tie at thirteen. We ranked six common formulas under three measures. The line and the power law stay simplest under all three. The logistic curve is fifth by node count, but last by depth and by weighted cost. So declare your complexity measure before you see the results. Otherwise it's far too easy to pick the measure that flatters your favorite. Representation also shapes the search itself. Small edits can cause big changes. Big edits can change nothing. And trees can keep growing without improving the fit, a problem called bloat. Some methods vary formulas by their behavior instead of their syntax. Others choose parents one data case at a time, which keeps specialists alive. Each changes which formulas survive long enough to matter.
Designing a language for a pendulum. Part four: let's design a language before touching any data. A pendulum swings with air drag. We measure the angle theta and the angular speed omega, and we want a law for the angular acceleration. Units first. The angle is a pure number. Omega has units of one over time. The target has units of one over time squared. A conservative language: plus, minus, times, and the sine of the angle, which is allowed because the angle is a pure number. It already contains the classic law: minus c one times the sine of theta, minus c two times omega. And the units assign every constant a physical type. c one must carry one over time squared. c two must carry one over time. A broader language adds absolute value and division. Now minus c three times omega times the absolute value of omega becomes reachable: air drag that grows with the square of the speed. Here c three turns out to be a pure number. That's more expressive, but the space is bigger, and division brings new questions about dividing by zero. Broader is justified only when your question needs those alternatives. Before searching, also declare the equivalence policy. Sort commutative arguments, collect constants, drop zeros and ones. And never cancel omega over omega, because omega is zero at every turning point. Declare the complexity weights now as well, not after you've seen the winners. Here's the checklist to write down before any run: the terminals, the operators with their arities and domains, the unit rules, the constant strategy, the size limits, the simplification and equivalence rules, the complexity measure, and any special building blocks. Report it like an apparatus. It matters as much as the optimizer's settings. So which representation should you choose? Trees are a strong default for compact laws in a few variables. Graphs help when pieces repeat. Grammars help when you know the roles of terms. Token sequences suit neural generators. And fixed libraries of terms suit problems where you already know the vocabulary. No representation is best for everything. Choose the one that exposes the structure your question is about.
Recap. Let's recap. Constants are continuous: fit them numerically, watch for redundancy, and snap them to famous numbers only with evidence. Equivalent formulas waste search unless you define sameness and remove duplicates carefully. And complexity depends on the language, so fix your measure in advance. In the lab, you'll test equivalence at random points, compare complexity measures, and design your own language. Next module: encoding physics and domain knowledge. See you there.
9:53Video 4 · 2.1Expressions as computational objectsWith six operators, our tiny language has about 8.9 billion formulas and fewer than 4% pass the unit check; units are a filter, not a validation.
9:30Video 5 · 2.2Constants, equivalence and complexityLeast squares reached the noise level in 6 evaluations where 1,000 random guesses did not; and the bell curve is simpler than a quadratic by node count, more complex by depth, and tied by weight.
Interactive lab
Expression workbench
Type a formula and see its tree, prefix and postfix strings, size measures and sharing. Mutate branches, test two formulas for equivalence, check units, and count what survives the unit rules.
Everything is computed in your browser from your own formulas; the counts are exact. Four challenges are checked as you go.
One formula, many objects
Type a formula with + − * / ^, the functions sin, cos, exp, log, sqrt and abs, numbers, and variable names. The page turns it into a tree and measures it. Everything runs in your browser.
Weights: + − × and leaves 1; ÷, √ and |·| 2; powers, sin, cos, exp and log 3. A graph with sharing stores repeated pieces once.
Sums need matching units; products add powers; sin, exp and log need a pure number inside. A free constant can take any unit.
Running…
The tree of A
Circles are operations, squares are variables and numbers.
- infix
- –
- prefix
- –
- postfix
- –
- B, prefix
- –
Same function?
Equal values on many random points suggest the same function on that range; one clear difference proves they differ.
–
Units of A
Give each variable its units. The check runs while the tree is built, before any evaluation.
–
How much do units remove?
Every formula with n operators from + − × ÷ and leaves x [L], t [T], v [L/T], c [pure number], counted exactly.
Challenges
Each one is checked on your current formulas and settings.
- Make A and B different trees (different prefix strings) that the test calls the same function.
- Type a formula of your own (not a preset) whose graph with sharing saves at least four nodes over its tree.
- Build a formula A that contains a sine or cosine and whose units come out as a speed, L/T.
- Set the operator count to the smallest size at which fewer than 5% of formulas pass the unit check.
