# Relations

Document Sample

```					Sequences ,Strings and Binary
operations
Reading: Chapter 5 (315 – 340)
From the textbook

1
Sequences
• A sequence is an ordered list of values. These
values could come from any set:
1.0, 1.2, 1.4, 1.6, 1.8, 2.0
1, 1, 2, 1, 2, 3, 1, 2
m, a, t, h, e, m, a, t, i, c, s
and can be finite (as above), or infinite:
1, 2, 4, 8, 16, …
1, 1, 2, 3, 5, 8, 13, …
1/1, 3/2, 7/5, 17/12, 41/29, …           2
Sequences
• We usually denote the elements of sequences
using subscripts: c1, c2, c3, ….

• The first finite sequence of the last slide is
given by:
ci = 0.8 + 0.2 × i for 1 ≤ i ≤ 6.

• The first infinite sequence is given by:
di = 2i for i ∈ ℕ.
3
What is a sequence?

• A sequence is really nothing more (or less) than a
function.
• A finite sequence having n elements is a function
whose domain is In = {1, 2, …,n} and whose
codomain is whatever set the elements of the
sequence belong to.
• An infinite sequence is a function with domain ℕ.

4
Some special sequences
• Let a and d be real numbers. The sequence:
a, a + d, a + 2d, a + 3d, ...,a + (n - 1)d,...
is called an arithmetic progression (AP) with
first term a and common difference d. If we
make the sequence finite by chopping it off at
some point, then we may add “of length n”.
• For instance, the AP of length 7 with first term
-2 and common difference 3 is:
-2, 1, 4, 7, 10, 13, 16.
5
Some special sequences
• In an AP, the difference between consecutive
terms is fixed (equal to d).
• What if, instead, the ratio between successive
terms is fixed, say equal to r. Then we have,
the sequence:
a, ar, ar2; ar3, ...,arn-1,...
called a geometric progression (GP) with first
term a and common ratio r.
6
Summation
• Adding up all or part of a sequence is such a
common operation that it has its own
notation.
• Sometimes we can make do with “dot dot dot”:
a4 + a5 + …+ a17 or 1 + 3 + 5 + …+ 21
but we often need to be more precise.
• To do this we introduce summation notation
using the symbol ∑.
7
Summation
• In this notation, the two sums of the last slide
could be written as:
17                  10

a
i4
i
and       (2 j  1)
j 0

• The variable occurring in these sums (i and j)
is known as a dummy variable. It is really just
a placeholder for an index, which runs
through the indicated range (from 4 to 17, and
0 to 10 respectively) in steps of 1.               8
Strings
• Let A be a finite non-empty set. A finite sequence
of elements belonging to A is called a string over
the alphabet A.
• If A is clear from context, such a sequence may
simply be called a string.
• When writing strings we usually omit the
commas between elements, and rarely refer to
the subscript notation. So, if A = {a, b, c}, then
we might write some strings over A as:
abbaca, aaaaaaaa, abccbaabccba.        9
Strings
• The length of a string is the number of symbols
that it contains. For a string s, the length of s is
denoted |s|. So:

|abbaca| = 6, |aaaaaaaa| = 8,
|abccbaabccba| = 12.

• A string with no elements is called the empty
string, and is usually denoted by λ.
10
Concatenation of strings
• There is a very important binary operation on
strings called concatenation.
• The concatenation of a string s and a string t is
just the string obtained by writing down s and
then following it with t.
• Because this operation is so simple and
fundamental, we usually don’t even bother with a
symbol for it (like multiplication among numbers
and variables). If we do need one, we’ll use · .
11
Concatenation of strings
• Concatenation is associative but not commutative.
• An illustrative example and counterexample:
(ab · a) · c = aba · c = abac = ab · ac = ab · (a · c),
aba · bba = ababba ≠ bbaaba = bba · aba
• Concatenation has an identity element (the empty
string, λ) both on the left and the right.
• The length of a concatenated string can be
computed from the lengths of its parts as follows:
|s · t| = |s| + |t|               12
Binary operations
• A binary operation on a set A is nothing more
than a function from A × A to A.
• In other words, it takes pairs of values from A
and converts them into single values from A.
• The most familiar of binary operations are
addition and multiplication. But, we don’t write:
+:ℝ×ℝ⟶ℝ
or ×(5, 2) = 10. We write, x+y, and 5 × 2 instead.
13
Binary operations
• For this reason we usually write binary operations
infix that is, between their arguments, rather than
prefix, before their arguments.
• Also, the symbols chosen for binary operations are
usually reminiscent of + or × rather than letters
like f and g as we did for single variable functions.
• For a generic binary operation we will use the
symbol ∗ .
14
Operation tables
• When we are given a binary operation on a
finite set, it is common to specify it in tabular
form, sometimes called a Cayley table.
• For example, if we take ∗ to be the binary
operation on {0, 1, 2, 3} defined by
a ∗ b = min(a, b) the corresponding Cayley
table is:           ∗ 0 1 2 3
0   0   0   0   0
1   0   1   1   1
2   0   1   2   2
3   0   1   2   3                 15
Operation tables
∗ 0 1 2 3
0   0   0   0   0
1   0   1   1   1
2   0   1   2   2
3   0   1   2   3

• To find a ∗ b in such a table we look at the
value written in the intersection of the row
marked with a (to the left of the vertical bar)
and the column marked with b (above the line.)

16
Properties of binary operations
Let S be a set, and ∗ a binary operation on S.
Then:
• ∗ is associative if, for all a, b, c ∈ S:
a ∗ (b ∗ c) = (a ∗ b) ∗ c
• ∗ is commutative if, for all a, b ∈ S:
a∗b=b∗a
• Note that the operations × and + are both
associative and commutative.
17
Example
• Consider the operation of subtraction, -, on R.

• This operation is certainly not commutative
because, for instance:
5-3≠3–5
(in fact, pairs of real numbers a and b for
which a - b = b - a are rather special!)

18
Example
• Nor is it associative:
(3 - 5) - 2 = -2 - 2 = -4
3 - (5 - 2) = 3 - 3 = 0
• The commutative and associative properties
are universal properties of a binary operation,
and so to show that they do not hold requires
only a single counterexample (though for
subtraction it’s not hard to find many others!)
19
Identity
• Let S be a set, and ∗ a binary operation on S.
Then:
• An element e ∈ S is a left identity for ∗, if for
all a ∈ S:
e∗a=a
• An element f ∈ S is a right identity for ∗, if for
all a ∈ S:
a∗f=a
20
Identity
Note that on ℝ:
• 0 is both a left and right identity for addition

• 1 is both a left and right identity for
multiplication

• 0 is a right identity for subtraction, but
subtraction has no left identity.
21

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 4 posted: 4/4/2011 language: English pages: 21
How are you planning on using Docstoc?