reserve x, y for object, X for set,
  i, j, k, l, n, m for Nat,
  D for non empty set,
  K for commutative Ring,
  a,b for Element of K,
  perm, p, q for Element of Permutations(n),
  Perm,P for Permutation of Seg n,
  F for Function of Seg n,Seg n,
  perm2, p2, q2, pq2 for Element of Permutations(n+2),
  Perm2 for Permutation of Seg (n+2);
reserve s for Element of 2Set Seg (n+2);
reserve pD for FinSequence of D,
  M for Matrix of n,m,D,
  pK,qK for FinSequence of K,
  A for Matrix of n,K;

theorem Th61:
  for A,B be Matrix of n,K st 0 < n ex P be Function of
  Permutations n,the carrier of K st Det(A*B) = (the addF of K) $$
  (In(Permutations n,Fin Permutations n),P) &
  for perm be Element of Permutations n holds P.perm= (the
  multF of K) $$ Path_matrix(perm,A) * -(Det B,perm)
proof
  let A,B be Matrix of n,K such that
A1: 0 < n;
  set P=Permutations n;
A2: dom id P=P;
  set KK=the carrier of K;
  set mm=the multF of K;
  set aa=the addF of K;
  set AB=A*B;
  set X=Seg n;
  set F=Funcs(X,X);
  consider SUM1 be Function of F,KK such that
A3: for F be Function of X,X ex Path be FinSequence of K st len Path=n &
 (for Fj,j be Nat st j in Seg n & Fj=F.j holds Path.j=A*(j,Fj)) & SUM1.F= mm $$
  Path * Det (B*F) and
A4: Det(AB)=aa $$ (In(F,Fin F),SUM1) by A1,Th60;
  reconsider FP=F\P as Element of Fin F by FINSUB_1:def 5;
A6: P c= F
  proof
    let x be object;
    assume x in P;
    then reconsider p=x as Permutation of X by MATRIX_1:def 12;
    p is Element of F by FUNCT_2:9;
    hence thesis;
  end;
  then reconsider P9=P as Element of Fin F by FINSUB_1:def 5;
  P in Fin P by FINSUB_1:def 5; then
A7: P=In (P,Fin P) by SUBSET_1:def 8;
    F in Fin F by FINSUB_1:def 5; then
A8: In (F,Fin F)=F by SUBSET_1:def 8;
A9: now
    per cases;
    suppose
      FP={};
      then F c= P by XBOOLE_1:37;
      hence Det(AB)=aa $$ (P9,SUM1) by A4,A8,A6,XBOOLE_0:def 10;
    end;
    suppose
A10:  FP<>{};
A11:  0.K = the_unity_wrt aa by FVSUM_1:7;
A12:  SUM1.:FP c= {0.K}
      proof
        let s be object;
        assume s in SUM1.:FP;
        then consider x being object such that
        x in dom SUM1 and
A13:    x in FP and
A14:    s = SUM1.x by FUNCT_1:def 6;
        reconsider f=x as Function of X,X by A13,FUNCT_2:66;
        not f in P by A13,XBOOLE_0:def 5;
        then
A15:    Det(B*f)=0.K by Th54;
        ex Path be FinSequence of K st len Path=n &( for Fj,j be Nat st
j in Seg n & Fj=f.j holds Path.j=A*(j,Fj))& SUM1.f= (mm $$ Path) * Det ( B*f)
        by A3;
        then SUM1.f=0.K by A15;
        hence thesis by A14,TARSKI:def 1;
      end;
      dom SUM1=F by FUNCT_2:def 1;
      then SUM1.:FP={0.K} by A10,A12,ZFMISC_1:33;
      then
A16:  aa $$ (FP,SUM1)=0.K by A11,FVSUM_1:8,SETWOP_2:8;
A17:  FP misses P by XBOOLE_1:79;
A18:  FP\/P=F\/P by XBOOLE_1:39;
      F\/P=F by A6,XBOOLE_1:12;
      hence Det(AB) = aa $$ (P9,SUM1)+0.K by A4,A8,A16,A17,A18,FVSUM_1:8
,SETWOP_2:4
        .= aa $$ (P9,SUM1) by RLVECT_1:4;
    end;
  end;
  dom SUM1=F by FUNCT_2:def 1;
  then
A19: dom (SUM1|P)=P by A6,RELAT_1:62;
  rng (SUM1|P) c= KK by RELAT_1:def 19;
  then reconsider SP=SUM1|P as Function of P,KK by A19,FUNCT_2:2;
  take SP;
A20: rng id P=P;
  SP*id P=SP by A19,RELAT_1:52;
  hence Det(AB)=aa $$ (In(P,Fin P),SP) by A9,A2,A20,A7,SETWOP_2:5;
  let perm be Element of P;
  reconsider Perm=perm as Permutation of X by MATRIX_1:def 12;
  SUM1.Perm=SP.Perm by A19,FUNCT_1:47;
  then consider Path be FinSequence of K such that
A21: len Path=n and
A22: for Fj,j be Nat st j in Seg n & Fj=Perm.j holds Path.j=A*(j,Fj) and
A23: SP.Perm= mm $$ Path * Det (B*Perm) by A3;
  set PM=Path_matrix(perm,A);
A24: len PM=n by MATRIX_3:def 7;
  now
A25: X=dom Perm by FUNCT_2:52;
    let i be Nat such that
A26: 1 <= i and
A27: i <= len Path;
A28: i in X by A21,A26,A27;
    i in X by A21,A26,A27;
    then
A29: Perm.i in rng Perm by A25,FUNCT_1:def 3;
    rng Perm c= X by RELAT_1:def 19;
    then Perm.i in X by A29;
    then reconsider Pi=Perm.i as Element of NAT;
    dom PM=X by A24,FINSEQ_1:def 3;
    then PM.i=A*(i,Pi) by A28,MATRIX_3:def 7;
    hence Path.i=PM.i by A22,A28;
  end;
  then Path=PM by A21,A24;
  hence thesis by A23,Th46;
end;
