Functions
Multiplicities � Relations can be associated with multiplicities. (e.g. in UML diagrams) m..n B A � The annotation ` m..n’ on B means that each A is associated with between m and n members of B
Multiplicity annotations � m..n means ` between m and n’ � * means ` any number’ � m..* means ` any number greater than or equal to m’ � m means ` exactly m’
A common annotation � The annotation ` 1’ is particularly common. 1 B A � This means each A is associated with exactly one B � This kind of relation is termed a function
Functions more formally
CS153 CS173 CS189 CS183 CS154 Example: favourite Charlotte Emily Abigail Barney Dora
Examples
0% s d n e p e D 0% o N 0% s e Y be a function? Would Depends Yes No 1. 2. 3.
0% s d n e p e D 0% o N 0% s e Y be a function? Depends Would Yes No 1. 2. 3.
0% s d n e p e D 0% o N 0% s e Y be a function? Would Depends Yes No 1. 2. 3.
0% s d n e p e D 0% o N 0% s e Y be a function? Depends Would Yes No 1. 2. 3.
Partial functions � Partial functions are like functions, except that not all A’s have to relate to a B. � They have a weaker multiplicity requirement. 0..1 B A
Partial functions more formally
Example: on_loan_to Neil War and Peace Olivia Bleak House Madame Bovary Petra Lord of the Rings Quentin Using Z Ulysses Catch-22
Examples
Would be a partial function? Yes 1. No 2. Depends 3. 0% 0% 0% s o s e d N Y n e p e D
Would be a partial function? Yes 1. No 2. Depends 3. 0% 0% 0% s o s e d N Y n e p e D
Would be a partial function? Yes 1. No 2. Depends 3. 0% 0% 0% s o s e d N Y n e p e D
Injective functions � Multiplicity requirements on the domain of the function are also useful. � If each B relates to 0 or 1 A’s then the relation is injective . � Different A’s must relate to different B’s 0..1 B A
Injective functions more formally NO YES
Example: exam numbers Abigail 1455673 1522368 Barney 1556398 Charlotte 1415926 Dora Emily 1529937
Examples � Exam numbers: different students need different numbers � Fingerprints: different people have different fingerprints � Biometrics: different people have different biometrics
Partial injective functions
Example: passport numbers 31258734 Abigail 48219347 Barney 34182730 Charlotte 62399853 Dora 32452263 Emily 32452275
Would be a partial injective function? Yes 1. No 2. Depends 3. 0% 0% 0% s o s e d N Y n e p e D
Exercise
Which symbol best matches the relation diagram? 1. 2. 3. 4. 0..1 1 B A 0% 0% 0% 0%
Using relational notation Functions are (special kinds of) relations, and so the relational notation can be used:
A new library Z spec: state on_loan_to declared as a partial function
Event: Borrowing a book Δ Library means that the Library state changes
Event: Looking up a borrower b? is an input p! is an output Ξ Library means the Library state does not change
Surjective functions (in brief)
Multiplicities � A surjective function from A to B involves every element of B � So every B relates to at least one A. 1..* B A
Bijective functions (in brief)
Examples
Summary
Please ensure you return your handset before leaving. The handset is useless outside of this class and non-returns will decease the likelihood of future voting system use on this course.
Recommend
More recommend