Functions

https://slides.com/georgelee/ics141-sets-functions/live

Algebraic Laws of Sets

Set Identities

  • Table 1 on page 130
  • Identity
  • Domination
  • Idempotent
  • Complementation
  • Associative
  • Distributive
  • De Morgan's
  • Absorption
  • Complement

Functions

Function

A Function f is a mapping between two sets X and Y such that if x ∈ X and y ∈ Y, then f(x) maps to exactly one element of Y.

 

Partial Function is a mapping between two sets where
∃x where x ∈ X, but f(x)  Y.

Domain, Image, and Range

Let f be a function from A to B. A is the Domain of the function f and B is the Codomain.

 

Let a ∈ A and b ∈ B and f(a) = b. Then b is the Image of a and a is the Preimage of b.

 

The Range of f is the set of all images of elements of A.

Domains in Programming

Consider the function with the signature:

public bool isPositive(int x)

 

Domains and Codomains can be considered "types"

 

What about dynamic languages?

function isPositive(x)

Don't We Already Know This?

Algebraic Functions

  • What are we mapping to and from?
  • Domains and ranges of a function f(x)

Digression

Functional Programming

Types of Functions

One to One (Injective)

A function f is one-to-one, or an injunction if and only if
f(a) = f(b) implies that a = b for all a and b in the domain.

 

Examples

 

f(x) = x's full name (injective)

g(x) = x's class standing (not injective)

Onto (Surjective)

A function f from A to B is onto, or surjective, if and only if for every element b ∈ B there is an element a ∈ A such that f(a) = b.

 

Examples

 

f(x) = x's name (where the domain is people in this class and the codomain is the class roster)

g(x) = x * x (not onto if the codomain is all real numbers)

Bijection

A function f from A to B is a one to one correspondence, or bijectiveif and only if the function is both one to one and onto.

 

Examples

 

f(x) = x's name (where the domain is people in this class and the codomain is the class roster)

g(x) = x + 1

Inverse

A function f from A to B has an inverse if it is a bijection. The function is denoted as f   (y). The inverse of a function f is a mapping from B to A.

 

Examples

 

f(x) = x + 1, f   (y) = y - 1

-1

-1

Composition

Let g be a function from A to B and f be a function from B to C. Then the composition of f and g is (f ○ g)(x) = f(g(x))


Special Functions

Some special functions

See: http://pearl.ics.hawaii.edu/~sugihara/course/ics141/notes/Functions.html#SpecialFunctions

Made with Slides.com