18 April 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Formal Methods Sequences
18 April 2009Instructor: Tasneem Darwish2 Outlines Sequence notation A model for sequences Functions on sequences Structural induction Bags
18 April 2009Instructor: Tasneem Darwish3 Sequence notation A sequence is an ordered collection of objects If there are no objects in the collection, the sequence is the empty sequence, and it is written as The expression denotes the sequence containing objects a, b, and c, in that order Concatenation is when two sequences are combined in such a way that the elements of one follow the elements of the other, and order is maintained Example: If s and t are sequences, we write s ̑ t to denote the concatenation of s and t
18 April 2009Instructor: Tasneem Darwish4 Sequence notation Example 9.1 The ticket office in a railway station has a choice of two counters at which tickets may be purchased. There are two queues of people, one at each counter; these may be modelled as sequences To restrict elements of a sequence we can use the filter operator if s is a sequence, then is the largest subsequence of s containing only those objects that are elements of the set A Note: The order and multiplicity of elements must be preserved
18 April 2009Instructor: Tasneem Darwish5 Sequence notation Example 9.2 In the station, there is a destination board displaying a list of trains, arranged in order of departure. This may be modelled as a sequence of pairs, each recording a time and a destination Sally is interested only in those trains that are going to London;
18 April 2009Instructor: Tasneem Darwish6 Sequence notation To refer to the first element of a sequence, or to the part of the sequence that follows the first element; these are called the head and tail, respectively Notice that the head of a sequence is an element, while the tail is another sequence. If s is any non-empty sequence
18 April 2009Instructor: Tasneem Darwish7 Sequence notation Example 9.3 Sally wants to take the first train to London. From the list of trains on the destination board Tim is still waiting to buy a ticket, and the first train is about to leave, then the list of available trains is given by `tail trains', the sequence
18 April 2009Instructor: Tasneem Darwish8 Sequence notation if s is a sequence, then we write `#s' to denote the length of s. For example Example 9.4 The total number of trains on the destination board is given by and the total number of trains to London is given by flattening is to map a sequence of sequences to a single sequence; For example,