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;
reserve fp,fp1 for FinSequence of NAT,

  b,c,d, n for Element of NAT,
  a for Nat;
reserve i,m,m1,m2,m3,r,s,a,b,c,c1,c2,x,y for Integer;
reserve

  a,b,c,m for Element of NAT;

theorem Th52:
  for X being finite Subset of INT st card X = m & (for x,y being
Integer st x in X & y in X & x<>y holds not [x,y] in Cong m) holds X is_CRS_of
  m
proof
  let X be finite Subset of INT;
  assume that
A1: card X = m and
A2: for x,y being Integer st x in X & y in X & x<>y holds not [x,y] in Cong(m);
  per cases;
  suppose
    X is empty;
    hence thesis by A1,Th50;
  end;
  suppose
    X is non empty;
    then reconsider X as non empty finite Subset of INT;
    defpred P[Nat,set] means $2 in Class(Cong(m),$1-'1);
A3: X <> {};
A4: for a be Nat st a in Seg m ex y being Element of X st P[a,y]
    proof
      set Y = Segm m;
      let a be Nat such that
A5:   a in Seg m;
      a<=m by A5,FINSEQ_1:1;
      then
A6:   a-1<m by XREAL_1:147;
      consider fp being FinSequence such that
A7:   len fp = m and
A8:   for b st b in dom fp holds fp.b in X and
A9:   fp is one-to-one by A1,Th51;
      for b being Nat st b in dom fp holds fp.b in X by A8;
      then reconsider fp as FinSequence of X by FINSEQ_2:12;
      defpred PP[Nat,set] means fp.$1 in Class(Cong(m),$2);
A10:  for c st c in Seg m ex r being Element of Y st PP[c,r]
      proof
        let c;
        assume c in Seg m;
        consider q,r being Integer such that
A11:    fp.c = m * q + r and
A12:    r >= 0 and
A13:    r < m by A1,Th13;
        fp.c mod m = r mod m by A11,NAT_D:61;
        then r,fp.c are_congruent_mod m by A1,NAT_D:64;
        then
A14:    [r,fp.c] in Cong(m) by Def1;
        reconsider r as Element of NAT by A12,INT_1:3;
        reconsider r as Element of Y by A13,NAT_1:44;
        take r;
        thus thesis by A14,EQREL_1:18;
      end;
      reconsider Y as non empty set by A1,A3;
A15:  for c be Nat st c in Seg m ex r being Element of Y st PP[c,r] by A10;
      consider fr being FinSequence of Y such that
A16:  dom fr = Seg m & for c be Nat st c in Seg m holds PP[c,fr.c]
      from FINSEQ_1:sch 5(A15);
      for x1,x2 being object st x1 in dom fr & x2 in dom fr & fr.x1 = fr.x2
      holds x1 = x2
      proof
        let x1,x2 be object;
        assume that
A17:    x1 in dom fr and
A18:    x2 in dom fr and
A19:    fr.x1 = fr.x2;
        fp.x1 in Class(Cong(m),fr.x1) & fp.x2 in Class(Cong(m),fr.x1) by A16
,A17,A18,A19;
        then
A20:    [fp.x1,fp.x2] in Cong(m) by EQREL_1:22;
        assume
A21:    x1 <> x2;
        reconsider x1,x2 as Element of NAT by A17,A18;
A22:    x1 in dom fp by A7,A16,A17,FINSEQ_1:def 3;
        then
A23:    fp.x1 in X by FINSEQ_2:11;
A24:    x2 in dom fp by A7,A16,A18,FINSEQ_1:def 3;
        then
A25:    fp.x2 in X by FINSEQ_2:11;
        fp.x1 <> fp.x2 by A9,A21,A22,A24;
        hence contradiction by A2,A20,A23,A25;
      end;
      then fr is one-to-one;
      then
A26:  card rng fr = len fr by FINSEQ_4:62
        .= m by A16,FINSEQ_1:def 3;
      reconsider Y as finite set;
      a>=1 by A5,FINSEQ_1:1;
      then a-'1<m by A6,XREAL_1:233;
      then
A27:  a-'1 in Y by NAT_1:44;
      card Y = m;
      then rng fr = Y by A26,CARD_2:102;
      then consider w being object such that
A28:  w in dom fr and
A29:  fr.w = a-'1 by A27,FUNCT_1:def 3;
      reconsider w as Element of NAT by A28;
      w in dom fp by A7,A16,A28,FINSEQ_1:def 3;
      then reconsider y = fp.w as Element of X by FINSEQ_2:11;
      take y;
      thus thesis by A16,A28,A29;
    end;
    consider fp being FinSequence of X such that
A30: dom fp = Seg m & for a be Nat st a in Seg m holds P[a,fp.a] from
    FINSEQ_1:sch 5(A4);
A31: rng fp c= X by FINSEQ_1:def 4;
A32: len fp = m by A30,FINSEQ_1:def 3;
    for a,b being object st a in dom fp & b in dom fp & fp.a = fp.b
holds a = b
    proof
      let a,b be object;
      assume that
A33:  a in dom fp and
A34:  b in dom fp and
A35:  fp.a = fp.b;
      reconsider a,b as Element of NAT by A33,A34;
A36:  b>=1 by A30,A34,FINSEQ_1:1;
A37:  a>=1 by A30,A33,FINSEQ_1:1;
      then
A38:  (a-'1)-(b-'1) = (a-1)-(b-'1) by XREAL_1:233
        .= (a-1)-(b-1) by A36,XREAL_1:233
        .= a-b;
      reconsider l=fp.a,ll=fp.b as Element of INT by A33,A34,FINSEQ_2:11;
      fp.b in Class(Cong(m),b-'1) by A30,A34;
      then [b-'1,fp.b] in Cong(m) by EQREL_1:18;
      then (b-'1),ll are_congruent_mod m by Def1;
      then
A39:  l,(b-'1) are_congruent_mod m by A35,INT_1:14;
      b<=m by A30,A34,FINSEQ_1:1;
      then a-b >= 1-m by A37,XREAL_1:13;
      then
A40:  a-b > -m by XREAL_1:145;
      a<=m by A30,A33,FINSEQ_1:1;
      then a-b <= m-1 by A36,XREAL_1:13;
      then a-b < m by XREAL_1:147;
      then |.a-b.| < m by A40,SEQ_2:1;
      then
A41:  |.a-b.| < |.m.| by ABSVALUE:def 1;
      fp.a in Class(Cong(m),a-'1) by A30,A33;
      then [a-'1,fp.a] in Cong(m) by EQREL_1:18;
      then (a-'1),l are_congruent_mod m by Def1;
      then (a-'1),(b-'1) are_congruent_mod m by A39,INT_1:15;
      then
A42:  m divides (a-b) by A38;
      now
        assume a<>b;
        then a-b<>0;
        hence contradiction by A42,A41,Th6;
      end;
      hence thesis;
    end;
    then fp is one-to-one;
    then card X = card(rng fp) by A1,A32,FINSEQ_4:62;
    then X = rng fp by A31,CARD_2:102;
    hence thesis by A30,A32;
  end;
end;
