Random trees of depth 1 to 5, as many as the budget allows.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
Two thirds were repeats. Two thirds of the formulas our genetic programming evaluated had already been evaluated before. Search is full of waste, and fairness starts with counting it. In this video: building formulas one token at a time, learned and differentiable search, constants inside the loop, keeping several answers, speed-ups, when to stop, and how to compare searchers fairly. Last video, genetic programming beat blind search, by a margin that swung with the data. This video asks what else is possible, and how to make a race fair.
Sequential and tree search. Part one: sequential search. Instead of whole trees, build a formula one token at a time, in prefix order. Each partial formula is a state, and each next token is an action. A policy, often a neural network, gives probabilities to the next tokens. Reinforcement learning rewards it for good finished formulas, and risk-seeking variants learn only from the best few percent, because we want the best formula, not a good average. Monte Carlo tree search treats the same choices as a game tree. It balances exploiting branches that already look promising against exploring branches it hardly knows. And partial formulas can be checked early. A branch that already breaks the units, or can't close within the length limit, is pruned before it's finished. The hard part is credit assignment: a token chosen early only gets its reward when the whole formula is finished and fitted.
Learned and differentiable search. Part two: learned and differentiable search. A transformer pretrained on millions of synthetic formulas can propose candidates for new data in a fraction of a second. But that speed was paid for in advance, during pretraining, and its proposals lean toward the kinds of formulas it was trained on. Report both costs, and ask how far your data are from its training. Differentiable methods relax the discrete choice. Each node becomes a soft mixture of operators, with weights trained by gradient descent, then sharpened until one operator wins. The catch is the final rounding: the best soft mixture can be far from the best single formula. Always refit after discretizing. Many systems mix these ideas: a network proposes formulas, an evolutionary search refines them, and the network learns again from the refined results. Training data matter: if most training formulas were polynomials, a generator will keep proposing polynomials, even for a pendulum.
Constants inside the loop. Part three: constants. Structure and constants are coupled. A correct structure with bad constants looks wrong, and gets thrown away. Take the right structure for our throws, with random constants: its typical error is more than ten times the spread of the data. With fitted constants: 0.0225, the noise level. A wrong structure, v squared times theta, fitted just as carefully, still scores 0.67. And the fitted scale comes out as 0.1023. One over g is 0.1019. The fitted constant carries physics. So every candidate deserves a fair shot at its constants: linear least squares when they enter linearly, a few local steps otherwise, and restarts when the landscape is rough. Constant fitting has a price too. In many systems it takes most of the compute, so it belongs in the accounting when methods are compared.
Several answers: the Pareto front. Part four: keep several answers. Here's the final population of one run, as error against size. Its Pareto front has four members: v alone, v squared, the range law with eight nodes, and a nineteen-node formula that's better by a hair. The knee is obvious. From eight nodes to nineteen, the error drops by just two ten-thousandths, to 0.0223. That's noise, not physics. Choose from the front with held-out data and the checks from Module one, not with the training error. Some methods search the front directly, keeping error and complexity as separate objectives, sometimes with more: a physics residual, a smoothness score, or the error on held-out data.
Speed, stopping and reporting. Part five: speed. Most of the cost is evaluation, so the tricks are about evaluating less. Cache results: two thirds of our candidates were repeats. Take a quick look first: a check on ten of the sixty points would have flagged 37 percent of candidates as hopeless before the full evaluation. Vectorize, compile, and run in parallel, but remember that the slowest serial part limits any speed-up. Even the timing of evaluations matters. Asynchronous workers don't wait for a whole generation to finish, and that changes the evolution itself, not just the speed. Simplify before you evaluate: when two candidates reduce to the same canonical form, one evaluation serves both. Part six: when to stop, and what to report. Stop on a budget, on a front that has stopped improving, or on a target error. And state which one in advance. Report the language, the budget in evaluations and in time, the number of seeds, the constant fitting, the simplification rules, the full Pareto fronts, and the success rate across seeds, not just the best run. Watch diagnostics while it runs: the front over time, the population's diversity, the share of duplicates, and how often constant fitting fails. They tell you whether a search is stuck, or just slow. And seeds belong in the report: with the same seed and the same software, anyone should get exactly your front. One lucky seed is an anecdote. Many seeds, on several sets of data, are evidence. Pause. One searcher returns its answers in a second, another takes an hour. Is the first one cheaper? Think about what might be hidden. Not necessarily. The fast one may have spent weeks pretraining. A fair comparison counts offline and online cost separately, and reports both. Hardware counts too: a run on many processors and a run on one are different budgets, even with the same number of evaluations. Memory and engineering count as well. A method that needs a cache of millions of formulas, or a specialised compiler, carries costs that a count of evaluations never shows.
A fair comparison. Part seven: a fair comparison. Give every searcher identical data, language, constant fitting, budget, and number of seeds. Then measure several things: how often each recovers the true structure, not just a good fit; error on held-out and extrapolated data; complexity; time to the first success; and how much effort went to repeats. Then remove pieces, and use enough runs. On one set of throws and ten seeds, removing crossover looked like a disaster: two successes. Over a hundred runs, it was the best setting we tried: 45 successes. With crossover, 28. A claim that one method is better is incomplete until it says: better at what, on which problems, and with which budget. Run a version without constant fitting, and one without removing duplicates. The differences show how much of the success came from the search itself, and how much from the machinery around it. Summarize with several views, not one winning number: error against time, the final fronts, and recovery rates across seeds. And state the scope. Our arena had two variables, one law and sixty throws. A real study needs several problems, noise levels and held-out regions before a ranking means much. Our own runs show why. With identical settings, standard genetic programming succeeded in only one seed out of twenty on one set of throws. On another set, it succeeded in eleven.
Recap. Let's recap. Sequential and tree-search methods build formulas token by token. Learned generators are fast, but carry their training with them. Differentiable search must be rounded, and refit. Constants need a fair fit inside the loop. Several answers should be kept on a Pareto front. And speed comes from evaluating less: caching, quick checks, parallel work. And compare searchers on equal terms, across many seeds. In the lab, you'll do exactly that. Next module: scientific data, noise, and experimental design.
9:12Video 8 · 4.1Searching an enormous spaceOn 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.
8:17Video 9 · 4.2Other ways to search, and a fair comparisonWith 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.
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.
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.
Every different candidate in order of size; repeats (equal up to scale and offset) are skipped. One run: it has no randomness.
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.
- Raise the budget until enumeration recovers the law. How many evaluations did it need?
- Find settings where genetic programming without crossover recovers the law at least as often as with it (everything else the same).
- Find a tournament size that recovers the law less often than tournaments of 4 (everything else the same).
- 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.
