
theorem
  for n being Nat st n is odd holds
  ex a being non empty positive at_most_one FinSequence of REAL st
  len a = n &
  for f being non empty FinSequence of NAT st
  f = OnlinePacking(a, NextFit(a)) holds
  n = card rng f & n = 2 * Opt a - 1
  proof
    let n be Nat;

    assume that
    L010: n is odd;
    L020: 1 <= n by L010,NF992;

    set epsilon = 1 / (n + 1);

    defpred P[Nat, object] means
    ($1 is odd  implies $2 = 2 * epsilon) &
    ($1 is even implies $2 = 1 - epsilon);

    L100: for i being Nat st i in Seg n holds ex x being object st P[i, x]
    proof
      let i be Nat;

      assume i in Seg n;

      per cases;
      suppose i is odd;
        hence thesis;
      end;
      suppose i is even;
        hence thesis;
      end;
    end;

    consider a0 being FinSequence such that
    L200: dom a0 = Seg n and
    L210: for i being Nat st i in Seg n holds P[i, a0 . i]
    from FINSEQ_1:sch 1 (L100);

    for i being Nat st i in dom a0 holds a0 . i in REAL
    proof
      let i be Nat;

      assume L309: i in dom a0;

      per cases;
      suppose i is odd;
        then a0 . i = 2 * epsilon by L309,L200,L210;
        hence a0 . i in REAL by XREAL_0:def 1;
      end;
      suppose i is even;
        then a0 . i = 1 - epsilon by L309,L200,L210;
        hence a0 . i in REAL by XREAL_0:def 1;
      end;
    end;
    then reconsider a0 as non empty FinSequence of REAL by NF315,L010,L200;

    L500: a0 is positive
    proof
      1 + 1 <= n + 1 by L010,NF992,XREAL_1:6;
      then 2 <= n or 2 = n + 1 by NAT_1:8;
      then per cases;
      suppose B000: n = 1;
        for y being object holds
        y in {2 * epsilon} iff
        ex x being object st x in dom a0 & y = a0 . x
        proof
          let y be object;

          hereby
            assume y in {2 * epsilon};
            then L410: y = 2 * epsilon by TARSKI:def 1;

            set x0 = 1;

            L415: x0 in Seg n by L020;

            L420: x0 in dom a0 by L020,L200;

            reconsider x0 as Nat;

            x0 mod 2 = 1 by NAT_D:14;
            then x0 is odd by NAT_2:22;
            then y = a0 . x0 by L415,L210,L410;
            hence ex x being object st x in dom a0 & y = a0 . x by L420;
          end;

          given x0 being object such that
          L440: x0 in dom a0 and
          L442: y = a0 . x0;
          L455: x0 = 1 by L440,L200,B000,FINSEQ_1:2,TARSKI:def 1;

          reconsider x0 as Nat by L440;

          x0 mod 2 = 1 by L455,NAT_D:14;
          then L460: x0 is odd by NAT_2:22;

          a0 . x0 = 2 * epsilon by L440,L200,L460,L210;
          hence y in {2 * epsilon} by L442,TARSKI:def 1;
        end;
        then L480: rng a0 = {2 * epsilon} by FUNCT_1:def 3;

        for r being Real st r in rng a0 holds 0 < r
        proof
          let r be Real;

          assume L489: r in rng a0;

          0 / (n + 1) < 1 / (n + 1) by XREAL_1:74;
          then 0 * 2 < epsilon * 2 by XREAL_1:68;
          hence 0 < r by L489,L480,TARSKI:def 1;
        end;
        hence a0 is positive by PARTFUN3:def 1;
      end;
      suppose B500: 2 <= n;
        for y being object holds
        y in {2 * epsilon, 1 - epsilon} iff
        ex x being object st x in dom a0 & y = a0 . x
        proof
          let y be object;

          hereby
            assume y in {2 * epsilon, 1 - epsilon};
            then per cases by TARSKI:def 2;
            suppose L410: y = 2 * epsilon;
              set x0 = 1;

              L415: x0 in Seg n by L020;

              L420: x0 in dom a0 by L020,L200;

              reconsider x0 as Nat;

              x0 = 2 * 0 + 1;
              then y = a0 . x0 by L415,L210,L410;
              hence ex x being object st x in dom a0 & y = a0 . x by L420;
            end;
            suppose L430: y = 1 - epsilon;

              set x0 = 2;

              L415: x0 in Seg n by B500;

              L420: x0 in dom a0 by L200,B500;

              reconsider x0 as Nat;

              x0 = 2 * 1;
              then y = a0 . x0 by L415,L210,L430;
              hence ex x being object st x in dom a0 & y = a0 . x by L420;
            end;
          end;

          given x0 being object such that
          L440: x0 in dom a0 and
          L442: y = a0 . x0;

          reconsider x0 as Nat by L440;

          per cases;
          suppose x0 is odd;
            P[x0, a0 . x0] by L440,L200,L210;
            hence y in {2 * epsilon, 1 - epsilon} by L442,TARSKI:def 2;
          end;
          suppose x0 is even;
            P[x0, a0 . x0] by L440,L200,L210;
            hence y in {2 * epsilon, 1 - epsilon} by L442,TARSKI:def 2;
          end;
        end;
        then L480: rng a0 = {2 * epsilon, 1 - epsilon} by FUNCT_1:def 3;

        for r being Real st r in rng a0 holds 0 < r
        proof
          let r be Real;

          assume r in rng a0;
          then per cases by L480,TARSKI:def 2;
          suppose L490: r = 2 * epsilon;
            0 / (n + 1) < 1 / (n + 1) by XREAL_1:74;
            then 0 * 2 < epsilon * 2 by XREAL_1:68;
            hence thesis by L490;
          end;
          suppose L495: r = 1 - epsilon;
            1 < (n + 1) * 1 by L010,NF992,NAT_1:13;
            then 1 / (n + 1) < 1 by XREAL_1:83;
            hence thesis by XREAL_1:50,L495;
          end;
        end;
        hence a0 is positive by PARTFUN3:def 1;
      end;
    end;

    for i being Nat st 1 <= i & i <= len a0 holds a0 . i <= 1
    proof
      let i be Nat;

      assume 1 <= i & i <= len a0;
      then L510: i in Seg n by FINSEQ_3:25,L200;

      per cases;
      suppose i is odd;
        then L530: a0 . i = 2 * epsilon by L510,L210;
        1 + 1 <= n + 1 by L010,NF992,XREAL_1:6;
        then (2 * 1) / (n + 1) <= 1 by XREAL_1:183;
        hence a0 . i <= 1 by XCMPLX_1:74,L530;
      end;
      suppose L560: i is even;
        1 - 1 / (n + 1) <= 1 - 0 by XREAL_1:10;
        hence a0 . i <= 1 by L510,L560,L210;
      end;
    end;
    then a0 is at_most_one; then

    reconsider a0 as non empty positive at_most_one FinSequence of REAL
    by L500;

    take a0;

    L649: Seg len a0 = Seg n by FINSEQ_1:def 3,L200;
    hence len a0 = n by FINSEQ_1:6;

    let f be non empty FinSequence of NAT;

    assume f = OnlinePacking(a0, NextFit(a0));

    hence n = card rng f by L010,L649,FINSEQ_1:6,L210,NF993;

    thus n = 2 * Opt a0 - 1 by L010,L649,FINSEQ_1:6,L210,NF997;
  end;
