Hello! Welcome back to our course on the theory of computation.
In our last lesson, we defined Context-Sensitive Grammars (CSGs) as non-contracting grammars and Linear Bounded Automata (LBAs) as a type of non-deterministic Turing machine whose tape is bounded by the length of its input. We concluded by stating the fundamental theorem that these two formalisms are equivalent.
Today, we will delve into that equivalence. The goal of this lesson is to fulfill the learning outcome: Explain the relationship between CSGs and LBAs. We will explore the "if and only if" nature of this relationship by sketching the proofs for both directions. This will solidify your understanding of why the LBA is the precise computational model for context-sensitive languages.
The Equivalence of CSGs and LBAs
The core relationship is stated by a theorem, sometimes known as the Kuroda-Myhill theorem:
Theorem: A language is context-sensitive if and only if it is accepted by a Linear Bounded Automaton.
To understand this, we need to see how to get from a grammar to a machine, and from a machine back to a grammar.
- If L is a CSL, then L is accepted by an LBA. (CSG LBA)
- If L is accepted by an LBA, then L is a CSL. (LBA CSG)
Let's explore each direction.
Part 1: From Context-Sensitive Grammar to Linear Bounded Automaton (CSG LBA)
If we have a language generated by a CSG, how can we build an LBA that accepts exactly the strings in ?
The key idea is to have the LBA perform a reverse derivation. Given an input string , the LBA will try to work backward through the grammar's production rules to see if it can reach the start symbol . If it can, the string must be in the language.
Here's how the LBA operates:
- The input string is placed on the LBA's tape.
- The LBA non-deterministically chooses a production rule from the CSG, say .
- It non-deterministically finds a substring on its tape that matches .
- It replaces that occurrence of with .
- The LBA repeats steps 2-4. If the tape ever contains only the start symbol (followed by blanks), the LBA halts and accepts.
Why does this work on an LBA?
The crucial property is that CSGs are non-contracting. Every rule satisfies . When our LBA works in reverse, it replaces with . This means the string on the tape will either shrink or stay the same length. It will never grow larger than the original input string .
Since the working tape space never needs to exceed the initial length of , all computations can be contained within the linear bounds of the LBA's tape.
To see a more formal description of this process, please read the first part of the proof in the following resource.
Context-sensitive Languages and Linear Bounded Automata
This document, 'Context-sensitive Languages and Linear Bounded Automata' by Josh Bax and Andre Nies, provides an excellent summary of the equivalence proof. We will focus on the first direction.
Please read the section titled 'Theorem 1.5.13', focusing specifically on the proof direction marked '”⇒”' (starts with 'Given a context-sensitive grammar G...'). This section details the reverse-derivation strategy we just discussed.
Part 2: From Linear Bounded Automaton to Context-Sensitive Grammar (LBA CSG)
This direction is more intricate. Given an LBA, how do we construct a CSG that generates the exact same language the LBA accepts?
The strategy is to make the grammar simulate the LBA's computation. The non-terminal symbols of our grammar will be complex, encoding the entire state of the LBA's computation at any given step.
This is often conceptualized as a "two-track" system:
- Track 1 (Bottom): Stores the final terminal string that we want to generate.
- Track 2 (Top): Simulates the LBA's computation on that string, including the current state and head position.
A non-terminal in our grammar might look like [q, X, a], which could mean: "The LBA is in state q with its head over this cell, the cell currently contains symbol X, and the final terminal symbol for this cell is a."
The grammar's derivation will proceed in three main phases:
- Initialization: A set of starting rules generates a string of these complex non-terminals, representing the initial configuration of the LBA on some input . This string effectively sets up the two tracks.
- Computation Simulation: The core of the grammar consists of production rules that mimic the LBA's transition function, .
- A right move
δ(p, X) = (q, Y, R)would correspond to a grammar rule like[p,X][Z] → [Y][q,Z], which moves the stateqto the next symbol. - A left move
δ(p, X) = (q, Y, L)would correspond to a rule like[Z][p,X] → [q,Z][Y].
These rules are carefully constructed to be non-contracting; they just shift the state information around within the sentential form.
- A right move
- Cleanup: If the simulated computation reaches an accepting state, a final set of rules cleans up the simulation track, leaving only the terminal symbols from the bottom track. For example, a rule like
[q_accept, X, a] → awould convert the complex non-terminal into its final terminal symbola.
The following resource provides a concise, rule-based summary of how this simulation works.
Second Course in Formal Languages and Automata Theory
These lecture slides from 'Second Course in Formal Languages and Automata Theory' by H.J. Hoogeboom show the patterns for the grammar rules that simulate LBA transitions.
Please review slides VII-7 and VII-8. Don't worry about memorizing every rule variant. Focus on understanding the pattern for each type of LBA move (right, stationary, left) and how a grammar rule can represent that action by rewriting adjacent non-terminals.
Given your experience with systems design, you can think of this construction as a form of transpilation: we are compiling the operational logic of one system (the LBA's transition function) into the declarative rules of another system (the CSG's productions). The complexity of the grammar's non-terminals is necessary to carry the state required to faithfully simulate the automaton.
Test your understanding!
Consider a grammar rule designed to simulate an LBA transition: A[p, B] → [q, A]C.
Based on the patterns we've discussed, what kind of LBA move does this rule most likely represent?
- A right move
- A left move
- A stationary move
- A cleanup move
Show answer
- A left move. The state symbol
pwas associated with the symbolBon the right. After the rule is applied, the new stateqis associated with the symbolAon the left. This represents the LBA's head moving one cell to the left. The symbolsBandCrepresent the new tape symbols written by the transition.
Conclusion
Today we've confirmed the deep and precise relationship between Context-Sensitive Grammars and Linear Bounded Automata. They are two sides of the same coin, describing the same class of languages.
Key Takeaways:
- CSG to LBA: An LBA can recognize a context-sensitive language by running a grammar's derivation in reverse. The non-contracting nature of CSG rules () guarantees that the LBA's tape usage will never exceed the length of the original input, fitting within its linear bounds.
- LBA to CSG: A CSG can generate the language of an LBA by simulating its computation. The grammar uses complex non-terminals to encode the LBA's configuration (state, head position, tape content) and has production rules that mimic the LBA's transitions. This construction yields a non-contracting grammar.
- This equivalence firmly establishes the LBA as the machine counterpart to CSGs, just as finite automata are to regular grammars and pushdown automata are to context-free grammars.

Preview of the Next Lesson:
We have now defined and related all the major language classes and their corresponding machines. In the next lesson, we will put it all together to formally present the Chomsky Hierarchy. We will illustrate the strict, nested containment of these language families (Regular Context-Free Context-Sensitive Recursive Recursively Enumerable) and summarize their defining characteristics.