200 likes | 472 Views
Discrete Mathematics Lecture 7. Alexander Bukharovich New York University. Generic Functions. A function f: X Y is a relationship between elements of X to elements of Y, when each element from X is related to a unique element from Y
E N D
Discrete MathematicsLecture 7 Alexander Bukharovich New York University
Generic Functions • A function f: X Y is a relationship between elements of X to elements of Y, when each element from X is related to a unique element from Y • X is called domain of f, range of f is a subset of Y so that for each element y of this subset there exists an element x from X such that y = f(x) • Sample functions: • f : R R, f(x) = x2 • f : Z Z, f(x) = x + 1 • f : Q Z, f(x) = 2
Generic Functions • Arrow diagrams for functions • Non-functions • Equality of functions: • f(x) = |x| and g(x) = sqrt(x2) • Identity function • Sequences as functions • Functions with a domain of some language • Logarithmic function
Generic Functions • Encoding and decoding of characters • Hamming distance function: number of differences between two encodings • Boolean functions: f : {0, 1}n {0, 1} • Well-defined functions • Euler function: (n) is the number of positive integers less than n, which are mutually prime with n
Exercises • Show that if p is a prime number, then (pn) = pn – pn-1 • Prove that there infinitely many integers for which Euler’s function is a perfect square • Show that (pq) = (p-1) (q-1) if p and q are distinct primes • Determine which of the following is true: • if A B, then f(A) f(B) • f(A B) = f(A) f(B) • f(A B) = f(A) f(B) • f(A - B) = f(A) - f(B)
Finite-State Automata (FSA) • Finite-state automata A is defined by 5 objects: • Set I of the input alphabet • Set S of automaton states • Designated initial state s0 from S • Designated set of accepted states from S • Next-state function N: S I S that associates next state to the pair {current state, input symbol} • Descriptions of finite-state automaton: • State-transition diagram • Next-state table
FSA by Transition Diagram 1 1 s0 s1 0 s2 0 0 1
FSA and Languages • Let A be an FSA with an input alphabet I. The set of all strings w from I* such that A goes to accepting state on w is called a language accepted by A: L(A) • Eventual state-function N* : S I* S is a function that maps a pair {state, input string} to the state to which FSA would lead from the original state given the symbols in the input string as an input.
Designing FSA • Design an FSA that accepts all strings of 0’s and 1’s such that the number of 1’s is divisible by 3 • Design an FSA that accepts the set of strings that contain exactly one 1 • Design an FSA with alphabet {a, b} which accepts strings that end on the same two characters • Simulating an FSA using software
One-to-One Functions • Function f : X Y is called one-to-one (injective) when for all elements x1 and x2 from X if f(x1) = f(x2), then x1 = x2 • Determine whether the following functions are one-to-one: • f : R R, f(x) = 4x – 1 • g : Z Z, g(n) = n2 • Hash functions
Onto Functions • Function f : X Y is called onto (surjective) when given any element y from Y, there exists x in X so that f(x) = y • Determine whether the following functions are onto: • f : R R, f(x) = 4x – 1 • f : Z Z, g(n) = 4n – 1 • Bijection is one-to-one and onto • Reversing strings function is bijective
Inverse Functions • If f : X Y is a bijective function, then it is possible to define an inverse function f-1: Y X so that f-1(y) = x whenever f(x) = y • Find an inverse for the following functions: • String-reverse function • f : R R, f(x) = 4x – 1 • Inverse function of a bijective function is a bijective function itself
Exercises • Let cm,n be the number of onto functions from a set of m elements to a set of n elements. Find a relationship between cm,n, cm-1,n and cm-1,n-1 • Let F: Z Z Z and G: Z Z Z, F(n, m) = 3n6m and G(n, m) = 3n5m. Is F one-to-one, is G one-to-one?
Pigeonhole Principle • If n pigeons fly into m pigeonholes and n > m, then at least one hole must contain two or more pigeons • A function from one finite set to a smaller finite set cannot be one-to-one • In a group of 13 people must there be at least two who have birthday in the same month? • A drawer contains 10 black and 10 white socks. How many socks need to be picked to ensure that a pair is found? • Let A = {1, 2, 3, 4, 5, 6, 7, 8}. If 5 integers are selected must at least one pair have sum of 9?
Pigeonhole Principle • There is no FSA that accepts the following language: L = {s = akbk, for positive k} • Generalized Pigeonhole Principle: For any function f : X Y acting on finite sets, if n(X) > k * N(Y), then there exists some y from Y so that there are at least k + 1 distinct x’s so that f(x) = y • There are 42 students who are to share 12 computers. Each student uses exactly 1 computer and no computer is used by more than 6 students. Show that at least 5 computers are used by 3 or more students.
Exercises • Let f : X Y and n(X) = n(Y), then f is bijective iff f is surjective • Let A be a set of 6 integers less than 13. Show that there must be two disjoint subsets of A whose sum of elements adds up to the same number • Given 52 distinct integers, show that there must be two whose sum or difference is divisible by 100 • Show that if 101 integers are chosen from 1 to 200 inclusive, there must be two with the property that one is divisible by the other • Suppose a1, a2, …, an is a sequence of n integers none of which is divisible by n. Show that at least one difference ai – aj is divisible by n
Composition of Functions • Let f : X Y and g : Y Z, let range of f be a subset of the domain of g. The we can define a composition of g o f : X Z • Let f,g : Z Z, f(n) = n + 1, g(n) = n2. Find f o g and g o f. • Composition with identity function • Composition with an inverse function • Composition of two one-to-one functions is one-to-one • Composition of two onto functions is onto
Cardinality • Cardinality refers to the size of the set • Finite and infinite sets • Two sets have the same cardinality when there is bijective function associating them • Cardinality is is reflexive, symmetric and transitive • Countable sets: set of all integers, set of even numbers • Set of real numbers • Computability of functions
Exercises • Show that the set of irrational numbers is dense • Show that a power set has always a greater cardinality than the original set