# Ewolucja gramatyczna (programy budowane z reguł gramatyki)

EN: **Grammatical evolution** · id `grammaticalevolution` · aliases: grammatical evolution, GE, ewolucja gramatyczna

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [Obliczenia ewolucyjne i inteligencja roju](https://aiatlasgraph.com/t/evolutionary.md) › [Klasyczne algorytmy ewolucyjne](https://aiatlasgraph.com/t/evoclassic.md) › [Programowanie genetyczne i regresja symboliczna](https://aiatlasgraph.com/t/geneticprogramming.md) › Ewolucja gramatyczna (programy budowane z reguł gramatyki)

## Description

- PL: Programowanie genetyczne z mapowaniem genotyp–fenotyp przez gramatykę bezkontekstową w notacji BNF, ewoluujące programy w dowolnym języku.
- EN: Genetic programming with a genotype–phenotype mapping through a context-free grammar in BNF notation, evolving programs in an arbitrary language.

## In one sentence

- PL: Odmiana programowania genetycznego, w której ciąg liczb wybiera kolejne reguły gramatyki, więc powstają zawsze poprawnie zbudowane programy lub wzory.
- EN: A kind of genetic programming where a string of numbers picks successive grammar rules, so the result is always a well-formed program or formula.

## Problem it solves

- PL: Losowo zmieniany kod zwykle przestaje się kompilować, a każdy język wymaga innego, specjalnego algorytmu ewolucyjnego.
- EN: Randomly changed code usually stops compiling, and each language would need its own special evolutionary algorithm.

## What it does

- PL: Jak gra w układanie zdań z kostek: rzut wskazuje, którą część zdania wstawić, a reguły gwarantują, że zdanie będzie poprawne.
- EN: Like a sentence-building dice game: each roll picks which part of speech to insert, and the rules guarantee a grammatical sentence.

## Everyday example

- PL: Analityk szuka wzoru na zużycie prądu w fabryce i podaje dozwolone działania; algorytm składa z nich czytelne równania pasujące do pomiarów.
- EN: An analyst looking for a formula for factory power use lists allowed operations; the algorithm assembles readable equations from them that fit the measurements.

## This concerns you if you…

- PL: chcesz ewolucyjnie tworzyć kod w wybranym języku
- PL: potrzebujesz wzorów zgodnych z zadanymi regułami
- PL: znasz już zwykłe programowanie genetyczne
- EN: want to evolve code in a language of your choice
- EN: need formulas that follow given rules
- EN: already know plain genetic programming

## Keywords

BNF grammar · PonyGE2 · GRAPE · structured grammatical evolution · SGE · codon · genotype-phenotype mapping · bloat

## How it works

- PL: Genotyp to ciąg liczb całkowitych zmiennej długości. Przy rozwijaniu wyprowadzenia gramatyki kolejny kodon modulo liczba alternatyw wybiera regułę produkcji dla bieżącego symbolu nieterminalnego. Operatory działają na prostym ciągu, a gramatyka zapewnia poprawność składniową i pozwala wprowadzić wiedzę dziedzinową.
- EN: The genotype is a variable-length integer string. While expanding a grammar derivation, the next codon modulo the number of alternatives picks a production rule for the current non-terminal. Operators act on the plain string, and the grammar guarantees syntactic correctness and injects domain knowledge.

## Limits

- PL: Mała zmiana wczesnego kodonu potrafi przebudować cały program, co osłabia lokalność przeszukiwania. Wynik mocno zależy od projektu gramatyki, a programy mogą się rozrastać bez poprawy jakości.
- EN: A small change in an early codon can rebuild the whole program, weakening search locality. Results depend heavily on grammar design, and programs can bloat without improving.

## Key terms

- PL: **BNF**: Sposób zapisu reguł gramatyki języka.
- PL: **kodon**: Liczba w genotypie wybierająca jedną regułę gramatyki.
- PL: **wrapping**: Ponowne czytanie genotypu od początku, gdy zabrakło kodonów.
- EN: **BNF**: A notation for writing a language's grammar rules.
- EN: **codon**: A number in the genotype that selects one grammar rule.
- EN: **wrapping**: Reading the genotype again from the start when codons run out.

## Know first

- [Algorytmy genetyczne (Genetic algorithms (GA))](https://aiatlasgraph.com/t/geneticalgorithms.md)

## Sources

- [Grammatical Evolution](<https://gpbib.cs.ucl.ac.uk/gp-html/oneill_2001_TEC.html>) `oneill-ryan-ge-2001` · by Michael O'Neill, Conor Ryan

---

AI Atlas revision 122 (2026-10-30) · HTML: https://aiatlasgraph.com/t/grammaticalevolution · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-10-30
