notes on relations

Definition 1.  Let A and B be sets. A binary relation from A to B is a subset of A X B.

In other words, a binary relation from A to B is a set R of ordered pair in which the first element of each ordered pair comes from A and the second element comes from B.  We use aRa to denote that (a, b) belongs to R.

Recall that a function f from a set A to a set B assigns exactly one element of B to each element of A. The graph of f is the set of ordered pairs (a, b) such that b=f(a). Because the graph of f is a subset of A X B, it is a relation from A to B. Moreover, the graph of f has the property that each element of A is the first element of exactly one ordered pair of the graph.

 

Definition 2. A relation on the set A is a relation from A to A.

 

Definition 3. A relation R is called reflexive if aRa for each element of A.

 

Definition 4. A relation R on a set A is called symmetric if bRa whenever aRb, for all a, b belongs to A.  A relation R on a set A such that for all a, b belongs to A, if aRb and bRa, then a=b, is called antisymmetric.

 

Definition 5. A relation R on a set A is called transitive if whenever aRb and bRc, then aRc, for all a, b, c belongs to A.

 

Combining relations

Because relations from A to B are subsets of A X B, two relations from A to B can be combined in any way two sets can be combined, e.g. using union operator.

 

Definition 6. Let R be a relation from a set A to a set B and S a relation from a set B to a set C. The composite of R and S is the relation consisting of ordered pairs (a, c), where a belongs to A, and c belongs to C, and for which there exist an element b belonging to B such that aRb and bRc.

 

Theorem 1. The relation R on a set A is transitive if and only if the nth order of composite of R is a subset of R, for n=1,2,3…

Definition 7. Let A1, A2, …, An be sets. An n-ary relation on these sets is a subset of A1 X A2 X …X An. The sets A1, A2,…, An are called the domains of the relation, and n is called its degree.

Databases and relations

Relations used to represent databases are also called tables, because these relations are often displayed as tables. Each column of the table corresponds to an attribute of the database.

A domain of an n-ary relation is called a primary key when the value of the n-tuple from this domain determines the n-tuple. That is, a domain is a primary key when no two n-tuples in the relation have the same value from this domain.

When the values of a set of domains determine an n-tuple in a relation, the Cartesian product of these domains is called composite key.

 

Definition 8. Let R be an n-ary relation and C a condition that the elements in R may satisfy. Then the selection operator Sc maps the n-ary relation to the n-ary relation of all n-tuples from R that satisfy the condition C.

 

Definition 9. The projection P(i1, i2,..im) where i1<i2<..<im, maps the n-tuple (a1,a2,…,an) to the m-tuple (ai1,ai2,…,aim), where m<=n.

In other words, the projection operator P(i1, i2,..im) deletes n-m of the components of an n-tuple, leaving the i1th,i2th,..,imth components.

Few rows may result when a projection is applied to a relation. This happens when some of the n-tuples in the relation have identical values in each of the m components of the projection, and only disagree in components deleted by the projection.

Definition 10. Let R be a relation of degree m and S a relation of degree n. The joint Jp(R, S), where p<=m and p<=n, is a relation of degree m+n-p that consist of all (m+n-p)-tuples (a1,a2,…,am-p, c1,c2,…cp,b1,b2,…bn-p), where the m-tuple (a1,a2,…am-p,c1,c2,…cp) belongs to R, and the n-tuple (c1,c2,…,cp,b1,b2,…,bn-p) belongs to S.

SQL

Example 1. SELECT * FROM Filights WHERE Destination=’Detroit’

It is a selection operator.

Example 2. SELECT Departure_time FROM Filights WHERE Destination=’Detroit’

A projection operator is used after a selection operator.

Example 3. SELECT Professor, Time FROM Teaching_assignments, Class_schedule WHERE Department=’Mathematics’

A joint operator is used, then a select operator, finally a projection operator.

 

SQL uses SELECT to represent a projection operation, uses WHERE to represent a select operation, use FROM to represent a joint operation.

 

Representing relations using matrices

A relation between finite sets can be represented using a zero-one matrix. Suppose that R is a relation from A={a1,a2,…,am} to B={b1,b2,…,bm}. The relation can be represented by the matrix MR=[Mij], where Mij=1 if aiRbj, otherwise Mij=0.

By using the matrix representation, it is easy to determine a relation R is reflexive, symmetric and antisymmetric.

 

Representing relations using digraphs

A directed graph, or digraph, consists of a set V of vertices together with a set E of ordered pair of elements of V called edges. The vertex a is called the initial vertex of the edge (a, b), and the vertex b is called the terminal vertex of this edge.

An edge of the form (a, a) is called a loop.

 

Definition 11. A relation on a set A is called equivalence relation if it is reflexive, symmetric, and transitive.

Definition 12. Two elements a and b that are related by an equivalence relation are called equivalent. The notation a~b is often used to denote that a and b are equivalent elements with respect to a particular equivalence relation.

Example4. Let R be the relation on the set of real numbers such that aRb iff a-b is an integer. Obviously, R is an equivalence relation.

 Example5. Let m be a positive integer with m>1. Show that the relation R={(a, b) | a =b (mod m)} is an equivalence relation on the set of integers.

 

Definition 13. Let R be an equivalence relation on a set A. The set of all elements that are related to an element a of A is called the equivalence class of A. The equivalence class of a with respect to R is denoted by [a]R.

In other words, if R is an equivalent relation on a set A, the equivalence class of the element a with respect to R is [a]R={s|aRs}. If b belongs to [a]R, then b is called a representative of equivalence class. Any element of a class can be used to as a representative of this class.

Theorem1. Let R be an equivalence relation on a set A. These statements for elements a and b of A are equivalent:

(i)                  aRb   (ii)[a]=[b]  (iii)[a] and [b] is not an empty set

We are now in a position to show how an equivalence relation partitions a set.

 

Theorem2. Let R be an equivalence relation on a set S. Then the equivalence classes of R form a partition of S. Conversely, given a partition {Ai|i belongs to I}, there is an equivalence relation R that has the set Ai, i belonging to I, as its equivalence classes.

 

Example6. What are the sets in the partition of the integers arising from congruence modulo 4?

 

Definition 14. A relation R on a set S is called partial ordering or partial order if it is reflexive, antisymmetric and transitive. A set S together with a partial ordering R is called a partial ordered set or poset, and is denoted by (S, R).

Example7. Show that the “greater than or equal to ” relation is a partial ordering on the set of integers.

Example8. Show that the divisibility relation | is a partial ordering on the set of positive integers.

Example9. Show that the include relation is a partial ordering on the power set of a set S.

 

Definition15. The elements a and b of poset (s ,<=) are called comparable if either a<=b or b<=a. When a and b are elements of S such that neither a<=b nor b<=a, a and b are called incomparable.

 

Definition16. If (S, <=) is a poset and every two elements of S are comparable, S is called a totally ordered or linearly ordered set, and <= is called a total order.

Example10. The poset (Z, <=) is total ordered, because a<=b or b<=a whenever a and b are integers.

  1. Example11.  The poset (Z+, |) is not totally ordered because it contains elements that are incomparable, such as 5 and 7.

 

Defintiion17. (S, <=) is a well-ordered set if S is a totally ordered set and every nonempty subset of S has a least element.

Example12. The set of ordered pairs of positive integers, Z+XZ+ with (a1, a2)<=(b1, b2) if a1<b1, or a1=b1 and a2<=b2 (the lexicographic ordering), is a well-order set.

Theorem1. The principle of well-ordered induction. Suppose that (S, <=) is a well-ordered set. Then P(x) is true for all elements x belonging to S, if

Basis step: P(x0) is true, where x0 is the least element of S

Inductive step:  for every y belonging to S, if P(x) is true for all x belonging to S with x0<x and x<y, then P(y) is true.

 

Defintiion18. The lexicographic ordering <= on A1 X A2 is defined by specifying an relation R on A1 X A2 such that (a1, a2) <= (b1, b2) if a1 <1 b1, or a1 =1 b1 and a2 <2 b2 where a1, b1 from poset (A1, <=1), and a2, b2 from poset (A2, <=2).

We can verify that this lexicographic ordering (R, <=) is a poset.

 

We can define a lexicographic ordering on the Cartesian product of n poset on A1 X A2 X… X An.

 

A Hasse Diagram is used to illustrate a finite poset.

 

Defintiion19. Let (S, <=) be a poset.

An element a of S is a maximal in the poset if there is no element b of S such that a < b.

An element b of S is a minimal in the poset if there is no element b of S such that b < a.

Note: a poset can have multiple maximal elements or minimal elements.

 

Definition20. Let (S, <=) be a poset.

An element a of S is a greatest element of the poset if b<=a for all b belonging to S.

An element a of S is a least element of the poset if a<= b for all b belonging to S.

Note: It is easy to show that the greatest/least element is unique when it exists.

 

Definition21. Let (S, <=) be a poset, and A is a subset of S.

If u is an element of S such that a<=u for all elements a belonging to A, then u is called an upper bound of A.

If l is an element of S such that l<=a for all element a belonging to A, then u is called a lower bound of A.

The element x is called the least upper bound of the subset A if x is an upper bound that is less than every other upper bound of A. That is, x is the least upper bound of A if a<=x whenever a belonging to A, and x<=z whenever z is an upper bound of A.

The element x is called the greatest low bound of the subset A if x is a lower bound that is greater than every other low bound of A. That is, x is the greatest lower bound of A if x<=a whenever a belonging to A, and z<=x whenever z is a lower bound of A.

Note: the least upper bound (the greatest low bound) is unique if it exists.

 

Definition22. A partially ordered set in which every pair of elements has both a least upper bound and greatest lower bound is called a lattice.

Lattices have many special properties. Furthermore, lattices are used in many different applications such as models of information flow and play an important role in Boolean algebra.

The lattice model of information flow. In many settings, the flow of information from one person or computer program to another is restricted via security clearances. We can use lattice model to represent different information flow polices. For example, a pair (A, C) is used to represent a security class where A is an authority level and C is a category. We can order security classes by specifying that (A1, C1) <= (A2, C2) iff A1<=A2 and C1 is contained in C2. Information is permitted to flow from security class (A1, C1) into security class (A2, C2) iff that (A1, C1) <= (A2, C2).

We can show that the set of all security classes with the ordering defined above forms a lattice.

 

Topological sorting

Definition23. A total ordering <= is said to be compatible with the partial ordering R if a<=b whenever aRb. Constructing a compatible total ordering from a partial ordering is called topological sorting.

 

Lemma1. Every finite nonempty poset (S, <=) has at least one minimal element.

 

Alogrithm1. Topological sorting

procedure topological sort ((S, <=) is a finite poset)

k = 1

while S is not empty

begin

                ak = a minimal element of S (such an element exists by lemma 1)

                S = S – {ak}

                K = k + 1

End {a1, a2,…,an is a compatible total ordering of S}

 

你可能感兴趣的:(Note)