reserve x,y for set,
  i,j,k,l,m,n for Nat,
  K for Field,
  N for without_zero finite Subset of NAT,
  a,b for Element of K,
  A,B,B1,B2,X,X1,X2 for (Matrix of K),
  A9 for (Matrix of m,n,K),
  B9 for (Matrix of m,k,K);
reserve D for non empty set,
  bD for FinSequence of D,
  b,f,g for FinSequence of K,
  MD for Matrix of D;

theorem Th57:
  for A,B be Matrix of K st len A = len B & (width A = 0 implies
width B = 0) holds the_rank_of A = the_rank_of (A^^B) iff Solutions_of(A,B) is
  non empty
proof
  let A,B be Matrix of K such that
A1: len A = len B and
A2: width A = 0 implies width B = 0;
  set wB=width B;
  set L=len A;
  reconsider B9=B as Matrix of L,wB,K by A1,MATRIX_0:51;
  set wA=width A;
  reconsider A9=A as Matrix of L,wA,K by MATRIX_0:51;
  deffunc F(Matrix of L,wB,K,Nat,Nat,Element of K) = RLine($1,$2,Line($1,$2) +
  $4*Line($1,$3));
  defpred P[set,set] means for A1 be Matrix of L,wA,K, B1 be Matrix of L,wB,K
st A1=$1 & B1=$2 holds the_rank_of (A9^^B9)=the_rank_of (A1^^B1) & Solutions_of
  (A9,B9)=Solutions_of(A1,B1);
A3: for A1 be Matrix of L,wA,K, B1 be Matrix of L,wB,K st P[A1,B1] for a be
Element of K for i,j st j in dom A1 & (i = j implies a <> -1_K ) holds P[RLine(
  A1,i,Line(A1,i) + a*Line(A1,j)),F(B1,i,j,a)]
  proof
    let A1 be Matrix of L,wA,K, B1 be Matrix of L,wB,K such that
A4: P[A1,B1];
    let a be Element of K;
    let i,j such that
A5: j in dom A1 and
A6: i = j implies a <> -1_K;
    set LAj=Line(A1,j);
    set LAi=Line(A1,i);
    set RA=RLine(A1,i,LAi + a*LAj);
A7: dom A1 = Seg len A1 by FINSEQ_1:def 3
      .= Seg L by MATRIX_0:def 2;
    then
A8: Solutions_of(A1,B1)=Solutions_of(RA,F(B1,i,j,a)) by A5,A6,Th40;
    set RB=F(B1,i,j,a);
    set LBj=Line(B1,j);
    set LBi=Line(B1,i);
A9: len A1=L & len B1=L by MATRIX_0:def 2;
    per cases;
    suppose
      not i in Seg L;
      then RA=A1 & RB=B1 by A9,MATRIX13:40;
      hence thesis by A4;
    end;
    suppose
A10:  i in Seg L;
A11:  len (A1^^B1)=L by MATRIX_0:def 2;
A12:  len (a*LAj)=width A1 & len (a*LBj)=width B1 by CARD_1:def 7;
A13:  len LAi=width A1 & len LBi=width B1 by CARD_1:def 7;
      len (LAi+a*LAj)=width A1 & len (LBi+a*LBj)=width B1 by CARD_1:def 7;
      then RA^^RB = RLine(A1^^B1,i,(LAi+a*LAj)^(LBi+a*LBj))by Th18
        .= RLine(A1^^B1,i,(LAi^LBi)+((a*LAj)^(a*LBj))) by A13,A12,Th3
        .= RLine(A1^^B1,i,(LAi^LBi)+a*(LAj^LBj)) by Th4
        .= RLine(A1^^B1,i,Line(A1^^B1,i)+a*(LAj^LBj))by A10,Th15
        .= RLine(A1^^B1,i,Line(A1^^B1,i)+a*Line(A1^^B1,j)) by A5,A7,Th15;
      then the_rank_of (RA^^RB)=the_rank_of (A1^^B1) by A5,A6,A7,A11,
MATRIX13:92;
      hence thesis by A4,A8;
    end;
  end;
A14: P[A9,B9];
  consider A1 be Matrix of L,wA,K, B1 be Matrix of L,wB,K,N such that
A15: N c= Seg wA and
A16: the_rank_of A9 = the_rank_of A1 & the_rank_of A9 = card N and
A17: P[A1,B1] & Segm(A1,Seg card N,N) = 1.(K,card N) and
A18: for i st i in dom A1 & i > card N holds Line(A1,i) = wA|->0.K and
  for i,j st i in Seg card N & j in Seg width A1 & j < Sgm N.i holds A1*(i
  ,j) = 0.K from GAUSS2(A14,A3);
  per cases;
  suppose
A19: L=0;
    then len (A9^^B9)=0 & the_rank_of A =0 by MATRIX13:74,MATRIX_0:def 2;
    hence thesis by A19,Th51,MATRIX13:74;
  end;
  suppose
A20: L>0;
    per cases;
    suppose
A21:  N<>{};
      set SN=Seg card N;
      set SS=Seg L\SN;
A22:  card SN=card N by FINSEQ_1:57;
      reconsider P2=Sgm SN " SN,Q2 = Sgm Seg wA " N as without_zero finite
      Subset of NAT by MATRIX13:53;
      dom Sgm SN=Seg card SN & rng Sgm SN=SN by FINSEQ_1:def 14,FINSEQ_3:40;
      then
A23:  P2 = SN by A22,RELAT_1:134;
      rng Sgm Seg wA=Seg wA by FINSEQ_1:def 14;
      then
A24:  Sgm Seg wA.:Q2 = N by A15,FUNCT_1:77;
      Q2 c= dom Sgm Seg wA & Sgm Seg wA is one-to-one by FINSEQ_3:92
,RELAT_1:132;
      then N,Q2 are_equipotent by A24,CARD_1:33;
      then
A25:  dom Sgm Seg wA=Seg card Seg wA & card N=card Q2 by CARD_1:5,FINSEQ_3:40;
A26:  Seg len A1=dom A1 & len A1=L by A20,FINSEQ_1:def 3,MATRIX_0:23;
A27:  width A1=wA by A20,MATRIX_0:23;
A28:  now
        let i such that
A29:    i in SS;
        not i in SN by A29,XBOOLE_0:def 5;
        then
A30:    i<1 or i> card N;
        i in Seg L by A29,XBOOLE_0:def 5;
        hence Line(A1,i)=width A1|->0.K by A18,A26,A27,A30,FINSEQ_1:1;
      end;
      card N<=L by A16,MATRIX13:74;
      then
A31:  Seg card N c= Seg L by FINSEQ_1:5;
A32:  len B1=L by A20,MATRIX_0:23;
A33:  Seg len B1=dom B1 & width B1=wB by A20,FINSEQ_1:def 3,MATRIX_0:23;
      thus the_rank_of A=the_rank_of(A^^B) implies Solutions_of(A,B) is non
      empty
      proof
        assume the_rank_of A = the_rank_of (A^^B);
        then the_rank_of A1 = the_rank_of (A1^^B1) by A16,A17;
        then for i st i in (dom A1)\Seg card N holds Line(A1,i) = width A1|->
        0.K & Line(B1,i) = width B1 |-> 0.K by A26,A32,A28,Th24,XBOOLE_1:36;
        then
A34:    Solutions_of(A1,B1)=Solutions_of(Segm(A1,SN,Seg wA), Segm(B1,SN,
        Seg wB)) by A21,A31,A26,A32,A27,A33,Th45;
        Segm(Segm(A1,SN,Seg wA),P2,Q2)=1.(K,card N) by A15,A17,MATRIX13:56;
        then ex X be Matrix of card Seg wA,card Seg wB,K st Segm(X,Seg card
Seg wA \ Q2,Seg card Seg wB) = 0.(K,card Seg wA-'card SN,card Seg wB) & Segm(X,
Q2,Seg card Seg wB) = Segm(B1,SN,Seg wB) & X in Solutions_of(Segm(A1,SN,Seg wA)
        ,Segm(B1,SN,Seg wB)) by A21,A22,A23,A25,Th50,RELAT_1:132;
        hence thesis by A17,A34;
      end;
A35:  Seg L\Seg card N c= Seg L by XBOOLE_1:36;
      thus Solutions_of(A,B) is non empty implies the_rank_of A=the_rank_of (A
      ^^B)
      proof
        assume Solutions_of(A,B) is non empty;
        then Solutions_of(A1,B1) is non empty by A17;
        then consider x being object such that
A36:    x in Solutions_of(A1,B1);
        set AB=A1^^B1;
A37:    len Segm(AB,SN,Seg width AB)=card SN by MATRIX_0:def 2;
A38:    dom AB=Seg len AB & len AB=L by A20,FINSEQ_1:def 3,MATRIX_0:23;
        reconsider x as Matrix of wA,wB,K by A20,A36,Th53;
A39:    the_rank_of Segm(AB,Seg L,Seg width A1)=card N by A16,Th19;
A40:    width AB=width A1+width B1 by A20,MATRIX_0:23;
        now
          let i such that
A41:      i in SS;
A42:      Line(A1,i)=width A1|->0.K by A28,A41;
A43:      x in Solutions_of(A1,B1) & i in dom A1 & Line(A1,i)= width A1
          |->0.K implies Line(B1,i)=width B1|->0.K by Th41;
          thus Line(AB,i)=Line(A1,i)^Line(B1,i)by A35,A41,Th15
            .=width AB|->0.K by A26,A35,A36,A40,A41,A42,A43,FINSEQ_2:123;
        end;
        then the_rank_of Segm(AB,SN,Seg width AB)=the_rank_of AB by A31,A38
,Th11;
        then the_rank_of AB<=card SN by A37,MATRIX13:74;
        then
A44:    the_rank_of AB<=card N by FINSEQ_1:57;
        width A1<=width AB by A40,NAT_1:11;
        then Seg width A1 c= Seg width AB by FINSEQ_1:5;
        then [:Seg L,Seg width A1:] c= Indices AB by A38,ZFMISC_1:95;
        then card N <= the_rank_of AB by A39,MATRIX13:79;
        then the_rank_of AB=card N by A44,XXREAL_0:1;
        hence thesis by A16,A17;
      end;
    end;
    suppose
A45:  N={};
      set ZERO=0.(K,L,wA);
A46:  now
        let i such that
A47:    1<=i & i<=L;
A48:    dom A1=Seg len A1 & len A1=L by FINSEQ_1:def 3,MATRIX_0:def 2;
A49:    i in Seg L by A47;
        hence ZERO.i = wA|->0.K by FINSEQ_2:57
          .= Line(A1,i) by A18,A45,A49,A48
          .= A1.i by A49,MATRIX_0:52;
      end;
A50:  len ZERO=L by A20,MATRIX_0:23;
A51:  width A1=wA by A20,MATRIX_0:23;
      len A1=L by A20,MATRIX_0:23;
      then ZERO=A1 by A50,A46;
      then
A52:  the_rank_of A=0 by A16,A50,A51,MATRIX13:95;
      then
A53:  ZERO=A by MATRIX13:95;
A54:  Indices (A9^^B9)=[:Seg L,Seg (wA+wB):] by A20,MATRIX_0:23;
      thus the_rank_of A=the_rank_of(A^^B) implies Solutions_of(A,B) is non
      empty
      proof
        set x = the Matrix of wA,wB,K;
        assume
A55:    the_rank_of A = the_rank_of (A^^B);
        Seg (wA+wB)\Seg wA c= Seg (wA+wB) by XBOOLE_1:36;
        then
A56:    [:Seg L,Seg (wA+wB)\Seg wA:] c= Indices (A^^B) by A54,ZFMISC_1:95;
        Segm(A9^^B9,Seg L,Seg (wA+wB)\Seg wA)=B by Th19;
        then 0=the_rank_of B by A52,A55,A56,MATRIX13:79;
        then
A57:    B=0.(K,L,wB) by A1,MATRIX13:95;
        then wA=0 & wB=0 or Solutions_of(A9,B9) = the set of all
X where X is Matrix of wA,
        wB,K by A2,A20,A53,Th54;
        then Solutions_of(A9,B9)={{}} or x in Solutions_of(A9,B9) by A53,A57
,Th56;
        hence thesis;
      end;
A58:  Indices B9=[:Seg L,Seg wB:] by A20,MATRIX_0:23;
A59:  wA+wB = width (A9^^B9) by A20,MATRIX_0:23;
A60:  Indices ZERO=[:Seg L,Seg wA:] by A20,MATRIX_0:23;
      thus Solutions_of(A,B) is non empty implies the_rank_of A=the_rank_of(A
      ^^B)
      proof
        assume
A61:    Solutions_of(A,B) is non empty;
        assume the_rank_of A <> the_rank_of (A^^B);
        then consider i,j such that
A62:    [i,j] in Indices (A9^^B9) and
A63:    (A9^^B9)*(i,j)<>0.K by A52,MATRIX13:94;
A64:    j in Seg (wA+wB) by A59,A62,ZFMISC_1:87;
A65:    dom Line(A9^^B9,i)=Seg (wA+wB) by A59,FINSEQ_2:124;
A66:    len Line(A9,i)=wA by CARD_1:def 7;
A67:    dom Line(B9,i)=Seg wB by FINSEQ_2:124;
A68:    dom Line(A9,i)=Seg wA by FINSEQ_2:124;
A69:    i in Seg L by A54,A62,ZFMISC_1:87;
        then
A70:    Line(A9^^B9,i)=Line(A9,i)^Line(B9,i) by Th15;
        per cases by A64,A66,A65,A70,FINSEQ_1:25;
        suppose
A71:      j in dom Line(A9,i);
          then
A72:      [i,j] in Indices ZERO by A60,A69,A68,ZFMISC_1:87;
          (A9^^B9)*(i,j) = Line(A9^^B9,i).j by A59,A64,MATRIX_0:def 7
            .= Line(A9,i).j by A70,A71,FINSEQ_1:def 7
            .= A9*(i,j) by A68,A71,MATRIX_0:def 7
            .= 0.K by A53,A72,MATRIX_3:1;
          hence thesis by A63;
        end;
        suppose
          ex n st n in dom Line(B9,i) & j=wA + n;
          then consider n such that
A73:      n in dom Line(B9,i) and
A74:      j=wA + n;
A75:      [i,n] in Indices B by A58,A69,A67,A73,ZFMISC_1:87;
A76:      B=0.(K,L,wB) by A53,A61,Th52;
          (A9^^B9)*(i,j) = Line(A9^^B9,i).j by A59,A64,MATRIX_0:def 7
            .= Line(B9,i).n by A66,A70,A73,A74,FINSEQ_1:def 7
            .= B9*(i,n) by A67,A73,MATRIX_0:def 7
            .= 0.K by A75,A76,MATRIX_3:1;
          hence thesis by A63;
        end;
      end;
    end;
  end;
end;
