Describe the Language with Operations
Practice describing languages with union, intersection, difference, complement, concatenation, star, reverse and prefixes: requirements from DNA, codes and file names turned into expressions and checked exactly, three representations of one language, and an open lab.
Last updated:
From a requirement in words to an expression
A requirement such as “a DNA sequence that starts with ATG and ends with a stop codon” is a condition on words.
Each part of it, “starts with ATG”, “ends with a stop codon”, is a language, and “and” combines the two.
The operations on languages (union, intersection, difference, complement, concatenation, star, reverse, prefixes) combine languages into a new language.
An expression is a combination of languages by means of these operations, and two expressions are equal when they describe exactly the same words.
This requirement is solved in Languages: Practice and Check of Understanding, in questions 4 and 5.
The tool decides equality exactly, and not by trying words. When your expression is not the required language, the tool shows a shortest word on which they differ and which side contains it.
Questions are drawn at random; press “New task” for another one.
The tool has three activities, among them the open lab: in it you choose reference languages (they are named , , …), write an expression over them and see its words.
The tool needs JavaScript. The written questions below can be done on paper.
Written questions
Question 1. Let be the words over that start with , the words that end with , and the words of even length.
The expressions and look alike. In the open lab choose , and , and compare them.
On which word do they differ, and which of the two contains it?
Hint
By the order of operations in Languages: Operations and Equalities, intersection binds before union, so the first expression is .
Check the words of length , , in this order.
Answer
The shortest word is . It starts with , so it is in and therefore in .
In it is not, because its length is odd, so it is not in .
The words and are in neither expression, so is the shortest difference.
Question 2. Over the alphabet a code is a word. With (the letters, without the digits), and , write an expression for “a code that starts with a letter and ends with a digit”.
Do you need to add a condition on the length of the code to the expression?
Explain.
Hint
Try a code of length .
Answer
. The condition on the length already follows from the expression:
a word of this language has a first character from and a last character from , and these are two different characters, because no character is both a letter and a digit.
So every word of the language has at least two characters, and the middle part may be empty.
Question 3. Show that for all languages over the same alphabet, after checking it in the open lab on two reference languages.
Hint
Take a word and unfold ” is in the complement of an intersection” with the definitions of complement and intersection.
Answer
For :
The two languages have the same words, so they are equal.