{0ⁿ 1ⁿ : n ≥ 0}: the canonical push-down language #
The first non-regular language formalized here: the TM uses its single work
tape as a counter (push on 0, pop on 1). Demonstrates a textbook
push-down construction with an O(n) time bound.
The machine has six control states (start, initWork, scanZeros,
scanOnes, reject, done) and maintains the invariant that the work
head equals the current stack size. Emptiness is detected structurally
via the permanently-▷ cell 0.
Main definitions #
TM.anbnTM— 6-state 1-work-tape push-down machine.Language.anbn—{0ⁿ 1ⁿ : n ≥ 0}.
Main results #
anbnTM_reachesIn— halts in|x| + 3steps on every input.anbn_in_DTIME,anbn_mem_P.
Control states of anbnTM.
start: initial state. Moves all heads from cell 0 (▷) to cell 1.initWork: rewinds work head back to cell 0 (where ▷ marks emptiness).scanZeros: scanning the0-prefix; pushes on0, transitions on1.scanOnes: scanning the1-suffix; pops on1, rejects on0.reject: sink state; consumes remaining input then halts with0.done: halted.
- start : AnBnPhase
- initWork : AnBnPhase
- scanZeros : AnBnPhase
- scanOnes : AnBnPhase
- reject : AnBnPhase
- done : AnBnPhase
Instances For
Equations
- One or more equations did not get rendered due to their size.
Push-down TM deciding {0ⁿ 1ⁿ}. One work tape used as a unary counter:
the work head holds the current stack size (0 means empty, detected by
reading ▷ at cell 0).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The output that anbnTM produces when run from scan state s with work
head h (= stack size) and remaining input rest. Structurally
recursive on rest.
Equations
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.reject x✝ [] = Complexity.Γw.zero
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.reject x✝ (head :: rest) = Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.reject x✝ rest
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanZeros 0 [] = Complexity.Γw.one
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanZeros n.succ [] = Complexity.Γw.zero
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanZeros x✝ (false :: rest) = Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanZeros (x✝ + 1) rest
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanZeros 0 (true :: rest) = Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.reject 1 rest
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanZeros h.succ (true :: rest) = Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanOnes h rest
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanOnes 0 [] = Complexity.Γw.one
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanOnes n.succ [] = Complexity.Γw.zero
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanOnes x✝ (false :: rest) = Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.reject x✝ rest
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanOnes 0 (true :: rest) = Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.reject 1 rest
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanOnes h.succ (true :: rest) = Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.scanOnes h rest
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.start x✝¹ x✝ = Complexity.Γw.blank
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.initWork x✝¹ x✝ = Complexity.Γw.blank
- Complexity.TM.anbnExpected Complexity.TM.AnBnPhase.done x✝¹ x✝ = Complexity.Γw.blank
Instances For
Common invariants for a configuration during the scan phase.
Instances For
anbnTM halts in |x| + 3 steps on every input, writing the correct
answer (Γ.one if x = 0ⁿ 1ⁿ, else Γ.zero) to output cell 1.
The language {0ⁿ 1ⁿ : n ≥ 0} — the canonical context-free
but non-regular language. A string x is in anbn iff it consists of
some n copies of false followed by the same number of copies of
true.
Equations
- Complexity.Language.anbn = {x : List Bool | ∃ (n : ℕ), x = List.replicate n false ++ List.replicate n true}
Instances For
anbnTM decides Language.anbn in time |x| + 3.
anbn ∈ DTIME(n + 3).