Notation | Equivalent SML with SEQUENCE library |
S[i] | nth S i |
|S| | length S |
⟨⟩ | empty () |
⟨v⟩ | singleton v |
⟨i,…,j⟩ | tabulate (fn k => i + k) ( j - i + 1) |
S⟨i,…,j⟩ | subseq S ( i, j - i + 1) |
⟨e:p∈S⟩ | map (fn p => e) S |
⟨e:0≤i<n⟩ | tabulate (fn i => e) n |
⟨p∈S|e⟩ | filter (fn p => e) S |
⟨e1:p∈S|e2⟩ | map (fn p => e1) (filter (fn p => e2) S) |
⟨e:p1∈S1,p2∈S2⟩ | flatten (map (fn p1 => map (fn p2 => e) S2) S1) |
⟨e:0≤i<n,0≤j<i⟩ | flatten (tabulate (fn i => tabulate (fn j => e) i) n) |
∑p∈Se | reduce add 0 (map (fn p => e) S) |
n∑i=ke | reduce add 0 (map (fn i => e) ⟨k,…,n⟩) |
The meaning of add
and 0
in the
reduce
will depend on the type (e.g. Int.+
and
0
for integers or Real.+
and 0.0
for
reals). We can also replace ∑ with other operations such as min and
\max with the implied semantics.