Egyptian fraction calculator
The Egyptian fraction calculator takes a numerator and a denominator and rewrites the fraction the way ancient Egyptian scribes did: as a sum of distinct unit fractions such as 1/2 + 1/4.
Run — free
It uses the greedy Fibonacci–Sylvester algorithm, which is guaranteed to terminate and always yields different denominators. Send two positive integers, receive the expansion, the number of terms and the whole part when the fraction is improper. The same code runs free in your browser on this page and costs $0.002 per request when you call the API.
What an Egyptian fraction is and why it still matters
Ancient Egyptian mathematics avoided general fractions almost entirely. Instead of writing 3/4, a scribe would record 1/2 + 1/4: a sum of unit fractions, each with numerator one and all denominators distinct. The Rhind papyrus opens with a long table doing exactly this for fractions of the form 2/n, because tables of unit fraction expansions were the everyday calculation tool of the time. Today the idea is more than a curiosity. Unit fraction expansions appear in number theory, in fair division problems, in teaching about fraction equivalence, and in recreational mathematics. The egyptian fraction calculator reproduces that decomposition instantly for any positive rational you give it. You supply a numerator and a denominator, both positive integers, and the endpoint returns the list of distinct denominators, the expansion written out as a sum, the term count, and a separate whole part when the fraction is greater than one. The fraction is first reduced to lowest terms so the expansion is canonical: 2/4 and 3/6 both expand as 1/2, which keeps results stable and comparable regardless of how the input was written.
How the greedy algorithm builds the expansion
The engine uses the greedy method often attributed to Fibonacci and studied by Sylvester. At each step it takes the largest unit fraction not exceeding what remains: if the remainder is n/d, the next term is 1/ceil(d/n). Subtracting that term leaves n*ceil(d/n) − d over d*ceil(d/n), and the new numerator is strictly smaller than the old one, so the process always terminates in at most n steps. A pleasant side effect is that every chosen denominator is larger than the previous one, so distinctness is guaranteed by construction rather than checked afterwards. The implementation works over arbitrary-precision integers, so values up to one trillion are handled exactly, with no floating point rounding anywhere in the computation. There is a declared ceiling on the number of terms, and inputs that would exceed it are rejected with a clear error instead of running unbounded. Because the expansion is deterministic, the same input always returns byte-identical output, which makes the endpoint safe to cache and to embed in pipelines that compare results.
Reading the output and handling edge cases
The response gives you the reduced expansion plus the original inputs echoed back, so a client can log exactly what was decomposed. The field unit_fractions holds the denominators in increasing order, expansion renders them as a human-readable sum like 1/2 + 1/11 + 1/111 + 1/1221, and count is simply the number of terms. When the fraction is improper, the integer part is returned separately in whole and the unit fractions expand only the fractional remainder, because classical Egyptian notation kept whole numbers outside the sum. Validation is strict on purpose: the denominator zero is rejected, non-integer values such as 2.5 or 1/2 as a string are rejected, and negative inputs are rejected, each with a message naming the offending field. Calling the API costs $0.002 per request, and the identical algorithm runs free in the browser widget on this page, so you can explore interactively and only pay when you automate. Everything is computed on demand and nothing you send is stored after the response is produced.
What you can do with it
Teach fraction equivalence
Show students that one rational number has many faces by expanding 5/6 as 1/2 + 1/3 and comparing it with other representations.
Reproduce historical mathematics
Check Rhind papyrus style decompositions of 2/n against a deterministic greedy baseline without building the tables by hand.
Generate puzzle and worksheet material
Produce unit fraction sums programmatically for math competitions, worksheets or game content, with a stable output you can diff.
FAQ
What does it cost?
$0.002 per request via the API. The same algorithm also runs free in your browser on this page.
Which inputs are accepted?
Two positive integers: a numerator and a denominator. Zero denominators, negatives, decimals and non-numeric values are rejected with a clear error.
Does the expansion always terminate?
Yes. The greedy algorithm strictly reduces the remaining numerator at each step, so it always finishes, and every denominator it emits is distinct.
What happens with fractions greater than one?
The whole part is returned separately in the whole field and the unit fractions expand only the fractional remainder, following classical Egyptian notation.
Is the fraction simplified first?
Yes. The input is reduced to lowest terms before expanding, so equivalent fractions always produce the same expansion.
Is anything stored?
No. The computation is done in memory and only the expansion is returned; your inputs are discarded.
For developers — API access
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.
API endpoint
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.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/egyptian-fraction \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"numerator":5,"denominator":6}'const res = await fetch("https://api.kit.forhosting.com/math/egyptian-fraction", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"numerator": 5,
"denominator": 6
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/egyptian-fraction",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"numerator": 5,
"denominator": 6
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/egyptian-fraction", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"numerator":5,"denominator":6}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"numerator":5,"denominator":6}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/egyptian-fraction", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"numerator": 5,
"denominator": 6
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.egyptian_fraction",
"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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_value | 1000000000000 |
max_terms | 1000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |