reserve x,y for set,
  n,m for Nat,
  r,s for Real;

theorem Th16:
  for R be real-valued FinSequence st len R <> 0 holds Sum MIM(R) = R. 1
proof
  defpred P[Nat] means for R be real-valued FinSequence st len R <> 0 &
  len R = $1 holds Sum MIM(R) = R.1;
  let R be real-valued FinSequence;
  assume
A1: len R <> 0;
A2: for n st P[n] holds P[n+1]
  proof
    let n;
    assume
A3: P[n];
    let R be real-valued FinSequence;
    assume that
    len R <> 0 and
A4: len R = n+1;
    now
      per cases;
      case
A5:     n = 0;
A6:     R.1 in REAL by XREAL_0:def 1;
A7:     R = <*R.1*> by A4,A5,FINSEQ_1:40;
        then MIM(R) = R by Th13;
        hence thesis by A7,A6,FINSOP_1:11;
      end;
      case
        n <> 0;
        then 0<n;
        then 0 qua Nat+1<=n by NAT_1:13;
        then max(0,n-1) = n-1 by FINSEQ_2:4;
        then reconsider n1 = n-1 as Element of NAT by FINSEQ_2:5;
A8:     0 qua Nat+1<=n1+1 by NAT_1:11;
        then
A9:     Seg len R = dom R & 1 in Seg(n1+1) by FINSEQ_1:def 3;
        n1+2 = n1+1+1;
        then n1+1<=n1+2 by NAT_1:11;
        then
A10:     n1+1 in Seg(n1+2) by A8;
        set f1 = R|(n1+1);
        set s = R.(n1+2);
        set r = R.(n1+1);
A11:     n1+2 = len R by A4;
A12:    len f1 = n1+1 by A4,FINSEQ_1:59,NAT_1:11;
        thus Sum MIM(R) = Sum((MIM(R)|n1) ^ <* r-s,s *>) by A4,Th11
          .= Sum(MIM(R)|n1) + Sum(<* r-s,s *>) by RVSUM_1:75
          .= Sum(MIM(R)|n1) + (r-s + s) by RVSUM_1:77
          .= Sum((MIM(R)|n1) ^<*r*>) by RVSUM_1:74
          .= Sum MIM(f1) by A11,Th10
          .= f1.1 by A3,A12
          .= R.1 by A4,A10,A9,Th6;
      end;
    end;
    hence thesis;
  end;
A13: P[0];
  for n holds P[n] from NAT_1:sch 2(A13,A2);
  hence thesis by A1;
end;
