Section comparisons.
(* Fist a function Qcompare is defined, who takes two diadic numbers	*)
(* and answers SUPERIEUR, EGAL or INFERIEUR.				*)
(* Qcompare is similary to Zcompare from the omega library		*)
(* Then the usual predicates "less or equal", "less than", "greater	*)
(* or equal" and "greater than" are defined. Since these predicates	*)
(* are deterministic, the boolean equivalents are also defined	*)
(* Be careful ! Two diadic numbers x, y are equal iff the predicate	*)
(* (Deq x y) is true, that is (Dcompare x y)=EGAL			*)
(* That's not equivalent to : (eq D x y)				*)
Definition Dcompare (x y : diadic) : Datatypes.comparison :=
let nx := Dnum x in
let ny := Dnum y in
let ex := Dexp x in
let ey := Dexp y in
(two_p (ex - Z.min ex ey) * nx ?= two_p (ey - Z.min ex ey) * ny)%Z.
(* Inductive relation := EGAL | INFERIEUR | SUPERIEUR *)
Definition Deq (x y : diadic) :=
match Dcompare x y with
| Datatypes.Eq => True
| Datatypes.Lt => False
| Datatypes.Gt => False
end.
Definition Dneq (x y : diadic) :=
match Dcompare x y with
| Datatypes.Eq => False
| Datatypes.Lt => True
| Datatypes.Gt => True
end.
Definition Dle (x y : diadic) :=
match Dcompare x y with
| Datatypes.Eq => True
| Datatypes.Lt => True
| Datatypes.Gt => False
end.
Definition Dlt (x y : diadic) :=
match Dcompare x y with
| Datatypes.Eq => False
| Datatypes.Lt => True
| Datatypes.Gt => False
end.
Definition Dge (x y : diadic) :=
match Dcompare x y with
| Datatypes.Eq => True
| Datatypes.Lt => False
| Datatypes.Gt => True
end.
Definition Dgt (x y : diadic) :=
match Dcompare x y with
| Datatypes.Eq => False
| Datatypes.Lt => False
| Datatypes.Gt => True
end.
Definition Deq_bool (x y : diadic) :=
match Dcompare x y with
| Datatypes.Eq => true
| Datatypes.Lt => false
| Datatypes.Gt => false
end.
Definition Dneq_bool (x y : diadic) :=
match Dcompare x y with
| Datatypes.Eq => false
| Datatypes.Lt => true
| Datatypes.Gt => true
end.
Definition Dle_bool (x y : diadic) :=
match Dcompare x y with
| Datatypes.Eq => true
| Datatypes.Lt => true
| Datatypes.Gt => false
end.
Definition Dlt_bool (x y : diadic) :=
match Dcompare x y with
| Datatypes.Eq => false
| Datatypes.Lt => true
| Datatypes.Gt => false
end.
Definition Dge_bool (x y : diadic) :=
match Dcompare x y with
| Datatypes.Eq => true
| Datatypes.Lt => false
| Datatypes.Gt => true
end.
Definition Dgt_bool (x y : diadic) :=
match Dcompare x y with
| Datatypes.Eq => false
| Datatypes.Lt => false
| Datatypes.Gt => true
end.

Lemma Dcompare_shift :
forall (x y : diadic) (n : Z),
Dcompare (Dshift n x) (Dshift n y) = Dcompare x y.