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.

By the end you should be able to store and measure formulas in several representations, write a grammar with unit rules, fit and question constants, define equivalence for your problem, and declare a complexity measure in advance.

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.

The title slide of Module 2: Mathematical languages for symbolic models

43 slides, written to be read on your own, with worked examples, our own small simulations and check-yourself questions (answers at the end). PDF, 2.1 MB.

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
0:00

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.

0:52

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.

2:19

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.

2:54

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.

6:18

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.

8:58

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.

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.

Simple math

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.

Trees and strings
(x − 2) × y → × − x 2 y

Prefix writes each operator first, postfix last. Neither needs parentheses.

Size, three ways
nodes · depth · weighted

Weights: + − × and leaves 1; ÷, √ and |·| 2; powers, sin, cos, exp and log 3. A graph with sharing stores repeated pieces once.

Units as types
[L] + [T] ✗

Sums need matching units; products add powers; sin, exp and log need a pure number inside. A free constant can take any unit.

Nodes (tree)
–
Nodes (graph with sharing)
–
Depth
–
Weighted
–

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.

4

Challenges

Each one is checked on your current formulas and settings.

  1. Make A and B different trees (different prefix strings) that the test calls the same function.
  2. Type a formula of your own (not a preset) whose graph with sharing saves at least four nodes over its tree.
  3. Build a formula A that contains a sine or cosine and whose units come out as a speed, L/T.
  4. Set the operator count to the smallest size at which fewer than 5% of formulas pass the unit check.