Ltac Rewrite_eq_ :=
  repeat
   match goal with
   | id1:(_ = left _ _) |- _ => rewrite id1; clear id1
   | id1:(_ = right _ _) |- _ => rewrite id1; clear id1
   | id1:(_ = inleft _ _) |- _ =>
       rewrite id1; clear id1
   | id1:(_ = inright _ _) |- _ => rewrite id1; clear id1
   end.Ltac Clear_eq_ :=
  repeat
   match goal with
   | id1:(_ = left _ _) |- _ => clear id1
   | id1:(_ = right _ _) |- _ => clear id1
   | id1:(_ = inleft _ _) |- _ => clear id1
   | id1:(_ = inright _ _) |- _ => clear id1
   end.Ltac Sign_mismatch :=
  Clear_eq_;
   match goal with
   | id1:(?X1 = 1%Z),id2:(?X1 = 0%Z) |- _ =>
       rewrite id2 in id1; discriminate id1
   | id1:(?X1 = 0%Z),id2:(?X1 = 1%Z) |- _ =>
       rewrite id2 in id1; discriminate id1
   | id1:(?X1 = (-1)%Z),id2:(?X1 = 0%Z) |- _ =>
       rewrite id2 in id1; discriminate id1
   | id1:(?X1 = 0%Z),id2:(?X1 = (-1)%Z) |- _ =>
       rewrite id2 in id1; discriminate id1
   | id1:(?X1 = 1%Z),id2:(?X1 = (-1)%Z) |- _ =>
       rewrite id2 in id1; discriminate id1
   | id1:(?X1 = (-1)%Z),id2:(?X1 = 1%Z) |- _ =>
       rewrite id2 in id1; discriminate id1
   end.

Lemma Qhomographic_Qpositive_to_Q_0 : forall (a b c d : Z) (p : Qpositive) (H_Qhomographic_sg_denom_nonzero : Qhomographic_sg_denom_nonzero c d p) (Hc : c <> 0%Z), (a * d)%Z = (b * c)%Z -> d = 0%Z -> Qhomographic_Qpositive_to_Q a b c d p H_Qhomographic_sg_denom_nonzero = fraction_encoding a c Hc.