
theorem Th11:
  for A being set, S being finite Subset of A, b being Rbag of A
  st support b c= S ex f being FinSequence of REAL st f = b*canFS(S) & Sum b =
  Sum f
proof
  let A be set, S be finite Subset of A, b be Rbag of A such that
A1: support b c= S;
A2: card support b <= card S by A1,NAT_1:43;
  set cs = canFS(support b);
A3: rng cs = support b by FUNCT_2:def 3;
  set cS = canFS(S);
  set f = b*cS;
  len cS = card S by FINSEQ_1:93;
  then
A4: dom cS = Seg card S by FINSEQ_1:def 3;
  len cs = card support b by FINSEQ_1:93;
  then
A5: dom cs = Seg card support b by FINSEQ_1:def 3;
  consider g being FinSequence of REAL such that
A6: Sum b = Sum g and
A7: g = b*cs by Def2;
A8: dom b = A by PARTFUN1:def 2;
  then
A9: dom g = Seg card support b by A1,A7,A5,A3,RELAT_1:27,XBOOLE_1:1;
  then
A10: len g = card support b by FINSEQ_1:def 3;
A11: rng cS = S by FUNCT_2:def 3;
  then
A12: dom f = Seg card S by A4,A8,RELAT_1:27;
  then reconsider f as FinSequence by FINSEQ_1:def 2;
  rng f c= rng b by RELAT_1:26;
  then rng f c= REAL by XBOOLE_1:1;
  then reconsider f as FinSequence of REAL by FINSEQ_1:def 4;
  take f;
  thus f = b*canFS(S);
  per cases by A2,XXREAL_0:1;
  suppose
A13: card support b < card S;
    set dd = {j where j is Element of NAT : j in dom f & f.j = 0};
A14: now
      consider x being object such that
A15:  not (x in support b iff x in S) by A13,TARSKI:2;
      consider j being object such that
A16:  j in dom cS and
A17:  cS.j = x by A1,A11,A15,FUNCT_1:def 3;
      reconsider j as Element of NAT by A16;
      f.j =b.x by A16,A17,FUNCT_1:13;
      then f.j = 0 by A1,A15,PRE_POLY:def 7;
      then j in dd by A4,A12,A16;
      hence dd is non empty;
    end;
    reconsider gr = g as FinSequence of REAL;
A18: dd c= dom f
    proof
      let x be object;
      assume x in dd;
      then ex j being Element of NAT st x = j & j in dom f & f.j = 0;
      hence thesis;
    end;
    then reconsider dd as finite non empty set by A14;
    consider d being Element of NAT such that
A19: card S = (card support b) + d and
    1 <= d by A13,FINSEQ_4:84;
    set h = d |-> (In(0,REAL));
    set F = gr^h;
    rng canFS(dd) = dd & dd c= NAT by A18,FUNCT_2:def 3,XBOOLE_1:1;
    then reconsider cdd = canFS(dd) as FinSequence of NAT by FINSEQ_1:def 4;
    set cdi = cdd qua Function";
    reconsider cdi as Function of dd, Seg card dd by FINSEQ_1:95;
    reconsider cdi as Function of dd, NAT by FUNCT_2:7;
    deffunc Z(object) = cdi /. $1 + card support b;
    consider z being Function such that
A20: dom z = dd and
A21: for x being object st x in dd holds z.x = Z(x) from FUNCT_1:sch 3;
    set p = cs"*cS +* z;
A22: dom cdi = dd by FUNCT_2:def 1;
    set cSr = cS | (dom f \ dd);
    now
      let y be object;
      hereby
        assume y in rng cSr;
        then consider x being object such that
A23:    x in dom cSr and
A24:    y = cSr.x by FUNCT_1:def 3;
A25:    cSr.x = cS.x by A23,FUNCT_1:47;
        x in dom cS by A23,RELAT_1:57;
        then reconsider j = x as Element of NAT;
        dom cSr c= dom f \ dd by RELAT_1:58;
        then
A26:    x in findom f \ dd by A23;
        then not j in dd by XBOOLE_0:def 5;
        then
A27:    f.j <> 0 by A26;
        x in dom cS by A23,RELAT_1:57;
        then b.(cS.j) <> 0 by A27,FUNCT_1:13;
        hence y in support b by A24,A25,PRE_POLY:def 7;
      end;
      assume
A28:  y in support b;
      then consider x being object such that
A29:  x in dom cS and
A30:  y = cS.x by A1,A11,FUNCT_1:def 3;
      now
        assume x in dd;
        then consider j being Element of NAT such that
A31:    j = x and
A32:    j in dom f & f.j = 0;
        0 = b.(cS.j) by A4,A12,A32,FUNCT_1:13;
        hence contradiction by A28,A30,A31,PRE_POLY:def 7;
      end;
      then x in dom f \ dd by A4,A12,A29,XBOOLE_0:def 5;
      hence y in rng cSr by A29,A30,FUNCT_1:50;
    end;
    then
A33: rng cSr = support b by TARSKI:2;
    (findom f \ dd) /\ dom f = dom f \ dd by XBOOLE_1:28;
    then cSr is one-to-one & dom cSr = (dom f \ dd) by A4,A12,FUNCT_1:52
,RELAT_1:61;
    then support b, dom f \dd are_equipotent by A33,WELLORD2:def 4;
    then
A34: card support b = card (dom f \ dd) by CARD_1:5;
    card (dom f \ dd) = card dom f - card dd by A18,CARD_2:44;
    then
A35: card support b + card dd = card S by A12,A34,FINSEQ_1:57;
A36: now
A37:  dom (cs") = support b by A3,FUNCT_1:33;
      assume dom (cs"*cS) /\ dom z <> {};
      then consider x being object such that
A38:  x in dom (cs"*cS) /\ dom z by XBOOLE_0:def 1;
      x in dom z by A38,XBOOLE_0:def 4;
      then consider j being Element of NAT such that
A39:  j = x and
      j in dom f and
A40:  f.j = 0 by A20;
A41:  x in dom (cs"*cS) by A38,XBOOLE_0:def 4;
      then j in dom cS by A39,FUNCT_1:11;
      then f.j = b.(cS.j) by FUNCT_1:13;
      then not cS.j in support b by A40,PRE_POLY:def 7;
      hence contradiction by A41,A39,A37,FUNCT_1:11;
    end;
    len F = len g + len h by FINSEQ_1:22
      .= card S by A10,A19,CARD_1:def 7;
    then
A42: dom F = Seg card S by FINSEQ_1:def 3;
    now
      let x be object;
      hereby
        assume
A43:    x in dom (cs"*cS) \/ dom z;
        per cases by A43,XBOOLE_0:def 3;
        suppose
          x in dom (cs"*cS);
          hence x in dom F by A4,A42,FUNCT_1:11;
        end;
        suppose
          x in dom z;
          hence x in dom F by A12,A42,A18,A20;
        end;
      end;
      assume
A44:  x in dom F;
      then reconsider i = x as Element of NAT;
      per cases;
      suppose
        f.x = 0;
        then i in dom z by A12,A42,A20,A44;
        hence x in dom (cs"*cS) \/ dom z by XBOOLE_0:def 3;
      end;
      suppose
A45:    f.x <> 0;
        f.i = b.(cS.i) by A4,A42,A44,FUNCT_1:13;
        then cS.i in support b by A45,PRE_POLY:def 7;
        then cS. i in dom (cs") by A3,FUNCT_1:33;
        then i in dom (cs"*cS) by A4,A42,A44,FUNCT_1:11;
        hence x in dom (cs"*cS) \/ dom z by XBOOLE_0:def 3;
      end;
    end;
    then
A46: dom (cs"*cS) \/ dom z = dom F by TARSKI:2;
    then
A47: dom p = dom F by FUNCT_4:def 1;
    len cdd = card dd by FINSEQ_1:93;
    then
A48: dom cdd = Seg d by A19,A35,FINSEQ_1:def 3;
    then
A49: rng cdi = Seg d by FUNCT_1:33;
A50: rng z c= Seg card S
    proof
      let y be object;
      assume y in rng z;
      then consider x being object such that
A51:  x in dom z and
A52:  y = z.x by FUNCT_1:def 3;
A53:  cdi/.x = cdi.x & cdi.x in Seg d by A22,A49,A20,A51,FUNCT_1:3
,PARTFUN1:def 6;
      then 1 <= cdi/.x by FINSEQ_1:1;
      then
A54:  1 <= cdi/.x + card support b by NAT_1:12;
      cdi/.x <= d by A53,FINSEQ_1:1;
      then
A55:  cdi/.x + card support b <= d + card support b by XREAL_1:6;
      y = cdi/.x + card support b by A20,A21,A51,A52;
      hence thesis by A19,A54,A55,FINSEQ_1:1;
    end;
A56: now
      let x be object such that
A57:  x in dom F;
      per cases by A46,A57,XBOOLE_0:def 3;
      suppose
A58:    x in dom (cs"*cS);
        then (cs"*cS).x in rng (cs"*cS) by FUNCT_1:3;
        then (cs"*cS).x in rng (cs") by FUNCT_1:14;
        then
A59:    (cs"*cS).x in dom cs by FUNCT_1:33;
        not x in dom z by A36,A58,XBOOLE_0:def 4;
        then
A60:    p.x = (cs"*cS).x by FUNCT_4:11;
        Seg card support b c= Seg card S by A2,FINSEQ_1:5;
        hence p.x in dom F by A5,A42,A60,A59;
      end;
      suppose
        x in dom z;
        then p.x = z.x & z.x in rng z by FUNCT_1:3,FUNCT_4:13;
        hence p.x in dom F by A42,A50;
      end;
    end;
A61: dom p = dom (cs"*cS) \/ dom z by FUNCT_4:def 1;
    reconsider p as Function of dom F, dom F by A47,A56,FUNCT_2:3;
    len h = d by CARD_1:def 7;
    then
A62: dom h = Seg d by FINSEQ_1:def 3;
A63: rng cdd = dd by FUNCT_2:def 3;
    now
      let x be object;
      hereby
        assume x in rng p;
        then consider a being object such that
A64:    a in dom p and
A65:    x = p.a by FUNCT_1:def 3;
        per cases by A64,FUNCT_4:12;
        suppose
A66:      a in dom (cs"*cS);
          then cS.a in dom (cs") by FUNCT_1:11;
          then cs".(cS.a) in rng (cs") by FUNCT_1:3;
          then
A67:      cs".(cS.a) in dom cs by FUNCT_1:33;
          not a in dom z by A36,A66,XBOOLE_0:def 4;
          then
A68:      p.a = (cs"*cS).a by FUNCT_4:11
            .= cs".(cS.a) by A66,FUNCT_1:12;
          dom cs c= dom F by A5,A2,A42,FINSEQ_1:5;
          hence x in dom F by A65,A68,A67;
        end;
        suppose
          a in dom z;
          then z.a in rng z & p.a = z.a by FUNCT_1:3,FUNCT_4:13;
          hence x in dom F by A42,A50,A65;
        end;
      end;
      assume
A69:  x in dom F;
      then reconsider j = x as Element of NAT;
      per cases by A69,FINSEQ_1:25;
      suppose
A70:    j in dom gr;
        then
A71:    cs.j in support b by A5,A3,A9,FUNCT_1:3;
        then
A72:    cS".(cs.j) in Seg card S by A1,A4,A11,FUNCT_1:32;
        now
          assume cS".(cs.j) in dom z;
          then
A73:      ex k being Element of NAT st k = cS".(cs.j) & k in dom f & f.k
          = 0 by A20;
          (b*cS).(cS".(cs.j)) = b.(cS.(cS".(cs.j))) by A4,A72,FUNCT_1:13
            .= b.(cs.j) by A1,A11,A71,FUNCT_1:35;
          hence contradiction by A71,A73,PRE_POLY:def 7;
        end;
        then p.(cS".(cs.j)) = (cs"*cS).(cS".(cs.j)) by FUNCT_4:11
          .= cs".(cS.(cS".(cs.j))) by A4,A72,FUNCT_1:13
          .= cs".(cs.j) by A1,A11,A71,FUNCT_1:35
          .= j by A5,A9,A70,FUNCT_1:34;
        hence x in rng p by A42,A47,A72,FUNCT_1:3;
      end;
      suppose
        ex n being Nat st n in dom h & j=len gr + n;
        then consider n being Nat such that
A74:    n in dom h and
A75:    j = len gr + n;
A76:    cdd.n in dd by A62,A48,A63,A74,FUNCT_1:3;
        p.(cdd.n) = z.(cdd.n) by A62,A48,A63,A20,A74,FUNCT_1:3,FUNCT_4:13
          .= cdi /. (cdd.n) + card support b by A62,A48,A63,A21,A74,FUNCT_1:3
          .= cdi.(cdd.n) + card support b by A62,A48,A63,A22,A74,FUNCT_1:3
,PARTFUN1:def 6
          .= n + card support b by A62,A48,A74,FUNCT_1:34
          .= j by A9,A75,FINSEQ_1:def 3;
        hence x in rng p by A12,A42,A18,A47,A76,FUNCT_1:3;
      end;
    end;
    then
A77: rng p = dom F by TARSKI:2;
    then
A78: dom (F*p) = dom F by A47,RELAT_1:27;
    now
      let x be object;
      assume
A79:  x in dom f;
      per cases;
      suppose
A80:    f.x = 0;
        reconsider cdix = cdi /. x as Element of NAT;
        reconsider px = p.x as Element of NAT by ORDINAL1:def 12;
        reconsider j = x as Element of NAT by A79;
A81:    j in dom z by A20,A79,A80;
        then
A82:    p.x = z.x by FUNCT_4:13
          .= cdi /. x + card support b by A20,A21,A81;
A83:    cdi.x in Seg card dd by A20,A81,FUNCT_2:5;
        dom cdi = dd by FUNCT_2:def 1;
        then
A84:    cdi /. x = cdi.x by A20,A81,PARTFUN1:def 6;
        thus f.x = h.(cdix) by A80
          .= F.px by A10,A19,A62,A35,A82,A84,A83,FINSEQ_1:def 7
          .= (F*p).x by A12,A42,A78,A79,FUNCT_1:12;
      end;
      suppose
A85:    f.x <> 0;
        reconsider px = p.x as Element of NAT by ORDINAL1:def 12;
        f.x = b.(cS.x) by A79,FUNCT_1:12;
        then cS.x in support b by A85,PRE_POLY:def 7;
        then
A86:    cS.x in rng cs by FUNCT_2:def 3;
        then
A87:    cs".(cS.x) in dom cs by FUNCT_1:32;
        now
          assume x in dd;
          then ex j being Element of NAT st j=x & j in dom f & f.j = 0;
          hence contradiction by A85;
        end;
        then
A88:    p.x = (cs"*cS).x by A20,FUNCT_4:11
          .= cs".(cS.x) by A4,A12,A79,FUNCT_1:13;
        thus f.x = b.(cS.x) by A79,FUNCT_1:12
          .= b.(cs.px) by A86,A88,FUNCT_1:32
          .= g.(px) by A7,A87,A88,FUNCT_1:13
          .= F.(px) by A5,A9,A87,A88,FINSEQ_1:def 7
          .= (F*p).x by A12,A42,A78,A79,FUNCT_1:12;
      end;
    end;
    then
A89: f = F*p by A4,A11,A8,A42,A78,RELAT_1:27;
A90: p is one-to-one
    proof
      let a, c be object such that
A91:  a in dom p & c in dom p and
A92:  p.a = p.c;
      per cases by A61,A91,XBOOLE_0:def 3;
      suppose
A93:    a in dom (cs"*cS) & c in dom (cs"*cS);
        then cS.a in dom (cs") by FUNCT_1:11;
        then cS.a in rng cs by FUNCT_1:33;
        then
A94:    cs.(cs".(cS.a)) = cS.a by FUNCT_1:35;
        a in dom cS by A93,FUNCT_1:11;
        then
A95:    cS".(cS.a) = a by FUNCT_1:34;
        cS.c in dom (cs") by A93,FUNCT_1:11;
        then
A96:    cS.c in rng cs by FUNCT_1:33;
        not c in dom z by A36,A93,XBOOLE_0:def 4;
        then
A97:    p.c = (cs"*cS).c by FUNCT_4:11
          .= cs".(cS.c) by A93,FUNCT_1:12;
A98:    c in dom cS by A93,FUNCT_1:11;
        not a in dom z by A36,A93,XBOOLE_0:def 4;
        then p.a = (cs"*cS).a by FUNCT_4:11
          .= cs".(cS.a) by A93,FUNCT_1:12;
        then cS".(cS.a) = cS".(cS.c) by A92,A97,A94,A96,FUNCT_1:35;
        hence thesis by A95,A98,FUNCT_1:34;
      end;
      suppose
A99:    a in dom (cs"*cS) & c in dom z;
        then cS.a in dom (cs") by FUNCT_1:11;
        then cs".(cS.a) in rng (cs") by FUNCT_1:3;
        then
A100:   cs".(cS.a) in dom cs by FUNCT_1:33;
        not a in dom z by A36,A99,XBOOLE_0:def 4;
        then
A101:   p.a = (cs"*cS).a by FUNCT_4:11
          .= cs".(cS.a) by A99,FUNCT_1:12;
        p.c = z.c by A99,FUNCT_4:13
          .= cdi /. c + card support b by A20,A21,A99;
        then cdi /. c + card support b <= (0 qua Nat)+card support b by A5,A92
,A101,A100,FINSEQ_1:1;
        then cdi /. c = 0 by XREAL_1:6;
        then
A102:   cdi.c = 0 by A22,A20,A99,PARTFUN1:def 6;
        cdi.c in rng cdi by A22,A20,A99,FUNCT_1:3;
        hence thesis by A49,A102,FINSEQ_1:1;
      end;
      suppose
A103:   a in dom z & c in dom (cs"*cS);
        then cS.c in dom (cs") by FUNCT_1:11;
        then cs".(cS.c) in rng (cs") by FUNCT_1:3;
        then
A104:   cs".(cS.c) in dom cs by FUNCT_1:33;
        not c in dom z by A36,A103,XBOOLE_0:def 4;
        then
A105:   p.c = (cs"*cS).c by FUNCT_4:11
          .= cs".(cS.c) by A103,FUNCT_1:12;
        p.a = z.a by A103,FUNCT_4:13
          .= cdi /. a + card support b by A20,A21,A103;
        then cdi /. a + card support b <= (0 qua Nat)+card support b by A5,A92
,A105,A104,FINSEQ_1:1;
        then cdi /. a = 0 by XREAL_1:6;
        then
A106:   cdi.a = 0 by A22,A20,A103,PARTFUN1:def 6;
        cdi.a in rng cdi by A22,A20,A103,FUNCT_1:3;
        hence thesis by A49,A106,FINSEQ_1:1;
      end;
      suppose
A107:   a in dom z & c in dom z;
        then
A108:   cdi /. a = cdi . a & cdi /. c = cdi . c by A22,A20,PARTFUN1:def 6;
A109:   p.c = z.c by A107,FUNCT_4:13
          .= cdi /. c + card support b by A20,A21,A107;
        p.a = z.a by A107,FUNCT_4:13
          .= cdi /. a + card support b by A20,A21,A107;
        hence thesis by A22,A20,A92,A107,A109,A108,FUNCT_1:def 4;
      end;
    end;
    Sum h = 0 by RVSUM_1:81;
    then
A110: Sum gr = Sum gr + Sum h .= Sum F by RVSUM_1:75;
    p is onto by A77,FUNCT_2:def 3;
    hence thesis by A6,A90,A89,A110,FINSOP_1:7;
  end;
  suppose
    card support b = card S;
    hence thesis by A1,A6,A7,CARD_2:102;
  end;
end;
