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 Th55:
  for K being Ring
  for A,B be Matrix of K st width A = len B & len B > 0 for i st i
in Seg len A ex P be FinSequence of (the carrier of K)* st len P = len B & Line
  (A*B,i) = addFinS(K) "**" P & for j st j in Seg len B holds P.j = A*(i,j) *
  Line(B,j)
proof
  let K be Ring;
  let A,B be Matrix of K such that
A1: width A = len B and
A2: len B > 0;
  set aa=the addF of K;
  set mm=the multF of K;
  set a=addFinS(K);
  set KK=the carrier of K;
  reconsider m=len B,w=width B as Nat;
  let i such that
A3: i in Seg len A;
  deffunc F(Nat)=A*(i,$1) * Line(B,$1);
  consider P be FinSequence such that
A4: len P = len B and
A5: for k be Nat st k in dom P holds P.k = F(k) from FINSEQ_1:sch 2;
A6: dom P = dom B by A4,FINSEQ_3:29
    .= Seg len B by FINSEQ_1:def 3;
  rng P c= KK*
  proof
    let y be object;
    assume y in rng P;
    then consider x being object such that
A7: x in dom P and
A8: y=P.x by FUNCT_1:def 3;
    reconsider x as Element of NAT by A7;
    P.x=A*(i,x) * Line(B,x) by A5,A7;
    hence thesis by A8,FINSEQ_1:def 11;
  end;
  then reconsider P as FinSequence of KK* by FINSEQ_1:def 4;
A9: m>=1 by A2,NAT_1:14;
  then consider F be sequence of KK* such that
A10: F.1 = P.1 and
A11: for n be Nat st 0<>n & n<len P holds F.(n+1)=a.(F.n,P.(n
  +1)) and
A12: a "**" P = F.(len P) by A4,FINSOP_1:def 1;
  defpred P[Nat] means 1 <= $1 & $1 <= m implies for F1 be FinSequence of KK
  st F.$1=F1 holds len F1=w & for j be Element of NAT st j in Seg w holds ex LC
be FinSequence of KK st LC = mlt(Line(A,i),Col(B,j)) | Seg $1 & aa"**"LC=F1.j;
A13: for k be Nat st P[k] holds P[k+1]
  proof
    let k be Nat such that
A14: P[k];
    set k1=k+1;
    assume that
A15: 1 <= k1 and
A16: k1 <= m;
A17: k1 in Seg m by A15,A16;
    let Fk1 be FinSequence of KK such that
A18: F.k1=Fk1;
    per cases;
    suppose
A19:  k=0;
      then
A20:  P.1=A*(i,1) * Line(B,1) by A5,A6,A17;
A21:  len Line(B,1) =w by MATRIX_0:def 7;
      hence len Fk1= w by A10,A18,A19,A20,Lm5;
      let j be Element of NAT such that
A22:  j in Seg w;
      len Fk1 =w by A10,A18,A19,A20,A21,Lm5;
      then
A23:  j in dom Fk1 by A22,FINSEQ_1:def 3;
      Line(B,1).j=B*(1,j) by A22,MATRIX_0:def 7;
      then
A24:  Fk1.j=(A*(i,1)) * (B*(1,j)) by A10,A18,A19,A20,A23,FVSUM_1:50;
      set C=Col(B,j);
      set L=Line(A,i);
      reconsider LC1=(mlt(L,C)) | (Seg k1),mLC=mlt(L,C) as FinSequence of KK
by FINSEQ_1:18;
A25:  mm.:(L,C) is Element of m-tuples_on KK by A1,FINSEQ_2:120;
      then len mLC=m by CARD_1:def 7;
      then
A26:  dom mLC=Seg m by FINSEQ_1:def 3;
      Seg 1 = Seg m/\Seg 1 by A2,FINSEQ_1:7,NAT_1:14;
      then
A27:  dom LC1=Seg 1 by A19,A26,RELAT_1:61;
      then
A28:  len LC1=1 by FINSEQ_1:def 3;
      1 in Seg 1;
      then LC1.1=mLC.1 by A27,FUNCT_1:47;
      then
A29:  LC1=<*mLC.1*> by A28,FINSEQ_1:40;
      take LC1;
A30:  1 in Seg m by A9;
      len mLC=m by A25,CARD_1:def 7;
      then
A31:  1 in dom mLC by A30,FINSEQ_1:def 3;
      Seg m=dom B by FINSEQ_1:def 3;
      then
A32:  C.1=B*(1,j) by A30,MATRIX_0:def 8;
      L.1=A*(i,1) by A1,A30,MATRIX_0:def 7;
      then mLC.1=(A*(i,1)) * (B*(1,j)) by A32,A31,FVSUM_1:60;
      hence thesis by A24,A29,FINSOP_1:11;
    end;
    suppose
A33:  k>0;
      dom P=Seg m by A4,FINSEQ_1:def 3;
      then
A34:  P.k1 in rng P by A17,FUNCT_1:def 3;
      rng P c= KK* by FINSEQ_1:def 4;
      then reconsider Pk1=P.k1,Fk=F.k as FinSequence of KK
      by A34,FINSEQ_1:def 11;
      reconsider Pk1,Fk as Element of KK* by FINSEQ_1:def 11;
A35:  a.(Fk,Pk1)=Fk+Pk1 by Def5;
A36:  k+0<k1 by XREAL_1:8;
      then k < m by A16,XXREAL_0:2;
      then
A37:  Fk1=Fk+Pk1 by A4,A11,A18,A33,A35;
A38:  len Line(B,k1)=w by MATRIX_0:def 7;
      Pk1 = F(k1) by A5,A6,A17;
      then len Pk1=w by A38,Lm5;
      then
A39:  dom Pk1=Seg w by FINSEQ_1:def 3;
A40:   w in NAT by ORDINAL1:def 12;
A41:  len Fk=w by A14,A16,A33,A36,NAT_1:14,XXREAL_0:2;
      then dom Fk=Seg w by FINSEQ_1:def 3;
      then
A42:  dom (Fk+Pk1)=Seg w /\Seg w by A39,Lm9;
      hence len Fk1=w by A37,FINSEQ_1:def 3,A40;
A43:  rng Fk c= KK by FINSEQ_1:def 4;
      set L=Line(A,i);
A44:  Pk1 = F(k1) by A5,A6,A17;
      let j be Element of NAT such that
A45:  j in Seg w;
A46:  Line(B,k1).j=B*(k1,j) by A45,MATRIX_0:def 7;
      then Pk1.j=(A*(i,k1)) * (B*(k1,j)) by A39,A45,A44,FVSUM_1:50;
      then reconsider Pk1j=Pk1.j as Element of KK;
      set C=Col(B,j);
      consider LC be FinSequence of KK such that
A47:  LC = mlt(L,C) | (Seg k) and
A48:  (the addF of K)"**"LC=Fk.j by A14,A16,A33,A36,A45,NAT_1:14,XXREAL_0:2;
      reconsider LC1=mlt(L,C) | (Seg k1),mLC=mlt(L,C) as FinSequence of KK by
FINSEQ_1:18;
      take LC1;
      mm.:(L,C) is Element of m-tuples_on KK by A1,FINSEQ_2:120;
      then len mLC=m by CARD_1:def 7;
      then
A49:  k1 in dom mLC by A17,FINSEQ_1:def 3;
A50:  k1 in Seg m by A15,A16;
      then
A51:  L.k1=A*(i,k1) by A1,MATRIX_0:def 7;
      Seg m=dom B by FINSEQ_1:def 3;
      then C.k1=B*(k1,j) by A50,MATRIX_0:def 8;
      then
A52:  mLC.k1=(A*(i,k1))*(B*(k1,j)) by A51,A49,FVSUM_1:60;
      LC1=LC^<*mLC.k1*> by A47,A49,FINSEQ_5:10;
      then
A53:  aa"**"LC1=aa.(Fk.j,(A*(i,k1)) * (B*(k1,j)))
      by A48,A52,FINSOP_1:4,FVSUM_1:8;
      j in dom Fk by A41,A45,FINSEQ_1:def 3;
      then Fk.j in rng Fk by FUNCT_1:def 3;
      then reconsider Fkj=Fk.j as Element of KK by A43;
      Fk1.j=Fkj+Pk1j by A42,A37,A45,FVSUM_1:17;
      hence thesis by A39,A45,A46,A44,A53,FVSUM_1:50;
    end;
  end;
  set L=Line(A*B,i);
  width (A*B)=w by A1,MATRIX_3:def 4;
  then
A54: len L = w by MATRIX_0:def 7;
  reconsider Fm=F.m as FinSequence of KK;
A55: P[0];
A56: for k be Nat holds P[k] from NAT_1:sch 2(A55,A13);
A57: for j be Nat st 1 <=j & j <= len L holds L.j=Fm.j
  proof
    set AB=A*B;
    set LA=Line(A,i);
    let j be Nat such that
A58: 1 <=j and
A59: j <= len L;
    set CB=Col(B,j);
    mm.:(LA,CB) is Element of m-tuples_on KK by A1,FINSEQ_2:120;
    then len mlt(LA,CB)=m by CARD_1:def 7;
    then
A60: dom mlt(LA,CB)=Seg m by FINSEQ_1:def 3;
A61: j in Seg w by A54,A58,A59;
    then
    ex LC be FinSequence of KK st LC = mlt(LA,CB) | (Seg m) & aa"**"LC=Fm
    .j by A9,A56;
    then
A62: Fm.j=LA "*" CB by A60;
A63: len AB=len A by A1,MATRIX_3:def 4;
A64: width AB=w by A1,MATRIX_3:def 4;
    len A<>0 by A3;
    then AB is Matrix of len A,w,K by A63,A64,MATRIX_0:20;
    then Indices AB=[:Seg len A,Seg w:] by A64,MATRIX_0:25;
    then [i,j] in Indices AB by A3,A61,ZFMISC_1:87;
    then AB*(i,j)=LA "*" CB by A1,MATRIX_3:def 4;
    hence thesis by A61,A62,A64,MATRIX_0:def 7;
  end;
  take P;
  thus len P=len B by A4;
  len Fm=w by A9,A56;
  hence L=a "**" P by A4,A12,A54,A57;
  let j;
  assume j in Seg len B;
  hence thesis by A5,A6;
end;
