CS100: DISCRETE STRUCTURES

Similar documents
Section Summary. Definition of a Function.

Section Summary. Definition of a Function.

Func%ons. function f to the element a of A. Functions are sometimes called mappings or transformations.

Sec$on Summary. Definition of a Function.

Chapter Summary. Sets The Language of Sets Set Operations Set Identities Functions Types of Functions Operations on Functions Computability

Functions. Given a function f: A B:

Chapter Summary. Sets (2.1) Set Operations (2.2) Functions (2.3) Sequences and Summations (2.4) Cardinality of Sets (2.5) Matrices (2.

Functions as Relations

9/21/2018. Properties of Functions. Properties of Functions. Properties of Functions. Properties of Functions. Properties of Functions

2.1 Sets. Definition 1 A set is an unordered collection of objects. Important sets: N, Z, Z +, Q, R.

Section 4.4 Functions. CS 130 Discrete Structures

Today s Topics. Methods of proof Relationships to logical equivalences. Important definitions Relationships to sets, relations Special functions

9/21/17. Functions. CS 220: Discrete Structures and their Applications. Functions. Chapter 5 in zybooks. definition. definition

1. Decide for each of the following expressions: Is it a function? If so, f is a function. (i) Domain: R. Codomain: R. Range: R. (iii) Yes surjective.

CS 220: Discrete Structures and their Applications. Functions Chapter 5 in zybooks

Notes. Functions. Introduction. Notes. Notes. Definition Function. Definition. Slides by Christopher M. Bourke Instructor: Berthe Y.

Sets and Functions. MATH 464/506, Real Analysis. J. Robert Buchanan. Summer Department of Mathematics. J. Robert Buchanan Sets and Functions

Introduction to Decision Sciences Lecture 6

Selected problems from past exams

3 FUNCTIONS. 3.1 Definition and Basic Properties. c Dr Oksana Shatalov, Spring

3 FUNCTIONS. 3.1 Definition and Basic Properties. c Dr Oksana Shatalov, Fall

3 FUNCTIONS. 3.1 Definition and Basic Properties. c Dr Oksana Shatalov, Fall

4) Have you met any functions during our previous lectures in this course?

Functions Functions and Modeling A UTeach/TNT Course

Solutions to Homework Problems

Week Some Warm-up Questions

SETS AND FUNCTIONS JOSHUA BALLEW

Sets. We discuss an informal (naive) set theory as needed in Computer Science. It was introduced by G. Cantor in the second half of the nineteenth

5 FUNCTIONS. 5.1 Definition and Basic Properties. c Dr Oksana Shatalov, Fall

9 FUNCTIONS. 9.1 The Definition of Function. c Dr Oksana Shatalov, Fall

0 Sets and Induction. Sets

CSE 20 DISCRETE MATH. Fall

RELATIONS AND FUNCTIONS

Chapter 2 - Basics Structures MATH 213. Chapter 2: Basic Structures. Dr. Eric Bancroft. Fall Dr. Eric Bancroft MATH 213 Fall / 60

Discussion Summary 10/16/2018

Functions. Definition 1 Let A and B be sets. A relation between A and B is any subset of A B.

Chapter 2 - Basics Structures

Cartesian Products and Relations

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Inverse Functions. One-to-one. Horizontal line test. Onto

Discrete Structures for Computer Science

Review Problems for Midterm Exam II MTH 299 Spring n(n + 1) 2. = 1. So assume there is some k 1 for which

Caculus 221. Possible questions for Exam II. March 19, 2002

Countable and uncountable sets. Matrices.

4.1 Real-valued functions of a real variable

General Notation. Exercises and Problems

CSE 20 DISCRETE MATH WINTER

Sets and Functions. (As we will see, in describing a set the order in which elements are listed is irrelevant).

Real Analysis. Joe Patten August 12, 2018

Practice Exam 1 CIS/CSE 607, Spring 2009

INFINITY.THINK BEYOND.

CSCE 222 Discrete Structures for Computing

LESSON RELATIONS & FUNCTION THEORY

(So SamID 1 ( ) = Ken W. Smith.)

Section 7.2: One-to-One, Onto and Inverse Functions

Discrete dynamics on the real line

CIS 375 Intro to Discrete Mathematics Exam 2 (Section M001: Yellow) 10 November Points Possible

ICS141: Discrete Mathematics for Computer Science I

MATH 220 (all sections) Homework #12 not to be turned in posted Friday, November 24, 2017

Review of Functions. Functions. Philippe B. Laval. Current Semester KSU. Philippe B. Laval (KSU) Functions Current Semester 1 / 12

Intro to Theory of Computation

Math 300 Introduction to Mathematical Reasoning Autumn 2017 Inverse Functions

CLASS12 RELATIONS AND FUNCTIONS

Introduction to Functions

Functions of Several Variables (Rudin)

Sets & Functions. x A. 7 Z, 2/3 Z, Z pow(r) Examples: {7, Albert R., π/2, T} x is a member of A: x A

Section Summary. Sequences. Recurrence Relations. Summations. Examples: Geometric Progression, Arithmetic Progression. Example: Fibonacci Sequence

Countable and uncountable sets. Matrices.

Relations, Functions, Binary Relations (Chapter 1, Sections 1.2, 1.3)

QF101: Quantitative Finance August 22, Week 1: Functions. Facilitator: Christopher Ting AY 2017/2018

COM S 330 Homework 05 Solutions. Type your answers to the following questions and submit a PDF file to Blackboard. One page per problem.

Foundations of Mathematics MATH 220 FALL 2017 Lecture Notes

Functions and cardinality (solutions) sections A and F TA: Clive Newstead 6 th May 2014

(a) We need to prove that is reflexive, symmetric and transitive. 2b + a = 3a + 3b (2a + b) = 3a + 3b 3k = 3(a + b k)

QUESTION BANK II PUC SCIENCE

and problem sheet 6

CS Discrete Mathematics Dr. D. Manivannan (Mani)

MODEL ANSWERS TO THE SEVENTH HOMEWORK. (b) We proved in homework six, question 2 (c) that. But we also proved homework six, question 2 (a) that

Theorem. For every positive integer n, the sum of the positive integers from 1 to n is n(n+1)

We could express the left side as a sum of vectors and obtain the Vector Form of a Linear System: a 12 a x n. a m2

RED. Name: Math 290 Fall 2016 Sample Exam 3

REVIEW FOR THIRD 3200 MIDTERM

Math 42, Discrete Mathematics

Day 15. Tuesday June 12, 2012

Introduction to Proofs

RED. Fall 2016 Student Submitted Sample Questions

Sets, Functions and Relations

Finite and Infinite Sets

Mathematics Review for Business PhD Students

MATH 201 Solutions: TEST 3-A (in class)

Number Axioms. P. Danziger. A Group is a set S together with a binary operation (*) on S, denoted a b such that for all a, b. a b S.

Discrete Mathematics: Lectures 6 and 7 Sets, Relations, Functions and Counting Instructor: Arijit Bishnu Date: August 4 and 6, 2009

2 Functions. 2.1 What is a function?

Chapter 1 : The language of mathematics.

Undecidability. Andreas Klappenecker. [based on slides by Prof. Welch]

Propositional Logic, Predicates, and Equivalence

Numbers, sets, and functions

CHAPTER 7 FUNCTIONS. Alessandro Artale UniBZ - artale/

MATH 215 DISCRETE MATHEMATICS INSTRUCTOR: P. WENG

Relationships between elements of sets occur in many contexts. Every day we deal with

Transcription:

1 CS100: DISCRETE STRUCTURES Computer Science Department Lecture 2: Functions, Sequences, and Sums Ch2.3, Ch2.4

2.3 Function introduction : 2 v Function: task, subroutine, procedure, method, mapping, v E.g. Find the grades of student x. char findgrades(string name){ } //go to grades array, //find the name, and find the corresponding grades return grades; 17-Feb-17 Computer Science Department

2.3 Functions 3 DEFINITION 1 Let A and B to be nonempty sets. a function f from A to B is an assignment of exactly one element of B to each element of A. We write f(a) = b if b is the unique element of B assigned by the function f to the element a of A. If f is a function from A to B, we write f: A B. We can use a formula or a computer program to define a function. Example: f(x) = x + 1 described as: int increasebyone(int x){ x = x + 1; return x; }

2.3 Functions 4 DEFINITION 2 If f is a function from A to B, we say that A is the domain of f and B is the Co-domain of f. If f(a) = b, we say that b is the image of a and a is a preimage of b. The range of f is the set of all images of elements of A. Also, if f is a function from A to B, we say that f maps A to B. v For each function, we specify its domain, codomain and the mapping of elements of the domain to elements in the codomain v Two functions are said to be equal if they have the same domain, codomain, and the map elements of their common domain to the same elements of their common codomain v A function is differ by changing its domain, codomain or the mapping of elements

Exercise.. 5 What are the domain, codomain, and range of the function that assigns grades to students described in the slide 2? Solution: domain: {Adams, Chou, Goodfriend, Rodriguez, Stevens} codomain: {A, B, C, D, F} range: {A, B, C, F}

2.3 Functions - Example 6 v ü Let f be the function that assigns the last two bits of a bit string of length 2 or greater to that string. For example, f (11010) = 10. What is the domain, codomain and range of the function? Solution: the domain of f is the set of all bit strings of length 2 or greater.. and both the codomain and range are the set {00,01,10,11}..

2.3 Functions - Example 7 ü What is the domain and codomain of the function : int floor(real float){ }? Solution: domain: the set of real numbers codomain: the set of integer numbers

2.3 Functions 8 DEFINITION 3 If f 1 and f 2 be functions from A to R. Then f 1 + f 2 and f 1 f 2 are also functions from A to R defined by (f 1 + f 2 )(x) = f 1 (x) + f 2 (x) (f 1 f 2 ) (x) = f 1 (x) f 2 (x) v Example: Let f 1 and f 2 be functions from R to R such that f 1 (x) =x 2 and f 2 (x) = x x 2. v What are the functions f 1 + f 2 and f 1 f 2? Solution: (f 1 + f 2 )(x) = f 1 (x) + f 2 (x) = x 2 + (x x 2 ) = x (f 1 f 2 ) (x) = f 1 (x) f 2 (x) = x 2 (x x 2 ) = x 3 x 4

2.3 Functions One-to-One and Onto Functions 9 DEFINITION 5 A function f is said to be one-to-one, or injective, if and only if f(a) = f(b) implies that a = b for all a and b in the domain of f. A function is said to be an injection if it is one-to-one. (every element in the range is a unique image for element of A all image have at most one arrow or none) " a, b(a b f(a) f(b)) (If it s a different element, it should map to a different value.) Example: Determine whether the function f from {a,b,c,d} to {1,2,3,4,5} with f(a) = 4, f(b) = 5, f(c) = 1 and f(d) = 3 is one-to-one. Solution: Yes.

2.3 Functions 10 DEFINITION 7 A function f from A to B is called onto, or surjective, if and only if for every element b ÎB there is an element aîa with f(a) = b. a function f is called a surjection if it is onto. Co-domain = range Example: Let f be the function from {a,b,c,d} to {1,2,3} defined by f(a) = 3, f(b) = 2, f(c) = 1, and f(d) = 3. Is f an onto function? Solution: Yes. Example: Is the function f (x) = x 2 from the set of integers to the set of integers onto? Solution: No. There is no integer x with x 2 = -1, for instance.

2.3 Functions 11 DEFINITION 8 The function f is a one-to-one correspondence or a bijection, if it is both oneto-one and onto. One-to-One Not onto Onto Not One-to-One One-to-One And onto bijection Not One-to-One Not onto (Neither) Not Function

Exercise.. 12 Determine whether each of these functions is a bijection from R to R. a) f(x) = 2x + 1 b) f(x) = x 2 + 1 Yes No c) f(x) = x 3 Yes d) f(x) = (x 2 + I )/(x 2 + 2) No 17-Feb-17 Computer Science Department

Exercise.. 13 Why f is not a function from R to R? f(x)= f(0) is not defined f(x)= f(x) is not defined for x<0 f(x)= f(x) is not function because there are two values assigned to each x. 17-Feb-17 Computer Science Department

2.3 Functions 14 DEFINITION 9 Let f be a one-to-one correspondence from the set A to the set B. The inverse function of f is the function that assigns to an element b belonging to B the unique element a in A such that f(a) = b. The inverse function of f is denoted by f -1. Hence, f -1 (b)=a when f(a) = b. A one-to-one correspondence is called invertible because we can define an inverse of this function. A function is not invertible if it is not a one-to-one correspondence because the inverse of such function does not exist.

2.3 Functions 15 Example: Let f be the function from {a, b, c} to {1, 2, 3} such that f(a) =2, f(b) = 3 and f(c) = 1. Is f invertible? And if it is, what is its inverse? Solution: Yes, it is invertible, because it is a one-to-one correspondence. f -1 (1) = c, f -1 (2) = a, f -1 (3) = b. Exercise: Let f : Z àz be such that f(x) = x+1. Is f invertible? And if it is, what is its inverse? Solution: Yes, it is invertible, because it is a one-to-one correspondence. f -1 (y) = y-1. Exercise: Let f be a function from R to R with f(x) = x 2. Is f invertible? Solution: f is not one-to-one because f(-2) = f(2) = 4. So, it is not one-toone correspondence and hence it is not invertible.

2.3 Functions 16 DEFINITION 10 Let g be a function from the set A to the set B, and let f be a function from the set B to the set C. The composition of the functions f and g, denoted by f o g, is defined by: (f o g)(a) = f(g(a))

2.3 Functions 17 o f o g is the function that assigns to the element a of A the element assigned by f to g(a). That is, to find (f o g )(a) we: 1. Apply the function g to a to obtain g(a) 2. Then we apply the function f to the result g(a) to obtain (f o g)(a) = f(g(a)) o NOTE: The composition f o g cannot be defined unless the range of g is a subset of the domain of f.

2.3 Functions 18 Example: Let g be the function from the set {a, b, c} to itself such that g(a) = b, g(b) = c, and g(c) = a Let f be the function from the set {a, b, c} to the set { l, 2, 3 } such that f(a) = 3, f(b) = 2, and f(c) = 1 What is the composition of f and g, and what is the composition of g and f? Solution: The composition f o g is defined by: (f o g)(a) = f(g(a)) = f(b) =2 (f o g)(b) = f(g(b)) = f(c) =1 (f o g)(c) = f(g(c)) = f(a) = 3 g o f is not defined, because the range of f is not a subset of the domain of g

2.3 Functions 19 Example: Let f and g be the functions from the set of integers to the set of integers defined by f(x) = 2x + 3 and g(x) = 3x + 2. What is the composition of f and g? What is the composition of g and f? Solution: Both the compositions f o g and g o f are defined (f o g)(x) = f(g(x)) = f(3x + 2) = 2(3x + 2) + 3 = 6x + 7 (g 0 f)(x) = g(f(x)) = g(2x + 3) = 3(2x + 3) + 2 = 6x + 11.

20 v 2.4 Sequences and Summations Sequences A sequence is a discrete structure used to represent an ordered list v Example: 1,2,3,5,8 1,3,9,27,81,,30, DEFINITION 1 a sequence is a function from a subset of the set of integers (usually either the set {0,1,2, } or the set {1,2,3, }) to a set S. We use the notation a n to denote the image of the integer n. We call a n a term of the sequence. We use the notation {a n } to denote the sequence. Example: Consider the sequence {a n }, where a n = 1/n. The list of the terms of this sequence, beginning with a 1, namely a 1, a 2, a 3, a 4,, starts with 1, 1/2, 1/3, 1/4,

2.4 Sequences and Summations 21 DEFINITION 2 a geometric progression is a sequence of the form a, ar, ar 2,, ar n, where the initial term a and the common ratio r are real numbers. Example: The following sequence are geometric progressions. {b n } with b n = (-1) n starts with 1, -1, 1, -1, 1, initial term: 1, common ratio: -1 {c n } with c n = 2*5 n starts with 2, 10, 50, 250, 1250, initial term: 2, common ratio: 5 {d n } with d n = 6 *(1/3) n starts with 6,2, 2/3, 2/9, 2/27, initial term: 6, common ratio: 1/3

2.4 Sequences and Summations 22 DEFINITION 3 A arithmetic progression is a sequence of the form a, a + d, a + 2d,, a + nd, where the initial term a and the common difference d are real numbers. Example: The following sequence are arithmetic progressions. {s n } with s n = -1 + 4n starts with -1, 3, 7, 11, initial term: -1, common difference: 4 {t n } with t n = 7 3n starts with 7, 4, 1, -2, initial term: 7, common difference: -3

2.4 Sequences and Summations 23 Example : Find formulae for the sequences with the following first five terms (a). 1, 1/2, 1/4, 1/8, 1/16 Solution: a n = 1/2 n (b). 1, 3, 5, 7, 9 Solution: a n = (2n )+ 1 (c). 1, -1, 1, -1, 1 Solution: a n = (-1) n

Exercises 24 Find the formula of this sequence and find A6, A8 : A = 10, 14, 18, 22, 26 It is arithmetic sequence, initial term a= 20, common difference d= 4, a n =10+4n A 6 = 34, A 8 = 42

Exercises 25 A = 4, 8, 16, 32 It is geometric sequence, initial term = 4, common ratio = 2, a n =4*2 n A 6 = 256, A 8 = 1024

Exercises 26 o in a geometric sequence a 0 was =3 and r =1/2 then a 3 is equal to a. 3/16 b. 3/4 c. 3/2 d. 3/8 In an arithmetic sequence a 0 was =7 and a 3 was 19 the value of a 2 is= a.14 b.11 c.15 d.23

2.4 Sequences and Summations Summations 27 v The sum of the terms from the sequence a m + a m+1,, a n can be expressed as n å j= m n a j å j = m, Or a å j 1 j n a j Where m is the lower limit, n is the upper limit, and j is the index of the summation Example: Express the sum of the first 100 terms of the sequence {a n }, where an = 1/n for n = 1,2,3,. Solution: 100 å j= 1 1 j

2.4 Sequences and Summations 28 5 å = What is the value of j 1? Solution: 5 å j = 1 j 2 = 1 + 4 + 9 + 16 + 25 = 55 j 2 Expressed with a for loop: int sum = 0; for (int i =1; i <=5; i++) { sum = sum + i * i ; }

2.4 Sequences and Summations 29 What is the value of the double summation ij? Solution: 4 3 åå i= 1 j= 1 ij = 4 å i= 1 4 å ( i + 2i + 3i) = 6i = 6 + 12 + 18 + 24 = 60 i= 1 4 3 åå i= 1 j= 1

Sequences and Summations 30 Expressed with two for loops: Solution: int sum1 = 0; int sum2 = 0; for (int i =1; i <=4; i ++){ sum2 = 0; for (int j=1; j<=3; j++){ sum2 = sum2 + i *j; } sum1 = sum1 + sum2; }

Exercises 31 Write ( 1 + 4 + 9 + 16 +... + 49 notation. ) using sigma Solution: $! k # %&' 17-Feb-17 Computer Science Department

ANY QUESTIONS?? 32 Refer to chapter 2 of the book for further reading