skip to content

Why are the languages a pushdown automaton accepts closed under union but not under intersection?

level: seniorimportance: nice to knowfreq 26%

answer

  1. union needs one choice at the start
  2. the branches never share the store
  3. a product machine would need two stores
  4. three-equal-blocks is the counterexample
  5. complement follows by De Morgan

basics

~20 s

Union needs only one decision at the start: a machine that guesses which of two machines to run accepts exactly their union. Intersection would need two stores at once, and a counterexample settles it - two languages whose intersection demands three equal blocks.

solid answer

~40 s

For union, add a fresh start that moves without consuming input into either machine's start configuration; whichever branch succeeds, the word is accepted, and the branches never share the store. With rule sets the same construction is `S -> S1 | S2` over disjoint nonterminals. Intersection has no such trick, because a product machine would need **both** stores running at once and the model has one. The counterexample is concrete: `{a^i b^i c^j}` and `{a^i b^j c^j}` are each accepted by one store, and their intersection is `{a^n b^n c^n}`, which no stack machine accepts. Complement then falls out by De Morgan - closure under union plus closure under complement would force closure under intersection, so complement fails too. Intersecting with a **regular** language is the exception and stays inside the class.

go deeper

for a junior

Know what the question is asking: whether combining two accepted languages with 'or' or with 'and' gives you something the same kind of machine still accepts.

for a middle

Explain the union construction and why it costs nothing: the two branches are alternatives, so only one of them ever uses the store in a run.

for a senior

Be able to produce the intersection counterexample and state what it implies for a validator: two independent structural rules mean two readers, not a merged rule set.

for a principal

The consequence to plan around is that a format cannot acquire a second independent structural constraint for free; it changes every consumer's reader from one pass into two or into a parallel pair.

Closure properties are the compact way of saying which ways of combining two accepted languages give you another one. For this class the pattern is lopsided, and the lopsidedness has a direct consequence for anyone building a validator out of two independent structural rules. ## Union: one decision, then never again Given two machines, build a third with a fresh start state and two moves out of it that consume no input, one into each machine's start configuration. A word is accepted if some run accepts it, so the new machine accepts exactly the words one of the originals accepts. The essential point is that the two branches are **alternatives**: only one of them ever touches the store in a given run, so the single store is never contended. The same construction in rule form is `S -> S1 | S2`, after renaming so the two rule sets share no nonterminals. Concatenation (`S -> S1 S2`) and repetition (`S -> S S1` with an empty alternative) work for the same reason. ## Intersection: two machines, one store The product construction that works for finite-state machines - run both in lock-step, with the state being a pair - fails here. Pairing the states is fine, since the control is finite either way. Pairing the **stores** is not: the model has one, and two independent last-in-first-out sequences cannot be interleaved into one and later drawn off separately. That is motivation rather than proof. The proof is a counterexample: 1. Let `L1` be the words `a^i b^i c^j` - the first two blocks equal, the third free. One store accepts it: match a's against b's, then consume the c's. 2. Let `L2` be the words `a^i b^j c^j` - the last two blocks equal, the first free. One store accepts it: consume the a's, then match b's against c's. 3. A word lies in both exactly when its first two blocks are equal **and** its last two blocks are equal, which forces all three to be equal. 4. So the intersection is `{a^n b^n c^n}`, which no stack machine accepts. Two members of the class whose intersection is outside it is exactly what non-closure means. ## Complement: settled by De Morgan The intersection of two languages is the complement of the union of their complements. The class is already closed under union; if it were also closed under complement, that identity would make it closed under intersection as well. Intersection fails, so **complement must fail too**. Worth stating in that direction: the argument runs from union plus complement to intersection, not the other way round. Note that the deterministic subclass behaves differently and **is** closed under complement - the failure here is a property of the full class. ## The exception that is genuinely useful Intersecting with a **regular** language stays inside the class. A finite-state machine has no unbounded memory, so its current state rides along inside the stack machine's finite control, and the pair advances together while the one store is used exactly as before. The result is another stack machine. | operation | stays in the class? | why | |---|---|---| | union | yes | one initial choice picks a machine; branches never share the store | | concatenation | yes | one rule set's start feeds the other's | | repetition | yes | a rule that re-enters the start symbol | | intersection | no | `a^i b^i c^j` with `a^i b^j c^j` yields three equal blocks | | complement | no | union closure plus complement closure would force intersection | | intersection with a regular language | yes | the finite-state machine's state rides in the control | ## What a validator author takes from this - 'Accepted by both rule sets' is **not** in general expressible as a third rule set. There may be no such rule set at all, so merging two grammars is not a technique. - A validator enforcing two independent structural constraints runs both readers and combines the verdicts, which means either two passes over buffered input or two readers driven over the same stream in parallel. - Layering a **regular** side-condition on top of a nesting-checked format is free in this sense: it can be folded into the reader's control without touching the store. - Because complement is not available, 'describe everything this format rejects' is not a request that always has a rule-set answer. A rejection story has to come from the reader, not from a second grammar.

  • Why does closure under union plus failure under intersection settle complement?
    By De Morgan, the intersection of two languages is the complement of the union of their complements. If the class were closed under complement it would then be closed under intersection too, since union closure already holds. Intersection fails on a known pair, so complement closure cannot hold either.
  • Why is intersecting with a regular language different?
    A finite-state machine carries no unbounded memory, so its state fits inside the stack machine's finite control: the product tracks both at once and the single store is used exactly as before. Two stack machines cannot be combined that way, because each of them wants the one store to itself.
  • What does non-closure under intersection mean for a validator built from rule sets?
    You cannot in general express 'accepted by both rule sets' as a third rule set - there may be none. A validator applying two independent structural constraints has to run both readers over the input and combine the verdicts, which costs either a second pass over buffered input or two readers driven in parallel.

saying these in an interview costs you the question

  • Says the union machine runs both machines on one shared store
  • Thinks merging two rule sets yields the intersection of their languages
  • Believes closure under complement follows from closure under union
  • Says intersecting with a regular language also leaves the class
  • Treats the three-block counterexample as an exotic edge case
  • Confuses the full class with its deterministic subclass on complement