reserve D for non empty set,
  i,j,k,l for Nat,
  n for Nat,
  x for set,
  a,b,c,r,r1,r2 for Real,
  p,q for FinSequence of REAL,
  MR,MR1 for Matrix of REAL;

theorem Th28:
  for p being ProbFinS FinSequence of REAL for M being non
empty-yielding Conditional_Probability Matrix of REAL st len p = len M holds (
  Vec2DiagMx p) * M is Joint_Probability
proof
  let p be ProbFinS FinSequence of REAL;
  let M be non empty-yielding Conditional_Probability Matrix of REAL;
  set M1 = (Vec2DiagMx p) * M;
  assume
A1: len p = len M;
  then
A2: len M1 = len p by Th26;
A3: LineSum M1 = p
  proof
    set M2=LineSum M1;
A4: len M2 = len M1 by MATRPROB:20;
    then
A5: dom M2 = dom M by A1,A2,FINSEQ_3:29;
A6: dom M2 = dom M1 by A4,FINSEQ_3:29;
A7: now
      let k be Nat such that
A8:   k in dom M2;
      k in Seg len M1 by A4,A8,FINSEQ_1:def 3;
      hence M2.k = Sum(Line(M1,k)) by MATRPROB:20
        .= Sum(p.k*Line(M,k)) by A1,A6,A8,Th27
        .= p.k * Sum Line(M,k) by RVSUM_1:87
        .= p.k * Sum(M.k) by A5,A8,MATRIX_0:60
        .= p.k * 1 by A5,A8,MATRPROB:def 9
        .= p.k;
    end;
    dom M2 = dom p by A2,A4,FINSEQ_3:29;
    hence thesis by A7,FINSEQ_1:13;
  end;
A9: width M1 = width M by A1,Th26;
  now
    let i,j such that
A10: [i,j] in Indices M1;
A11: j in Seg width M by A9,A10,MATRPROB:12;
    i in Seg len p by A2,A10,MATRPROB:12;
    then i in dom p by FINSEQ_1:def 3;
    then
A12: p.i >= 0 by MATRPROB:def 5;
    i in Seg len M by A1,A2,A10,MATRPROB:12;
    then [i,j] in Indices M by A11,MATRPROB:12;
    then
A13: M*(i,j) >= 0 by MATRPROB:def 6;
    M1*(i,j) = p.i *(M*(i,j)) by A1,A10,Th26;
    hence M1*(i,j) >= 0 by A12,A13;
  end;
  then
A14: M1 is m-nonnegative by MATRPROB:def 6;
  SumAll M1 = Sum LineSum M1 by MATRPROB:def 3
    .= 1 by A3,MATRPROB:def 5;
  then M1 is with_sum=1 by MATRPROB:def 7;
  hence thesis by A14;
end;
