Functions Flashcards
(44 cards)
Partial function
R : A -|-> B is functional, and a partial function iff
- For all a in domain,
- For all b1, b2 in codomain:
: (a R b1 && a R b2) => b1 = b2
Analogy : an array indexed by elements of the codomain, may store null or a unique element.
How to disprove that a relation has the property of being functional.
R : A -|-> B is NOT functional if exists an a in domain A, and b1 != b2 in B, such that both:
[(a, b1) in R & (a, b2) in R]
Analogy: Chaining to resolve hash collisions. A particular key may correspond to multiple values under a hash collision - hence exist distinct values which are associated with the same key. So the hash function in this sense is not a partial function.
Give 3 examples of relations that are also functional.
- {(x, y) | y = x^2} : Z -|-> N
every integer has a unique square in N. - ADD
- ADD
Give 3 examples of relations that are NOT functional
- { (m,n) | m = n^2} : N -|-> Z.
because some integers have more than one square root in the integers. (e.g. both (1, 1) and (1, -1) are in this relation. - ADD
- ADD
A -` B
partial function with domain A and codomain B.
(A =`` B)
the set of all partial functions from A to B.
In/out degrees-type definition of a partial function f : A -‘ B
for each element a in A, (exists at most one) b in B $ b = f ( a ) iff b is the value of f at a iff (a f b) iff (a,b) in f.
Array indexing defines a partial function from integers to Strings (etc…) with each element of domain (subscript position) being associated to at most one element of codomain (= a reference to a string, or NULL).
Semantics of f(a) in context of partial functions
f(a) denotes ‘the value of’ f at a, whenever this exists, and is considered undefined otherwise.
Analogy: A[i] denotes the value of the array at index position i, or throws an NPE (imagine…) or throws other exceptions if A[i] is not defined.
Prove that the composition of partial functions is a partial function
(answer p359 notes … relevant qn in exercises)
- Suppose f : A - B and g: B -
C are partial functions.
- The expression g(f(a)) is defined iff f(a) is defined (call it b) and so an element of b …
&& if g(b) is defined where b= f(a),
Analogy: if our array holds yet other array positions, if A[i] is defined and A is defined on A[i] then A[A[i]] defined and is a partial function from indices to type of value stored by array.
Functional composition
Case of relational composition
g(f(x)) = (g o f) (x)
How is functional equality defined?
f = g : A -` B if - have same codomain and domain && - For all elements of domain, f is defined on x iff g is defined on x in A. - And, f(a) = g(a).
Analogy: Two arrays are value-equal if they are of the same size and type, and all index positions agree on value mapped to in codomain.
State how to define a partial function f : A -` B
- Specify a domain of definition Df subset of A.
- Specify a mapping
f : a |-> b_a
rule that assigns a unique element b_a in codomain B to each element a in the domain of definition,
such that f(a) = b_a.
State how to prove that a partial function is well defined.
- Show definition of partial function holds (for every a in Df, the b_a as described by your mapping rule is (i) unique, and (ii) is in B)
- which hows that f(a) has a well defined value. - Show domain of definition is a subset of domain A.
Give an example of a partial function from ZZ -` ZN based on quo(m,n) and rem(m,n) given these take non-negative arguments. State its domain of definition
see 363 of notes
Df = integer tuples where second tuple element is nonzero.
Definition of a total function / map
f : A -> B is a total function whenever:
domain of definition = source
Meaning of f : A -> B
f is a total function from A to B.
notation: A => B
the set of functions from A to B
State a theorem relating functions to relations
A relation is a function from A to B iff
for all a in A, there exists a unique b in B such that (a f b)
Count the number of partial functions from A to B (i.e. what is #(A =`` B) ?
For each element of A there are (#B + 1) choices to map to (either one of the #B elements of B, or ‘null’, leave undefined). This choice is repeated for #A elements, hence #(A =`` B) = (#B + 1) ^ (#A).
How many functions are there from a set A to a set B?
For each of the #A elements of A, there are #B choices (since undefined is no longer an option), so there are (#B) ^ (#A) such total functions from finite sets A to B.
Compare definition of function with definition of partial function (operationally)
- Total function - a mapping rule f : a |-> b_a suffices, w/o needing a domain of definition.
- Mapping should be defined for every element in A specifying a unique element of B.
Thm 126 : The identity partial function is a function
- id(x) = x
Defined for every element of source, mapping to a unique element of codomain.
assume id (x) = id (y) implies x = y (as required - uniqueness)
Thm 126 ii: Composition of functions is a function
Let f : A -> B and g : B -> C be functions. Let a be an arbitrary member of A, then f(a) is defined and a member of B, say ‘b’ since f is a function. Since g is a function, g(b) will be defined and equal to a unique c in C. Hence g(f(a)) is defined for all ‘a’ and equal to a unique c in C, so g(f(a)) is a function from A -> C, such that
(g o f) : a |-> g(f(a))
What is a bijection? Or, given a function f : A -> B, when is it bijective?
A fn f:A ->B is bijective if: exists a (necessarily unique) function g : B -> A (g is the inverse of f) such that g is both a retraction and a section for f.