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 Th31:
  for l,pK,qK,perm st l in Seg n & len pK = n & len qK = n for M
be Matrix of n,K holds (the multF of K) $$ Path_matrix(perm,RLine(M,l,a * pK +
  b * qK)) = a * ((the multF of K) $$ Path_matrix(perm,RLine(M,l,pK))) + b * ((
  the multF of K) $$ Path_matrix(perm,RLine(M,l,qK)))
proof
  let l,pK,qK,perm such that
A1: l in Seg n and
A2: len pK = n and
A3: len qK = n;
 Seg n <> {} by A1;
   then
A4: n <> 0 ;
  reconsider L=l as Element of NAT by ORDINAL1:def 12;
  set mm=the multF of K;
  let M be Matrix of n,K;
  set Rpq=RLine(M,l,a*pK+b*qK);
  set Ppq=Path_matrix(perm,Rpq);
A5: len Ppq=n by MATRIX_3:def 7;
  then consider fpq be sequence of the carrier of K such that
A6: fpq.1 = Ppq.1 and
A7: for k be Nat st 0<>k & k<len Ppq holds fpq.(k+1)=mm.(fpq.
  k,Ppq.(k+1)) and
A8: mm $$ Ppq=fpq.(len Ppq) by A4,FINSOP_1:def 1;
  set Rq=RLine(M,l,qK);
  set Pq=Path_matrix(perm,Rq);
A9: len Pq=n by MATRIX_3:def 7;
  then consider fq be sequence of the carrier of K such that
A10: fq.1 = Pq.1 and
A11: for k be Nat st 0<>k & k<len Pq holds fq.(k+1)=mm.(fq.k,
  Pq.(k+1)) and
A12: mm $$ Pq=fq.(len Pq) by A4,FINSOP_1:def 1;
  set Rp=RLine(M,l,pK);
  set Pp=Path_matrix(perm,Rp);
A13: len Pp=n by MATRIX_3:def 7;
  then consider fp be sequence of the carrier of K such that
A14: fp.1 = Pp.1 and
A15: for k be Nat st 0<>k & k<len Pp holds fp.(k+1)=mm.(fp.k,
  Pp.(k+1)) and
A16: mm $$ Pp=fp.(len Pp) by A4,FINSOP_1:def 1;
A17: n>=1 by A4,NAT_1:14;
  defpred P[Nat] means (1 <= $1 & $1 < L) implies (fp.$1=fq.$1 & fpq.$1=fp.$1);
A18: for k be Element of NAT st k in Seg n holds (k<>L implies Ppq.k=Pp.k &
  Pp.k=Pq.k)& (k=L implies ex Ppk,Pqk be Element of K st Ppk=Pp.k & Pqk=Pq.k &
  Ppq.k=a*Ppk+b*Pqk)
  proof
    let k be Element of NAT such that
A19: k in Seg n;
A20: perm.k in Seg n by A19,MATRIX_7:14;
    then reconsider pk=perm.k as Element of NAT;
A21: k in dom Pp by A13,A19,FINSEQ_1:def 3;
A22: k in dom Pq by A9,A19,FINSEQ_1:def 3;
    [k,pk] in [:Seg n,Seg n:] by A19,A20,ZFMISC_1:87;
    then
A23: [k,pk] in Indices M by MATRIX_0:24;
    dom qK=Seg n by A3,FINSEQ_1:def 3;
    then
A24: qK/.pk=qK.pk by A19,MATRIX_7:14,PARTFUN1:def 6;
    dom pK=Seg n by A2,FINSEQ_1:def 3;
    then pK/.pk=pK.pk by A19,MATRIX_7:14,PARTFUN1:def 6;
    then reconsider ppk=pK.pk, qpk=qK.pk as Element of K by A24;
A25: len (b*qK)=n by A3,Lm5;
    then dom (b*qK) =Seg n by FINSEQ_1:def 3;
    then
A26: (b*qK).pk = b*qpk by A19,FVSUM_1:50,MATRIX_7:14;
A27: len (a*pK)=n by A2,Lm5;
    then
A28: len (a*pK+b*qK)=n by A25,Lm6;
    then
A29: dom (a*pK+b*qK)=Seg n by FINSEQ_1:def 3;
    dom (a*pK) =Seg n by A27,FINSEQ_1:def 3;
    then
A30: (a*pK).pk = a*ppk by A19,FVSUM_1:50,MATRIX_7:14;
A31: width M=n by MATRIX_0:24;
A32: k in dom Ppq by A5,A19,FINSEQ_1:def 3;
    thus k<>L implies Ppq.k=Pp.k & Pp.k=Pq.k
    proof
      assume
A33:  k<>L;
      then
A34:  Rq*(k,pk)=M*(k,pk) by A3,A23,A31,Def3;
      Rp*(k,pk)=M*(k,pk) by A2,A23,A31,A33,Def3;
      then
A35:  Pp.k=M*(k,pk) by A21,MATRIX_3:def 7;
      Rpq*(k,pk)=M*(k,pk) by A28,A23,A31,A33,Def3;
      hence thesis by A32,A22,A34,A35,MATRIX_3:def 7;
    end;
    assume
A36: k=L;
    then
A37: Rp*(k,pk)=pK.pk by A2,A23,A31,Def3;
A38: Rq*(k,pk)=qK.pk by A3,A23,A31,A36,Def3;
    take ppk,qpk;
    Rpq*(k,pk) = (a*pK+b*qK).pk by A28,A23,A31,A36,Def3;
    then Rpq*(k,pk)=(a*ppk)+(b*qpk) by A19,A29,A30,A26,FVSUM_1:17
,MATRIX_7:14;
    hence thesis by A32,A21,A22,A37,A38,MATRIX_3:def 7;
  end;
A39: for k be Nat st P[k] holds P[k+1]
  proof
    let k be Nat such that
A40: P[k];
    set k1=k+1;
    assume that
A41: 1 <= k1 and
A42: k1 < L;
    L<=n by A1,FINSEQ_1:1;
    then
A43: k1 <= n by A42,XXREAL_0:2;
    then
A44: k < n by NAT_1:13;
A45: k1 in Seg n by A41,A43;
    now
      per cases;
      case
        k=0;
        hence thesis by A6,A14,A10,A18,A42,A45;
      end;
      case
A46:    k>0;
        then
A47:    fp.k1=mm.(fp.k,Pp.k1) by A13,A15,A44;
A48:    0<k+0 by A46;
A49:    fq.k1=mm.(fq.k,Pq.k1) by A9,A11,A44,A46;
        fpq.k1=mm.(fpq.k,Ppq.k1) by A5,A7,A44,A46;
        hence thesis by A18,A40,A42,A45,A48,A47,A49,NAT_1:13,19;
      end;
    end;
    hence thesis;
  end;
  defpred Q[Nat] means (1<=$1 & L<=$1 & $1<=n) implies for k be Nat
  st $1=k holds fpq.k=a*fp.k+b*fq.k;
A50: P[0];
A51: fpq.L=a*fp.L+b*fq.L
  proof
    consider PpL,PqL be Element of K such that
A52: PpL=Pp.L and
A53: PqL=Pq.L and
A54: Ppq.L=a*PpL+b*PqL by A1,A18;
A55: L>=1 by A1,FINSEQ_1:1;
    now
      per cases by A55,XXREAL_0:1;
      case
A56:    L>1;
        then reconsider L1=L-1 as Element of NAT by NAT_1:20;
A57:    L1+1>1+0 by A56;
A58:    L1<L1+1 by NAT_1:19;
        L <= n by A1,FINSEQ_1:1;
        then
A59:    L1 < n by A58,XXREAL_0:2;
        then fp.L=fp.L1*PpL by A13,A15,A52,A57;
        then
A60:    fp.L1*(a*PpL)=a*fp.L by GROUP_1:def 3;
A61:    for k be Nat holds P[k] from NAT_1:sch 2(A50,A39);
A62:    1<=L1 by A57,NAT_1:19;
        then fp.L1=fq.L1 by A61,A58;
        then fq.L=fp.L1*PqL by A9,A11,A53,A57,A59;
        then
A63:    fp.L1*(b*PqL)=b*fq.L by GROUP_1:def 3;
        fpq.L1=fp.L1 by A61,A58,A62;
        then fpq.L=fp.L1*(a*PpL+b*PqL ) by A5,A7,A54,A57,A59;
        hence thesis by A60,A63,VECTSP_1:def 7;
      end;
      case
        L=1;
        hence thesis by A6,A14,A10,A52,A53,A54;
      end;
    end;
    hence thesis;
  end;
A64: for k be Nat st Q[k] holds Q[k+1]
  proof
    let k be Nat such that
A65: Q[k];
    set k1=k+1;
    assume that
A66: 1<=k1 and
A67: L<=k1 and
A68: k1<=n;
    let k9 be Nat such that
A69: k9=k1;
    now
      per cases by A67,XXREAL_0:1;
      case
        k1=L;
        hence thesis by A51,A69;
      end;
      case
A70:    k1>L;
A71:    k1 in Seg n by A66,A68;
        then
A72:    Ppq.k1=Pp.k1 by A18,A70;
        k1 in dom Pp by A13,A71,FINSEQ_1:def 3;
        then Pp/.k1=Pp.k1 by PARTFUN1:def 6;
        then reconsider Ppk1=Pp.k1 as Element of K;
A73:    k<n by A68,NAT_1:13;
A74:    (b*fq.k)*Ppk1=b*(fq.k*Ppk1) by GROUP_1:def 3;
A75:    (a*fp.k)*Ppk1=a*(fp.k*Ppk1) by GROUP_1:def 3;
A76:    1<=L by A1,FINSEQ_1:1;
A77:    k>=L by A70,NAT_1:13;
        then fpq.k=a*fp.k+b*fq.k by A65,A68,A76,NAT_1:13,XXREAL_0:2;
        then
A78:    fpq.k1=(a*fp.k+b*fq.k)*Ppk1 by A5,A7,A77,A73,A76,A72;
        Pp.k1=Pq.k1 by A18,A70,A71;
        then
A79:    fq.k1=fq.k*Ppk1 by A9,A11,A77,A73,A76;
        fp.k1=fp.k*Ppk1 by A13,A15,A77,A73,A76;
        hence thesis by A69,A78,A79,A75,A74,VECTSP_1:def 7;
      end;
    end;
    hence thesis;
  end;
A80: L<=n by A1,FINSEQ_1:1;
A81: Q[0];
  for k be Nat holds Q[k] from NAT_1:sch 2(A81,A64);
  hence thesis by A17,A5,A13,A9,A8,A16,A12,A80;
end;
