Module Type NZLog2Prop
(Import A : NZOrdAxiomsSig')
(Import B : NZPow' A)
(Import C : NZLog2 A B)
(Import D : NZMulOrderProp A)
(Import E : NZPowProp A B D).
(** log2 is always non-negative *)
(** A tactic for proving positivity and non-negativity *)
Ltac order_pos :=
((apply add_pos_pos || apply add_nonneg_nonneg ||
apply mul_pos_pos || apply mul_nonneg_nonneg ||
apply pow_nonneg || apply pow_pos_nonneg ||
apply log2_nonneg || apply (le_le_succ_r 0));
order_pos) (* in case of success of an apply, we recurse *)
|| order'.  (* otherwise *)
(** The spec of log2 indeed determines it *)
(** Hence log2 is a morphism. *)
Instance log2_wd : Proper (eq==>eq) log2.
(** An alternate specification *)
(** log2 is exact on powers of 2 *)
(** log2 and predecessors of powers of 2 *)
(** log2 and basic constants *)
(** log2 n is strictly positive for 1<n *)
(** Said otherwise, log2 is null only below 1 *)
(** log2 is a monotone function (but not a strict one) *)
(** No reverse result for <=, consider for instance log2 3 <= log2 2 *)
(** When left side is a power of 2, we have an equivalence for <= *)
(** When right side is a square, we have an equivalence for < *)
(** Comparing log2 and identity *)
(** Log2 and multiplication. *)
(** Due to rounding error, we don't have the usual [log2 (a*b) = log2 a + log2 b] but we may be off by 1 at most *)
(** And we can't find better approximations in general. - The lower bound is exact for powers of 2. - Concerning the upper bound, for any c>1, take a=b=2^c-1, then log2 (a*b) = c+c -1 while (log2 a) = (log2 b) = c-1 *)
(** At least, we get back the usual equation when we multiply by 2 (or 2^k) *)
(** Two numbers with same log2 cannot be far away. *)

Lemma log2_same : forall a b, 0<a -> 0<b -> log2 a == log2 b -> a < 2*b.