The Basics: Sets, Tuples & Functions Sets

download The Basics:  Sets, Tuples & Functions  Sets

of 21

Transcript of The Basics: Sets, Tuples & Functions Sets

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    1/21

    Chapter 1

    The Basics:Sets, Tuples & Functions

    Sets

    Asetis a collection of objects. We will usually describe a particular setby listing its objects, separated by commas, within a pair of opposingcurly braces. For example, the set

    { 2, 4, 6, 8 }

    is the set of all positive integers that are evenly divisible by two andare less than ten. We say, for example, that the object 2 is amemberorelementof that set. The set

    { 1, 2, 3, 4, 6, 8, 12, 24 }

    is the set of all positive divisors of twenty-four. The set of all U.S.states that start with the letter c is

    { California, Colorado, Connecticut }.

    The set of all binary strings of length two is

    { 00, 01, 10,11 }.

    The set ofbooleanvalues isB

    booleans{ TRUE, FALSE }.

    We will useBto denote this set.Id like to be clear about one thing: the curly braces are very loaded

    symbols in the work that were doing here. They most often will be

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    2/21

    24 CHAPTER 1. SETS, TUPLES & FUNCTIONS

    = 203

    0= 1

    = 203

    1= 3

    = 223

    0= 4

    = 223

    1= 12

    = 2

    1

    3

    0

    = 2

    = 213

    1= 6

    = 233

    0= 8

    = 233

    1= 24

    powers of 2: of 3:

    Figure 1.1: A frivolous, but suggestive, picture depicting the factors of24 the positive integer divisors of 24 according to its factorizationinto primes.

    used to denote sets and will never be used merely as an alternative

    to their more vanilla brethren (parentheses), say, as some of you mayhave done in the past with extra-complicated arithmetic expressions.

    We should also point out that the order that we list the elementsdoes not matter. Though there may be a natural order for the objectsin any particular set, the notation is not intended to suggest an order.By listing the objects we are only intending to communicate each ob-

    jects membership in the set. So, for example the sets{ 8, 2, 4, 6 } and{ 2, 2, 2, 4, 6, 6, 8 } are each the same set as { 2, 4, 6, 8 }. In the former,the presentation just seems a little less natural. In the latter, we aresimply being inefficient in communicating membership of2and6.

    All the example sets that weve given above are finite ones. Thenotation gets strained when describing infinite sets. For example theset ofnatural numberscan be written as

    Nnatural num-bers

    { 0, 1, 2, 3, 4, . . . }.

    It is such an important set for our study that we will write it as N forshort. The set of primes? (positive integers with exactly two positivedivisors) You could write that set as

    { 2, 3, 5, 7, 11, 13, 17, . . . }.

    For these the order we list the elements is important simply to suggestthe other elements that arent written down. My use of ellipsis ( . . .) issayingI hope you know what Im getting at here since I obviously cant listthem all on this and the following pages.I suppose when you use this kind

    of notation for infinite sets, order matters. The order should suggestsome sort of method for enumerating the members of the set.Two ellipses can also be employed. The set of all integers can be

    Zintegers

    written{ . . . , 2, 1, 0, 1, 2, . . . }.

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    3/21

    SETS 25

    This set, too, will occur so readily in our discussion so we will write itasZ, instead.

    Typically, there is some property shared by the members of theset we wish to describe. If thats the case, you can use this barrednotation:

    placeholder name

    or expressionfor a generic

    member of the set

    property of all the members

    expressed using the nameor the names that appear

    in that expression

    For example,

    { n| nis a positive even integer less than ten }

    and also

    { 2k|for integerskwhere0 < kand k

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    4/21

    26 CHAPTER 1. SETS, TUPLES & FUNCTIONS

    Exercise 1. Give a barred expression for the set of all odd integers.

    Exercise 2. Give a barred expression describing the set of all perfect squares,integers that are the square of some integer E.g. 10 10 = 100 is a perfectsquare.

    Exercise 3. Give a barred expression describing the set of all even perfectsquares.

    Suppose we have two setsSand Twhere every element ofSis an subset relation

    element ofT, that is, they have the property that

    x Sonly ifx T .

    In this case, we say that S is a subset ofT and write S T. So, forexample,{ 2 } { 2, 8 } { 2, 4, 6, 8 }andN Z. Also, by our defini-tion, any set is a subset of itself because certainly

    x Sonly ifx S

    for any setS. Now if the subsetSis astrictsubset ofT, that is, if

    S TandS=T

    then we might write S T instead. For example, since the set ofintegersZhas members that are not in the set of natural numbersN,thenNis a strict subset ofZ, and we can write that

    N Z.

    For finite sets, we use double vertical bars to describe the numberof elements of a set.| |number of ele-ments

    |B|= 2

    |{ California, Colorado, Connecticut }|= 3

    |{ 2k Z |0< kandk

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    5/21

    SETS 27

    {2,3}

    1

    14

    2

    3

    {1,2}

    {4,3}

    {4,2}{1

    ,3}

    {4,1

    }

    (a)

    1 2 3

    { 1, 2, 3 }

    { 1, 2 }{ 1, 3 }

    { 1 }

    { 2, 3 }

    { 2 }

    { 3 }

    { }

    (b)

    Figure 1.2: (a) A rendering of the subsets of{ 1, 2, 3, 4 } with two mem-bers. (b) A rendering of the power set of{ 1, 2, 3 }.

    Whats a set with no members? Well, how about the set of all states inthe continental U.S. that start with the letter z? That is an empty set.

    The empty set is a useful concept mathematically. For one thing,is a subset of any set S. Why? Well, note that there is no elementof the empty set that is not in the set S, because there just arent anyelements in the empty set. Everyelement of is an element ofS. Asa result of this logic you can conclude that . I suppose we saidthis earlier when we said thatS Sfor any setS.

    We can have sets of sets. For example, the set of all subsets of{ 1, 2, 3, 4 }that each have exactly two members is the set

    { { 1, 2 }, { 1, 3 }, { 1, 4 }, { 2, 3 }, { 2, 4 }, { 3, 4 } } .

    See Figure 1.2a for a suggestive rendering of this set of sets.Define thepower setof a setSto be the set of all subsets ofS. De-

    P()power set

    notedP(S), it is given by the expression

    P(S) = { A| A S}.

    For example,

    P({ 1, 2, 3 }) = { , { 1 }, { 2 }, { 3 }, { 1, 2 }, { 1, 3 }, { 2, 3 }, { 1, 2, 3 } } .

    Figure 1.2b is an attempt to render this set of sets.

    Exercise 4. Suppose we have a set Swith n members where n is at least two.How many subsets ofSwith exactly two members are there? For examplewhenn= 4there are six such subsets.

    Exercise 5. Determine the elements ofP({ 1, 2, 3, 4 }).

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    6/21

    28 CHAPTER 1. SETS, TUPLES & FUNCTIONS

    Exercise 6. What isP()?

    Exercise 7. Suppose we have a set with n members. How many membersdoes its power set have?

    Operations on sets

    When we first learned about the natural numbers, we soon learnedhow to add, subtract, multiply, and divide them. In an analogous way,now that weve looked at some sets, lets look at some operationsthatwe canapplyto them.

    The most natural operation we can make on two sets is to com- set union bine their elements using theset unionoperation. For example, the set

    { 1, 2, 3, 5 }results from the union-ing of the set { 2, 3, 5 }with the set{ 1, 3 }. The shorthand for the set union operation is . Thus, we can

    write{ 2, 3, 5 } { 1, 3 }= { 1, 2, 3, 5 }

    and this is analogous for sets to writing something like

    1 + 3 = 4.

    for integers. More formally, we can define union using the set notationwe introduced earlier by the following

    S T :={ x|x Sor x T}. (1.1)

    In other words, an object that is in S T is one that is inS, in T, or inboth sets.

    Note that the following is true for any set S:

    S = S= S

    for any set S. Now you see more evidence for being a useful con-cept: is for what 0 is for+. That is, we know that

    n + 0 = 0 + n= n

    no matter what the integer nis, and so 0 is identity-preserving for theinteger addition.

    If instead we wish to express the set of members common to two set intersec-

    tion

    sets, we would instead use the intersectionoperation :

    { 2, 3, 5 } { 1, 3 }= { 3 }

    and{ 2, 3, 5, 8, 9 } { 0, 1, 3, 5, 9 }= { 3, 5, 9 }

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    7/21

    SETS 29

    and more generally

    S T ={ x|x Sand x T}. (1.2)

    Finally, theset difference ofSfromTis the set of elements ofSthat

    e are not inT, and writtenS T. For example,

    { 1, 3, 4 } { 1, 2, 8, 9, 10 }={ 3, 4 }.

    Operationally, the differenceS Tcan be computed by takingSandremoving all elements ofTfrom it.

    Id like to point out the two ways that we have been describing setshere. I apologize if this moment of reflection is completely obvious.We can think of a set simply as (1) its members, or we instead thinkabout (2) that sets members distinguishing property. For example,suppose we have a set Uof objects that we are discussing in some

    context, call it our universe of objects for consideration, e.g. the setof all states. So, the set of states we gave above corresponds to theproperty starts with the letter c. Lets call that set C. Then the setU Ccorresponds to does not start with the letter c. A property ofa state, inturn, defines a subset ofU, for example, those states formed

    before 1860.You can think of set union as an operation that takes the elements

    of one set and combines them with another set. Or instead you canthink ofA B as describing those things with the defining propertyof the setA along with those things with the defining property of theset B.A Bare formed by those elements that have at least one of thetwo properties. The expressionA B are those things that have bothproperties.

    Note that this means that the or being used in the defining ex-pression (1.1) is aninclusiveone. Typically, in common language oractsexclusively. For example, when we say things like Im going toride my bike or Im going to take the bus we usually mean to suggestthateitherwell be biking or well be busing, and excluding the casethat well do both. In our mathematical language, we typically useor inclusively, which allows the case of both. When we mean orexclusively in mathematical language, we will state so explicitly.

    This brings us to an important (logical) relationship that holds be-DeMorganslaws

    tween the three set operations , and that are consequences ofDeMorgans Laws. Let A and B be subsets of a set S. DeMorgansLaws tell us that

    S (A B) = ((S A) (S B))and that

    S (A B) = ((S A) (S B))

    The first equation above is saying that

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    8/21

    30 CHAPTER 1. SETS, TUPLES & FUNCTIONS

    = U

    A BBS

    Figure 1.3: An illustration of the first DeMorgan Law S A B =(S A) (S B).

    Those objects that dont have both properties are those that donthave the first property along with those that dont have the sec-

    ond property.

    Lets reverse the second DeMorgan equation:

    ((S A) (S B)) = S (A B).

    This equation is saying that

    Those objects that dont have the first property and dont havethe second property are those that dont have at least one of thetwo properties, that is, those that have neither.

    Figure 1.3 gives different shadings and colorings of the Venn diagramof a setSwith two of its subsets AandB. A Venn diagram intends todepict the different possible subsets ofSdue to membership, or lack ofmembership, in setsAand B . For example, the left half-moon regionof the diagram corresponds to A B, the middle sliver corresponds toA B, &c. The whole figure illustrates the first law of DeMorgan.

    Exercise 8. What isS ? ?

    Exercise 9. Explain why A B= A (A B)for any sets A and B. WhendoesA B= B A?

    Exercise 10.

    Give a definition ofS Tusing notation similar to whats used in equations(1.1) and (1.2).

    Exercise 11. Figure 1.4 gives the Venn diagram of three sets A, B , andCthat are subsets of a set S. Give set expressions describing at least two of theeight regions of the figure and point out which regions they describe. Now,see if you can add a closed curve representing a fourth subsetD to the Venndiagram.

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    9/21

    SETS 31

    A

    BC

    Figure 1.4: A Venn diagram of three sets.

    Note that the resulting figure should have exactly sixteen regions, divid-ing each of the eight into a part that is inside the D curve and a part that isoutside theDcurve.

    Ordered pairs, tuples

    Throughout this course we will need notation for sticking objects to-(, , . . . , )tuple

    gether and treating them as a single entity. For example, suppose thatyou wish to construct a database for a class containing informationabout each member of that class. A record for a certain member might

    be, say, the3-tuple(or more simply, the triple)

    ( Smith, Bob, 3, apple fritter )

    describing the relevant information one wishes to store about that per-son: their name, their year in school (a junior), and their favorite typeof donut. Tuples are often used to express some relation among theirconstituent components. This tuple might represent the fact:

    There is a person in this class named Bob Smith that is in hisJunior year and likes apple fritters.

    This line of objects forming the ordered tuple might be a record in aso-calledrelational databasealong with, maybe,

    ( Soprano, Meadow, 1, cruller ),

    representing someone else in the class. We call these objects that con-sist of an ordered sequence of componentsordered tuplesor justtuples.As another example, suppose a class of five students decide to give

    gifts to each other in such a way that every student gives a gift toexactly one classmate, and every student receives a gift from exactly

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    10/21

    32 CHAPTER 1. SETS, TUPLES & FUNCTIONS

    Jones, Ignacio

    12

    3

    4

    fritter

    crullerglazed

    Soprano, Meadow

    Xu, FalstaffSmith, BobLaBonne, Jo

    Jones, Ignacio

    1

    23

    4

    frittercruller

    glazed

    Soprano, Meadow

    Xu, FalstaffSmith, Bob

    LaBonne, Jo

    Figure 1.5: Two database entries each depicted as three menu choices,thus corresponding to a triple of values.

    one classmate, and nobody gives a gift to him- or herself. They drawnames randomly and determine that

    Smith gives to SopranoSoprano gives to JonesLaBonne gives to XuXu gives to LaBonne

    Jones gives to Smith

    We can represent this gift-giving relationship more succinctly as theset of giver-receiver pairs

    { ( Smith, Soprano ), ( Soprano,Jones ), ( LaBonne, Xu ),( Xu, LaBonne ), (Jones, Smith ). }

    We will also use tuples to define mathematical models of computation,for example, a deterministic finite automaton. While a class recordcontains three defining components of a member, a finite automatonconsists of five: its states, its start state, its input symbols, its acceptingstates, and its state transition behavior. A finite automaton, then, is a

    5-tuple.Note that the use of parentheses in tuple notation is loaded (as

    opposed to set notations curly braces). In the above example, the pair

    ( LaBonne, Xu )

    means something significantly different than the pair

    ( Xu, LaBonne ).

    Lets now define an operation on sets that yields the set of possibleordered pairs. For setsAand B the cartesian productA Bis defined

    cartesian prod-uct of sets

    by the set{ (x, y)|x Aandy B },

    the set of all ordered pairs where the first component is a member ofAand the second component is a member ofB. For example

    {Jones, Smith } { 1, 2, 3 }={ (Jones, 1), (Jones, 2), (Jones, 3), (Smith, 1), (Smith, 2), (Smith, 3) }

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    11/21

    SETS 33

    portland

    san fran.

    missoula

    idaho falls

    reno

    seattle

    LaBonne, JoJones, Ignacio

    Smith, Bob

    Soprano, Meadow

    Xu, Falstaff

    Figure 1.6: Left: a graph depicting possible legs of travel. Right: a

    possible secret Santa relation for a group of five people.

    More generally, if we haven sets A1, A2, . . . , An then their cartesianproduct, written

    A1 A2 An

    is the set of all n-tuples whose first component is from A1, secondcomponent is fromA2, and so forth.

    Directed graphs of binary relations

    One particularly well-studied object in discrete mathematics and com-puter algorithms is adirected graph. Figure 1.6 depicts two such crea-tures. Mathematically, a directed graph consists of a collection of ob-

    jects, called itsnodesor its vertices, combined with a collection of or-dered pairs of vertices, called itsedgesor edge relation. The graph de-picted on the left can be written as

    ( { seattle, portland, san fran., missoula, idaho falls, reno },{ ( seattle, portland ), ( portland, seattle ), ( seattle, missoula ),( idaho falls, missoula ), ( san fran., reno ), ( portland, san fran. ),( portland, idaho falls ), ( portland, missoula ) } ).

    I apologize for the braces and parentheses needed for this description.The first component of the ordered pair, given on the first line, is theset of vertices (cities, in this case). The second component, given onthe next three lines, is the set of edges (travel legs between city pairs).

    The second graph, of course, depicts our gift-giving relation. The

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    12/21

    34 CHAPTER 1. SETS, TUPLES & FUNCTIONS

    graph can be written as

    ( {Jones, Smith, Soprano, LaBonne, Xu },{ (Jones, Smith ), ( Smith, Soprano ), ( Soprano,Jones ),( LaBonne, Xu ), ( Xu, LaBonne ) } ).

    In these examples, I prefer the pictures.More generally, a directed graph is a pair G= (V, E)where

    directed graph

    Vis the set ofGs vertices, and

    Eis the set ofGs edges and is a subset ofV V.

    Graphs are used to represent binary relations binary meaning thatthe relation is between two things for example a travel leg from onecity to another.

    Exercise 12. List all the pairs of the set{1, 2, 3} {1, 2, 3}.

    Exercise 13. List the triples of the set{0, 1} {0, 1} {0, 1}.

    Exercise 14. Give the set of pairs BN. Since the resulting set is infinite,you should just give a few elements to suggest an enumeration of the wholeset.

    Exercise 15. Find a nice way to depict the setZ Z.

    Exercise 16. SupposeAhasnmembers andB has mmembers. How manypairs are in the setA B? How manyk-tuples are in the product

    A A A ktimes

    ?

    Exercise 17. Atournamentis a directed graph where there is exactly onedirected edge between any two distinct vertices and there are no self-loopedges, i.e. no directed edges of the form (v, v). Using the notation wevedeveloped, its a directed graphT= (V, E)where

    (v, v) Efor everyv V, and

    either(u, v) Eor (v, u) Efor anyu, v V whereu =v .

    You can think of a tournament as a depiction of the results of a series of gameswhere each team involved plays every other team in a match and no draws areallowed. When teamxhas beaten teamy, then theres an edge(x, y).

    1. Draw an example of a tournament with four vertices.

    2. How many edges are there in a tournament with n vertices? Howmany tournaments are there withnvertices?

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    13/21

    FUNCTIONS 35

    3. A tournament isconsistentif there is no walk you can take, followingthe directed edges, from a vertex back to itself. Give all the consistent

    tournaments of 4 vertices.4. How would you define precisely the winning vertex of a consistent

    tournament?

    5. A challenge: give the number of consistent tournaments withn ver-tices.

    Functions

    Afunction associates each value in that functions domain set with somevalue in the functionsrangeset. A function is usually given by a rulethat governs the association. We say that the functionmaps values

    from its domain to values in its range.For example, we can define a function sthat maps integers to inte-

    gers by the rules(i) = i + 1

    Using this rule, for example, we see that s(5) = 6 and s(0) = 1, thatis, thats maps 5 to 6 and maps 0 to 1. We write that s :: Z Z. Ingeneral, we write

    f ::A B

    to mean say the functionfmaps members of its rangeAto membersof its domain B. The set Zhappens to be ss domain and also itsrange. I suppose we could depict the function slike so

    -2 -1 0 1 2 s:

    -1 0 1 2 3

    to suggest the association.The number n + 1is usually called nssuccessorand arises in the

    study of the natural numbers. The function succ ::N Ndefined bysucc()successorfunction

    succ(n) = n + 1

    is called thesuccessor functionon the natural numbers. In this case, itis acceptable to say that the set Nis the range of succ, even though thenumber0 Nis not the successor of any natural number.

    Note that we are actually conceiving of functions in two differentways. In the one sense, a function is anassociation. Some texts wouldsay thatsis given by the set expression

    s={ . . . , (2, 1), (1, 0), (0, 1), (1, 2), (2, 3), . . . }

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    14/21

    36 CHAPTER 1. SETS, TUPLES & FUNCTIONS

    In other words, one could think of a function as a set of pairs whereevery element of the domain appears on the left part of exactly one

    pair in the set. The right part of each pair gives the associated elementin the functions range.Alternatively, we have the other sense that a function is a rulethat

    can be evaluated to compute a value in the range for every value inthe domain. Taking that view, the following might define a differentfunctiont ::Z Z

    t(i) = (i + 1)2 i(i + 1)

    so that we have, for example,

    t(5) = 66 56 = 36 30 = 6

    t(0) = 11 01 = 1 0 = 1

    and in generalt(i) = s(i)for everyi Z. They are two different rulesbut they yield the same association.We will not be careful about these two different ways of thinking

    about functions.There is one further notation we need to introduce: defining a func-

    tion by cases. As illustration consider a function p ::Z Bgiven by

    p(i) =

    TRUE ifi >0

    FALSE otherwise.

    Using this rule, p(5) = TRUEand p(0) = FALSE. In general, the func-tion p tells us whether or not an integer is positive. In the case thati >0 the value ofp(i)is TRUE. In the case thati 0 the value ofp(i)isFALSE.

    -2 -1 0 1 2 p:

    FA LS E FA LS E FA LS E T RU E T RU E

    So far, we have only described functions that take a single argu-ment. Consider instead the following function definition:

    max(a, b) =

    a ifa > bb otherwise

    .

    With this definition, we have max(5, 0) = 5 and max(0, 1) = 0, forexample. We say that

    max :Z Z Z

    We can think ofmax as associating an integer with every pair of in-tegers, particularly the larger of the two. If you think about it, theinteger operation+might be thought of as a function

    + :: Z Z Z.

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    15/21

    FUNCTIONS 37

    For example, we view + as mapping the pair (5, 6) to the value 11, thatis, +(5,6) = 11. We have instead adopted the convention of writing + as

    aninfix operation, so we write 5+6 instead. It will be useful sometimesto think of the condition>as being a function from number pairs to aboolean value, that is,

    > ::Z Z B.

    so that for example>maps the pair(5, 6)to FALSEand maps the pair(6, 5)to TRUE.

    Defining sets with functions

    So far Ive been giving a computational spin to all of the concepts andnotation that I have been introducing here: and are setoperations,functions arerules, &c. This is certainly being done on purpose. Thevery act of specifying rules for computing values, either in mathemat-ical notation or as a computing device, or somewhere in betweenasa computer program that can be executedis at the heart of our busi-ness here. One of the trickier aspects of our work is that some of theobjects we describe are not of finite size, and giving a succinct rule thatcan be generically applied, perhaps mechanically, to describe such ob-

    jects is the trick.

    One way to define a set computationally is to give the definingpropertyPas a rule, or function, that determines membership. IfU isthe universe objects were considering for membership, then we makePmaps elements ofU to the booleans B = { TRUE, FALSE }, that is,

    P :: U B. If we take somex Uand compute P(x)to be TRUE,thenxis in the set were defining. If instead P(x) = FALSE, then wellsay thatxis not in that set.

    For example, consider the following rule, applied when given ann N:

    Divide the integer nby 2 and examine the remainder. If theremainder is1, then outputfalse. Otherwise, outputtrue.

    More suucinctly, that rule defines the functionP ::N Bgiven by

    P(n) = TRUE ifnis evenly divisible by2

    FALSE otherwise.

    This, of course, defines the set of even non-negative integers.

    Providing adecision function(ordecision algorithm) is thus one com-putational way for describing a set.

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    16/21

    38 CHAPTER 1. SETS, TUPLES & FUNCTIONS

    Recursive definition

    In this section we begin survey of a somewhat unusual technique fordefining mathematical objects like sets and functions, one that is alsoinherently computational. The idea is the following: we define anobject in terms of itself.

    This may at first seem rather odd. We certainly would not behappy with a dictionary entry like

    make:v.to engage in the act of making.

    The wordmake, which the dictionary is attempting to define for us,occurs again orrecursin some form in the text of the definition... not agreat way to make meaning clear.

    Nevertheless, when done properly, recursive definition can be in-credibly useful or illuminating.

    Recursive definition of sets

    When used to define sets, the method of recursive definition is a con-structive one in that we describe a rule or rules for fashioning elementsof the set we are defining. We will do this by constructing its elementsfrom other elements that weve already asserted to be in the set. Forsome of you the effect will be chilling, I imagine akin to what peoplefelt when they first witnessed the movement of a steam locomotiverolling from a standstill on its tracks.

    The set expression given by the definition

    The set of even natural numbers is{ 0, 2, 4, 6, 8, . . . }.

    suggests the kind of definition we are getting at. There is a computa-tional rule suggested in the enumeration above:

    Zero is in the set. Add two to that and we get two. 2is in the set.Add two to that and we get four.4 is in the set. &c.

    A recursive set definition makes this kind of enumeration more delib-erate. Here is an example of such definition:

    LetAby given by the following rules:

    1. BASIS: 0 is inA.

    2. RECURSIVE STEP: Ifnis inA, then so isn + 2.

    3. THE FINE PRINT: No other elements are in A other

    than those formed through a finite number of appli-cations of the two rules above.

    This is really no different that the ellipses stuff above. The voice of thedefinition asserts that:

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    17/21

    RECURSIVE DEFINITION 39

    Zero is in the set A.Zero plus two, which is two, is in the set A.

    Two plus two, which is four, is in the set A.Four plus two, which is six, is in the set A.Six plus two, which is eight, is in the set A.

    and so forth. Chugga, chug.Let me explain the parts of this definition further. By providing

    thebasisof the set in rule (1), we are asserting that certain objects aremembers. They form the sets foundation.

    Contrast this with the assertion made in therecursiverule. It pro-vides a way of constructing more members. With no applications ofrule (2) we have just the basis element 0. From one application of rule(2) we now must include the element 2. From a second application ofrule (2) we must include 4. We can keep doing this ad infinitum. Since

    rule (2) defines members ofA

    using members ofA

    , and henceA

    occursin its own definition, the definition is recursive.Rule (3) is one that was implied in our ellipses above: we should

    only consider elements produced by rules (1) and (2) to be in the set.From now on we will assume that a rule like (3) comes with all ourrecursive definitions of sets.

    Here is another example:

    LetB by given by the following rules:

    1. BASIS:

    (a) 1 is inB.

    (b) 2 is inB.

    (c) 3 is inB.

    (d) 4 is inB.

    2. RECURSIVE STEP: Ifnis inB, then so isn + 5.

    What is the set B?B is the set of all natural numbers that are not evenlydivisible by5. Why, for example, is17 in the set B ? Well, according torule (1b) we see that 2 is inB. By rule (2) we see that7is inB. By rule(2) we have that12is in the setB. Finally, by rule (2) one last time wesee that17is inB.

    Here is another example, a set that consists of words (i.e. sequencesof letters):

    LetDby given by the following rules:

    1. BASIS: The single-letter words A, C, G, and T are eachinD.

    2. RECURSIVE STEP: Take a word x in Dand append oneof the four single-letter words ofD at the end ofx.The resulting word is also in D.

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    18/21

    40 CHAPTER 1. SETS, TUPLES & FUNCTIONS

    What are the words inD? Well there are four single-letter words inD,asserted by rule (1):

    A, C, G, TNow, by applying rule (2) to these in all the possible ways we can, wefind that the two-letter words

    AA, AC,AG,AT, CA, CC,CG, CT, GA, GC,GG, GT, TA,TC, TG, TT

    are also in D . By applying rule(2) to these we get three letter wordslike

    AAA, CAG, CAT

    &c. Continuing this way, we see that Dis the set of all finite sequencesofAs, Cs, Gs, and Ts.

    Exercise 18. Consider the following:

    LetEby given by the following rules:

    1. BASIS: 0 is inE.

    2. RECURSIVE STEP: Ifnis inE, then so is2n + 1.

    What property do the members of the setEshare?

    Exercise 19. Consider this definition:

    LetFby given by the following rules:

    1. BASIS: The single-letter words A, C, G, and Tare each in F.

    2. RECURSIVE STEP: Take a wordx in Fand append one ofthe four single-letter words ofFto the front and to the end

    ofx. The resulting word (e.g. AxA) is also inF.

    What are the letter sequences inF?

    Some thoughts on recursion

    Recursive definition is natural in the study of computation. Methodsof problem solving often rely on taking a few initial steps that work to-wards a grander solution, or, alternatively, decomposing a larger prob-lem into smaller ones. These two notionsconstructing more compli-cated things from basic stuff; reducing more complicated to simplerare part of the trick in making recursive definitions work especiallywhen devising computer algorithms. Recursive algorithms are often

    said to pick themselves up by their own boot straps.The characteristic that may be unsettling at firstdefining some-thing in terms of itselfis something that youve probably seen else-where. For example, you might have been asked once in some wordproblem to look for a number according to something like

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    19/21

    RECURSIVE DEFINITION 41

    Let a be a positive integer equal to half of the successor of itssquare.

    What as satisfy this definition? Any integera > 0 that satisfies theequation

    a= a2 + 1

    2 .

    Solving this equation, youll see that a must be 1. Just to introducesome more terminology, let g :: N Nbe defined by

    g(n) = n2 + 1

    2

    We would say that1 is fixedby the function g , becauseg(1) = 1. Thevalue1is a fixed pointofg.

    The notion of a fixed point forms the foundation for defining ob-jects recursively. At issue is the following: take some mathematicalentity, apply some operation to it, and suppose we get that entity backagain. Then there is something special about that entity relative to thatoperation.

    Lets consider another example. Define a set addition operator, forany integer setsS, T Zby

    S+ T ={ x + y| x Sand y T}

    In other words, S+T is just the set of all integers that result fromadding something fromSwith something fromT. For example

    { 3, 4, 7 }+{ 1, 2 }={ 3+1, 4+1, 7+1, 3+2, 4+2, 7+2 }={ 4, 5, 6, 8, 9 }.

    With this in hand, consider the following description of a set C Z:

    LetCbe the set of integers that satisfies the equation

    C= {1, 2, 3, 4} (C+{5}) (1.3)

    and has the fewest elements of those sets that do.1

    In other words, find a minimal set of integers Cwhere if you

    1. add 5 to each of its members then

    2. throw in the members 1, 2, 3, and 4

    1Such sets Care infinite, so I should make what I mean by fewest more precisehere. Ill refrain.

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    20/21

    42 CHAPTER 1. SETS, TUPLES & FUNCTIONS

    you get the set Cback again. Now, it turns out that this C is exactlythe same set given by our recursive definition of a setB earlier. C is

    the set of all positive integers that are not divisible by5. C= BWhy consider this example? I hope you see that Cis a set thats afixed point of the operation

    Add 5 to everything then throw in 1, 2, 3, and 4.

    I also think that equation (1.3) makes the recurrence ofCin its defini-tion more explicit. Now, it turns out that there are other sets that arefixed points of that operation (the set of all integersZ, for example).To pin downCwe ask for the minimal one. This happens to be a least

    fixed pointof that operation.Recursive definition of sets will be even more useful to us when we

    discuss languages. We will use grammars, for example, which provide

    a more precisely ruled form of recursive definition.

    Recursive definition of functions

    We can employ recursive practice to define functions. Consider thefollowing rules for a functiont::N N:

    t(n) =

    0 ifn= 0n + t(n 1) ifn >0.

    Notice the recurrence oft on the right hand side of its own definingrule. What function does this define?

    Forn= 0the functions definition yields an immediate answer

    t(0) = 0.

    For n = 1we have to work a little harder. To computet(1)we firstneed to computet(0), then add one to the result. So

    t(1) = 1 + t(0) = 1 + 0 = 1.

    Lets aim a little higher:Whats t(4)?Forgive my enthusiasm for demon-strating this calculation but, according to the rule, we know that

    t(4) = 4 + t(3)

    and so it looks like we need to compute t(3)first. Hmm... whats t(3)then?

    t(3) = 3 + t(2)

    Okay whatst(2)?

    t(2) = 2 + t(1) = 2 + 1 = 3.

  • 8/12/2019 The Basics: Sets, Tuples & Functions Sets

    21/21

    RECURSIVE DEFINITION 43

    We had already computedt(1)above, so I just completed that calcula-tion. Now I think Im ready for t(3).

    t(3) = 3 + t(2) = 3 + 3 = 6

    So finally we see that

    t(4) = 4 + t(3) = 4 + 6 = 10

    Lets look at that calculation in one fell swoop, substituting t cal-culations in-line:

    t(4) = 4 + t(3)

    = 4 + (3 + t(2))

    = 4 + (3 + (2 + t(1)))

    = 4 + (3 + (2 + (1 + t(0))))= 4 + (3 + (2 + (1 + (0))))

    The parenthesization just makes the sub-calculations apparent. I hopeit is clear that, in general, the function that weve defined is

    t(n) = n + (n 1) + + 3 + 2 + 1 + 0,

    the sum of the natural numbers from 0 to n.Perhaps reading all these evaluation steps is a bit tediousIm not

    expecting you to want to do this kind of hand calculation. Soon, wewill study programming language systems like Haskelland Javathatperform this type of calculation for you. Whats important here is

    that you see the mechanics of applying recursive formulae. They willbe used to great effect, say, for dealing with sequenced data, and fordefining sorting and searching algorithms.