What are the paths to create a grammar of a specified type? For example, how do I define a type 3 grammar for the language of the strings on the alphabet {a,b} that contain an odd number of "a".
2026-04-05 14:54:04.1775400844
How do you create a grammar?
63 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2

Wikipedia has a nice article on Formal grammar.
And here is a type $3$ grammar to deal with your example:
$S \to a$
$S \to bS$
$S \to Sb$
$S \to aSa$
$S \to Saa$
$S \to aaS$
An easy proof by induction on the number of applied rules shows that only strings with an odd number of $a$'s can be constructed. On the other hand, every such string is obtainable: Let $x$ be a counterexample of minimal length. By the rule $S \mapsto bS$, the leftmost character of $x$ must be $a$. By $S \mapsto Sb$ the last character of $x$ must be $a$. Write $x = aya$. Then $y$ has an odd number of $a$'s and, by the minimality of $x$, can hence be constructed. But then $S \mapsto aSa$ witnessed that $x$ can be constructed as well. Contradiction!
Note that this proof also shows that the rules $S \mapsto Saa$ and $S \mapsto aaS$ are not actually required. Something that I didn't notice until I went through the motions.