Binary positive numbers, operations
Initial development by Pierre Crégut, CNET, Lannion, France
The type
positive and its constructors
xI and
xO and
xH
are now defined in
BinNums.v
Postfix notation for positive numbers, which allows mimicking
the position of bits in a big-endian representation.
For instance, we can write 1~1~0 instead of (xO (xI xH))
for the number 6 (which is 110 in binary notation).
A Square Root function for positive numbers
We proceed by blocks of two digits : if p is written qbb'
then sqrt(p) will be sqrt(q)~0 or sqrt(q)~1.
For deciding easily in which case we are, we store the remainder
(as a mask, since it can be null).
Instead of copy-pasting the following code four times, we
factorize as an auxiliary function, with f and g being either
xO or xI depending of the initial digits.
NB: (sub_mask (g (f 1)) 4) is a hack, morally it's g (f 0).