Preface

Every programmer has felt this wish: show the machine a few examples of what you want, and let it write the code. Program synthesis makes that idea precise. You give a system examples, a specification, a grammar, or a proof obligation. It searches through candidate programs, tests each one, and returns something you can run.

The returned artifact is the whole point. It is not a table of weights and not a nearest-neighbor guess. It is a program: short enough to read, executable on inputs not seen in a training run (the out of sample issue with machine learning), and checkable against a formal specification. When the system in Chapter 8 rediscovers Kepler’s third law from six noisy measurements, it returns a law, not a curve fit. A law holds everywhere. A curve fit holds where you sampled.

This book builds the machinery behind that result, and it builds it with you, in code you can read in an afternoon and run in a second. Here is the plan:

  • Chapters 1 and 2 (Part I) lay the foundation: logic, unification, inference, knowledge representation, and a precise statement of the synthesis problem.
  • Chapters 3 and 4 (Part II) give you the two classical engines. Inductive synthesis learns programs from examples with enumeration, version spaces, evolutionary search, and the version space algebra behind Excel’s Flash Fill. Deductive synthesis derives programs from specifications with proof extraction, SAT and SMT constraints, CEGIS, and syntax-guided search.
  • Chapters 5 and 6 (Part III) join the engines. You will see exactly why deep learning alone cannot extrapolate or compose, and how a learned proposer, the role a large language model (LLM) plays in today’s synthesis systems, speeds up search without weakening its guarantees. Then you build miniature versions of four real neurosymbolic architectures: Logic Tensor Networks, Logical Neural Networks, NeurASP, and differentiable ILP.
  • Chapters 7 and 8 (Part IV) attack the frontier problems. Chapter 7 takes on generalization: systems that build libraries from their own discoveries, adapt at test time, and acquire new skills autonomously. Chapter 8 points the machinery at science: hypothesis generation, data-efficient equation discovery, causal reasoning, the Kepler case study, and the LLM-plus-checker systems (FunSearch, AlphaEvolve, AlphaGeometry, AlphaProof) that have found new mathematics.
  • Chapter 9 (Part V) asks the question that keeps the field honest: how do we know a system generalizes rather than memorizes? You will build ARC-style and SCAN-style tests and a leaderboard that reports the generalization gap, then read the real ARC-AGI results against them. The book closes with an appendix of essential tools (Z3, CVC5, Rosette, Sketch, clingo, LTNtorch) and where to take each chapter’s ideas at full scale.

Every example is a complete Racket program. The code runs on a stock installation of Racket 8.x or newer with no external packages, and each program prints a trace of its own search, so you can watch hypotheses rise and fall rather than take results on faith. Racket earns its place here for a simple reason: a synthesizer treats programs as data, and Lisp descendants make that natural. A few dozen lines of Racket are enough to hold a real algorithm, all of it visible.

The book asks little of you in advance. If you can write a recursive function, you can read every chapter. Students will find the classical algorithms explained by working code rather than by prose alone. Working programmers will find techniques with a track record in industry, from Flash Fill-style example programming to solver-based synthesis. Researchers will find that the small systems here contain the seeds of the large ones: every example in this book has a published relative that runs a thousand times faster and a million times larger.

Why this subject, and why now? Deep learning gave machines perception. That achievement is real, and this book does not minimize it. But perception is one half of intelligence. The other half is the old symbolic dream: learn a rule from two examples, state it exactly, apply it correctly on the hundredth case, and compose it with everything you already know. A child does this. Benchmarks such as ARC exist because our best LLM-based systems still struggle with it. The strongest results on ARC so far come from hybrids: an LLM proposes, a search explores, and a check against the examples decides. The systems that close the gap will likely need both halves: neural networks to perceive a noisy world and propose likely answers, and symbolic engines to reason about those proposals and verify them. This book teaches the symbolic half in full and shows where the neural half plugs in.

That gap is also the opportunity. The techniques in this book fit in your head. The open problems are concrete: better abstractions, better search, better ways to let gradients flow through logic. You now hold the tools to think about and work on them, one small runnable program at a time.

Run the examples. Change a grammar and watch a law fail to appear, then fix it and watch it emerge. Reading about synthesis is useful; running it is more convincing.