Exercise

Sort the Words: Languages as Sets

Practice languages as sets: sort the 15 words of length at most 3 into the regions of a Venn diagram of two or three languages, or choose the words of a set expression, and get an explanation for every mistake.

Last updated:


Where does each word belong?

A language over {a,b}\{a,b\} is a set of words, so two languages can be compared the way two sets are compared.
In this tool each language is given by a condition, such as “words that start with aa”, and the universe is the 1515 words of length at most 33 (the empty word ε\varepsilon is one of them).
The universe is the set of words that the diagram shows; it is finite so that every word can be seen, and the complement of a language is the words of the universe that are not in it.
A Venn diagram draws every language as a circle. A word belongs to the region that records which circles it is inside:
only L1L_1⁠, both L1L_1 and L2L_2⁠, or none of them.

The tool draws a new random question each time. It checks your answer at once, and for every wrong word it says, in words, which conditions the word satisfies and where it should have been placed.

How to use the tool
  1. Choose a task type: sorting into two sets, sorting into three sets, or choosing the words of a set expression.
  2. In a sorting task, drag a word to a region of the diagram or to one of the region boxes under it. On a keyboard or a touch screen, choose a word and then press the button of its region; the next word that is not placed yet is chosen for you.
  3. In an expression task, tap every word that belongs to the set expression shown.
  4. Press “Check”. Words marked with ✓ are right, and words marked with ✗ come with the reason. “Show the solution” fills in the answer, and “New question” draws another question. The question number can be added to the page address as ?seed= to get the same question again.

The tool needs JavaScript. Use the questions below on paper instead.

Figure of one question
A Venn diagram of the 15 words of length at most 3 for L1, the words that start with a, and L2, the words that end with b. Only in L1: a, aa, aaa, aba. In both: ab, aab, abb. Only in L2: b, bb, bab, bbb. In neither: the empty word, ba, baa, bba.
The figure shows one question: L₁ is the set of words that start with a, L₂ is the set of words that end with b.

Questions

In these questions L1L_1 is the language of the words that start with aa⁠, and L2L_2 is the language of the words that end with bb⁠, inside the 1515 words of length at most 33⁠.

Question 1. In which region of the diagram is the empty word ε\varepsilon⁠, and why?

Hint

Does ε\varepsilon have a first letter? Does it have a last letter?

Answer

The empty word has no letters, so it does not start with aa and does not end with bb⁠.
It is in neither circle, in the region outside both L1L_1 and L2L_2⁠, together with baba⁠, baabaa and bbabba⁠.

Question 2. Write the words of L1△L2L_1\triangle L_2 (the symmetric difference: the words that are in exactly one of the two languages, see Languages: Operations and Equalities), and check that this set equals (L1∪L2)−(L1∩L2)(L_1\cup L_2)-(L_1\cap L_2)⁠.

Hint

List L1L_1 and L2L_2 first, then L1∩L2L_1\cap L_2 (the words in both lists) and L1∪L2L_1\cup L_2 (the words in at least one list).
Count: the number of words in L1∪L2L_1\cup L_2 is the number in L1L_1⁠, plus the number in L2L_2⁠, minus the number in both.

Answer

L1={a,aa,ab,aaa,aab,aba,abb}L_1=\{a,aa,ab,aaa,aab,aba,abb\} has 77 words and L2={b,ab,bb,aab,abb,bab,bbb}L_2=\{b,ab,bb,aab,abb,bab,bbb\} has 77 words. Three words are in both:
L1∩L2={ab,aab,abb}L_1\cap L_2=\{ab,aab,abb\}⁠. So L1∪L2L_1\cup L_2 has 7+7−3=117+7-3=11 words. Removing the three words of L1∩L2L_1\cap L_2 from L1∪L2L_1\cup L_2 leaves 88 words:
a,aa,aaa,aba,b,bb,bab,bbba,aa,aaa,aba,b,bb,bab,bbb⁠. These are exactly the words that are in one language and not in the other, which is the definition of L1△L2L_1\triangle L_2⁠.

Question 3. Find the words of (L1∪L2)C(L_1\cup L_2)^{C} and the words of L1C∩L2CL_1^{C}\cap L_2^{C}⁠, and explain in one sentence why they are the same.

Hint 1

What does “not (L1L_1 or L2L_2⁠)” say in words?

Hint 2

A word is in (L1∪L2)C(L_1\cup L_2)^{C} when it is not in L1L_1 and not in L2L_2⁠.
Compare this sentence with the meaning of L1C∩L2CL_1^{C}\cap L_2^{C}⁠.

Answer

The words that are in neither language are ε,ba,baa,bba\varepsilon, ba, baa, bba⁠. For L1C∩L2CL_1^{C}\cap L_2^{C}⁠:
the words that do not start with aa are ε,b,ba,bb,baa,bab,bba,bbb\varepsilon,b,ba,bb,baa,bab,bba,bbb⁠, and of these the ones that do not end with bb are ε,ba,baa,bba\varepsilon,ba,baa,bba⁠, the same four words.
The reason: the statement “the word is in L1L_1 or in L2L_2” is false exactly when the word is in neither language, that is, when it is not in L1L_1 and also not in L2L_2⁠.
This is one of De Morgan’s laws.