The dichotomic strategy

This file presents our favorite strategy, which gave the best results (see our included paper).

Let n be a natural number (n>4), l be the logarithm by excess of n; if we assume that n is not a power of 2, (see our informal presentation), then l is the number of digits in the binary representation of n.

The dichotomic strategy associates to n its quotient by 2^l' where l' is the quotient of l by 2.

For instance, let n be 87.
The binary representation of n is 1010111, then l=7 and l'=3.
Therefore our strategy associates to n the number 10.

The name "dichotomic" comes from the fact that we divide the representation of n into two halves (here 1010 and 111).

The complete example is developed in our informal presentation.

For the beginner ...

The definition of our strategy uses the integer logarithm of base 2, specified in log2_spec.
In order to increase the modularity of our development, we used the Section mechanism:
Require log2_spec.
...
Section import_log2.
Variable log2_r:(n:nat)(lt O n)->(log2_spec n). 
 Lemma dicho:strategy.
 ...
 Realizer <some Fw-term using log2_r >
 ...
 Qed
End import_log2.
At the end of the section, we obtain a lemma:
dicho:(log2_r:(n:nat)(lt O n)->(log2_spec n))
      -> strategy.
Since the module log2_implementation provides a correct implementation log2_impl of the logarithm, we can use the term (dicho log2_impl) as a correct term of type strategy.

Problems with Program ....

I wanted to get a proof of the form:
Lemma dicho:strategy.
Proof.
 Realizer [n:nat]<nat>let(l:nat)=
             (ceiling_log2 log2_r n) in
           <nat> let (l':nat)=(quotient two l) in
              (quotient (two_power l') n).
 Program ...
 ...
Qed.
But i could'nt... Instead of that, i had to do some hand-made Intros and Elims before the first Realizer.
Someone to help me ?

Moreover, the proof of dicho is very long, and contains many Cuts.

Click here to look at the source .

In Caml Light ...

#load "Demo.ml"
##open "Demo";;

#dicho;;
- : (int -> (int, sumbool) sigS) -> int -> int = <fun>

#dicho log2_impl;;
- : int -> int = <fun>

#dicho  log2_impl 87;;
- : int = 10

#dicho  log2_impl 1023;;
- : int = 31

#binary 1023;;
- : int = 511