Theorem addchains:(gamma:strategy) (n:nat) (M:Set) (MO:(monoid M)) (a:M) {b:M|b=(power M MO a n)}.This theorem is proved constructively as follows: Given a strategy gamma, and n >0, we build a code for an abstract machine, the execution of which gives the n-th power of some a in any monoid MO = (M,u,o).
Click here to see the source.
log2_spec
and
log2_implementation
.
The second Require
allows us to use a real implementation of
log2
, whereas only log2_spec
is required in such modules as generation
and dicho_strat
.
Lemma fib_computation:(n:nat)(lt O n)-> (Fib n)= (M11 (power Mat2 matrix fib_mat n)).Since
power
can be efficiently implemented with addition chains,
we link all that together:
Lemma fibonacci:(n:nat){q:nat | q=(Fib n)}. Proof. Realizer [n:nat] <nat>if (zerop n) then (S O) else (M11 (addchains dic n Mat2 matrix fib_mat)). Program_all. Rewrite e;Rewrite Unfold_FibO;Auto. Rewrite fib_computation. Rewrite e;Auto. Auto. Qed.
nat
with
int
, we got the file Demo.ml
which you can use to better visualize our algorithms.
Some examples are listed in a file demos.txt
Since addchains
has an informative contents, we can show you the
following extract of this file:
#load "Demos.ml";; ##open "Demos";; #addchains;; - : (int -> int) -> int -> 'a monoid -> 'a -> 'a =#addchains binary 10 standard 2;; - : int = 1024 let it= addchains (dicho log2_impl) 87 funmono (function l->"boum"::l) ;; it : string list -> string list = it [];; - : string list = ["boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"; "boum"] #fibonacci 20;; - : int = 10946