reserve n,m,k for Nat,
        p,q for n-element XFinSequence of NAT,
        i1,i2,i3,i4,i5,i6 for Element of n,
        a,b,c,d,e for Integer;

theorem Th21:
  for a,b,c,i1,i2,i3 holds
    {p: a*p.i1,b*p.i2 are_congruent_mod c*p.i3}
       is diophantine Subset of n -xtuples_of NAT
proof
  let a,b,c,i1,i2,i3;
  defpred P[XFinSequence of NAT] means ex z be Nat st a*$1.i1
  = b*$1.i2+ z*c*$1.i3;
  defpred Q[XFinSequence of NAT] means ex z be Nat st b*$1.i2
  = a*$1.i1+ z*c*$1.i3;
  A1:{p:P[p]} is diophantine Subset of n -xtuples_of NAT by Th10;
  A2:{p:Q[p]} is diophantine Subset of n -xtuples_of NAT by Th10;
  A3:{p:P[p] or Q[p]}is diophantine Subset of n -xtuples_of NAT
    from UnionDiophantine(A1,A2);
  set PP={p: a*p.i1,b*p.i2 are_congruent_mod c*p.i3};
  A4:PP c= {p:P[p] or Q[p]}
  proof
    let x be object;
    assume x in PP;
    then consider p such that
    A5:x= p & a*p.i1,b*p.i2 are_congruent_mod c*p.i3;
    consider i be Integer such that
    A6: (c*p.i3)*i = a*p.i1-b*p.i2 by A5,INT_1:def 5;
    per cases;
    suppose i>=0;
      then reconsider i as Element of NAT by INT_1:3;
      a*p.i1=b*p.i2+i*c*p.i3 by A6;
      hence thesis by A5;
    end;
    suppose i<0;
      then reconsider I=- i as Element of NAT by INT_1:3;
      A7: a*p.i1=b*p.i2+i*c*p.i3 by A6;
      a*p.i1=b*p.i2+(-I)*c*p.i3 by A7;
      then b*p.i2=a*p.i1+I*c*p.i3;
      hence thesis by A5;
    end;
  end;
  {p:P[p] or Q[p]} c= PP
  proof
    let x be object;
    assume x in {p:P[p] or Q[p]};
    then consider p such that
    A8:x= p & (P[p] or Q[p]);
    per cases by A8;
    suppose P[p];
      then consider z be Nat such that A9: a*p.i1 = b*p.i2+ z*c*p.i3;
      z*(c*p.i3) = a*p.i1 - b*p.i2 by A9;
      then a*p.i1,b*p.i2 are_congruent_mod c*p.i3 by INT_1:def 5;
      hence x in PP by A8;
    end;
    suppose Q[p];
      then consider z be Nat such that A10: b*p.i2 = a*p.i1+ z*c*p.i3;
      (-z)*(c*p.i3) =   a*p.i1 - b*p.i2 by A10;
      then a*p.i1, b*p.i2 are_congruent_mod c*p.i3 by INT_1:def 5;
      hence x in PP by A8;
    end;
  end;
  hence thesis by A3,A4,XBOOLE_0:def 10;
end;
