Functions Flashcards
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