reserve Al for QC-alphabet;
reserve p,q,p1,p2,q1 for Element of CQC-WFF(Al),
  k for Element of NAT,
  f,f1,f2,g for FinSequence of CQC-WFF(Al),
  a,b,b1,b2,c,i,n for Nat;
reserve P for Permutation of dom f;

theorem Th29:
  |- Per(f,P)^<*Impl(Rev (f^<*p*>))*> implies |- Per(f,P)^<*p*>
proof
  set g = f^<*p*>;
  set h = Rev g;
A1: 1 <= len g by CALCUL_1:10;
  then
A2: 1 <= len h by FINSEQ_5:def 3;
  then consider F being FinSequence of CQC-WFF(Al) such that
A3: Impl(h) = F.(len h) and
A4: len F = len h and
A5: F.1 = Begin(h) or len h = 0 and
A6: for n being Nat st 1 <= n & n < len h
    ex p,q st p = h.(n+1) & q = F.n &
  F.(n+1) = p => q by Def4;
  set H = Rev F;
A7: 1 <= len H by A2,A4,FINSEQ_5:def 3;
  defpred P[Nat] means 1 <= $1 & $1 <= len H implies ex p st p = H.
  $1 & |- Per(f,P)^<*p*>;
  assume
A8: |- Per(f,P)^<*Impl(Rev (f^<*p*>))*>;
A9: for k being Nat st P[k] holds P[k+1]
  proof
    let k be Nat such that
A10: P[k];
    assume that
A11: 1 <= k+1 and
A12: k+1 <= len H;
A13: now
A14:  k < len H by A12,NAT_1:13;
      then 0+k < len F by FINSEQ_5:def 3;
      then
A15:  0+k+(-k) < len F+(-k) by XREAL_1:8;
      then reconsider i = len F-k as Element of NAT by INT_1:3;
A16:  len g-i = len g - (len g-k) by A4,FINSEQ_5:def 3
        .= k;
      then reconsider j = len g-i as Nat;
A17:  0+1 <= i by A15,NAT_1:13;
      then
A18:  1 <= i+1 by NAT_1:13;
      assume
A19:  k <> 0;
      then
A20:  0+1 <= k by NAT_1:13;
      then consider pk being Element of CQC-WFF(Al) such that
A21:  pk = H.k and
A22:  |- Per(f,P)^<*pk*> by A10,A12,NAT_1:13;
      len F < len F+k by A19,XREAL_1:29;
      then
A23:  len F+(-k) < len F+k+(-k) by XREAL_1:8;
      then consider p1,q1 such that
A24:  p1 = h.(i+1) and
A25:  q1 = F.i and
A26:  F.(i+1) = p1 => q1 by A4,A6,A17;
      take q1;
      k+1 in dom H by A11,A12,FINSEQ_3:25;
      then i = len F-(k+1)+1 & k+1 in dom F by FINSEQ_5:57;
      then
A27:  q1 = H.(k+1) by A25,FINSEQ_5:58;
      len g < len g+i by A15,XREAL_1:29;
      then len g+(-i) < len g+i+(-i) by XREAL_1:8;
      then j < len f+len <*p*> by FINSEQ_1:22;
      then j < len f+1 by FINSEQ_1:39;
      then j <= len f by NAT_1:13;
      then
A28:  j in dom f by A20,A16,FINSEQ_3:25;
      then
A29:  g.j = (g|dom f).j by FUNCT_1:49;
      j in rng P by A28,FUNCT_2:def 3;
      then consider a being object such that
A30:  a in dom P and
A31:  P.a = j by FUNCT_1:def 3;
A32:  a in dom f by A30;
      then reconsider j1 = a as Element of NAT;
      set g1 = Per(f,P)^<*p1*>;
      i+1 <= len h by A4,A23,NAT_1:13;
      then i+1 in dom h by A18,FINSEQ_3:25;
      then i+1 in dom g by FINSEQ_5:57;
      then p1 = g.(len g - (i+1) + 1) by A24,FINSEQ_5:58
        .= g.(len g - i);
      then p1 = f.(P.j1) by A29,A31,FINSEQ_1:21;
      then p1 = (P*f).j1 by A30,FUNCT_1:13;
      then Suc(g1) = Per(f,P).j1 by CALCUL_1:5;
      then
A33:  Suc(g1) = (Ant(g1)).j1 by CALCUL_1:5;
      j1 in dom Per(f,P) by A32,Th19;
      then j1 in dom Ant(g1) by CALCUL_1:5;
      then Suc(g1) is_tail_of Ant(g1) by A33,CALCUL_1:def 16;
      then
A34:  |- g1 by CALCUL_1:33;
      k in dom H by A20,A14,FINSEQ_3:25;
      then k in dom F by FINSEQ_5:57;
      then pk = p1 => q1 by A21,A26,FINSEQ_5:58;
      then |- Per(f,P)^<*q1*> by A22,A34,CALCUL_1:56;
      hence thesis by A27;
    end;
    now
      1 <= len H by A2,A4,FINSEQ_5:def 3;
      then
A35:  1 in dom H by FINSEQ_3:25;
      then reconsider p = H.1 as Element of CQC-WFF(Al) by FINSEQ_2:11;
      assume
A36:  k = 0;
      take p;
      1 in dom F by A35,FINSEQ_5:57;
      then p = F.(len F-1+1) by FINSEQ_5:58
        .= Impl(h) by A3,A4;
      hence thesis by A8,A36;
    end;
    hence thesis by A13;
  end;
A37: P[0];
  for k being Nat holds P[k] from NAT_1:sch 2(A37,A9);
  then consider q such that
A38: q = H.(len H) and
A39: |- Per(f,P)^<*q*> by A7;
  q = H.(len F) by A38,FINSEQ_5:def 3;
  then q = Begin(h) by A1,A5,FINSEQ_5:62,def 3;
  then q = h.1 by A2,Def3;
  then q = g.(len g) by FINSEQ_5:62;
  then q = g.(len f+len <*p*>) by FINSEQ_1:22;
  then q = g.(len f+1) by FINSEQ_1:39;
  hence thesis by A39,FINSEQ_1:42;
end;
