reserve Al for QC-alphabet;
reserve a,a1,a2,b,c,d for set,
  X,Y,Z for Subset of CQC-WFF(Al),
  i,k,m,n for Nat,
  p,q for Element of CQC-WFF(Al),
  P for QC-pred_symbol of k,Al,
  ll for CQC-variable_list of k,Al,
  f,f1,f2,g for FinSequence of CQC-WFF(Al);
reserve A for non empty finite Subset of NAT;
reserve C for non empty set;

theorem
  X \/ {p} |- q implies ex g st rng g c= X & |- g^<*p*>^<*q*>
proof
  assume X \/ {p} |- q;
  then consider f such that
A1: rng f c= X \/ {p} and
A2: |- f^<*q*>;
A3: now
    set g = f - {p};
    reconsider A = f"{p} as finite set;
    reconsider B = dom f as finite set;
    set n = card A;
    set h = g^IdFinS(p,n);
A4: len IdFinS(p,n) = n by CARD_1:def 7;
    A c= B by RELAT_1:132;
    then A c= Seg len f by FINSEQ_1:def 3;
    then
a5: A is included_in_Seg by FINSEQ_1:def 13;
A6: now
      let i;
      reconsider j = i-len g as Integer;
      assume
A7:   i in seq(len g,n);
      then
A8:   1+len g <= i by CALCUL_2:1;
      then
A9:   1 <= j by XREAL_1:19;
      i <= n+len g by A7,CALCUL_2:1;
      then
A10:  j <= n by XREAL_1:20;
      0 <= j by A8,XREAL_1:19;
      then reconsider j as Element of NAT by INT_1:3;
      j in Seg n by A9,A10,FINSEQ_1:1;
      hence i-len g in dom Sgm(A) by a5,FINSEQ_3:40;
    end;
    assume not rng f c= X;
    then consider a being object such that
A11: a in rng f and
A12: not a in X;
    a in X or a in {p} by A1,A11,XBOOLE_0:def 3;
    then a = p by A12,TARSKI:def 1;
    then consider i being Nat such that
A13: i in B and
A14: f.i = p by A11,FINSEQ_2:10;
    reconsider C = B \ A as finite set;
    defpred P[Nat,object] means
($1 in Seg len g implies $2 = Sgm(B \ A).$1) & (
    $1 in seq(len g,n) implies $2 = Sgm(A).($1 - len g));
A15: card C = card B - n by CARD_2:44,RELAT_1:132
      .= card Seg len f - n by FINSEQ_1:def 3
      .= len f - n by FINSEQ_1:57
      .= len g by FINSEQ_3:59;
A16: for k be Nat st k in Seg len h ex a being object st P[k,a]
    proof
      let k be Nat such that
      k in Seg len h;
      now
        assume
A17:    k in Seg len g;
        take a = Sgm(B\A).k;
        Seg len g misses seq(len g,n) by CALCUL_2:8;
        hence P[k,a] by A17,XBOOLE_0:3;
      end;
      hence thesis;
    end;
    consider F being FinSequence such that
A18: dom F = Seg len h & for k be Nat st k in Seg len h holds P[k,F.k]
    from FINSEQ_1:sch 1(A16);
A20: dom Sgm(C) = Seg card C by FINSEQ_3:40;
A21: rng F = B
    proof
      now
        let a be object;
        assume a in rng F;
        then consider i being Nat such that
A22:    i in dom F and
A23:    F.i = a by FINSEQ_2:10;
A24:    now
          assume i in Seg len g;
          then a = Sgm(C).i & i in dom Sgm(C) by A18,A15,A22,A23,
FINSEQ_3:40;
          then a in rng Sgm(C) by FUNCT_1:3;
          then a in C by FINSEQ_1:def 14;
          hence a in B;
        end;
A25:    now
A26:      rng Sgm(A) = A by a5,FINSEQ_1:def 14;
A27:      A c= B by RELAT_1:132;
          assume
A28:      i in seq(len g,n);
          then a = Sgm(A).(i-len g) by A18,A22,A23;
          then a in A by A6,A28,A26,FUNCT_1:3;
          hence a in B by A27;
        end;
        i in Seg len g \/ seq(len g,n) by A4,A18,A22,Lm1;
        hence a in B by A24,A25,XBOOLE_0:def 3;
      end;
      hence rng F c= B;
      let a be object such that
A29:  a in B;
A30:  now
        assume not a in A;
        then a in C by A29,XBOOLE_0:def 5;
        then a in rng Sgm(C) by FINSEQ_1:def 14;
        then consider i being Nat such that
A32:    i in dom Sgm(C) and
A33:    Sgm(C).i = a by FINSEQ_2:10;
A34:    1 <= i by A32,FINSEQ_3:25;
        len Sgm(C) = len g by A20,A15,FINSEQ_1:def 3;
        then
A35:    i <= len g by A32,FINSEQ_3:25;
        len g <= len h by CALCUL_1:6;
        then i <= len h by A35,XXREAL_0:2;
        then
A36:    i in Seg len h by A34,FINSEQ_1:1;
        i in Seg len g by A34,A35,FINSEQ_1:1;
        then a = F.i by A18,A33,A36;
        hence thesis by A18,A36,FUNCT_1:3;
      end;
      now
        assume
A37:    a in A;
        rng Sgm(A) = A by a5,FINSEQ_1:def 14;
        then consider i being Nat such that
A38:    i in dom Sgm(A) and
A39:    Sgm(A).i = a by A37,FINSEQ_2:10;
        reconsider i as Nat;
        set m = i + len g;
        len Sgm(A) = n by a5,FINSEQ_3:39;
        then i <= n by A38,FINSEQ_3:25;
        then
A40:    m <= n+len g by XREAL_1:6;
        then m <= len g + len IdFinS(p,n) by CARD_1:def 7;
        then
A41:    m <= len h by FINSEQ_1:22;
A42:    1 <= i by A38,FINSEQ_3:25;
        then 1+len g <= m by XREAL_1:6;
        then
A43:    m in seq(len g,n) by A40,CALCUL_2:1;
        i <= m by NAT_1:11;
        then 1 <= m by A42,XXREAL_0:2;
        then m in dom h by A41,FINSEQ_3:25;
        then
A44:    m in Seg len h by FINSEQ_1:def 3;
        a = Sgm(A).(m - len g) by A39;
        then a = F.m by A18,A43,A44;
        hence thesis by A18,A44,FUNCT_1:3;
      end;
      hence thesis by A30;
    end;
A45: len h = len g + len IdFinS(p,n) by FINSEQ_1:22
      .= len f - n + len IdFinS(p,n) by FINSEQ_3:59
      .= len f - n + n by CARD_1:def 7
      .= len f;
    then
A46: dom F = B by A18,FINSEQ_1:def 3;
    then reconsider F as Relation of B,B by A21,RELSET_1:4;
    rng F c= B;
    then reconsider F as Function of B,B by A46,FUNCT_2:2;
    F is one-to-one
    proof
      let a1,a2 be object such that
A47:  a1 in dom F and
A48:  a2 in dom F and
A49:  F.a1 = F.a2;
A50:  a2 in Seg len g \/ seq(len g,n) by A4,A18,A48,Lm1;
A51:  now
        assume
A52:    a1 in Seg len g;
        then
A53:    a1 in dom Sgm(C) by A15,FINSEQ_3:40;
        F.a1 = Sgm(C).a1 by A18,A47,A52;
        then F.a1 in rng Sgm(C) by A53,FUNCT_1:3;
        then
A54:    F.a1 in C by FINSEQ_1:def 14;
A55:    now
          assume
A56:      a2 in seq(len g,n);
          then reconsider i = a2 as Nat;
          Sgm(A).(i-len g) in rng Sgm(A) by A6,A56,FUNCT_1:3;
          then F.a2 in rng Sgm(A) by A18,A48,A56;
          then F.a2 in A by a5,FINSEQ_1:def 14;
          hence contradiction by A49,A54,XBOOLE_0:def 5;
        end;
        now
          assume
A57:      a2 in Seg len g;
          then F.a2 = Sgm(C).a2 by A18,A48;
          then
A58:      Sgm(C).a1 = Sgm(C).a2 by A18,A47,A49,A52;
A59:      Sgm(C) is one-to-one by FINSEQ_3:92;
          a2 in dom Sgm(C) by A15,A57,FINSEQ_3:40;
          hence thesis by A53,A58,A59;
        end;
        hence thesis by A50,A55,XBOOLE_0:def 3;
      end;
A60:  now
        assume
A61:    a1 in seq(len g,n);
        then reconsider i = a1 as Nat;
A62:    i-len g in dom Sgm(A) by A6,A61;
A63:    now
          assume
A64:      a2 in seq(len g,n);
          then reconsider i1 = a2 as Nat;
          F.a2 = Sgm(A).(i1-len g) by A18,A48,A64;
          then
A65:      Sgm(A).(i1-len g) = Sgm(A).(i-len g) by A18,A47,A49,A61;
A66:      Sgm(A) is one-to-one by a5,FINSEQ_3:92;
          i1-len g in dom Sgm(A) by A6,A64;
          then i1-len g+len g = i-len g+len g by A62,A65,A66;
          hence thesis;
        end;
        Sgm(A).(i-len g) in rng Sgm(A) by A6,A61,FUNCT_1:3;
        then F.a1 in rng Sgm(A) by A18,A47,A61;
        then
A67:    F.a1 in A by a5,FINSEQ_1:def 14;
        now
          assume a2 in Seg len g;
          then F.a2 = Sgm(C).a2 & a2 in dom Sgm(C) by A18,A15,A48,
FINSEQ_3:40;
          then F.a2 in rng Sgm(C) by FUNCT_1:3;
          then F.a2 in C by FINSEQ_1:def 14;
          hence contradiction by A49,A67,XBOOLE_0:def 5;
        end;
        hence thesis by A50,A63,XBOOLE_0:def 3;
      end;
      a1 in Seg len g \/ seq(len g,n) by A4,A18,A47,Lm1;
      hence thesis by A51,A60,XBOOLE_0:def 3;
    end;
    then reconsider F as Permutation of dom f by A21,FUNCT_2:57;
    consider j being Nat such that
A68: j in dom F and
A69: F.j = i by A21,A13,FINSEQ_2:10;
A70: dom Per(f,F) = B by CALCUL_2:19
      .= dom F by A18,A45,FINSEQ_1:def 3
      .= dom h by A18,FINSEQ_1:def 3;
A71: now
      let k be Nat such that
A72:  k in dom h;
A73:  k in Seg len h by A72,FINSEQ_1:def 3;
A74:  now
A75:    k in dom (F*f) by A70,A72,CALCUL_2:def 2;
        given i be Nat such that
A76:    i in dom IdFinS(p,n) and
A77:    k = len g + i;
        len IdFinS(p,n) = n by CARD_1:def 7;
        then
A78:    i <= n by A76,FINSEQ_3:25;
        then
A79:    k <= n+len g by A77,XREAL_1:6;
A80:    1 <= i by A76,FINSEQ_3:25;
        then 1+len g <= k by A77,XREAL_1:6;
        then
A81:    k in seq(len g,n) by A79,CALCUL_2:1;
        then F.k = Sgm(A).(k-len g) by A18,A73;
        then F.k in rng Sgm(A) by A6,A81,FUNCT_1:3;
        then F.k in A by a5,FINSEQ_1:def 14;
        then f.(F.k) in {p} by FUNCT_1:def 7;
        then f.(F.k) = p by TARSKI:def 1;
        then (F*f).k = p by A75,FUNCT_1:12;
        then
A82:    Per(f,F).k = p by CALCUL_2:def 2;
        i in Seg n by A80,A78,FINSEQ_1:1;
        hence Per(f,F).k = IdFinS(p,n).i by A82,FUNCOP_1:7
          .= h.k by A76,A77,FINSEQ_1:def 7;
      end;
      now
        assume
A83:    k in dom g;
        then
A84:    k in dom Sgm(C) by A20,A15,FINSEQ_1:def 3;
        k in Seg len g by A83,FINSEQ_1:def 3;
        then
A85:    F.k = Sgm(C).k by A18,A73;
        k in dom (F*f) by A70,A72,CALCUL_2:def 2;
        then (F*f).k = f.(Sgm(C).k) by A85,FUNCT_1:12;
        hence Per(f,F).k = f.(Sgm(C).k) by CALCUL_2:def 2
          .= (Sgm(C)*f).k by A84,FUNCT_1:13
          .= g.k by FINSEQ_3:def 1
          .= h.k by A83,FINSEQ_1:def 7;
      end;
      hence Per(f,F).k = h.k by A72,A74,FINSEQ_1:25;
    end;
    then
A86: Per(f,F) = h by A70;
    reconsider h as FinSequence of CQC-WFF(Al) by A70,A71,FINSEQ_1:13;
    (F*f).j = p by A14,A68,A69,FUNCT_1:13;
    then
A87: h.j = p by A86,CALCUL_2:def 2;
A88: now
      assume
A89:  j in dom g;
      then g.j = p by A87,FINSEQ_1:def 7;
      then
A90:  g.j in {p} by TARSKI:def 1;
A91:  rng g = rng f \ {p} by FINSEQ_3:65;
      g.j in rng g by A89,FUNCT_1:3;
      hence contradiction by A90,A91,XBOOLE_0:def 5;
    end;
    j in dom f by A68;
    then j in dom h by A70,CALCUL_2:19;
    then consider k be Nat such that
A92: k in dom IdFinS(p,n) and
    j = len g + k by A88,FINSEQ_1:25;
    reconsider g as FinSequence of CQC-WFF(Al) by FINSEQ_3:86;
    1 <= k & k <= len IdFinS(p,n) by A92,FINSEQ_3:25;
    then 1 <= len IdFinS(p,n) by XXREAL_0:2;
    then
A93: 1 <= n by CARD_1:def 7;
    |- h^<*q*> by A2,A86,CALCUL_2:30;
    then
A94: |- g^<*p*>^<*q*> by A93,CALCUL_2:32;
    take g;
    rng g = rng f \ {p} & rng f \ {p} c= (X \/ {p}) \ {p} by A1,FINSEQ_3:65
,XBOOLE_1:33;
    then
A95: rng g c= X \ {p} by XBOOLE_1:40;
    X \ {p} c= X by XBOOLE_1:36;
    hence thesis by A94,A95,XBOOLE_1:1;
  end;
  now
    assume
A96: rng f c= X;
    take f;
    |- f^<*p*>^<*q*> by A2,Th5;
    hence thesis by A96;
  end;
  hence thesis by A3;
end;
