3. Tuple
Tuples associate particular elements of any type, in a fixed order
If we use set (2,11,11) and (11,2,11) won’t be different.
Tuples are instances of Cartesian product types, sometimes called cross
product types. We define product types using the cross product symbol x. This
abbreviation definition introduces a set of tuples named DATE
DATE=DAY X MONTH X YEAR
DATE has product type P(Z X Z X Z)
4.
5. Relation, Table and Database
A set of tuples is called a relation. Relations can model tables and databases.
You have probably heard of the relational database, which is just a database
where the data are stored in one or more relations
6.
7. Pair and binary relation
It has two components.
. We can use a pair to associate a name with a telephone extension number,
as in (aki, 4117). Z provides an alternate syntax for pairs that uses the maplet
arrow ---> to emphasize the asymmetry between the two components. The
pair (aki, 4117) can also be written aki -->4117
Z also provides the first and second operators for extracting each component
from a pair: first(aki,41) = aki second(aki,41) = 41 operators like these that
extract components from structures are called projection operators.
10. Operators for relations
The relation image operator
The relational image operator can model table lookup. Its first argument is a
relation, its second argument is a set of elements from the domain, and its
value is the set of corresponding elements from the range. It is notated in an
unusual mixfix syntax: Thick brackets (]...[) surround the second argument.
To look up the numbers for Doug and Philip in the phone relation, we use the
relational image: phone
18. Composition relation
Relational composition formalizes this kind of reasoning: It merges two
relations into one by combining pairs that share a matching component.
19. Binary relation and linked data
structure.
Relations are not just for modelling tables and flat databases. They can model
linked data structures as well. Linked data structures are often pictured as
graphs: networks of nodes connected by arcs. Data flow diagrams, state
transition diagrams, and syntax trees are all examples of graphs.
20.
21. Function
Sometimes we need to associate a single item with each element in a set. For
this we use a special kind of relation, called & function. A function is a binary
relation where an element can appear only once as the first element in a pair.
24. Partial and total function
The domain of a partial function might not include every element of the
source set.
Total function apply to every element of the source set
Square of x.
25. Injections
every element of the function's codomain is the image of at most one element
of its domain.