Symbolic Physical Laws DiscoverySearch and data

Module 4Search and optimization

Equation space is huge and rough: one edit can change everything, and many change nothing. With the range of a thrown ball as the running example, we count the space exactly (729,657 trees up to eight nodes, 107,570 different candidates), enumerate it with pruning, and evolve formulas with genetic programming: selection, crossover, mutation, diversity and bloat. A race on one budget, repeated over 100 runs on five sets of throws, shows how much a single data set or ten seeds can mislead. Then the other families: token-by-token policies and tree search, pretrained and differentiable generators, constants fitted inside the loop, Pareto fronts, caching and quick checks, stopping rules, and how to compare searchers fairly.

By the end you should be able to explain how enumeration, genetic programming and sequential or learned searchers move through equation space, fit constants inside the loop, keep a Pareto front, and design a fair comparison with enough seeds, data sets and ablations.

Key ideas, one per video

  • Video 8On our first set of throws, genetic programming found the range law in 11 of 20 runs, random search in 3 and enumeration in none. Over 100 runs on five sets of throws it was 28 against 15, and switching crossover off gave 45: rank searchers on many runs, not one.
  • Video 9With fitted constants the right structure reaches the noise level (0.0225) and its scale, 0.1023, matches 1/g = 0.1019. Ten seeds made crossover look essential; 100 runs said otherwise. Compare searchers on equal terms, over many seeds and data sets.

Book: Chapter 4 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 4: Search and optimization

30 slides, written to be read on your own, with worked examples, our own small simulations and check-yourself questions (answers at the end). PDF, 1.5 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 8 · 9:12

Searching an enormous space

Sixty throws, one law hidden among hundreds of thousands of formulas, and three searchers with the same budget.

On our first set of throws, genetic programming found the range law in 11 of 20 runs, random search in 3 and enumeration in none. Over 100 runs on five sets of throws it was 28 against 15, and switching crossover off gave 45: rank searchers on many runs, not one.

TranscriptVideo 8
0:00

Sixty throws, three searchers. We throw a ball sixty times, at different speeds and angles, and measure how far it lands. Somewhere among hundreds of thousands of formulas is the range law. Who finds it, with ten thousand tries? Three searchers get the same budget: a blind random searcher, a careful enumerator that tries every formula from small to large, and an evolving population of formulas. By the end of this video you'll know who won, and how much to trust the answer. This is Module four: search and optimization. Part one: the shape of the problem. Part two: searching systematically, with pruning. Part three: genetic programming, the evolutionary workhorse.

0:45

Why search is hard. Formally, we want the structure and the constants that minimize the error plus a complexity penalty. Even restricted versions of this problem are known to be computationally hard. So every practical solver bets on some structure: bounded size, good priors, useful building blocks, or learned proposals. And judging a solver by its smallest training error is a trap. A flexible approximation can win on error and still miss the law. Large comparisons show it too: solvers differ in accuracy, in the size of their formulas, and in how often they recover the exact law, and their ranking changes with the benchmark and the metric. Solvers come in families. Enumerators list formulas by complexity. Genetic programming evolves a population. Sequential methods build a formula token by token, guided by a policy or a tree search. Neural generators propose formulas after pretraining. And differentiable methods relax the choice of operators into something continuous. What separates them is the search policy: the rule that decides where the computing effort goes. Which candidates get generated, refined or thrown away, and when to stop.

1:50

The shape of the space. Part one: the space. Our language has four binary operations, sine and cosine, and three leaves: the speed v, the angle theta, and the number one. Every candidate also gets a fitted scale and offset, so overall constants come for free. Counted exactly, there are 729,657 trees with at most eight nodes. Most repeat each other: once a scale and offset are allowed, they describe only about 108,000 different candidates, roughly one in seven. The range law, v squared times the sine of twice theta, needs eight nodes: v times v, times the sine of theta plus theta. And this space isn't smooth. One edit can change everything, many edits change nothing, and good formulas sit on narrow ridges between wide plateaus. Picture the neighbours of a formula: change one leaf, swap one operator, replace one branch. From v times v, a single swap gives v plus v, a completely different curve. From v times v times one, removing the one changes nothing at all.

2:54

Systematic search and pruning. Part two: systematic search. List candidates in order of complexity, and evaluate each one. Its great virtue is honesty: up to the size you reached, nothing was missed. And it can be pruned. Check syntax, types and units before evaluating. Drop candidates that repeat a function already tried. Bound the size. Screen out variables that don't matter. Guard against division by zero. Order the checks from cheap to expensive: syntax, then units, then a quick numerical check, then fitting constants, then the full data, and only then slow simulation tests. Each stage is a filter with a price. A pruning rule is worth it only when it saves more than it costs, and when the assumption behind it can be defended. Our enumerator skips repeats, so ten thousand evaluations cover every candidate up to six nodes, and part of the seven-node ones. The range law is number 68,655 on its list. So the enumerator is certain to find it, but only after almost seven times the budget. Enumeration can certify that nothing simpler exists. It struggles as soon as the law is a few nodes bigger. Enumeration is most useful inside bigger systems: to search small pieces, to seed a population, or to prove that nothing simpler exists below some size. Pruning has a dark side. A rule that removes the true law turns a belief into an invisible theorem. No amount of optimization brings it back. So record every pruning rule as part of the method, and rerun important discoveries with the rules relaxed.

4:24

Genetic programming. Part three: genetic programming. Start with a population of random formulas. Pick parents that fit well. Make children by swapping subtrees between two parents, or by replacing a subtree with a fresh random one. Keep the best, and repeat. The first population is usually grown at several depths, some trees full and some irregular, so that it starts out diverse. Children replace their parents a whole generation at a time, or one by one, and the best can be kept unchanged. Our version: two hundred formulas, ten thousand evaluations, tournaments of four, crossover four times out of five, and the best formula always survives. Every design choice matters: how the first formulas are grown, how parents are chosen, how children are made, who survives, how diversity is kept, and how bloat is controlled. Here's one run. For a while the best error barely moves, near 0.4. Then it slips to 0.3, and after about four thousand four hundred evaluations it drops to 0.045. Later it reaches 0.0225, the noise level. The law itself is now in the population: v times the sine of theta plus theta, times v. Meanwhile the trees grow, from about four nodes on average to about sixteen. And the population's diversity rises, then falls as one family takes over. Look inside good formulas from different runs. The same pieces keep coming back: v times v, and the sine of twice theta, or a sine times a cosine. Genetic programming bets that such pieces can be found apart, and joined by crossover. Pause. Two questions. Does crossover really help here? And does tougher selection, with bigger tournaments, help? Decide before we show you the numbers. We ran every setting a hundred times: five sets of throws, twenty seeds each. Tournaments of two found the law in 33 runs. Tournaments of four, in 28. Tournaments of ten, in 31. Differences that small are within the noise. And crossover? Without it, mutation alone found the law in 45 runs out of 100. With crossover, in 28. In this small language, swapping pieces between formulas did not pay off. We expected the opposite. On our first set of throws, ten seeds without crossover found the law only twice, and crossover looked essential. A hundred runs said otherwise. Small samples tell confident stories. Selection decides which errors count. Tournaments compare total error. Lexicase selection compares parents one data case at a time, in random order, so specialists that are excellent on a few cases survive. Diversity can be measured by the trees, or by what they compute. Semantic methods vary formulas by their behaviour, not just their syntax. And bloat, trees that grow without getting better, is controlled with size limits, with a pressure toward smaller formulas, or by keeping a Pareto front of error against size. Diversity has a structural side too: remove duplicates by hashing, keep niches apart by tree distance, and watch the share of the population that still differs.

7:25

Who won. So who won? On our first set of throws, with ten thousand evaluations and twenty seeds each, random search recovered the law in 3 runs, enumeration in none, and genetic programming in 11. Recovered means more than a good fit. The formula must predict throws faster than any in the data, to within two percent. The losers didn't fail quietly. Random search's best formulas fit to about fifteen percent of the spread, and enumeration's best within budget to about twenty four: decent curves, but not the law. Then we drew four more sets of throws: same law, new speeds, new noise. For genetic programming, the worst set gave one success in twenty. The best gave eleven. Over all hundred runs, random search found the law 15 times, and genetic programming 28 times. Enumeration, never. Genetic programming beat blind search here, but by less than one set of throws suggested, and its settings mattered in ways we did not expect. In another language, or with another budget, the ranking can change. That's the subject of the next video.

8:24

Recap. Let's recap. Symbolic regression is hard in general, so every solver exploits structure. Enumeration is honest and can certify, but runs out of budget fast. Pruning helps, as long as you record it. Genetic programming adapts, and it beat blind search over a hundred runs. But its success swung with the data, crossover did not pay off here, and its trees bloat. In the lab, you'll race these searchers yourself, on one budget. Next video: other ways to search, and how to compare them fairly.

Interactive lab

Search arena

Race random search, size-ordered enumeration and a small genetic program on one budget to recover the range of a thrown ball. Change the budget, seeds, tournament size, crossover and noise, and watch the best error, the recovery rate and the Pareto front.

The throws are simulated in your browser (R = v²·sin 2θ / g with small noise), and each searcher runs here too. Four challenges are checked against the runs you make.

Simple math

Sixty throws, three searchers

The page simulates 60 throws (speeds 5–15 m/s, angles 0.2–1.2 rad, small measurement noise) from the law R = v²·sin(2θ)/g. The searchers see only v, θ and the ranges, and may use + − × ÷ sin cos and the number 1; every candidate gets a fitted scale and offset. Everything runs in your browser.

Random search
draw, fit, keep the best

Random trees of depth 1 to 5, as many as the budget allows.

Enumeration
smallest first, no repeats

Every different candidate in order of size; repeats (equal up to scale and offset) are skipped. One run: it has no randomness.

Genetic programming
select · cross · mutate · keep the best

200 formulas, tournament selection, subtree crossover and mutation, size limit 21.

Choose settings and press Run.

Results

Errors are the misfit on the 60 throws, as a share of their spread.

Best error during the run (seed 1)

Grey: random search; orange: enumeration; blue: genetic programming.

Size against error (genetic programming, seed 1)

Grey: the final population. Blue: the Pareto front, the best formula of each size found during the run that beats every smaller one. Look for the knee.


            

Challenges

Each one is checked against the runs you have made.

  1. Raise the budget until enumeration recovers the law. How many evaluations did it need?
  2. Find settings where genetic programming without crossover recovers the law at least as often as with it (everything else the same).
  3. Find a tournament size that recovers the law less often than tournaments of 4 (everything else the same).
  4. With at least 10 seeds, raise the noise until genetic programming never recovers the law, although it did at a lower noise with the same budget.