reserve x,y for object,X,Y for set,
  D for non empty set,
  i,j,k,l,m,n,m9,n9 for Nat,
  i0,j0,n0,m0 for non zero Nat,
  K for Field,
  a,b for Element of K,
  p for FinSequence of K,
  M for Matrix of n,K;
reserve A for (Matrix of D),
  A9 for Matrix of n9,m9,D,
  M9 for Matrix of n9, m9,K,
  nt,nt1,nt2 for Element of n-tuples_on NAT,
  mt,mt1 for Element of m -tuples_on NAT,
  M for Matrix of K;
reserve P,P1,P2,Q,Q1,Q2 for without_zero finite Subset of NAT;

theorem
  for M be diagonal Matrix of K for NonZero1 be set st NonZero1={i where i
is Element of NAT:[i,i] in Indices M & M*(i,i)<>0.K} holds the_rank_of M = card
  NonZero1
proof
  let M be diagonal Matrix of K;
  consider P,Q such that
A1: [:P,Q:] c= Indices M and
A2: card P = card Q and
A3: card P = the_rank_of M and
A4: Det EqSegm(M,P,Q)<>0.K by Def4;
  let NZ be set such that
A5: NZ={i where i is Element of NAT:[i,i] in Indices M & M*(i,i)<>0.K};
A6: NZ c= Seg width M
  proof
    let x be object;
    assume x in NZ;
    then ex i be Element of NAT st x=i & [i,i] in Indices M & M*(i,i)<>0.K by
A5;
    hence thesis by ZFMISC_1:87;
  end;
  then not 0 in NZ;
  then reconsider nz=NZ as without_zero finite Subset of NAT by A6,
MEASURE6:def 2,XBOOLE_1:1;
  set S=Segm(M,nz,nz);
  NZ c= dom M
  proof
    let x be object;
    assume x in NZ;
    then ex i be Element of NAT st x=i & [i,i] in Indices M & M*(i,i)<>0.K by
A5;
    hence thesis by ZFMISC_1:87;
  end;
  then
A7: [:nz,nz:] c= Indices M by A6,ZFMISC_1:96;
  then reconsider S as diagonal Matrix of card nz,K by Th100;
  set d=diagonal_of_Matrix S;
  now
    per cases by NAT_1:14;
    suppose
      card nz=0;
      then Det S=1_K by MATRIXR2:41;
      hence Det S<>0.K;
    end;
    suppose
A8:   card nz>=1;
      set Sn=Sgm nz;
A9:   now
A10:    rng Sn=nz by FINSEQ_1:def 14;
A11:    dom d=Seg len d by FINSEQ_1:def 3;
A12:    len d=card nz by MATRIX_3:def 10;
        let k be Nat such that
A13:    k in dom d;
A14:    d.k=S*(k,k) by A13,A11,A12,MATRIX_3:def 10;
        dom Sn=dom d by A11,A12,FINSEQ_3:40;
        then Sn.k in nz by A13,A10,FUNCT_1:def 3;
        then
A15:    ex i be Element of NAT st i=Sn.k & [i,i] in Indices M & M*(i,i)<>
        0.K by A5;
        Indices S=[:Seg card nz,Seg card nz:] by MATRIX_0:24;
        then [k,k] in Indices S by A13,A11,A12,ZFMISC_1:87;
        hence d.k <> 0.K by A14,A15,Def1;
      end;
      Det S = Product d by A8,MATRIX_7:17;
      hence Det S<>0.K by A9,FVSUM_1:82;
    end;
  end;
  then Det EqSegm(M,nz,nz)<>0.K by Def3;
  then
A16: the_rank_of M >= card nz by A7,Def4;
  P c= nz by A5,A1,A2,A4,Th99;
  then card P <= card nz by NAT_1:43;
  hence thesis by A16,A3,XXREAL_0:1;
end;
