Fixpoint Qquadratic_Qpositive_to_Qpositive (a b c d e f g h : Z)
 (p1 p2 : Qpositive) (hyp : quadraticAcc a b c d e f g h p1 p2) {struct hyp} 
   : Qpositive :=
  match Qpositive_dec_One p1 with
  | left Hp1 =>
      Qhomographic_Qpositive_to_Qpositive (a + c) (b + d) 
        (e + g) (f + h) p2 (quadraticacc_0 a b c d e f g h p1 p2 hyp Hp1)
  | right Hp1 =>
      match Qpositive_dec_One p2 with
      | left Hp2 =>
          Qhomographic_Qpositive_to_Qpositive (a + b) 
            (c + d) (e + f) (g + h) p1
            (quadraticacc_0' a b c d e f g h p1 p2 hyp Hp1 Hp2)
      | right Hp2 =>
          match quadratic_top_more_informative a b c d e f g h with
          | left Habcdefgh =>
              nR
                (Qquadratic_Qpositive_to_Qpositive 
                   (a - e)%Z (b - f)%Z (c - g)%Z (d - h)%Z e f g h p1 p2
                   (quadraticacc_1 a b c d e f g h p1 p2 hyp Hp1 Hp2
                      Habcdefgh))
          | right Habcdefgh =>
              match quadratic_top_more_informative e f g h a b c d with
              | left Hefghabcd =>
                  dL
                    (Qquadratic_Qpositive_to_Qpositive a b c d 
                       (e - a)%Z (f - b)%Z (g - c)%Z 
                       (h - d)%Z p1 p2
                       (quadraticacc_2 a b c d e f g h p1 p2 hyp Hp1 Hp2
                          Habcdefgh Hefghabcd))
              | right Hefghabcd =>
                  match p1 as q return (p1 = q -> Qpositive) with
                  | nR x =>
                      match
                        p2 as q
                        return
                          (p2 = q ->
                           forall q0 : Qpositive, p1 = nR q0 -> Qpositive)
                      with
                      | nR ys =>
                          fun (Hys : p2 = nR ys) (xs : Qpositive)
                            (Hxs : p1 = nR xs) =>
                          Qquadratic_Qpositive_to_Qpositive 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_3_II a b c d e f g h p1 p2 hyp xs
                               ys Hxs Hys Habcdefgh Hefghabcd)
                      | dL ys =>
                          fun (Hys : p2 = dL ys) (xs : Qpositive)
                            (Hxs : p1 = nR xs) =>
                          Qquadratic_Qpositive_to_Qpositive 
                            (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_3_IO a b c d e f g h p1 p2 hyp xs
                               ys Hxs Hys Habcdefgh Hefghabcd)
                      | One =>
                          fun Hp2_ : p2 = One =>
                          False_rec
                            (forall q : Qpositive, p1 = nR q -> Qpositive)
                            (False_ind False (Hp2 Hp2_))
                      end (refl_equal p2) x
                  | dL x =>
                      match
                        p2 as q
                        return
                          (p2 = q ->
                           forall q0 : Qpositive, p1 = dL q0 -> Qpositive)
                      with
                      | nR ys =>
                          fun (Hys : p2 = nR ys) (xs : Qpositive)
                            (Hxs : p1 = dL xs) =>
                          Qquadratic_Qpositive_to_Qpositive 
                            (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_3_OI a b c d e f g h p1 p2 hyp xs
                               ys Hxs Hys Habcdefgh Hefghabcd)
                      | dL ys =>
                          fun (Hys : p2 = dL ys) (xs : Qpositive)
                            (Hxs : p1 = dL xs) =>
                          Qquadratic_Qpositive_to_Qpositive 
                            (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_3_OO a b c d e f g h p1 p2 hyp xs
                               ys Hxs Hys Habcdefgh Hefghabcd)
                      | One =>
                          fun Hp2_ : p2 = One =>
                          False_rec
                            (forall q : Qpositive, p1 = dL q -> Qpositive)
                            (False_ind False (Hp2 Hp2_))
                      end (refl_equal p2) x
                  | One =>
                      fun Hp1_ : p1 = One =>
                      False_rec Qpositive (False_ind False (Hp1 Hp1_))
                  end (refl_equal p1)
              end
          end
      end
  end.(** The interactive version of the above definition :
Definition Qquadratic_Qpositive_to_Qpositive [a,b,c,d,e,f,g,h:Z; p1,p2:Qpositive; hyp:(quadraticAcc a b c d e f g h p1 p2)]:Qpositive.
Refine (Fix Qquadratic_Qpositive_to_Qpositive { Qquadratic_Qpositive_to_Qpositive[a,b,c,d,e,f,g,h:Z; p1,p2:Qpositive; hyp:(quadraticAcc a b c d e f g h p1 p2)]:Qpositive:=?}). 
Case (Qpositive_dec_One p1);
Intro Hp1.
 Exact (Qhomographic_Qpositive_to_Qpositive `a+c` `b+d` `e+g` `f+h` p2 (quadraticacc_0 ?????????? hyp Hp1)). 
 Case (Qpositive_dec_One p2);
 Intro Hp2.
  Exact (Qhomographic_Qpositive_to_Qpositive `a+b` `c+d` `e+f` `g+h` p1 (quadraticacc_0' ?????????? hyp Hp1 Hp2)). 
  Case (quadratic_top_more_informative a b c d e f g h);
  Intro Habcdefgh. 
   Exact (nR (Qquadratic_Qpositive_to_Qpositive `a-e` `b-f` `c-g` `d-h` e f g h p1 p2 (quadraticacc_1 ?????????? hyp Hp1 Hp2 Habcdefgh))).
   Case (quadratic_top_more_informative e f g h a b c d);
   Intro Hefghabcd.
    Exact (dL (Qquadratic_Qpositive_to_Qpositive a b c d `e-a` `f-b` `g-c` `h-d` p1 p2 (quadraticacc_2 ?????????? hyp Hp1 Hp2 Habcdefgh Hefghabcd))).
    CaseEq p1; [ Idtac | Idtac| Intro Hp1_; Apply False_rec; Falsum]; 
    CaseEq p2.
      Intros ys Hys xs Hxs.
      Refine (Qquadratic_Qpositive_to_Qpositive a `a+b` `a+c` `a+b+c+d` e `e+f` `e+g` `e+f+g+h` xs ys ?).
      Apply (quadraticacc_3_II ?????????? hyp ?? Hxs Hys Habcdefgh Hefghabcd).
      Intros ys Hys xs Hxs.
      Refine (Qquadratic_Qpositive_to_Qpositive `a+b` b `a+b+c+d` `b+d` `e+f` f `e+f+g+h` `f+h` xs ys ?).
      Apply (quadraticacc_3_IO ?????????? hyp ?? Hxs Hys Habcdefgh Hefghabcd).
      Intro Hp2_; Apply False_rec; Falsum.

      Intros ys Hys xs Hxs.
      Refine (Qquadratic_Qpositive_to_Qpositive `a+c` `a+b+c+d` c `c+d` `e+g` `e+f+g+h` g `g+h` xs ys ?).
      Apply (quadraticacc_3_OI ?????????? hyp ?? Hxs Hys Habcdefgh Hefghabcd).
      Intros ys Hys xs Hxs.
      Refine (Qquadratic_Qpositive_to_Qpositive `a+b+c+d` `b+d` `c+d` d `e+f+g+h` `f+h` `g+h` h xs ys ?).
      Apply (quadraticacc_3_OO ?????????? hyp ?? Hxs Hys Habcdefgh Hefghabcd).
      Intro Hp2_; Apply False_rec; Falsum.
Qed.
*)




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}.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}.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.Definition Z8_eq : Z8 -> Z8 -> Prop.

Lemma Z8_lt_is_transitive : forall x y z : Z8, Z8_lt x y -> Z8_lt y z -> Z8_lt x z.