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