Functions Multiplicities Relations can be associated with - - PDF document
Functions Multiplicities Relations can be associated with - - PDF document
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
Multiplicities
Relations can be associated with
- multiplicities. (e.g. in UML diagrams)
The annotation ` m..n’ on B means that
each A is associated with between m and n members of B
A B
m..n
Multiplicity annotations
m..n means ` between m and n’ * means ` any number’ m..* means ` any number greater than
- r equal to m’
m means ` exactly m’
A common annotation
The annotation ` 1’ is particularly
common.
This means each A is associated with
exactly one B
This kind of relation is termed a
function
A B
1
Functions more formally
Example: favourite
Abigail Barney Charlotte Dora Emily CS189 CS153 CS154 CS173 CS183
Examples
Would be a function?
Y e s N
- D
e p e n d s
0% 0% 0%
1.
Yes
2.
No
3.
Depends
Would be a function?
Y e s N
- D
e p e n d s
0% 0% 0%
1.
Yes
2.
No
3.
Depends
Would be a function?
Y e s N
- D
e p e n d s
0% 0% 0%
1.
Yes
2.
No
3.
Depends
Would be a function?
Y e s N
- D
e p e n d s
0% 0% 0%
1.
Yes
2.
No
3.
Depends
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.
A B
0..1
Partial functions more formally
Example: on_loan_to
War and Peace Bleak House Madame Bovary Lord of the Rings Using Z Neil Olivia Petra Quentin Ulysses Catch-22
Examples
Would be a partial function?
Y e s N
- D
e p e n d s
0% 0% 0%
1.
Yes
2.
No
3.
Depends
Would be a partial function?
Y e s N
- D
e p e n d s
0% 0% 0%
1.
Yes
2.
No
3.
Depends
Would be a partial function?
Y e s N
- D
e p e n d s
0% 0% 0%
1.
Yes
2.
No
3.
Depends
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
A B
0..1
Injective functions more formally
YES NO
Example: exam numbers
Abigail Barney Charlotte Dora Emily 1455673 1522368 1415926 1556398 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
Abigail Barney Charlotte Dora Emily 31258734 48219347 32452263 62399853 34182730 32452275
Would be a partial injective function?
Y e s N
- D
e p e n d s
0% 0% 0%
1.
Yes
2.
No
3.
Depends
Exercise
Which symbol best matches the relation diagram?
0% 0% 0% 0%
1. 2. 3. 4.
A B
0..1 1
Using relational notation
Functions are (special kinds of) relations, and so the relational notation can be used:
A new library Z spec: state
- n_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.
A B
1..*