reserve i,j,k,n,m for Nat,
        X for set,
        b,s for bag of X,
        x for object;

theorem Th19:
  for n be Nat, b be bag of n, i st b.i = degree b holds
    b = (EmptyBag n) +* (i,b.i)
proof
  let n be Nat, b be bag of n, i such that
A1: b.i = degree b;
  per cases;
  suppose degree b=0;
    then
A2: b = EmptyBag n by UPROOTS:12;
A3: dom ((EmptyBag n) +* (i,b.i)) = n =dom b by PARTFUN1:def 2;
    x in dom b implies b.x = ((EmptyBag n) +* (i,b.i)).x
    proof
      assume A4:x in dom b;
      per cases;
      suppose x=i;
        hence thesis by A4,A2,FUNCT_7:31;
      end;
      suppose x<>i;
        hence thesis by A2,FUNCT_7:32;
      end;
    end;
    hence thesis by A3;
  end;
  suppose
A5: degree b > 0;
    then
A6: i in dom b =n by A1,FUNCT_1:def 2,PARTFUN1:def 2;
    set E = (EmptyBag n) +* (i,b.i);
A7: dom EmptyBag n = n by PARTFUN1:def 2;
A8: b = b +*(i,0) + (EmptyBag n) +* (i,b.i) by Th15;
    then
A9: Sum b = Sum (b +*(i,0)) + Sum (E) by UPROOTS:15;
A10: support E = {i} by A5,A1,A6,Th13;
A11: RelIncl n  linearly_orders support E by PRE_POLY:82;
    set S=SgmX(RelIncl n, support E);
A12: rng S = {i} & len S = card {i}=1
    by A10,A11,PRE_POLY:def 2,PRE_POLY:11,CARD_1:30;
    {i} c= dom E by A10,PRE_POLY:37;
    then
A13: dom (E*S) = dom S by A12,RELAT_1:27;
    then
A14: len (E*S) = 1 by A12,FINSEQ_3:29;
    1 in dom (E*S) by A13,FINSEQ_3:25,A12;
    then (E*S).1 = E.(S.1) & S.1 in rng S by A13,FUNCT_1:12,def 3;
    then (E*S).1 = E.i by A12,TARSKI:def 1;
    then E*S = <*E.i*> by A14,FINSEQ_1:40;
    then Sum (E*S) = b.i by A7,A6,FUNCT_7:31;
    then b.i = Sum (b +*(i,0)) + b.i by A9,A1,HILB10_5:5;
    then b +*(i,0) = EmptyBag n by UPROOTS:12;
    hence thesis by PRE_POLY:53,A8;
  end;
end;
