"Dive into the origin of assembler language - This is how you control the computer"
Table of Contents
Turing Machines (TM)
Combining TMs
Recursive languages
Recursive Functions
Recursively Enumerable Languages
Extensions of Turing Machines
1. Turing Machines (TM)
Historical Context: The Colossus Computer
Real-life Connection: The Colossus was one of the first electronic digital programmable computers. Built during WWII at Bletchley Park, it was used for codebreaking. The image in the lecture shows operators working with this massive machine that used vacuum tubes and had magnetic tape for memory storage.
Components of a Turing Machine
A Turing Machine consists of:
CPU (Finite Control)
State register that memorizes the current stage of the machine
Contains the program (instruction set) of the machine
Has states: q0,q1,q2,q3,h (where h is the halting state)
Memory (Tape)
But back then we didn't have RAM!
We have magnetic tape instead
Infinite tape divided into cells
Each cell can contain a symbol from the alphabet
Read/Write Head
Can move in both directions (left or right)
Can read the current symbol
Can write a new symbol
Analogy: Think of a Turing Machine like an old cassette tape player. The tape moves left and right, there's a read/write head that can detect and change what's on the tape, and there's a control unit that decides what to do based on what it reads.
Formal Definition
มาเริ่มกันละว่า How can we define those components mathematically
Definition: A Turing machine is a 5-tuple M=(K,Σ,δ,s,H) where:
K is a finite set of states
Σ is an alphabet containing:
The blank symbol ⊔ (represents empty cells)
The left end symbol ▹ (marks the start of the tape)
But NOT containing the symbols → and ← (these are for movement)
s∈K is the initial state (starting point)
H⊆K is the set of halting states (when machine stops)
It gets out of an infinite loop when it reaches a halting state
δ is the transition function (the program/instruction set): δ:(K−H)×Σ→K×(Σ∪{←,→})
With these constraints:
For all q∈K−H, there exists p such that δ(q,▹)=(p,→)
Meaning: It never writes ▹ onto the memory. The tape start is always ▹, and when you see it, you can only move right.
Write down อะไรก็ได้ แต่จะ Write ▹ หรอ ตลก55555
For all q∈K−H and a∈Σ−{▹}, if δ(q,a)=(p,b) then b=▹
Meaning: Only one tape start exists, and it's always on the left
Exam Tip: Remember the mnemonic:
K = Kollection of states
Σ = Symbols (alphabet)
δ = Decisions (transitions)
s = start
H = Halt
Understanding the Transition Function
The transition function δ takes:
Input: (current state, input symbol)
Output: (next state, action)
Where action can be:
A symbol to write (replacing current cell content)
←: move pointer to the left (LHS)
→: move pointer to the right (RHS)
Important constraints:
Start of tape marker (▹) is never written by the machine (นี่แหละ ๆ)
When seeing ▹, the head must move right
Example 4.1.1: Simple Turing Machine
Consider the Turing machine M=(K,Σ,δ,s,{h}) where:
A configuration of a Turing machine M=(K,Σ,δ,s,H) is a member of:
K×▹Σ∗×(Σ∗(Σ−{⊔})∪{e})
Breaking this down:
Current state: q∈K
Before the header: ▹ω1 (everything to the left including start marker)
After the header: ω2 (everything to the right)
If it consists of only ⊔'s or empty string, we can ignore it
Notation: Configuration is written as (q,ω1aω2) where:
q = current state
▹ω1 = tape content before head
a = symbol under the head (current cell)
ω2 = tape content after head
Syntactic Sugar:
(q1,▹⊔abac⊔)=(q1,▹⊔abac) (CHECK)
The underline shows where the head is positioned
Computation Steps (Yields Relation)
Definition: Let (q1,ω1a1u1) and (q2,ω2a2u2) be configurations of M. Then: (q1,ω1a1u1)⊢M(q2,ω2a2u2)
if and only if for some b∈Σ∪{←,→}, δ(q1,a1)=(q2,b) and one of the following cases holds:
Case 1: Write a symbol (b∈Σ)
b∈Σ,ω1=ω2,u1=u2 and a2=b
Meaning: Replace the cell's content with symbol b, stay in place
Intuition: Think of configurations as "snapshots" of the machine at any point in time. The ⊢M symbol means "yields" or "steps to" - it shows how one snapshot transitions to the next.
Halted Configuration and Computation
แล้วหยุด กูจะหยุดมึงเอง!
Definition: Halted Configuration
A halted configuration is of the form: (h,ω1aω2) with h∈H
The machine returns a result when it reaches a halted configuration
Result is whatever is on the tape at that moment
Definition: Computation
A computation is a sequence of configurations C1,C2,…,Cn such that: C1⊢MC2⊢M⋯⊢MCn
We say that:
The computation has lengthn
C1yieldsCn
Definition: Halting
M is said to halt on inputω iff (s,▹⊔ω) yields some halted configuration. (s,▹⊔ω)⊢M∗(h,▹ω′)
Where:
(s,▹⊔ω) = initial configuration
(h,▹ω′) = final configuration (may not need to be the same)
ω′ = the result
⊢M∗ means "yields in zero or more steps"
Important Note: The mem ctn (memory content) needs not be the same before and after computation.
Exam Tip: When tracing a computation:
Start with initial config: (s,▹⊔ω)
Apply transitions step by step
Stop when you reach a halting state
Check if the final configuration is what you expect
2. Combining TMs
Symbol Writing Machines
For each symbol a∈Σ∪{←,→}−{▹}, Ma is a Turing machine which writes the symbol a into the scanned tape square.
Formal definition: Ma=({s,h},Σ,δ,s,{h}) where δ(s,b)=(h,a) for each b∈Σ−{▹}.
Mnemonics (Short Notations)
To keep things simple, we write:
a for Ma → write 'a' to the current cell
L for M← → move pointer to LHS (Left)
R for M→ → move pointer to RHS (Right)
Special composite machines:
L⊔: Finds the first blank square to the left of the currently scanned symbol
(p,▹⊔abc⊔⊔efg)⊢L⊔(p,▹⊔abc⊔⊔efg)
- Scan left until blank found
R⊔: Finds the first blank square to the right of the currently scanned symbol
(p,▹⊔abcd⊔efg⊔hij)⊢R⊔(p,▹⊔abcd⊔efg⊔hij)
- Scan right until blank found
Atomic vs Composite Machines
Type
Examples
Description
Atomic
a, L, R
Write symbol, move left, move right
Composite
L⊔, R⊔, C, S→
Built from atomic machines
If you have two Turing machines, you can connect them together!
Example 4.1.5: Sequential Composition
Machine: RR or R2
Diagram: What it does:
Start: move right
If cell is a, b, ⊔, or ▹: move right again
Shorthand notation:
Unlabeled arrow = works for all symbols in alphabet
Can omit arrow entirely by juxtaposing: R→R becomes just RR
Note: "Program" states are hidden - each node is a sequence of commands, each edge is a peek to the current cell.
Example trace:
▹⊔⊔⊔b⊢R▹⊔⊔⊔b⊢R▹⊔⊔⊔b(move right once)(move right again)
Example 4.1.6: Conditional Movement (R⊔)
Machine: R⊔ - moves right until blank found
Diagram:
Alternative notation:
Where a=⊔ is read as "any symbol a other than ⊔"
What it does:
Scan right
If current cell is NOT blank: keep moving right
If current cell IS blank: halt
Advantage of a=⊔ notation: The variable a can be used elsewhere in the diagram
Example 4.1.6 continuation: Copy and Move
▹→R⊔a=⊔L→a
ตรง R⊔ มี Self-loop ถ้าเป็น ⊔ What this does:
Scan right until blank found (R⊔)
If found a non-blank symbol a (store it as variable)
Move left (L)
Write that symbol a at the new position
Example 4.1.7: Find Marked or Unmarked Squares
Four useful machines for finding specific squares:
(a) R⊔: Find first blank square to the right
⊔
┌────────┐
↓ │
▷→ R
(b) L⊔: Find first blank square to the left
⊔
┌────────┐
↓ │
←─ L
(c) R⊔: Find first non-blank square to the right
⊔
┌────────┐
↓ │
▷→ R
(d) L⊔: Find first non-blank square to the left
⊔
┌────────┐
↓ │
←─ L
Summary Table:
Machine
Description
Scan Direction
Looking For
R⊔
R-blank
Right
First blank
L⊔
L-blank
Left
First blank
R⊔
R-nonblank
Right
First non-blank
L⊔
L-nonblank
Left
First non-blank
Example 4.1.8: The Copying Machine (C) (CHECK!)
Purpose: Copy input string - transforms ⊔ω⊔ into ⊔ω⊔ω⊔
Starting condition:
Input: String ω containing only non-blank symbols (possibly empty)
Tape: ω on an otherwise blank tape with one blank square to its left
Head: Positioned on the blank square to the left of ω
Result: Eventually stops with ω⊔ω on an otherwise blank tape
If current cell is a: replace with blank, stay in state
If current cell is blank: halt
Otherwise: move right
This is the "clear the tape" operation - removes all occurrences of symbol a.
▹⊔aac⊔⊔⊢M∗▹⊔⊔⊔c
Rules for Combining Machines (Formal Definition)
Suppose we have three Turing machines:
M1=(K1,Σ,δ1,s1,H1)
M2=(K2,Σ,δ2,s2,H2)
M3=(K3,Σ,δ3,s3,H3)
Combined Machine Structure
▷ M₁ ──a──→ M₂
│
b
↓
M₃
How it works:
Let M1 work until it halts
Peek the current cell
If the cell contains a, let M2 work
If the cell contains b, let M3 work
Formal Construction
The combined machine M=(K,Σ,δ,s,H) where:
K=K1∪K2∪K3 (union of all states)
s=s1 (start with first machine's start state)
H=H2∪H3 (halt when any component halts)
For each σ∈Σ, q∈K−H, δ(q,σ) is defined as follows:
If q∈K1−H1 (non-halting state of M1):
δ(q,σ)=δ1(q,σ)
Use M1's transitions
If q∈K2−H2 (non-halting state of M2):
δ(q,σ)=δ2(q,σ)
Use M2's transitions
If q∈K3−H3 (non-halting state of M3):
δ(q,σ)=δ3(q,σ)
Use M3's transitions
If q∈H1 (halting state of M1):
δ(q,σ)=(s2,σ) if σ=a (jump to M2)
δ(q,σ)=(s3,σ) if σ=b (jump to M3)
δ(q,σ)∈H otherwise (halt if no condition matches)
Programming Analogy: This is like an if-clause in programming:
def combined_machine(tape): M1.run(tape) # Run M1 until it halts symbol = tape.read_current() if symbol == 'a': M2.run(tape) # JMP to M2 elif symbol == 'b': M3.run(tape) # JMP to M3 else: halt() # Stop if no condition matches
Assembly Language Equivalent:
JMP (unconditional jump)
JZ (jump if zero)
JNZ (jump if not zero)
These are the "branching" or "flowchart" operations
Quick Reference: Composite Machine Notations
Notation
Description
L
Move left
R
Move right
L⊔
Scan left for previous blank
R⊔
Scan right for next blank
L⊔
Scan left for previous non-blank
R⊔
Scan right for next non-blank
S←
Shift the tape to left
S→
Shift the tape to right
C
Copy the tape's content
Diagram notation:
Initial Configuration: ▹⊔ω
Condition/Branch: Decision points (if-then)
Self-loop: Repeating state
3. Recursive Languages
3.1 Definition: Accepting and Rejecting Configurations
Context: Recursive languages can be defined as a recursive function (recursive algorithm)
Addition as recursion example: f(a,b) = f(a+1, b-1) \text{ if } b > 0$$$$f(a,0) = a
Definition: Given is a Turing machine M=(K,Σ,δ,s,H) with H={y,n}.
Any halting configuration whose state is y is said to be an accepting configuration(y,_)
A halting configuration whose state is n is said to be a rejecting configuration(n,_)
An initial configuration is of the form (s,▹⊔ω)
For an input ω∈(Σ−{⊔,▹})∗, we say that:
M accepts ω if (s,▹⊔ω) yields an accepting configuration ⊢M∗(y,_)
M rejects ω if (s,▹⊔ω) yields a rejecting configuration ⊢M∗(n,_)
Definition: Deciding a Language (Recursive Languages)
Definition: Let Σ0⊆Σ−{⊔,▹} be an alphabet, called input alphabet. We say that Mdecides a language L⊆Σ0∗ if for any string ω∈Σ0∗:
\begin{align*}
&\text{If } \omega \in L \text{ then } M \text{ accepts } \omega \\
&\text{If } \omega \notin L \text{ (i.e. } \omega \in \Sigma_0^* - L\text{) then } M \text{ rejects } \omega
\end{align*}
}$$
A language $L$ is called **recursive** if it is decided by some Turing machine.
> **Key Concept - Deciding**:
> - **$M$ has to HALT** on all inputs in $\Sigma_0^*$
> - $M$ can tell if it accepts/rejects an input string
> - คือถ้าได้คำตอบไม่ว่าจะเป็น $y,n$ คือมัน decided
> - **ถ้าติดใน loop ก็คือ undecided**
**Important Note**: If TM $M$ decides a language $L \subseteq \Sigma_0^*$, then $M$ halts on any $\omega \in \Sigma_0^*$, but $M$ is **not required** to halt on $\omega \in \Sigma^* - \Sigma_0^*$ (see supplementary note for further discussion)
> **Exam Insight**:
> - Aj. Hung จะถามงี้ Show that $a^nb^n$ is a recursive language
> - (Actual Question) แปลว่าให้ design a turing machine for $a^nb^n$
### Example: $L_0 = \{a^n b^n \mid n \geq 0\}$ is Recursive
>ถึงนี่!
**Example**: Show that $L_0 = \{a^n b^n \mid n \geq 0\}$ is recursive.
**Transition Diagram**:
![[Pasted image 20251105120100.png|center|500]]
**Strategy**:
1. Start from the left
2. Find an $a$, replace it with $d$ (mark as processed)
3. Find a $b$, replace it with $d$ (mark as processed)
4. Return to left using $L_\sqcup$
5. Repeat until all symbols are replaced with $d$
6. If pattern doesn't match $a^*b^*$, reject ($n$)
7. If all replaced successfully, accept ($y$)
**State Diagram Explanation**:
\begin{align*}
&\triangleright R \xrightarrow{a} dR \xrightarrow{b} dL_\sqcup \
&\text{where:} \
&\quad R: \text{Move right (self-loop on } d\text{)} \
&\quad dR: \text{Replace } a \text{ with } d\text{, then move right (self-loop on } a,d\text{)} \
&\quad dL_\sqcup: \text{Replace } b \text{ with } d\text{, then scan left to blank}
\end{align*}
**Rejection conditions**:
- If see $\sqcup$ while in first state $R$ → accept (empty string or all matched)
- If see $b$ or $c$ while looking for $a$ → reject
- If see $c$ or $\sqcup$ while looking for $b$ → reject
- If see $a$ or $\sqcup$ while looking for $c$ → reject
**Sample run for $\omega = aabb$**:
Initial config: $(s, \triangleright \underline{\sqcup} aabb)$
ผิด แก้ด้วย
**Detailed trace with annotations**:
![[Pasted image 20251105120200.png|center|600]]
> **Exam Strategy**:
> - ต้อง cancel ตัวที่ pair กัน (ในอัตราส่วนที่เท่ากัน) $(a:b) = (n:n)$
> - Don't stop until reaching the halting states
> - เวลา trace ให้เขียน configuration แต่ละ step
> - Mark processed symbols with $d$ to avoid reprocessing
**Alternative trace format**:
Starting: $\triangleright \sqcup aabb$
| Step | Configuration | Action |
|------|---------------|--------|
| 0 | $\triangleright \underline{\sqcup}aabb$ | Initial |
| 1 | $\triangleright \sqcup \underline{a}abb$ | $R$: move right |
| 2 | $\triangleright \sqcup \underline{d}abb$ | Replace $a$ with $d$ |
| 3 | $\triangleright \sqcup d\underline{a}bb$ | $R$: move right |
| 4 | $\triangleright \sqcup da\underline{b}b$ | $R$: move right |
| 5 | $\triangleright \sqcup da\underline{d}b$ | Replace $b$ with $d$ |
| 6 | $\triangleright \underline{\sqcup}dadb$ | $L_\sqcup$: back to start |
| ... | ... | Continue matching |
| n | $\triangleright \sqcup dddd\underline{\sqcup}$ | Accept: $y$ |
> **Real-world Analogy**: This is like checking if opening and closing parentheses match in code - you need to ensure each opening bracket has a corresponding closing bracket.
---
### 3.4 Example: $L_1 = \{a^n b^n c^n \mid n \geq 0\}$ is Recursive
- เคยมีวใน #FinalExam ปีนึง
- มีโปรแกรมมารันให้หน่อย
- Design Machine บวกเลขง่าย ๆ $n+3=n+2+1$
**Example**: Show that $L_1 = \{a^n b^n c^n \mid n \geq 0\}$ is recursive.
This language has previously evaded FSA, PDA recognizers - but TM can decide it!
**Transition Diagram**:
![[Pasted image 20251105120300.png|center|500]]
\begin{align*}
&\text{From Figure 4-11:} \
&\triangleright R \xrightarrow{a} dR \xrightarrow{b} dR \xrightarrow{c} dL_\sqcup \
&\text{Self-loops: } d \text{ on each state}
\end{align*}
**Strategy**:
1. Start from left, find first $a$
2. Replace $a$ with $d$, continue right to find $b$
3. Replace $b$ with $d$, continue right to find $c$
4. Replace $c$ with $d$, return to left with $L_\sqcup$
5. Repeat: each stage replaces one $a$, one $b$, and one $c$
6. Accept if all replaced (reach blank while looking for $a$)
7. Reject if pattern broken or mismatch
**Reject conditions**:
- $\sqcup$ at first $R$ → accept (empty string)
- $b,c$ while looking for $a$ → reject
- $c, \sqcup$ while looking for $b$ → reject
- $a, \sqcup$ while looking for $c$ → reject
**Sample run for $\omega = aabbcc$**:
Initial: $\triangleright \underline{\sqcup} aabbcc$
**Detailed computation trace**:
![[Pasted image 20251105120400.png|center|700]]
**Visual trace for $aabbcc$**:
```
Stage 1: aabbcc → dabbcc → dadbcc → dadbdc → back to start
Stage 2: dadbdc → dddbdc → dddddc → dddddd → back to start
Check: dddddd → all d, no more a → ACCEPT
```
> **Exam Question (This appeared in last year's final)**:
>
> Show that $a^n b^m c^n d^m$ is recursive
>
> **Hint ๆ อย่าอย่าโกนไป**:
> - Replace $d$ with $z$
> - For each decision point, write the remaining symbols in the $n$-transition
> - Similar strategy: match $a$ with $c$, and $b$ with $d$
**Another diagram representation**:
![[Pasted image 20251105120500.png|center|400]]
> **Exam Strategy**:
> - อันนี้ยากกว่า $a^nb^nc^n$ เพราะต้อง track 2 pairs
> - $n$ = count of $(a,c)$ pair
> - $m$ = count of $(b,d)$ pair
> - Each iteration: cancel one $a$ with one $c$, and one $b$ with one $d$
---
### 3.5 Example: Any Regular Language is Recursive
**Theorem**: Any regular language is recursive.
**Proof**: Let $M = (K, \Sigma, \delta, s, F)$ be a DFA. We can build a TM:
$$M' = (K \cup \{y, n\}, \Sigma', \delta', s', \{y, n\})$$
that decides $L(M)$ as follows:
- $\Sigma' = \Sigma \cup \{\triangleright, \sqcup\}$
- $\delta': K \times \Sigma' \rightarrow (K \cup \{y,n\}) \times (\Sigma' \cup \{\leftarrow, \rightarrow\})$ where:
- $\delta'(s', \sqcup) = (s, \rightarrow)$ — skip initial blank
- $\delta'(p, a) = (\delta(p, a), \rightarrow)$ for $p \in K, a \in \Sigma$ — **scan through + make state transition**
- $\delta'(p, \sqcup) = (y, \sqcup)$ for $p \in F$ — accept if in final state
- $\delta'(p, \sqcup) = (n, \sqcup)$ for $p \notin F$ — reject if not in final state
**Diagram**:
![[Pasted image 20251105120600.png|center|300]]
**Key insight**: The TM simulates the DFA by:
1. Reading input left to right (move right after each symbol)
2. Making the same state transitions as the DFA
3. When reaching end (blank), checking if in accepting state
4. Going to $y$ if accept, $n$ if reject
> **Important**: **IF you have FSA, you can convert it into TM**
>
> This proves that: **Regular Languages ⊂ Recursive Languages**
---
# 4. Recursive Functions
### 4.1 Definition: Recursive Functions
> **Modern computing**: We treat math functions as TM... tape manipulation
>
> Operations: $+, -, \times, \div, \sqrt{}, \cup, \ldots$
**Definition**: Let $M = (K, \Sigma, \delta, s, \{h\})$, $\Sigma_0 \subseteq (\Sigma - \{\sqcup, \triangleright\})$ and $\omega \in \Sigma_0^*$. If
$$(s, \triangleright \sqcup \omega) \vdash_M^* (h, \triangleright \sqcup u)$$
then $u$ is called the **output** of $M$ on input $\omega$ and denoted by $M(\omega)$.
$$\boxed{f(\omega_1, \omega_2, \ldots, \omega_k) \xrightarrow{\text{TM}} M(\omega_1, \omega_2, \ldots, \omega_k)}$$
We say that:
1. **$M$ computes function** $f: \Sigma_0^* \rightarrow \Sigma_0^*$ if for any $\omega \in \Sigma_0^*$, $M(\omega) = f(\omega)$
2. **$M$ computes function** $f: \mathbb{N}^k \rightarrow \mathbb{N}$ $(k \geq 1)$ if for all binary numbers $\omega_1, \ldots, \omega_k$:
$$M(\omega_1; \ldots; \omega_k) = f(\omega_1, \ldots, \omega_k)$$
where $f(\omega_1, \ldots, \omega_k)$ is also in **binary representation**
**A function $f$ is recursive if there is a Turing machine computing $f$.**
> **Key Point**: In TM, integers are **"convert to be binary string"** not decimal!
---
### 4.2 Example: Successor and Doubling Functions
**Example**: Show that $\text{succ}(n) = n + 1$ and $d(n) = 2n$ are recursive functions.
#### 4.2.1 Successor Function: $\text{succ}(n) = n + 1$
**Strategy**: Add 1 to a binary number
- If last digit is $0$: change to $1$
- If last digit is $1$: change to $0$ and carry
**Examples**:
- $\text{succ}(101_2) = 110_2$ (5 → 6)
- $\text{succ}(111_2) = 1000_2$ (7 → 8)
**Transition Diagram** (Figure 4-12):
![[Pasted image 20251105120700.png|center|400]]
\begin{align*}
&\triangleright R_\sqcup \begin{cases}
0 \rightarrow 1 \
1 \rightarrow 0
\end{cases} \text{ (go to last digit)} \
&\text{then: } \begin{cases}
0 \rightarrow 1 \text{ and halt} \
1 \rightarrow 0 \text{ and } L \text{ (carry)} \
\sqcup \rightarrow 1S_\rightarrow L_\sqcup \text{ (overflow: add digit)}
\end{cases}
\end{align*}
---
## Exam Tips & Strategies
### For Recursive Language Proofs
1. **Design the TM systematically**:
- Identify what needs to be matched/counted
- Use markers ($d$, $z$, etc.) to track processed symbols
- Always return to start position with $L_\sqcup$
2. **Common patterns**:
- **Matching**: $a^nb^n$ → cancel pairs
- **Multiple matching**: $a^nb^nc^n$ → cancel triplets
- **Complex matching**: $a^nb^mc^nd^m$ → two separate pair counts
3. **Trace format**:
- Start with initial configuration
- Show each step with clear action
- Mark current position with underline
- End with accept/reject state
### For Recursive Function Proofs
1. **Binary representation**:
- All numbers are in binary
- Think bit-wise operations
2. **Decompose complex functions**:
- Break into simpler operations
- Combine existing machines (succ, double, etc.)
- Example: $2n+2 = 2(n+1) = \text{succ} \circ \text{double}$
3. **Common building blocks**:
- $\text{succ}(n) = n+1$
- $\text{pred}(n) = n-1$ (if $n>0$)
- $\text{double}(n) = 2n$
- $\text{half}(n) = \lfloor n/2 \rfloor$
### Time Management
- **Simple language** ($a^nb^n$): ~10-15 minutes
- **Complex language** ($a^nb^nc^n$): ~15-20 minutes
- **Function design**: ~15 minutes
- **Leave time for trace**: Always show at least one complete example
---
## Practice Problems
1. **Design TM for**: $L = \{a^nb^{2n} \mid n \geq 0\}$
- Hint: For each $a$, need to find two $b$'s
2. **Design TM for**: $L = \{ww^R \mid w \in \{a,b\}^*\}$ (palindromes)
- Hint: Match first with last, second with second-last, etc.
3. **Show recursive**: $f(n) = n \bmod 2$ (parity check)
- Hint: Check last bit of binary representation
4. **Show recursive**: $f(n,m) = n + m$ (addition)
- Hint: Use repeated successor
---
*End of Recursive Languages & Functions*
> "Decidability is about whether we can always get an answer. Recursive languages guarantee we'll always know yes or no - no infinite waiting!" - Theory of Computation wisdom
## Key Takeaways
### Turing Machine = Modern Computer
The Turing Machine model captures the essence of computation:
- **CPU** → Finite control (states and transitions)
- **RAM** → Infinite tape (memory)
- **Program** → Transition function (instruction set)
### Building Complex from Simple
Just like assembly language, we:
1. Start with **atomic operations** ($L$, $R$, write symbols)
2. Build **composite operations** ($L_\sqcup$, $R_\sqcup$, $C$, $S_\rightarrow$)
3. Combine machines using **conditionals** (branching on tape symbols)
### Important Concepts to Remember
1. **Configuration**: Snapshot of machine state + tape + head position
2. **Computation**: Sequence of configurations (step-by-step execution)
3. **Halting**: When machine reaches a halting state
4. **Combining**: Connect machines like flowchart nodes
---
## Exam Tips Summary
1. **For definitions**: Remember the 5-tuple $(K, \Sigma, \delta, s, H)$
2. **For tracing computations**:
- Start with $(s, \triangleright \sqcup \omega)$
- Apply $\delta$ step by step
- Use the notation $(q_1, \text{tape}) \vdash_M (q_2, \text{tape})$
- Stop at halting state
3. **For designing TMs**:
- Break problem into smaller tasks
- Use standard building blocks ($L_\sqcup$, $R_\sqcup$, etc.)
- Draw state diagram first
- Then write formal transition table
4. **Common patterns**:
- **Even/odd counting**: Alternate between two states
- **Finding blanks**: Use $L_\sqcup$ or $R_\sqcup$
- **Copying**: Use markers and back-and-forth scanning
- **Shifting**: Store symbol, erase, move, write
5. **Don't forget**:
- $\triangleright$ is never written, only read
- When seeing $\triangleright$, must move right
- Blank squares at the end can be omitted in configuration notation
- Each "state node" in a flowchart is actually a sequence of basic commands