reserve a,b,m,x,y,i1,i2,i3,i for Integer,
  k,p,q,n for Nat,
  c,c1,c2 for Element of NAT,
  z for set;

theorem Th22:
  for p,q,n being Nat st n>0 holds (p - q) mod n = 0 iff p mod n = q mod n
proof
  let p,q,n be Nat;
  assume
A1: n>0;
  thus (p - q) mod n = 0 implies p mod n = q mod n
  proof
    assume (p - q) mod n = 0;
    then n divides (p - q) by A1,INT_1:62;
    then consider s being Integer such that
A2: n * s = p - q;
    per cases by XXREAL_0:1;
    suppose
      p > q;
      then s > 0 by A2,XREAL_1:50;
      then s in NAT by INT_1:3;
      then reconsider s9=s as Nat;
      p mod n = (n * s9 + q) mod n by A2
        .= q mod n by NAT_D:21;
      hence thesis;
    end;
    suppose
      p = q;
      hence thesis;
    end;
    suppose
A3:   p < q;
A4:   q - p = n * (-s) by A2;
      then (-s) > 0 by A3,XREAL_1:50;
      then (-s) in NAT by INT_1:3;
      then reconsider s9=(-s) as Nat;
      q - p = n * s9 by A4;
      then q mod n = (n * s9 + p) mod n .= p mod n by NAT_D:21;
      hence thesis;
    end;
  end;
  assume
A5: p mod n = q mod n;
  p = n * (p div n) + (p mod n) by A1,NAT_D:2
    .= n * (p div n) + (q - n * (q div n)) by A1,A5,NEWTON:63
    .= q + n * ((p div n) - (q div n));
  then n divides (p - q);
  hence thesis by A1,INT_1:62;
end;
