reserve x,y for object,
  N for Element of NAT,
  c,i,j,k,m,n for Nat,
  D for non empty set,
  s for Element of 2Set Seg (n+2),
  p for Element of Permutations(n) ,
  p1, q1 for Element of Permutations(n+1),
  p2 for Element of Permutations(n +2),
  K for Field,
  a for Element of K,
  f for FinSequence of K,
  A for (Matrix of K),
  AD for Matrix of n,m,D,
  pD for FinSequence of D,
  M for Matrix of n,K;

theorem Th25:
  for i be Nat, M be Matrix of n,K st i in Seg n holds Det M = Sum
  LaplaceExpL(M,i)
proof
  reconsider N=n as Element of NAT by ORDINAL1:def 12;
  set P=Permutations n;
  set KK=the carrier of K;
  set aa=the addF of K;
A1: aa is having_a_unity by FVSUM_1:8;
  let i be Nat, M be Matrix of n,K such that
A2: i in Seg n;
  reconsider X=finSeg N as non empty set by A2;
  set Path=Path_product(M);
  deffunc G(Element of Fin P)=aa $$ ($1,Path);
  consider g be Function of Fin P,KK such that
A3: for x being Element of Fin P holds g.x = G(x) from FUNCT_2:sch 4;
A4: for A,B be Element of Fin P st A misses B holds aa.(g.A,g.B)=g.(A \/ B)
  proof
    let A,B be Element of Fin P such that
A5: A misses B;
A6: g.(A)=G(A) by A3;
A7: g.B=G(B) by A3;
    g.(A \/ B)=G(A\/B) by A3;
    hence thesis by A5,A6,A7,FVSUM_1:8,SETWOP_2:4;
  end;
  deffunc F(object) = {p:p.i=$1};
  consider f be Function such that
A8: dom f = X &
for x being object st x in X holds f.x = F(x) from FUNCT_1:sch 3;
  rng f c= Fin P
  proof
    let x be object;
    assume x in rng f;
    then consider y being object such that
A9: y in dom f and
A10: f.y=x by FUNCT_1:def 3;
A11: F(y) c= P
    proof
      let z be object;
      assume z in F(y);
      then ex p st p=z& p.i=y;
      hence thesis;
    end;
    F(y) in Fin P by A11,FINSUB_1:def 5;
    hence thesis by A8,A9,A10;
  end;
  then reconsider f as Function of X,Fin P by A8,FUNCT_2:2;
A12: g.In(P,Fin P)=Det M by A3;
  set gf=g*f;
A13: dom gf=X by FUNCT_2:def 1;
  then
A14: gf*(id X)=gf by RELAT_1:52;
A15: P c= union (f.:X)
  proof
    let x be object;
    assume
A16: x in P;
    then reconsider p=x as Permutation of X by MATRIX_1:def 12;
A17: x in F(p.i) by A16;
A18: rng p=X by FUNCT_2:def 3;
    dom p=X by FUNCT_2:52;
    then
A19: p.i in X by A2,A18,FUNCT_1:def 3;
    then
A20: f.(p.i) in f.:X by A8,FUNCT_1:def 6;
    f.(p.i)=F(p.i) by A8,A19;
    hence thesis by A17,A20,TARSKI:def 4;
  end;
  set L=LaplaceExpL(M,i);
  len L=n by Def7;
  then
A21: dom L=Seg n by FINSEQ_1:def 3;
  then
A22: dom id X=dom L;
  reconsider X9=X as Element of Fin X by FINSUB_1:def 5;
  P in Fin P by FINSUB_1:def 5; then
A23: In(P,Fin P)=P by SUBSET_1:def 8;
  g.{}.Fin P=aa $$ ({}.P,Path) by A3;
  then
A24: g.{}=the_unity_wrt aa by FVSUM_1:8,SETWISEO:31;
A25: now
    let x,y such that
A26: x in X9 and
A27: y in X9 and
A28: f.x meets f.y;
    consider z being object such that
A29: z in f.x and
A30: z in f.y by A28,XBOOLE_0:3;
    f.y=F(y) by A8,A27;
    then
A31: ex p st p=z& p.i=y by A30;
    f.x=F(x) by A8,A26;
    then ex p st p=z& p.i=x by A29;
    hence x=y by A31;
  end;
  now
A32: rng f c= Fin P by RELAT_1:def 19;
    let x be object such that
A33: x in dom gf;
    consider k being Nat such that
A34: k=x and
    1<=k and
    k<=n by A13,A33;
    f.k in rng f by A8,A33,A34,FUNCT_1:def 3;
    then reconsider Fk=F(k) as Element of Fin P by A8,A33,A34,A32;
A35: f.k=Fk by A8,A33,A34;
    gf.k=g.(f.k) by A8,A33,A34,FUNCT_1:13;
    then
A36: gf.k=G(Fk) by A3,A35;
    G(Fk)=M*(i,k)*Cofactor(M,i,k) by A2,A33,A34,Th23;
    hence L.x=gf.x by A21,A33,A34,A36,Def7;
  end;
  then
A37: L=gf by A21,A13,FUNCT_1:2;
  set Laa=[#](L,the_unity_wrt aa);
A38: rng id X=X9;
A39: Laa| (dom L)=L by SETWOP_2:21;
  union (f.:X) c= P
  proof
    let x be object;
    assume x in union (f.:X);
    then consider y being set such that
A40: x in y and
A41: y in f.:X by TARSKI:def 4;
    consider z be object such that
A42: z in dom f and
    z in X and
A43: f.z=y by A41,FUNCT_1:def 6;
    y=F(z) by A8,A42,A43;
    then ex p st x=p & p.i=z by A40;
    hence thesis;
  end;
  then P=union (f.:X) by A15,XBOOLE_0:def 10;
  then
A44: aa $$ (f.:X9,g)= g.In(P,Fin P) by A25,A4,A1,A24,A23,Th12;
  aa $$ (X9,g*f)=aa $$ (f.:X9,g) by A25,A4,A1,A24,Th12;
  hence Det M = aa $$(findom L,Laa) by A22,A38,A39,A14,A37,A44,A12,SETWOP_2:5
    .= Sum L by FVSUM_1:8,SETWOP_2:def 2;
end;
