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.

Theorem quadratic_algorithm_is_correct : forall (a b c d e f g h : Z) (q1 q2 : Q) (H_denom : Qplus (Qplus (Qplus (Qmult (Qmult e q1) q2) (Qmult f q1)) (Qmult g q2)) h <> Zero), Qquadratic a b c d e f g h q1 q2 (Qquadratic_denom_nonzero_correct_2 e f g h q1 q2 H_denom) = 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)).