reserve x,y,z,X,Y for set;
reserve X,Y for non empty set,
  f for Function of X,Y;
reserve X, Y for non empty set,
  F for (BinOp of Y),
  B for (Element of Fin X),
  f for Function of X,Y;

theorem Th23:
  F is commutative & F is associative & F is idempotent implies
for f,g being Function of X,Y for A,B being Element of Fin X st A <> {} & f.:A
  = g.:B holds F$$(A,f) = F$$(B,g)
proof
  assume that
A1: F is commutative and
A2: F is associative and
A3: F is idempotent;
  let f,g be Function of X,Y;
  defpred X[Element of Fin X] means $1 <> {} implies for B being Element of
  Fin X st f.:$1 = g.:B holds F$$($1,f) = F$$(B,g);
A4: for B9 being Element of Fin X, b being Element of X holds X[B9] implies
  X[B9 \/ {.b.}]
  proof
    let A be (Element of Fin X), x be Element of X such that
A5: A <> {} implies for B being Element of Fin X st f.:A = g.:B holds
    F$$(A,f) = F$$(B,g);
    assume A \/ {x} <> {};
    let B be Element of Fin X such that
A6: f.:(A \/ {x}) = g.:B;
    per cases;
    suppose
      f.x in f.:A;
      then consider x9 being Element of X such that
A7:   x9 in A and
A8:   f.x9 = f.x by FUNCT_2:65;
A9:   g.:B = f.:A \/ Im(f,x) by A6,RELAT_1:120
        .= f.:A \/ {f.x} by Th5
        .= f.:A by A7,A8,FUNCT_2:35,ZFMISC_1:40;
      thus F$$(A \/ {.x.},f) = F.(F$$(A,f), f.x) by A1,A2,A3,A7,Th17
        .= F.(F$$(A \/ {.x9.},f), f.x) by A7,ZFMISC_1:40
        .= F.(F.(F$$(A,f), f.x9), f.x) by A1,A2,A3,A7,Th17
        .= F.(F$$(A,f), F.(f.x9, f.x9)) by A2,A8
        .= F$$(A \/ {.x9.},f) by A1,A2,A3,A7,Th17
        .= F$$(A,f) by A7,ZFMISC_1:40
        .= F$$(B,g) by A5,A7,A9;
    end;
    suppose
A10:  not f.x in f.:A;
      per cases;
      suppose
A11:    A = {};
        then
A12:    g.:B = Im(f,x) by A6
          .= {f.x} by Th5;
        thus F$$(A \/ {.x.},f) = f.x by A1,A2,A11,Th14
          .= F$$(B,g) by A1,A2,A3,A12,Th22;
      end;
      suppose
A13:    A <> {};
        reconsider B1 = B \ g"{f.x} as Element of Fin X by Th8;
A14:    now
          assume B1 = {};
          then
A15:      g.:B c= g.:g"{f.x} by RELAT_1:123,XBOOLE_1:37;
          g.:g"{f.x} c= {f.x} by FUNCT_1:75;
          then f.:(A \/ {x}) c= {f.x} by A6,A15;
          then f.:A \/ f.:{x} c= {f.x} by RELAT_1:120;
          then f.:A = f.:A /\ {f.x} by XBOOLE_1:11,28
            .= {} by A10,XBOOLE_0:def 7,ZFMISC_1:50;
          hence contradiction by A13,Th10;
        end;
        reconsider B2 = B /\ g"{f.x} as Element of Fin X by Th8,XBOOLE_1:17;
A16:    B = B1 \/ B2 by XBOOLE_1:51;
A17:    for b being Element of X st b in B2 holds g.b = f.x
        proof
          let b be Element of X;
          assume b in B2;
          then b in g"{f.x} by XBOOLE_0:def 4;
          then g.b in {f.x} by FUNCT_1:def 7;
          hence thesis by TARSKI:def 1;
        end;
A18:    f.:A = f.:A \ {f.x} by A10,ZFMISC_1:57
          .= f.:A \ Im(f,x) by Th5
          .= (f.:A \/ f.:{x}) \ f.:{x} by XBOOLE_1:40
          .= f.:(A \/ {x}) \ Im(f,x) by RELAT_1:120
          .= g.:B \ {f.x} by A6,Th5
          .= g.:B1 by Th3;
        x in A \/ {x} by ZFMISC_1:136;
        then consider x9 being Element of X such that
A19:    x9 in B and
A20:    g.x9 = f.x by A6,FUNCT_2:35,65;
        x9 in g"{f.x} by A20,Th4;
        then
A21:    B2 <> {} by A19,XBOOLE_0:def 4;
        thus F$$(A \/ {.x.},f) = F.(F$$(A,f), f.x) by A1,A2,A3,A13,Th17
          .= F.(F$$(B1,g), f.x) by A5,A13,A18
          .= F.(F$$(B1,g), F$$(B2,g)) by A1,A2,A3,A21,A17,Th21
          .= F$$(B,g) by A1,A2,A3,A16,A14,A21,Th18;
      end;
    end;
  end;
A22: X[{}.X];
A23: for A being Element of Fin X holds X[A] from FinSubInd3(A22,A4);
  let A,B be Element of Fin X;
  assume A <> {} & f.:A = g.:B;
  hence thesis by A23;
end;
