reserve Al for QC-alphabet;
reserve PHI for Consistent Subset of CQC-WFF(Al),
        p,q,r,s for Element of CQC-WFF(Al),
        A for non empty set,
        J for interpretation of Al,A,
        v for Element of Valuations_in(Al,A),
        m,n,i,j,k for Nat,
        l for CQC-variable_list of k,Al,
        P for QC-pred_symbol of k,Al,
        x,y,z for bound_QC-variable of Al,
        b for QC-symbol of Al,
        PR for FinSequence of [:set_of_CQC-WFF-seq(Al),Proof_Step_Kinds:];
reserve Al2 for Al-expanding QC-alphabet,
        J2 for interpretation of Al2,A,
        Jp for interpretation of Al,A,
        v2 for Element of Valuations_in(Al2,A),
        vp for Element of Valuations_in(Al,A);

theorem Th17:
  for p2 being Element of CQC-WFF(Al2),x2,y2 being bound_QC-variable of Al2,
  p,x,y st p=p2 & x=x2 & y=y2 holds p.(x,y) = p2.(x2,y2)
proof
  defpred P[Element of CQC-WFF(Al)] means for p2 being Element of CQC-WFF(Al2),
   S being CQC_Substitution of Al, S2 being CQC_Substitution of Al2
   st $1 = p2 & S = S2 holds CQC_Sub [$1,S] = CQC_Sub [p2,S2];
A1: P[VERUM(Al)]
  proof
    set p = VERUM(Al);
    let p2 be Element of CQC-WFF(Al2), S be CQC_Substitution of Al,
     S2 be CQC_Substitution of Al2 such that
A2:  p = p2 & S = S2;
A3: VERUM(Al2) = p2 by A2;
A4: [p,S] is Al-Sub_VERUM & [p2,S2] is Al2-Sub_VERUM by A3,SUBSTUT1:def 19;
    thus CQC_Sub [p,S] = VERUM(Al2) by A4,SUBLEMMA:3
      .= CQC_Sub [p2,S2] by A4,SUBLEMMA:3;
  end;
A5: for k,P,l holds P[P!l]
  proof
    let k,P,l;
    set P2 = Al2-Cast(P);
    set l2 = Al2-Cast(l);
    reconsider P2 as QC-pred_symbol of k,Al2;
    reconsider l2 as CQC-variable_list of k,Al2;
    let p2 be Element of CQC-WFF(Al2), S be CQC_Substitution of Al,
     S2 be CQC_Substitution of Al2 such that
A6:  P!l = p2 & S = S2;
A7: p2 = Al2-Cast(P!l) by A6 .= P2!l2 by Th8;
    set p = P!l;
    reconsider p as Element of CQC-WFF(Al);
    set sub = CQC_Subst(l,S);
A8: sub = CQC_Subst(Al2-Cast(l),S2)
    proof
A9:   len sub = len l by SUBSTUT1:def 3
       .= len CQC_Subst(Al2-Cast(l),S2) by SUBSTUT1:def 3;
      for n being Nat st n in dom sub holds
       sub.n = (CQC_Subst(Al2-Cast(l),S2)).n
      proof
        let n be Nat such that
A10:     n in dom sub;
        n in Seg len sub by A10,FINSEQ_1:def 3;
        then 1 <= n & n <= len sub by FINSEQ_1:1;
        then
A11:    1 <= n & n <= len l by SUBSTUT1:def 3;
        reconsider n as Element of NAT by ORDINAL1:def 12;
        per cases;
        suppose
A12:      l.n in dom S;
          sub.n = S.(l.n) by A11,A12,SUBSTUT1:def 3
           .= CQC_Subst(Al2-Cast(l),S2).n by A6,A11,A12,SUBSTUT1:def 3;
          hence thesis;
        end;
        suppose
A13:      not l.n in dom S;
          sub.n = l.n by A11,A13,SUBSTUT1:def 3
           .= CQC_Subst(Al2-Cast(l),S2).n by A6,A11,A13,SUBSTUT1:def 3;
          hence thesis;
        end;
      end;
      hence thesis by A9,FINSEQ_2:9;
    end;
    the_arity_of P = len l & the_arity_of P2 = len l2 by Th1;
    then
A14: [P!l,S] = Sub_P(P,l,S) & [P2!l2,S2] = Sub_P(P2,l2,S2)
     by SUBSTUT1:def 18;
    P!l is atomic & P2!l2 is atomic;
    then
A15: P = the_pred_symbol_of P!l & P2 = the_pred_symbol_of P2!l2
     by QC_LANG1:def 22;
A16: [P!l,S]`1 = P!l & [P!l,S]`2 = S & [P2!l2,S2]`1 = P2!l2 & [P2!l2,S2]`2 = S2
     & Sub_the_arguments_of [P!l,S] = l & Sub_the_arguments_of [P2!l2,S2] = l2
     by A14,SUBSTUT1:def 29;
    thus CQC_Sub [P!l,S] = Al2-Cast(P!CQC_Subst(l,S)) by A14,A15,A16,SUBLEMMA:6
     .= (Al2-Cast(P))!(Al2-Cast(CQC_Subst(l,S))) by Th8
     .= CQC_Sub [p2,S2] by A7,A8,A14,A15,A16,SUBLEMMA:6;
  end;
A17: for q st P[q] holds P['not' q]
  proof
    let q such that
A18: P[q];
    set p = 'not' q;
    reconsider p as Element of CQC-WFF(Al);
    set q2 = Al2-Cast(q);
    reconsider q2 as Element of CQC-WFF(Al2);
    let p2 be Element of CQC-WFF(Al2), S being CQC_Substitution of Al,
     S2 being CQC_Substitution of Al2 such that
A19:  'not' q = p2 & S = S2;
A20: [q,S]`1 = q & [q,S]`2 = S & [q2,S2]`1 = q2 & [q2,S2]`2 = S2;
    thus CQC_Sub ['not' q, S] = CQC_Sub Sub_not [q,S] by A20,SUBSTUT1:def 20
    .= Al2-Cast('not' CQC_Sub [q,S]) by SUBSTUT1:29
    .= 'not' CQC_Sub [q2,S2] by A18,A19
    .= CQC_Sub Sub_not [q2,S2] by SUBSTUT1:29 .= CQC_Sub ['not' q2,S2]
     by A20,SUBSTUT1:def 20
    .= CQC_Sub [p2,S2] by A19;
  end;
A21: for r,s st P[r] & P[s] holds P[r '&' s]
  proof
    let r,s such that
A22: P[r] & P[s];
    set r2 = Al2-Cast(r);
    set s2 = Al2-Cast(s);
    reconsider r2,s2 as Element of CQC-WFF(Al2);
    let p2 be Element of CQC-WFF(Al2), S be CQC_Substitution of Al,
    S2 be CQC_Substitution of Al2 such that
A23: r '&' s = p2 & S = S2;
A24: CQC_Sub[r,S] = CQC_Sub[r2,S2] & CQC_Sub[s,S] = CQC_Sub[s2,S2] by A22,A23;
A25: [r,S]`1 = r & [r,S]`2 = S & [s,S]`1 = s & [s,S]`2 = S & [r2,S2]`1 = r2 &
     [r2,S2]`2 = S2 & [s2,S2]`1 = s2 & [s2,S2]`2 = S2;
    thus CQC_Sub[r '&' s,S] = CQC_Sub CQCSub_&([r,S],[s,S]) by SUBSTUT2:19
     .= Al2-Cast((CQC_Sub [r,S]) '&' (CQC_Sub[s,S])) by A25,SUBLEMMA:23
     .= Al2-Cast(CQC_Sub [r,S]) '&' Al2-Cast(CQC_Sub[s,S])
     .= CQC_Sub CQCSub_&([r2,S2],[s2,S2]) by A24,A25,SUBLEMMA:23
     .= CQC_Sub [r2 '&' s2,S2] by SUBSTUT2:19
     .= CQC_Sub [p2,S2] by A23;
  end;
  for z being bound_QC-variable of Al,q st P[q] holds P[All(z,q)]
  proof
    let z be bound_QC-variable of Al,q such that
A26: P[q];
    set p = All(z,q);
    set q2 = Al2-Cast(q);
    set z2 = Al2-Cast(z);
    reconsider p as Element of CQC-WFF(Al);
    let p2 be Element of CQC-WFF(Al2), S be CQC_Substitution of Al,
     S2 be CQC_Substitution of Al2 such that
A27: All(z,q) = p2 & S = S2;
    set qsc = Qsc(q,z,S);
    set qsc2 = Qsc(q2,z2,S2);
    set sub = [All(z,q),S];
    set sub2 = [All(z2,q2),S2];
    set qscope = [q,(CFQ(Al)).sub];
    set qscope2 = [q2,(CFQ(Al2)).sub2];
A28: QScope(q,z,S) = [qscope,z] by SUBSTUT2:def 3;
    reconsider qscope as Element of CQC-Sub-WFF(Al);
    reconsider qsc as second_Q_comp of [qscope,z] by SUBSTUT2:def 3;
A29: QScope(q2,z2,S2) = [qscope2,z2] by SUBSTUT2:def 3;
    reconsider qscope2 as Element of CQC-Sub-WFF(Al2);
    reconsider qsc2 as second_Q_comp of [qscope2,z2] by SUBSTUT2:def 3;
A30: sub = CQCSub_All([qscope,z],qsc) & [qscope,z] is quantifiable &
     sub2 = CQCSub_All([qscope2,z2],qsc2) & [qscope2,z2] is quantifiable
     by A28,A29,SUBSTUT2:22;
    set expandsub = ExpandSub(z,q,RestrictSub(z,All(z,q),S));
    set expandsub2 = ExpandSub(z2,q2,RestrictSub(z2,All(z2,q2),S2));
A31: All(z,q) is universal & All(z2,q2) is universal;
     then z = bound_in All(z,q) & q = the_scope_of All(z,q) &
      z2 = bound_in All(z2,q2) & q2 = the_scope_of All(z2,q2)
     by QC_LANG1:def 27, def 28;
    then All(z,q),S PQSub expandsub &
     All(z2,q2),S2 PQSub expandsub2 by A31,SUBSTUT1:def 14;
    then [sub,expandsub] in QSub(Al) & [sub2,expandsub2] in QSub(Al2)
     by SUBSTUT1:def 15;
    then [sub,expandsub] in (QSub(Al))|(CQC-Sub-WFF(Al)) &
     [sub2,expandsub2] in (QSub(Al2))|(CQC-Sub-WFF(Al2)) by RELAT_1:def 11;
    then
A32:[sub,expandsub] in CFQ(Al) & [sub2,expandsub2] in CFQ(Al2)
     by SUBSTUT2:def 2;
    set scope = CQCSub_the_scope_of sub;
    set scope2 = CQCSub_the_scope_of sub2;
A33: bound_in sub`1 = z by A31,QC_LANG1:def 27
      .= bound_in sub2`1 by A31,QC_LANG1:def 27;
A34: the_scope_of sub`1 = q by A31,QC_LANG1:def 28
      .= the_scope_of sub2`1 by A31,QC_LANG1:def 28;
A35: expandsub = expandsub2 by A27,Th15;
A36: CQC_Sub qscope = CQC_Sub[q,expandsub] by A32,FUNCT_1:1
      .= CQC_Sub qscope2 by A26,A32,A35,FUNCT_1:1;
    CQC_Sub [p,S] = CQCQuant(sub, CQC_Sub scope) by A30,SUBLEMMA:27,28
     .= Quant(sub,CQC_Sub scope) by A30,SUBLEMMA:27,def 7
     .= All(S_Bound(@sub),CQC_Sub scope) by SUBSTUT1:def 37
     .= Al2-Cast(All(S_Bound(@sub),CQC_Sub qscope)) by A30,SUBLEMMA:30
     .= All(S_Bound(@sub2),CQC_Sub qscope2) by A36,A27,A31,A33,A34,Th16
     .= All(S_Bound(@sub2),CQC_Sub scope2) by A30,SUBLEMMA:30
     .= Quant(sub2,CQC_Sub scope2) by SUBSTUT1:def 37
     .= CQCQuant(sub2, CQC_Sub scope2) by A30,SUBLEMMA:27,def 7
     .= CQC_Sub [p2,S2] by A27,A30,SUBLEMMA:27,28;
    hence thesis;
  end;
then
A37: for r,s,x,k,l,P holds P[VERUM(Al)] & P[P!l] & (P[r] implies P['not' r]) &
  (P[r] & P[s] implies P[r '&' s]) & (P[r] implies P[All(x, r)])
   by A1,A5,A17,A21;
A38: for p being Element of CQC-WFF(Al) holds P[p] from CQC_LANG:sch 1(A37);
  let p2 be Element of CQC-WFF(Al2),x2,y2 be bound_QC-variable of Al2 ,p,x,y
   such that
A39: p=p2 & x=x2 & y=y2;
  thus p.(x,y) = CQC_Sub [p,Sbst(x,y)] by SUBSTUT2:def 1
   .= CQC_Sub [p2,Sbst(x2,y2)] by A38,A39 .= p2.(x2,y2) by SUBSTUT2:def 1;
end;
