cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-3 of 3 results.

A231693 Define a sequence of rationals by f(0)=0, thereafter f(n)=f(n-1)-1/n if that is >= 0, otherwise f(n)=f(n-1)+1/n; a(n) = denominator of f(n).

Original entry on oeis.org

1, 1, 2, 6, 12, 60, 20, 140, 280, 2520, 2520, 27720, 27720, 360360, 360360, 360360, 720720, 12252240, 4084080, 77597520, 77597520, 11085360, 11085360, 254963280, 84987760, 424938800, 424938800, 11473347600, 80313433200, 2329089562800, 2329089562800, 72201776446800, 144403552893600, 144403552893600
Offset: 0

Views

Author

N. J. A. Sloane, Nov 15 2013

Keywords

Comments

See Comments in A231692, which is the sequence of numerators of {f(n)}.
Note that this sequence is not monotonic.
Differs from A002805 starting at a(20)=77597520: A002805(20)=15519504. See also A203811 for a very similar idea. - M. F. Hasler, Nov 15 2013

Examples

			0, 1, 1/2, 1/6, 5/12, 13/60, 1/20, 27/140, 19/280, 451/2520, 199/2520, 4709/27720, ...
		

References

  • David Wilson, Posting to Sequence Fans Mailing List, Nov 14 2013.

Crossrefs

Programs

  • Haskell
    a231693 n = a231693_list !! n
    a231693_list = map denominator $ 0 : wilson 1 0 where
       wilson x y = y' : wilson (x + 1) y'
                    where y' = y + (if y < 1 % x then 1 else -1) % x
    -- Reinhard Zumkeller, Nov 16 2013
    
  • Maple
    f:=proc(n) option remember;
    if n=0 then 0 elif
    f(n-1) >= 1/n then f(n-1)-1/n else f(n-1)+1/n; fi; end;
  • Mathematica
    Denominator[FoldList[# + (-1)^Boole[#*#2 >= 1]/#2 &, Range[0, 35]]] (* Paolo Xausa, Aug 16 2025 *)
  • PARI
    s=0;vector(30,n,denominator(s-=(-1)^(n*s<1)/n)) \\ M. F. Hasler, Nov 15 2013
    
  • Python
    from fractions import Fraction
    A231693 = [(f:=Fraction(0)).denominator] + [(f:=(f + (Fraction(1,i) if Fraction(1,i)>f else -Fraction(1,i)))).denominator for i in range(1, 34)]  # Jwalin Bhatt, Apr 08 2025

A232111 Numerator of smallest nonnegative fraction of form +- 1 +- 1/2 +- 1/3 ... +- 1/n.

Original entry on oeis.org

0, 1, 1, 1, 1, 7, 1, 11, 13, 11, 11, 23, 23, 607, 251, 251, 25, 97, 97, 3767, 3767, 3767, 457, 24319, 24319, 7951, 4261, 13703, 13703, 872843, 872843, 17424097, 13828799, 902339, 7850449, 7850449, 7850449, 1526171, 68185267, 3429883, 3429883
Offset: 0

Views

Author

David W. Wilson, Nov 18 2013

Keywords

Comments

Sequence A231692 includes a proof that a(n) is never 0 for n > 1.

Examples

			1-1/2-1/3-1/4+1/5 = 7/60. No other choice of term signs yields a smaller nonnegative fraction, so a(5) = 7.
0/1, 1/1, 1/2, 1/6, 1/12, 7/60, 1/20, 11/420, 13/840, 11/2520, 11/2520, 23/27720, 23/27720, 607/360360, 251/360360, 251/360360, 25/144144, 97/12252240, ...
		

Crossrefs

Cf. A232112 (denominators), A231692.

Programs

  • Mathematica
    nMax = 19; d = {0}; Table[d = Flatten[{d + 1/n, d - 1/n}]; Numerator[Min[Abs[d]]], {n, nMax}] (* T. D. Noe, Nov 20 2013 *)
  • PARI
    a(n,t=0)=if(n==1,numerator(abs(n-t)),min(a(n-1,t-1/n),a(n-1,t+1/n))) \\ Charles R Greathouse IV, Apr 06 2014
    
  • Python
    from itertools import product
    from fractions import Fraction
    def A232111(n): return min(x for x in (sum(d[i]*Fraction(1,i+1) for i in range(n)) for d in product((1,-1),repeat=n)) if x >= 0).numerator # Chai Wah Wu, Nov 24 2021

A386883 Define a sequence of rationals by f(0) = 0, thereafter f(n) = f(n-1) - 1/n if that is >= 0, otherwise f(n) = f(n-1) + 1/n; a(n) corresponds to the number of addition steps minus the number of subtraction steps involved in calculating f(n).

Original entry on oeis.org

0, 1, 0, -1, 0, -1, -2, -1, -2, -1, -2, -1, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3
Offset: 0

Views

Author

Rémy Sigrist, Aug 06 2025

Keywords

Comments

This sequence is unbounded below.
By contradiction:
- let M be the minimum value of the sequence and a(n) = M be the first occurrence of M in the sequence,
- as an addition step is always followed by a subtraction step, and the value M can only be followed by M+1, a(n+2*k) = M and a(n+2*k+1) = M+1 for any k >= 0,
- for any m >= n, f(m) = f(n) + Sum_{k = n+1..m} (-1)^(k-n-1) / k,
- as the alternating harmonic series converges to log(2), the sequence f will have a positive limit, say L > 0,
- hence for some m0 >= 0, f(m) > L/2 for any m >= m0,
- let k be such that n+2*k >= m0 and 1/(n+2*k+1) < L/2: f(n+2*k) > L/2, so f(n+2*k+1) = f(n+2*k) - 1/(n+2*k+1), and a(n+2*k+1) = a(n+2*k)-1 = M-1, a contradiction.

Examples

			Sequence begins:
  n   a(n)  f(n)-f(n-1)
  --  ----  -----------
   0     0  N/A
   1     1  +1
   2     0  -1/2
   3    -1  -1/3
   4     0  +1/4
   5    -1  -1/5
   6    -2  -1/6
   7    -1  +1/7
   8    -2  -1/8
   9    -1  +1/9
  10    -2  -1/10
  11    -1  +1/11
  12    -2  -1/12
  13    -3  -1/13
  14    -2  +1/14
  15    -3  -1/15
		

Crossrefs

Programs

  • Mathematica
    Module[{f = 0, a = 0}, Array[If[f >= 1/#, f -= 1/#; a--, f += 1/#; a++] &, 100]] (* Paolo Xausa, Aug 25 2025 *)
  • PARI
    { print1(0); f = 0; a = 0; for (n = 1, 65, if (f >= 1/n, f -= 1/n; a--, f += 1/n; a++); print1 (", "a);); }

Formula

a(n) = Sum_{k = 1..n} sign(A231692(n)/A231693(n) - A231692(n-1)/A231693(n-1)).
Showing 1-3 of 3 results.