reserve i,s,t,m,n,k for Nat,
        c,d,e for Element of NAT,
        fn for FinSequence of NAT,
        x,y for Integer;
reserve p for Prime;

theorem Th10:
  for i,n st n>1 & i,n are_coprime holds
    i|^s,i|^t are_congruent_mod n iff s,t are_congruent_mod order(i,n)
proof let i,n;
   assume A1:n>1 & i,n are_coprime;
A2:i <> 0 & n > 0 by A1,Th5;
  set R = order(i,n);
  reconsider RR = R as Element of NAT;
  thus i|^s,i|^t are_congruent_mod n implies s,t are_congruent_mod R
  proof
  assume A3:i|^s,i|^t are_congruent_mod n;
A4: i gcd n = 1 by A1,INT_2:def 3;
  per cases by XXREAL_0:1;
    suppose s = t;
     hence thesis by INT_1:11;
    end;
    suppose s > t;
      then consider l be Nat such that A5: s = t + l by NAT_1:10;
      n divides (i|^s - i|^t) by A3,INT_2:15;
      then n divides (i|^t * i|^l - i|^t * 1) by A5,NEWTON:8;
      then A6:n divides (i|^t * (i|^l - 1));
      reconsider ll = i|^l - 1 as Element of NAT by NAT_1:21,14,A2;
A7:   n gcd i|^t = 1 by A4,A2,NAT_4:10;
      n divides ll by A6,A7,WSIERP_1:30;
      then i|^l,1 are_congruent_mod n by INT_2:15;
      then i|^l mod n = 1 mod n by NAT_D:64  .= 1 by A1,PEPIN:5;
      then R divides (s - t) by A5,A1,PEPIN:47;
     hence thesis by INT_2:15;
    end;
    suppose s < t;
      then consider l be Nat such that A8:t = s + l by NAT_1:10;
      i|^t,i|^s are_congruent_mod n by A3,INT_1:14;
      then n divides (i|^t - i|^s) by INT_2:15;
      then n divides (i|^s * i|^l - i|^s * 1) by A8,NEWTON:8;
      then A9:n divides (i|^s * (i|^l - 1));
A10:  n gcd i|^s = 1 by A4,A2,NAT_4:10;
      reconsider ll = i|^l - 1 as Element of NAT by NAT_1:21,14,A2;
      n divides ll by A10,A9,WSIERP_1:30;
      then i|^l,1 are_congruent_mod n by INT_2:15;
      then i|^l mod n = 1 mod n by NAT_D:64
                     .= 1 by A1,PEPIN:5;
      then R divides (t - s) by A1,A8,PEPIN:47;
      then t,s are_congruent_mod R by INT_2:15;
     hence thesis by INT_1:14;
    end;
  end;
  assume A11:s,t are_congruent_mod R;
A12:R > 0 by A1,PEPIN:def 2;
   then A13:s = (s div R) * R + (s mod R) &
           t = (t div R) * R + (t mod R) by NEWTON:66;
   then A14:i|^s = i|^ (R * (s div R)) * i|^(s mod R) by NEWTON:8
              .= i|^R|^(s div R) * i|^(s mod R) by NEWTON:9;
A15:i|^R mod n = 1 by A1,PEPIN:def 2
             .= 1 mod n by A1,PEPIN:5;
   then (i|^R|^(s div R)) mod n = 1|^(s div R) mod n by INT_4:8
         .= 1 mod n;
   then i|^R|^(s div R),1 are_congruent_mod n by A1,NAT_D:64;
   then i|^R|^(s div R)*i|^(s mod R),1*i|^(s mod R) are_congruent_mod n
                                                             by INT_4:11;
   then A16:i|^s mod n = i|^(s mod R) mod n by A14,NAT_D:64;
A17:i|^t = i|^ (R * (t div R)) * i|^(t mod R) by NEWTON:8,A13
     .= i|^R|^(t div R) * i|^(t mod R) by NEWTON:9;
   i|^R|^(t div R) mod n = 1|^(t div R) mod n by A15,INT_4:8
         .= 1 mod n;
   then i|^R|^(t div R),1 are_congruent_mod n by A1,NAT_D:64;
   then i|^R|^(t div R)*i|^(t mod R),1*i|^(t mod R) are_congruent_mod n
                                                             by INT_4:11;
   then A18:i|^t mod n = i|^(t mod R) mod n by A17,NAT_D:64;
   s mod R = (s mod R) mod R & t mod R = (t mod R) mod R by NAT_D:73;
   then A19:s,(s mod R) are_congruent_mod R
            & t,(t mod R) are_congruent_mod R by A12,NAT_D:64;
   then t,(s mod R) are_congruent_mod R by A11,PEPIN:40;
   then (s mod R),(t mod R) are_congruent_mod R by A19,PEPIN:40;
   then A20:R divides ((s mod R)-(t mod R)) by INT_2:15;
    now assume (s mod R)<>(t mod R);
      then (s mod R)-(t mod R)<>0;
      then |.R.| <= |.((s mod R)-(t mod R)).| by A20,INT_4:6;
      then A21:R <= |.((s mod R)-(t mod R)).| by ABSVALUE:def 1;
      reconsider sR = s mod RR, tR = t mod RR as Element of REAL
        by XREAL_0:def 1;
      reconsider rR = -R as Element of REAL by XREAL_0:def 1;
A22:    sR < RR & sR >= 0 & tR < RR & tR >= 0 by A12,NAT_D:1;
      sR - tR <= sR by XREAL_1:43; then
A23:    sR - tR < RR by A22,XXREAL_0:2;
A24:    (-1)*tR > (-1)*RR by XREAL_1:69,A22;
      sR + -tR >= -tR by XREAL_1:31; then
      sR + -tR > rR by XXREAL_0:2,A24;
     hence contradiction by A21,SEQ_2:1,A23;
    end;
  hence thesis by A1,A16,A18,NAT_D:64;
end;
