A005374 Hofstadter H-sequence: a(n) = n - a(a(a(n-1))).
0, 1, 1, 2, 3, 4, 4, 5, 5, 6, 7, 7, 8, 9, 10, 10, 11, 12, 13, 13, 14, 14, 15, 16, 17, 17, 18, 18, 19, 20, 20, 21, 22, 23, 23, 24, 24, 25, 26, 26, 27, 28, 29, 29, 30, 31, 32, 32, 33, 33, 34, 35, 35, 36, 37, 38, 38, 39, 40, 41, 41, 42, 42, 43, 44, 45, 45, 46, 46, 47, 48, 48, 49, 50
Offset: 0
References
- D. R. Hofstadter, Goedel, Escher, Bach: an Eternal Golden Braid, Random House, 1980, p. 137.
- N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
Links
- Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
- Benoit Cloitre, Plot of a(n)-c*n where c=0.6823278...
- Larry Ericksen and Peter G. Anderson, Patterns in differences between rows in k-Zeckendorf arrays, The Fibonacci Quarterly, Vol. 50, No. 1 (February 2012), pp. 11-18.
- Nick Hobson, Python program for this sequence
- D. R. Hofstadter, Eta-Lore [Cached copy, with permission]
- D. R. Hofstadter, Pi-Mu Sequences [Cached copy, with permission]
- D. R. Hofstadter and N. J. A. Sloane, Correspondence, 1977 and 1991
- Pierre Letouzey, S. Li and W. Steiner, Pointwise order of generalized Hofstadter functions G,H and beyond, arXiv:2410.00529 [cs.DM], 2024.
- Pierre Letouzey, Generalized Hofstadter functions G,H and beyond: numeration systems and discrepancy arXiv:2502.12615 [cs.DM], 2025.
- Programming Puzzles & Code Golf Stack Exchange, Hofstadter H-sequence
- Jeffrey Shallit, The Narayana Morphism and Related Words, arXiv:2503.01026 [math.CO], 2025.
- Eric Weisstein's World of Mathematics, Hofstadter H-Sequence
- Wikipedia, Hofstadter sequence
- Index entries for Hofstadter-type sequences
- Index entries for sequences from "Goedel, Escher, Bach"
Programs
-
Haskell
a005374 n = a005374_list !! n a005374_list = 0 : 1 : zipWith (-) [2..] (map (a005374 . a005374) $ tail a005374_list) -- Reinhard Zumkeller, Dec 17 2011
-
Maple
A005374 := proc(n) option remember: if n<1 then 0 else n-A005374(A005374(A005374(n-1))) fi end: # Francisco Salinas (franciscodesalinas(AT)hotmail.com), Jan 06 2002 H:=proc(n) option remember; if n=1 then 1 else n-H(H(H(n-1))); fi; end proc;
-
Mathematica
a[n_]:= a[n]= n - a[a[a[n-1]]]; a[0] = 0; Table[a[n], {n, 0, 73}] (* Jean-François Alcover, Jul 28 2011 *)
-
PARI
first(m)=my(v=vector(m));v[1]=1;for(i=2,m,v[i]=i-v[v[v[i-1]]]);concat([0],v) \\ Anders Hellström, Dec 07 2015
-
SageMath
@CachedFunction # a = A005374 def a(n): return 0 if (n==0) else n - a(a(a(n-1))) [a(n) for n in range(101)] # G. C. Greubel, Nov 14 2022
Formula
Conjecture: a(n) = floor(c*n) + 0 or 1, where c is the real root of x^3+x-1 = 0, c=0.682327803828019327369483739... - Benoit Cloitre, Nov 05 2002 [Proved by Letouzey, see Letouzey link. - Pierre Letouzey, Feb 20 2025], [Also proved in Shallit (2025). - Jeffrey Shallit, Mar 09 2025]
a(n) = A020942(n) - 2*A064105(n) + A064106(n) (e.g. for n = 30 we get 20 = 93 - 2*137 + 201), and a(n) = 2*A020942(n) - A064105(n) - A023443(n) (e.g. for n = 30 we get 20 = 2*93 - 137 - 29). [Corrected by N. J. A. Sloane, Apr 29 2024 at the suggestion of A.H.M. Smeets.]
Recurrence: a(n) = a(n-1) if n-1 belongs to sequence A020942, a(n-1) + 1 otherwise.
Recurrence for n>=3: a(n) = Lm(k-1) + a(n-Lm(k)), where Lm(n) denotes Lamé sequence A000930(n) (Lm(n) = Lm(n-1) + Lm(n-3)) and k is such that Lm(k)< n <= Lm(k+1). Special case: a(Lm(n)) = Lm(n-1) for n>=1.
For n > 0: a(A136495(n)) = n. - Reinhard Zumkeller, Dec 17 2011
Extensions
More terms from James Sellers, Jul 12 2000
Additional comments and formulas from Diego Torres (torresvillarroel(AT)hotmail.com), Nov 23 2002
Comments