Closure Properties in Theory of Computation: Proof Methods, Worked Examples and Exam Traps

Learn how to prove closure with machine constructions and disprove it with counterexamples across regular, context-free, decidable and recognisable languages.

KnowledgeGate Team

Exam prep & CS education

Updated 22 Sep 20265 min read

Memorising a yes or no closure table is fragile because the answer changes with both the language class and the operation. A safer method is to construct a machine when closure holds, or produce a standard counterexample when it fails. This guide covers regular, context-free, decidable and Turing-recognisable languages, while the Semester & College Exam Courses collection places the topic in the wider CS curriculum.

Closure properties: what the definition actually quantifies

A class of languages C\mathcal C is closed under a binary operation ∘\circ if, for every L1,L2∈CL_1,L_2\in\mathcal C, the language L1∘L2L_1\circ L_2 also belongs to C\mathcal C. For a unary operation such as complement, Kleene star or reversal, closure means that applying the operation to every language in C\mathcal C keeps the result in C\mathcal C.

The quantifier “for every” matters. One successful pair cannot prove closure, but one valid pair whose result leaves the class disproves it.

Keep three questions separate:

  1. What does the operation do to the strings or languages?

  2. Does the resulting language belong to the class?

  3. What construction or counterexample proves that class-level claim?

Positive proofs usually build a machine of the required type. Negative proofs choose members of the class whose result is a known non-member.

Language operations: calculate before naming a theorem

Let L1={ε,0,11}L_1=\{\varepsilon,0,11\} and L2={1,01}L_2=\{1,01\} over Σ={0,1}\Sigma=\{0,1\}. Then

\[

L1∪L2={ε,0,1,01,11},L1∩L2=∅L_1\cup L_2=\{\varepsilon,0,1,01,11\},\qquad L_1\cap L_2=\varnothing.

\]

A complement cannot be calculated until its universe is fixed, normally as Σ∗\Sigma^*.

For concatenation, calculate every pair:

  • ε⋅1=1\varepsilon\cdot1=1 and ε⋅01=01\varepsilon\cdot01=01

  • 0⋅1=010\cdot1=01 and 0⋅01=0010\cdot01=001

  • 11⋅1=11111\cdot1=111 and 11⋅01=110111\cdot01=1101

Therefore,

\[

L_1L_2=\{1,01,001,111,1101\}.

\]

The string 0101 appears once because a language is a set, even though two pairs generate it. Union collects existing strings. Concatenation joins one string from the first language to one from the second.

Regular-language closure: a product-DFA example

Let AA contain binary strings ending in 0. Its DFA has p0p_0, the non-final start state, and final state p1p_1. On 0, either state moves to p1p_1; on 1, either moves to p0p_0.

Let BB contain strings with an even number of 1s. State EE is initial and final, while OO is non-final. A 0 leaves the state unchanged and a 1 toggles E↔OE\leftrightarrow O.

For A∩BA\cap B, form product states S0=(p0,E)S_0=(p_0,E), S1=(p0,O)S_1=(p_0,O), S2=(p1,E)S_2=(p_1,E) and S3=(p1,O)S_3=(p_1,O). Start at S0S_0; only S2S_2 is final.

State

On 0

On 1

S0S_0

S2S_2

S1S_1

S1S_1

S3S_3

S0S_0

S2S_2

S2S_2

S1S_1

S3S_3

S3S_3

S0S_0

Trace 10101010 exactly:

\[

S_0\xrightarrow{1}S_1\xrightarrow{0}S_3\xrightarrow{1}S_0\xrightarrow{0}S_2.

\]

The trace ends in S2S_2, so 10101010 is accepted.

Product DFA trace for strings ending in 0 and containing an even number of 1s. Show states S0=(p0,E) as start, S1=(p0,O), S2=(p1,E) as the only double-circled accepting state, and S3=(p1,O); label 0-transitions S0 to S2, S1 to S3, S2 to S2, S3 to S3; label 1-transitions S0 to S1, S1 to S0, S2 to S1, S3 to S0; below the DFA show the worked input 1010 and the exact trace S0 --1--> S1 --0--> S3 --1--> S0 --0--> S2, ending with ACCEPT.

Changing the final product states proves closure under union or difference. The Regular Language Properties: Closure and Decision Tests guide develops the wider construction toolkit.

Closure-properties comparison table

Operation

Regular

Context-free

Decidable

Turing-recognisable

Union

Yes

Yes

Yes

Yes

Intersection

Yes

No

Yes

Yes

Complement

Yes

No

Yes

No

Difference

Yes

No

Yes

No

Concatenation

Yes

Yes

Yes

Yes

Kleene star

Yes

Yes

Yes

Yes

Reversal

Yes

Yes

Yes

Yes

Precision point: Context-free languages are closed under intersection with a regular language, although they are not closed under arbitrary CFL intersection. Also, L1−L2=L1∩L2‾L_1-L_2=L_1\cap\overline{L_2}, so complement and intersection help explain the difference row.

Use the table for recall, not as the proof. An unfamiliar variation should be settled by a construction or counterexample.

Context-free non-closure: force three counts to agree

Consider

\[

LA={aibicj∣i,j≥0}L_A=\{a^i b^i c^j\mid i,j\ge 0\}.

\]

A grammar is S→XCS\to XC, X→aXb∣εX\to aXb\mid\varepsilon, C→cC∣εC\to cC\mid\varepsilon. It matches the number of aas and bbs. Similarly,

\[

LB={aibjcj∣i,j≥0}L_B=\{a^i b^j c^j\mid i,j\ge 0\}

\]

is generated by T→PQT\to PQ, P→aP∣εP\to aP\mid\varepsilon, Q→bQc∣εQ\to bQc\mid\varepsilon. It matches the number of bbs and ccs. Each language is context-free because each grammar manages one matched pair of counts.

Membership in LAL_A enforces #a=#b\#a=\#b, while membership in LBL_B enforces #b=#c\#b=\#c. Thus both constraints together give

\[

L_A\cap L_B=\{a^n b^n c^n\mid n\ge0\},

\]

which is not context-free. For n=2n=2, aabbccaabbcc satisfies both input constraints. That string illustrates the equality, but the whole non-context-free intersection language is the counterexample.

Why CFL intersection can produce a non-context-free language. Show a left panel LA={a^i b^i c^j | i,j>=0} labelled constraint #a=#b, a right panel LB={a^i b^j c^j | i,j>=0} labelled constraint #b=#c, and the string aabbcc entering both panels with i=2 and j=2; arrows from both panels meet at LA intersection LB={a^n b^n c^n | n>=0}, labelled combined constraint #a=#b=#c and NOT context-free.

The Context-Free Grammars and PDAs: CNF, GNF, Pumping Lemma guide covers the machinery for recognising and disproving CFL claims.

Turing-machine closure: deciders and recognisers

For decidable languages, let D1D_1 and D2D_2 halt on every input. Run both deciders for union and accept if either accepts. For intersection, accept only if both accept. For complement, run D1D_1 and swap its accept and reject outcomes. Guaranteed halting makes each construction safe.

Recognisers require more care because one may loop on a non-member. For recognisable union, dovetail R1(w)R_1(w) and R2(w)R_2(w) by alternating one transition from each, then accept when either accepts. For intersection, record each acceptance and accept after both have occurred.

Why does complement fail? HALTTMHALT_{TM} is recognisable but undecidable. If it and its complement were both recognisable, dovetailing their recognisers would always reveal which side contains the input and would therefore decide HALTTMHALT_{TM}, a contradiction. The Turing Machines and Decidability: Halting Problem Proof article develops the adjacent proof ideas.

Closure-properties question patterns and traps

Check these four statements:

  • P: Regular languages are closed under complement. True, because a complete DFA can have its final and non-final states swapped.

  • Q: Context-free languages are closed under intersection. False, as the LA∩LBL_A\cap L_B counterexample shows.

  • R: A context-free language intersected with a regular language is context-free. True, using a PDA and DFA product construction.

  • S: Turing-recognisable languages are closed under complement. False, as the HALTTMHALT_{TM} argument shows.

The answer is P and R only.

Typical forms include selecting correct statements, matching a class to an operation, supplying a counterexample and choosing a machine construction. Three traps deserve special attention:

  • Flipping final states in an incomplete DFA. First add a dead state and complete every transition, then flip.

  • Treating one successful pair as proof. Closure quantifies over every pair in the class.

  • Running one recogniser until it halts before starting the other. Alternate their steps by dovetailing.

Closure properties: the short decision method

Ask four questions: What is the language class? What operation is applied? Can I build a machine that remains in the class? If not, can I force a known non-member with a counterexample? For Turing machines, add one decisive question: must the machine halt, or only recognise?

The proof anchors are compact: product construction for regular intersection, LA∩LB={anbncn}L_A\cap L_B=\{a^n b^n c^n\} for CFL non-closure, and dovetailing for recognisable union and intersection. After learning the method, use the over 30 published Closure Properties questions for varied practice.

The Theory Of Computation / Automata Theory course is the structured next step for connecting closure properties to automata, grammars, Turing machines, decidability and practice.