SE 500, 507
Relations

Ordered Pair: Examples are (a,b), (Mary, Jim), (3,7), and (Bill, 4).

Similarly, examples of ordered triples are (a,c,b) and (Mary, Jim, 13). In general, we talk of tuples, or, more precisely, of 2-tuples, 3-tuples, or even 1-tuples. (By convention, a 1-tuple, such as (34), could be written without the parentheses and hence is indistinguishable from the value 34.)

Cartesian/Cross Product: Let A and B be sets. In traditional notation, A × B = { (a,b) | a A    b B }.

In Gries & Schneider's (superior) notation, it is written A × B = { a,b | a A  ∧  b B : (a,b) }.

That is, A × B is the set of ordered pairs (i.e., 2-tuples) formed by pairing each element of A with each element of B.

Properties of cross product: see G&S, pages 266-267. Included among these are that × distributes over union, intersection, and difference; monotonicity.

Extension to three or more sets: A × B × C is the set of all 3-tuples formed using elements from A, B, and C, respectively.

Relation: A relation R is simply a subset of B1 × B2 × ... × Bn, where each Bi is some set. We say that it is an n-ary relation, or it has arity n. If n = 2, it is a binary relation. If n = 1, it is a unary relation. When a relation is unary, we usually refer to it as a "set" rather than a "relation". (For example, we can view the set { 2,4,9 } as being the same thing as the unary relation { (2),(4),(9) }.)

If all the Bi's are the same set, B, we say that R is an n-ary relation on B. Perhaps the most common kind of relation is a binary relation on a set.

Describing a relation: The two main ways are by enumeration and by set comprehension. By the former we mean to list the elements exhaustively, as in

{(David, Molly), (Jim, Mary), (Paul, Heather)}

Obviously, this works only for finite sets in principle and, in practice, only for relatively small finite sets. By the latter we mean to specify the conditions under which a tuple is a member and/or how to generate each member. For example,

{ k:ℕ   |   isEven.k : (k,k2) }

describes the binary relation containing precisely those ordered pairs of the form (k,k2) (i.e., in which the second component is the square of the first), where k is an even natural number. (Hence, this is the set { (0,0), (2,4), (4,16), ... }.)

Expressing membership in a relation: Let R be a binary relation. Then (a,b) ∈ R As a relation is a set, to express the idea that a particular tuple is a member of a relation R, we can use the standard set membership operator ∈, as in (a,b) ∈ R. (Depending upon the context, this expression could be interpreted either as an assertion that (a,b) is a member of R or as an expression whose value is true in that case but false otherwise.)

If R is binary, an alternative way to express that (a,b) is a member of R is to say aRb.

This infix notation is used in a "conjunctional" manner (similar to <); that is, a R1 b R2 c is shorthand for   a R1 b   ∧   b R2 c.

Connection between binary relations (over a finite set) and directed graphs: For purposes of illustration, it is often useful to depict a binary relation R (over a small finite set) as a directed graph. Each element of the "universe" is depicted as a vertex, and an edge from x to y, say, means that xRy holds.

Examples of binary relations:

Domain of a relation: Let R A × B. Then
Dom.R = { a:A | (∃b:B |: aRb) : a}
Ran.R = { b:B | (∃a:A |: aRb) : b}

That is, the domain of relation R ⊆ A×B includes all (and only) those elements of A that are related to at least one member of B. Similarly, the range of R includes all (and only) those elements of B that are related to at least one member of A.

Operations on relations:

Exercise: define the relation sibling (that relates any two persons having at least one parent in common).

Exercise: define the relation firstCousinOf

Exercise: define the relation secondCousinOfOnceRemoved

Important classes of relations. (G&S, page 273)

PropertyConditionAlternative
Reflexivity(∀a |: aRa)ι ⊆ R
Irreflexivity(∀a |: ¬aRa)ι ∩ R = ∅
Symmetry(∀a,b |: aRb ≡ bRa)R = R-1
Antisymmetry (∀a,b |: aRb ∧ bRa ⇒ a=b) R ∩ R-1 ⊆ ι
Asymmetry(∀a,b |: aRb ⇒ ¬bRa) R ∩ R-1 = ∅
Transitivity(∀a,b,c | aRb ∧ bRc : aRc) R = (∪k | k>0 : Rk)

The closure of relation R with respect to a particular property is the smallest relation containing R and having that property. (See examples in G&S on pp. 274-275.)

A common example is transitive closure. The isProperAncestorOf relation is the transitive closure of isParentOf.

Also common is reflexive transitive closure. The isAncestorOf relation is the reflexive transitive closure of isParentOf.

Reflexive Closurer(R) = R ∪ ι
Symmetric Closures(R) = R ∪ R-1
Transitive Closure R+ = R1 ∪ R2 ∪ R3 ∪ ...
Reflexive Transitive Closure R* = R0 ∪ R+

Equivalence Relations: A relation R⊆A×A is said to be an equivalence relation if (and only if) it is reflexive, symmetric, and transitive. Such a relation induces a partitioning of the domain (i.e., set A) into equivalence classes. (Within each equivalence class, every element is related to every element. No two elements in distinct equivalence classes are related.) Examples of equivalence relations:


Functions

A function is a relation that satisfies a particular condition. Take a function f: A → B. We can view f as being the set of ordered pairs (i.e., binary relation) { a:A |: (a,f.a)}. That is, (a,b) ∈ f  ≡  f.a = b. From this point of view, to be a function, a relation R must satisfy the property that

(a:A, b,c:B | aRb ∧ aRc : b=c)

In other words, each member of Dom.R (the domain of R) must be related to exactly one member of Ran.R (R's range).

Notions of total vs. partial function, injective (and inverse function), surjective, bijective.

Partial Order: A relation that is reflexive, antisymmetric, and transitive. (page 285)

Quasi (or Strict Partial) Order: (page 287) A relation that is irreflexive and transitive (which implies asymmetric). To get a quasi order from a partial order, simply take its reflexive reduction (meaning remove all ordered pairs of the form (a,a)).

Total Order: is a partial order such that its union with its own inverse is B × B (all possible pairs).

Topological Sort: Given a (strict) partial order, compute a total order that is consistent with it (meaning that the former is a subset of the latter).