\alik{\<Sum>(x) = x \bmod \1^{b+1}. \cr}
-This works because when we work modulo~$\1^{b+1}$, the number $2^{b+1}=\1\0^{b+1}$
+This is correct because when we calculate modulo~$\1^{b+1}$, the number $2^{b+1}=\1\0^{b+1}$
is congruent to~1 and thus $x = \sum_i 2^{(b+1)i}\cdot x_i \equiv \sum_i 1^i\cdot x_i \equiv \sum_i x_i$.
As the result should fit in $b$~bits, the modulo makes no difference.
It only remains to shift the separator bits to the right positions, negate them
and mask out all other bits.
-\:$\<Rank>(x,\alpha)$ --- return the number of elements of~${\bf x}$ which are less than~$\alpha$,
+\:$\<Rank>(x,\alpha)$ --- returns the number of elements of~${\bf x}$ which are less than~$\alpha$,
assuming that the result fits in~$b$ bits:
\alik{
\<Rank>(x,\alpha) = \<Sum>(\<Cmp>(x,\<Replicate>(\alpha))). \cr
}
-\:$\<Insert>(x,\alpha)$ --- insert~$\alpha$ into a~sorted vector $\bf x$:
+\:$\<Insert>(x,\alpha)$ --- inserts~$\alpha$ into a~sorted vector $\bf x$:
-Calculate $k = \<Rank>(x,\alpha)$ first, then insert~$\alpha$ as the $k$-th
+We calculate $k = \<Rank>(x,\alpha)$ first, then insert~$\alpha$ as the $k$-th
field of~$\bf x$ using masking operations and shifts.
-\:$\<Unpack>(\alpha)$ --- create a~vector whose elements are the bits of~$\(\alpha)_d$.
-In other words, insert blocks~$\0^b$ between the bits of~$\alpha$. Assuming that $b\ge d$,
+\:$\<Unpack>(\alpha)$ --- creates a~vector whose elements are the bits of~$\(\alpha)_d$.
+In other words, inserts blocks~$\0^b$ between the bits of~$\alpha$. Assuming that $b\ge d$,
we can do it as follows:
\algo
\endlist
\para
-We can use the above tricks to perform interesting operations on individual
+We can use the aforementioned tricks to perform interesting operations on individual
numbers in constant time, too. Let us assume for a~while that we are
operating on $b$-bit numbers and the word size is at least~$b^2$.
This enables us to make use of intermediate vectors with $b$~elements
\itemize\ibull
-\:$\<Weight>(\alpha)$ --- compute the Hamming weight of~$\alpha$, i.e., the number of ones in~$\(\alpha)$.
+\:$\<Weight>(\alpha)$ --- computes the Hamming weight of~$\alpha$, i.e., the number of ones in~$\(\alpha)$.
-Perform \<Unpack> and then \<Sum>.
+We perform \<Unpack> and then \<Sum>.
-\:$\<Permute>_\pi(\alpha)$ --- shuffle the bits of~$\alpha$ according
+\:$\<Permute>_\pi(\alpha)$ --- shuffles the bits of~$\alpha$ according
to a~fixed permutation~$\pi$.
-Perform $\<Unpack>_\pi$ and \<Pack> back.
+We perform $\<Unpack>_\pi$ and \<Pack> back.
-\:$\<LSB>(\alpha)$ --- find the least significant bit of~$\alpha$,
+\:$\<LSB>(\alpha)$ --- finds the least significant bit of~$\alpha$,
i.e., the smallest~$i$ such that $\alpha[i]=1$.
By a~combination of subtraction with $\bxor$, we create a~number
Then we calculate the \<Weight> of the result and subtract~1.
-\:$\<MSB>(\alpha)$ --- find the most significant bit of~$\alpha$ (the position
+\:$\<MSB>(\alpha)$ --- finds the most significant bit of~$\alpha$ (the position
of the highest bit set).
Reverse the bits of the number~$\alpha$ first by calling \<Permute>, then apply \<LSB>