reserve Al for QC-alphabet;
reserve a,b,b1 for object,
  i,j,k,n for Nat,
  p,q,r,s for Element of CQC-WFF(Al),
  x,y,y1 for bound_QC-variable of Al,
  P for QC-pred_symbol of k,Al,
  l,ll for CQC-variable_list of k,Al,
  Sub,Sub1 for CQC_Substitution of Al,
  S,S1,S2 for Element of CQC-Sub-WFF(Al),
  P1,P2 for Element of QC-pred_symbols(Al);
reserve F1,F2,F3 for QC-formula of Al,
  L for FinSequence;

theorem Th29:
  for L being PATH of q,p st QuantNbr(p) <= n & q is_subformula_of
  p & 1 <= i & i <= len L holds ex r st r = L.i & QuantNbr(r) <= n
proof
  let L be PATH of q,p;
  set m = len L;
  assume that
A1: QuantNbr(p) <= n and
A2: q is_subformula_of p and
A3: 1 <= i and
A4: i <= m;
  i+(-i) <= m+(-i) by A4,XREAL_1:6;
  then reconsider l = m-i as Element of NAT by INT_1:3;
  m+1 <= m+i by A3,XREAL_1:6;
  then m+1+(-1) <= m+i+(-1) by XREAL_1:6;
  then
A5: m+(-i) <= m-1+i+(-i) by XREAL_1:6;
  defpred P[Nat] means $1 <= m-1 implies ex r st r = L.(m-$1) &
  QuantNbr(r) <= n;
A6: for k st P[k] holds P[k+1]
  proof
    let k such that
A7: P[k];
    assume
A8: k+1 <= m-1;
    then k+1+1 <= m-1+1 by XREAL_1:6;
    then
A9: 2+k+(-k) <= m+(-k) by XREAL_1:6;
    then reconsider j = m-k as Element of NAT by INT_1:3;
A10: 1+1+(-1) <= j+(-1) by A9,XREAL_1:6;
    then reconsider j1 = j-1 as Element of NAT by INT_1:3;
    m <= m+k by NAT_1:11;
    then m+(-k) <= m+k+(-k) by XREAL_1:6;
    then
A11: j-1 < m by XREAL_1:146,XXREAL_0:2;
    j1+1 = j;
    then consider G1,H1 being Element of QC-WFF(Al) such that
A12: L.j1 = G1 and
A13: L.j = H1 & G1 is_immediate_constituent_of H1 by A2,A10,A11,Def5;
    reconsider r = G1 as Element of CQC-WFF(Al) by A2,A10,A11,A12,Th28;
    k < k+1 by NAT_1:13;
    then consider q such that
A14: q = L.j and
A15: QuantNbr(q) <= n by A7,A8,XXREAL_0:2;
A16: now
      given x such that
A17:  q = All(x,G1);
      take r;
      QuantNbr(r)+1 <= n by A15,A17,CQC_SIM1:18;
      then QuantNbr(r) <= n by NAT_1:13;
      hence thesis by A12;
    end;
A18: now
      given F being Element of QC-WFF(Al) such that
A19:  q = F '&' G1;
      reconsider F as Element of CQC-WFF(Al) by A19,CQC_LANG:9;
      take r;
      n <= n+QuantNbr(F) by NAT_1:11;
      then
A20:  n+(-QuantNbr(F)) <= n+QuantNbr(F)+(-QuantNbr(F)) by XREAL_1:6;
      QuantNbr(r) + QuantNbr(F) <= n by A15,A19,CQC_SIM1:17;
      then QuantNbr(r) + QuantNbr(F)+(-QuantNbr(F)) <= n +(-QuantNbr(F)) by
XREAL_1:6;
      hence thesis by A12,A20,XXREAL_0:2;
    end;
A21: now
      given F being Element of QC-WFF(Al) such that
A22:  q = G1 '&' F;
      reconsider F as Element of CQC-WFF(Al) by A22,CQC_LANG:9;
      take r;
      n <= n+QuantNbr(F) by NAT_1:11;
      then
A23:  n+(-QuantNbr(F)) <= n+QuantNbr(F)+(-QuantNbr(F)) by XREAL_1:6;
      QuantNbr(r) + QuantNbr(F) <= n by A15,A22,CQC_SIM1:17;
      then QuantNbr(r) + QuantNbr(F)+(-QuantNbr(F)) <= n +(-QuantNbr(F)) by
XREAL_1:6;
      hence thesis by A12,A23,XXREAL_0:2;
    end;
    now
      assume
A24:  q = 'not' G1;
      take r;
      QuantNbr(r) <= n by A15,A24,CQC_SIM1:16;
      hence thesis by A12;
    end;
    hence thesis by A14,A13,A21,A18,A16,QC_LANG2:def 19;
  end;
  L.m = p by A2,Def5;
  then
A25: P[0] by A1;
  for k holds P[k] from NAT_1:sch 2(A25,A6);
  then ex r st r = L.(m-l) & QuantNbr(r) <= n by A5;
  hence thesis;
end;
