(* ArithCompl.v *)
(**********************************)
(* Some complements of arithmetic *)
(**********************************)
Require Export Wf_nat.
Require Export ZArith.
Require Export Znumtheory.
Require Export Reals.
Open Scope Z_scope.
Unset Standard Proposition Elimination Names.
(***************)
(* Regarding Z *)
(***************)
Definition is_sqr (n : Z) : Prop :=
0 <= n /\ exists i : Z, i * i = n /\ 0 <= i.
Definition both_odd (x y : Z) := Zodd x /\ Zodd y.
Definition distinct_parity (a b : Z) :=
(Zeven a) /\ (Zodd b) \/ (Zodd a) /\ (Zeven b).
Definition R_prime (x y : Z) := 1 < x /\ 1 < y /\ x < y.
Definition f_Z (x : Z) := Z.abs_nat x.
Definition R_fact (x y : Z) :=
1 < x /\ 1 < y /\ exists q : Z, y = q * x /\ 1 < q.
Definition R_p4 (x y : Z) :=
0 <= x /\ 1 < y /\ exists d : Z, y = d * d * x /\ 1 < d.
(***************)
(* Regarding R *)
(***************)
(***********************)
(* Regarding rationals *)
(***********************)
Definition frac (a b : Z) := ((IZR a) / (IZR b))%R.
Definition is_rat (r : R) :=
exists pq : Z * Z, let (p,q) := pq in ~(q = 0) /\ r = (frac p q).
Definition is_ratp (c : R * R) := let (x,y) := c in (is_rat x) /\ (is_rat y).

Lemma frac_rat : forall a b : Z,
b <> 0 -> (frac a b >= 0)%R -> (frac a b <= 1)%R ->
a >= 0 /\ b > 0 /\ a <= b \/ a <= 0 /\ b < 0 /\ b <= a.