
theorem NF993:
  for n being Nat, epsilon being Real,
  a being non empty positive at_most_one FinSequence of REAL,
  f being non empty FinSequence of NAT st
  n is odd & len a = n & epsilon = 1 / (n + 1) &
  (for i being Nat st i in Seg n holds
  (i is odd  implies a . i = 2 * epsilon) &
  (i is even implies a . i = 1 - epsilon)) &
  f = OnlinePacking(a, NextFit(a)) holds
  n = card rng f
  proof
    let n be Nat, epsilon be Real,
    a be non empty positive at_most_one FinSequence of REAL,
    f be non empty FinSequence of NAT;

    assume that
    L010: n is odd and
    L030: len a = n and
    L040: epsilon = 1 / (n + 1) and
    L050: for i being Nat st i in Seg n holds
    (i is odd  implies a . i = 2 * epsilon) &
    (i is even implies a . i = 1 - epsilon) and
    HL00: f = OnlinePacking(a, NextFit(a));

    L020: 1 <= n by L010,NF992;

    set h = OnlinePackingHistory(a, NextFit(a));

    defpred ODDEVENHIST[Nat] means
    ($1 is odd implies
    SumBin (a, h . $1, {(h . $1) . $1}) = 2 * epsilon) &
    ($1 is even implies
    SumBin (a, h . $1, {(h . $1) . $1}) = 1 - epsilon) &
    (h . $1) . $1 = $1 & rng (h . $1) = Seg $1;

    L300: ODDEVENHIST[1]
    proof
      L305: h . 1 = <* 1 *> by defPackHistory;

      L324: 1 = 2 * 0 + 1;

      L332: 1 in Seg n by L020;

      SumBin (a, h . 1, {(h . 1) . 1})
      =  a . 1 by NF502
      .= 2 * epsilon by L324,L332,L050;
      hence thesis by L305,FINSEQ_1:39,FINSEQ_1:2,L324;
    end;

    L400: for i being Element of NAT st 1 <= i & i < len a & ODDEVENHIST[i]
    holds ODDEVENHIST[i + 1]
    proof
      let i0 be Element of NAT;

      assume that
      L410: 1 <= i0 and
      L411: i0 < len a and
      L412: ODDEVENHIST[i0];

      reconsider i0p = i0 + 1 as Nat;

      L469: 1 + 0 <= i0 + 1 by XREAL_1:7;

      L480: i0p <= n by L411,L030,NAT_1:13; then

      L490: i0p in Seg n by L469;

      reconsider hi0 = h . i0 as FinSequence of NAT by L410,L411,NF505;
      reconsider hi0p = h . i0p as FinSequence of NAT by L469,L030,L480,NF505;

      L496: hi0p = hi0 ^ <* (NextFit(a)) . (a . i0p, hi0) *> &
      hi0p . i0p = (NextFit(a)) . (a . i0p, hi0) by L410,L411,NF520;

      L498: len hi0 = i0 by L410,L411,NF510;

      L500: i0p is odd implies
      hi0p . i0p = i0p & rng hi0p = Seg i0p &
      SumBin (a, h . i0p, {(h . i0p) . i0p}) = 2 * epsilon
      proof
        assume L510: i0p is odd;
        then a . i0p = 2 * epsilon by L050,L490;
        then L542: a . i0p + SumBin (a, hi0, {hi0 . i0}) = 1 + epsilon
        by L510,L412;

        L549: 0 + 1 < epsilon + 1 by XREAL_1:139,L040,XREAL_1:6;

        L580: hi0p . i0p
        =  (NextFit(a)) . (a . i0p, hi0) by L410,L411,NF520
        .= hi0 . i0 + 1 by L549,L542,L498,defNextFit;
        hence hi0p . i0p = i0p by L412;

        thus rng hi0p = rng hi0 \/ {hi0p . i0p} by L410,L411,NF525
        .= Seg i0p by L580,L412,FINSEQ_1:9;

        not i0 + 1 in Seg i0 by XREAL_1:29,FINSEQ_1:1;
        then L590: SumBin (a, hi0, {hi0 . i0 + 1}) = 0
        by L412,ZFMISC_1:50,NF290;

        SumBin (a, hi0p, {hi0p . i0p})
        = SumBin (a, hi0, {hi0p . i0p}) + a . (len hi0 + 1)
        by L496,L498,L480,L030,NF200
        .= a . (i0 + 1) by L580,L590,L410,L411,NF510
        .= 2 * epsilon by L490,L510,L050;
        hence SumBin (a, h . i0p, {(h . i0p) . i0p}) = 2 * epsilon;
      end;

      i0p is even implies
      hi0p . i0p = i0p & rng hi0p = Seg i0p &
      SumBin (a, hi0p, {hi0p . i0p}) = 1 - epsilon
      proof
        assume L710: i0p is even;
        then L720: a . i0p = 1 - epsilon by L050,L490;

        L742: a . i0p + SumBin (a, hi0, {hi0 . i0}) = 1 + epsilon
        by L720,L710,L412;

        L749: 0 + 1 < epsilon + 1 by XREAL_1:139,L040,XREAL_1:6;

        L780: hi0p . i0p
        =  (NextFit(a)) . (a . i0p, hi0) by L410,L411,NF520
        .= hi0 . i0 + 1 by L742,L498,defNextFit,L749;
        hence hi0p . i0p = i0p by L412;

        thus rng hi0p = rng hi0 \/ {hi0p . i0p} by L410,L411,NF525
        .= Seg i0p by L780,L412,FINSEQ_1:9;

        not i0 + 1 in Seg i0 by XREAL_1:29,FINSEQ_1:1;
        then L790: SumBin (a, hi0, {hi0 . i0 + 1}) = 0
        by L412,ZFMISC_1:50,NF290;

        SumBin (a, hi0p, {hi0p . i0p})
        =  SumBin (a, hi0, {hi0p . i0p}) + a . (len hi0 + 1)
        by L496,L498,L480,L030,NF200
        .= a . (i0 + 1) by L780,L790,L410,L411,NF510
        .= 1 - epsilon by L490,L710,L050;
        hence SumBin (a, hi0p, {hi0p . i0p}) = 1 - epsilon;
      end;
      hence ODDEVENHIST[i0 + 1] by L500;
    end;

    L899: for i being Element of NAT st 1 <= i & i <= len a holds
    ODDEVENHIST[i] from INT_1:sch 7(L300,L400);

    L902: f = h . n by HL00,defPackHistory,L030;

    thus n = card Seg n by FINSEQ_1:57
    .= card rng f by L020,L030,L899,L902;
  end;
