ForHosting KIT · Math

Calkin–Wilf sequence term

Term 5 of the Calkin-Wilf sequence is 3/2, reached from the root 1/1 by one step left and one step right. Enter a position from 1 to one billion to get the reduced fraction and its path. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
N
5
You get
Numerator
3
Denominator
2
Fraction
3/2
Path
LR

The Calkin–Wilf tree is a complete binary tree whose nodes are exactly the positive rational numbers, each appearing once in lowest terms. Reading the tree level by level (or indexing nodes in the natural breadth-first order that matches the binary path of a positive integer n) yields a famous enumeration of Q+: the Calkin–Wilf sequence. Index one is the root fraction one over one; every later index follows a unique left-right path encoded by the binary digits of n after the leading one-bit. Students of enumerative combinatorics, discrete mathematics, and rational reconstruction need a fast oracle that returns numerator and denominator for an arbitrary safe index without building the whole tree. This capability accepts a positive integer n, walks that path with a handful of integer additions, and returns the reduced fraction a/b together with a path string and a short formula.

What the Calkin–Wilf enumeration is and how the n-th fraction is defined

Neil Calkin and Herbert Wilf popularized a remarkably simple binary tree of positive rationals: the root is one over one; the left child of a fraction a over b is a over (a plus b); the right child is (a plus b) over b. Every positive rational appears exactly once, already in lowest terms, so the tree is both an enumeration of Q+ and a canonical reduced form for each value.

Equivalently, write n in binary, drop the leading one-bit that always marks the root, and interpret each remaining bit from most significant to least as a move: zero means left, one means right. After those moves you hold the unique reduced fraction a/b at that node. A classical identity links this walk to Stern's diatomic sequence s: the Calkin–Wilf fraction at index n is s(n) over s(n plus one).

Because each step only adds two positive integers, the algorithm is deterministic, allocation-light, and free of floating-point rounding—ideal for homework oracles, LMS plugins, and research notebooks that need exact numerators and denominators rather than approximate decimals.

What you enter and what you get back

Values below one—including zero and every negative index—fail with a clear message that the Calkin–Wilf index must be at least one; those validation failures are not billed. On success the body echoes n, provides numerator and denominator as positive integers, fraction as the display string numerator slash denominator, formula as a short restatement of the root and child rules plus the binary-path rule, and path as the letters L and R for the moves after the root (or the word root when n equals one).

Example: n equals one yields fraction one slash one and path root. Example: n equals five has binary one zero one, path bits zero then one, so left then right from one over one gives three over two, path LR. Example: n equals seven has path RR and fraction three over one.

Clients that only need the rational can read fraction or the integer pair; tutors can show path next to the answer so students audit each left and right step.

Where the Calkin–Wilf term comes in handy

Research notebooks that explore hyperbinary representations, Minkowski question-mark function demos, or rational sampling strategies often need a quick exact oracle for the n-th Calkin–Wilf fraction while keeping results reduced by construction. Engineering and education tools that generate unique positive test rationals for property-based tests can pull successive terms by index instead of inventing random unreduced pairs that later need gcd cleanup. Keep requests small, document that n is a positive integer starting at one, and treat numerator, denominator, and fraction as the canonical answer fields for automated checks.

Classroom and homework checks

Let students submit a positive index n and verify the Calkin–Wilf fraction a/b against the left/right child rules, with the path string shown for partial credit.

LMS and exam auto-grading

Mark Calkin–Wilf enumeration items with a deterministic oracle that rejects n below one and never invents unreduced or duplicate rationals.

Unique positive test rationals

Generate a stream of distinct reduced positive rationals by index for property-based tests without calling gcd on random pairs.

How do I get the n-th Calkin–Wilf fraction?

Send a positive integer n (n ≥ 1).

What happens if n is zero or negative?

The Calkin–Wilf index used here is a positive integer starting at one; values below one are rejected and not billed.

Is the returned fraction always reduced?

Yes. Every node of the Calkin–Wilf tree is already in lowest terms, so numerator and denominator are coprime for every valid n.

How is this different from the Stern–Brocot sequence?

Stern’s diatomic sequence returns a single integer s(n). The Calkin–Wilf term is the rational s(n)/s(n+1) (equivalently the tree walk above). Search intent and output shape differ: fraction versus diatomic value.

What does the path of L and R letters mean?

Write n in binary and drop the leading 1; each remaining 0 is a step left and each 1 a step right from the root. For position 5, binary 101 leaves the digits 0 and 1, so the path is LR and ends at 3/2.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/numth/calkin-wilf-term

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/numth/calkin-wilf-term \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":5}'
{
  "n": 5
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.calkin_wilf_term",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Indices below one are rejected with invalid_input so graders and scripts never treat zero or negative positions as valid sequence terms.

What the Calkin–Wilf enumeration is and how the n-th fraction is defined

The natural 1-based index n labels nodes by their position in the complete binary heap order: n equals one is the root, n equals two is the left child of the root (one half), n equals three is the right child (two over one), n equals four is the left-left grandchild (one third), and so on. This endpoint implements the direct tree walk rather than a separate Stern table, but the answers match that identity for every positive n.

Input contract, response fields, and error behaviour

POST a JSON body with a single required field n: a positive integer greater than or equal to one, either as a JSON number or as a decimal digit string, at most one billion. The aliases index and order are accepted with the same meaning. Missing n, empty strings, non-integers, non-finite numbers, and values above the maximum fail with invalid_input naming the problem.

Where a Calkin–Wilf term API earns its keep

Enumerative combinatorics and discrete-math courses use the Calkin–Wilf tree when teaching bijections between positive integers and positive rationals, continued-fraction connections, and comparisons with the Stern–Brocot tree; a tiny API lets LMS plugins check student answers for arbitrary n without shipping a full computer-algebra package. Because every successful call costs the published $0.002 base price with no model tokens and no outbound network, failed validation does not consume balance, and the algorithm is only O(log n) integer additions, you get reproducible fractions for homework, grading, and edge workers without standing up heavier number-theory infrastructure.

What does the Calkin–Wilf term calculator cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →