Left and right shifts

Multiplication and division by 2 are used directly in efficient programs; this module provides these operations, and some of their properties are proved.

Left shift

We need only a global definition:
Definition shift:=[n:nat](mult two n).

Right shift

We first give a specification under the form:
(n:nat){m:nat & {n=(shift m)}+{n=(S (shift m))}}
The variable Unshift is bound to a proof of this statement, obtained by a:
Realizer [n:nat]<nat*bool>let (q,r:nat)=(eucl_dev two n)
                          in (q,(zerop r)).

For the beginner ...

Please notice how the Program tactic works: The specification of zerop (of module $COQTH/theories/ARITH/Compare_dec) is:
(n:nat){n=O}+{(lt O n)}
But its extraction is of type nat->bool, and allows to put (q,(zerop r)) as a nat*bool Fwterm.

Click here to look at the source .