Hofstadter Q Sequence Calculator

Sequences

Hofstadter Q-sequence value Q(100)56
previous term Q(n - 1)54
next term Q(n + 1)48
largest value among the first n terms64
How this was calculated
  1. The Hofstadter Q sequence starts Q(1) = Q(2) = 1 and follows the self-referential recurrence Q(n) = Q(n - Q(n - 1)) + Q(n - Q(n - 2)).
  2. Running the recurrence up to n = 100 gives Q(100) = 56.
  3. Unlike tame recurrences, this one is chaotic: the terms hover near n / 2 but lurch unpredictably, and no closed form is known.
  4. Douglas Hofstadter introduced the sequence in Godel, Escher, Bach (1979); whether it even continues forever without hitting an undefined term is still unproven in general.

Some recurrences look back a fixed distance. Hofstadter's Q sequence looks back by amounts it chooses itself: Q(n) = Q(n - Q(n - 1)) + Q(n - Q(n - 2)). The reach of each term depends on the values of the previous terms, so the sequence navigates by its own lights - and the result is chaos. The terms hover near n / 2, lurching above and below it in bursts nobody has learned to predict: Q(100) = 56, Q(500) = 257, Q(1000) = 502.

Douglas Hofstadter introduced the sequence in Godel, Escher, Bach in 1979 as a emblem of self-reference - a sequence defined by pointing at itself. Nearly half a century later there is still no closed form, and it is not even proven in general that the sequence can always be continued.

This calculator generates the sequence exactly, term by term: value mode reports Q(n) with its neighbours and the running maximum, list mode shows the first terms with their average.

Worked examples

Q(100)

(0 - the value Q(n) · 100)

Hofstadter Q-sequence value Q(100)56
previous term Q(n - 1)54
next term Q(n + 1)48
largest value among the first n terms64

Q(1000)

(0 - the value Q(n) · 1000)

Hofstadter Q-sequence value Q(1,000)502
previous term Q(n - 1)499
next term Q(n + 1)533
largest value among the first n terms605

First 20 terms

(1 - the first n terms · 20)

first 20 terms of the Hofstadter Q sequence1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 6, 8, 8, 8, 10, 9, 10, 11, 11, 12
largest term shown12
last term shown, Q(n)12
average of the terms shown6.5

A chaotic recurrence

The Fibonacci recurrence adds the two previous terms. The Q recurrence does something stranger: it adds two earlier terms, but which two is decided by the values of the previous terms. Q(n - 1) and Q(n - 2) act as distances: from position n, reach back Q(n - 1) steps for one summand and Q(n - 2) steps for the other. The sequence is constantly consulting itself about where to look next.

Sequences of this shape are called meta-Fibonacci recurrences, and the Q sequence is their most famous member. The self-consultation creates feedback: a large term makes the next look-backs long, which tends to pull in small old terms, which then shorten the look-backs, and so on. That feedback loop, not any randomness, generates the chaos - every term is exactly determined, yet the trajectory defies summarising.

  • Q(1) = Q(2) = 1
  • Q(n) = Q(n - Q(n - 1)) + Q(n - Q(n - 2))
  • Look-back distances are the sequence's own values
  • A meta-Fibonacci recurrence - the index arithmetic is self-referential

The first terms

The opening is deceptively calm: 1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 6, 8, 8, 8, 10 - a staircase with a steady rhythm, growing by roughly one every two steps. Then term 16 is 9, a step backwards. Nothing in the staircase pattern warned of it; the look-back arithmetic simply reached somewhere unexpected. From there the sequence continues 10, 11, 11, 12, apparently calm again, but the stumble at 16 is the signature of everything that follows.

List mode reports the largest term, the last term and the average of the terms shown. The average is a useful fingerprint: since terms hover near half their index, the average of the first n terms sits near n / 4, and watching it as you extend the list shows the hovering in aggregate even while individual terms jitter.

  • First 20: 1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 6, 8, 8, 8, 10, 9, 10, 11, 11, 12
  • The drop at term 16: 10 falls to 9
  • Early terms mimic tame sequences - then deviate
  • List mode reports the average, close to n / 4 over the first n terms

Values further out

At n = 100 the sequence gives Q(100) = 56 - near 50, but 6 above it. At n = 500, Q(500) = 257. At n = 1000, Q(1000) = 502, almost exactly n / 2. Value mode reports each with its neighbours and the largest value among the first n terms, so you can see both the local jitter and the running extremes. The excursions matter: the maximum over the first n terms regularly overshoots n / 2 by a wide margin during turbulent generations, then the sequence settles again.

Researchers describe the trajectory as generations - stretches of relative order punctuated by chaotic bursts. The pattern is robust enough to recognise and too irregular to prove much about. It is a humbling object: a three-line definition, fully deterministic, that has resisted complete analysis since 1979.

  • Q(100) = 56, Q(500) = 257, Q(1000) = 502
  • Terms hover near n / 2 with unpredictable excursions
  • Generations of terms alternate calm and turbulence
  • No closed form and no proven growth law

What is not known

The deepest open question is embarrassingly basic: does the sequence even go on forever? A term Q(n) needs Q(n - Q(n - 1)) to refer to an existing earlier term, and if some Q value ever exceeded its position, the recurrence would ask for Q(0) or worse and break. It has never happened in the ranges computed - millions of terms - but there is no proof it cannot. The calculator generates the standard sequence as far as its limits allow, on the empirical evidence that the look-backs stay in range.

Hofstadter placed the sequence in Godel, Escher, Bach among dialogues and canons about self-reference, as mathematics' version of a sentence that talks about itself. The Q sequence talks about itself so literally that its own future is still an open question - which is exactly why it remains the canonical example of how much mystery a tiny recurrence can hold.

  • Not proven that Q(n) is always well-defined
  • A look-back could in principle reach position 0 or beyond
  • In practice it continues for millions of computed terms
  • Sits in Godel, Escher, Bach as an emblem of self-reference

Studying the chaos

Because proof has failed, the Q sequence is studied experimentally. Plot Q(n) against n and the eye picks out structure the theorems cannot yet touch: long ramps where the sequence climbs almost linearly with slope near 1/2, sudden collapses, and what researchers call generations - epochs in which the terms stay within a band around n/2, separated by turbulent transitions. The calculator's largest-among-first-n output gives a cheap probe of those excursions: run value mode at increasing n and watch the running maximum lurch ahead of n/2 during turbulent stretches.

A second probe is the average in list mode: over calm generations the average of the first n terms sits close to n/4, and deviations flag the turbulent ones. These statistics are how the sequence is actually researched - as data. Papers on the Q sequence are full of computed plots and conjectures fitted to them, a style of mathematics closer to astronomy than to algebra, forced by the object's refusal to yield to direct proof.

The Q sequence also has siblings - Hofstadter's other lettered sequences and the Conway's subprime fibonacci and other meta-Fibonacci families catalogued in the OEIS - some of which are provably well-behaved. The family portrait is the lesson: tiny changes to a self-referential recurrence move it across the order-chaos border. Golomb's sequence, elsewhere on this site, sits on the order side; the Q sequence is the famous resident of the chaos side.

  • Studied experimentally: generations, ramps, collapses
  • Running maximum and term average as chaos probes
  • Research style is data-driven - plots and conjectures
  • Meta-Fibonacci family spans the order-chaos border

Worked checks and pitfalls

Hand-check the recurrence at a small index to fix the definition. Q(6): the previous terms are Q(5) = 3 and Q(4) = 3, so Q(6) = Q(6 - 3) + Q(6 - 3) = Q(3) + Q(3) = 2 + 2 = 4. Correct. Q(11): Q(10) = 6 and Q(9) = 6, so Q(11) = Q(5) + Q(5) = 3 + 3 = 6. Correct. The double look-back with both distances occasionally equal is characteristic - the sequence often adds a term to itself.

Pitfalls: several Hofstadter sequences share initials and similar recurrences - the Q sequence is the one from Godel, Escher, Bach with seeds 1, 1 and the two-sided look-back above; Conway's subprime fibonacci and Hofstadter's G-sequence are different objects with tamer behaviour. And any implementation must generate strictly in order with the full history retained: the look-backs can reach arbitrarily far back, so windowed or approximate generation silently corrupts later terms. This calculator keeps the whole table, which is why its values can be trusted to the stated limits.

  • Q(6) = 4 and Q(11) = 6 by hand
  • Both look-backs can land on the same term
  • Not the G-sequence or subprime fibonacci
  • Full history required - no windowed shortcuts

A note on computation limits

Computing Q(n) is cheap per term and unforgiving in aggregate: every term needs two look-backs into a table that must be kept whole, and there is no shortcut, no formula and no periodicity to exploit. The calculator generates sequentially to its stated limits, which are set by that honesty - a million terms is a million iterations, each trivial, none skippable. Researchers who have pushed the sequence furthest use exactly this method with bigger budgets. If a tool claims Q values at large n instantly from a closed form, it is claiming something mathematics does not currently possess.

  • Sequential generation, full table, no shortcuts
  • No closed form exists to exploit
  • Instant large-n claims should be doubted

FAQs

What is the Hofstadter Q sequence?

The self-referential sequence Q(n) = Q(n - Q(n - 1)) + Q(n - Q(n - 2)) with Q(1) = Q(2) = 1, introduced by Douglas Hofstadter in Godel, Escher, Bach (1979).

What is Q(100)?

56.

What is Q(1000)?

502 - remarkably close to half of 1000, where the sequence spends most of its time.

Does the Q sequence always increase?

No. It mostly climbs, but it stumbles - the 16th term drops from 10 to 9, and such drops recur unpredictably.

Who invented the Q sequence?

Douglas Hofstadter, in his 1979 book Godel, Escher, Bach: An Eternal Golden Braid.

Is there a formula for Q(n)?

No closed form is known. The terms hover near n / 2, but their exact behaviour has resisted proof for over four decades.

Sources

Related calculators

Aliquot Sequence Calculator
Trace an aliquot sequence to its fate: termination at 0, a perfect fixed point, or an amicable or sociable cycle.
Arithmetic Sequence Calculator
The nth term and the sum of the first n terms of an arithmetic sequence from the first term and common difference.
Euclid-Mullin Sequence Calculator
Euclid-Mullin sequence terms: each is the smallest prime factor of one plus the product of all previous terms.