Regular Languages

COS2601 - Theoretical Computer Science II · Automata Theory

Regular Languages

A language is called a regular language if it can be defined by a regular expression. Regular languages are important in computer science and automata theory. They can be recognised by finite automata and described using regular expressions, transition graphs, or transition tables.

Definition of Regular Languages

A regular language can be defined using the following methods:

  • Regular Expressions: A formal way to describe a set of strings using symbols and operators.
  • Finite Automata: A computational model that accepts or rejects strings based on its state transitions.
  • Transition Graphs: A visual representation of finite automata showing states and transitions.

Closure Properties of Regular Languages

Regular languages have several important closure properties. These properties describe how regular languages behave under certain operations. The main closure properties are:

  • Union: If L1 and L2 are regular languages, then L1 + L2 (the union of L1 and L2) is also a regular language.
  • Concatenation: If L1 and L2 are regular languages, then L1L2 (the concatenation of L1 and L2) is also a regular language.
  • Kleene Closure: If L1 is a regular language, then L1* (the language of all strings that can be formed by concatenating zero or more strings from L1) is also a regular language.

Theorem 10

If L1 and L2 are regular languages, then L1 + L2, L1L2, and L1* are also regular languages.

This theorem can be proven using regular expressions or finite automata. For example, if L1 and L2 can be described by regular expressions r1 and r2, then:

  • The regular expression for L1 + L2 is (r1 + r2).
  • The regular expression for L1L2 is (r1r2).
  • The regular expression for L1* is (r1*).

Example of Regular Languages

Consider the following languages:

  • L1: All words of two or more letters that begin and end with the same letter.
  • L2: All words that contain the substring aba.

We can represent these languages using regular expressions:

  • For L1, the regular expression could be: a(a + b)*a + b(a + b)*b.
  • For L2, the regular expression could be: (a + b)*aba(a + b)*.

The union of L1 and L2, denoted L1 + L2, is also a regular language. It can be defined by the regular expression:

[a(a + b)*a + b(a + b)*b] + [(a + b)*aba(a + b)*].

Finite Automata and Regular Languages

Finite automata are machines that accept or reject strings based on their states. There are two main types of finite automata:

  • Deterministic Finite Automata (DFA): In a DFA, for each state and input symbol, there is exactly one transition to the next state.
  • Nondeterministic Finite Automata (NFA): In an NFA, for a given state and input symbol, there can be multiple possible transitions to different states.

Example of Finite Automata

Let us consider a simple DFA that accepts the language L1 described earlier. The states of the DFA could be defined as follows:

  • State q0: Start state, where no input has been read.
  • State q1: The first letter has been read.
  • State q2: The last letter read is the same as the first letter.
  • State q3: The last letter read is different from the first letter.

The transitions could be defined as:

  1. From q0, reading 'a' goes to q1.
  2. From q0, reading 'b' goes to q1.
  3. From q1, reading 'a' goes to q2.
  4. From q1, reading 'b' goes to q3.
  5. From q2, reading 'a' goes to q2.
  6. From q2, reading 'b' goes to q3.
  7. From q3, reading 'a' goes to q2.
  8. From q3, reading 'b' goes to q3.

The final state for acceptance could be q2, indicating that the string begins and ends with the same letter.

Self-Check Questions

Check your understanding

  • What are the main closure properties of regular languages?
  • How can you represent a regular language using finite automata?
  • What is the difference between a DFA and an NFA?
  • Provide an example of a regular expression and explain what language it represents.
    Regular Languages – COS2601 - Theoretical Computer Science II notes | Tyro Study