Handout 3

Handout 3 - Mehran Sahami CS103B Handout #3 January 7, 2009...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Mehran Sahami Handout #3 CS103B January 7, 2009 Functions, Functions. .. Everywhere! Thanks to Maggie Johnson for some portions of this handout. In CS103A, it is likely that you already received an introduction to functions. Since we'll be working more with them in CS103B, we present a review of functions here, as well as provide some additional information on functions that you may not have seen before. As used in ordinary language, the word function indicates the dependence of one varying quantity on another. If I tell you that your grade in this class is a function of the number of thousands of dollars you pay me, you interpret this to mean that I have a rule for translating a number in thousands into a letter grade. Unfortunately, passing this class isn't that simple (much to my chagrin…). But seriously, we can formalize the notion of a function mathematically. Generally, suppose two sets of objects are given: set A and set B; and suppose that with each element of A there is associated a particular element of B. These three things: the two sets and the correspondence between elements comprise a function. Definition : A function f is a mapping from a set D to a set T with the property that for each element d in D, the function f maps d to a single element of T, denoted f(d). Here, D is called the domain of f, and T is called the target or co-domain . Thus, we write f: D T. We also say that f(d) is the image of d under f, and we call the set of all images the range R of f. A mapping might fail to be a function if it is not defined at every element of the domain, or if it maps an element of the domain to two or more elements in the range: Consider the mappings shown in the diagram above. We note that examples a and b are both functions since every element in the first set (the domain) maps to a single element in the second set (the co-domain or target). Note that it is fine for two elements in the domain to map to the same element in the co-domain (as is the case in b ). We point out that example c is not a function, since there is an element in the domain which does not map to any element in the co- domain. Also, example d is not a function since there is an element in the domain that maps to more than one element in the co-domain. To define a function f, we must specify its domain D and a rule for how it operates. We consider some examples below. a b c d
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
- 2 - Example 1 Let B be the set of all non-negative binary numbers. Let N be the set of natural numbers {0, 1, 2, 3, …} expressed in decimal (base ten) notation. Let f, g, h, and j be the following functions (mapping from B to N ): f(s) = decimal equivalent of s g(s) = number of bits in s h(s) = number of ones in s j(s) = the "ones" bit (i.e., lowest order bit) of s If s = 110010 then f(s) = 50, g(s) = 6, h(s) = 3, j(s) = 0. The range of function f, g, and h is N but the range of function j is {0, 1}. Here are two mappings from B to
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/26/2009 for the course CS 103B taught by Professor Sahami,m during the Winter '08 term at Stanford.

Page1 / 7

Handout 3 - Mehran Sahami CS103B Handout #3 January 7, 2009...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online