(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
(* Contribution to the Coq Library   V6.3 (July 1999)                    *)
(*  ---                       dicho_strat.v                    --- *)
(*                                                                          *)
(* Author: Pierre Casteran.                                                 *)
(*    LABRI, URA CNRS 1304,                                                 *)
(*    Departement d'Informatique, Universite Bordeaux I,                    *)
(*    33405 Talence CEDEX,                                                  *)
(*    e-mail:  casteran@labri.u-bordeaux.fr                                 *)
(*  This file presents our favorite strategy, which gave the best results (see the included paper)  Briefly:   dicho-strat(n)= let l=(ceiling_log2 log2 n) in (eucl_dev (two_power (eucl_dev 2 l)) n)  (recall that in the distribution (quotient b a) is the notation for the euclidean division of a by b !)  For instance let n be 87, The ceiling logarithm (base 2) of n is l=7 since 64<n<=128 ; thus the quotient of 87 by 2^3 is 10.  Perhaps it's easier to understand this strategy in terms of binary representation of natural integers:  For instance, 87 is represented by 1010111; if we cut this representation in two halves (the shorter at the right hand side, if the number of digits is odd), we have two words: -   1011 -> 10 (it is just dicho_strat(10)) -    111 -> 7 Since we have 87=8*10+7, the code for (CALL_M 87) will be the  code for (CALL_C 87 10), i.e. the concatenation of the code for (CALL_K 10 7), the code for (CALL_M 8), and a MUL statement:  Statement  register  stack  code for (CALL_K 10 7):  x         [] PUSH        x         [x] PUSH        x         [x,x] SQR         x^2       [x,x] MUL         x^3       [x] PUSH        x^3       [x^3,x] SWAP        x^3       [x,x^3] SQR         x^6       [x,x^3] MUL         x^7       [x^3] PUSH        x^7       [x^7,x^3] SWAP        x^7       [x^3,x^7] MUL         x^10      [x^7]  code for (CALL_M 8):  SQR         x^20      [x^7] SQR         x^40      [x^7] SQR         x^80      [x^7]  the final MUL: MUL         x^87      []   The proof is very long, and we hope to shorten it quickly.   *)
Section import_log2.
Variable log2_r : forall n : nat, 0 < n -> log2_spec n.

Lemma dicho : strategy.
End import_log2.