Download presentation
Presentation is loading. Please wait.
1
Sequences
2
What is sequence? A sequence is an ordered collection of objects. We use sequences to model collections in which order or multiplicity is important. If we do not wish to impose an order, then we may choose to use bags instead. A sequence of values of type X is a partial function from natural numbers N to X whose domain is just 1..n, where n is the length of the sequence. Formally we can define the set of all sequences of values of type X as follows: seq X == { f : N ↛ X | ( n : N dom f = 1..n)}
3
Since seq X is a set of functions, the type of seq X must be ℙ (ℙ(ℤ X)) The type of any sequence of values of type X is ℙ(ℤ X) The following notation denote a sequence: {1 ↦ u, 2 ↦ s, 3 ↦ i, 4 ↦ n, 5 ↦ g, 6 ↦ z} ‹u,s,i,n,g,z› ‹› empty sequence
4
If we let s denotes the above sequence, then the following statements are well-formed and true: dom s = 1..6 ran s = {u,s,i,n,g,z} #s = 4 s 4 = n
5
Sequence notation
8
last s = s #s front s = {#s} s
9
Filter If s is a sequence, then s ↾ A is the largest subsequence of s containing only those objects that are elements of A. ↾ {a, b} =
10
Question
12
Sequences as function
13
Concatenation
15
Bag A bag is an unordered collection of objects in which multiplicities are important: [[ ]] [[a, b, c, a, b, c]]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.