MSB

# Library MSB

`Require Export Fprop.
Require Export Zdivides.
Require Export Fnorm.
Section mf.
Variable radix : Z.
Hypothesis radixMoreThanOne : (1 < radix)%Z.
Let radixMoreThanZERO := Zlt_1_O _ (Zlt_le_weak _ _ radixMoreThanOne).
Hint Resolve radixMoreThanZERO: zarith.
Coercion Local FtoRradix := FtoR radix.
Fixpoint maxDiv (v : Z) (p : nat) {struct p} : nat :=
match p with
| O => 0
| S p' =>
match ZdividesP v (Zpower_nat radix p) with
| left _ => p
| right _ => maxDiv v p'
end
end.
Theorem maxDivLess : forall (v : Z) (p : nat), maxDiv v p <= p.
Theorem maxDivLt :
forall (v : Z) (p : nat),
~ Zdivides v (Zpower_nat radix p) -> maxDiv v p < p.
Theorem maxDivCorrect :
forall (v : Z) (p : nat), Zdivides v (Zpower_nat radix (maxDiv v p)).
Theorem maxDivSimplAux :
forall (v : Z) (p q : nat),
p = maxDiv v (S (q + p)) -> p = maxDiv v (S p).
Theorem maxDivSimpl :
forall (v : Z) (p q : nat),
p < q -> p = maxDiv v q -> p = maxDiv v (S p).
Theorem maxDivSimplInvAux :
forall (v : Z) (p q : nat),
p = maxDiv v (S p) -> p = maxDiv v (S (q + p)).
Theorem maxDivSimplInv :
forall (v : Z) (p q : nat),
p < q -> p = maxDiv v (S p) -> p = maxDiv v q.
Theorem maxDivUnique :
forall (v : Z) (p : nat),
p = maxDiv v (S p) ->
Zdivides v (Zpower_nat radix p) /\ ~ Zdivides v (Zpower_nat radix (S p)).
Theorem maxDivUniqueDigit :
forall v : Z,
v <> 0 ->
Zdivides v (Zpower_nat radix (maxDiv v (digit radix v))) /\
~ Zdivides v (Zpower_nat radix (S (maxDiv v (digit radix v)))).
Theorem maxDivUniqueInverse :
forall (v : Z) (p : nat),
Zdivides v (Zpower_nat radix p) ->
~ Zdivides v (Zpower_nat radix (S p)) -> p = maxDiv v (S p).
Theorem maxDivUniqueInverseDigit :
forall (v : Z) (p : nat),
v <> 0 ->
Zdivides v (Zpower_nat radix p) ->
~ Zdivides v (Zpower_nat radix (S p)) -> p = maxDiv v (digit radix v).
Theorem maxDivPlus :
forall (v : Z) (n : nat),
v <> 0 ->
maxDiv (v * Zpower_nat radix n) (digit radix v + n) =
maxDiv v (digit radix v) + n.
Definition LSB (x : float) :=
(Z_of_nat (maxDiv (Fnum x) (Fdigit radix x)) + Fexp x)%Z.
Theorem LSB_shift :
forall (x : float) (n : nat), ~ is_Fzero x -> LSB x = LSB (Fshift radix n x).
Theorem LSB_comp :
forall (x y : float) (n : nat), ~ is_Fzero x -> x = y :>R -> LSB x = LSB y.
Theorem maxDiv_opp :
forall (v : Z) (p : nat), maxDiv v p = maxDiv (- v) p.
Theorem LSB_opp : forall x : float, LSB x = LSB (Fopp x).
Theorem maxDiv_abs :
forall (v : Z) (p : nat), maxDiv v p = maxDiv (Zabs v) p.
Theorem LSB_abs : forall x : float, LSB x = LSB (Fabs x).
Definition MSB (x : float) := Zpred (Z_of_nat (Fdigit radix x) + Fexp x).
Theorem MSB_shift :
forall (x : float) (n : nat), ~ is_Fzero x -> MSB x = MSB (Fshift radix n x).
Theorem MSB_comp :
forall (x y : float) (n : nat), ~ is_Fzero x -> x = y :>R -> MSB x = MSB y.
Theorem MSB_opp : forall x : float, MSB x = MSB (Fopp x).
Theorem MSB_abs : forall x : float, MSB x = MSB (Fabs x).
Theorem LSB_le_MSB : forall x : float, ~ is_Fzero x -> (LSB x <= MSB x)%Z.
Theorem Fexp_le_LSB : forall x : float, (Fexp x <= LSB x)%Z.
Theorem Ulp_Le_LSigB :
forall x : float, (Float 1%nat (Fexp x) <= Float 1%nat (LSB x))%R.
Theorem Fexp_le_MSB : forall x : float, ~ is_Fzero x -> (Fexp x <= MSB x)%Z.
Theorem MSB_le_abs :
forall x : float, ~ is_Fzero x -> (Float 1%nat (MSB x) <= Fabs x)%R.
Theorem abs_lt_MSB :
forall x : float, (Fabs x < Float 1%nat (Zsucc (MSB x)))%R.
Theorem LSB_le_abs :
forall x : float, ~ is_Fzero x -> (Float 1%nat (LSB x) <= Fabs x)%R.
Theorem MSB_monotoneAux :
forall x y : float,
(Fabs x <= Fabs y)%R -> Fexp x = Fexp y -> (MSB x <= MSB y)%Z.
Theorem MSB_monotone :
forall x y : float,
~ is_Fzero x -> ~ is_Fzero y -> (Fabs x <= Fabs y)%R -> (MSB x <= MSB y)%Z.
Theorem MSB_le_multAux :
forall x y : float,
~ is_Fzero x -> ~ is_Fzero y -> (MSB x + MSB y <= MSB (Fmult x y))%Z.
Theorem MSB_le_mult :
forall x y : float,
~ is_Fzero x ->
~ is_Fzero y ->
(Fmult (Float 1%nat (MSB x)) (Float 1%nat (MSB y)) <=
Float 1%nat (MSB (Fmult x y)))%R.
Theorem mult_le_MSBAux :
forall x y : float,
~ is_Fzero x -> ~ is_Fzero y -> (MSB (Fmult x y) <= Zsucc (MSB x + MSB y))%Z.
Theorem mult_le_MSB :
forall x y : float,
~ is_Fzero x ->
~ is_Fzero y ->
(Float 1%nat (MSB (Fmult x y)) <=
radix * Fmult (Float 1%nat (MSB x)) (Float 1%nat (MSB y)))%R.
Theorem MSB_mix :
forall x y : float,
~ is_Fzero x ->
~ is_Fzero y ->
(Fabs x * Float 1%nat (MSB y) < radix * (Fabs y * Float 1%nat (MSB x)))%R.
Theorem LSB_rep :
forall x y : float,
~ is_Fzero y ->
(LSB x <= LSB y)%Z -> exists z : Z, y = Float z (Fexp x) :>R.
Theorem LSB_rep_min :
forall p : float, exists z : Z, p = Float z (LSB p) :>R.
End mf.
`