Context:FIT2014_MOC · the exam hand skill of Turing Machines — “design a TM accepting L” · the tape-level answer to the languages the pumping lemmas ruled out
Problem it solves: turn a counting/matching language into a finite state diagram, using the tape itself as the counter.
Quick Revision
🎯 Trigger: the language couples two or more unbounded counts ➔ mark one symbol of each group per pass, sweep back, repeat until one group runs out, then verify the others are exhausted too.
⚠️ Key Constraint: marking must be reversible information, not destruction — write a distinct symbol (A for a consumed a, B for a consumed b, # for a pass boundary) so the sweep-left phase can still tell “already matched” from “not yet reached”.
📐 The marking recipe
Handle ε first ➔ if the very first cell is Δ, the input is empty; accept or reject immediately from State 1.
Mark one symbol from the leftmost group and move right.
Sweep right over already-marked symbols and unprocessed ones until the next group’s first unmarked symbol appears; mark it.
Sweep left back to the boundary marker, land on the first unmarked symbol of group 1, and loop.
Detect exhaustion ➔ when group 1 has no unmarked symbol left, leave the loop and verify the tail: sweep right over the remaining marks and require Δ. Anything else ⟹ crash ⟹ reject.
⚡ Why this works and a PDA’s stack wouldn’t for ≥3 groups ➔ the head can revisit any cell, so the marks act as an arbitrary number of independent counters. This is exactly the capability anbnan needed and could not get from a stack.
🔧 Worked machine 1 — {anbn:n≥0}
Lecture pseudocode
If the current letter is blank, then Accept string.Loop { If current letter is a then change a to A & move right. Move right over every a and B. If current letter is b then change b to B & move left. Move left over every B. If current letter is A then move right & exit the loop. If current letter is a then move left over every a. If current letter is A then move right.}Move right over every B.If current letter is blank, then Accept string.
Loop { If current letter is blank, then Accept string. If current letter is a, then change a to A & move right. Move right over a* b b*. If current letter is a, then move left. If current letter is b, then change b to a & move right. Move right over every a. If current letter is blank, then delete aa on the left. Move left over every a and b. If current letter is A, then move right.}
Strategy ➔ per pass, consume one a from the front (mark it #), one b from the middle (rewrite it as a so it joins the right block), then delete two as from the right end — one for the rewritten b and one for the trailing block. Every group shrinks in lockstep; the input is in L iff they empty together.
From
To
Read
Write
Move
Purpose
1
3
a
#
R
mark the front a as the pass boundary
3
3
a
a
R
sweep right over remaining front as
3
4
b
b
R
enter the b block
4
4
b
b
R
sweep right over the bs
4
5
a
a
L
hit the rear block — step back onto the lastb
5
6
b
a
R
rewrite that b as an a
6
6
a
a
R
run to the right end
6
7
Δ
Δ
L
found the end — turn around
7
8
a
Δ
L
delete the last a
8
9
a
Δ
L
delete the second-last a
9
9
a
a
L
sweep left home
9
9
b
b
L
sweep left home
9
1
#
#
R
back at the boundary — next pass
1
2
Δ
Δ
R
nothing left ⟹ Accept
(Lecture 18 draws this same machine with A where Lecture 19’s table writes # — same machine, and # is the symbol assumed by the tape alphabet {a,b,#} in Encoding Turing Machines (Code Words).)
Manual Execution Trace — w=aba
Step
State
Pos
Tape before
Read
Write
Move
Next
0
1
0
aba
a
#
R
3
1
3
1
#ba
b
b
R
4
2
4
2
#ba
a
a
L
5
3
5
1
#ba
b
a
R
6
4
6
2
#aa
a
a
R
6
5
6
3
#aa
Δ
Δ
L
7
6
7
2
#aa
a
Δ
L
8
7
8
1
#a
a
Δ
L
9
8
9
0
#
#
#
R
1
9
1
1
#
Δ
Δ
R
2 — Accept
✍️ Practice
Practice 1: convert the FA over {a,b} accepting strings ending in b (states q0 start, q1 final; q0bq1, q1bq1, q1aq0, q0aq0) into a Turing machine, and say why the result is a decider.
Reference solution q0↦1, q1↦3; rewrite every edge label x as x→R; drop q1's double circle and add 3Δ→R2:
Key move: every transition moves right and never writes, so after ∣w∣+1 steps the head is past the input and the machine has halted ⟹ Loop(T)=∅ ⟹ decider. State 1 deliberately has noΔ rule, so strings ending in a (and ε) crash ⟹ reject.
Practice 2: design a TM accepting {anbncn:n≥0} over tape alphabet {a,b,c,A,B,C,Δ}. Give the pseudocode, not the full diagram.
Reference solution
If the current letter is blank, then Accept string.Loop { If current letter is a then change a to A & move right. Move right over every a and B. If current letter is b then change b to B & move right. Move right over every b and C. If current letter is c then change c to C & move left. Move left over every b, B, a and C, back to the last A. Move right. If current letter is B then exit the loop.}Move right over every B and C.If current letter is blank, then Accept string.
Key move: the anbn machine generalises by adding one marker alphabet per group — the loop body gains one “sweep right, mark one” stage, the verification tail gains one symbol to sweep over. No new idea is needed, which is precisely why the language hierarchy stops mattering above the TM.
⚠️ Common Mistakes
💡 Don’t erase what you consume ➔ overwrite a→A rather than a→Δ inside the matching loop; blanking a cell mid-tape destroys the left/right sweep landmarks. (Machine 2 only deletes at the right end, where nothing lies beyond.)
💡 Verify the tail, don’t just exit the loop ➔ leaving the loop means “group 1 exhausted”; you still must sweep right and require Δ, or ab3 slips through.
💡 Handle ε explicitly ➔ n=0 is in both languages here; if State 1 has no Δ→R edge to State 2 the empty string crashes and you lose the base case.
💡 Every state needs every rule you rely on ➔ omitted (state, symbol) pairs are rejections by design in these machines; state which omissions are intentional, or a marker reads them as gaps.
🧠 Active Recall
anbnan is not context-free, so no PDA accepts it — what does the TM have that closes the gap?
Answer
Short answer:random access to its own memory. A PDA can only see the top of its stack and must destroy it to look deeper; a TM’s head can return to any cell, so marks left in three different regions of the tape act as three independent counters.
Why:Coupled counts = marks, not pushes ➔ the CFL pumping lemma failed on three groups because uvxyz offers only two pumping sites. The machine-side mirror of that is: one stack ⇒ one count kept in step. Machine 2 keeps three in step by shrinking each group by one per pass, a schedule that needs no memory beyond the tape marks themselves.