reserve n,m,k for Nat,
  x,y for set,
  r for Real;
reserve C,D for non empty finite set,
  a for FinSequence of bool D;

theorem Th13:
  for c be Element of C, F be PartFunc of D,REAL, A be
RearrangmentGen of C st F is total & card C = card D holds (c in A.1 implies (
MIM(FinS(F,D)) (#) CHI(A,C))#c = MIM(FinS(F,D))) & for n st 1<=n & n<len A & c
in A.(n+1) \ A.n holds (MIM(FinS(F,D)) (#) CHI(A,C))#c = (n |-> (0 qua Real)) ^
  (MIM(FinS(F,D)/^n))
proof
  let c be Element of C, F be PartFunc of D,REAL, A be RearrangmentGen of C;
  set fd = FinS(F,D), mf = MIM(fd), h = CHI(A,C), fh = (mf(#)h)#c;
A1: dom A = Seg len A by FINSEQ_1:def 3;
A2: dom(mf(#)h) =Seg len(mf(#)h) by FINSEQ_1:def 3;
A3: len h = len A by RFUNCT_3:def 6;
A4: len mf = len fd by RFINSEQ:def 2;
A5: dom fh = Seg len fh by FINSEQ_1:def 3;
A6: min(len mf,len h) = len(mf(#)h) by RFUNCT_3:def 7;
  assume F is total & card C = card D;
  then
A7: len mf = len h by Th11;
A8: len fh =len(mf(#)h) by RFUNCT_3:def 8;
A9: dom h = Seg len h by FINSEQ_1:def 3;
  thus c in A.1 implies (mf (#) h)#c = mf
  proof
    assume
A10: c in A.1;
A11: for n st n in dom A holds c in A.n
    proof
      let n;
      assume
A12:  n in dom A;
      then
A13:  1<=n by FINSEQ_3:25;
      n<=len A by A12,FINSEQ_3:25;
      then 1<=len A by A13,XXREAL_0:2;
      then 1 in dom A by FINSEQ_3:25;
      then A.1 c= A.n by A12,A13,Th2;
      hence thesis by A10;
    end;
A14: dom ((mf(#)h)#c) = Seg len mf by A7,A6,A8,FINSEQ_1:def 3;
    now
      let m be Nat;
      reconsider m1 = m as Element of NAT by ORDINAL1:def 12;
      reconsider r1=fd.m as Real;
      assume
A15:  m in dom((mf(#)h)#c);
      then
A16:  1<=m by FINSEQ_3:25;
A17:  h.m = chi(A.m,C) by A9,A5,A7,A6,A8,A15,RFUNCT_3:def 6;
A18:  c in A.m by A1,A5,A7,A3,A6,A8,A11,A15;
      m in dom mf by A14,A15,FINSEQ_1:def 3;
      then
A19:  m<=len mf by FINSEQ_3:25;
      now
        per cases;
        case
A20:      m=len mf;
          then mf.m = r1 by A4,RFINSEQ:def 2;
          then (mf(#)h).m = r1(#)chi(A.m,C) by A2,A5,A8,A15,A17,RFUNCT_3:def 7;
          then
A21:      ((mf(#)h)#c).m = (r1(#)chi(A.m,C)).c by A15,RFUNCT_3:def 8;
          dom(r1(#)chi(A.m,C)) = dom chi(A.m,C) by VALUED_1:def 5
            .= C by RFUNCT_1:61;
          hence ((mf(#)h)#c).m = r1*(chi(A.m,C)).c by A21,VALUED_1:def 5
            .= r1*1 by A18,RFUNCT_1:63
            .= mf.m by A4,A20,RFINSEQ:def 2;
        end;
        case
A22:      m<>len mf;
          reconsider r2=fd.(m+1) as Real;
          m<len mf by A19,A22,XXREAL_0:1;
          then m+1<=len mf by NAT_1:13;
          then
A23:      m<=len mf - 1 by XREAL_1:19;
          then mf.m1 = r1-r2 by A16,RFINSEQ:def 2;
          then (mf(#)h).m = (r1-r2)(#)chi(A.m,C) by A2,A5,A8,A15,A17,
RFUNCT_3:def 7;
          then
A24:      ((mf(#)h)#c).m =((r1-r2)(#)chi(A.m,C)).c by A15,RFUNCT_3:def 8;
          dom((r1-r2)(#)chi(A.m,C)) = dom chi(A.m,C) by VALUED_1:def 5
            .= C by RFUNCT_1:61;
          hence ((mf(#)h)#c).m = (r1-r2)*(chi(A.m,C)).c by A24,VALUED_1:def 5
            .= (r1-r2)*1 by A18,RFUNCT_1:63
            .= mf.m1 by A16,A23,RFINSEQ:def 2;
        end;
      end;
      hence ((mf(#)h)#c).m = mf.m;
    end;
    hence thesis by A7,A6,A8,FINSEQ_2:9;
  end;
  let n;
  assume that
A25: 1<=n and
A26: n<len A and
A27: c in A.(n+1) \ A.n;
A28: len(mf/^n) = len mf - n by A7,A3,A26,RFINSEQ:def 1;
A29: for k st k in dom A & k<=n holds not c in A.k
  proof
    let k;
    assume
A30: k in dom A & k<=n;
    assume
A31: c in A.k;
    n in dom A by A25,A26,FINSEQ_3:25;
    then A.k c= A.n by A30,Th2;
    hence contradiction by A27,A31,XBOOLE_0:def 5;
  end;
A32: c in A.(n+1) by A27;
A33: n+1<=len A by A26,NAT_1:13;
A34: 1<=n+1 by A25,NAT_1:13;
A35: for k st k in dom A & n+1<=k holds c in A.k
  proof
    let k;
    assume
A36: k in dom A & n+1<=k;
    n+1 in dom A by A33,A34,FINSEQ_3:25;
    then A.(n+1) c= A.k by A36,Th2;
    hence thesis by A32;
  end;
  set fdn = FinS(F,D)/^n, mfn = MIM(fdn), n0 = n |-> (0 qua Real);
A37: len mfn = len fdn by RFINSEQ:def 2;
A38: len n0 = n by CARD_1:def 7;
  len fdn = len fd - n by A7,A3,A4,A26,RFINSEQ:def 1;
  then
A39: len (n0 ^ mfn) = n + (len fd -n) by A37,A38,FINSEQ_1:22
    .= len mf by RFINSEQ:def 2;
  then
A40: dom(n0^mfn) = Seg len mf by FINSEQ_1:def 3;
A41: dom n0 = Seg len n0 by FINSEQ_1:def 3;
  now
    let m be Nat;
    reconsider m1 = m as Element of NAT by ORDINAL1:def 12;
    reconsider r1=fd.m as Real;
    assume
A42: m in dom (n0^mfn);
    then
A43: 1<=m by FINSEQ_3:25;
    m in dom mf by A40,A42,FINSEQ_1:def 3;
    then
A44: m<=len mf by FINSEQ_3:25;
A45: h.m = chi(A.m,C) by A9,A7,A40,A42,RFUNCT_3:def 6;
    now
      per cases;
      case
A46:    m<=n;
        reconsider r2=fd.(m+1) as Real;
        m<n+1 by A46,NAT_1:13;
        then m<len A by A33,XXREAL_0:2;
        then m+1<=len A by NAT_1:13;
        then m<=len mf - 1 by A7,A3,XREAL_1:19;
        then mf.m1 = r1-r2 by A43,RFINSEQ:def 2;
        then (mf(#)h).m = (r1-r2)(#)chi(A.m,C) by A2,A7,A6,A40,A42,A45,
RFUNCT_3:def 7;
        then
A47:    ((mf(#)h)#c).m =((r1-r2)(#)chi(A.m,C)).c by A5,A7,A6,A8,A40,A42,
RFUNCT_3:def 8;
        not c in A.m by A1,A7,A3,A29,A40,A42,A46;
        then
A48:    chi(A.m,C).c = 0 by RFUNCT_1:64;
A49:    m in Seg n by A43,A46,FINSEQ_1:1;
A50:    n0.m = 0;
        dom((r1-r2)(#)chi(A.m,C)) = dom chi(A.m,C) by VALUED_1:def 5
          .= C by RFUNCT_1:61;
        hence ((mf(#)h)#c).m = (r1-r2)*(chi(A.m,C)).c by A47,VALUED_1:def 5
          .= (n0^mfn).m by A38,A41,A48,A49,A50,FINSEQ_1:def 7;
      end;
      case
A51:    n<m;
        then max(0,m-n) = m-n by FINSEQ_2:4;
        then reconsider mn = m-n as Element of NAT by FINSEQ_2:5;
A52:    n+1<=m by A51,NAT_1:13;
        then c in A.m by A1,A7,A3,A35,A40,A42;
        then
A53:    chi(A.m,C).c = 1 by RFUNCT_1:63;
A54:    1<=mn by A52,XREAL_1:19;
        now
          per cases;
          case
A55:        m = len mf;
            then mf.m = r1 by A4,RFINSEQ:def 2;
            then (mf(#)h).m = r1(#)chi(A.m,C) by A2,A7,A6,A40,A42,A45,
RFUNCT_3:def 7;
            then
A56:        ((mf(#)h)#c).m =(r1(#)chi(A.m,C)).c by A5,A7,A6,A8,A40,A42,
RFUNCT_3:def 8;
A57:        mn in dom(mf/^n) by A28,A54,A55,FINSEQ_3:25;
A58:        (n0^mfn).m = mfn.(m-n) by A38,A39,A44,A51,FINSEQ_1:24
              .=(mf/^n).mn by RFINSEQ:15
              .= mf.(mn+n) by A7,A3,A26,A57,RFINSEQ:def 1
              .= r1 by A4,A55,RFINSEQ:def 2;
            dom(r1(#)chi(A.m,C)) = dom chi(A.m,C) by VALUED_1:def 5
              .= C by RFUNCT_1:61;
            hence ((mf(#)h)#c).m = r1*(chi(A.m,C)).c by A56,VALUED_1:def 5
              .= (n0^mfn).m by A53,A58;
          end;
          case
A59:        m<>len mf;
            reconsider r2=fd.(m+1) as Real;
            m<len mf by A44,A59,XXREAL_0:1;
            then m+1<=len mf by NAT_1:13;
            then
A60:        m<=len mf - 1 by XREAL_1:19;
            then mf.m1 = r1-r2 by A43,RFINSEQ:def 2;
            then (mf(#)h).m = (r1-r2)(#)chi(A.m,C) by A2,A7,A6,A40,A42,A45,
RFUNCT_3:def 7;
            then
A61:        ((mf(#)h)#c).m =((r1-r2)(#)chi(A.m,C)).c by A5,A7,A6,A8,A40,A42,
RFUNCT_3:def 8;
            mn<=len(mf/^n) by A28,A44,XREAL_1:9;
            then
A62:        mn in dom(mf/^n) by A54,FINSEQ_3:25;
A63:        (n0^mfn).m = mfn.(m-n) by A38,A39,A44,A51,FINSEQ_1:24
              .=(mf/^n).mn by RFINSEQ:15
              .= mf.(mn+n) by A7,A3,A26,A62,RFINSEQ:def 1
              .= r1-r2 by A43,A60,RFINSEQ:def 2;
            dom((r1-r2)(#)chi(A.m,C)) = dom chi(A.m,C) by VALUED_1:def 5
              .= C by RFUNCT_1:61;
            hence ((mf(#)h)#c).m = (r1-r2)*(chi(A.m,C)).c by A61,VALUED_1:def 5
              .= (n0^mfn).m by A53,A63;
          end;
        end;
        hence ((mf(#)h)#c).m = (n0^mfn).m;
      end;
    end;
    hence ((mf(#)h)#c).m = (n0^mfn).m;
  end;
  hence thesis by A7,A6,A8,A39,FINSEQ_2:9;
end;
