Section Z_compl.
Local Open Scope Z_scope.
(* Provides a way to reason directly on Z in terms of nats instead of positive *)
Inductive Z_spec (x : Z) : Z -> Type :=
| ZintNull : x = 0 -> Z_spec x 0
| ZintPos (n : nat) : x = n -> Z_spec x n
| ZintNeg (n : nat) : x = - n -> Z_spec x (- n).
End Z_compl.
Definition powerRZ (x:R) (n:Z) :=
match n with
| Z0 => 1
| Zpos p => x ^ Pos.to_nat p
| Zneg p => / x ^ Pos.to_nat p
end.
Local Infix "^Z" := powerRZ (at level 30, right associativity) : R_scope.
Hint Resolve powerRZ_O powerRZ_1 powerRZ_NOR powerRZ_add: real.
Hint Resolve powerRZ_lt: real.
Hint Resolve powerRZ_le: real.
Local Open Scope Z_scope.
End PowerRZ.
Local Infix "^Z" := powerRZ (at level 30, right associativity) : R_scope.
(*******************************)
(* For easy interface          *)
(*******************************)
(* decimal_exp r z is defined as r 10^z *)
Definition decimal_exp (r:R) (z:Z) : R := (r * 10 ^Z z).
(*******************************)
(** * Sum of n first naturals  *)
(*******************************)
(*********)
Fixpoint sum_nat_f_O (f:nat -> nat) (n:nat) : nat :=
match n with
| O => f 0%nat
| S n' => (sum_nat_f_O f n' + f (S n'))%nat
end.
(*********)
Definition sum_nat_f (s n:nat) (f:nat -> nat) : nat :=
sum_nat_f_O (fun x:nat => f (x + s)%nat) (n - s).
(*********)
Definition sum_nat_O (n:nat) : nat := sum_nat_f_O (fun x:nat => x) n.
(*********)
Definition sum_nat (s n:nat) : nat := sum_nat_f s n (fun x:nat => x).
(*******************************)
(** *          Sum             *)
(*******************************)
(*********)
Fixpoint sum_f_R0 (f:nat -> R) (N:nat) : R :=
match N with
| O => f 0%nat
| S i => sum_f_R0 f i + f (S i)
end.
(*********)
Definition sum_f (s n:nat) (f:nat -> R) : R :=
sum_f_R0 (fun x:nat => f (x + s)%nat) (n - s).
(*******************************)
(** *     Distance  in R       *)
(*******************************)
(*********)
Definition R_dist (x y:R) : R := Rabs (x - y).

(*********)
Lemma R_dist_refl : forall x y:R, R_dist x y = 0 <-> x = y.