111. Formal languages
111.1 Definition: language
A language is a set of strings in some finite alphabet $A$.
111.1.1 Usage
a) In the research literature, this concept of language is often call “formal language”.
b) If $L$ is a language consisting of strings in $A^{*}$ for some finite alphabet $A$, then one says that $L$ is a “language in $A$”. This is common terminology but may be slightly confusing since in fact the elements of $L$ are not elements of $A$, they are elements of $A^{*}$.
111.1.2 Remark The definition says that a language is a subset of $A^{*}$. Note that the language may be infinite although the alphabet is finite.
111.1.3 Example The empty language is the set $\emptyset$. No strings are elements of the empty language.
111.1.4 Example Another example is the language $\{\Lambda\}$ whose only element is the empty string. It is important to distinguish this from the empty language $\emptyset$.
111.1.5 Example Another uninteresting language is the language $A^{*}$, containing as elements every string in the alphabet $A$.
111.1.6 Example The set $\{\text{‘01’},\text{‘011’},\text{‘1’}\}$ is a language in $\{ 0, 1\}$.
111.1.7 Example The set of strings in $\{ 0, 1\}^{*}$ with 1 in the second place is a language. Note that ‘0110’ is in the language but ‘1’ and ‘100’ are not in the language.
111.1.8 Example If $n$ is a positive integer, then $A^{n}$ denotes the set of strings in the alphabet $A$ of length $n$. Thus if $A =\{ 0, 1\}$, then $A^{2} =\{\text{‘00’},\text{‘01’},\text{‘10’},\text{‘11’}\}$. We take $A^{0} =\{\Lambda\}$. Note that $A^{1}$ is the set of strings of length 1 in $A$, and so is not the same thing as $A$.
111.1.9 Example The set $L$ of strings in $\{ 0, 1\}^{*}$ which read the same forward and backward is a language. For example, ‘0110’ $\in L$, but ‘10010’ $\notin L$. Such strings are called palindromes.
111.2 Theorem
For any alphabet $A$,
$$A^{*} =A^{0} \cup A^{1} \cup \cdots \cup A^{n}\cup \cdots \tag{111.1}$$
the union of the infinite sequence of languages $A^{0},A^{1},\ldots ,A^{n},\ldots$ .
Proof This follows from the fact that every string in $A^{*}$ has some length $n$.
111.2.1 Remark An element of $A^{*}$ is a string of finite length. $A^{*}$ contains as elements no infinite sequences of elements of $A$, although Equation (111.1) expresses it as the union of an infinite sequence of sets. This follows from the definition of “union”: to be in $A^{*}$ according to 111.1, an element has to be in $A^{n}$ for some integer $n$, so has to be a string of length $n$ for some $n$.
111.3 Inductive definition of languages
A language can sometimes be given an inductive definition paralleling the definition of $A^{*}$ given previously.
111.3.1 Example Let $L$ be the set of strings in $\{ 0, 1\}$ of the form $0^{k} 1^{k}$, for $k= 1$, 2, .... In other words, $L$ consists of Λ, ‘01’, ‘0011’, ‘000111’, ‘00001111’, and so on. Then $L$ can be defined by induction this way:
L.1 The empty string Λ is a string in $L$.
L.2 If $w \in L$, then ‘0’ $w$‘1’ $\in L$.
L.3 Every string in $L$ is given by one of the preceding rules.
111.3.2 Example The set $P$ of palindromes can be defined this way:
111.4 Definition: the set of palindromes
Let $A$ be a set.
PAL.1 The empty string Λ is a string in $P$.
PAL.2 If $a\in A$, then ‘$a$’ is a string in $P$.
PAL.3 If $w$ is a string in $P$ and $a \in A$, then $awa$ is a string in $P$.
PAL.4 Every string in $P$ is given by one of the preceding rules.
111.4.1 Remark Thus to show that ‘$abba$’ is a palindrome, we say that Λ is a palindrome by PAL.1, so ‘$bb$’ (which is ‘$b$Λ $b$’) is a palindrome by PAL.3, so ‘$abba$’, which is ‘$a$’‘$bb$’‘$a$’, is a palindrome by PAL.3.
111.4.2 Exercise Give inductive definitions of the following languages in the alphabet $\{a,b\}$:
a) The set of strings containing no $a$’s.
b) The set of strings containing exactly one $a$.
c) The set of strings containing exactly two $a$’s.
Pages 169–170 of the book (PDF).