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

Slides:



Advertisements
Similar presentations
Functions Reading: Epp Chp 7.1, 7.2, 7.4
Advertisements

Snick  snack CPSC 121: Models of Computation 2009 Winter Term 1 Functions Steve Wolfman, based on notes by Patrice Belleville and others 1.
Functions Section 2.3 of Rosen Fall 2008
Discrete Structures Chapter 5 Relations and Functions Nurul Amelina Nasharuddin Multimedia Department.
Lecture 3 Set Operations & Set Functions. Recap Set: unordered collection of objects Equal sets have the same elements Subset: elements in A are also.
Discrete Math for CS Chapter 5: Functions. Discrete Math for CS New Relation Operations: Given R, a relation on A x B, we define the inverse relation,
Functions Goals Introduce the concept of function Introduce injective, surjective, & bijective functions.
1 Section 1.8 Functions. 2 Loose Definition Mapping of each element of one set onto some element of another set –each element of 1st set must map to something,
Functions.
Chapter 7 Functions Dr. Curry Guinn. Outline of Today Section 7.1: Functions Defined on General Sets Section 7.2: One-to-One and Onto Section 7.3: The.
Functions. Let A and B be sets A function is a mapping from elements of A to elements of B and is a subset of AxB i.e. can be defined by a set of tuples!
Discrete Structures Functions Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore.
Section 1.8: Functions A function is a mapping from one set to another that satisfies certain properties. We will first introduce the notion of a mapping.
Functions A B f( ) =. This Lecture We will define a function formally, and then in the next lecture we will use this concept in counting. We will also.
Sets Set Operations Functions. 1. Sets 1.1 Introduction and Notation 1.2 Cardinality 1.3 Power Set 1.4 Cartesian Products.
2.1 Sets 2.2 Set Operations 2.3 Functions ‒Functions ‒ Injections, Surjections and Bijections ‒ Inverse Functions ‒Composition 2.4 Sequences and Summations.
FUNCTION Discrete Mathematics Asst. Prof. Dr. Choopan Rattanapoka.
A Brief Summary for Exam 1 Subject Topics Propositional Logic (sections 1.1, 1.2) –Propositions Statement, Truth value, Proposition, Propositional symbol,
Foundations of Discrete Mathematics Chapter 3 By Dr. Dalia M. Gil, Ph.D.
Functions. Copyright © Peter Cappello2 Definition Let D and C be nonempty sets. A function f from D to C, for each element d  D, assigns exactly 1 element.
Week 7 - Friday.  What did we talk about last time?  Set disproofs  Russell’s paradox  Function basics.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFunctions.
Fall 2002CMSC Discrete Structures1 … and the following mathematical appetizer is about… Functions.
10/26/20151 … and the following mathematical appetizer is about… Functions.
1 Annoucement n Skills you need: (1) (In Thinking) You think and move by Logic Definitions Mathematical properties (Basic algebra etc.) (2) (In Exploration)
FUNCTIONS.
Discrete Mathematics CS 2610 September 12, Agenda Last class Functions  Vertical line rule  Ordered pairs  Graphical representation  Predicates.
Functions Section 2.3 of Rosen Spring 2012 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions: Use Piazza.
1 Discrete Structures – CNS 2300 Text Discrete Mathematics and Its Applications (5 th Edition) Kenneth H. Rosen Chapter 1 The Foundations: Logic, Sets,
Chapter 1 SETS, FUNCTIONs, ELEMENTARY LOGIC & BOOLEAN ALGEBRAs BY: MISS FARAH ADIBAH ADNAN IMK.
1.4 Sets Definition 1. A set is a group of objects . The objects in a set are called the elements, or members, of the set. Example 2 The set of positive.
Example Prove that: “IF 3n + 2 is odd, then n is odd” Proof by Contradiction: -p = 3n + 2 is odd, q = n is odd. -Assume that ~(p  q) is true OR -(p 
Functions Reading: Chapter 6 (94 – 107) from the text book 1.
Basic Structures: Functions Muhammad Arief download dari
CSE 2353 – October 1 st 2003 Functions. For Real Numbers F: R->R –f(x) = 7x + 5 –f(x) = sin(x)
Agenda Week 10 Lecture coverage: –Functions –Types of Function –Composite function –Inverse of a function.
Functions. L62 Agenda Section 1.8: Functions Domain, co-domain, range Image, pre-image One-to-one, onto, bijective, inverse Functional composition and.
11 DISCRETE STRUCTURES DISCRETE STRUCTURES UNIT 5 SSK3003 DR. ALI MAMAT 1.
MATH 224 – Discrete Mathematics
Math 344 Winter 07 Group Theory Part 2: Subgroups and Isomorphism
CSC102 - Discrete Structures Functions
Based on slides by Patrice Belleville and Steve Wolfman CPSC 121: Models of Computation Unit 11: Sets.
1 Functions CS 202 Epp section ??? Aaron Bloomfield.
FUNCTIONS COSC-1321 Discrete Structures 1. Function. Definition Let X and Y be sets. A function f from X to Y is a relation from X to Y with the property.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
Functions CSRU1400 Spring 2008Ellen Zhang 1 CISC1400, Fall 2010 Ellen Zhang.
CMSC250 S ECTIONS 0303 & 0304 M IDTERM R EVIEW Sri Kankanahalli Discussion 10: 9 March 2016 Office Hrs: Mon. and Wed. 4-6PM AVW 1112.
1 Lecture 5 Functions. 2 Functions in real applications Curve of a bridge can be described by a function Converting Celsius to Fahrenheit.
Section 2.3. Section Summary  Definition of a Function. o Domain, Cdomain o Image, Preimage  One-to-one (Injection), onto (Surjection), Bijection 
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
FUNCTIONS.
Week 8 - Wednesday.  What did we talk about last time?  Relations  Properties of relations  Reflexive  Symmetric  Transitive.
Discrete Mathematics Lecture # 17 Function. Relations and Functions  A function F from a set X to a set Y is a relation from X to Y that satisfies the.
Discrete Mathematics Functions
Functions 7/7/2016COCS - Discrete Structures1. Functions A function f from a set A to a set B is an assignment of exactly one element of B to each element.
Functions Goals Introduce the concept of function
Function Hubert Chan (Chapter 2.1, 2.2) [O1 Abstract Concepts]
Functions Section 2.3.
Relations, Functions, and Matrices
CPSC 121: Models of Computation 2008/9 Winter Term 2
CPSC 121: Models of Computation 2011 Winter Term 1
Function Hubert Chan (Chapter 2.1, 2.2) [O1 Abstract Concepts]
Functions Section 2.3.
Functions CS 202 Epp section 7.1.
A Brief Summary for Exam 1
Functions.
Ch 5 Functions Chapter 5: Functions
CPSC 121: Models of Computation 2016W2
CPSC 121: Models of Computation
Functions Section 2.3.
Presentation transcript:

snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Functions Steve Wolfman, based on notes by Patrice Belleville and others

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

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.

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.

Outline Functions as “Computation Abstractions” Definition of Functions and Function Terminology Function Properties –Injective –Surjective –Bijective Function Operations –Inverse –Composition Dropped from learning goals and exam.

What is this? control data1 data2 output

What is this? control data1 data2 output

What is this? control data1 data2 output

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

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 level that let us talk about how computations work and fit together. Bonus: functions alone are enough for all of computation, using the “λ calculus”.

Outline Functions as “Computation Abstractions” Definition of Functions and Function Terminology Function Properties –Injective –Surjective –Bijective Function Operations –Inverse –Composition

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)

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)

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)

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)

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)

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)

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)

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)

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 CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

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 CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

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)

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)

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)

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!).

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)

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)

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

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

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)

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)

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)

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)

Functions We’ve Used Any combinational logic circuit The “inverse” and “zip” operations over algorithms from the midterm The operation that gives you a student’s grade given the student: G(s) = s’s grade Arrays, as long as they’re immutable (unchangeable): A(i) = the i th value in array A. Sequential circuits and mutable arrays aren’t functions. Why not? (Actually we can model them as functions by making time explicit)

Outline Functions as “Computation Abstractions” Definition of Functions and Function Terminology Function Properties –Injective –Surjective –Bijective Function Operations –Inverse –Composition

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 Alan Steve Paul Patrice Karon George 211/ / /BCS / / /BCS Injective?

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

Trying out Terminology f:{s|s is a 121 student}  {A+, A, …, D, F} f(s) = s’s mark in 121 Is f injective? 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}

Nifty Injective Function: Error-Correcting Codes Error-correcting codes must be injective. Why?

Outline Functions as “Computation Abstractions” Definition of Functions and Function Terminology Function Properties –Injective –Surjective –Bijective Function Operations –Inverse –Composition

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 Alan Steve Paul Patrice Karon George 211/ / /BCS / / /BCS Surjective? Can we define “surjective” in terms of “range” and “co-domain”?

Trying out Terminology f(x) = x 2 f: R  R 0 ? Surjective? What if f: R  R? What if f: Z  Z 0 ? How about f(x) =  x  ? For what types is it surjective? x f(x)

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

Nifty Surjective Function: “Lossy” Compression WARNING: Lossy compression functions are not always surjective… But it’s valuable if they are. Why?

Surjective Functions So Far Under what circumstances is a combinational circuit with one ouput surjective? Under what circumstances is it not surjective? So, are our circuits usually surjective or not?

Outline Functions as “Computation Abstractions” Definition of Functions and Function Terminology Function Properties –Injective –Surjective –Bijective Function Operations –Inverse –Composition

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

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 Alan Steve Paul Patrice Karon George 211/ / /BCS 121/ / /BCS Bijective? 111

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

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?

Outline Functions as “Computation Abstractions” Definition of Functions and Function Terminology Function Properties –Injective –Surjective –Bijective Function Operations –Inverse –Composition

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?

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

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

Outline Functions as “Computation Abstractions” Definition of Functions and Function Terminology Function Properties –Injective –Surjective –Bijective Function Operations –Inverse –Composition Dropped from learning goals and exam.

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)) Alan Steve Paul Patrice Karon George 211/ / /BCS 121/ / /BCS / / /BCS 121/ / /BCS What is f ? What is g ? What is f o g ? Dropped from learning goals and exam.

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.

Problem: x is injective Theorem: f(x) = x is injective, where f : Z  Z.

Worked Problem: x 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 = 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 ? No: the square root of x 2 may be +x or -x !

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.

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

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

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

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

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.

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

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.

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.

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

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 !

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.