L06: Functions Flashcards
What is a function?
A function f is a binary relation between 2 sets: a domain and codomain
Has the property that each element of the domain is related to at most one element of the codomain -> its image
We write f(x) = y to mean that the image of x under the function f is y
The range of the function is the subset of elements of the codomain, each of which is the image of some element of the function domain
Where does the function pattern occur?
Graph colouring
- fund a function from the vertices to a set of colours such that touching vertices are not the same colour
Warehouse location
- Find a function from stores to warehouse to indicate which store is supplied by which warehouse
What is a total function?
In a total function, every element in the domain has an image in the codomain
How can we use explicit representation for total functions?
We can have a table indexed by each element of the domain, and the domain for each variable is the codomain.
How can we use occurrence representation for total functions?
We can have a 2D table with one dimension indexed by the domain, and the other indexed by the codomain. The domain for the variables are 0/1 to represent the relationship between the domain and codomain.
Constraint:
The sum of each column = 1(assuming the domain index is at the top)
This will ensure that each element of the domain has an image in the codomain
What is a partial function?
In a partial function, some elements of the domain have no image in the codomain.
How can we use explicit representation for partial functions?
We can have a table indexed by each element of the domain, and the domain for each variable is the codomain and a dummy variable, as not every element in the domain needs to have an image in the codomain
How can we use occurrence representation for partial functions?
We can have a 2D table with one dimension indexed by the domain, and the other indexed by the codomain. The domain for the variables are 0/1 to represent the relationship between the domain and codomain.
Constraint:
The sum of each column <= 1(assuming the domain index is at the top)
This will ensure that each element of the domain has at most 1 image in the codomain
What is an injection?
In an injective function, the images of distinct elements are distinct
I.e. no 2 elements in the domain map to the same element in the codomain
How can we use explicit representation for injective functions?
We can have a table indexed by each element of the domain, and the domain for each variable is the codomain.
Constraints:
- Total function: allDifferent(injection)
- Partial function: allDifferent(injection) but ignoring repetition of the dummy variable
How can we use occurrence representation for total injective functions?
We can have a 2D table with one dimension indexed by the domain, and the other indexed by the codomain. The domain for the variables are 0/1 to represent the relationship between the domain and codomain.
Constraints:
- The sum of each column = 1 (assuming the domain index is at the top)
This will ensure that each element of the domain has an image in the codomain
- The sum of each row <= 1 (assuming the codomain index is on the left)
This will ensure that each element of the codomain is only mapped from one element in the domain
How can we use occurrence representation for partial injective functions?
We can have a 2D table with one dimension indexed by the domain, and the other indexed by the codomain. The domain for the variables are 0/1 to represent the relationship between the domain and codomain.
Constraints:
- The sum of each column <= 1 (assuming the domain index is at the top)
This will ensure that each element of the domain has at most 1 image in the codomain
- The sum of each row <= 1 (assuming the codomain index is on the left)
This will ensure that each element of the codomain is only mapped from one element in the domain
What is a surjective function?
A function is surjective if every element in the codomain is the image of some element of the domain
I.e. every element in the codomain is image of an element in the domain
How can we use explicit representation for surjective functions?
We can have a table indexed by each element of the domain, and the domain for each variable is the codomain.
Constraints:
- There must exist indices where each of the elements in the codomain appear
How can we use occurrence representation for surjective functions?
We can have a 2D table with one dimension indexed by the domain, and the other indexed by the codomain. The domain for the variables are 0/1 to represent the relationship between the domain and codomain.
Constraints:
- The sum of each row >= 1 (assuming the codomain index is on the left)
This will ensure that each element of the codomain is mapped to at least once