42
Relations. Functions. Bijection and counting.

Relations.Functions. Bijectionandcounting.Cartesianproduct Functions Bijection Inclusion-Exclusion p.12 Relations Example of a relation: S = set of students C = set of classes R =

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

  • Relations. Functions.Bijection and counting.

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 2

    Cartesian products

    Given two setsA= {1, 2,3}B = {1, 2,3, 4}

    Their Cartesian product

    A× B = {(1,1), (2,1), (3,1),(1,2), (2,2), (3,2),(1,3), (2,3), (3,3),(1,4), (2,4), (3,4)}

    Question: What is the cartesian product of Z×Z?

    (Z is the set of all integers)

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 3

    Cartesian product Z×Z= Z2

    x

    y

    Origin (0, 0)

    (1, 2)

    (−3, 0)

    (−1,−3)

    All pairs ofintegers are in Z2,for exmaple(1, 2) ∈ Z2

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 4

    Is it a Cartesian product?

    x

    y

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 5

    Cartesian product of Z×N

    x

    y

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 6

    Is it a Cartesian product?

    x

    y

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 7

    Cartesian product of N×N= N2

    x

    y

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 8

    Is it a Cartesian product?

    x

    y

    (2,0)(−2,0)

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 9

    Is it a Cartesian product? No

    x

    y

    (2,0)(−2,0)

    R=�

    (x , y) ∈ Z2�

    � max(|x |, |y|) = 2

    ⊆ Z2

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 10

    Is it a Cartesian product? No

    x

    y

    (2,0)(−2,0)

    A subset R ⊆ Z×Z of a Cartesianproduct is called a relation.

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 11

    Relations

    Given any two sets

    A= {♠,♣,♥,♦} and B = {1,2, 3, . . .}

    Def. A subset R of the Cartesian product A× B is called a relationfrom the set A to the set B.

    R=�

    (♠, 99), (♥, 15), (♣, 105), (♣, 1), (♣, 15)

    ⊆ A× B

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 12

    Relations

    Example of a relation:

    S = set of students

    C = set of classes

    R= {(s, c) | student s takes class c}

    Alice

    Bob

    Eve

    Mark

    Zack

    CS 150

    CS 235

    Math 254

    Hist 152

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 13

    Airline routemap

    We connect two cities if the airline operates a flight from one tothe other. Is it a relation?

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 14

    Airline routemap

    Routes ⊆ Cities× Cities

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 15

    Airline routemap

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 16

    Any subset of A× B is a relation

    x

    y

    R ⊆ Z×ZR=�

    (−1,2), (1, 2), (−1, 1),(1, 1), (−2,−1), (−1,−2),(0,−2), (1,−2), (2,−1)

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 17

    Any subset of A× B is a relation

    x

    y

    (−1, 1)

    R ⊆ R×RR=�

    (x , y) ∈ R×R | (x+1)2+(y−1)2 ≤ 2

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 18

    A function is a relation too!

    x

    y

    R ⊆ R×RR=�

    (x , y) ∈ R×R | y = f (x)

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 19

    Relation {(x , y) | y = |x |}

    x

    y

    Z→ Z

    3

    2

    1

    0

    −1

    −2

    −3

    3

    2

    1

    0

    −1

    −2

    −3

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 20

    Relation {(x , y) | y = x rem 3}

    x

    y

    Z→ Z

    3

    2

    1

    0

    −1

    −2

    −3

    3

    2

    1

    0

    −1

    −2

    −3

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 21

    Functions

    Def. A relation R ⊆ A× B is a function (a functional relation) if forevery a ∈ A, there is at most one b ∈ B so that (a, b) ∈ R.

    A= {1, 2,3}, B = {1,2, 3,4}

    R1 = {(1, 1), (2,2), (3,3)}R2 = {(1, 2), (1,3), (1,4), (2,3), (2,4), (3,4)} ← Not a functionR3 = {(1, 2), (2,3), (3,4)}

    1

    2

    3

    1

    2

    3

    4

    1

    2

    3

    1

    2

    3

    4

    1

    2

    3

    1

    2

    3

    4

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 22

    Functions

    Functional relation R ⊆ A× B defines a unique way to map eachelement from the set A to an element from the set B.

    There is a well-known and convenient notation for functions:

    f (a) = b where a ∈ A and b ∈ B

    It maps elements from A to B:

    f : A→ B

    Af−→ B

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 23

    Functions

    Def. For the function f : A→ B, set A is called domain, and set Bis called codomain.

    x

    y

    z

    1

    2

    3

    4f : A→ B

    domain( f ) = A= {x , y, z}codomain( f ) = B = {1, 2,3, 4}image( f ) = f (A) = {2, 3}

    Def. f (a) is the image of a point a ∈ A.

    Def. The image of a function f , denoted by f (A), is the set of allimages of all points a ∈ A

    f (A) = {x | ∃a ∈ A ( f (a) = x)}.

    The image of a function is also called range.

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 24

    Onto

    Def. A function f : A → B is called onto if and only if for everyelement b ∈ B there is an element a ∈ A with f (a) = b.

    In other words, the image f (A) is the whole codomain B.

    f : A→ B is onto

    v

    w

    x

    y

    z

    1

    2

    3

    4

    g : A→ B is not onto

    v

    w

    x

    y

    z

    1

    2

    3

    4

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 25

    One-to-one

    Def. A function f : A → B is said to be one-to-one if and only iff (x) = f (y) implies that x = y for all x , y ∈ A.

    f : A→ B is one-to-one

    w

    x

    y

    z

    0

    1

    2

    3

    4

    g : B→ C is not one-to-one

    0

    1

    2

    3

    4

    1/5

    1/6

    1/7

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 26

    Bijection

    Def. The function f is a bijection (also called one-to-one correspon-dence) if and only if it is both one-to-one and onto.

    f : A→ B is a bijection

    v

    w

    x

    y

    z

    0

    1

    2

    3

    4

    g : A→ B is not a bijection

    v

    w

    x

    y

    z

    0

    1

    2

    3

    4

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 27

    Bijection

    f : A→ B is one-to-one, butnot onto

    w

    x

    y

    z

    0

    1

    2

    3

    4

    g : C → D is onto, but notone-to-one

    v

    w

    x

    y

    z

    0

    1

    2

    3

    So, both functions are not bijections.

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 28

    Bijection. Observation

    Bijection Rule. Given two sets A and B, if there exists a bijection

    f : A→ B, then |A|= |B|.

    v

    w

    x

    y

    z

    0

    1

    2

    3

    4

    We can count the size of the set A, instead of the size of B!

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 29

    Bijection Rule.

    Consider two similar problems:

    (a) How many bit strings contain exactly three 1s and two 0s?

    11010

    (b) How many strings can be composed of three ‘A’s and five ‘b’s sothat an ‘A’ is always followed by a ‘b’?

    AbAbbAbb

    We show that this two problems are equivalent by constructing abijection.

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 30

    Bijection Rule.

    Let X be the set of bit strings

    X = {11010, . . .}

    and Y be the set of ‘A’ and ‘b’ strings

    Y = {AbAbbAbb, . . .}

    We can construct a bijection f : X → Y :

    1 gets replaced by Ab0 gets replaced by b

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 31

    Bijection Rule.

    f : 11100 7→ Ab Ab Ab b b11010 7→ Ab Ab b Ab b11001 7→ Ab Ab b b Ab10110 7→ Ab b Ab Ab b10101 7→ Ab b Ab b Ab10011 7→ Ab b b Ab Ab01110 7→ b Ab Ab Ab b01101 7→ b Ab Ab b Ab01011 7→ b Ab b Ab Ab00111 7→ b b Ab Ab Ab

    Function f is one-to-one and onto, so it is a bijection. Therefore,the cardinalities of two sets are equal: |X |= |Y |=

    �53

    = 10.

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 32

    Bijection. Observation

    Observation For every bijection f : A→ B, exists an inverse function

    f −1 : B→ A

    f : A→ B1

    v

    w

    x

    y

    z

    0

    1

    2

    3

    4

    The inverse function is a bijection too.

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 33

    Bijection. Observation

    Observation For every bijection f : A→ B, exists an inverse function

    f −1 : B→ A

    f : A→ B1

    v

    w

    x

    y

    z

    0

    1

    2

    3

    4

    f −1 : B→ A

    0

    1

    2

    3

    4

    v

    w

    x

    y

    z

    The inverse function is a bijection too.

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 34

    Bijection. Observation

    Given two bijections f : A→ B and g : B→ C .Consider their composition

    h(x) = g( f (x))

    f : A→ B

    w

    x

    y

    z

    1

    2

    3

    4

    g : B→ C

    1

    2

    3

    4

    1/5

    2/5

    3/5

    4/5

    h : A→ C is a bijection, and therefore |A|= |C |.

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 35

    Bijection. Observation

    Given two bijections f : A→ B and g : B→ C .Consider their composition

    h(x) = g( f (x))

    f : A→ B

    w

    x

    y

    z

    1

    2

    3

    4

    g : B→ C

    1

    2

    3

    4

    1/5

    2/5

    3/5

    4/5

    h : A→ C

    w

    x

    y

    z

    1/5

    2/5

    3/5

    4/5

    h : A→ C is a bijection, and therefore |A|= |C |.

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 36

    Bijection. Counting subsets

    Please, count the number of subsets of a set

    A= {a, b, c, d, e}

    by reducing the problem to counting bit strings.

    Let’s find a bijection between the power set

    P (A) = {∅, {a}, {b}, . . .}

    and the set of bit stings of length 5:

    {0, 1}5 = {00000, 00001,00010, 00011, . . .}

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 37

    Bijection. Counting subsets

    Please, count the number of subsets of a set

    A= {a, b, c, d, e}

    by reducing the problem to counting bit strings.

    Let’s find a bijection f between the power set

    P (A) = {∅, {a}, {b}, . . .}

    and the set of bit stings of length 5:

    {0, 1}5 = {00000, 00001,00010, 00011, . . .}

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 38

    Bijection. Counting subsets

    f :P ({a, b, c, d, e})→ {0,1}5

    0s and 1s encode the membership of the five elements of{a, b, c, d, e}

    f :∅ 7→ 00000{a} 7→ 10000{b} 7→ 01000{a, b} 7→ 11000{c} 7→ 00100{a, c} 7→ 10100{b, c} 7→ 01100{a, b, c} 7→ 11100

    . . .skipping um.. 23 subsets

    {a, b, c, d, e} 7→ 11111

    The cardinality�

    �{0, 1}5�

    �= 25 = 32

    Therefore, by the bijectionrule,�

    �P (A)�

    �= 25

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 39

    Inclusion-Exclusion principle

    We remember the subtraction rule for the union of two sets

    |A∪ B|= |A|+ |B| − |A∩ B|

    Can it be generalized for a union of n sets

    |A1 ∪ . . .∪ An|= |A1|+ . . .+ |An| − 〈something〉?

    Of course, it can!

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 40

    Inclusion-Exclusion principle

    We remember the subtraction rule for the union of two sets

    |A∪ B|= |A|+ |B| − |A∩ B|

    Can it be generalized for a union of n sets

    |A1 ∪ . . .∪ An|= |A1|+ . . .+ |An| − 〈something〉?

    Of course, it can!

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 41

    Inclusion-Exclusion principle

    Union of three sets

    |A1 ∪ A2 ∪ A3|= |A1|+ |A2|+ |A3|− |A1 ∩ A2| − |A2 ∩ A3| − |A1 ∩ A3|+ |A1 ∩ A2 ∩ A3|

    |{1,2, 3} ∪ {2, 3,4} ∪ {3, 4,1}|= 3+ 3+ 3− 2− 2− 2+ 1= 4

  • Cartesian product

    Functions

    Bijection

    Inclusion-Exclusion

    p. 42

    Inclusion-Exclusion principle

    Union of n sets

    |A1 ∪ . . .∪ An|= the sum of the sizes of the individual setsminus the sizes of all two-way intersections

    plus the sizes of all three-way intersections

    minus the sizes of all four-way intersections

    plus the sizes of all five-way intersections

    etc.