SE381-07 (Week 4, lecture 1)
Structures
Tuples and records
Tuple -- association of elements in a fixed order
Simplest case -- an ordered pair
How do we declare a tuple variable?
By the set of values it can take on
Set of possible values generated by a cross product
Tuple syntax
(1,2,EECS) or (5,blue)
For pairs only: 5 \mapsto blue ("maplet arrow"), page 81
Accessing the elements of a pair or tuple
"tuplevariable.1", "tuplevariable.3"
"first pairvariable", "second pairvariable"
Example
"Elevator call" in elevator system specification
Two pieces of information: floor and desired direction
Floor -- a member of set "Floors"
Direction -- up or down (subset of elevator direction?)
Define all possible combinations with cross product ...
... then remove "up" for top floor and "down" for bottom floor
Binary relations
Domain and range
Operators for relations
Lookup - relational image
Text, page 83
Domain and range restriction
Text, page 83
Warning!
Error in text table, page 301
"Range" operations have reversed operands
The relation is always on the "big" side of the triangle
The "selecting" set is always on the "point" of the triangle
See the top of page 311; notation is correct there
Domain and range "antirestriction"
Text, page 84
Override
Text, page 84
Inverse
Text, page 85
How do you make the "~" symbol?
Use "\inv" (~ means non-breaking space in LaTeX)
Functions
Basic definition
Like a relation, but no duplicates in first element of pairs
Function application
Variants
Total
Partial
Injections
Sequences
Text, page 93
Like a set, except . . .
Ordered
May have duplicate values (if not \iseq)
Operations
Concatenation
Reversal
Head, last
Tail, front
Subsequence membership (\inseq)
What is a sequence, really?
Just a function, with domain 1 .. n
Each domain value maps to corresponding sequence element
Example
Floor number to floor label mapping in elevator system