CADiZ

Reference manual / Standard toolkit / section sequence_toolkit


Sequences

section sequence_toolkit parents function_toolkit, number_toolkit

Number range

function 20 leftassoc (_ .. _)


_ .. _ : \arithmos \cross \arithmos \pfun \power \arithmos
\where
(\num \cross \num) \dres (_ .. _) \in \num \cross \num \fun \power \num
\forall i , j : \num @ i .. j = {  k : \num | i \leq k \leq 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 : \num \fun (X \rel X) \fun (X \rel X)
\where \where \where
\forall r : X \rel X @ iter   0   r = id X
\forall r : X \rel X; n : \nat @ iter (n+1) r = r \comp (iter n r)
\forall r : X \rel X; n : \nat @ iter (- n) r = iter n (r ~)

iter is the iteration function for a relation. The iteration of a relation r : X \rel X for zero times is the identity relation on X. The iteration of a relation r : X \rel X for n+1 times is the composition of the relation with its iteration n times. The iteration of a relation r : X \rel X for - n times is the iteration for n times of the inverse of the relation.

function (_  _ )

[X]

 _  : (X \rel X) \cross \num \fun (X \rel X)
\where \where \where
\forall r : X \rel X; n : \nat @ n  = iter n r

iter n r may be written as r n .

Number of members of a set

function (# _)

[X]

# _ : \finset X \fun \nat
\where \where \where
\forall a : \finset X @ # a = (\mu n : \nat | ( \exists f : 1 .. n \inj 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

function (min _)


min _ : \power \arithmos \pfun \arithmos
\where
\power \num \dres (min _) = {  a : \power \num ; m : \num | m \in a \land ( \forall n : a @ m \leq n ) @ a \mapsto 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

function (max _)


max _ : \power \arithmos \pfun \arithmos
\where
\power \num \dres (max _) = {  a : \power \num ; m : \num | m \in a \land ( \forall n : a @ n \leq m ) @ a \mapsto 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

generic (seq _)

seq X == {  f : \nat \ffun 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 \ { \emptyset }

seq1 X is the set of all non-empty finite sequences of values of X.

Injective sequences

generic (iseq _)

iseq X == seq X \cap (\nat \pinj X)

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 (\langle ,, \rangle)

\langle ,, \rangle [ X ] == \lambda s : seq X @ s

The brackets \langle and \rangle can be used for enumerated sequences.

Concatenation

function 30 leftassoc (_ \cat _)

[X]

_ \cat _ : seq X \cross seq X \fun seq X
\where \where \where
\forall s , t : seq X @
s \cat t = s \cup {  n : dom t @ n + # s \mapsto 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 \fun seq X
\where \where \where
\forall s : seq X @ rev s = \lambda 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 \fun X
\where \where \where
\forall 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 \fun X
\where \where \where
\forall 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 \fun seq X
\where \where \where
\forall s : seq1 X @ tail s = \lambda 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 \fun seq X
\where \where \where
\forall s : seq1 X @ front s = { # s } \ndres 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 : ( \num \ffun X ) \fun seq X
\where \where \where
\forall f : \num \ffun X @ squash f =
{  p : f @ # {  i : dom f | i \leq p.1  } \mapsto p.2  }

squash takes a finite function f : \num \ffun X and renumbers its domain to produce a finite sequence.

Extraction

function 45 rightassoc (_ \extract _)

[X]

_ \extract _ : \power \num \cross seq X \fun seq X
\where \where \where
\forall a : \power \num ; s : seq X @
a \extract s = squash ( a \dres 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 (_ \filter _)

[X]

_ \filter _ : seq X \cross \power X \fun seq X
\where \where \where
\forall s : seq X ; a : \power X @
s \filter a = squash ( s \rres 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

relation (_ prefix _)

[X]

_ prefix _ : seq X \rel seq X
\where \where \where
\forall s,t: seq X @
s prefix t \iff s \subseteq t

A sequence s is a prefix of another sequence t if it forms the front portion of t.

Suffix relation

relation (_ suffix _)

[X]

_ suffix _ : seq X \rel seq X
\where \where \where
\forall s,t: seq X @
s suffix t \iff ( \exists u: seq X @ u \cat s = t)

A sequence s is a suffix of another sequence t if it forms the end portion of t.

Infix relation

relation (_ infix _)

[X]

_ infix _ : seq X \rel seq X
\where \where \where
\forall s,t: seq X @
s infix t \iff ( \exists u,v: seq X @ u \cat s \cat v = t)

A sequence s is an infix of another sequence t if it forms a mid portion of t.

Distributed concatenation

[X]

\dcat : seq seq X \fun seq X
\where \where \where
\dcat \langle \rangle = \langle \rangle
\forall s : seq X @ \dcat \langle s \rangle = s
\forall q , r : seq seq X @ \dcat ( q \cat r ) = ( \dcat q ) \cat ( \dcat 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