reserve d,i,j,k,m,n,p,q,x,k1,k2 for Nat,
  a,c,i1,i2,i3,i5 for Integer;

theorem Th47:
  p > 1 & (i |^ n) mod p = 1 & i,p are_coprime implies order(i,p) divides n
proof
  assume that
A1: p > 1 and
A2: (i |^ n) mod p = 1 and
A3: i,p are_coprime;
A4: order(i,p) <> 0 by A1,A3,Def2;
A5: (i |^ order(i,p)) mod p = 1 by A1,A3,Def2;
  n mod order(i,p) = 0
  proof
    set I = n mod order(i,p);
    consider t being Nat such that
A6: n = order(i,p)*t + I and
A7: I < order(i,p) by A4,NAT_D:def 2;
    reconsider t as Element of NAT by ORDINAL1:def 12;
    (i |^ (order(i,p)*t))*(i |^ I) mod p = 1 by A2,A6,NEWTON:8;
    then ((i |^ order(i,p)) |^ t)*(i |^ I) mod p = 1 by NEWTON:9;
    then ((((i |^ order(i,p)) |^ t) mod p)*(i |^ I)) mod p = 1 by EULER_2:8;
    then (1*(i |^ I)) mod p = 1 by A1,A5,Th35;
    hence thesis by A1,A3,A7,Def2;
  end;
  hence thesis by A4,Th6;
end;
