updated: 2022-01-23_12:32:30-05:00
updated: 2021-12-16_10:59:43-05:00
Theory of Computation
- ^^ Fundamental Capabilities and limitations of computers
- Also known as Automata Theory
If a language is regular, it is also Context free, and Turing recognizable
If it is a non-regular language, some may be context free, some may be not context free
- Complexity --> Why are some problems harder than others?
- Computability --> Are there problems that cannot be solved by computers?
- What is an Automata Theory?
- A mathematical model of computation which could be used to address the two above questions
- Complexity example:
- Problem: Sorting a deck of 100 uniquely numbered cards
- Easy, Computable
- Problem: Checking whether such a deck exists
- What is the input? Given a box of cards? or?
- This is why we need to know the Domain
- Problem (Complex): Scheduling 100 unique classes with 25 instructors into 9 class rooms with 3 time slots a day 4 days a week
- Constraint: Avoiding room or instructor conflicts
- Computable but complex
- Problem: Sorting a deck of 100 uniquely numbered cards
- How do we deal with complexity?
- Abstraction and simplification
-
- Alter the root of difficulty
-
- Settle for a less than perfect solution
-
- Only hard in the worst case situation
- History Lesson:
- 1900: David Hilbert proposed in Paris 23 mathematical problems for the century
- # 10: test if a polynomial has an integral root
- 1900: David Hilbert proposed in Paris 23 mathematical problems for the century
- In order to study this we will be reviewing Set Theory
Functions and Relations
- f(a) = b
- f maps a to b
- Add function.. Domain is the set of ordered pairs
- Binary Function: A function with two arguments
- Relation: A property who's domain is a set of k-tuples
Special Binary Relation: Equivalence Relation
Theorem: DeMorgans Law
Theorem: sqrt(2) is irrational
Building Blocks of TOC
Symbol: a,b,*, etc
From symbols, we can form an alphabet: $\Sigma$
- collection of symbols
String: a sequence of symbols
- Consider an alphabet $\Sigma$ = {a,b}
- how many strings of length n?
- 2^n strings
- if the alphabet is $\Sigma$ then a number of symbols in $\Sigma$ = |$\Sigma$|
- the number of strings over $\Sigma$ is $|\Sigma|^n$
Language is a collection of Strings
Powers of $\Sigma$
- * = 0 union 1 union 2 etc (set of all possible strings)
- universal set
- 0 = {$\epsilon$}
- 1 = set of all strings of length 1
- n = all strings of length n
- etc..
How do we describe Automatas?
Computational Model
State Diagram
-
State diagrams usually describe DFAs, which are a type of Finite Automata
-
Any Language that can be represented by a DFA is called a Regular Language
Regular Language
Formal Definition of Computation
let $M=(Q,\Sigma,\delta,q_0,f)$ be a finite automata
and let $w_1...w_n$ be a string where $w_i\in\Sigma$
then $M$ accepts $w$ if a sequence of states $r_0,r_1...r_n$ in $Q$ exists such that
$r_0=q_0$
$\delta(r_i,w_{i+1})=r_{i+1}$ for $i=0...n-1$
$r_n\in f$
$M$ recognizes language $A$ if $A={w|M$ accepts $w}$
Regular Language Closure:
- Regular Languages are closed under:
Generalized form for multiple of M
- Sum of digits is a multiple of m
- $(Q,\Sigma,\delta,q_0,f)$
- $Q={q_0...q_{m-1}}$
- $\Sigma = {0,1,2,3,4,5,6,7,8,9}$
- $q_0=q_0$
- $\delta(q_2,3)=q_1$
- $(i+d)mod(m)$
Looking at NFA's:
Nondeterministic Finite Automata#Example Finite Automata that accepts all strings of form 0 k where k is a multiple of 2 or 3
Nondeterministic Finite Automata#Example the language of strings of length at least 2 that begin with 0 and end in 1]
Nondeterministic Finite Automata#Example the language of strings of length at least 2 that have a 1 in the second to last position
-
- includes empty set
NFA to DFA
- Why?
- NFA is not serial, making it a DFA you can predict runtime etc
Every NFA has a DFA
- For every ambiguous transition (where it goes to 2 or more states), unify them as a 'combo state'
- instead of 0 going to q0 and q1, it goes to q0q1
- Table method
- Only read epsilon symbol after character (on transition table)
- Start state can be different
- Domain of DFA includes the powerset of the sets in the NFA (think epsilon transitions)
- How to simplify states
- if no input states, remove state
Regular Language
We are now going to learn about:
Regular Expression
Converting R into an NFA
DFA to Regular Expression
Example: NFA->DFA
Exam 1
- shouldn't take more than the class time.
- can start 5m early
- Closed book
- Everything we have learned so far
Non-Regular Language
Pumping Lemma
Context free stuff
- Context Free Language
- has a Context Free Language#Context Free Grammar
- Push Down Automata
Chomsky Normal Form
Let's do another example for ada? pda? didn't hear her right... :
Closure properties of CFL
*Regular languages are closed under $\cup$,$\cap$,-,$\cdot$,* *
- The class of context free languages is closed under union, concatenation, and star operations.
- L1 and L2 are two CFL then L1 $\cup$ L2 is also CFL (L1 L2 => CFL)
- L1$^\star$ or L2$^\star$ is also CFL
- You could do this with PDA, but let's do it with CFG
Union: - S -> S1 | S2
CFG of L1
CFG of L2
Concatenation: - L1 and L2 are CFLs
let s1 be the start variable for L1's grammar
let s2 be the start variable for L2
L = L1 L2 - S -> S1 S2
CFG of L1
CFG of L2
Star: - S -> S S1 | e
CFG of L1 - L = L$^{\star}$ CFG
- The class of CFL are not closed under intersection or compliment (one implies the other)
- Easiest to do this as an example, rather than a proper proof (proof by example)
Intersection: - Consider the language L1= {$a^nb^nc^i|i,n\geq0$}
S -> TU
T -> aTb | e
U -> cU | e - Now consider the language L2 = {$a^ib^nc^{n}|i,n\geq 0$}
- Both are CFG
- L1 $\cap$ L2 = {$a^nb^nc^n|n\geq0$}
- this is not a CFG
- we will go over this next class
Complementation: - if it were, then it would be closed under intersection because of DeMorgan's Law
- A$\cap$B = $\overline{\overline{A}\cup\overline{B}}$
- Easiest to do this as an example, rather than a proper proof (proof by example)
- a^i b^j c^k | i =/= j or j=/=k
- find the grammar for this
Non-Context Free Languages
Non-Context Free Languages#Theorem
Non-Context Free Languages#Pumping Lemma
Turing Machine
HW (sorta, for practice)
TM
C = {a^i b^j c^k | i x j = k and i,j,k >= 1}
L = {a^2i b^i c^2i | i>0}
Theorem: If a language is regular then it is decidable
- Approach, come up with turing machine
Proof: Suppose M is a DFA for a given regular language
A TM can simulate M by reading the input from left to right while going through the same states as M
Once you reach the end of input, the TM enters the accept state if M is in accept state
Let M = (Q $\Sigma$ $\delta$ q0 f)
M' (Q $\Sigma$ $\rho$ $\delta'$ q0 qa qr)
where Q' = Q $\cup$ {qa,qr}
$\rho$ = $\Sigma$ $\cup$ {_}
$\delta'$(q,a) = ($\delta$(q,a),a,R)
(a is some input not _) ($a\in\Sigma$)
if q $\in$ Q & a $\ne$ _
$\delta$(q,_) = {
(qa,_,R) | if q $\in$ F |
---|---|
(qR,_,R ) | if q$\notin$F |
} |
Theorem: If a language is context free then it is decidable
Proof: Simulate a TM by using a PDA if PDA goes to accept state at the end of the input then the TM will go to the accept state, otherwise TM will go to reject
Claim: the class of languages accepted by deterministic TM's and Non-deterministic TM's are equal
Closure Properties of decidable and turing recognizable languages
Operation | Decidable | Turing Recognizable |
---|---|---|
Union | $\checkmark$ | $\checkmark$ |
Concatenation | $\checkmark$ | $\checkmark$ |
Intersection | $\checkmark$ | $\checkmark$ |
Star | $\checkmark$ | $\checkmark$ |
Complement | $\checkmark$ | NO |
Are decidable and recognizable languages closed under union?
** * Reference for Non-determinism in TM: * ** Turing Machine#Multitape Turing Machine
Union
Decidable
let l1 and l2 be decidable languages via halting TMs M1 & M2 respectively (both halt)
is L1 $\cup$ L2 decidable
yes... Given input x; x $\in$ L'; L' = L1 $\cup$ L2
- Simulate M1 on x ... if M1 accepts then accept else
- Simulate M2 on x ... if M2 accepts then accept else
- Reject
Recognizable (harder to prove, start with this)
let L1 and L2 be turing recognizable languages
is L1 $\cup$ L2 turing recognizable
M1 is TM for L1 and
M2 is a TM for L2
M1 and M2 may accept or loop
(overall x $\in$ L1 $\cup$ L2)
Say x $\in$ L2
if we run x on M1 it may loop
Non-determinism...
- Run them simultaneously on x.
- If either accept, accept, else
- loop or reject
.
If it is turing recognizable $\therefore$ it is also turing decidable
Concatenation
Recognizable
L1 and L2 are TR via TMs M1 and M2 respectively
is L1.L2 TR?
given input x, where x $\in$ L1.L2
First partition x into L1 and L2
Nondeterministically... (ie: try every possible split)
- Partition x as x1.x2
- Simulate M1 on x1, if M1 rejects, then reject
- if M1 accepts, simulate M2 on x2
- if M2 accepts; accept
- if M2 rejects; reject
- if M2 loops; loop (implies x2 $\notin$ L2)
- if M1 loops;loop (implies x1 $\notin$ L1)
Decidable: If it is turing recognizable $\therefore$ it is also turing decidable
Intersection
Recognizable
L1 and L2 are turing recognizable via TMs M1 and M2 respectively
is L1 $\cap$ L2 TR?
Given x $\in$ L1 $\cap$ L2
- Simulate M1 on x, if M1 rejects, then reject
- If M1 accepts, simulate M2 on x, if M2 accepts; accept; else reject
- If M1 loop (x $\notin$ L1 and $\therefore$ will loop)
Star
Recognizable
L1 is TR via Turing Machine M1
Proof:
Given input x where x in L1*
- Nondeterministically guess a number t
- partition x as x1.x2 ... xt
- Simulate the machine M1 on the strings x1,x2 ... xt in sequence
if M1 accepts, accept....etc
Complement
Decidable
L is decidable via halting TM M
given input x where x $\in \bar{L}$
- Simulate M on x;
- If M accepts, reject; else accept
Recognizable? No
If it doesn't reject (but loops), this will not accept
so it can't be recognizable
L is decidable iff L and $\bar{L}$ are turing recognizable
- if L is decidable, by closure properties, L and $\bar{L}$ are decidable
- if L and $\bar{L}$ are turing recognizable, is L decidable?
let L be TR via M
$\bar{L}$ be TR via M1
construct a machine...
- Simulate M on x and M1 on x simultaneously
- if M accepts, accept; if M1 accepts, reject
- for every x you will halt
Decidable properties of RLs and CFLs
we are looking at RLs and CFLs
- Is ADFA decidable?
- ADFA = {<D,w>| D is a DFA and w $\in$ L(D)}
- <D,W> encoding of a DFA and a string w
- is ADFA decidable? yes
- Machine M:
- given input <D,w>
-
- Simulate D on w
-
- If D accepts then accept; else reject
- E_DFA (empty DFA)
- is it decidable?
- E_DFA = { < D >|D is a DFA and L(D)=0}
-
- Check to see if there is a path from start state to an accept state
-
- If no path exists then accept; else reject
Is EQDFA = {< D1, D2 > | D1 and D2 are DFA's and L(D1) = L(D2) }
(they accept the same language) this is only possible if...
L(D1)=L(D2) iff {(L(D1)/L(D2)) $\cup$ (L(D2)/L(D1))} = ∅
Using closure properties:
- $\exists$ a regular language L such that L = ({(L(D1)/L(D2)) $\cup$ (L(D2)/L(D1))} = ∅)
- L1 = L(DFA1) (implies regular language)
- L2 = L(DFA2) (implies regular language)
- L is regular because regularity is closed under union
- This implies $\exists$ DFA D such that L(D) = L
- This DFA accepts only empty strings
- Check if D $\in$ EDFA
- $\therefore$ EQ_DFA is decidable
ACFG = { < G, w > | G is CFG and w $\in$ L(G) }
is ACFG decidable?
We need to figure out how many number of steps...
Use Chomsky Normal Form
- if w = $\epsilon$ then $\exists$ a derivation of w with respect to G' having 1 step
- if w $\ne$ $\epsilon$ then $\exists$ a derivation of w with respect to G' having 2 |w| - 1 steps
- list all derivations of length 2 |w| - 1
- if w is generated by one such derivation then accept; otherwise reject
- ACFG is decidable
Quiz: E_CFG = { < G > | G is a CFG and L(G) = null}
- Look at rules backwards. If you see a terminal, mark it.
- Repeat the following until no new variables can be marked
- $\exists$ a rule A-> A1...AK
- Mark A if all A1...AK are marked
- If S is marked, reject; else accept
$\therefore$ E_CFG is decidable
EQ_CFG = { <G1, G2> | G1 & G2 are CFG ^ L(G1)=L(G2)}
they derive the same languages
Is it decidable?
Regular Languages are closed under union and set difference, CFL are closed under union but not set difference
$\therefore$ EQ_CFG is undecidable
Proof: There are Non-Turing Recognizable Languages
Diagonalization Proof
when we say strings, we mean languages
Languages/problems (x) vs solutions (y)
S1 | S2 | S3 | ... | Sn | Language of Machine | |
---|---|---|---|---|---|---|
M1 | A | R | R | L(M1){S1,S4...} | ||
M2 | R | R | R | L(M2){S4...} | ||
M3 | R | R | A | L(M3){S3...} |
Let we call the diagonal line d = {S1, S3, ...}
Let there be $\bar{d}$ = {Every string that is not in d}
Let us say $\bar M$ decides $\bar d$
At position Sn where Sn = $\bar d$, $\bar M$ should accept, but cannot, since it is defined as not
Halting Problem
All Turing machines are undecidable
Proof
Let's say Halting problem is decidable
H(P,i) where p is program and i is input, does output-> halt or not
Assume H'(X):
if (H(X,X)== halt){
loop forever;
}
else return;
Problem: not all programs can halt
proof is through a program that does the opposite of a halting program
Post Correspondence Problem (PCP/Domino Problem)
dominoes?
- b/ca a/ab ca/a abc/c
Reduce to pcp that has solution, then
How to convert any TM to a PCP Problem
PCP is undicidable:
Proof Represent an undecidable problem n in the form of PCP
Proof by reduction, then we can say PCP is undecidable
Acceptance problem of a TM is undecidable:
We care converting to a PCP with solution
[q1] 0=> X,R -> [q2]
[q2]1=>X,L -> [q3]
$\Sigma$ = {0,1}
$\rho$ = {0,1,X,_}
Seven Steps
Review
- Concatenation
- EQ_TM is not turing recognizable
- Con_TM { < M1 M2 M3> | M1, M2, M3 are three TMS and L(M1)=L(M2)=L(M3)}
- EQ_TM <=m CON_TM (reduction)
Reduction
we are reducing the problem to a known 'undecidable' problem, in this case, EQ_TM (from CON_TM)
Instance of EQ_TM
Two TM
input < M1, M2>
- Set N1 := M1
- Set N2 := M2
- Design a TM N3 that accepts only the string e
Output <N1, N2, N3> (Instance of CON_TM)
Proof of Correctness
Let <M1, M2> $\in$ EQ_TM
ie L(M1)= L(M2)
L(N1) = L(N2) by reduction method
= L(N2).{e}
= L(N2).L(N3)
L(N1) = L(N2).L(N3)
<N1,N2,N3> $\in$ CON_TM
- Let <M1,M2> $\notin$ EQ_TM
L(M1) $\ne$ L(M2)
L(N1) $\ne$ L(N2)
L(N1) $\ne$ L(N2).{e}
L(N1) $\ne$ L(N2).L(N3)
<N1, N2, N3> $\notin$ CON_TM
EQ_TM $\leq$m CON_TM
TR
TNR
TD If turing decidable, then no others
TU
TNR, TU, basically the same so if not recognizable, then undecidable
More Review
AeCFG = { < G > | G is a CFG that generates E}
4.11 Infinite PDA
M is a PDA and L(M) is infinite
Decidable or not?
Decidable
Proof:
Given < M > , a description of a PDA
Convert it to a CFG G
Compute G's Pumping length. (CNF, ... P = N ^ (|V| +1) v is variables set, n is largest number of symbols in rhs of r)
PDA M accepts a string longer than PL iff M's language is infinite
We show how to test whether M accepts such a string
Let T RL containing all strings longer than p
Find CFG H that generates L(G) $\cap$ T
it could be empty or not empty
if its empty, it's not an infinite language
E_CFG is decidable
Use E_CFG to test
whether L(H) is empty
Accept if L(H) is not empty
- accept if E_CFG reject
Reject otherwise - reject if E_CFG accepts
A_TM is TR