Functions Definition & purpose Notation Functions on binary / returning binary values Finite automaton model We haven’t completely left the world of counting.

Slides:



Advertisements
Similar presentations
Section 4.1: The Basics of Counting As we have seen, one way to count the number of objects in a finite set S is to produce a one-to-one correspondence.
Advertisements

Copyright © Cengage Learning. All rights reserved. CHAPTER 1 SPEAKING MATHEMATICALLY SPEAKING MATHEMATICALLY.
Great Theoretical Ideas in Computer Science.
61 Nondeterminism and Nodeterministic Automata. 62 The computational machine models that we learned in the class are deterministic in the sense that the.
1 Undecidability Andreas Klappenecker [based on slides by Prof. Welch]
Discrete Structures Chapter 5 Relations and Functions Nurul Amelina Nasharuddin Multimedia Department.
Discrete Mathematics Lecture 7 Alexander Bukharovich New York University.
CSE115/ENGR160 Discrete Mathematics 02/22/11 Ming-Hsuan Yang UC Merced 1.
CSE115/ENGR160 Discrete Mathematics 02/21/12
CHAPTER 4 Decidability Contents Decidable Languages
1 Intro to Finite Automata Chapter 2 introduces the concept of a Finite Automata (or FA). An FA has several properties: It is theoretical. It allows computer.
COMS 3261, Lecture 2 Strings, Languages, Automata September 6, 2001.
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,
Copyright © Cengage Learning. All rights reserved.
1 Introduction to Computability Theory Lecture11: The Halting Problem Prof. Amos Israeli.
Cantor’s Legacy: Infinity And Diagonalization Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 25Apr 13, 2004Carnegie.
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, Sequences, and Sums
CS355 - Theory of Computation Lecture 2: Mathematical Preliminaries.
Sets Set Operations Functions. 1. Sets 1.1 Introduction and Notation 1.2 Cardinality 1.3 Power Set 1.4 Cartesian Products.
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
 Let A and B be any sets A binary relation R from A to B is a subset of AxB Given an ordered pair (x, y), x is related to y by R iff (x, y) is in R. This.
Lecture 03: Theory of Automata:08 Finite Automata.
Lecture 23: Finite State Machines with no Outputs Acceptors & Recognizers.
INTRODUCTION TO THE THEORY OF COMPUTATION INTRODUCTION MICHAEL SIPSER, SECOND EDITION 1.
DECIDABILITY OF PRESBURGER ARITHMETIC USING FINITE AUTOMATA Presented by : Shubha Jain Reference : Paper by Alexandre Boudet and Hubert Comon.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Week 7 - Friday.  What did we talk about last time?  Set disproofs  Russell’s paradox  Function basics.
An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered.
Lecture 07: Formal Methods in SE Finite Automata Lecture # 07 Qaisar Javaid Assistant Professor.
Copyright © 2010 Pearson Education, Inc. All rights reserved Sec
Chapter 2: Basic Structures: Sets, Functions, Sequences, and Sums (2)
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Copyright  The McGraw-Hill Companies, Inc. Permission required for reproduction.
Copyright © Cengage Learning. All rights reserved. CHAPTER 7 FUNCTIONS.
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
Functions Reading: Chapter 6 (94 – 107) from the text book 1.
Basic Structures: Sets, Functions, Sequences, and Sums CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Mathematical Notions and Terminology Lecture 2 Section 0.2 Fri, Aug 24, 2007.
Functions Section 2.3. Section Summary Definition of a Function. – Domain, Cdomain – Image, Preimage Injection, Surjection, Bijection Inverse Function.
MATH 224 – Discrete Mathematics
COMPSCI 102 Introduction to Discrete Mathematics.
Mathematical Preliminaries
Basic Structures: Sets, Functions, Sequences, and Sums.
Sets Definition: A set is an unordered collection of objects, called elements or members of the set. A set is said to contain its elements. We write a.
Great Theoretical Ideas in Computer Science.
Functions Discrete Structure. L62 Functions. Basic-Terms. DEF: A function f : A  B is given by a domain set A, a codomain set B, and a rule which for.
1 Melikyan/DM/Fall09 Discrete Mathematics Ch. 7 Functions Instructor: Hayk Melikyan Today we will review sections 7.3, 7.4 and 7.5.
Date: 1.2 Functions And Their Properties A relation is any set of ordered pairs. The set of all first components of the ordered pairs is called the domain.
Relations and Functions ORDERED PAIRS AND CARTESIAN PRODUCT An ordered pair consists of two elements, say a and b, in which one of them, say a is designated.
Functions CSRU1400 Spring 2008Ellen Zhang 1 CISC1400, Fall 2010 Ellen Zhang.
To Infinity And Beyond! CS Lecture 11 The Ideal Computer: no bound on amount of memory Whenever you run out of memory, the computer contacts the.
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 - Monday.  What did we talk about last time?  Properties of functions  One-to-one  Onto  Inverses  Cardinality.
Theory of Computation Automata Theory Dr. Ayman Srour.
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
Function Let be a mapping. If both A and B are sets of real numbers, we say that f is a function or, more precisely, a real function in one variable. When.
Function Hubert Chan (Chapter 2.1, 2.2) [O1 Abstract Concepts]
The Acceptance Problem for TMs
CS 461 – Nov. 2 Sets Prepare for ATM finite vs. infinite Infinite sets
Copyright © Cengage Learning. All rights reserved.
MATH 224 – Discrete Mathematics
Lecture12 The Halting Problem
Function Hubert Chan (Chapter 2.1, 2.2) [O1 Abstract Concepts]
Functions Defined on General Sets
Jaya Krishna, M.Tech, Assistant Professor
Discrete Structure II: Introduction
CS100: Discrete structures
Copyright © Cengage Learning. All rights reserved.
Counting Discrete Mathematics.
Presentation transcript:

Functions Definition & purpose Notation Functions on binary / returning binary values Finite automaton model We haven’t completely left the world of counting. Sometimes we wish to know how many functions / how many inputs …

Introduction Function: any procedure that takes input, produces output, and has exactly 1 possible output value for a given input. – Example: A vending machine takes money, and if the correct amount is entered, there is output. As the machine “runs” it must keep track of the money so it knows the instant that the right amount has been reached. The code directs the computation to make transitions from one state to another, depending on the input or result of some calculation. Alternate definition: set of ordered pairs (x, y) in which the x’s are not repeated.

continued Functions are not really a new concept to you… For each input value, we expect one output value. – If you run the same program on the same input data, you expect the same output. Notation – Name : domain  co-domain – For example: f : Z  Z – The domain is akin to the parameter type – The co-domain is the return type. – Don’t confuse co-domain with range. At a minimum, to specify a function, you need to give the domain and rule.

Examples Mathematical notationC/C++/Java notation square : Z  Z square(x) = x 2 int square(int x) { return x * x; } sum : Z  Z  Z sum (x, y) = x + y int sum(int x, int y) { return x + y; } pow : R  R  R pow(x, y) = x y double pow(double x, double y) { // implementation goes here // return a value of type double } Note the format of these definitions. Usual mathematical convention: Domain = set of all values where rule is defined. Co-domain = set of real numbers.

Defining a function Sometimes the domain needs to be restricted in some way. – If a function’s parameter type is int, does this mean that any integer value can be sent? – What should we do if not? Make sure your definition is “well formed.” – Each value in the input (domain) has exactly one output (range) drawn from the co-domain. “Not well formed” could mean: – f(x) is undefined for some x – f(x) is ambiguous for some x

Binary examples A Boolean function – Let B = { T, F } – f : B  B  B – f(x, y) = xy’ Parity bit – Let B = { 0, 1 } – parity : B 8  B 9 (or you could say parity : Z  Z) – Rule for parity: if x 7 + x 6 + … x 0 is even, then x 8 = 0 else x 8 = 1.

More about binary It turns out that in CS, many important functions are those on binary input (of arbitrary length) – And if the function returns true/false, we may wish to know which inputs make the function return true. Truth table is not feasible! Alphabet Σ = { 0, 1 } or { a, b }. Example – Let L = Σ 3  Σ 4 and let boolean = { true, false } – f : L  boolean – f(x) = x begins with 0 – Describe in your own words.

More examples A way to reverse a string – reverse : Σ*  Σ* – reverse(x) = the reversal of the bits of x The “equal” language – f : Σ*  boolean – f(x) = x has an equal number of 0’s and 1’s – For instance: f(ε) = true f(1) = false f(1010) = true – Can you give more examples of x where f(x) = true?

Counting them How many functions exist? Let D = domain, C = co-domain Each value in the domain can choose 1 value in co- domain. In other words, it has |C| choices. Number of functions is |C| |D|. Special case: C and D are the same set, or just the same size, n elements: Then, the number of functions is n n. Invertible function: each value in range has to be different. Then, the number of functions is n!.

Finite automata Automata is plural; automaton is singular Also called a finite state machine, or just FA Very common type of function used in CS, of the form Σ*  boolean When an FA is given input, it can’t immediately determine whether to determine true/false. So we must have various states and transitions to assist in the computation. We can specify an FA by either – A drawing – A state table

Example Start state Accept/happy state(s) – If we are in one of these when input is done, we accept string. Transitions “finite” refers to # of states. More on limitations later. s1 s2 1 0, 1 0

Example The FA could also be expressed in a table. The table tells us where to go on each possible input bit. FromInput 0 Input 1 s1s2s1 s2 s1 s2 1 0, 1 0

Example Let’s try sample input like 101. Can you figure out the language of this machine? – i.e. How do we get to the happy state? s1 s2 1 0, 1 0

More FA’s Finite automata: functions on a binary string that return boolean – Determine behavior of given FA – Draw our own FA that recognizes some type of input (e.g. even number of 0’s) Properties of functions – One-to-one – Onto – Counting question: how many functions are there?

Example #2 What is language of this FA? Note: if we change which state is the accept state, we’d have a different language! Inverting accept & nonaccept states gives us the opposite language. s1s2 s , 1 1

What languages? AB C , 1 AC D B

Practice with FA’s Goals: – Drawing of FA  figure out its language – Language description  draw corresponding FA FA’s are good when conceptualizing how to read a program’s input. For example, the format of a floating-point number. – States: “need sign”, “need digit”, “need point”, “need digit”, “happy” Note: if a transition you need is not specified by an FA, we say that it “crashes” – immediately rejects. When done reading input, see if in happy state.

Draw our own Anything beginning with 01 – States: “need 01”, “need 1”, “dead”, “happy” Begin with 0, contains an odd number of 1’s – States: “need 0 & odd 1’s”, “even 1’s”, “dead”, “happy” Don’t forget to finish putting 0/1 transitions on all states. Be sure to identify the start state.

Function properties Sometimes a (mathematical) function has a special property – One-to-one – Onto For a function to be a reversible process, both these properties must hold. – Useful in cryptography – Decompiling a program where you have lost the source code. – The “undo” button!

Definitions One-to-one: All values in the range are unique. – For all a, b in the domain, f(a) = f(b)  a = b – No value in co-domain has 2+ arrows pointing to it. – “horizontal line test” – Consider negation: there exist distinct a, b in domain for which: f(a) = f(b). Onto: All values in the co-domain are achieved. – For all y in co-domain, there is an x in the domain such that f(x) = y. – Every value in co-domain has arrow(s) pointing to it. – For a real number function, the graph goes vertically up to +  and down to – . – Consider negation: there exists y in co-domain such that for all x in domain, f(x)  y.

Example Define f: Z  Z with the rule f(x) = 4x + 3. Is f one-to-one? For all a and b, f(a) = f(b) should imply a=b. 4a + 3 = 4b + 3 a = bYes! Is f onto? For all y, there is an x such that f(x) = y. In other words, we can always solve for x. y = 4x + 3 x = (y – 3)/4Not necessarily true for integers! What would be a good counterexample?

Notes To be 1-1, |domain|  |co-domain| – For example, we can define the function y = 3x with domain and co-domain as { 1, 2, 3 }  { 3, 4, 5, 6, 7, 8, 9 } To be onto, |domain|  |co-domain| – For example, consider y = x mod 2 for the domain and co- domain: { 1, 2, 3, 4 }  { 0, 1 }

Classify For the following real-number functions, determine whether each is 1-1 or onto or both. 1.y = x 3 2.y = x 3 – x 3.y = sqrt(x) 4.y = x 2 5.Integer function: y = 2x Integer function: y = x mod 5 – How can we restrict this function so that it is 1-1 and onto?

Counting functions Given sizes of domain and co-domain: let’s say they are d and c, respectively. How many 1-1 functions? – For each value in domain, determine how many possible values in co-domain are eligible as the functional value. – We have c choices for first value in D, c – 1 values for second value, c – 2 for third, etc. – Total is P(c, d). How many onto functions? …

# Onto functions A more difficult question than for 1-1. Note: Typically the domain is larger than co-domain. Example |domain| = 4 and |co-domain| = 2 – i.e. How many onto functions { 1, 2, 3, 4 }  { a, b } – Without restrictions: each value 1-4 has 2 choices of a functional value, so total # functions is 2 4. – But, need to subtract out the functions that are NOT onto. This means functions that assign only to a or only to b. There are 2 of these. – Total onto functions = 16 – 2 = 14.

Larger case To motivate a more general solution, consider a larger case: |domain| = 5 and |co-domain| = 3. – { 1, 2, 3, 4, 5 }  { a, b, c } – Total # functions is 3 5. – Need to subtract out functions that only assign to 2 of the 3 values. One of the 3 values is excluded – we choose which one in 3 ways. How many functions assign 5 domain values to just 2 co-domain values? That’s 2 5. Thus, we need to subtract out 3 * 2 5. – *** We should also subtract out functions that assign to just 1 of the 3 values. Already handled. In fact, we overdid it! Need to add back functions that assign to 1 value. –  This turns into a “nested” inclusion/exclusion problem!

General formula If the domain has D elements and co-domain has C elements, how many onto functions? (D  C) – Total functions: Each of the C values can be mapped to from any of the D values: C D – Take out cases where not all C values are used. How many functions assign to just C – 1? (C – 1) D, but we also have to choose which C is omitted: C * (C – 1) D – Add back cases where C – 2 values are assigned to. Choose which 2 to omit: C(C, 2) * (C – 2) D – And so on, and we obtain C D – C * (C – 1) D + C(C, 2) * (C – 2) D – C(C, 3) * (C – 3) D + …

Finite/infinite Finite set – means that its elements can be numbered. Formally: its elements can be put into a 1-1 correspondence with the sequence 1, 2, 3, … n, where n is some positive integer. An infinite set is one that’s not finite. However, there are 2 kinds of infinity!

Countable Countable set: An infinite set whose elements can be put into a 1-1 correspondence with the positive integers. – Examples we can show are countable: Even numbers, all integers, rational numbers, ordered pairs. Uncountable set = ∞ set that’s not countable. – Examples we can show are uncountable: Real numbers, functions of integers, infinite-length strings

Examples The set of even numbers is countable. The set of integers is countable … … …

Ordered pairs j = 1j = 2j = 3j = 4 i = 11247… i = 2358… i = 369… i = 410… … The number assigned to (i, j) is (i + j – 1)*(i + j – 2)/2 + i

Real numbers Suppose real numbers were countable. The numbering might go something like this: The problem is that we can create a value that has no place in the correspondence! Real #Value … … … … …… X ? …

Infinite bit strings #Value … … … … … … ?11010…