Exercise

Counterexample Hunter

Claims about languages and their operations: decide whether each is true for all languages, refute the false ones with a counterexample that the tool checks exactly, and order the proof of the true ones.

Last updated:


True for all languages, or false for some?

A claim about languages says that two expressions always describe the same language, whatever languages we put in the variables L1,L2,L3L_1,L_2,L_3⁠.
For example, ”L1L2=L2L1L_1L_2=L_2L_1 for all languages”. Two kinds of work belong to such a claim:

  • To show that it is false, one counterexample is enough: particular languages, and one word that belongs to one side and not to the other.
  • To show that it is true, no number of examples is enough, because there are infinitely many languages. We need a proof for an arbitrary word, usually a chain of “if and only if” steps, each justified by a definition or a law of logic.

The tool below draws a claim about languages over the alphabet {a,b}\{a,b\}⁠, and you decide whether it is true.

How to use the tool

Choose whether the claim is true or false. For a false claim, build small finite languages and a word that is in only one of the sides, and the tool evaluates both sides exactly.
For a true claim, put the lines of its proof in order and pick the reason for each line.
The languages that you type are finite lists of words.

The Counterexample Hunter needs JavaScript. Use the questions below on paper instead.

Questions on paper

Question 1. Decide whether (L1∩L2)L3=L1L3∩L2L3(L_1\cap L_2)L_3=L_1L_3\cap L_2L_3 holds for all languages. If not, give languages and a word that separates the two sides.

Hint 1

What happens on the left-hand side when L1L_1 and L2L_2 have no word in common?

Hint 2

A word can be split into a part from L1L_1 or L2L_2 and a part from L3L_3 in more than one way.
Take L1L_1 and L2L_2 with no word in common.

Answer

The claim is false. Take L1={a}L_1=\{a\}⁠, L2={aa}L_2=\{aa\} and L3={ε,a}L_3=\{\varepsilon,a\}⁠. The languages L1L_1 and L2L_2 have no word in common, so the left side is ∅\varnothing⁠.
On the right, L1L3={a,aa}L_1L_3=\{a,aa\} and L2L3={aa,aaa}L_2L_3=\{aa,aaa\}⁠, so their intersection is {aa}\{aa\}⁠.
The word aaaa is in the right side only.

Question 2. Prove that (L1L2)R=L2RL1R(L_1L_2)^R=L_2^RL_1^R for all languages.

Hint

Take an arbitrary word ww and follow it through the definitions.
The reverse of a product of two words is the product of the reverses in the opposite order:
(xy)R=yRxR(xy)^R=y^Rx^R⁠.

Answer

Let ww be an arbitrary word. Then w∈(L1L2)Rw\in(L_1L_2)^R if and only if wR∈L1L2w^R\in L_1L_2 (definition of reverse), if and only if wR=xyw^R=xy for some x∈L1x\in L_1 and y∈L2y\in L_2 (definition of concatenation), if and only if w=(wR)R=(xy)R=yRxRw=(w^R)^R=(xy)^R=y^Rx^R for some such xx and yy (by the lemma (vR)R=v(v^R)^R=v⁠, Question 13 in Languages: Practice and Check of Understanding, and by the reverse of xyxy⁠), if and only if w∈L2RL1Rw\in L_2^RL_1^R (definitions of reverse and concatenation).
The two languages have the same words, so they are equal.

Question 3. A student tests a claim on a thousand random small languages and finds no counterexample.
Does this prove the claim? What would you do next?

Answer

No. A claim “for all languages” can fail only on rare languages that the random choice did not produce, and there are infinitely many languages, so a finite test is evidence and not a proof.
The next step is a proof for an arbitrary word, or a search that is aimed at the places where such claims usually fail:
empty languages, languages that contain ε\varepsilon⁠, and languages with no word in common.