Functions and Relations

Similar documents
Functions. Def. Let A and B be sets. A function f from A to B is an assignment of exactly one element of B to each element of A.

Relations and Graphs

2/18/14. Uses for Discrete Math in Computer Science. What is discrete? Why Study Discrete Math? Sets and Functions (Rosen, Sections 2.1,2.2, 2.

Situation 3. Parentheses vs. Brackets. Colleen Foy

Sets MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Sets Fall / 31

What Is A Relation? Example. is a relation from A to B.

2.3: FUNCTIONS. abs( x)

1.1 - Functions, Domain, and Range

Functions. How is this definition written in symbolic logic notation?

Using APIs. Chapter 3. Outline Fields Overall Layout. Java By Abstraction Chapter 3. Field Summary static double PI

9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS

Learning Log Title: CHAPTER 3: PORTIONS AND INTEGERS. Date: Lesson: Chapter 3: Portions and Integers

Mini-Project 1: The Library of Functions and Piecewise-Defined Functions

W13:Homework:H07. CS40 Foundations of Computer Science W13. From 40wiki

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

2.4 Multiplication and Division of Integers

Func%ons (Math) Func%on Defini%ons. Func%ons (Computer Sciences) Func%on = mappings or transforma%ons Math examples:

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #28. Functions: Examples 2

A set with only one member is called a SINGLETON. A set with no members is called the EMPTY SET or 2 N

1. Variables 2. Arithmetic 3. Input and output 4. Problem solving: first do it by hand 5. Strings 6. Chapter summary

Name: Date: Review Packet: Unit 1 The Number System

Functions 2/1/2017. Exercises. Exercises. Exercises. and the following mathematical appetizer is about. Functions. Functions

Chapter 4 Defining Classes I

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Name Course Days/Start Time

3. Determine whether f is a function from the set of all bit strings to the set of integers if

Lecture 5: Methods CS2301

Slides for Faculty Oxford University Press All rights reserved.

CS-201 Introduction to Programming with Java

CS 1200 Discrete Math Math Preliminaries. A.R. Hurson 323 CS Building, Missouri S&T

Defining Functions. CSc 372. Comparative Programming Languages. 5 : Haskell Function Definitions. Department of Computer Science University of Arizona

Math 202 Test Problem Solving, Sets, and Whole Numbers 19 September, 2008

Math Analysis Chapter 1 Notes: Functions and Graphs

Square roots: We say that the square root of 16 is 4. We write this as 16 4.

Comparing sizes of sets

Introduction to C++ Part II. Søren Debois. Department of Theoretical Computer Science IT University of Copenhagen. September 12th, 2005

CS2383 Programming Assignment 3

An introduction to Java II

Sets. Sets. Examples. 5 2 {2, 3, 5} 2, 3 2 {2, 3, 5} 1 /2 {2, 3, 5}

Figure 1.1: This is an illustration of a generic set and its elements.

S.W.B.A.T: Identify the independent and dependent variable in sentence. Write a function rule for a table and a situation.

Math Analysis Chapter 1 Notes: Functions and Graphs

!"!!!"!!"!! = 10!!!!!(!!) = 10! = 1,000,000

Section Graphs and Lines

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Module 10. Recursion. Adapted from Absolute Java, Rose Williams, Binghamton University

Java Review. Fundamentals of Computer Science

Some inequality statements contain 2 inequalities with an and or an or between them. We call these type of inequalities compound inequalities.

2. Functions, sets, countability and uncountability. Let A, B be sets (often, in this module, subsets of R).

2.Simplification & Approximation

THE EVALUATION OF OPERANDS AND ITS PROBLEMS IN C++

Binary Search. Roland Backhouse February 5th, 2001

MATH 22 MORE ABOUT FUNCTIONS. Lecture M: 10/14/2003. Form follows function. Louis Henri Sullivan

APCS Semester #1 Final Exam Practice Problems

2.1 Basics of Functions and Their Graphs

But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15

CCNY Math Review Chapter 2: Functions

Multiply Decimals Multiply # s, Ignore Decimals, Count # of Decimals, Place in Product from right counting in to left

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Calculating Cardinalities

CS1150 Principles of Computer Science Methods

Functions and Sequences Rosen, Secs. 2.3, 2.4

Lesson 12: The Graph of the Equation y = f(x)

Integers and Rational Numbers

MAT 003 Brian Killough s Instructor Notes Saint Leo University

These are square roots, cube roots, etc. Intermediate algebra Class notes Radicals and Radical Functions (section 10.1)

Conformance. Object-Oriented Programming Spring 2015

Graphing by. Points. The. Plotting Points. Line by the Plotting Points Method. So let s try this (-2, -4) (0, 2) (2, 8) many points do I.

Basic Types & User Defined Types

VARIABLES AND TYPES CITS1001

Divisibility Rules and Their Explanations

Object Orientated Analysis and Design. Benjamin Kenwright

Note: The last command (10-5) will generate an error message. Can you see why the calculator is having difficulty deciphering the command?

Learning Log Title: CHAPTER 2: FRACTIONS AND INTEGER ADDITION. Date: Lesson: Chapter 2: Fractions and Integer Addition

Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6

Object Oriented Methods : Deeper Look Lecture Three

6/4/12. Recursive void Methods. Chapter 11. Vertical Numbers. Vertical Numbers. Vertical Numbers. Algorithm for Vertical Numbers

More on Classes. The job of this method is to return a String representation of the object. Here is the tostring method from the Time class:

The Language of Sets and Functions

COMP 250 Winter 2011 Reading: Java background January 5, 2011

Python: Functions. Thomas Schwarz, SJ Marquette University

Denotational Semantics. Domain Theory

1.1: Basic Functions and Translations

Gateway Regional School District VERTICAL ALIGNMENT OF MATHEMATICS STANDARDS Grades 3-6

Unit 4: Client View of a Component Methods

COMS 1003 Fall Introduction to Computer Programming in C. Bits, Boolean Logic & Discrete Math. September 13 th

COMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.

Piecewise Defined Functions

. p.1/23. Today. 1. Questions and discussion from lecture. 2. Type-checking Functions Arrays Records (maybe)

Repetition Structures

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

CS313D: ADVANCED PROGRAMMING LANGUAGE

Inequalities and you 3

CSE 105 THEORY OF COMPUTATION

36 Modular Arithmetic

Today s Topics. What is a set?

Rational Numbers: Multiply and Divide

COMP 250 Fall inheritance Nov. 17, 2017

Transcription:

s and Relations Definitions and Examples E. Wenderholm Department of Computer Science SUNY Oswego c 2016 Elaine Wenderholm All rights Reserved E. Wenderholm s and Relations

Outline 1 Java Methods Method Overloading 2 A is a Mapping E. Wenderholm s and Relations

s Java Methods Java Methods Method Overloading We define and use Java methods to perform some operation. Methods are a handy way to group together a sequence of statements to be used over and over again. E. Wenderholm s and Relations

s Java Methods Java Methods Method Overloading We define and use Java methods to perform some operation. Methods are a handy way to group together a sequence of statements to be used over and over again. The signature of a Java method consists of the: method name The (ordered) sequence of its input parameter types. The return type and thrown Exceptions are not part of the signature. E. Wenderholm s and Relations

Method Overloading Different Signatures Java Methods Method Overloading What is method overloading? Two methods of the same name but with different input parameters. E. Wenderholm s and Relations

Method Overloading Different Signatures Java Methods Method Overloading What is method overloading? Two methods of the same name but with different input parameters. The return type is not part of the signature. That s why trying to overload a method by changing only it s return type causes a compile error. E. Wenderholm s and Relations

Method Signatures Set Theory Explanation Java Methods Method Overloading Example: method m name <visibility> <return type> m name(t 1 p 1,..., T n p n ) Remember - visibility and return type are not part of a signature. E. Wenderholm s and Relations

Method Signatures Set Theory Explanation Java Methods Method Overloading Example: method m name <visibility> <return type> m name(t 1 p 1,..., T n p n ) Remember - visibility and return type are not part of a signature. To define m name in math notation we would write m name: T 1... T n return type Here we use return type. E. Wenderholm s and Relations

Method Signatures Set Theory Explanation Java Methods Method Overloading Example: method m name <visibility> <return type> m name(t 1 p 1,..., T n p n ) Remember - visibility and return type are not part of a signature. To define m name in math notation we would write m name: T 1... T n return type Here we use return type. Both these notations say the same thing: The function (method) has n input parameters of types T 1,..., T n. The function (method) returns an element of type <return type> E. Wenderholm s and Relations

s in Math A Mapping A is a Mapping Let s look at a function definition using math notation. m name : T 1... T n return type E. Wenderholm s and Relations

s in Math A Mapping A is a Mapping Let s look at a function definition using math notation. m name : T 1... T n return type Think of the types T i as sets. E. Wenderholm s and Relations

s in Math A Mapping A is a Mapping Let s look at a function definition using math notation. m name : T 1... T n return type Think of the types T i as sets. The set of all inputs T 1... T n is the Cartesian product of the sets. E. Wenderholm s and Relations

s in Math A Mapping A is a Mapping Let s look at a function definition using math notation. m name : T 1... T n return type Think of the types T i as sets. The set of all inputs T 1... T n is the Cartesian product of the sets. This says passing any n-tuple of elements (e 1 T 1,..., e n T n ) to the function (method) m name will return an element e T return type. E. Wenderholm s and Relations

s Drawn as a Picture A is a Mapping Let s keep this simple. Say we have a function that has one input argument of type A, and returns an element of type B. E. Wenderholm s and Relations

s Drawn as a Picture A is a Mapping Let s keep this simple. Say we have a function that has one input argument of type A, and returns an element of type B. B f(a a); (Java notation) f : A B (math notation) The math notation is typically drawn as a picture. A f B f: A > B A is the domain of f B is the codomain of f E. Wenderholm s and Relations

A is a Mapping Consider f : A B The domain of f is the set A. The codomain of f is the set B. E. Wenderholm s and Relations

A is a Mapping Consider f : A B The domain of f is the set A. The codomain of f is the set B. The range of f is the (subset) of B that f actually maps to. E. Wenderholm s and Relations

A is a Mapping Consider f : A B The domain of f is the set A. The codomain of f is the set B. The range of f is the (subset) of B that f actually maps to. The range of f is R B = {y f (x) = y, x A} E. Wenderholm s and Relations

Example A is a Mapping abs maps an int to it s absolute value abs: Z > Z domain(abs) = Z codomain(abs) = Z BUT abs only returns positive ints! Z abs Z Z+ The range of abs is the set of values returned by the function abs. range(abs) = {y abs(x) = y, x in Z} = Z+ E. Wenderholm s and Relations

Example A is a Mapping abs maps an int to it s absolute value abs: Z > Z domain(abs) = Z codomain(abs) = Z BUT abs only returns positive ints! Z abs Z Z+ The range of abs is the set of values returned by the function abs. abs maps all integers Z into only the positive integers Z+. The negative integers get left out. Even though the codomain is Z, the range is the positive integers - a subset of Z range(abs) = {y abs(x) = y, x in Z} = Z+ E. Wenderholm s and Relations

Codomain vs Range A is a Mapping The difference between codomain and range becomes painful. Sipser defines the Range as I ve defined the Codomain. I told you it s painful. abs maps an int to it s absolute value abs: Z > Z domain(abs) = Z codomain(abs) = Z BUT abs only returns positive ints! Why might you care? Z abs Z Z+ The range of abs is the set of values returned by the function abs. range(abs) = {y abs(x) = y, x in Z} = Z+ E. Wenderholm s and Relations

Codomain vs Range A is a Mapping The difference between codomain and range becomes painful. Sipser defines the Range as I ve defined the Codomain. I told you it s painful. abs maps an int to it s absolute value abs: Z > Z domain(abs) = Z codomain(abs) = Z BUT abs only returns positive ints! Why might you care? Z abs Z Z+ The range of abs is the set of values returned by the function abs. range(abs) = {y abs(x) = y, x in Z} = Z+ E. Wenderholm s and Relations

Codomain vs Range A is a Mapping The difference between codomain and range becomes painful. Sipser defines the Range as I ve defined the Codomain. I told you it s painful. abs maps an int to it s absolute value abs: Z > Z domain(abs) = Z codomain(abs) = Z BUT abs only returns positive ints! Z abs Z Z+ Why might you care? You will need to in MAT 215. The range of abs is the set of values returned by the function abs. range(abs) = {y abs(x) = y, x in Z} = Z+ E. Wenderholm s and Relations

Codomain vs Range A is a Mapping The difference between codomain and range becomes painful. Sipser defines the Range as I ve defined the Codomain. I told you it s painful. abs maps an int to it s absolute value abs: Z > Z domain(abs) = Z codomain(abs) = Z BUT abs only returns positive ints! Why might you care? Z abs Z Z+ I will make the distinction. The range of abs is the set of values returned by the function abs. range(abs) = {y abs(x) = y, x in Z} = Z+ E. Wenderholm s and Relations

s Just a few more Definitions A is a Mapping Let s use a simple function f : A B as an example. f is a total function provided every element a A is mapped by f to an element f (a) = b B. E. Wenderholm s and Relations

s Just a few more Definitions A is a Mapping Let s use a simple function f : A B as an example. f is a total function provided every element a A is mapped by f to an element f (a) = b B. Integer addition is total. E. Wenderholm s and Relations

s Just a few more Definitions A is a Mapping Let s use a simple function f : A B as an example. f is a total function provided every element a A is mapped by f to an element f (a) = b B. Integer addition is total. f is a partial function if there is at least one element a A in which f (a) is undefined. E. Wenderholm s and Relations

s Just a few more Definitions A is a Mapping Let s use a simple function f : A B as an example. f is a total function provided every element a A is mapped by f to an element f (a) = b B. Integer addition is total. f is a partial function if there is at least one element a A in which f (a) is undefined. Example: integer divide is undefined whenever the denominator is zero. E. Wenderholm s and Relations

s Just a few more Definitions A is a Mapping Let s use a simple function f : A B as an example. f is a total function provided every element a A is mapped by f to an element f (a) = b B. Integer addition is total. f is a partial function if there is at least one element a A in which f (a) is undefined. Example: integer divide is undefined whenever the denominator is zero. f is onto whenever the range(f ) = codomain(f ). E. Wenderholm s and Relations

s Just a few more Definitions A is a Mapping Let s use a simple function f : A B as an example. f is a total function provided every element a A is mapped by f to an element f (a) = b B. Integer addition is total. f is a partial function if there is at least one element a A in which f (a) is undefined. Example: integer divide is undefined whenever the denominator is zero. f is onto whenever the range(f ) = codomain(f ). Example: Absolute value is not onto; increment is onto. E. Wenderholm s and Relations

s Just a few more Definitions A is a Mapping Let s use a simple function f : A B as an example. f is a total function provided every element a A is mapped by f to an element f (a) = b B. Integer addition is total. f is a partial function if there is at least one element a A in which f (a) is undefined. Example: integer divide is undefined whenever the denominator is zero. f is onto whenever the range(f ) = codomain(f ). Example: Absolute value is not onto; increment is onto. f is one-to-one if every element a A is mapped to a unique element in B. E. Wenderholm s and Relations

s Just a few more Definitions A is a Mapping Let s use a simple function f : A B as an example. f is a total function provided every element a A is mapped by f to an element f (a) = b B. Integer addition is total. f is a partial function if there is at least one element a A in which f (a) is undefined. Example: integer divide is undefined whenever the denominator is zero. f is onto whenever the range(f ) = codomain(f ). Example: Absolute value is not onto; increment is onto. f is one-to-one if every element a A is mapped to a unique element in B. Example: Increment is one-to-one. E. Wenderholm s and Relations

s Just a few more Definitions A is a Mapping Let s use a simple function f : A B as an example. f is a total function provided every element a A is mapped by f to an element f (a) = b B. Integer addition is total. f is a partial function if there is at least one element a A in which f (a) is undefined. Example: integer divide is undefined whenever the denominator is zero. f is onto whenever the range(f ) = codomain(f ). Example: Absolute value is not onto; increment is onto. f is one-to-one if every element a A is mapped to a unique element in B. Example: Increment is one-to-one. f has an inverse provided it is one-to-one and onto. Why dwell on this? We will be analyzing and defining functions, and we will need to be sure they are total. E. Wenderholm s and Relations