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 |- 'not' p iff X \/ {p} is Inconsistent
proof
  thus X |- 'not' p implies X \/ {p} is Inconsistent
  proof
    assume X |- 'not' p;
    then consider f such that
A1: rng f c= X and
A2: |- f^<*'not' p*>;
    set f2 = f^<*p*>;
    set f1 = f^<*p*>^<*p*>;
A3: Ant(f1) = f^<*p*> by CALCUL_1:5;
    1 in Seg 1 by FINSEQ_1:1;
    then 1 in dom <*p*> by FINSEQ_1:38;
    then
A4: len f+1 in dom (Ant(f1)) by A3,FINSEQ_1:28;
    Suc(f1) = p by CALCUL_1:5;
    then (Ant(f1)).(len f+1) = Suc(f1) by A3,FINSEQ_1:42;
    then Suc(f1) is_tail_of Ant(f1) by A4,CALCUL_1:def 16;
    then
A5: |- f1 by CALCUL_1:33;
A6: 0+1 <= len f2 by CALCUL_1:10;
    Ant(f2) = f & Suc(f2) = p by CALCUL_1:5;
    then
A7: rng f2 = rng f \/ {p} by A6,CALCUL_1:3;
    |- f^<*p*>^<*'not' p*> by A2,Th5;
    then not f^<*p*> is Consistent by A5;
    hence thesis by A1,A7,Th4,XBOOLE_1:9;
  end;
  thus X \/ {p} is Inconsistent implies X |- 'not' p
  proof
    assume X \/ {p} is Inconsistent;
    then X \/ {p} |- 'not' p by Th6;
    then consider f such that
A8: rng f c= X \/ {p} and
A9: |- f^<*'not' p*>;
    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);
A10:  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
a11:  A is included_in_Seg by FINSEQ_1:def 13;
A12:  now
        let i;
        reconsider j = i-len g as Integer;
        assume
A13:    i in seq(len g,n);
        then
A14:    1+len g <= i by CALCUL_2:1;
        then
A15:    1 <= j by XREAL_1:19;
        i <= n+len g by A13,CALCUL_2:1;
        then
A16:    j <= n by XREAL_1:20;
        0 <= j by A14,XREAL_1:19;
        then reconsider j as Element of NAT by INT_1:3;
        j in Seg n by A15,A16,FINSEQ_1:1;
        hence i-len g in dom Sgm(A) by a11,FINSEQ_3:40;
      end;
      assume not rng f c= X;
      then consider a being object such that
A17:  a in rng f and
A18:  not a in X;
      a in X or a in {p} by A8,A17,XBOOLE_0:def 3;
      then a = p by A18,TARSKI:def 1;
      then consider i being Nat such that
A19:  i in B and
A20:  f.i = p by A17,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));
A21:  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;
A22:  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
A23:      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 A23,XBOOLE_0:3;
        end;
        hence thesis;
      end;
      consider F being FinSequence such that
A24:  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(A22);
A26:  dom Sgm(C) = Seg card C by FINSEQ_3:40;
A27:  rng F = B
      proof
        now
          let a be object;
          assume a in rng F;
          then consider i being Nat such that
A28:      i in dom F and
A29:      F.i = a by FINSEQ_2:10;
A30:      now
            assume i in Seg len g;
            then a = Sgm(C).i & i in dom Sgm(C) by A24,A21,A28,A29,
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;
A31:      now
A32:        rng Sgm(A) = A by a11,FINSEQ_1:def 14;
A33:        A c= B by RELAT_1:132;
            assume
A34:        i in seq(len g,n);
            then a = Sgm(A).(i-len g) by A24,A28,A29;
            then a in A by A12,A34,A32,FUNCT_1:3;
            hence a in B by A33;
          end;
          i in Seg len g \/ seq(len g,n) by A10,A24,A28,Lm1;
          hence a in B by A30,A31,XBOOLE_0:def 3;
        end;
        hence rng F c= B;
        let a be object such that
A35:    a in B;
A36:    now
          assume not a in A;
          then a in C by A35,XBOOLE_0:def 5;
          then a in rng Sgm(C) by FINSEQ_1:def 14;
          then consider i being Nat such that
A38:      i in dom Sgm(C) and
A39:      Sgm(C).i = a by FINSEQ_2:10;
A40:      1 <= i by A38,FINSEQ_3:25;
          len Sgm(C) = len g by A26,A21,FINSEQ_1:def 3;
          then
A41:      i <= len g by A38,FINSEQ_3:25;
          len g <= len h by CALCUL_1:6;
          then i <= len h by A41,XXREAL_0:2;
          then
A42:      i in Seg len h by A40,FINSEQ_1:1;
          i in Seg len g by A40,A41,FINSEQ_1:1;
          then a = F.i by A24,A39,A42;
          hence thesis by A24,A42,FUNCT_1:3;
        end;
        now
          assume
A43:      a in A;
          rng Sgm(A) = A by a11,FINSEQ_1:def 14;
          then consider i being Nat such that
A44:      i in dom Sgm(A) and
A45:      Sgm(A).i = a by A43,FINSEQ_2:10;
          reconsider i as Nat;
          set m = i + len g;
          len Sgm(A) = n by a11,FINSEQ_3:39;
          then i <= n by A44,FINSEQ_3:25;
          then
A46:      m <= n+len g by XREAL_1:6;
          then m <= len g + len IdFinS(p,n) by CARD_1:def 7;
          then
A47:      m <= len h by FINSEQ_1:22;
A48:      1 <= i by A44,FINSEQ_3:25;
          then 1+len g <= m by XREAL_1:6;
          then
A49:      m in seq(len g,n) by A46,CALCUL_2:1;
          i <= m by NAT_1:11;
          then 1 <= m by A48,XXREAL_0:2;
          then m in dom h by A47,FINSEQ_3:25;
          then
A50:      m in Seg len h by FINSEQ_1:def 3;
          a = Sgm(A).(m - len g) by A45;
          then a = F.m by A24,A49,A50;
          hence thesis by A24,A50,FUNCT_1:3;
        end;
        hence thesis by A36;
      end;
A51:  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
A52:  dom F = B by A24,FINSEQ_1:def 3;
      then reconsider F as Relation of B,B by A27,RELSET_1:4;
      rng F c= B;
      then reconsider F as Function of B,B by A52,FUNCT_2:2;
      F is one-to-one
      proof
        let a1,a2 be object such that
A53:    a1 in dom F and
A54:    a2 in dom F and
A55:    F.a1 = F.a2;
A56:    a2 in Seg len g \/ seq(len g,n) by A10,A24,A54,Lm1;
A57:    now
          assume
A58:      a1 in Seg len g;
          then
A59:      a1 in dom Sgm(C) by A21,FINSEQ_3:40;
          F.a1 = Sgm(C).a1 by A24,A53,A58;
          then F.a1 in rng Sgm(C) by A59,FUNCT_1:3;
          then
A60:      F.a1 in C by FINSEQ_1:def 14;
A61:      now
            assume
A62:        a2 in seq(len g,n);
            then reconsider i = a2 as Nat;
            Sgm(A).(i-len g) in rng Sgm(A) by A12,A62,FUNCT_1:3;
            then F.a2 in rng Sgm(A) by A24,A54,A62;
            then F.a2 in A by a11,FINSEQ_1:def 14;
            hence contradiction by A55,A60,XBOOLE_0:def 5;
          end;
          now
            assume
A63:        a2 in Seg len g;
            then F.a2 = Sgm(C).a2 by A24,A54;
            then
A64:        Sgm(C).a1 = Sgm(C).a2 by A24,A53,A55,A58;
A65:        Sgm(C) is one-to-one by FINSEQ_3:92;
            a2 in dom Sgm(C) by A21,A63,FINSEQ_3:40;
            hence thesis by A59,A64,A65;
          end;
          hence thesis by A56,A61,XBOOLE_0:def 3;
        end;
A66:    now
          assume
A67:      a1 in seq(len g,n);
          then reconsider i = a1 as Nat;
A68:      i-len g in dom Sgm(A) by A12,A67;
A69:      now
            assume
A70:        a2 in seq(len g,n);
            then reconsider i1 = a2 as Nat;
            F.a2 = Sgm(A).(i1-len g) by A24,A54,A70;
            then
A71:        Sgm(A).(i1-len g) = Sgm(A).(i-len g) by A24,A53,A55,A67;
A72:        Sgm(A) is one-to-one by a11,FINSEQ_3:92;
            i1-len g in dom Sgm(A) by A12,A70;
            then i1-len g+len g = i-len g+len g by A68,A71,A72;
            hence thesis;
          end;
          Sgm(A).(i-len g) in rng Sgm(A) by A12,A67,FUNCT_1:3;
          then F.a1 in rng Sgm(A) by A24,A53,A67;
          then
A73:      F.a1 in A by a11,FINSEQ_1:def 14;
          now
            assume a2 in Seg len g;
            then
            F.a2 = Sgm(C).a2 & a2 in dom Sgm(C) by A24,A21,A54,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 A55,A73,XBOOLE_0:def 5;
          end;
          hence thesis by A56,A69,XBOOLE_0:def 3;
        end;
        a1 in Seg len g \/ seq(len g,n) by A10,A24,A53,Lm1;
        hence thesis by A57,A66,XBOOLE_0:def 3;
      end;
      then reconsider F as Permutation of dom f by A27,FUNCT_2:57;
      consider j being Nat such that
A74:  j in dom F and
A75:  F.j = i by A27,A19,FINSEQ_2:10;
A76:  dom Per(f,F) = B by CALCUL_2:19
        .= dom F by A24,A51,FINSEQ_1:def 3
        .= dom h by A24,FINSEQ_1:def 3;
A77:  now
        let k be Nat such that
A78:    k in dom h;
A79:    k in Seg len h by A78,FINSEQ_1:def 3;
A80:    now
A81:      k in dom (F*f) by A76,A78,CALCUL_2:def 2;
          given i be Nat such that
A82:      i in dom IdFinS(p,n) and
A83:      k = len g + i;
          len IdFinS(p,n) = n by CARD_1:def 7;
          then
A84:      i <= n by A82,FINSEQ_3:25;
          then
A85:      k <= n+len g by A83,XREAL_1:6;
A86:      1 <= i by A82,FINSEQ_3:25;
          then 1+len g <= k by A83,XREAL_1:6;
          then
A87:      k in seq(len g,n) by A85,CALCUL_2:1;
          then F.k = Sgm(A).(k-len g) by A24,A79;
          then F.k in rng Sgm(A) by A12,A87,FUNCT_1:3;
          then F.k in A by a11,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 A81,FUNCT_1:12;
          then
A88:      Per(f,F).k = p by CALCUL_2:def 2;
          i in Seg n by A86,A84,FINSEQ_1:1;
          hence Per(f,F).k = IdFinS(p,n).i by A88,FUNCOP_1:7
            .= h.k by A82,A83,FINSEQ_1:def 7;
        end;
        now
          assume
A89:      k in dom g;
          then
A90:      k in dom Sgm(C) by A26,A21,FINSEQ_1:def 3;
          k in Seg len g by A89,FINSEQ_1:def 3;
          then
A91:      F.k = Sgm(C).k by A24,A79;
          k in dom (F*f) by A76,A78,CALCUL_2:def 2;
          then (F*f).k = f.(Sgm(C).k) by A91,FUNCT_1:12;
          hence Per(f,F).k = f.(Sgm(C).k) by CALCUL_2:def 2
            .= (Sgm(C)*f).k by A90,FUNCT_1:13
            .= g.k by FINSEQ_3:def 1
            .= h.k by A89,FINSEQ_1:def 7;
        end;
        hence Per(f,F).k = h.k by A78,A80,FINSEQ_1:25;
      end;
      then
A92:  Per(f,F) = h by A76;
      reconsider h as FinSequence of CQC-WFF(Al) by A76,A77,FINSEQ_1:13;
      (F*f).j = p by A20,A74,A75,FUNCT_1:13;
      then
A93:  h.j = p by A92,CALCUL_2:def 2;
A94:  now
        assume
A95:    j in dom g;
        then g.j = p by A93,FINSEQ_1:def 7;
        then
A96:    g.j in {p} by TARSKI:def 1;
A97:    rng g = rng f \ {p} by FINSEQ_3:65;
        g.j in rng g by A95,FUNCT_1:3;
        hence contradiction by A96,A97,XBOOLE_0:def 5;
      end;
      j in dom f by A74;
      then j in dom h by A76,CALCUL_2:19;
      then consider k be Nat such that
A98:  k in dom IdFinS(p,n) and
      j = len g + k by A94,FINSEQ_1:25;
      reconsider g as FinSequence of CQC-WFF(Al) by FINSEQ_3:86;
      1 <= k & k <= len IdFinS(p,n) by A98,FINSEQ_3:25;
      then 1 <= len IdFinS(p,n) by XXREAL_0:2;
      then
A99:  1 <= n by CARD_1:def 7;
      |- h^<*'not' p*> by A9,A92,CALCUL_2:30;
      then
A100: |- g^<*p*>^<*'not' p*> by A99,CALCUL_2:32;
      rng g = rng f \ {p} & rng f \ {p} c= (X \/ {p}) \ {p} by A8,FINSEQ_3:65
,XBOOLE_1:33;
      then
A101: rng g c= X \ {p} by XBOOLE_1:40;
      X \ {p} c= X by XBOOLE_1:36;
      then
A102: rng g c= X by A101;
      |- g^<*'not' p*>^<*'not' p*> by CALCUL_2:21;
      then |- g^<*'not' p*> by A100,CALCUL_2:26;
      hence thesis by A102;
    end;
    hence thesis by A9;
  end;
end;
