Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sequences. What is sequence? A sequence is an ordered collection of objects. We use sequences to model collections in which order or multiplicity is important.

Similar presentations


Presentation on theme: "Sequences. What is sequence? A sequence is an ordered collection of objects. We use sequences to model collections in which order or multiplicity is important."— Presentation transcript:

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

6

7

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

11

12 Sequences as function

13 Concatenation

14

15 Bag A bag is an unordered collection of objects in which multiplicities are important: [[ ]] [[a, b, c, a, b, c]]


Download ppt "Sequences. What is sequence? A sequence is an ordered collection of objects. We use sequences to model collections in which order or multiplicity is important."

Similar presentations


Ads by Google