 reserve x,y,z for object, X for set,
         i,k,n,m for Nat,
         R for Relation,
         P for finite Relation,
         p,q for FinSequence;

theorem Th7:
  len p is prime & (ex i st 0 < i & i < len p & p = (p/^i) ^ (p|i))
    implies rng p c= {p.1}
proof
  set L=len p;
  assume A1:L is prime;
  reconsider P=p as FinSequence of rng p \/{1} by XBOOLE_1:7,FINSEQ_1:def 4;
  given j be Nat such that
        A2: 0 < j
    and A3: j < L
    and A4: p = (p/^j)^(p|j);
  defpred P[Nat] means p.1 = p.((j*$1 mod L)+1);
  set p1j=p/^j,pj=p|j;
  A5:for k be Nat st P[k] holds P[k+1]
  proof
    let k be Nat;
    assume A6:P[k];
    set k1=k+1,jk=(j*k mod L);
    j*k1=j*k+j;
    then A7:j*k1 mod L = jk+j mod L by NAT_D:23;
    A8: len pj = j by A3,FINSEQ_1:59;
    A9: len p1j = L-j by A3,RFINSEQ:def 1;
    jk+1<=L by NAT_D:1, A3,NAT_1:13;
    then A10:jk+1 in dom p by NAT_1:11,FINSEQ_3:25;
    per cases by A4,A10,FINSEQ_1:25;
      suppose A11:jk+1 in dom p1j;
        then jk+1 <= L-j by A9,FINSEQ_3:25;
        then jk+1+j <= L-j+j by XREAL_1:6;
        then jk+j+1 <= L;
        then jk+j < L by NAT_1:13;
        then A12: jk+j mod L = jk+j by NAT_D:24;
        p.(jk+1) = p1j.(jk+1) by A11,A4,FINSEQ_1:def 7
            .= p.(jk+1+j) by A3,A11,RFINSEQ:def 1;
        hence thesis by A12,A7,A6;
      end;
      suppose ex n be Nat st n in dom pj & jk+1=len p1j + n;
        then consider n be Nat such that
              A13: n in dom pj
          and A14: jk+1=len p1j + n;
        len pj >= n by A13,FINSEQ_3:25;
        then A15: n < L by A8,A3,XXREAL_0:2;
        reconsider n1=n-1 as Nat by A13,FINSEQ_3:25,NAT_1:21;
        n1 < n1+1 by NAT_1 :13;
        then A16:n1 < L by A15,XXREAL_0:2;
        jk+j = 1*L+n1 by A14,A9;
        then A17: jk+j mod L = n1 mod L by NAT_D:21
           .= n1 by A16,NAT_D:24;
        p.(jk+1) = pj.n by A4,A13,A14,FINSEQ_1:def 7
           .= p.n by A13,FUNCT_1:47;
        hence thesis by A17,A7,A6;
      end;
    end;
    j*0 mod L = 0 by NAT_D:26;
    then A18: P[0];
    A19:for k be Nat holds P[k] from NAT_1:sch 2(A18,A5);
    let y be object;
    assume y in rng p;
    then consider m be object such that
           A20: m in dom p
      and  A21: p.m=y by FUNCT_1:def 3;
    reconsider m as Nat by A20;
    A22: m <= L by A20,FINSEQ_3:25;
    reconsider m1=m-1 as Nat by A20,FINSEQ_3:25,NAT_1:21;
    per cases;
      suppose m=1;
        hence thesis by A21,TARSKI:def 1;
      end;
      suppose m<>1;
        j gcd L =1
        proof
          j gcd L divides L by INT_2:def 2;
          then A23: j gcd L = 1 or j gcd L = L by A1,INT_2:def 4;
          assume j gcd L <>1;
          then L divides j by A23,INT_2:def 2;
          hence contradiction by A2,NAT_D:7, A3;
        end;
        then consider n be Nat such that
        A24: (j*n-m1) mod L=0 by INT_2:def 3, A3,INT_4:16;
        A25:m1+1=m;
        then m1 < L by A22,NAT_1:13;
        then m1 mod L=m1 by NAT_D:24;
        then j*n mod L = m1 by A3,INT_4:22,A24;
        then p.1 = p.m by A25,A19;
        hence thesis by TARSKI:def 1,A21;
      end;
end;
