Presentation is loading. Please wait.

Presentation is loading. Please wait.

Snick  snack CPSC 121: Models of Computation 2009 Winter Term 1 Functions Steve Wolfman, based on notes by Patrice Belleville and others 1.

Similar presentations


Presentation on theme: "Snick  snack CPSC 121: Models of Computation 2009 Winter Term 1 Functions Steve Wolfman, based on notes by Patrice Belleville and others 1."— Presentation transcript:

1 snick  snack CPSC 121: Models of Computation 2009 Winter Term 1 Functions Steve Wolfman, based on notes by Patrice Belleville and others 1

2 Outline Prereqs, Learning Goals, and Quiz Notes Functions as “Computation Abstractions” Terminology (out-of-class) Properties: Injective, Surjective, Bijective Inverse Operation Function Proofs Next Lecture Notes 2

3 Lecture Prerequisites Read Section 7.1. Solve problems like Exercise Set 7.1, #1-4, 13-14, 23-24. 3

4 Learning Goals: Pre-Class By the start of class, you should be able to: –Define the terms domain, co-domain, range, image, and pre-image –Use appropriate function syntax to relate these terms (e.g., f : A  B indicates that f is a function mapping domain A to co- domain B ). –Determine whether f : A  B is a function given a definition for f as an equation or arrow diagram. 4

5 Learning Goals: In-Class By the end of this unit, you should be able to: –Define the terms injective (one-to-one), surjective (onto), bijective (one-to-one correspondence), and inverse. –Determine whether a given function is injective, surjective, and/or bijective. –Apply your proof skills to proofs about the properties (e.g., injectiveness, surjectiveness, bijectiveness, and function-ness) of functions and their inverses. 5

6 Outline Prereqs, Learning Goals, and Quiz Notes Functions as “Computation Abstractions” Terminology (out-of-class) Properties: Injective, Surjective, Bijective Inverse Operation Function Proofs Next Lecture Notes 6

7 What is this? control data1 data2 output 7

8 What is this? control data1 data2 output 8

9 What is this? control data1 data2 output 9

10 What is this? control data1 data2 output In the lab, you implemented a multiplexer and then used it as a piece in larger circuits. You abstracted from the concrete implementation to a description of its function: f(control, data1, data2) = output = (~control  data1)  (control  data2) = data1 if control is 0, but data2 otherwise 10

11 Functions, Abstraction, and CPSC 121 Computer scientists use many abstraction levels, with reasoning and often execution tools at each level. In 121, we learn tools for some key abstraction levels: wiring physical gates, computer-based hardware design techniques, propositional logic, predicate logic, sets, … Functions are a new model that let us talk about how computations work and fit together. Bonus: functions alone are enough for all of computation, using the “λ calculus”. 11

12 Functions We’ve Used Any combinational logic circuit Arrays, as long as they’re immutable (unchangeable): A(i) = the i th value in array A. The Power Set operation (mapping a set to another set) Addition, subtraction, multiplication,... Sequential circuits and mutable arrays aren’t functions. Why not? (Actually we can model them as functions by making time explicit) 12

13 Outline Prereqs, Learning Goals, and Quiz Notes Functions as “Computation Abstractions” Terminology (out-of-class) Properties: Injective, Surjective, Bijective Inverse Operation Function Proofs Next Lecture Notes 13

14 What is a Function? Mostly, a function is what you learned it was all through K-12 mathematics, with strange vocabulary to make it more interesting… A function f:A  B maps values from its domain A to its co-domain B. Domain Co-domain f(x) = x 3 f(x) = x mod 4 f(x) =  x  Look, sets! CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 14

15 What is a Function? Mostly, a function is what you learned it was all through K-12 mathematics, with strange vocabulary to make it more interesting… A function f:A  B maps values from its domain A to its co-domain B. Domain Co-domain f(x) = x 3 R or Z or... R or Z or... f(x) = x mod 4 Z or Z + or... Z or Z + or... f(x) =  x  R or R + or... Z or Z + or... CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 15

16 Plotting Functions f(x) = x 3 f(x) = x mod 4 f(x) =  x  Not every function is easy to plot! CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 16

17 Plotting Functions f(x) = x 3 f(x) = x mod 4 f(x) =  x  Not every function is easy to plot! CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 17

18 What is a Function? Not every function has to do with numbers… A function f:A  B maps values from its domain A to its co-domain B. Domain Co-domain f(x) = ~x f(x,y) = x  y f(x) = x ’s phone # CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 18

19 What is a Function? Not every function has to do with numbers… A function f:A  B maps values from its domain A to its co-domain B. Domain Co-domain f(x) = ~x{T, F} {T, F} f(x,y) = x  y{T,F}  {T,F}{T, F} f(x) = x ’s phone #Set of people?10-dig #s? CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 19

20 What is a Function? A function f:A  B maps values from its domain A to its co-domain B. f(control, data1, data2) = (~control  data1)  (control  data2) Domain? Co-domain? CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 20

21 What is a Function? A function f:A  B maps values from its domain A to its co-domain B. f(control, data1, data2) = (~control  data1)  (control  data2) Let B = {T,F} : Domain? B  B  B Co-domain? B CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 21

22 What is a Function? A function f:A  B maps values from its domain A to its co-domain B. Domain? Co-domain? Other examples? Alan Steve Paul Patrice Karon George 111 121 211 CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 22

23 What is a Function? A function f:A  B maps values from its domain A to its co-domain B. Domain? {Alan, Steve, Paul, Patrice, Karon, George} Co-domain? {111, 121, 211} Other examples? Alan Steve Paul Patrice Karon George 111 121 211 CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 23

24 What is a Function? A function f:A  B maps values from its domain A to its co-domain B. f can’t map one element of its domain to more than one element of its co-domain:  x  A,  y 1,y 2  B, [(f(x) = y 1 )  (f(x) = y 2 )]  (y 1 = y 2 ). Why insist on this? A B f CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 24

25 What is a Function? A function f:A  B maps values from its domain A to its co-domain B. f can’t map one element of its domain to more than one element of its co-domain:  x  A,  y 1,y 2  B, [(f(x) = y 1 )  (f(x) = y 2 )]  (y 1 = y 2 ). Why insist on this? Why not? We give a different name (relation) to things that do. A B f CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 25

26 Not a Function Why isn’t this a function? (The Laffer Curve: a non-functional tax policy.) CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 26

27 Not a Function Why isn’t this a function? (The Laffer Curve: a non-functional tax policy.) CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) x There is some single value x such that f(x) has more than one value. It may also be true that there is a value y such that f(y) has no value (depending on f’s domain!). 27

28 Function Terminology A function f:A  B maps values from its domain A to its co-domain B. For f to be a function, it must map every element in its domain:  x  A,  y  B, f(x) = y. Why insist on this? A B f Warning: some mathematicians would say that makes f “total”. CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 28

29 Function Terminology A function f:A  B maps values from its domain A to its co-domain B. For f to be a function, it must map every element in its domain:  x  A,  y  B, f(x) = y. Why insist on this? This proves handy in some later definitions. A B f CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 29

30 Not a Function Foiled by sabbatical. Alan Steve Paul Patrice Karon George 111 121 211 Anne CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 30

31 Not a Function Anne does not map to anything: not a function. Alan Steve Paul Patrice Karon George 111 121 211 Anne CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 31

32 Function Terminology A function f:A  B maps values from its domain A to its co-domain B. f(x) is called the image of x (under f ). x is called the pre-image of f(x) (under f ). A B f x y CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 32

33 Function Terminology A function f:A  B maps values from its domain A to its co-domain B. The range of f is the set of all images of elements of f ’s domain. In other words: { f(x) | x  A } A B f x y Which is clearer, the English or the logic? CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 33

34 Trying out Terminology f(x) = x 2 What is the image of 16? What is the range of f ? x f(x) CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 34

35 Trying out Terminology f(x) = x 2 What is the image of 16? f(16) = 16 2 = 256 What is the range of f ? R 0 (assuming the domain is R ) x f(x) CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 35

36 Outline Prereqs, Learning Goals, and Quiz Notes Functions as “Computation Abstractions” Terminology (out-of-class) Properties: Injective, Surjective, Bijective Inverse Operation Function Proofs Next Lecture Notes 36

37 Function Properties: Injective A function f:A  B is injective (also one- to-one) if each image is associated with at most one pre-image:  x,y  A, x  y  f(x)  f(y). Alan Steve Paul Patrice Karon George 111 121 211 Alan Steve Paul Patrice Karon George 211/201 211/202 211/BCS 111 121/202 121/203 121/BCS Injective? 37

38 Trying out Terminology f(x) = x 2 Injective? What if f: R +  R + ? x f(x) 38

39 Trying out Terminology f(x) = |x| (the absolute value of x ) Injective? a.Yes, if f: R  R + b.Yes, if f: R +  R c.Yes, for some other domain/co-domain d.No, not for any domain/co-domain e.None of these is correct x f(x) 39

40 Trying out Terminology f:{s|s is a 121 student}  {A+, A, …, D, F} f(s) = s’s mark in 121 Is f injective? a.Yes b.No c.Not enough information 40

41 Trying out Terminology f:{s|s is a 121 student}  {A+, A, …, D, F} f(s) = s’s mark in 121 What if we didn’t know what f represented, only its “type” and the fact that there are lots of 121 students: f:{s|s is a 121 student}  {A+, A, …, D, F} Is f injective? a.Yes b.No c.Not enough information 41

42 Nifty Injective Function: Error-Detecting Codes Error-detecting codes must be injective. Why? 42

43 Outline Prereqs, Learning Goals, and Quiz Notes Functions as “Computation Abstractions” Terminology (out-of-class) Properties: Injective, Surjective, Bijective Inverse Operation Function Proofs Next Lecture Notes 43

44 Function Properties: Surjective f:A  B is surjective (also onto) if every element of the co-domain has a pre-image:  y  B,  x  A, y = f(x). Alan Steve Paul Patrice Karon George 121 211 Alan Steve Paul Patrice Karon George 211/201 211/202 211/BCS 111 121/202 121/203 121/BCS Surjective? Can we define “surjective” in terms of “range” and “co-domain”? 44

45 Trying out Terminology f(x) = x 2 f: R  R 0 ? Surjective? What if f: R  R? What if f: Z  Z 0 ? x f(x) 45

46 Trying out Terminology f(x) =  x  Is f surjective? a.Yes, for f: R  R 0 ? b.Yes, for f: R 0  R ? c.Yes, for f: R  Z ? d.No, not for any domain/co-domain e.None of these is correct x f(x) 46

47 Trying out Terminology f:{s|s is a 121 student}  {A+, A, …, D, F} f(s) = s’s mark in 121 Is f surjective? a.Yes b.No c.Not enough information Could we ever know that f was surjective just by knowing f ’s domain and co-domain? 47

48 Trying out Terminology Could we ever know that f was surjective just by knowing f ’s domain and co-domain (and their cardinalities)? a.Yes b.No c.Not enough information 48

49 Nifty Surjective Function: Hash Function Hash functions are not always surjective, but they should be. Hash functions usually cannot be injective, which makes hashing hard! 49

50 Surjective Functions So Far Which combinational circuits with one ouput are surjective? a.Every such circuit. b.Any such circuit that represents a contingency (neither a tautology nor contradiction). c.Only the ones equivalent to an inverter. d.No such circuit is surjective. e.None of these is correct. 50

51 Outline Prereqs, Learning Goals, and Quiz Notes Functions as “Computation Abstractions” Terminology (out-of-class) Properties: Injective, Surjective, Bijective Inverse Operation Function Proofs Next Lecture Notes 51

52 Function Properties: Bijective A function f:A  B is bijective (also one- to-one correspondence) if it is both one-to- one and onto (both injective and surjective). Every element in the domain has exactly one unique image. Every element in the co-domain has exactly one unique pre- image. 52

53 Function Properties: Bijective A function f:A  B is bijective (also one- to-one correspondence) if it is both one-to- one and onto. Alan Steve Paul Patrice Karon George 121 211 Alan Steve Paul Patrice Karon George 211/201 211/202 211/BCS 121/202 121/203 121/BCS Bijective? 111 53

54 Trying out Terminology f(x) = x 2 f:?  ? Bijective for what domain/co-domain? x f(x) 54

55 Nifty Bijective Function: Encryption/Lossless Compression Two sets have the same cardinality if we can put them in a bijection. What does that say about lossless compression? 55

56 Outline Prereqs, Learning Goals, and Quiz Notes Functions as “Computation Abstractions” Terminology (out-of-class) Properties: Injective, Surjective, Bijective Inverse Operation Function Proofs Next Lecture Notes 56

57 Function Operations: Inverse The inverse of a function f:A  B is f -1 :B  A. f(x) = y  f -1 (y) = x. How can we tell whether f -1 is a function? (Hint: what would make f -1 not a function?) Can we prove it? 57

58 Trying out Terminology What’s the inverse of each of these f s? Alan Steve Paul Patrice Karon George 121 211 Alan Steve Paul Patrice Karon George 211/201 211/202 211/BCS 121/202 121/203 121/BCS 111 58

59 Trying out Terminology f(x) = x 2 What’s the inverse of f ? What should the domain/co-domain be? x f(x) 59

60 Outline Prereqs, Learning Goals, and Quiz Notes Functions as “Computation Abstractions” Terminology (out-of-class) Properties: Injective, Surjective, Bijective Inverse Operation Function Proofs Next Lecture Notes 60

61 Proving a function injective Recall: A function f : A  B is injective exactly when:  x,y  A, x  y  f(x)  f(y). A typical approach is to prove the contrapositive by antecedent assumption: assume f(x) = f(y) and show that x = y. 61

62 Problem: x 3 + 5 is injective Theorem: f(x) = x 3 + 5 is injective, where f : Z  Z. 62

63 Worked Problem: x 3 + 5 is injective Theorem: f(x) = x 3 +5 is injective, where f : Z  Z. Recall: A function f : A  B is injective exactly when:  x,y  A, x  y  f(x)  f(y). We proceed by establishing the contrapositive of this definition. Then, x 3 + 5 = y 3 + 5by antecedent assumption x 3 = y 3 subtracting 5 from both sides x = ycube root of both sides QED Be careful! Would the same proof work for x 2 + 5 ? No: the square root of x 2 may be +x or -x ! 63

64 Proving a function surjective Recall: A function f : A  B is surjective exactly when:  y  B,  x  A, y = f(x). That existential gives us a lot of freedom to pick a witness! A typical approach is to “solve for” the necessary x given a y. 64

65 Problem: w + 2z is surjective Theorem: f(w,z) = w + 2z is surjective, where f : (Z  Z)  Z. 65

66 Worked Problem: w + 2z is surjective Theorem: f(w,z) = w + 2z is surjective, where f : (Z  Z)  Z. Recall: A function f : A  B is surjective exactly when:  y  B,  x  A, y = f(x). WLOG, let y be an arbitrary integer. Let w = y and z = 0. Then, w + 2z = y + 2(0) = y. QED 66

67 Proving a function bijective Prove that it’s injective. Prove that it’s surjective. Done. 67

68 Proving a function has an inverse Prove that it’s bijective. Done. 68

69 An Inverse Proof Theorem: If f:A  B is bijective, then f -1 : B  A is a function. Recall that f -1 (f(x)) = x. 69

70 An Inverse Proof, Worked Theorem: If f : A  B is bijective, then f -1 : B  A is a function. We proceed by antecedent assumption. Assume f : A  B is bijective. Consider an arbitrary element y of B. Because f is surjective, there is some x in A such that f(x) = y. Because f is injective, that is the only such x. f -1 (y) = x by definition; so, f -1 maps every element of B to exactly one element of A. QED 70

71 Aside: Functions are Just Sets We can define functions in terms of sets and tuples (and we can define tuples in terms of sets!). The function f:A  B is the set {(x, f(x)) | x  A}. f is a subset of A  B ! 71

72 Outline Prereqs, Learning Goals, and Quiz Notes Functions as “Computation Abstractions” Terminology (out-of-class) Properties: Injective, Surjective, Bijective Inverse Operation Function Proofs Next Lecture Notes 72

73 Learning Goals: In-Class By the end of this unit, you should be able to: –Define the terms injective (one-to-one), surjective (onto), bijective (one-to-one correspondence), and inverse. –Determine whether a given function is injective, surjective, and/or bijective. –Apply your proof skills to proofs about the properties (e.g., injectiveness, surjectiveness, bijectiveness, and function-ness) of functions and their inverses. 73

74 Lecture Prerequisites (REPEAT) Read Section 12.2 pages 745-747 and “Designing a Finite Automaton” on 752-754 (skipping part b of the examples). We’ll reread and revisit this later; focus on getting a strong intuitive sense of how DFAs work. Solve problems like Exercise Set 12.2 #1, #12a-c, #13a-c, and #14-19a. Complete the open-book, untimed quiz on Vista that was due before class. 74

75 Learning Goals: “Pre-Class” (REPEAT) The pre-class goals are to be able to: –Trace the operation of a deterministic finite- state automaton (represented as a diagram) on an input, including indicating whether the DFA accepts or rejects the input. –Deduce the language accepted by a simple DFA after working through multiple example inputs. 75

76 snick  snack Extra Slides… 76

77 Function Operations: Composition The composition of two functions f:B  C and g:A  B written f o g is the function h:A  C, where:  x  A, h(x) = f(g(x)). 121 211 Alan Steve Paul Patrice Karon George 211/201 211/202 211/BCS 121/202 121/203 121/BCS 111 211/201 211/202 211/BCS 121/202 121/203 121/BCS What is f ? What is g ? What is f o g ? Dropped from learning goals and exam. 77

78 A Composition Proof Theorem: If g:A  B and f:B  C are functions, then f o g is a function. Recall that (f o g)(x) = f(g(x)). Dropped from learning goals and exam. 78

79 A Composition Proof, Worked Theorem: If g:A  B and f:B  C are functions, then f o g is a function. We proceed by antecedent assumption. Assume g and f are functions. We must show that fog is a function: every element of the domain of f o g ( A ), is mapped to one and only one element of its co-domain ( C ). (Continued on next slide.) Dropped from learning goals and exam. 79

80 A Composition Proof, Worked WLOG, let x be an arbitrary element of A. By the definition of f o g, (f o g)(x) = f(g(x)). We know g(x) is an (i.e., “one and only one”) element of B, since g is a function, x  A, and g : A  B. By similar reasoning, since g(x)  B, we know f(g(x))  C because f is a function. QED Dropped from learning goals and exam. 80


Download ppt "Snick  snack CPSC 121: Models of Computation 2009 Winter Term 1 Functions Steve Wolfman, based on notes by Patrice Belleville and others 1."

Similar presentations


Ads by Google