0% found this document useful (0 votes)
22 views4 pages

Section 1 3

The document defines and provides examples of ordered structures like tuples, Cartesian products, lists, strings, and relations. It also discusses languages, language operations, relational databases, and counting tuples. Key points include: - Tuples can have repetitions and order, Cartesian products combine sets, and lists are like tuples but without random access. - Strings are like lists over an alphabet, languages are sets of strings, and language operations combine languages. - Relations are sets of tuples that can represent things like databases. Relational databases have attributes for tuple indexes. - The product and counting rules allow calculating sizes of Cartesian products and sets formed from languages and relations.

Uploaded by

Mihaela Andrei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

Section 1 3

The document defines and provides examples of ordered structures like tuples, Cartesian products, lists, strings, and relations. It also discusses languages, language operations, relational databases, and counting tuples. Key points include: - Tuples can have repetitions and order, Cartesian products combine sets, and lists are like tuples but without random access. - Strings are like lists over an alphabet, languages are sets of strings, and language operations combine languages. - Relations are sets of tuples that can represent things like databases. Relational databases have attributes for tuple indexes. - The product and counting rules allow calculating sizes of Cartesian products and sets formed from languages and relations.

Uploaded by

Mihaela Andrei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Section 1.

3 Ordered Structures
Tuples: Have order and can have repetitions. For example, (6, 7, 6) is a 3-tuple and ( ) is
the empty tuple. We write (x1, …, xn) = (y1, …, yn) to mean xi = yi for 1 ≤ i ≤ n.
Cartesian Product: A ¥ B = {(x, y) | x Œ A and y Œ B}. The definition extends to more than
two sets. For example, A ¥ B ¥ C = {(x, y, z) | x Œ A, y Œ B, z Œ C}.
• Notation: A0 = {( )}, A1 = {(x) | x Œ A}, and in general, An = {(x1, …, xn) | xi Œ A}.
Quiz (1 minute). Does (A ¥ B) ¥ C = A ¥ (B ¥ C)?
Lists: Are like tuples but there is no random access. For example, ·a, b, a, cÒ is a list with 4
elements and · Ò is the empty list.
• The operations on lists are head, tail, and cons. For example,
head(·a, b, a, cÒ) = a, tail(·a, b, a, cÒ) = ·b, a, cÒ, cons(a, ·b, a, cÒ) = ·a, b, a, cÒ.
• The set of lists whose elements are in A is denoted by lists(A).
Quiz (1 minute). For L = · ·aÒ, b, ·c, dÒ Ò, find head(L) and tail(L).
Strings: Are like lists, but are represented as juxtaposed elements from a given alphabet.
For example, if A = {a, b}, then some strings over A are: a, b, aa, ab, ba, bb, aaa, bbb.
• The empty string is denoted by L.
• The concatenation of two strings is their juxtaposition. For example, the concatenation of
ab and bab is abbab.
• For any string s we have sL = Ls = s.
• If s is a string, sn denotes the concatenation of s with itself n times. Also s0 = L. For
1
example, (ab)3 = ababab.
Languages
A language is a set of strings, usually taken over some alphabet.
Notation: If A is an alphabet, then the set of all strings over A is denoted by A*.
Example. Some languages over A are: ∅, {L}, A, and A*.
Example. {abna | n Œ N} = {aa, aba, abba, abbba, … } is a language over {a, b}.
Language Operations
Let L and M be languages. The product of L and M, denoted LM, is the language
LM = {st | s Œ L and t Œ M}.
• Notation: L0 = {L}; and Ln = {s1…sn | si Œ L}.
Quiz (1 minute). What are the products L∅ and L{L}?
Quiz (1 minute). Solve for L in the equation {L, a, b}L = {L, a, b, aa, ba, aba, bba}.
• The closure L* is the set of all possible concatenations of strings in L. So
L* = L0 » L1 » … » Ln » …
Quiz (1 minute). What are {L}* and ∅*?
Example. Examine the structure of an arbitrary string x Œ L*(ML)*.
A solution: Use the definitions to write x in terms of strings in L and M.
1. Since x Œ L*(ML)*, it follows that x = uv where u Œ L* and v Œ (ML)*.
2. Since u Œ L*, either u = L or u = s1…sn for some n where si Œ L.
3. Since v Œ (ML)*, either v = L or v = r1t1 …rktk for some k where ri Œ M and ti Œ L.
So x has one of four forms: L, s1…sn, r1t1 …rktk, or s1…snr1t1 …rktk. 2
Relations.
A relation is a set of tuples. If R is a relation and (x1, …, xn) Œ R, we write R(x1, …, xn).
We can usually represent a relation as a subset of some cartesian product.
Example. Let R = {(0, 0), (1, 1), (4, 2), (9, 3), …, (n2, n), …} = {(n2, n) | n Œ N}. We might
call R the “is square of” relation on N. Notice also that R Ã N ¥ N.
Notation: If R is binary, we can use infix to represent pairs in R. For example, from the
previous example, we have (9, 3) Œ R. So we can also write
R(9, 3) or 9 R 3 or 9 is square of 3.
Relational Databases
A relational database is a relation where the indexes of a tuple have associated names
called attributes.
Example. Let Students = {(x, y, z) | x is a Name, y is a Major, and z is Credits}.
Who are the people majoring in CS?
{x | (x, CS, z) Œ Students, for some z}.
Note: We need “for some z” to indicate that z is a variable.
How many math majors are upper division students?
| {x | (x, math, z) Œ Students and z ≥ 90} |.
What is the major of AbeLincoln?
{y | (AbeLincoln, y, z) Œ Students, for some z}.
What is the history department database of names and their credits?
3
{(x, z) | (x, history, z) Œ Students}.
Counting Tuples (or strings or lists)
Product Rule: | A ¥ B | = | A | | B | and | An | = | A |n.
Example. If A = {a, b} and B = {1, 2, 3}, then
A ¥ B = {(a, 1), (a, 2), (a, 3), (b, 1), (b, 2), (b, 3)}.
So | A ¥ B | = 6 = (2)(3) = | A | | B |.
Example. Count the number of strings of length 8 over A = {a, b, c} that begin with either
a or c and have at least one b.
A Solution: Split the problem up into easier problems and combine
U–B U
the results (divide and conquer). Let U be the universe consisting
of the strings over A of length 8 that begin with either a or c. Let B
be the subset of U consisting of strings with no b’s. Then the set of B
strings to count is U – B, as pictured.
It is easy to calculate the cardinality of U – B:
| U – B | = | U | – | U « B | = | U | – | B | (since B is a subset of U)
It is also easy to count U because it has the same cardinality as the set {a, c} ¥ A7, which is
| {a, c} ¥ A7 | = | {a, c} | | A7 | = | {a, c} | | A |7 = (2)37.
It is also easy to count B because it has the same cardinality as the set {a, c}8, which is
| {a, c}8 | = | {a, c} |8 = 28.
So we have the answer:
4
| U – B | = | U | – | U « B | = | U | – | B | = (2)37 – 28, which is 4118.

You might also like