(* 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).

Lemma quadraticacc_0 :
forall (a b c d e f g h : Z) (p1 p2 : Qpositive),
quadraticAcc a b c d e f g h p1 p2 ->
p1 = One -> homographicAcc (a + c) (b + d) (e + g) (f + h) p2.