AI Glossary / Graphs and symbolic AI / Advanced
Genetic programming
Definition
Genetic programming is an evolutionary computation approach that searches for programs or executable expressions. It evaluates a population of candidates and uses selection and variation to create new candidates, aiming to solve a task defined by a fitness measure.
What it means
The object being evolved is itself a program. In a common representation, the program is a tree whose internal nodes are operations and whose leaves are inputs or constants. For example, an expression can combine addition, multiplication and a variable x.
A person still defines the available building blocks, how candidates are evaluated and when the search stops. Genetic programming does not discover a complete business objective from an unspecified wish. It searches within the language and evaluation environment provided.
The approach is related to genetic algorithms, but its emphasis is program structure rather than only a fixed collection of parameter values. Tree-based programs are common, although they are not the only possible representation.
How it works
Specify permitted functions, terminals, input and output requirements, and the fitness procedure. Generate initial candidate programs and evaluate their behavior on the task's cases.
Selection identifies candidates for further use. Crossover can exchange subtrees between programs; mutation can replace or change a selected part. Type constraints can prevent incompatible combinations, such as feeding a Boolean value into an operation that requires a numerical input.
The resulting programs require fresh evaluation. Practical searches also manage invalid operations, execution cost and excessive program growth. A large expression can fit examples well while being difficult to inspect or unreliable on new cases. Fitness, complexity controls and held-out evaluation therefore influence which program should be retained. Producing executable syntax is only one part of producing a useful result.
Three practical examples
- A symbolic-regression experiment searches mathematical expressions that describe a measured relationship.
- A simulation study evolves a small decision rule for selecting actions from a constrained set of observations.
- A software-research exercise evolves short programs against test cases, then independently checks the resulting candidates.
Think of it this way
Think of rearranging a box of permitted sentence fragments into instructions, testing each draft and keeping useful constructions for the next round.
The analogy highlights structured recombination. Real programs require precise syntax, types and execution semantics; a plausible arrangement of fragments does not guarantee correct behavior. The evaluation must detect the mistakes that matter for the task.
Worked example
Evaluating and changing an expression tree
Suppose the permitted ingredients are addition, multiplication, input x and constant 1. The teaching target is y = x² + 1. Evaluate candidates at x = 0, 1 and 2, where the target outputs are 1, 2 and 5. Define fitness as mean squared error, with smaller values preferred.
Candidate A is x + 1, producing 1, 2 and 3. Its squared errors are 0, 0 and 4, so its mean squared error is 4/3.
Candidate B is x × x, producing 0, 1 and 4. Its squared errors are 1, 1 and 1, giving mean squared error 1.
A subtree replacement in A can replace its left-hand x with the multiplication subtree x × x from B. The resulting expression is (x × x) + 1. It produces all three target outputs and has zero error on these cases.
This particular expression also matches the stated target algebraically, but zero error on three examples alone would not prove that fact. Another expression might agree at those inputs and disagree elsewhere. A search evaluated only on the examples needs additional evidence before claiming general correctness.
Illustrative case study
The fictional Maple Formulas team explores compact expressions for an internal simulator's output. It provides arithmetic building blocks and scores candidates on a selected set of simulator runs.
One expression has excellent training error but is much larger than competing candidates. The team inspects it, evaluates it at reserved inputs and compares both accuracy and expression size. It also defines what happens when a candidate requests an invalid operation rather than allowing such behavior to distort the score.
Maple treats the chosen expression as a candidate surrogate whose useful range must be established. The case illustrates evaluation beyond training fitness; it does not report discovery of a physical law or claim that evolved programs are automatically interpretable.
Common misconceptions and mistakes
- Genetic programming is just changing numerical coefficients. It can change a program's structure as well as constants, depending on the representation.
- Every evolved program is understandable. Unrestricted expressions can become large or complicated.
- Passing the fitness cases proves general correctness. A finite test set normally supports a narrower claim.
- The system requires no human specification. Building blocks, fitness, constraints and stopping conditions all shape the search.
Business use
The approach can be useful when an explicit expression or compact decision procedure is valuable and a reliable evaluator is available. It may also expose alternative structures that a fixed-form model would not consider.
Before using a result, examine its behavior across the intended input range, its complexity and the assumptions embedded in allowed operations. Record the search budget and compare against simpler models. If runtime behavior matters, test that directly rather than assuming a short-looking expression is cheap. For consequential use, independently review the final program instead of treating evolutionary fitness as a substitute for acceptance criteria.
People also ask
Is genetic programming the same as an AI coding assistant?
No. Genetic programming specifically uses evolutionary search over candidate programs; a coding assistant may use very different mechanisms.
Why use typed building blocks?
They can prevent some structurally invalid combinations, although type correctness does not establish task correctness.
What is program bloat?
It is growth in program size without a corresponding useful improvement in fitness, a concern addressed by various size-control techniques.
Check your understanding
Why does the worked expression's zero error on three cases not, by itself, prove it works for every x?
Answer: The test covers only three inputs. Agreement elsewhere requires further evidence, such as the direct algebraic comparison available in this deliberately simple example.
Related terms
- Genetic algorithms
- Evolutionary computation
- Symbolic regression
- Fitness function
- Genetic algorithm
- syntax tree
- subtree crossover
- program synthesis
- program bloat
Learn next
Add subtraction to the permitted operations and construct a different expression that matches the three training inputs but differs at x = 3. Use the exercise to explain the difference between fitting examples and establishing a general relationship.
More in Graphs and symbolic AI
- Generalization hierarchy - A generalization hierarchy organizes concepts or descriptions from more specific to more general.
- Generalization loss - Generalization loss is a model's expected loss on examples drawn from the target data distribution.
- Generalized modus ponens - Generalized modus ponens is a first-order logic inference rule that derives a conclusion when known facts match all premises of an implication under a...
- Gestalt pattern matching - Gestalt pattern matching, also called Ratcliff/Obershelp pattern recognition, is a string-similarity approach that finds matching contiguous blocks and...
- Gittins index - The Gittins index is a priority value for an individual option, or arm, in a classical discounted multi-armed bandit problem.
- GLIE - GLIE stands for greedy in the limit with infinite exploration.
Sources
Koza's project tutorial describes genetic programming's preparatory choices and evolutionary operations: https://www.genetic-programming.com/gpanimatedtutorial.html
The DEAP developers document expression trees, typed primitives and practical program-generation considerations: https://deap.readthedocs.io/en/master/tutorials/advanced/gp.html
The expression arithmetic and Maple Formulas case are original examples. The historical tutorial is used for method description, not current capability or adoption claims.
Previous: Genetic fuzzy systems Next: Geo-replication