reserve F,G for Group;
reserve G1 for Subgroup of G;
reserve Gc for cyclic Group;
reserve H for Subgroup of Gc;
reserve f for Homomorphism of G,Gc;
reserve a,b for Element of G;
reserve g for Element of Gc;
reserve a1 for Element of G1;
reserve k,m,n,p,s for Element of NAT;
reserve i0,i,i1,i2 for Integer;
reserve j,j1 for Element of INT.Group;
reserve x,y,t for set;

theorem Th14:
  Gc = gr {g} implies ( Gc is finite iff ex i,i1 st i<>i1 & g|^i = g|^i1 )
proof
  assume
A1: Gc = gr {g};
A2: ( ex i,i1 st i<>i1 & g|^i = g|^i1) implies Gc is finite
  proof
    given i,i1 such that
A3: i<>i1 and
A4: g|^i = g|^i1;
    now
      per cases by A3,XXREAL_0:1;
      suppose
A5:     i < i1;
        set r = i1-i;
        i1 > i+0 by A5;
        then
A6:     i1-i > 0 by XREAL_1:20;
        then reconsider m=r as Element of NAT by INT_1:3;
        (g|^i1)*g|^(-i) = (g|^i) *(g|^(i))" by A4,GROUP_1:36;
        then (g|^i1)*g|^(-i) = 1_Gc by GROUP_1:def 5;
        then
A7:     g|^(i1+-i) = 1_Gc by GROUP_1:33;
A8:     for i2 ex n st g|^i2=g|^n & n >= 0 & n < i1-i
        proof
          let i2;
          reconsider m=i2 mod r as Element of NAT by A6,INT_1:3,NEWTON:64;
          take m;
          g|^i2 = g|^( (i2 div r) * r + (i2 mod r) ) by A6,NEWTON:66
            .=g|^(r* (i2 div r) ) *(g|^ (i2 mod r)) by GROUP_1:33
            .=(1_Gc)|^(i2 div r) *(g|^ (i2 mod r)) by A7,GROUP_1:35
            .=(1_Gc) *(g|^ (i2 mod r)) by GROUP_1:31
            .=g|^ (i2 mod r) by GROUP_1:def 4;
          hence thesis by A6,NEWTON:65;
        end;
        ex F being FinSequence st rng F= the carrier of Gc
        proof
          deffunc F(Nat) = g|^$1;
          consider F being FinSequence such that
A9:       len F = m and
A10:      for p be Nat holds p in dom F implies F.p = F(p) from
          FINSEQ_1:sch 2;
A11:      dom F = Seg m by A9,FINSEQ_1:def 3;
A12:      the carrier of Gc c= rng F
          proof
            let y be object;
            assume y in the carrier of Gc;
            then reconsider a=y as Element of Gc;
            a in Gc by STRUCT_0:def 5;
            then
A13:        ex i2 st a=g|^i2 by A1,GR_CY_1:5;
            ex n st n in dom F & F.n=a
            proof
              consider n such that
A14:          a=g|^n and
              n >= 0 and
A15:          n < i1-i by A8,A13;
              per cases;
              suppose
A16:            n=0;
A17:            m >= 0 +1 by A6,NAT_1:13;
                then
A18:            m in Seg m by FINSEQ_1:1;
A19:            m in dom F by A11,A17,FINSEQ_1:1;
                a = g|^m by A7,A14,A16,GROUP_1:25;
                then F.m = a by A10,A11,A18;
                hence thesis by A19;
              end;
              suppose
                n >0;
                then
A20:            n >= 0 +1 by NAT_1:13;
                then n in Seg m by A15,FINSEQ_1:1;
                then
A21:            F.n = a by A10,A11,A14;
                n in dom F by A11,A15,A20,FINSEQ_1:1;
                hence thesis by A21;
              end;
            end;
            hence thesis by FUNCT_1:def 3;
          end;
          take F;
A22:      for y st y in rng F holds ex n st y=g|^n
          proof
            let y;
            assume y in rng F;
            then consider x being object such that
A23:        x in dom F and
A24:        F.x=y by FUNCT_1:def 3;
            reconsider n=x as Element of NAT by A23;
            take n;
            thus thesis by A10,A23,A24;
          end;
          rng F c= the carrier of Gc
          proof
            let y be object;
            assume y in rng F;
            then ex n st y= g|^n by A22;
            hence thesis;
          end;
          hence thesis by A12,XBOOLE_0:def 10;
        end;
        hence thesis;
      end;
      suppose
A25:    i1 < i;
        set r = i-i1;
        i > i1+0 by A25;
        then
A26:    i-i1 > 0 by XREAL_1:20;
        then reconsider m=r as Element of NAT by INT_1:3;
        (g|^i)*g|^(-i1) = (g|^i1) *(g|^(i1))" by A4,GROUP_1:36;
        then (g|^i)*g|^(-i1) = 1_Gc by GROUP_1:def 5;
        then
A27:    g|^(i+-i1) = 1_Gc by GROUP_1:33;
A28:    for i2 ex n st g|^i2=g|^n & n >= 0 & n < i-i1
        proof
          let i2;
          reconsider m=i2 mod r as Element of NAT by A26,INT_1:3,NEWTON:64;
          take m;
          g|^i2 = g|^( (i2 div r) * r + (i2 mod r) ) by A26,NEWTON:66
            .=g|^(r* (i2 div r) ) *(g|^ (i2 mod r)) by GROUP_1:33
            .=(1_Gc)|^(i2 div r) *(g|^ (i2 mod r)) by A27,GROUP_1:35
            .=(1_Gc) *(g|^ (i2 mod r)) by GROUP_1:31
            .=g|^ (i2 mod r) by GROUP_1:def 4;
          hence thesis by A26,NEWTON:65;
        end;
        ex F being FinSequence st rng F= the carrier of Gc
        proof
          deffunc F(Nat) = g|^$1;
          consider F being FinSequence such that
A29:      len F = m and
A30:      for p be Nat holds p in dom F implies F.p=F(p) from
          FINSEQ_1:sch 2;
A31:      dom F = Seg m by A29,FINSEQ_1:def 3;
A32:      the carrier of Gc c= rng F
          proof
            let y be object;
            assume y in the carrier of Gc;
            then reconsider a=y as Element of Gc;
            a in Gc by STRUCT_0:def 5;
            then
A33:        ex i2 st a=g|^i2 by A1,GR_CY_1:5;
            ex n st n in dom F & F.n=a
            proof
              consider n such that
A34:          a=g|^n and
              n >= 0 and
A35:          n < i-i1 by A28,A33;
              per cases;
              suppose
A36:            n=0;
A37:            m >= 0 +1 by A26,NAT_1:13;
                then
A38:            m in Seg m by FINSEQ_1:1;
A39:            m in dom F by A31,A37,FINSEQ_1:1;
                a = g|^m by A27,A34,A36,GROUP_1:25;
                then F.m = a by A30,A31,A38;
                hence thesis by A39;
              end;
              suppose
                n >0;
                then
A40:            n >= 0 +1 by NAT_1:13;
                then n in Seg m by A35,FINSEQ_1:1;
                then
A41:            F.n = a by A30,A31,A34;
                n in dom F by A31,A35,A40,FINSEQ_1:1;
                hence thesis by A41;
              end;
            end;
            hence thesis by FUNCT_1:def 3;
          end;
          take F;
A42:      for y st y in rng F holds ex n st y=g|^n
          proof
            let y;
            assume y in rng F;
            then consider x being object such that
A43:        x in dom F and
A44:        F.x=y by FUNCT_1:def 3;
            reconsider n=x as Element of NAT by A43;
            take n;
            thus thesis by A30,A43,A44;
          end;
          rng F c= the carrier of Gc
          proof
            let y be object;
            assume y in rng F;
            then ex n st y= g|^n by A42;
            hence thesis;
          end;
          hence thesis by A32,XBOOLE_0:def 10;
        end;
        hence thesis;
      end;
    end;
    hence thesis;
  end;
  Gc is finite implies ex i,i1 st i<>i1 & g|^i = g|^i1
  proof
    assume Gc is finite;
    then reconsider Gc as finite cyclic Group;
    reconsider z=0,i0=card Gc as Integer;
A45: g|^z = 1_Gc by GROUP_1:25
      .= g|^i0 by GR_CY_1:9;
    thus thesis by A45;
  end;
  hence thesis by A2;
end;
