ForHosting KIT · Math

Pierce expansion calculator

Enter a fraction between 0 and 1 and get its exact Pierce digits: 2/3 gives 1 and 3, because 1/1 − 1/(1·3) rebuilds two thirds. Each result shows the alternating series and its decimal value. 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
Power (W)
2
Q
3
You get
Value
0.6666666667
Fraction
2/3
Reduced p
2
Reduced q
3

The Pierce expansion of a real number strictly between zero and one is the unique strictly increasing sequence of positive integers that rebuilds the value as an alternating sum of unit products: one over a1, minus one over a1 times a2, plus one over a1 times a2 times a3, and so on. Every rational in the open unit interval has a finite Pierce series, so homework checks, contest graders, and number-theory notebooks can pin an exact digit list without floating truncation parameters. This Pierce expansion calculator accepts numerator p and non-zero denominator q, requires the reduced fraction to satisfy zero less than p over q less than one, and returns the complete digit sequence together with a readable expansion string and a reconstructed decimal value.

What a Pierce expansion is and how the digits are built

A Pierce expansion, also called an alternated Egyptian product, writes a number x in the open unit interval as x equals one over a1 minus one over the product a1 a2 plus one over a1 a2 a3 minus the next product term, continuing with strictly increasing positive integers a1 less than a2 less than a3 and so on. The construction is dual in spirit to the better-known Engel expansion: Engel uses only positive unit products, while Pierce alternates the sign of each successive product term.

The classical algorithm starts from the fraction itself, sets the next digit to the floor of one over the current remainder, then replaces the remainder by one minus that digit times the remainder, and repeats until the remainder is exactly zero.

A short textbook check is two thirds: floor of three halves is one, the remainder is one third, floor of three is three, and the remainder vanishes, so the Pierce digits are one and three, and the series one over one minus one over one times three rebuilds two thirds exactly. Another check is one half: a single digit two recovers the fraction as one over two.

Because each new digit is forced to be strictly larger than the previous one by the remainder map, the sequence never plateaus, and the length of the expansion for a reduced fraction p over q is bounded in theory by classical results of Erdős, Shallit, and later authors—practical homework fractions finish in a handful of integer steps.

Classroom Pierce series checks

Let students submit p and q for a fraction in (0,1) and verify the strictly increasing Pierce digits against hand-worked floor(1/x) remainder steps.

Exam and LMS auto-grading

Mark alternated Egyptian product items with a deterministic oracle that rejects fractions outside (0,1) and never invents extra terms for a rational.

Notebooks comparing series expansions

Compute Pierce digits beside Engel or continued-fraction expansions of the same rational without importing a full computer-algebra library.

What is a Pierce expansion of a fraction?

It is the unique strictly increasing sequence of positive integers a1<a2<… such that the fraction equals 1/a1 − 1/(a1·a2) + 1/(a1·a2·a3) − … (alternated Egyptian product). Every rational in (0,1) has a finite expansion.

Which fractions does the calculator accept?

Integer numerator p and non-zero denominator q with 0 < p/q < 1 after sign normalization.

How are the Pierce digits computed?

Set a = floor(1/x) for the current remainder x, replace x by 1 − a·x, and repeat until the remainder is zero. All steps use exact integer arithmetic on the reduced fraction.

How does Pierce expansion differ from Engel expansion?

Engel expansion uses only positive unit products with non-decreasing digits. Pierce alternates the sign of each successive product term and forces strictly increasing digits a1<a2<a3<….

What is the Pierce expansion of 1/2?

It is a single digit, 2, because one over two already equals the fraction. Longer fractions need more digits, each strictly larger than the one before, until the remainder reaches exactly zero.

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/pierce-expansion

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/pierce-expansion \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"p":2,"q":3}'
{
  "p": 2,
  "q": 3
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.pierce_expansion",
  "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.

Fractions outside that open interval, zero denominators, and non-integers fail with invalid_input instead of inventing terms.

What a Pierce expansion is and how the digits are built

For every rational the process terminates after finitely many steps; for irrationals it would continue forever, which is why this endpoint accepts an exact integer ratio rather than a float approximation.

Input contract, response fields, and error behaviour

Absolute values must stay inside the JavaScript safe-integer range so every intermediate product and remainder stays exact. Example: p equals two and q equals three yields terms one and three, expansion one over one minus one over one times three, and value two thirds. Example: p equals three and q equals seven yields a short alternating product you can rebuild by hand. POST a JSON body with two required finite integers: p, the numerator, and q, the non-zero denominator. Each field may arrive as a JSON number or as a digit string with an optional leading sign; non-integers, missing fields, and empty strings fail with invalid_input naming the field. On success the body echoes the original p and q, a fraction string, reduced_p and reduced_q after cancelling the greatest common divisor, the terms array of Pierce digits in order, length equal to that array size, an expansion string that writes the alternating unit products with middle dots in the denominators, a value field equal to the series sum rounded to fifteen decimal places for stable comparisons, and a short formula string restating the Pierce identity. Pair the digits with your own convergent or error-sum code if you need deeper metric theory; this endpoint expands the rational only.

Where a Pierce expansion calculator earns its keep

Classrooms and tutoring platforms use a Pierce expansion calculator so learners can check alternated Egyptian products for arbitrary fractions in the open unit interval without sign or floor errors. Failed validation does not consume balance. Contest and exam generators need a deterministic oracle that marks wrong digit sequences and that rejects fractions outside zero one instead of returning an empty success payload a buggy grader might treat as correct. Number-theory notebooks comparing Engel series, Sylvester series, and Pierce series on the same rational need a tiny pure API that never pulls a full computer-algebra system for a two-integer problem.

What does the Pierce expansion 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 →