1 / 15

Sequences

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. If we do not wish to impose an order, then we may choose to use bags instead.

babu
Download Presentation

Sequences

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 typeofseq 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. Sequence notation

  7. Sequence notation

  8. Sequence notation • 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, c, d, e, d, c, b, a> ↾ {a, b} = <a, b, b, a>

  10. Question

  11. Sequences as function

  12. Concatenation

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

More Related