Motivation

To reason precisely about computation, we encode objects as finite strings over a fixed alphabet. Problems can then be represented as languages, and solving a problem becomes deciding whether an input word belongs to a language.

Definitions

  • alphabet: an alphabet is any non-empty, finite set of symbols.
    • binary alphabet:
    • decimal digits:
    • lowercase letters:
  • word: a word over an alphabet is a finite sequence of symbols from .
    • example:
    • empty word: with
  • is the set of all finite words over .
    • is infinite if , but every word in it is finite.
  • is the set of all non-empty words over .

Length and occurrences

For a word , is the number of symbols in . Examples:

  • for ,

For and , is the number of occurrences of in . Example:

  • for , and

Number representation

Let .

For , is the binary expression of without leading zeros.

Examples:

Order on words

Let with .

The canonical order or shortlex order on orders words by:

  1. length first
  2. lexicographic order among words of the same length Formally:

Algebra of Words

Concatenation

Concatenation places one word after another:

Example:

  • , , then

Properties:

  • associative:
  • neutral element: Therefore is a monoid

Reverse

Let .

Examples:

Important property:

Iteration

Let and . The -th iteration of is:

  • for

Example:

  • if , then

Deconstruction of Words

Let for an alphabet .

  • is a subword or substring of if:
  • is a prefix of if:
  • is a suffix of if:

Languages: Sets of Words

A language over an alphabet is any subset of .

Examples:

  • is the set of all syntactically correct Java programs over the keyboard alphabet.
  • is a language.
  • is a language.

Problems as languages

Languages are used to formally represent decision problems. Example:

  • primality testing can be represented as the membership problem for
  • input: a word
  • question: is ? Similarly, a compiler checks whether a source file is in the language of syntactically valid programs.

Algebra of Languages

Since languages are sets, the standard set operations apply:

  • union:
  • intersection:
  • complement:

Concatenation of languages

For languages :

Example:

Duplicates disappear because languages are sets.

Powers of languages

For a language :

Important distinction:

but for :

Kleene star and Kleene plus

The Kleene star of a language is:

It means: zero or more concatenations of words from .

The Kleene plus is:

It means: one or more concatenations of words from . Relation:

Algebraic Laws for Languages

Concatenation distributes over union

This holds because a word on the left has the form where and , so is in or .

Concatenation does not distribute over intersection

In general:

The inclusion

holds, but the reverse inclusion can fail because the same word may have different decompositions.