Sequences
section sequence_toolkit parents function_toolkit, number_toolkit |
Number range
function 20 leftassoc (_ .. _) |
|
|
| _ .. _ :  |
|
 |
 |
 |
|
| ( ) (_ .. _)  |
|  |
| i , j : i .. j = { k : | i k j } |
The number range from i to j is the set of all integers
greater than or equal to i,
which are also less than or equal to j.
Iteration
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| iter : (X X) (X X) |
|
 |
 |
 |
|
| r : X X iter 0 r = id X |
|  |
| r : X X; n : iter (n+1) r = r (iter n r) |
|  |
| r : X X; n : iter (- n) r = iter n (r ~) |
|
iter is the iteration function for a relation.
The iteration of a relation r : X
X for zero times is the
identity relation on X.
The iteration of a relation r : X
X for n+1 times is the
composition of the relation with its iteration n times.
The iteration of a relation r : X
X for - n times is the
iteration for n times of the inverse of the relation.
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| _ _ : (X X) (X X) |
|
 |
 |
 |
|
| r : X X; n : r n = iter n r |
|
iter n r may be written as r n .
Number of members of a set
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| # _ : X  |
|
 |
 |
 |
|
| a : X # a = ( n : | ( f : 1 .. n a ran f = a ) ) |
|
The number of members of a finite set is the upper limit of the number
range starting at 1 that can be put into bijection with the set.
Minimum
|
|
| min _ :  |
|
 |
 |
 |
|
| (min _) = { a : ; m : | m a ( n : a m n ) a m } |
If a set of integers has a member that is less than or equal
to all members of that set,
that member is its minimum.
Maximum
|
|
| max _ :  |
|
 |
 |
 |
|
| (max _) = { a : ; m : | m a ( n : a n m ) a m } |
If a set of integers has a member that is greater than or equal
to all members of that set,
that member is its maximum.
Finite sequences
seq X == { f : X | dom f = 1 .. # f } |
A finite sequence is a finite indexed set of values of the same type,
whose domain is a contiguous set of positive integers starting at 1.
seq X is the set of all finite sequences of values of X,
that is, of finite functions from the set 1 .. n,
for some n, to elements of X.
Non-empty finite sequences
seq1 X == seq X \ { } |
seq1 X is the set of all non-empty finite sequences of values of X.
Injective sequences
iseq X is the set of all injective finite sequences of values of X,
that is, of finite sequences over X that are also injections.
Sequence brackets
function ( ,, ) |
The brackets
and
can be used for enumerated sequences.
Concatenation
function 30 leftassoc (_ _) |
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| _ _ : seq X seq X seq X |
|
 |
 |
 |
|
| s , t : seq X  |
| s t = s { n : dom t n + # s t n } |
|
Concatenation is a function of a pair of finite sequences of
values of the same type whose result is a sequence that
begins with all elements of the first sequence and
continues with all elements of the second sequence.
Reverse
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| rev : seq X seq X |
|
 |
 |
 |
|
| s : seq X rev s = n : dom s s ( # s - n + 1 ) |
|
The reverse of a sequence is the sequence obtained by taking its
elements in the opposite order.
Head of a sequence
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| head : seq1 X X |
|
 |
 |
 |
|
| s : seq1 X head s = s 1 |
|
If s is a non-empty sequence of values,
then head s is the value that is first in the sequence.
Last of a sequence
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| last : seq1 X X |
|
 |
 |
 |
|
| s : seq1 X last s = s ( # s ) |
|
If s is a non-empty sequence of values,
then last s is the value that is last in the sequence.
Tail of a sequence
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| tail : seq1 X seq X |
|
 |
 |
 |
|
| s : seq1 X tail s = n : 1 .. (# s - 1) s ( n + 1 ) |
|
If s is a non-empty sequence of values,
then tail s is the sequence of values that is obtained from s
by discarding the first element and renumbering the remainder.
Front of a sequence
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| front : seq1 X seq X |
|
 |
 |
 |
|
| s : seq1 X front s = { # s } s |
|
If s is a non-empty sequence of values,
then front s is the sequence of values that is obtained from s
by discarding the last element.
Squashing
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| squash : ( X ) seq X |
|
 |
 |
 |
|
| f : X squash f = |
| { p : f # { i : dom f | i p.1 } p.2 } |
|
squash takes a finite function f :
X
and renumbers its domain to produce a finite sequence.
Extraction
function 45 rightassoc (_ _) |
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| _ _ : seq X seq X |
|
 |
 |
 |
|
| a : ; s : seq X  |
| a s = squash ( a s ) |
|
The extraction of a set a of indices from a sequence
is the sequence obtained from the original by discarding any indices
that are not in the set a,
then renumbering the remainder.
Filtering
function 40 leftassoc (_ _) |
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| _ _ : seq X X seq X |
|
 |
 |
 |
|
| s : seq X ; a : X  |
| s a = squash ( s a ) |
|
The filter of a sequence by a set a
is the sequence obtained from the original by discarding any members
that are not in the set a,
then renumbering the remainder.
Prefix relation
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| _ prefix _ : seq X seq X |
|
 |
 |
 |
|
| s,t: seq X  |
| s prefix t s t |
|
A sequence s is a prefix of another sequence t
if it forms the front portion of t.
Suffix relation
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| _ suffix _ : seq X seq X |
|
 |
 |
 |
|
| s,t: seq X  |
| s suffix t ( u: seq X u s = t) |
|
A sequence s is a suffix of another sequence t
if it forms the end portion of t.
Infix relation
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| _ infix _ : seq X seq X |
|
 |
 |
 |
|
| s,t: seq X  |
| s infix t ( u,v: seq X u s v = t) |
|
A sequence s is an infix of another sequence t
if it forms a mid portion of t.
Distributed concatenation
|
|
[X] |
|
 |
|
 |
|
 |
|
 |
|
| : seq seq X seq X |
|
 |
 |
 |
|
| =  |
|  |
| s : seq X s = s |
|  |
| q , r : seq seq X ( q r ) = ( q ) ( r ) |
|
The distributed concatenation of a sequence t
of sequences of values of type X
is the sequence of values of type X
that is obtained by concatenating the members of t in order.
IT 22-Jan-2002