<< Chapter < Page | Chapter >> Page > |
The next two exercises aren't meant to be difficult, but rather to illustrate that, while we've sketched these twoapproaches and suggested they are equivalent, we still need an exact definition.
For the indicator function $f(x, y)=\begin{cases}\mbox{true} & \text{if $y=x^{2}$}\\ \mbox{false} & \text{otherwise}\end{cases}$ on the domain of (pairs of) natural numbers, write down the set-of-pairs representationfor the corresponding binary relation. It's insightful to give the answer both by listing the elements,possibly with ellipses, and also by using set-builder notation.
In general , for a binary indicator function $f$ , what, exactly, is the corresponding set?
$\{\left(0,0\right), \left(1,1\right), \left(2,4\right), \left(3,9\right), \text{\u2026}, \left(i,i^{2}\right), \text{\u2026}\}$ In set-builder notation, this is $\{\left(x,y\right)\colon y=x^{2}\}$
In general, for an indicator function $f$ , the correspondingset would be $\{\left(x,y\right)\colon f(x, y)\}$ (Note that we don't need to write
… $f(x, y)=\mbox{true}$; as computer scientists comfortable with Booleansas values, we see this is redundant.)
For the relation $\mathrm{hasPirate}=\{K, T, R, U, E\}$ on the set of (individual) WaterWorld locations, write down the indicator-function representationfor the corresponding unary relation. In general , how would you write down this translation?
$f_{\mathrm{hasPirate}}(x)=\begin{cases}\mbox{true} & \text{if $x=K$}\\ \mbox{true} & \text{if $x=T$}\\ \mbox{true} & \text{if $x=R$}\\ \mbox{true} & \text{if $x=U$}\\ \mbox{true} & \text{if $x=E$}\\ \mbox{false} & \text{otherwise}\end{cases}$ .
In general, for a (unary) relation $R$ , $f_{R}(x)=\begin{cases}\mbox{true} & \text{if $x\in R$}\\ \mbox{false} & \text{if $x\notin R$}\end{cases}$ .
Since these two formulations of a relation, sets and indicator functions,are so close, we'll often switch between them (a very slight abuse of terminology).
Think about when you write a program that uses the
abstract data type
Set
. Its main operation is
elementOf
.
When might you use an explicit enumeration to encode a set,and when an indicator function?
Which would you use for the set of WaterWorld locations?Which for the set of prime numbers?
Some binary relations have a special property: each element of the domain occurs as the first itemin exactly one tuple. For example, $\mathrm{isPlanet}=\{\left(\mathrm{Earth},\mbox{true}\right), \left(\mathrm{Venus},\mbox{true}\right), \left(\mathrm{Sol},\mbox{false}\right), \left(\mathrm{Ceres},\mbox{false}\right), \left(\mathrm{Mars},\mbox{true}\right)\}$ is actually a (unary) function. On the other hand, $\mathrm{isTheSquareOf}=\{\left(0,0\right), \left(1,1\right), \left(1,-1\right), \left(4,2\right), \left(4,-2\right), \left(9,3\right), \left(9,-3\right), \text{\u2026}\}$ is not a function, for two reasons. First, some numbers occur as the first element of multiple pairs. Second, some numbers, like $3$ , occurs as the first element of no pairs.
We can generalize this to relations of higher arity, also. This is explored in this exercise and this one .
One subclass of relations are common enough to merit some special discussion: binary relations. These are relations on pairs, like $\mathrm{nhbr}$ .
Although we introduced relations with prefix notation, e.g., $<(i, j)$ , we'll use the more common infix notation, $i< j$ , for well-known arithmetic binary relations.
In fact, binary relations are common enough that sometimes people use some entirely new vocabulary:A domain with a binary relation can be called vertices with edges between them. Together this is known as a graph . We won't stress these terms right now,as we're not studying graph theory.
Binary relations (graphs) can be depicted visually, by drawing the domain elements (vertices) as dots,and drawing arrows (edges) between related elements.
A binary relation with a whole website devoted to it is
has starred in a movie with. We'll call this relation $\mathrm{hasStarredWith}$ over the domain of actors. Some sample points in this relation:
location, and two actors being
adjacentto each other if they have ever starred in a movie together;two of these locations, even if not adjacent might have a multi-step path between them.(There is also a shorter path; can you think of it?The (in)famous Kevin Bacon game asks to find a shortest path from one location to thelocation Kevin Bacon. Make a guess, as to the longest shortest path leading from(some obscure) location to Kevin Bacon.)
Some other graphs:
Word laddersseek to transform one word to another by changing one letter at a time, while always remaining a word.For example, a ladder leading from WHITE to SPINE in three steps is:
Notification Switch
Would you like to follow the 'Intro to logic' conversation and receive update notifications?