(* 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 homographic_correctness.
Require Export Qquadratic_sign.
Require Export Qquadratic_Qpositive_to_Qpositive.
Require Export Qquadratic_sign_properties.
Require Export Qquadratic.
Require Export quadraticAcc_Qquadratic_sign.
Require Export Qquadratic_Qpositive_to_Q_properties.
Definition spec_q (a b c d e f g h : Z) (q1 q2 : Q) : Q :=
Qmult
(Qplus (Qplus (Qplus (Qmult (Qmult a q1) q2) (Qmult b q1)) (Qmult c q2))
d)
(Qinv
(Qplus
(Qplus (Qplus (Qmult (Qmult e q1) q2) (Qmult f q1)) (Qmult g q2)) h)).
Definition spec_Qquadratic_Qpositive_to_Q (a b c d e f g h : Z)
(p1 p2 : Qpositive) : Q :=
Qmult
(Qplus
(Qplus
(Qplus (Qmult (Qmult a (Qpos p1)) (Qpos p2)) (Qmult b (Qpos p1)))
(Qmult c (Qpos p2))) d)
(Qinv
(Qplus
(Qplus
(Qplus (Qmult (Qmult e (Qpos p1)) (Qpos p2)) (Qmult f (Qpos p1)))
(Qmult g (Qpos p2))) h)).
(* Here we should expect that ap1p2+bp1+cp2+d > 0 and ep1p1+fp1+gp2+h > 0, this follow - hopefully - from quadraticAcc *)
Definition spec_Qquadratic_Qpositive_to_Qpositive2
(a b c d e f g h : Z) (p1 p2 : Qpositive) : Qpositive :=
Qpositive_mult
(Q_tail
(Qplus
(Qplus
(Qplus (Qmult (Qmult a (Qpos p1)) (Qpos p2)) (Qmult b (Qpos p1)))
(Qmult c (Qpos p2))) d))
(Qpositive_inv
(Q_tail
(Qplus
(Qplus
(Qplus (Qmult (Qmult e (Qpos p1)) (Qpos p2))
(Qmult f (Qpos p1))) (Qmult g (Qpos p2))) h))).
Proof spec_Qquadratic_Qpositive_to_Q_p_One.
Proof spec_Qquadratic_Qpositive_to_Q_One_p.
Proof spec_Qquadratic_Qpositive_to_Q_nR_nR.
Proof spec_Qquadratic_Qpositive_to_Q_nR_dL.
Proof spec_Qquadratic_Qpositive_to_Q_dL_nR.
Proof spec_Qquadratic_Qpositive_to_Q_dL_dL.
Ltac Inside_Square_Qsgn_ p1 p2 :=
repeat
match goal with
| id1:(?X1 < ?X2)%Z |- _ =>
unfold X2 in id1 || unfold X1 in id1;
repeat
match goal with
| id1:(2 < outside_square ?X1 ?X2 ?X3 ?X4)%Z,id2:
(~ (?X2 = 0%Z /\ ?X3 = 0%Z /\ ?X4 = 0%Z)) |- _ =>
generalize
(Qsgn_7 _ (outside_square_correct_1 X1 X2 X3 X4 p1 p2 id1 id2));
clear id1
| id1:(outside_square ?X1 ?X2 ?X3 ?X4 < -2)%Z,id2:
(~ (?X2 = 0%Z /\ ?X3 = 0%Z /\ ?X4 = 0%Z)) |- _ =>
generalize
(Qsgn_8 _ (outside_square_correct_2 X1 X2 X3 X4 p1 p2 id1 id2));
clear id1
end
end.

Lemma quadratic_sign :
forall (a b c d e f g h : Z) (p1 p2 : Qpositive)
(H_Qquadratic_sg_denom_nonzero : Qquadratic_sg_denom_nonzero e f g h p1 p2),
q_sign a b c d e f g h p1 p2 H_Qquadratic_sg_denom_nonzero =
Qsgn (spec_Qquadratic_Qpositive_to_Q a b c d e f g h p1 p2).