(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
Require Export Qhomographic_Qpositive_to_Qpositive.
Definition quadratic_top_more (a b c d e f g h : Z) :=
(e <= a)%Z /\ (f <= b)%Z /\ (g <= c)%Z /\ (h < d)%Z \/
(e <= a)%Z /\ (f <= b)%Z /\ (g < c)%Z /\ (h <= d)%Z \/
(e <= a)%Z /\ (f < b)%Z /\ (g <= c)%Z /\ (h <= d)%Z \/
(e < a)%Z /\ (f <= b)%Z /\ (g <= c)%Z /\ (h <= d)%Z.
intros.
assert
((a + b + c + d + (e - a) + (f - b) + (g - c) + (h - d))%Z =
(0 + e + f + g + h)%Z).
abstract ring.
rewrite H0.
repeat rewrite Zplus_assoc_reverse with (n := (a + b + c + d)%Z).
repeat rewrite Zplus_assoc_reverse with (n := 0%Z).
apply Zplus_lt_le_compat.
assumption.
apply Z.le_refl.
Qed.
Inductive quadraticAcc :
Z -> Z -> Z -> Z -> Z -> Z -> Z -> Z -> Qpositive -> Qpositive -> Prop :=
| quadraticacc0 :
forall (a b c d e f g h : Z) (p1 p2 : Qpositive),
p1 = One ->
homographicAcc (a + c) (b + d) (e + g) (f + h) p2 ->
quadraticAcc a b c d e f g h p1 p2
| quadraticacc0' :
forall (a b c d e f g h : Z) (p1 p2 : Qpositive),
p1 <> One ->
p2 = One ->
homographicAcc (a + b) (c + d) (e + f) (g + h) p1 ->
quadraticAcc a b c d e f g h p1 p2
| quadraticacc1 :
forall (a b c d e f g h : Z) (p1 p2 : Qpositive),
p1 <> One ->
p2 <> One ->
quadratic_top_more a b c d e f g h ->
quadraticAcc (a - e)%Z (b - f)%Z (c - g)%Z (d - h)%Z e f g h p1 p2 ->
quadraticAcc a b c d e f g h p1 p2
| quadraticacc2 :
forall (a b c d e f g h : Z) (p1 p2 : Qpositive),
p1 <> One ->
p2 <> One ->
~ quadratic_top_more a b c d e f g h ->
quadratic_top_more e f g h a b c d ->
quadraticAcc a b c d (e - a)%Z (f - b)%Z (g - c)%Z (h - d)%Z p1 p2 ->
quadraticAcc a b c d e f g h p1 p2
| quadraticacc3_II :
forall (a b c d e f g h : Z) (xs ys : Qpositive),
~ quadratic_top_more a b c d e f g h ->
~ quadratic_top_more e f g h a b c d ->
quadraticAcc a (a + b)%Z (a + c)%Z (a + b + c + d)%Z e
(e + f)%Z (e + g)%Z (e + f + g + h)%Z xs ys ->
quadraticAcc a b c d e f g h (nR xs) (nR ys)
| quadraticacc3_IO :
forall (a b c d e f g h : Z) (xs ys : Qpositive),
~ quadratic_top_more a b c d e f g h ->
~ quadratic_top_more e f g h a b c d ->
quadraticAcc (a + b)%Z b (a + b + c + d)%Z (b + d)%Z
(e + f)%Z f (e + f + g + h)%Z (f + h)%Z xs ys ->
quadraticAcc a b c d e f g h (nR xs) (dL ys)
| quadraticacc3_OI :
forall (a b c d e f g h : Z) (xs ys : Qpositive),
~ quadratic_top_more a b c d e f g h ->
~ quadratic_top_more e f g h a b c d ->
quadraticAcc (a + c)%Z (a + b + c + d)%Z c (c + d)%Z
(e + g)%Z (e + f + g + h)%Z g (g + h)%Z xs ys ->
quadraticAcc a b c d e f g h (dL xs) (nR ys)
| quadraticacc3_OO :
forall (a b c d e f g h : Z) (xs ys : Qpositive),
~ quadratic_top_more a b c d e f g h ->
~ quadratic_top_more e f g h a b c d ->
quadraticAcc (a + b + c + d)%Z (b + d)%Z (c + d)%Z d
(e + f + g + h)%Z (f + h)%Z (g + h)%Z h xs ys ->
quadraticAcc a b c d e f g h (dL xs) (dL ys).
*)
Definition octet_lt (a b c d e f g h : Z) (p1 p2 : Qpositive)
(a' b' c' d' e' f' g' h' : Z) (p1' p2' : Qpositive) : Prop :=
bin_lt p1 p1' \/
p1 = p1' /\
(a + b + c + d + e + f + g + h < a' + b' + c' + d' + e' + f' + g' + h')%Z.
Definition octointegral_lt (a b c d e f g h a' b' c' d' e' f' g' h' : Z) :=
(a + b + c + d + e + f + g + h < a' + b' + c' + d' + e' + f' + g' + h')%Z.
Definition octointegral_eq (a b c d e f g h a' b' c' d' e' f' g' h' : Z) :=
a = a' /\
b = b' /\ c = c' /\ d = d' /\ e = e' /\ f = f' /\ g = g' /\ h = h'.
Record Z8 : Set :=
{z8crr :> Z * Z * (Z * Z) * (Z * Z * (Z * Z));
z8prf :
(0 <= fst (fst (fst z8crr)))%Z /\
(0 <= snd (fst (fst z8crr)))%Z /\
(0 <= fst (snd (fst z8crr)))%Z /\
(0 <= snd (snd (fst z8crr)))%Z /\
(0 <= fst (fst (snd z8crr)))%Z /\
(0 <= snd (fst (snd z8crr)))%Z /\
(0 <= fst (snd (snd z8crr)))%Z /\ (0 <= snd (snd (snd z8crr)))%Z}.
Definition Z8_lt : Z8 -> Z8 -> Prop.
intros x y.
case (z8crr x).
intros W1 W2.
case (z8crr y).
intros W3 W4.
case W1.
intros V1 V2.
case W2.
intros V3 V4.
case W3.
intros U1 U2.
case W4.
intros U3 U4.
case V1.
intros a b.
case V2.
intros c d.
case V3.
intros e f.
case V4.
intros g h.
case U1.
intros a' b'.
case U2.
intros c' d'.
case U3.
intros e' f'.
case U4.
intros g' h'.
exact (octointegral_lt a b c d e f g h a' b' c' d' e' f' g' h').
Defined.
Definition Z8_eq : Z8 -> Z8 -> Prop.
intros x y.
case (z8crr x).
intros W1 W2.
case (z8crr y).
intros W3 W4.
case W1.
intros V1 V2.
case W2.
intros V3 V4.
case W3.
intros U1 U2.
case W4.
intros U3 U4.
case V1.
intros a b.
case V2.
intros c d.
case V3.
intros e f.
case V4.
intros g h.
case U1.
intros a' b'.
case U2.
intros c' d'.
case U3.
intros e' f'.
case U4.
intros g' h'.
exact (octointegral_eq a b c d e f g h a' b' c' d' e' f' g' h').
Defined.
Definition Z8_as_well_ordering :=
Build_well_ordering Z8 Z8_lt Z8_eq Z8_lt_is_order Z8_eq_is_equality
Z8_lt_is_wf Z8_lt_is_well_def_rht.
Definition Qpositive2 := (Qpositive * Qpositive)%type.
Definition bin2_lt (x y : Qpositive2) :=
let (p1, p2) := x in let (p1', p2) := y in bin_lt p1 p1'.
Definition bin2_eq (x y : Qpositive2) :=
let (p1, p2) := x in let (p1', p2) := y in p1 = p1'.
Definition Qpositive2_as_well_ordering :=
Build_well_ordering Qpositive2 bin2_lt bin2_eq bin2_lt_is_order
bin2_eq_is_equality bin2_lt_is_wf bin2_lt_is_well_def_rht.
(** Proof independence of Qquadratic_Qpositive_to_Qpositive: *)
Scheme quadraticAcc_ind_dep := Induction for quadraticAcc Sort Prop.
(** Here we expand the fixpoint equations of "Qquadratic_Qpositive_to_Qpositive" function *)

Lemma Qquadratic_Qpositive_to_Qpositive_2 :
forall (a b c d e f g h : Z) (p1 p2 : Qpositive)
(hyp : quadraticAcc a b c d e f g h p1 p2),
p1 <> One ->
p2 <> One ->
~ quadratic_top_more a b c d e f g h ->
quadratic_top_more e f g h a b c d ->
forall hyp_rec : quadraticAcc a b c d (e - a) (f - b) (g - c) (h - d) p1 p2,
Qquadratic_Qpositive_to_Qpositive a b c d e f g h p1 p2 hyp =
dL
(Qquadratic_Qpositive_to_Qpositive a b c d (e - a)
(f - b) (g - c) (h - d) p1 p2 hyp_rec).