List Functions

This page documents library functions related to lists.


Tail

ftail(l)f_ ext{tail} left(, l , ight)

Get the tail of a list (all elements excluding the first).

Arguments

ArgumentDescriptionDomainConstraintsNotes
llsource listT:[T,...]\forall T: [T, ...]Not empty.

Return

ValueDescriptionCodomainConstraintsNotes
ω\omegatail[T,...][T, ...]undefined\text{undefined} if ll is empty.

Instances

f_{tail}left(left[\right]\right)
=rac{1}{0}

f_{tail}left(left[0\right]\right)-left[\right]
f_{tail}left(left[0, 10\right]\right)-left[10\right]
f_{tail}left(left[0, 10, 100\right]\right)-left[10, 100\right]

Implementation

ftail(l)={length(l)<1: [1/0],length(l)=1: [],[l[i]fori=[2...length(l)]]}egin{align*} f_ ext{tail} left(, l , ight) = {& operatorname{length}left(l ight)<1: left[1/0 ight], \ & operatorname{length}left(l ight)=1: left[ ight], \ & left[lleft[i ight]operatorname{for}i=left[2...operatorname{length}left(l ight) ight] ight] \ }& end{align*}

Dependencies

None


Count Occurrences

fcount(l,s)f_ ext{count} left(, l, s , ight)

Count the number of occurrences of a value ss in a list ll.

Arguments

ArgumentDescriptionDomainConstraintsNotes
llsource listT:[T,...]\forall T: [T, ...]The list can be empty.
sstarget valueTT

Return

ValueDescriptionCodomainConstraintsNotes
ω\omegaoccurrence countN\mathbb{N}ω=0\omega = 0 for an empty list.

Instances

f_{count}left(left[\right], 1\right) - 0
f_{count}left(left[1\right], 1\right) - 1
f_{count}left(left[1, 1, 1\right], 1\right) - 3

Implementation

fcount(l)=length(l[l=s])f_ ext{count} left(, l , ight) = operatorname{length}left(lleft[l=s ight] ight)

Dependencies

None


Count Occurrences (parallelised)

fcountl(l,ls)f_ ext{countl} left(, l, l_s , ight)

For each value ss in lsl_s, count the number of times ss appears in ll.

Arguments

ArgumentDescriptionDomainConstraintsNotes
llsource listT:[T,...]\forall T: [T, ...]The list can be empty.
lsl_starget values[T,...][T, ...]The list can be empty.

Return

ValueDescriptionCodomainConstraintsNotes
ω\omegaoccurrence counts[N,...][\mathbb{N}, ...]Same lenth as lsl_sCounts are in the same order as their corresponding values in lsl_s.

Instances

f_{countl}left(left[\right], left[\right]\right)-left[\right]
f_{countl}left(left[0, 1\right], left[\right]\right)-left[\right]
f_{countl}left(left[\right], left[1\right]\right)-0
f_{countl}left(left[0, 1, 1, 1\right], left[1\right]\right)-3
f_{countl}left(left[0, 1, 1, 1, 10, 10\right], left[1, 10\right]\right)-left[3, 2\right]

Implementation

fcountl(l,ls)= { length(ls)=0: [] , [length(l[l=ls[i]])fori=[1...length(ls)]] }egin{align*} f_ ext{countl} left(, l, l_s , ight) =& { operatorname{length}left(l_{s} ight) = 0: left[ ight] \ & , left[operatorname{length}left(lleft[l=l_{s}left[i ight] ight] ight)operatorname{for}i=left[1...operatorname{length}left(l_{s} ight) ight] ight] \ & } end{align*}

Dependencies

None


Map Occurrences

fcounts(l)f_ ext{counts} left(, l , ight)

Map each unique value ss in ll to a (s,c)(s, c) point, where cc is the number of times ss appears in ll.

Arguments

ArgumentDescriptionDomainConstraintsNotes
llsource listTR:[T,...]\forall T \subseteq \mathbb{R}: [T, ...]List can be empty.

Return

ValueDescriptionCodomainConstraintsNotes
ω\omegaoccurrence counts[(T,N),...][(T, \mathbb{N}), ...]Same length as ll.Points are in the same order as the corresponding values in ll.

Instances

f_{counts}left(left[\right]\right)-left[\right]
f_{counts}left(left[0, 10, 10\right]\right)-left[left(0, 1\right), left(10, 2\right)\right]
f_{counts}left(left[0, 10, 0, 100, 10\right]\right)-left[left(0, 2\right), left(10, 2\right), left(100, 1\right)\right]

Implementation

fcounts(l)= { length(l)=0: [] , unique([(l[i], fcount(l, l[i]))fori=[1...length(l)] ]) }egin{align*} f_ ext{counts} left(, l , ight) =& { operatorname{length}left(l ight)=0: left[ ight] \ & quad, operatorname{unique}([ \ &quadquadleft(lleft[i ight], f_{count}left(l, lleft[i ight] ight) ight) \ &quadquadoperatorname{for}i=left[1...operatorname{length}left(l ight) ight] \ & quad]) \ & } end{align*}

Dependencies

None