
theorem :: WWACorB:
  for X being finite non empty set, F being Dependency-set of X, K being
  Subset of X holds K in candidate-keys Dependency-closure F iff K
  is_p_i_w_ncv_of F
proof
  let X be finite non empty set, F be Dependency-set of X, K be Subset of X;
  set dcF = Dependency-closure F;
  set S = {P where P is Subset of X : [K, P] in dcF };
  S c= bool X
  proof
    let x be object;
    assume x in S;
    then ex P being Subset of X st x = P & [K, P] in dcF;
    hence thesis;
  end;
  then reconsider S as Subset-Family of X;
  set ck = candidate-keys dcF;
  set B = {c where c is Subset of X : for x, y being Subset of X st [x, y] in
  F & x c= c holds y c= c};
  [K, K] in dcF by Def11;
  then K in S;
  then consider m being set such that
A1: m in S and
A2: for B being set st B in S holds m c= B implies B = m by FINSET_1:6;
  B = enclosure_of F;
  then
A3: dcF = X deps_encl_by B by Th38;
  hereby
    assume K in ck;
    then consider A being Subset of X such that
A4: K = A and
A5: [A, X] in Maximal_wrt dcF;
A6: A ^|^ X, dcF by A5;
    [A, [#]X] in dcF by A5;
    then consider a, b being Subset of X such that
A7: [A,X] = [a,b] and
A8: for c being set st c in B & a c= c holds b c= c by A3;
A9: X = b by A7,XTUPLE_0:1;
A10: A = a by A7,XTUPLE_0:1;
    thus K is_p_i_w_ncv_of F
    proof
      hereby
        let z be Subset of X such that
A11:    K c= z and
A12:    z <> X and
A13:    not z in charact_set F;
        for x, y being Subset of X st [x,y]in F & x c=z holds y c=z by A13;
        then z in B;
        then X c= z by A4,A8,A10,A9,A11;
        hence contradiction by A12,XBOOLE_0:def 10;
      end;
      let k be set;
      assume
A14:  k c< K;
      then k c= A by A4,XBOOLE_0:def 8;
      then reconsider k as Subset of X by XBOOLE_1:1;
      set S = {P where P is Subset of X : [k, P] in dcF };
      S c= bool X
      proof
        let x be object;
        assume x in S;
        then ex P being Subset of X st x = P & [k, P] in dcF;
        hence thesis;
      end;
      then reconsider S as Subset-Family of X;
      [k, k] in dcF by Def11;
      then k in S;
      then consider m being set such that
A15:  m in S and
A16:  for B being set st B in S holds m c= B implies B =m by FINSET_1:6;
      consider P being Subset of X such that
A17:  m = P and
A18:  [k, P] in dcF by A15;
      [k, k] in dcF by Def11;
      then
A19:  [k\/k, k\/P] in dcF by A18,Def13;
      assume
A20:  not thesis;
A21:  [k, [#]X] in dcF
      proof
        per cases;
        suppose
          k\/P = X;
          hence thesis by A19;
        end;
        suppose
          k\/P <> X;
          then k\/P in charact_set F by A20,XBOOLE_1:7;
          then k\/P in charact_set dcF by Th59;
          then consider x, y being Subset of X such that
A22:      [x, y] in dcF and
A23:      x c= k\/P and
A24:      not y c= k\/P by Th55;
          [k\/P, k\/P] in dcF by Def11;
          then [x\/(k\/P), y\/(k\/P)] in dcF by A22,Def13;
          then [k\/P, y\/(k\/P)] in dcF by A23,XBOOLE_1:12;
          then [k, y\/(k\/P)] in dcF by A19,Th18;
          then
A25:      y\/(k\/P) in S;
          P c= k\/P by XBOOLE_1:7;
          then P = (y\/(k\/P)) by A16,A17,A25,XBOOLE_1:10;
          hence thesis by A24,XBOOLE_1:7,10;
        end;
      end;
      k c= K by A14,XBOOLE_0:def 8;
      then [K,[#]X] <= [k,[#]X];
      hence contradiction by A4,A6,A14,A21,Th27;
    end;
  end;
  consider P being Subset of X such that
A26: m = P and
A27: [K, P] in dcF by A1;
  [K, K] in dcF by Def11;
  then
A28: [K\/K, K\/P] in dcF by A27,Def13;
  assume
A29: K is_p_i_w_ncv_of F;
A30: K c= K\/P by XBOOLE_1:7;
A31: [K, [#]X] in dcF
  proof
    per cases;
    suppose
      K\/P = X;
      hence thesis by A28;
    end;
    suppose
      K\/P <> X;
      then K\/P in charact_set F by A29,A30;
      then K\/P in charact_set dcF by Th59;
      then consider x, y being Subset of X such that
A32:  [x, y] in dcF and
A33:  x c= K\/P and
A34:  not y c= K\/P by Th55;
      [K\/P, K\/P] in dcF by Def11;
      then [x\/(K\/P), y\/(K\/P)] in dcF by A32,Def13;
      then [K\/P, y\/(K\/P)] in dcF by A33,XBOOLE_1:12;
      then [K, y\/(K\/P)] in dcF by A28,Th18;
      then
A35:  y\/(K\/P) in S;
      P c= K\/P by XBOOLE_1:7;
      then P = (y\/(K\/P)) by A2,A26,A35,XBOOLE_1:10;
      hence thesis by A34,XBOOLE_1:7,10;
    end;
  end;
  now
    let x9, y9 be Subset of X such that
A36: [x9, y9] in dcF and
A37: K <> x9 or X <> y9 and
A38: [K, [#]X] <= [x9,y9];
A39: X c= y9 by A38;
    x9 c= K by A38;
    then x9 c< K by A37,A39,XBOOLE_0:def 8,def 10;
    then consider a being Subset of X such that
A40: x9 c= a and
A41: a <> X and
A42: not a in charact_set F by A29;
    X = y9 by A39,XBOOLE_0:def 10;
    then
A43: not y9 c= a by A41,XBOOLE_0:def 10;
    not a in charact_set dcF by A42,Th59;
    hence contradiction by A36,A40,A43;
  end;
  then K ^|^ X, dcF by A31,Th27;
  then [K,X] in Maximal_wrt dcF;
  hence thesis;
end;
