cs2200

Types of grammar:

  1. Right linear
  2. Context free
  3. unrestricted

Types of machine models:

  1. finite memory: finite automata, regex
  2. finite memory with stack: pushdown automata
  3. unrestricted: turing machines, post systems, λ calculus etc.

There is a one to one correspondence for the numberings above.

Gödel’s incompleteness theorem: No matter how strong a deductive system is, there are always statements that are true but unprovable.

Strings and Sets

Decision problem is a function that has a one bit output: true or false, 1 or 0.

To completely specify a decision problem, specify a set of possible inputs, and the subset for which the output is true.

Encoding the input of a decision problem as a fixed finite length string is possible over some fixed finite alphabet.

A finite alphabet is any finite set. A finite length string is a sequence of the elements.

Set ops for two sets:

  • Union
  • Intersection
  • Complement over set of all strings: Basically, it depends on the set of all strings that is chosen and hence this is often written as ΣA\Sigma^* — A to emphasize this.
  • Concatenation of two sets: AB={xyxA;yB}AB = {xy | x \in A; y \in B}.

Set ops on one set:

  • asterate A* of a set. A=n0AnA^* = \bigcup_{n\geq 0}A^n
  • A+ of a set. A+=n1AnA^+ = \bigcup_{n \geq 1}A^n.

States and transitions

A state of a system gives all the relevant information of a system, like a snapshot. Transitions are changes of states.

If both are finite, then the system is called a finite state transition system. We model them using finite automata.

Deterministic Finite Automata

Formally,

M=(Q,Σ,δ,s,F)M = \left(Q,\Sigma,\delta,s,F\right)

  • Q is the finite set of states.
  • Σ\Sigma is the finite set of the input alphabet.
  • δ\delta is the transition function that takes the current state and the input character as the inputs and gives the next state as the output.
  • s is the start state.
  • F is the finite subset of Q that are acceptable as the final states.

To extend the character input to a string, we define δ^\hat{\delta} inductively as follows:

  • δ^(q,xa)=δ(δ^(q,x),a)\hat{\delta}\left(q, xa\right) = \delta\left(\hat{\delta}\left(q, x\right), a\right)
  • δ^(q,ϵ)=q\hat{\delta}\left(q, \epsilon\right) = q

Where xx is a string, aa is a character, and ϵ\epsilon is the empty input.

These can also be translated to the finite state machines discussed here.

A string xx is accepted by an automation MM if

δ^(s,x)F\hat{\delta}\left(s,x\right) \in F

A set or a language accepted by MM is the set of all strings accepted by some automata MM, also called L(M)L(M). Any subset of Σ\Sigma^* is said to be regular if it is accepted by some automaton MM.

Any finite subset of Σ\Sigma^* is regular (brute-force all strings).

Proof that union of two regular languages is regular:

Let DFA 1 be (Q1,Σ,δ1,s1,F1)\left(Q_1, \Sigma, \delta_1, s_1, F_1\right) and DFA 2 be (Q2,Σ,δ2,s2,F2)\left(Q_2, \Sigma, \delta_2, s_2, F_2\right)

The final automata has the cartesian product of the two sets of states as the set of states (Q), and the delta is also from Q1×Q2Q_1 \times Q2 to Q1×Q2Q_1 \times Q2 . The set of final states is Q1×F2Q2×F1Q_1\times F_2 \cup Q_2 \times F_1. Also, δ^((s1,s2),w)=(δ^(s1,w),δ^(s2,w))\hat{\delta}\left(\left(s_1, s_2\right), w\right) = \left(\hat{\delta}\left(s_1, w\right),\hat{\delta}\left(s_2, w\right)\right)

Proof the the complement of a regular language is also regular:

All accepted final states become non-accepted, while all non-accepted final states become accepted.

Proof that the intersection of two regular languages is also regular:

Using set properties (De Morgan’s Law), or instead follow the proof of union and replace the final set with F1×F2F_1 \times F_2.

Non-deterministic Finite Automata

A finite automata where the next state is not necessarily determined by the current state, and the input symbol. It is effectively in a state of guessing.

To show that an automata accepts a set BB, we argue that there exists a lucky sequence of guesses that lead from the start state to an accept state when the end of xBx\in B is reached, but for any string outside the set, it is impossible.

Formally,

M=(Q,Σ,Δ,S,F)M = \left(Q,\Sigma,\Delta,S,F\right)

  • Q is the finite set of states.
  • Σ\Sigma is the finite set of the input alphabet.
  • Δ\Delta is the transition function that takes the current state and the input character as the inputs and gives the next state as the output. In this case, there are 2Q2^Q possible outputs, instead of the QQ possible outputs in case of DFA. Each output corresponds to a unique element in the power set of QQ.
  • S is the subset of acceptable states called the start states.
  • F is the finite subset of Q that are acceptable as the final states.

To define the acceptance, we use the following rules:

Δ^(A,ϵ)=A\hat{\Delta}\left(A,\epsilon\right) = A

Δ^(A,xa)=qΔ^(A,x)Δ(q,a)\hat{\Delta}\left(A, xa\right) = \bigcup_{q\in \hat{\Delta}\left(A,x\right)} \Delta\left(q,a\right)

Instead of the usual one state, we have the input to be a subset of the possible state for Δ^\hat{\Delta}.

Acceptance happens when xΣx \in \Sigma^* satisfies Δ^(S,x)Fϕ\hat{\Delta} \left(S,x\right) \cap F \neq \phi

Proof for Deterministic and Non-deterministic Finite Automata being equivalent:

  • First we prove that Δ^(A,xy)=Δ^(Δ^(A,x),y)\hat{\Delta}\left(A, xy\right) = \hat{\Delta}\left(\hat{\Delta}\left(A, x\right), y\right)

Induction on |y|:

For |y| = 0, it is trivially true from the above equations.

Assume for |y| ≤ n,

Δ^(A,xya)=qΔ^(A,xy)Δ(q,a)=qΔ^(Δ^(A,x),y)Δ(q,a)=Δ^(Δ^(A,x),ya) \begin{align*} \hat{\Delta}\left(A, xya\right) &= \bigcup_{q\in \hat{\Delta}\left(A,xy\right)} \Delta\left(q,a\right) \ & = \bigcup_{q\in \hat{\Delta}\left(\hat{\Delta}\left(A,x\right),y\right)} \Delta\left(q,a\right) \ & = \hat{\Delta}\left(\hat{\Delta}\left(A,x\right),ya\right) \end{align*}

  • Second, the function Δ^\hat{\Delta} commutes with the set union, i.e., Δ^(iAi,x)=iΔ^(Ai,x)\hat{\Delta}(\bigcup_i A_i,x) = \bigcup_i \hat{\Delta}(A_i, x)

Induction on |x|:

For |x| = 0, it is trivially true.

Assume for |x| ≤ n.

Δ^(iAi,xa)=Δ^(Δ^(iAi,x),a)=Δ^(iΔ^(Ai,x),a)=iΔ^(Δ^(Ai,x),a)=iΔ^(Ai,xa) \begin{align*} \hat{\Delta}\left(\bigcup_i A_i, xa\right) & = \hat{\Delta}\left(\hat{\Delta}\left(\bigcup_i A_i,x\right),a\right) \ & = \hat{\Delta}\left(\bigcup_i\hat{\Delta}\left(A_i, x\right),a\right) \ & = \bigcup_i \hat{\Delta}\left(\hat{\Delta}\left(A_i , x\right), a\right) \ & = \bigcup_i\hat{\Delta}\left(A_i, xa\right) \end{align*}

Now the following two automata can be shown to accept the same set.

(Q,Σ,Δ,S,F)=(2Q,Σ,Δ^,S,{AAQ,AFϕ})\left(Q, \Sigma, \Delta, S, F\right) = \left(2^Q, \Sigma, \hat{\Delta}, S, { A | A \subseteq Q, A \cap F ≠ \phi} \right)

To create a minimal DFA from an NFA, check the decision tree for the NFA and do a BFS, stopping when you don’t get any new states.

ϵ\epsilon transition

This has an ϵ\epsilon slip that allows the state to transition without reading any input symbol.

Proof that ϵ\epsilon transition NFA’s have an equivalent NFA with just one start state and no ϵ\epsilon transitions.

Defn: ϵ\epsilon closure: The set of all states that a state can reach on an ϵ\epsilon transition.

Define a new transition function such that the states attained by the state with ϵ\epsilon transitions further take one symbol.

For an ϵ\epsilon NFA to be converted to a regular NFA, we define

Δ(q,σ)=qϵ(q)Δ(q,σ)\begin{align*} \Delta'\left(q,\sigma\right) = \bigcup_{q'\in \epsilon(q)} \Delta\left(q', \sigma\right) \end{align*}

where ϵ(q)\epsilon(q) is the ϵ\epsilon closure of q.

The final states

F={qϵ(q)Fϕ} F' = {q | \epsilon(q)\cap F \neq \phi}

Everything else remains the same.

Pattern Matching

  • aa for each aΣa \in \Sigma, matched by aa only.
  • ϵ\epsilon, matched by the empty string.
  • ϕ\phi, matched by nothing.
  • #, matched by any symbol in Σ\Sigma.
  • @@, matched by anything in Σ\Sigma^*.

Combining patterns

  • xx matches α+β\alpha + \beta if xx matches either of those.
  • xx matches αβ\alpha\cap\beta if xx matches both of them.
  • xx matches αβ\alpha\beta if xx matches α\alpha followed by β\beta.
  • xx matches α˜~\alpha if it doesn’t match α\alpha.
  • xx matches α\alpha^* and α+\alpha^+ the same way as regex.

NOTE:
(0+1)\left(0 + 1\right)^* accepts 010101
0+1 0^* + 1^* accepts 000000 or 111111 but only strings of one symbol

For any pattern RR, we define L(R)L(R) to be the language that matches the pattern RR.

Any regular language can have countably infinite representations in form of patterns.

Theorem: If RR is a regular expression, then L(R)L(R) is regular.

Proof: Check for each possible case and all of them can be decomposed into a combination of the above situations.

It is always possible to remove the complement in a regular expression.

DFAs to Regex

  • State elimination
    • Keep remaining states
    • Replace transitions with transitions labelled as regex.
    • while true

Class

Theorem: Set of all C Programs is countable.

Proof:

Represent the ascii source code in binary. Then it will be a subset of {0,1}{0,1}^* and that is bijective with the natural numbers (n(b)+2b1n(b) + 2^{|b|} -1). It is also obviously infinite.

Hilbert’s Entscheidungs Problem: Given a mathematical statement, is it derivable from the axioms?

Defn: A language LL over an alphabet Σ\Sigma is a subset of Σ\Sigma^*.

Theorem: The cardinality of all the languages over some alphabet is uncountably infinite, i.e., P(L)>N\left|\mathcal{P}\left(L\right)\right| > \left|\mathbb{N}\right|.

Proof:

Cantor’s argument:

Set of all languages = P({0,1})\mathcal{P}\left({0,1}^*\right)

inputϵ\epsilon0100
f(ϵ\epsilon)1001
f(0)1000
f(1)0000
f(01)1101

The entries in the table tell whether that particular element is present in the subset is gotten from the result or not.

Take the diagonal and bit flip all bits. It will differ from all the strings in the table by atleast one bit.

Go to top till Deterministic Finite Automata along with a few examples of languages based on the problem.

Limits of DFAs

  • DFAs have finite memory.
  • They can also only read one symbol at a time from left to right.

For instance, there is no way of constructing a DFA that can accept L={0n1nnN}L = {0^n1^n | n \in \mathbb{N}}.

Similarly, there is no DFA that can accept the language L={02nnN}L = {0^{2^n}| n \in \mathbb{N}}

Important Proof

If LL is regular, where L={wwwΣ}L = {ww | w \in \Sigma^* }, then L\sqrt{L} is also regular.

Proof:

Let the DFA be (Q,Σ,δ,q0,F)\left(Q, \Sigma, \delta, q_0, F\right). We define the NFA as follows:

N=(Q×Q×Q,Σ,Δ,A,f)N = \left(Q \times Q \times Q, \Sigma, \Delta, A, f\right)

where

A=iQ(i,q0,i)f=iQzF(i,i,z)Δ((i,α,β),a0)=(i,δ(α,a0),δ(β,a0))\begin{align} A &= \bigcup_{i\in Q} {\left(i, q_0, i\right)} \ f &= \bigcup_{i \in Q\atop z\in F} {\left(i, i, z\right)} \ \Delta\left(\left(i, \alpha, \beta\right), a_0\right) &= \left(i, \delta\left(\alpha, a_0\right), \delta\left(\beta, a_0\right)\right) \end{align}

Pumping Lemma

Let LL be a regular language. k>0\exists k > 0, s.t. x,y,z\forall x,y,z s.t. xyzLxyz \in L and y>k|y| > k, u,v,w\exists u,v,w s.t. y=uvw,vϵy = uvw, v\ne \epsilon s.t. i0,xuviwzL\forall i \geq 0, xuv^iwz \in L.

Proof: M=(Q,Σ,δ,q0,F)\exists M = \left(Q, \Sigma, \delta, q_0, F\right) s.t. L(M)=LL\left(M\right) = L.

Set k=Qk = |Q|

Let x,y,zΣx,y,z \in \Sigma^* s.t. y>k|y| > k & xyzLxyz \in L

δ^(q0,x)=qδ^(q,y)=qδ^(q,z)F\begin{align*} \hat{\delta}\left(q_0, x\right) &= q & \hat{\delta}\left(q, y\right) &= q' & \hat{\delta}\left(q', z\right) & \in F & \end{align*}

y=y1y2...yr,r>ky = y_1y_2…y_r, r> k. We define qi=δ^(q,y1y2...yi)q_i = \hat{\delta} \left(q, y_1y_2…y_i\right)

Consider the sequence q1q2q3...qrq_1q_2q_3…q_r

    s,t\implies \exists s, t s.t. qs=qtq_s = q_t in the sequence (by PHP).

Define

u=y1y2...ysu = y_1y_2…y_s

v=ys+1ys+2...ytv = y_{s+1}y_{s+2}…y_t

w=yt+1yt+2...yrw = y_{t+1}y_{t+2}…y_r

δ^(q0,x)=qδ^(q,u)=qsδ^(qs,v)=qs    δ^(qs,vi)=qsδ^(qs,wz)F\begin{align} \hat{\delta}\left(q_0, x\right) &= q \ \hat{\delta}\left(q, u\right) &= q_s \ \hat{\delta}\left(q_s, v\right) &= q_s \implies \hat{\delta} \left(q_s, v^i\right) = q_s \ \hat{\delta}\left(q_s, wz\right) &\in F \end{align}

An analogy with a 2 player game:

Prover: I’ll give you a number k

Spoiler: I’ll find x, y, z such that the concatenation is in the language with length of y > k

Prover: I’ll split y into u, v, w where v is non-empty.

Spoiler: I’ll find an i > 0 such that the pumping lemma string doesn’t belong in the DFA. If I do that, I’ll win. And L will not be regular.

An alternate way to prove that a language is not regular.

Suppose you take a DFA for the language. We take an infinite set of strings such that all of them go to a different state. Then it’s obvious that the DFA cannot be finite and hence, it is not a DFA.

Example:

L={0n1nn0}M=(Q,Σ,δ,q0,F)L=L(M)W={0ii0}\begin{align} L &= {0^n1^n | n \ge 0} \ M &= \left(Q, \Sigma, \delta, q_0, F\right) \ L &= L\left(M\right) \ W &= {0^i | i \ge 0} \end{align}

We claim that any two strings in WW reach a different state.

Proof:

δ^(q0,0i)δ^(q0,0j)ijδ^(q0,0i1i)=δ^(δ^(q0,0i),1i)δ^(δ^(q0,0j),1i)\begin{align} \hat{\delta}\left(q_0, 0^i\right) &\ne \hat{\delta}\left(q_0, 0^j\right) \forall i \ne j \ \hat{\delta}\left(q_0, 0^i1^i\right) &= \hat{\delta}\left(\hat{\delta} \left(q_0, 0 ^i\right), 1^i\right) \ &\ne \hat{\delta}\left(\hat{\delta}\left(q_0, 0^j\right), 1^i\right) \end{align}

If this wasn’t true then both the strings will be accepted, which is impossible according to the language.

Distinguishability

Defn: Let LΣL \subseteq \Sigma^ be a language. Two strings x,yΣx,y \in \Sigma^ are said to be distinguishable by LL if zΣ\exists z \in \Sigma^* s.t. xzLxz \in L and yzLyz \notin L.

Defn: A set SS is distinguishable if ijS\forall i \ne j \in S and ii and jj are distinguishable.

Theorem: Let LΣL \subseteq \Sigma^* be a regular language and SS be a distinguishable set. For any DFA accepting LL, QS\left|Q\right| \ge \left|S\right|.

Myhill-Nerode Relations

An equivalence relation \equiv over a language LΣL \subseteq \Sigma^* is said to be a Myhill-Nerode relation if

  1. \equiv is a right congruence, i.e., if xyx \equiv y, then xσyσσΣx\sigma \equiv y\sigma \forall \sigma \in \Sigma.
  2. \equiv is a refinement of LL, i.e., if xyx\equiv y then xL    yLx\in L \iff y\in L.
  3. \equiv is of finite index.

If LL is regular and M=(Q,Σ,δ,q0,F)M = \left(Q,\Sigma, \delta, q_0, F\right) accepts M, then M\equiv_M is a Myhill-Nerode relation. It is trivial to see why this is the case.

We define M\equiv_M to be the equivalence relation gotten when any two strings end up in the same equivalence class in the language accepted by MM i.e. δ^(q0,x)=δ^(q0,y)\hat{\delta}\left(q_0, x\right) = \hat{\delta}\left(q_0, y\right).

We define L\equiv_L to be the equivalence relation gotten when any two strings xx and yy s.t. zΣ,xzLyzL\forall z \in \Sigma^*, xz \in L \Longleftrightarrow yz \in L.

Theorem: Let \equiv be an MH relation over LL.

Then L\equiv \subseteq \equiv_L.

Proof:

x,y,xyσΣ,xσyσzΣ,    (xzL    yzL)    xLy\begin{align} &\forall x,y, x\equiv y \ &\forall \sigma \in \Sigma, x\sigma \equiv y\sigma \ &\forall z \in \Sigma^* , \implies \left(xz \in L \iff yz\in L\right) \ &\implies x\equiv_L y \end{align}

Minimizing DFAs and Isomorphism

Let M=(Q,Σ,δ,s,F)M = \left(Q,\Sigma, \delta, s, F\right) and M=(Q,Σ,δ,s,F)M' = \left(Q', \Sigma, \delta', s', F' \right)

Let f:QQf: Q\rightarrow Q' be a bijection such that the following hold:

  1. s=f(s)s' = f(s)
  2. qFf(q)Fq\in F \Longleftrightarrow f(q) \in F'
  3. f(δ(q,σ))=δ(f(q),σ)qQ,σΣf(\delta(q,\sigma)) = \delta'(f(q), \sigma) \forall q \in Q, \sigma \in \Sigma

Theorem: If MM and MM' are two minimal automatas then they are isomorphic.

Proof:

We define the function f1:QQf^{-1}: Q' \rightarrow Q to be δ^(s,x)\hat{\delta}(s, x)

Algorithm to minimize the DFA:

States q,qMq, q' \in M are equivalent if xΣ,δ^(q,x)Fδ^(q,x)F\forall x\in \Sigma^*, \hat{\delta} (q,x) \in F \Longleftrightarrow \hat{\delta}(q', x) \in F

This is clearly an equivalence relation for the states.

Show that the Myhill-Nerode relation of the Quotient Automata M/M_{/\approx} is a superset of the other. Hence the quotient automata is the minimal one.

Algorithm:

Mark any two pairs of states that are clearly not equivalent (one of them is a final state, other is not).

Repeat until no new pairs are marked

If {p,q}\exists {p,q} s.t. for some σΣ\sigma \in \Sigma, {δ(p,σ),δ(q,σ)}{\delta(p,\sigma), \delta(q,\sigma)} are marked then mark {p,q}{p,q}

Go to pattern matching

Context free languages

Productions: A kind of statement that tells you substitution rule.

Non-terminal strings are strings that can be replaced using productions.

Terminals are ones that can’t be further replaced.

Therefore, CFG is a 4 tuple that is defined using (N,Σ,P,S)\left(N, \Sigma, P, S\right)

  • NN is the set of non-terminals (RHS in any production).
  • Σ\Sigma set of terminals
  • PP set of production girls
  • SS start symbol

E.g. L={0n1nn0}L = {0^n1^n| n \ge 0}

S0S1ϵS \rightarrow 0S1 | \epsilon

  • A string β(NΣ)\beta \in (N \bigcup \Sigma^* ) is derivable from α(NΣ)\alpha \in (N\bigcup \Sigma)^* if there is a production rule to substitute a non-terminal in α\alpha and get β\beta.
  • A string in (NΣ)(N\bigcup\Sigma)^* is known as a sentential form if it is derivable from S.
  • A string in Σ\Sigma^* is a sentence if it is derivable from SS.

Example: Dyck language (balanced parentheses)

[[][[]][[]]] is in L but []] is not

S[S]SSϵS \rightarrow [S] | SS | \epsilon

Theorem: For a regular language LL, there exists grammar GG s.t. L=L(G)L = L(G)

Construction:

M=(Q,Σ,δ,q0,F)L(M)=LN={SiqiQ}SiσSjδ(qi,σ)=qjqiF    Siϵ\begin{align} \exists M = \left(Q,\Sigma, \delta, q_0, F\right) \ L(M) = L \ N = {S_i | q_i \in Q} \ S_i \rightarrow \sigma S_j \forall \delta(q_i, \sigma) = q_j \ q_i \in F \implies S_i \rightarrow \epsilon \ \end{align}

Further proof:

  1. L(M)L(G)L(M) \subseteq L(G)

if δ^(qi,w)=qj\hat{\delta}\left(q_i, w\right) = q_j then SiS_i goes to wSjwS_j

Base case: δ^(qi,ϵ)=q0\hat{\delta}(q_i, \epsilon) = q_0 then SiSiS_i \rightarrow S_i

δ^(qi,σ)=qj\hat{\delta}(q_i, \sigma) = q_j then \exists productions SiσSjS_i \rightarrow \sigma S_j

  1. L(G)L(M)L(G) \subseteq L(M)

induct on the length of the derivation

Ambiguous CFGs

These are those for which there are more than one parse trees. It is ambiguous if it has more than one leftmost derivation. Use multiple rules to resolve amiguousness.

However some languages are inherently ambiguous.

aibjckdli=jk=li=lj=ka^ib^jc^kd^l | i = j \land k = l \lor i = l \land j = k

basically no possible grammar can make it unambiguous.

Closure properties

Closed under union, concatenation, kleene closure.

NOT CLOSED under intersection and complementation.

Chomsky Normal form

A CFG G is in CNF if every production is of the form ABCA\rightarrow BC or AσA\rightarrow \sigma

CNF grammars do not generate ϵ\epsilon

  • Remove AϵA\rightarrow \epsilon

    • For every production BαAβB\rightarrow \alpha A\beta, add BαβB\rightarrow \alpha\beta
  • Remove ABA\rightarrow B

    • BβB\rightarrow \beta with AβA\rightarrow \beta

First remove all the ϵ\epsilon productions as they give more unit productions.

Then remove all unit productions.

This gives the minimum size grammar in CNF.

Pumping Lemma

This is based on the fact that (almost) all languages are convertible to CNF. If we have a path from the root node SS to a leaf node in the parse tree that is greater than n+1n +1, i.e., w>2n+1|w| > 2^{n+1} where ww is the length of the string and nn is the number of non-terminals in the productions.

By PHP, we can clearly see that a symbol is going to be repeated. So we can repeat the entire length in the path, and the parse tree will still be valid. This is the pumping we do.

For every CFL L,k>0L, \exists k > 0 s.t. zL\forall z \in L s.t. zk,u,v,w,x,y|z| \ge k, \exists u,v,w,x,y s.t. z=uvwxyz = uvwxy with vxϵvx \ne \epsilon and vwxk|vwx| \le k s.t. i0uviwxiyL\forall i \ge 0 uv^iwx^iy \in L.

Contrapositive form:

If k>0,zL;zk\forall k > 0, \exists z \in L; |z| \ge k s.t. u,z,w,x,y\forall u,z,w,x,y with vxϵvx \ne \epsilon and vwxk|vwx \le k s.t. z=uvwxyz=uvwxy, i0\exists i\ge 0 s.t. uviwxiyLuv^iwx^iy \notin L then L is not context—free.

Prover and Spoiler:

  • Prover picks k > 0

  • Spoiler chooses the string zz

  • Prover chooses a split that he wants

  • Spoiler finds the i for which pumped string is outside the language.

Parsing Algorithms for CFGs — Cocke Kasami Younger

Assumptions: G is in CNF

Goal: Given wΣw \in \Sigma^* , check if S * w S \xrightarrow{\text{ * }} w

w=w1w2w3wnw = w_1w_2w_3\dots w_n

A,B\exists A, B s.t. SAB,A * w1w2wi,B * wi+1wi+2wnS\rightarrow AB, A \xrightarrow{\text{ * }} w_1w_2 \dots w_i, B \xrightarrow{\text{ * }} w_{i+1} w_{i+2} \dots w_n for some 1in1 \le i \le n

Try out all possible choices of ii and check if AA and BB match. This is done recursively.

Push Down Automata (non-deterministic)

Basically and NFA with a stack and a stack alphabet.

M=(Q,Σ,Γ,δ,s,,F)M = \left(Q, \Sigma, \Gamma, \delta, s, \perp, F\right)

These are in the order = start state, alphabet of the string, alphabet of the stack (string alphabet + non-terminals), transition function, initial state of the stack, and the final states.

δ(Q×Σ{ϵ}×Γ)×(Q×Γ)\delta \subseteq \left(Q\times \Sigma\cup {\epsilon}\times \Gamma\right) \times \left(Q\times \Gamma^*\right)

If (q,σ,A),(q,B1B2B3Bk)δ\left(q, \sigma, A\right), \left(q', B_1B_2B_3\dots B_k\right) \in \delta then we read σ\sigma from the string, pop AA from the stack, and push all of B1B2BkB_1B_2\dots B_k

If (q,ϵ,A),(q,B1B2B3Bk)δ\left(q, \epsilon, A\right), \left(q', B_1B_2B_3\dots B_k\right) \in \delta Read nothing but do the pushing and the popping.

Acceptance happens when it reaches a final state on reading the entire string.

Alternatively, empty stack acceptance happens when the string becomes empty and makes the stack empty as well.

Converting CFGs to PDAs

G=(N,Σ,P,S)G = \left(N, \Sigma, P, S\right)

Define Γ=NΣ{}\Gamma = N\cup\Sigma\cup{\perp}

For a production AαA \rightarrow \alpha, add stack transition ϵ,Aα\epsilon, A \rightarrow \alpha

Add transition ϵ,S\epsilon, \perp \rightarrow S

Add transition σ,σϵ\sigma, \sigma \rightarrow \epsilon

This PDA obviously accepts the CFG using empty staack acceptance as a basis.

Converting from PDAs to CFGs

TL;DR: Absolute pain in the ass

If you have a PDA with a single state that accepts using an empty stack:

If ((q,σ,A),(q,B1B2Bk))δ\left(\left(q,\sigma, A\right), \left(q, B_1B_2\dots B_k\right)\right) \in\delta then add the production AσB1B2BkA\rightarrow\sigma B_1B_2\dots B_k

Nothing pushed on the stack case needs to be handled separately.

To convert a general PDA with a single final state to a PDA that accepts with the empty stack:

Let M=(Q,Σ,Γ,δ,s,,{f})M = \left(Q, \Sigma, \Gamma, \delta, s, \perp, {f}\right)

We define M=(q,Σ,Γ,δ,{q},(s,,f),ϕ)M' = \left({q}, \Sigma, \Gamma', \delta', {q}, \left(s, \perp, f\right), \phi\right)

Here Γ=Q×Γ×Q\Gamma' = Q\times\Gamma\times Q

Over here, both the Q’s are guesses for us, and we keep on guessing the entire sequence of things that are happening and put it on the stack. So we have an exponential number of items pushed onto the stack.

Suppose you are at state pp with σ\sigma on the input string and the contents on the top of the stack were AA. You transition to qq and the stack is now B1B2BkB_1B_2\dots B_k. For each of those you add a guess to the new PDA stack with surrounding states pB1q1pB_1q_1 and so on upto qk1Bkqkq_{k-1}B_kq_k. Here qkq_k is equal to qq.

Effective Computability

Multiple notions of effective computability:

  • λ\lambda calculus
  • μ\mu recursive functions
  • Turing Machines

Church Turing thesis: Any physically reaslisable computationally device can be simulated by a Turing machine.

Turing Machines

M=(Q,Σ,Γ,,,δ,s,t,r)M = \left(Q, \Sigma, \Gamma, \vdash, \circ, \delta, s, t, r\right)

These are in the order state, string alphabet, tape alphabet, left end of the tape, blank symbol on the tape, transition, accept state and reject state.

δ:Q×ΓQ×Γ×{L,R}\delta: Q\times \Gamma \rightarrow Q\times\Gamma\times{L,R} where the first parentheses denotes the current state and the current symbol under the tape.

The right parentheses tells you the next state to go to, and the symbol to be written, and whether to move left or right.

Constraints:

  • If you are on the left delimiter of the tape you can only move to the right.
  • If you are on the accept/reject states, you are stuck there.

Configurations of a Turing Machine: Q×Γ×NQ\times \Gamma^* \times \mathbb{N}. These are, in order, current state, tape content, and the position of the tape head.

  • Initial contents are (s,x,0)\left(s, \vdash x, 0\right)
  • Acceptance happens when (s,x,0) * (t,y,m)\left(s,\perp x, 0\right) \xrightarrow{\text{ * }} \left(t, y, m\right)
  • Rejection happens when (s,s,0) * (r,y,n)\left(s, \perp s, 0\right) \xrightarrow{\text{ * }} \left(r, y, n\right)

An accepted language by a turing machine is called recursively enumerable (re). If it is a total turing machine then it is called recursive.

A total turing machine is one that eithers accepts a string or rejects a string. There is no string on which it never accepts and never rejects. (Basically loops forever on the tape)

A Multi tape turing machine, as it sounds, is a Turing Machine with multiple tapes. It is also possible to simulate a multi tape turing machine using a Turing Machine with a single tape.

Rough outline of how it happens:

  • The number of tapes is kk, and the number of states is SS, and the size of the alphabet is Σ|\Sigma|.
  • Our new Turing Machine has Σk\left|\Sigma\right|^k pre filled tape cells.
  • The tape alphabet is also enlarged similarly.
  • The characters are now encoded in the new tape in such a way that it contains all possible combinations of the first tape characters in index 0, second tape characters in index 1, and so on.
  • Finally, in a transition, it sweeps across the entire tape and finds where the character is.
  • Once that happens, the tape head sweeps backwards to update the letters that were updated.

A Universal Turing Machine has 3 tapes, one for the encoding of the TM it is trying to simulate, one for the tape of TM it is simulating, and one to store the states and positions of said turing machines.

Theorem: \exists a universal TM

Membership Problem: Given a TM MM and xx, check if MM accepts xx.

The language of this problem is r.e. (this is a fact).

Halting Problem: Check if MM halts on xx.

The language of this problem is r.e. (this is a fact).

Property: If LL is both r.e. and co-r.e., then it is recursive. (co-r.e. means complement is recursive)

Proof: Simulate both on a single turing machine. Whichever accepts, halt and accept/reject accordingly.

Enumeration Machines

These have no input, there is no need to halt, one work tape and one output tape, there is a special print state that prints the contents of the output tape, clears it and then exits the state.

A language is r.e. iff there exists an E.M. for it. This is equivalent to a time sharing simulation of M.

Undecidability and Diagonalization

Theorem(Turing): HP is not recursive.

Let MxM_x be the Turing Machine that is encoded by the string xx. If no such thing exists, then let it be the trivial TM accepting everything.

This way, we get a list of turing machines. Let us assume that this is the complete list of turing machines.

Now consider a 2D matrix containing strings yy in the row header and TMs MxM_x in the column header. The cell says H if the machine halts on the string and L if it loops forever. If our assumption that the list of turing machines being complete is true, then we can always do this table.

Suppose there is a universal Turing machine KK that halts and accepts if MM halts on xx and halts and rejects if MM loops on xx.

Consider a universal machine NN that takes input xx and runs KK on (Mx,x)(M_x,x). If KK rejects the input then NN accepts it and if KK accepts it then NN goes into a loop.

If NN halts on xKx \Longleftrightarrow K rejects (Mx,x)Mx(M_x,x) \Longleftrightarrow M_x loops on xx. This implies that NN differs from each row of the table at the diagonal. However the list contained every Turing Machine in existence, so the assumption that the table entries are determinable is wrong.

Reductions

If a problem AA is solvable by making a subroutine call to another problem BB, we say that the problem AA is reducible to another problem BB.

Basically all the following are equivalent:

  • if B is True:
      A is True
    else:
      A is False
    
  • AA is reducible to BB

  • AmBA \le_m B

  • AA can be solved by a subroutine call to BB

Many-one reductions can be used to prove that something is not recognizable (or vice-versa). In that case only one subroutine call is allowed and the result has to be passed as-is by the outer machine.

In case you are generating a description of a machine from the input machine, the function that you use to generate the description must be computable and total.

Also, if AmBA \le_m B, then AˉmBˉ\bar{A} \le_m \bar{B}.

Turing reductions are more lax in their rules, allowing multiple subroutine calls and modifying the output. However, they can only be used to demonstrate recursiveness (or the lack of it).

Examples of undecidable problems

Given a TM MM and a string xx, decide if MM accepts xx.

Proof:

Create a turing machine HH that takes input M,xM,x and decides whether MM accepts xx.

Create a machine DD that does the opposite of what HH does when given input M,MM,M

DD with the input DD will cause a contradiction.

Therefore HH cannot exist.


Undecidability of the Halting Problem using Reduction from TM acceptance

Proof:

If HH tell you that it halts, then we can run the simulation in a universal turing machine and see the acceptance. If HH tells you that it doesn’t halt, then you can say no for acceptance. Therefore, if the halting problem is solvable, then the acceptance problem is also solvable. But we know for a fact that acceptance problem isn’t solvable.


Check if a language of a turing machine is empty being undecidable

Proof:

We modify the machine MM and create a machine M1M_1.

If L(M)L(M) is empty, then it returns false. If L(M)L(M) is non-empty, then it checks if ww is in the language or not.

We use the description of M1M_1 to feed into the checker for ETME_{TM} that checks if the language is empty or not. Inverting the output of the checker can give us the output of the checker of Acceptance problem.

Note that the checker for ETME_{TM} need not necessarily run the machine description. It only deduces that based on some heuristics that are not our concern. We do not have to find the machine that does that, only prove it does not exist. For which we assume the contrary.


Check if a a language of a turing machine is regular or not being undecidable

Proof:

We have a machine RTMR_{TM} that decides whether a TM description is regular or not.

We need to create a machine ATMA_{TM} that decides whether the input (M,x)(M,x) will be accepted or not.

We create M1M_1 from (M,x)(M,x) and runs MM on xx and gives us “true” if the input to M1M_1, i.e. yy has the form 0n1n0^n1^n else it gives “true” if MM gives “true” on xx.

Carefully observe what this is doing. When MM accepts xx, its language is Σ\Sigma^*, otherwise it is 0n1n0^n1^n. So the regular language decider will give “true” if MM accepts xx and “false” otherwise.

We feed this description of M1M_1 to the decider RTMR_{TM} and use the output as the output of ATMA_{TM}.


Proof of two machines having equal languages being undecidable

Suppose a decider for the above problem exists. It takes M1,M2M_1,M_2 and gives “true” if they are equal. Run it with M,M1M, M_1 where M1M_1 rejects everything and MM is the input to the decider of the empty language problem will solve the empty language problem.