(****************************************************************************  IEEE754  :  Zenum  Laurent Thery  ***************************************************************************** Simple functions to enumerate relative numbers *)
Require Export Faux.
Require Export Omega.
Require Export List.
(* Returns the list of relative numbers from z to z+n *)
Fixpoint mZlist_aux (p : Z) (n : nat) {struct n} :
list Z :=
match n with
| O => p :: nil
| S n1 => p :: mZlist_aux (Z.succ p) n1
end.
intros n; elim n; clear n; auto.
intros p q; try rewrite <- Zplus_0_r_reverse.
intros H' H'0; simpl in |- *; left.
apply Zle_antisym; auto.
intros n H' p q H'0 H'1; case (Zle_lt_or_eq _ _ H'0); intros H'2.
simpl in |- *; right.
apply H'; auto with zarith.
rewrite Zplus_succ_comm.
rewrite <- inj_S; auto.
simpl in |- *; auto.
Qed.
intros n; elim n; clear n; simpl in |- *; auto.
intros p q H'; elim H'; auto with zarith.
intros n H' p q H'0; elim H'0; auto with zarith.
intros H'1; apply Zle_succ_le; auto with zarith.
Qed.
intros n; elim n; clear n; auto.
intros p q H'; elim H'; auto with zarith.
intros H'0; elim H'0.
intros n H' p q H'0; elim H'0; auto with zarith.
intros H'1; rewrite inj_S; rewrite <- Zplus_succ_comm; auto.
Qed.
(* Return the list of of relative numbres from p to p+q if p=<q, otherwise the empty list *)
Definition mZlist (p q : Z) : list Z :=
match (q - p)%Z with
| Z0 => p :: nil
| Zpos d => mZlist_aux p (nat_of_P d)
| Zneg _ => nil (A:=Z)
end.

Theorem mZlist_correct :
forall p q r : Z, (p <= r)%Z -> (r <= q)%Z -> In r (mZlist p q).