On this page:
End-of-class Surveys
In-Class Exercises
1 November 16, 2020:   Turing Machines and Recursion
2 Oct 5, 2020:   Context-free Grammars (CFGs)
2.1 Context-free Grammar Exercise
2.2 Solution
2.3 Solution Explained
3 Sept 28, 2020:   Regular Expressions and Homomorphisms
3.1 Regular Expressions
3.2 Homomorphism Definition
3.3 Homomorphism Closure
3.4 Proof of Homomorphism Closure
4 Sept 14, 2020:   DFAs
4.1 Question
4.2 Answer

Lecture Extra

This page will include any extra material from lectures.

End-of-class Surveys

Latest End-of-class Survey: Mon 12/7

Latest Presentations Survey:

Previous:

In-Class Exercises

1 November 16, 2020: Turing Machines and Recursion

Here is Racket the code I developed in class. It shows that, even though it’s not obvious how, the states-and-transitions definition of Turing machines we’ve been studying in class is sufficient for modeling computation via recursive programs.

See if you can do the equivalent in your favorite language!

2 Oct 5, 2020: Context-free Grammars (CFGs)

2.1 Context-free Grammar Exercise

Give a CFG for the language \{w\mid w\textrm{ starts and ends with the same symbol}\}, where \Sigma = \{\texttt{0},\texttt{1}\}.

2.2 Solution

G = (V,\Sigma,R,S), \textrm{ where } V = \{T,C^\prime,C\}, \Sigma = \{\texttt{0},\texttt{1}\}, S = T, \textrm{ and } R =

T \rightarrow \texttt{0}C^\prime\texttt{0} \mid \texttt{1}C^\prime\texttt{1}\mid \varepsilon

C^\prime \rightarrow C^\prime C\mid\varepsilon

C \rightarrow \texttt{0}\mid\texttt{1}

2.3 Solution Explained

3 Sept 28, 2020: Regular Expressions and Homomorphisms

3.1 Regular Expressions

We proved that a language is regular if and only if some regular expression describes it.

Recall the formal definition (Def 1.52) of Regular Expressions from the textbook:

R is a regular expression if R is:
  1. a for some a\in\textrm{alphabet }\Sigma,

  2. the empty string \varepsilon,

  3. the empty set \emptyset,

  4. R_1 \cup R_2, sometimes written R_1\mid R_2, where R_1 and R_2 are regular expressions,

  5. R_1 \circ R_2, sometimes written R_1R_2, where R_1 and R_2 are regular expressions,

  6. R_1^*, where R_1 is a regular expression.

3.2 Homomorphism Definition

Define a homomorphism to be a function H:\Sigma\rightarrow \Gamma from one alphabet to another.

We overload H to also operate on:
  • any string w: H(w) = H(w_1)\ldots H(w_n), where w = w_1\ldots w_n, and each w_i\in\Sigma;

  • any language A: H(A) = \{H(w)\mid w\in A\};

  • and any regular expression R: H(R) = H(L(R)), where L(R) is the language described by R.

3.3 Homomorphism Closure

Homomorphisms are closed under regular languages.

In other words, for any language A, if A is regular, then H(A) is also regular.

3.4 Proof of Homomorphism Closure

Since we know that a language is regular if and only if some regular expression describes it, we will prove that homomorphisms are closed under regular languages by induction on the definition of regular expressions.

The proof has six cases:

  1. Base case 1: a regular expression a\in\Sigma describes the language \{a\}, so H(a) describes the language \{H(a)\}, which is regular because it’s finite;

  2. Base case 2: H(\varepsilon) = \varepsilon, which describes the regular language \{\varepsilon\};

  3. Base case 3: H(\emptyset) = \emptyset, which describes the regular language \{\};

  4. Inductive step 1: We must show that H(R_1 \cup R_2) is regular.

    Inductive hypothesis (IH): We may assume that H(R) is regular to prove that H(R^\prime) is regular, for R^\prime larger than R.

    • H(R_1 \cup R_2) = H(R_1) \cup H(R_2), from the definition of homomorphisms above;

    • H(R_1) and H(R_2) are regular, by the IH;

    • then H(R_1) \cup H(R_2) is regular, because union is closed under regular languages;

    • therefore H(R_1 \cup R_2) is regular.

  5. Inductive step 2: We show that H(R_1 \circ R_2) is regular, using the same steps as the union case.

  6. Inductive step 3: We show that H(R_1^*) is regular, using the same steps as the union case.

\blacksquare

4 Sept 14, 2020: DFAs

4.1 Question

Design a DFA M that recognizes language A:

A = \{w\mid w\textrm{ has exactly three } 1\textrm{s}\}

Assume \Sigma = \{0,1\}.

Recall Definition 1.5 from the book: a DFA is a 5-tuple (Q,\Sigma,\delta,q_0,F), where:
  • Q is a finite set called the states,

  • \Sigma is a finite set called the alphabet,

  • \delta:Q\times\Sigma\rightarrow Q is the transition function,

  • q_0\in Q is the start state, and

  • F\subseteq Q is the set of accept states.

4.2 Answer