reserve k,n,i,j for Nat;

theorem
  for K being Field, n being Nat, A being Matrix of n,K st n
  >=1 & A is diagonal holds Det A = (the multF of K) $$ (diagonal_of_Matrix A)
proof
  let K be Field, n be Nat, A be Matrix of n,K;
  assume that
A1: n>=1 and
A2: A is diagonal;
  set k1=(the multF of K)$$(diagonal_of_Matrix A);
  set X=Permutations n;
  set Y=the carrier of K;
  reconsider p0=idseq n as Permutation of Seg n;
A3: len (diagonal_of_Matrix A)=n by MATRIX_3:def 10;
  deffunc F2(object) = IFEQ(idseq n,$1,k1,0.K);
A4: for x being object st x in X holds F2(x) in Y;
  ex f2 being Function of X,Y st for x being object st x in X holds f2.x =
  F2(x) from FUNCT_2:sch 2(A4);
  then consider f2 being Function of X,Y such that
A5: for x being object st x in X holds f2.x = F2(x);
A6: p0 is even by MATRIX_1:16;
A7: for x being object st x in dom (Path_product A)
    holds (Path_product A).x= f2.x
  proof
    let x be object;
    assume x in dom Path_product A;
    for p being Element of Permutations n holds f2.p = -((the multF of K)
    $$ Path_matrix(p,A),p)
    proof
      let p be Element of Permutations n;
A8:   now
        per cases;
        suppose
          p is even;
          hence -(0.K,p)=(0.K) by MATRIX_1:def 16;
        end;
        suppose
          p is odd;
          then -(0.K,p)= -(0.K) by MATRIX_1:def 16
            .=0.K by RLVECT_1:12;
          hence -(0.K,p)=0.K;
        end;
      end;
      now
        per cases;
        case
A9:       p=idseq n;
A10:      for i,j st i in dom ((diagonal_of_Matrix A)) & j=p.i holds (
          diagonal_of_Matrix A) .i=(A)*(i,j)
          proof
            let i,j;
            assume that
A11:        i in dom ((diagonal_of_Matrix A)) and
A12:        j=p.i;
A13:        i in Seg n by A3,A11,FINSEQ_1:def 3;
            then p.i=i by A9,FUNCT_1:17;
            hence thesis by A12,A13,MATRIX_3:def 10;
          end;
          len Permutations n = n by MATRIX_1:9;
          then
A14:      -((the multF of K) $$ Path_matrix(p,A),p) = (the multF of K) $$
          Path_matrix(p,(A)) by A6,A9,MATRIX_1:def 16;
          f2.p=F2(p) by A5
            .= k1 by A9,FUNCOP_1:def 8;
          hence thesis by A3,A14,A10,MATRIX_3:def 7;
        end;
        case
A15:      p<>idseq n;
          reconsider Ab=NAT as non empty set;
          defpred P3[Nat] means $1 < n implies ex p3 being
FinSequence of K st len p3=$1+1 & p3.1=(Path_matrix(p,A)).1 & (for n3 being
Nat st 0 <> n3 & n3 < $1+1 & n3<n holds p3.(n3 + 1) = (the multF of
          K). (p3.n3,(Path_matrix(p,A)).(n3 + 1)));
A16:      rng ((Path_matrix(p,A))) c= the carrier of K by FINSEQ_1:def 4;
A17:      len (Path_matrix(p,A))=n by MATRIX_3:def 7;
          then 1 in Seg len (Path_matrix(p,A)) by A1;
          then 1 in dom (Path_matrix(p,A)) by FINSEQ_1:def 3;
          then (Path_matrix(p,A)).1 in rng ((Path_matrix(p,A))) by
FUNCT_1:def 3;
          then reconsider d=(Path_matrix(p,A)).1 as Element of K by A16;
          reconsider q3=<* d *> as FinSequence of K;
A18:      for n3 being Nat st 0 <> n3 & n3 < 0+1 & n3< n holds
q3.(n3 + 1) = (the multF of K). (q3.n3,(Path_matrix(p,A)).(n3 + 1)) by NAT_1:13
          ;
A19:      for k being Nat st P3[k] holds P3[k+1]
          proof
            let k be Nat;
            assume
A20:        P3[k];
            now
              per cases;
              case
A21:            k+1<n;
                then consider p3 being FinSequence of K such that
A22:            len p3=k+1 and
A23:            p3.1=(Path_matrix(p,A)).1 and
A24:            for n3 being Nat st 0 <> n3 & n3 < k+1 &
n3<n holds p3.( n3 + 1) = (the multF of K). (p3.n3,(Path_matrix(p,A)).(n3 + 1))
                by A20,NAT_1:12;
                defpred P6[object,object] means
($1 in Seg (k+1) implies $2=p3.$1)&
                (not $1 in Seg (k+1) implies $2=0.K);
A25:            for x being object st x in NAT
ex y being object st y in the carrier of K & P6[x,y]
                proof
                  let x be object;
                  assume x in NAT;
                  now
                    per cases;
                    case
A26:                  x in Seg (k+1);
                      then reconsider nx=x as Nat;
                      nx in dom p3 by A22,A26,FINSEQ_1:def 3;
                      then
A27:                  p3.nx in rng p3 by FUNCT_1:def 3;
                      rng p3 c= the carrier of K by FINSEQ_1:def 4;
                      then reconsider s=p3.nx as Element of K by A27;
                      x in Seg (k+1) implies s=p3.x;
                      hence thesis by A26;
                    end;
                    case
                      not x in Seg (k+1);
                      hence thesis;
                    end;
                  end;
                  hence thesis;
                end;
                ex f6 being sequence of the carrier of K st for x
         being object st x in NAT holds P6[x,f6.x] from FUNCT_2:sch 1(A25);
                then consider
                f6 being sequence of the carrier of K such that
A28:            for x being object st x in NAT holds P6[x,f6.x];
                1<=k+1+1 & k+1+1 <=n by A21,NAT_1:12,13;
                then k+1+1 in Seg len (Path_matrix(p,A)) by A17;
                then k+1+1 in dom (Path_matrix(p,A)) by FINSEQ_1:def 3;
                then rng ((Path_matrix(p,A))) c= the carrier of K & (
Path_matrix(p,A)).(k + 1+1) in rng (Path_matrix(p,A)) by FINSEQ_1:def 4
,FUNCT_1:def 3;
                then [f6.(k+1),(Path_matrix(p,A)).(k + 1+1)] in [:the carrier
                of K, the carrier of K:] by ZFMISC_1:def 2;
                then reconsider
                e=(the multF of K). (f6.(k+1),(Path_matrix(p,A)).(k
                + 1+1)) as Element of K by FUNCT_2:5;
                reconsider q3=p3^<* e *> as FinSequence of K;
A29:            len q3=(len p3) + len (<*e*>) by FINSEQ_1:22
                  .=k+1+1 by A22,FINSEQ_1:40;
A30:            for n3 being Nat st 0 <> n3 & n3 < k+1+1 & n3<
n holds q3.(n3 + 1) = (the multF of K). (q3.n3,(Path_matrix(p,(A))).(n3 + 1))
                proof
                  let n3 be Nat;
                  assume that
A31:              0 <> n3 and
A32:              n3 < k+1+1 and
A33:              n3<n;
                  now
                    per cases;
                    case
A34:                  n3<k+1;
                      then 1<=n3+1 & n3+1<=k+1 by NAT_1:12,13;
                      then n3+1 in Seg len p3 by A22;
                      then n3+1 in dom p3 by FINSEQ_1:def 3;
                      then
A35:                  p3.(n3+1)=q3.(n3+1) by FINSEQ_1:def 7;
                      0+1<=n3 by A31,NAT_1:13;
                      then n3 in Seg len p3 by A22,A34;
                      then
A36:                  n3 in dom p3 by FINSEQ_1:def 3;
                      p3.(n3 + 1) = (the multF of K) . (p3.n3,(
                      Path_matrix(p,(A))).(n3 + 1)) by A24,A31,A33,A34;
                      hence thesis by A35,A36,FINSEQ_1:def 7;
                    end;
                    case
A37:                  n3>=k+1;
A38:                  n3+1<=k+1+1 by A32,NAT_1:13;
A39:                  n3+1>k+1 by A37,NAT_1:13;
                      then n3+1>=k+1+1 by NAT_1:13;
                      then
A40:                  n3+1=k+1+1 by A38,XXREAL_0:1;
                      1<=k+1 by NAT_1:12;
                      then
A41:                  k+1 in Seg (k+1);
                      then k+1 in dom p3 by A22,FINSEQ_1:def 3;
                      then
A42:                  q3.(k+1)=p3.(k+1) by FINSEQ_1:def 7;
                      (q3).(n3+1) = (<*e*>).(n3+1 - (k+1)) by A22,A29,A39,A38,
FINSEQ_1:24
                        .= e by A40;
                      hence thesis by A28,A40,A41,A42;
                    end;
                  end;
                  hence thesis;
                end;
                1<=k+1 by NAT_1:12;
                then 1 in Seg len p3 by A22;
                then 1 in dom p3 by FINSEQ_1:def 3;
                then q3.1=(Path_matrix(p,(A))).1 by A23,FINSEQ_1:def 7;
                hence thesis by A29,A30;
              end;
              case
                k+1>=n;
                hence thesis;
              end;
            end;
            hence thesis;
          end;
A43:      f2.p=F2(p) by A5
            .= 0.K by A15,FUNCOP_1:def 8;
          n<n+1 by NAT_1:13;
          then
A44:      n-1<n+1-1 by XREAL_1:14;
A45:      dom p = Seg len Permutations n by FUNCT_2:52;
          then
A46:      dom p = Seg n by MATRIX_1:9;
          then dom p = dom idseq n by RELAT_1:45;
          then consider i0 being object such that
A47:      i0 in dom p and
A48:      p.i0 <> (idseq n).i0 by A15,FUNCT_1:2;
A49:      i0 in Seg n by A45,A47,MATRIX_1:9;
          reconsider i0 as Nat by A45,A47;
A50:      p.i0<>i0 by A46,A47,A48,FUNCT_1:18;
          p is Permutation of Seg n by MATRIX_1:def 12;
          then
A51:      p.i0 in Seg n by A46,A47,FUNCT_2:5;
          then reconsider j0=p.i0 as Nat;
A52:      n-1=n-'1 by A1,XREAL_1:233;
          len q3=1 & q3.1=(Path_matrix(p,A)).1 by FINSEQ_1:40;
          then
A53:      P3[0] by A18;
          for k being Nat holds P3[k] from NAT_1:sch 2(A53,
          A19);
          then consider p3 being FinSequence of K such that
A54:      len p3=n-'1+1 and
A55:      p3.1=(Path_matrix(p,A)).1 and
A56:      for n3 being Nat st 0 <> n3 & n3 < n-'1+1 & n3<
n holds p3.(n3 + 1) = (the multF of K). (p3.n3,(Path_matrix(p,(A))).(n3 + 1))
          by A52,A44;
          defpred P[set,set] means ($1 in Seg n implies $2=p3.$1)& (not $1 in
          Seg n implies $2=0.K);
A57:      for x3 being Element of Ab ex y3 being Element of K st P[x3,y3 ]
          proof
            let x3 be Element of Ab;
            now
              per cases;
              case
A58:            x3 in Seg n;
                then x3 in dom p3 by A52,A54,FINSEQ_1:def 3;
                then rng p3 c= the carrier of K & p3.x3 in rng p3 by
FINSEQ_1:def 4,FUNCT_1:def 3;
                hence thesis by A58;
              end;
              case
                not x3 in Seg n;
                hence thesis;
              end;
            end;
            hence thesis;
          end;
          ex f4 being Function of Ab,the carrier of K st for x2 being
          Element of Ab holds P[x2,f4.x2] from FUNCT_2:sch 3(A57);
          then consider f4 being sequence of the carrier of K such that
A59:      for x4 being Element of NAT holds (x4 in Seg n implies f4.
          x4=p3.x4)& (not x4 in Seg n implies f4.x4=0.K);
A60:      for n3 being Nat st 0 <> n3 & n3 < len (Path_matrix(p,A))
     holds f4.(n3 + 1) = (the multF of K). (f4.n3,(Path_matrix(p,A)).(n3 + 1))
          proof
            let n3 be Nat;
            assume that
A61:        0 <> n3 and
A62:        n3 < len (Path_matrix(p,A));
A63:        n3+1<=len (Path_matrix(p,A)) by A62,NAT_1:13;
A64:        0+1<=n3 by A61,NAT_1:13;
            then
A65:        n3 in Seg n by A17,A62;
            1<n3+1 by A64,NAT_1:13;
            then n3+1 in Seg n by A17,A63;
            then
A66:        f4.(n3+1)=p3.(n3+1) by A59;
            p3.(n3 + 1) = (the multF of K). (p3.n3,(Path_matrix(p,A)).(
            n3 + 1)) by A17,A52,A56,A61,A62;
            hence thesis by A59,A66,A65;
          end;
A67:      i0<=n by A46,A47,FINSEQ_1:1;
          then
A68:      n-'i0 =n-i0 by XREAL_1:233;
          i0 in dom (Path_matrix(p,A)) by A49,A17,FINSEQ_1:def 3;
          then
A69:      (Path_matrix(p,A)).i0=(A)*(i0,j0) by MATRIX_3:def 7;
          defpred P5[Nat] means f4.(i0+$1)=0.K;
A70:      0<i0 by A45,A47,FINSEQ_1:1;
A71:      for k being Nat st P5[k] holds P5[k+1]
          proof
            let k be Nat;
A72:        1<=1+(i0+k) by NAT_1:12;
            assume
A73:        P5[k];
            now
              per cases;
              case
A74:            i0+k+1<=n;
                1<=1+(i0+k) by NAT_1:12;
                then i0+k+1 in Seg len (Path_matrix(p,A)) by A17,A74;
                then i0+k+1 in dom (Path_matrix(p,A)) by FINSEQ_1:def 3;
                then
A75:            (Path_matrix(p,A)).(i0+k+1) in rng (Path_matrix(p,A)) by
FUNCT_1:def 3;
                rng (Path_matrix(p,A)) c= the carrier of K by FINSEQ_1:def 4;
                then reconsider
                b=(Path_matrix(p,A)).(i0+k+1) as Element of K by A75;
                i0<=i0+k by NAT_1:12;
                then
A76:            0<i0+k by A45,A47,FINSEQ_1:1;
A77:            i0+k<n by A74,NAT_1:13;
                0+1<=i0+k by A70,NAT_1:13;
                then
A78:            i0+k in Seg n by A77;
                i0+k+1 in Seg n by A72,A74;
                then f4.(i0+k+1)=p3.(i0+k+1) by A59
                  .=(the multF of K). (p3.(i0+k),(Path_matrix(p,A)).(i0+k+1)
                ) by A52,A56,A77,A76
                  .= (0.K)*b by A59,A73,A78
                  .= 0.K;
                hence thesis;
              end;
              case
                i0+k+1>n;
                then not i0+(k+1) in Seg n by FINSEQ_1:1;
                hence thesis by A59;
              end;
            end;
            hence thesis;
          end;
          1 in Seg n by A1;
          then
A79:      f4.1=(Path_matrix(p,A)).1 by A55,A59;
A80:      1<=i0 by A45,A47,FINSEQ_1:1;
          now
            per cases;
            case
              i0<=1;
              then i0=1 by A80,XXREAL_0:1;
              hence P5[0] by A2,A49,A50,A51,A69,A79;
            end;
            case
A81:          i0>1;
              reconsider a=f4.(i0-'1) as Element of K;
              i0<i0+1 by NAT_1:13;
              then i0-1<i0+1-1 by XREAL_1:14;
              then
A82:          i0-1<len (Path_matrix(p,A)) by A67,A17,XXREAL_0:2;
              i0-'1=i0-1 by A81,XREAL_1:233;
              then
A83:          i0-'1+1=i0;
              i0-1> 1-1 by A81,XREAL_1:14;
              then f4.i0 = (the multF of K). (f4.(i0-'1),(Path_matrix(p,A)).
              i0) by A60,A82,A83
                .= a*(0.K) by A2,A49,A50,A51,A69
                .= 0.K;
              hence P5[0];
            end;
          end;
          then
A84:      P5[0];
          for k being Nat holds P5[k] from NAT_1:sch 2(A84,
          A71);
          then P5[n-'i0];
          hence thesis by A1,A8,A43,A17,A79,A60,A68,FINSOP_1:2;
        end;
      end;
      hence thesis;
    end;
    hence thesis by MATRIX_3:def 8;
  end;
  deffunc F3(set) = IFIN(idseq n,$1,k1,0.K);
  set F=the addF of K;
  set f=Path_product(A);
  set B=In(Permutations(n),Fin Permutations n);
A85: for x being set st x in Fin X holds F3(x) in Y
  proof
    let x be set;
    assume x in Fin X;
    per cases;
    suppose
      idseq n in x;
      then F3(x)=k1 by Def1;
      hence thesis;
    end;
    suppose
      not idseq n in x;
      then F3(x)=0.K by Def1;
      hence thesis;
    end;
  end;
  ex f2 being Function of Fin X,Y st
for x being set st x in Fin X holds
  f2.x = F3(x) from FUNCT_2:sch 11(A85);
  then consider G0 being Function of Fin X,Y such that
A86: for x being set st x in Fin X holds G0.x = F3(x);
  dom (f2)=Permutations(n) by FUNCT_2:def 1;
  then
A87: dom (Path_product A)=dom f2 by FUNCT_2:def 1;
  then
A88: Path_product(A)=f2 by A7,FUNCT_1:2;
A89: for B9 being Element of Fin X st B9 c= B & B9 <> {} for x being
  Element of X st x in B\B9 holds G0.(B9 \/ {x}) = F.(G0.B9,f.x)
  proof
    let B9 be Element of Fin X;
    assume that
    B9 c= B and
    B9 <> {};
    thus for x being Element of X st x in B\B9 holds G0.(B9 \/ {x}) = F.(G0.B9
    ,f.x)
    proof
      let x be Element of X;
      assume
A90:  x in B\B9;
A91:  now
        assume
A92:    not idseq n in B9 \/ {x};
        thus G0.(B9 \/ {x})=IFIN(idseq n,B9 \/ {.x.},k1,0.K) by A86
          .=0.K by A92,Def1;
      end;
A93:  0.K is_a_unity_wrt F by FVSUM_1:6;
A94:  now
        assume
A95:    not idseq n in B9;
        thus G0.(B9)=IFIN(idseq n,B9,k1,0.K) by A86
          .=0.K by A95,Def1;
      end;
A96:  now
        assume
A97:    not idseq n in B9 \/ {x};
        then not idseq n in {x} by XBOOLE_0:def 3;
        then
A98:    not idseq n=x by TARSKI:def 1;
        f.x=F2(x) by A5,A88
          .=0.K by A98,FUNCOP_1:def 8;
        hence F.(G0.B9,f.x)=0.K by A94,A93,A97,BINOP_1:3,XBOOLE_0:def 3;
      end;
A99:  now
        assume
A100:   idseq n in B9;
        thus G0.(B9)=IFIN(idseq n,B9,k1,0.K) by A86
          .=k1 by A100,Def1;
      end;
A101: now
        assume idseq n in B9 \/ {x};
        then
A102:   idseq n in B9 or idseq n in {x} by XBOOLE_0:def 3;
        now
          per cases by A102,TARSKI:def 1;
          case
A103:       idseq n in B9;
A104:       not x in B9 by A90,XBOOLE_0:def 5;
            f.x=F2(x) by A5,A88
              .=0.K by A103,A104,FUNCOP_1:def 8;
            hence F.(G0.B9,f.x)=k1 by A99,A93,A103,BINOP_1:3;
          end;
          case
A105:       idseq n=x;
            f.x=F2(x) by A5,A88
              .=k1 by A105,FUNCOP_1:def 8;
            hence F.(G0.B9,f.x)=k1 by A90,A94,A93,A105,BINOP_1:3,XBOOLE_0:def 5
;
          end;
        end;
        hence F.(G0.B9,f.x)=k1;
      end;
      now
        assume
A106:   idseq n in B9 \/ {x};
        thus G0.(B9 \/ {x})=IFIN(idseq n,B9 \/ {.x.},k1,0.K) by A86
          .=k1 by A106,Def1;
      end;
      hence thesis by A91,A101,A96;
    end;
  end;
A107: for x being Element of X holds G0.({x}) = f.x
  proof
    let x be Element of X;
    now
      per cases;
      case
A108:   x=idseq n;
        then idseq n in {x} by TARSKI:def 1;
        then
A109:   IFIN(idseq n,{x},k1,0.K)=k1 by Def1;
        f2.x=F2(x) by A5
          .=k1 by A108,FUNCOP_1:def 8;
        hence G0.({.x.})=f2.x by A86,A109;
      end;
      case
A110:   x <> idseq n;
        then not idseq n in {x} by TARSKI:def 1;
        then
A111:   IFIN(idseq n,{x},k1,0.K)=0.K by Def1;
        f2.x=F2(x) by A5
          .=0.K by A110,FUNCOP_1:def 8;
        hence G0.({.x.})=f2.x by A86,A111;
      end;
    end;
    hence thesis by A87,A7,FUNCT_1:2;
  end;
A112: for e being Element of Y st e is_a_unity_wrt F holds G0.({}) = e
  proof
    let e be Element of Y;
    assume e is_a_unity_wrt F;
    then
A113: F.(0.K,e)=0.K by BINOP_1:3;
    0.K is_a_unity_wrt F by FVSUM_1:6;
    then
A114: F.(0.K,e)=e by BINOP_1:3;
    IFIN(idseq n,{},k1,0.K)=0.K by Def1;
    hence thesis by A86,A113,A114,FINSUB_1:7;
  end;
A115: now
    assume
A116: idseq n in B;
    thus G0.(B)=IFIN(idseq n,B,k1,0.K) by A86
      .=(the multF of K)$$ (diagonal_of_Matrix A) by A116,Def1;
  end;
S:  (idseq n) is Element of Group_of_Perm(n) by MATRIX_1:11;
  Permutations n in Fin Permutations n by FINSUB_1:def 5;
  then B=Permutations(n) & (idseq n) in the carrier of Group_of_Perm(n) by
S,SUBSET_1:def 8;
  then (the addF of K) $$ (In(Permutations(n),Fin Permutations n),
Path_product(A))= (the
  multF of K)$$ (diagonal_of_Matrix A) by A115,A112,A107,A89,MATRIX_1:def 13
,SETWISEO:def 3;
  hence thesis by MATRIX_3:def 9;
end;
