Skip to content
Part IA Michaelmas, Lent Term

Formal Languages

Definition

A formal language (or just language) over alphabet Σ\Sigma is any subset LΣL \subseteq \Sigma^*.

Intuition

A language is specified by giving the “words in the dictionary” - the strings that belong to it.

Examples

LanguageAlphabetDescription
\emptysetanyEmpty language (no strings)
{ε}\{\varepsilon\}anyLanguage containing only the empty string
Σ\Sigma^*Σ\SigmaAll strings over Σ\Sigma
{anbn:n0}\{a^n b^n : n \geq 0\}{a,b}\{a, b\}Equal numbers of aa‘s and bb‘s
${w :w\text{ even}}$

Operations on Languages

Union

L1L2={w:wL1wL2}L_1 \cup L_2 = \{w : w \in L_1 \lor w \in L_2\}

Intersection

L1L2={w:wL1wL2}L_1 \cap L_2 = \{w : w \in L_1 \land w \in L_2\}

Complement

Lc=ΣL={wΣ:wL}L^c = \Sigma^* \setminus L = \{w \in \Sigma^* : w \notin L\}

Concatenation of Languages

Definition

L1L2={uv:uL1vL2}L_1 \cdot L_2 = \{uv : u \in L_1 \land v \in L_2\}

Properties

  • Identity: L{ε}=L={ε}LL \cdot \{\varepsilon\} = L = \{\varepsilon\} \cdot L
  • Associativity: (L1L2)L3=L1(L2L3)(L_1 \cdot L_2) \cdot L_3 = L_1 \cdot (L_2 \cdot L_3)
  • Distributive over union: L1(L2L3)=(L1L2)(L1L3)L_1 \cdot (L_2 \cup L_3) = (L_1 \cdot L_2) \cup (L_1 \cdot L_3)

Special Cases

  • L==LL \cdot \emptyset = \emptyset = \emptyset \cdot L
  • {ε}L=L\{\varepsilon\} \cdot L = L

Kleene Star

Definition

The Kleene star of language LL is:

L=n0Ln={ε}LL2L3L^* = \bigcup_{n \geq 0} L^n = \{\varepsilon\} \cup L \cup L^2 \cup L^3 \cup \cdots

where Ln=LLLn timesL^n = \underbrace{L \cdot L \cdot \ldots \cdot L}_{n \text{ times}}.

Alternative Definition

LL^* is the smallest language containing {ε}\{\varepsilon\} and LL, closed under concatenation.

Examples

  • {a}={ε,a,aa,aaa,}\{a\}^* = \{\varepsilon, a, aa, aaa, \ldots\}
  • {a,b}=Σ\{a, b\}^* = \Sigma^* if Σ={a,b}\Sigma = \{a, b\}
  • ={ε}\emptyset^* = \{\varepsilon\} (only the empty string)
  • {ε}={ε}\{\varepsilon\}^* = \{\varepsilon\}

Kleene Plus

L+=LL=L{ε}=n1LnL^+ = L \cdot L^* = L^* \setminus \{\varepsilon\} = \bigcup_{n \geq 1} L^n

Language Properties

Finite vs Infinite Languages

A language is finite if L<|L| < \infty, otherwise infinite.

Examples:

  • {a,aa,aaa}\{a, aa, aaa\}: finite (3 elements)
  • {an:n0}\{a^n : n \geq 0\}: infinite

Decidable Languages

A language LL is decidable if there is an algorithm that determines whether any wΣw \in \Sigma^* belongs to LL.

Closure Properties

Languages are closed under:

OperationResult
UnionL1L2L_1 \cup L_2
IntersectionL1L2L_1 \cap L_2
ComplementLcL^c
ConcatenationL1L2L_1 \cdot L_2
Kleene starLL^*

Special Languages

The Empty Language

L=L = \emptyset: contains no strings.

Note: {ε}\emptyset \neq \{\varepsilon\}.

The Universal Language

L=ΣL = \Sigma^*: contains all strings.

Singleton Languages

L={w}L = \{w\}: contains exactly one string.


Summary

  • A formal language is any subset LΣL \subseteq \Sigma^*
  • Operations: union, intersection, complement, concatenation, Kleene star
  • L=n0LnL^* = \bigcup_{n \geq 0} L^n is the Kleene closure
  • Languages form a Boolean algebra under \cup, \cap, complement