380 likes | 509 Vues
In this week's lecture for CS322, we explored the fundamental concepts of functions, including their definitions, properties, and applications. We discussed disproofs using Russell's paradox, the basics of functions mapping between sets, and the importance of well-defined functions. Key examples included the Hamming distance and the concept of one-to-one and onto functions. We also practiced logical problems involving mixing liquids and analyzing function definitions with various mathematical scenarios. Join us in our deeper understanding of functions and their significance in computer science.
E N D
Week 7 - Friday CS322
Last time • What did we talk about last time? • Set disproofs • Russell’s paradox • Function basics
Logical warmup • A man has two 10 gallon jars • The first contains 6 gallons of wine and the second contains 6 gallons of water • He poured 3 gallons of wine into the water jar and stirred • Then he poured 3 gallons of the mixture in the water jar into the wine jar and stirred • Then he poured 3 gallons of the mixture in the wine jar into the water jar and stirred • He continued the process until both jars had the same concentration of wine • How many pouring operations did he do?
Definitions • A function f from set X to set Y is a relation between elements of X (inputs) and elements of Y (outputs) such that each input is related to exactly one output • We write f: X Y to indicate this • X is called the domain of f • Y is called the co-domain of f • The range of f is { y Y | y = f(x), for some x X} • The inverse image of y is { x X | f(x) = y }
Examples • Using standard assumptions, consider f(x) = x2 • What is the domain? • What is the co-domain? • What is the range? • What is f(3.2)? • What is the inverse image of 4? • Assume that the set of positive integers is the domain and co-domain • What is the range? • What is f(3.2)? • What is the inverse image of 4?
Arrow diagrams • With finite domains and co-domains, we can define a function using an arrow diagram • What is the domain? • What is the co-domain? • What are f(a), f(b), and f(c)? • What is the range? • What are the inverse images of 1, 2, 3, and 4? • Represent f as a set of ordered pairs X f Y 1 2 3 4 a b c
Functions? • Which of the following are functions from X to Y? X f Y 1 2 3 4 a b c X g Y X h Y 1 2 3 4 1 2 3 4 a b c a b c
Function equality • Given two functions f and g from X to Y, • f equals g, written f = g, iff: • f(x) = g(x) for all xX • Let f(x) = |x| and g(x) = • Does f = g? • Let f(x) = x and g(x) = 1/(1/x) • Does f = g?
Applicability of functions • Functions can be defined from any well-defined set to any other • There is an identity function from any set to itself • We can represent a sequence as a function from a range of integers to the values of the sequence • We can create a function mapping from sets to integers, for example, giving the cardinality of certain sets
Logarithms • You should know this already • But, this is the official place where it should be covered formally • There is a function called the logarithm with base b of x defined from R+ - {1}to R as follows: • logbx = y by = x
Functions defined on Cartesian products • For a function of multiple values, we can define its domain to be the Cartesian product of sets • Let Sn be strings of 1's and 0's of length n • An important CS concept is Hamming distance • Hamming distance takes two binary strings of length n and gives the number of places where they differ • Let Hamming distance be H: Sn x Sn Znonneg • What is H(00101, 01110)? • What is H(10001, 01111)?
Well-defined functions • There are two ways in which a function can be poorly defined • It does not provide a mapping for every value in the domain • Example: f: R R such that f(x) = 1/x • It provides more than one mapping for some value in the domain • Example: f: Q Z such that f(m/n) = m, where m and n are the integers representing the rational number
One-to-one functions • Let F be a function from X to Y • F is one-to-one (or injective) if and only if: • If F(x1) = F(x2) then x1 = x2 • Is f(x) = x2 from Z to Z one-to-one? • Is f(x) = x2 from Z+ to Z one-to-one? • Is h(x) one-to-one? X h Y 1 2 3 4 a b c
Proving one-to-one • To prove that f from X to Y is one-to-one, prove that x1, x2 X, f(x1) = f(x2) x1 = x2 • To disprove, just find a counter example • Prove that f: R R defined by f(x) = 4x – 1 is one-to-one • Prove that g: Z Z defined by g(n) = n2 is not one-to-one
Onto functions • Let F be a function from X to Y • F is onto (or surjective) if and only if: • y Y, x X such that F(x) = y • Is f(x) = x2 from Z to Z onto? • Is f(x) = x2 from R+ to R+ onto? • Is h(x) onto? X h Y 1 2 3 a b c
Inverse functions • If a function F: X Yis both one-to-one and onto (bijective), then there is an inverse function F-1: Y X such that: • F-1(y) = x F(x) = y, for all x X and y Y
Composition of functions • If there are two functions f: A B and g: Y Z such that the range of f is a subset of the domain of g, we can define a new function g o f: A Z such that • (g o f)(x) = g(f(x)), for all x A
Finite sets • As before, we can show these functions for finite sets using arrow diagrams • What's the arrow diagram for (g o f)(x)? g f e a b c d 1 2 3 x y z
Identity function • The identity function (on set X) maps elements from set X to themselves • Thus, the identity function ix: X X is: • iX(x) = x • For functions f: X Y and g: Y X • What is (f o iX)(x)? • What is (iX 0 g)(x)?
One-to-one and onto • If functions f: X Y and g: Y Z are both one-to-one, then g o f is one-to-one • If functions f: X Y and g: Y Z are both onto, then g o f is onto • How would you go about proving these claims?
Inverses • If f: X Y is one-to-one and onto with inverse function f-1: Y X, then • What is f-1 o f? • What is f o f-1?
Pigeonhole Principle Student Lecture
Pigeonhole principle • If n pigeons fly into m pigeonholes, where n > m, then there is at least one pigeonhole with two or more pigeons in it • More formally, if a function has a larger domain than co-domain, it cannot be one-to-one • We cannot say exactly how many pigeons are in any given holes • Some holes may be empty • But, at least one hole will have at least two pigeons
Pigeonhole examples • A sock drawer has white socks, black socks, and red argyle socks, all mixed together, • What is the smallest number of socks you need to pull out to be guaranteed a matching pair? • Let A = {1, 2, 3, 4, 5, 6, 7, 8} • If you select five distinct elements from A, must it be the case that some pair of integers from the five you selected will sum to 9?
Generalized pigeonhole principle • If n pigeons fly into m pigeonholes, and for some positive integer k, n> km, then at least one pigeonhole contains k + 1 or more pigeons in it • Example: • In a group of 85 people, at least 4 must have the same last initial
Cardinality • Cardinality gives the number of things in a set • Cardinality is: • Reflexive:A has the same cardinality as A • Symmetric: If A has the same cardinality as B, B has the same cardinality as A • Transitive: If A has the same cardinality as B, and B has the same cardinality as C, A has the same cardinality as C • For finite sets, we could just count the things to determine if two sets have the same cardinality
Cardinality for infinite sets • Because we can't just count the number of things in infinite sets, we need a more general definition • For any sets A and B, A has the same cardinality as Biff there is a bijective mapping A to B • Thus, for any element in A, it corresponds to exactly one element in B, and everything in B has exactly one corresponding element in A
Cardinality example • Show that the set of positive integers has the same cardinality as the set of all integers • Hint: Create a bijective function from all integers to positive integers • Hint 2: Map the positive integers to even integers and the negative integers to odd integers
Countability • A set is called countably infinite if it has the same cardinality as Z+ • You have just shown that Z is countable • It turns out that (positive) rational numbers are countable too, because we can construct a table of their values and move diagonally across it, numbering values, skipping numbers that have been listed already
Uncountability • We showed that positive rational numbers were countable, but a trick similar to the one for integers can show that all rational numbers are countable • The book gives a classic proof that real numbers are not countable, but we don't have time to go through it • For future reference, the cardinality of positive integers, countable infinity, is named 0 (pronounced aleph null) • The cardinality of real numbers, the first uncountable infinity (because there are infinitely many uncountable infinities), is named 1 (pronounced aleph 1)
Next time… • Relations (after Spring Break) • Exam 2 is the Monday after the Monday after Spring Break
Reminders • Work on Homework 5 • Due on Monday after Spring Break • Look at Homework 6 • Read Chapter 8 for after Spring Break