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 Th8:
  m>=1 implies Euler(p|^m) = p|^m - p|^(m-'1)
proof assume A1: m >= 1;
   set X = {k where k is Element of NAT :
               p|^m,k are_coprime & k >= 1 & k <= p|^m};
   set X1 = {k where k is Element of NAT :
            not p|^m,k are_coprime & k >= 1 & k <= p|^m};
   set X2 = {k where k is Element of NAT :
            not p,k are_coprime & k >= 1 & k <= p|^m};
   set X3 = {k where k is Element of NAT :
             p divides k & k >= 1 & k <= p|^m};
    reconsider w = p|^(m-'1) as Element of NAT by ORDINAL1:def 12;
A2:    X1 = X2
   proof thus X1 c= X2
       proof let a be object;
          assume a in X1;
          then consider b be Element of NAT such that
A3:       b = a & not p|^m,b are_coprime & b >= 1 & b <= p|^m;
          not p,b are_coprime by A3,WSIERP_1:10;
         hence thesis by A3;
       end;
       let a be object;
         assume a in X2;
         then consider k be Element of NAT such that
A4:      k = a & not p,k are_coprime & k >= 1 & k <= p|^m;
         p gcd k = p by A4,PEPIN:2;then
A5:      p divides k by NAT_D:def 5;
         p|^1 divides p|^m by A1,NEWTON:89;then
A6:      p divides p|^m;
           now assume p|^m,k are_coprime;
              then p = 1 by A5,A6,PYTHTRIP:def 1;
             hence contradiction by INT_2:def 4;
           end;
        hence thesis by A4;
   end;
A7: X2 = X3
   proof thus X2 c= X3
     proof let x be object;
       assume x in X2;
       then consider k be Element of NAT such that
A8:   x = k & not p,k are_coprime & k >= 1 & k <= p|^m;
       p gcd k = p by A8,PEPIN:2;
       then p divides k by NAT_D:def 5;
      hence thesis by A8;
     end;
     let x be object;
       assume x in X3;
       then consider k be Element of NAT such that
A9:   x = k & p divides k & k >= 1 & k <= p|^m;
       p gcd k = p by A9,NEWTON:49;
       then p gcd k > 1 by INT_2:def 4;
       then not p,k are_coprime by INT_2:def 3;
      hence thesis by A9;
   end;
    X3 c= Seg(p|^m)
    proof
      let x be object;
      assume x in X3;
      then ex k be Element of NAT st
           k = x & p divides k & k >= 1 & k <= p|^m;
      hence x in Seg(p|^m);
    end;
    then reconsider X1,X2,X3 as finite Subset of NAT by A2,A7,XBOOLE_1:1;
    deffunc F(Nat) = $1 * p;
    consider f be FinSequence such that
A10:len f = w & for d be Nat st d in dom f holds f.d = F(d)
      from FINSEQ_1:sch 2;
A11: rng f = X3
     proof thus rng f c= X3
       proof let a be object;
          assume a in rng f;
          then consider s be Nat such that
A12:      s in dom f & f.s = a by FINSEQ_2:10;
A13:      a = s * p by A12,A10;then
          reconsider a as Element of NAT by ORDINAL1:def 12;
A14:      p divides a by A13,NAT_D:def 3;
          s in Seg w by A12,A10,FINSEQ_1:def 3;
          then A15:s >= 1 & s <= w by FINSEQ_1:1;
          p > 1 by INT_2:def 4;
          then A16:s * p >= 1*1 by A15,XREAL_1:66;
          s * p <= w * p by A15,XREAL_1:66;
          then A17:s * p <= p|^((m-'1) + 1) by NEWTON:6;
          p|^((m-'1) + 1)=p|^(m + 1-'1 ) by A1,NAT_D:38
                       .=p|^m by NAT_D:34;
         hence thesis by A13,A14,A16,A17;
       end;
         let a be object;
         assume a in X3;
         then consider k be Element of NAT such that
A18:     a = k & p divides k & k >= 1 & k <= p|^m;
         consider t be Nat such that A19:k = p * t by A18,NAT_D:def 3;
         t <> 0 by A19,A18;
         then A20:t >= 1 by NAT_1:14;
         p|^m = p|^(m + 1 -' 1) by NAT_D:34
             .=p|^(m-'1+1) by A1,NAT_D:38
             .=p|^(m-'1) * p by NEWTON:6;
         then p * t / p <= p|^(m-'1) * p / p by XREAL_1:72,A18,A19;
         then t <= w * p / p by XCMPLX_1:89;
         then t <= w by XCMPLX_1:89;
         then t in Seg w by A20;then
A21:     t in dom f by A10,FINSEQ_1:def 3;
         f.t = t * p by A21,A10;
        hence thesis by A18,A19,A21,FUNCT_1:3;
    end;
    for a,b be object st a in dom f & b in dom f & f.a = f.b holds a = b
    proof let a,b be object;
       assume A22:a in dom f & b in dom f & f.a = f.b;
       then reconsider a,b as Element of NAT;
       f.a = a * p & f.b = b * p by A22,A10;
      hence thesis by A22,XCMPLX_1:5;
    end;
    then f is one-to-one by FUNCT_1:def 4; then
A23:w = card X1 by A2,A7,A10,A11,FINSEQ_4:62;
A24:  X1 c= Seg(p|^m)
      proof let x be object;
         assume x in X1;
         then consider k be Element of NAT such that
A25:     x = k & not p|^m,k are_coprime & k >= 1 & k <= p|^m;
        thus thesis by A25;
      end;
A26:  X c= Seg(p|^m)
      proof let x be object;
         assume x in X;
         then consider k be Element of NAT such that
A27:     x = k & p|^m,k are_coprime & k >= 1 & k <= p|^m;
        thus thesis by A27;
      end;
      then A28:X1 \/ X c= Seg(p|^m) by A24,XBOOLE_1:8;
      reconsider X as finite Subset of NAT by A26,XBOOLE_1:1;
      Seg(p|^m) c= X1 \/ X
      proof let x be object;
         assume A29:x in Seg(p|^m);
         then reconsider x as Element of NAT;
A30:     x >= 1 & x <= p|^m by A29,FINSEQ_1:1;
         per cases;
         suppose p|^m,x are_coprime;
           then x in X by A30;
          hence thesis by XBOOLE_0:def 3;
         end;
         suppose not p|^m,x are_coprime;
          then x in X1 by A30;
          hence thesis by XBOOLE_0:def 3;
         end;
      end;
      then A31: X1 \/ X = Seg(p|^m) by A28;
      not ex x being object st x in X1 /\ X
      proof
         given x be object such that A32: x in X1 /\ X;
A33:     x in X1 & x in X by A32,XBOOLE_0:def 4;
         then consider k1 be Element of NAT such that
A34:     x = k1 & not p|^m,k1 are_coprime & k1 >= 1 & k1 <= p|^m;
         consider k2 be Element of NAT such that
A35:     x = k2 & p|^m,k2 are_coprime & k2 >= 1 & k2 <= p|^m by A33;
       thus contradiction by A34,A35;
      end;
      then X1 /\ X = {} by XBOOLE_0:def 1;
      then X1 misses X;
      then card X1 + card X = card Seg(p|^m) by A31,CARD_2:40;
      then w + card X = p|^m by A23,FINSEQ_1:57;
     hence thesis;
 end;
