Reduced binary quadratic forms
Lists the reduced primitive positive-definite forms ax² + bxy + cy² for a negative discriminant; −23 gives three forms, [1, 1, 6], [2, −1, 3] and [2, 1, 3], so its class number is 3. Exact whole-number arithmetic only. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Discriminant
- -23
- Quantity
- 3
This reduced binary quadratic forms calculator lists the canonical reduced representatives of primitive positive-definite integral forms with a chosen negative discriminant. Enter a valid discriminant and receive every coefficient triple [a, b, c], together with a count and the discriminant echoed in the result. The calculation is exact, deterministic, and performed with integer arithmetic. It is useful for checking class-number examples, preparing exercises, exploring equivalence classes, and validating hand calculations without relying on a symbolic algebra installation or a remote mathematical database.
What the calculator lists
A binary quadratic form is an expression ax² + bxy + cy² with integer coefficients. Its discriminant is D = b² − 4ac. When D is negative and a is positive, the form is positive definite, so it takes positive values away from the origin.
This calculator returns primitive forms, meaning gcd(a, b, c) = 1, and chooses reduced representatives satisfying |b| ≤ a ≤ c. On boundary cases it applies the conventional sign rule b ≥ 0 when |b| = a or a = c. Those inequalities make the result finite and provide a standard representative from each proper equivalence class.
Each result is shown both as separate numeric coefficients and in compact [a, b, c] notation. The reported count is therefore the number of reduced primitive forms found for the supplied discriminant, which is also the class number for primitive positive-definite forms under the usual proper equivalence convention.
Choosing and validating a discriminant
Enter a negative integer congruent to 0 or 1 modulo 4. That congruence is necessary because b² is always 0 or 1 modulo 4, so no integral coefficients can satisfy b² − 4ac = D for the other residue classes. For example, −23 is valid because it is 1 modulo 4, while −22 is not a quadratic discriminant.
The calculator rejects zero, positive values, unsafe or fractional numbers, and values outside its published bound. A valid discriminant need not be fundamental: the primitive-form filter still applies, and valid nonfundamental discriminants can be explored. However, some negative discriminants admit no primitive forms because a common square factor forces every coefficient triple to be imprimitive; in that case the calculator returns an empty list and a count of zero rather than treating the input as malformed.
How enumeration stays exact and reproducible
The algorithm follows directly from reduction theory. For a reduced positive-definite form, the inequalities imply a ≤ √(|D|/3), which gives a finite upper bound for the outer loop. For each possible a, the calculator tests integers b between −a and a, observes the required parity, and computes c from (b² − D)/(4a).
A candidate is retained only when c is integral, a ≤ c, the boundary sign convention holds, and the three coefficients have greatest common divisor one. No floating-point approximation is used to decide whether a candidate is a form; the only square root establishes a safe integer loop bound, while every membership test uses exact safe-integer arithmetic. Results are ordered first by increasing a and then by increasing b, making repeated calls byte-for-byte predictable.
What you can do with it
Check a class-number exercise
Compare a hand-derived list of reduced forms with a complete, consistently ordered enumeration.
Explore discriminants
Inspect how coefficient triples and form counts change across fundamental and nonfundamental negative discriminants.
FAQ
What inputs are valid?
Use a negative integer congruent to 0 or 1 modulo 4 and within the published range.
What does primitive mean?
A form [a, b, c] is primitive when the greatest common divisor of all three coefficients is one.
What does reduced mean here?
The output satisfies |b| ≤ a ≤ c, with b nonnegative when either boundary equality occurs.
Are equivalent duplicates included?
No. The reduction conditions select one representative for each proper equivalence class.
Can a valid discriminant return no forms?
Yes. A valid nonfundamental discriminant can have no primitive representatives; that produces an empty list, not an error.
Related tools
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/numth/reduced-binary-forms \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"discriminant":-23}'const res = await fetch("https://api.kit.forhosting.com/numth/reduced-binary-forms", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"discriminant": -23
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/reduced-binary-forms",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"discriminant": -23
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/reduced-binary-forms", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"discriminant":-23}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"discriminant":-23}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/reduced-binary-forms", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"discriminant": -23
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.reduced_binary_forms",
"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
min_discriminant | -10000000 |
max_discriminant | -3 |
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. |
Technical notes
Choosing and validating a discriminant
It also accepts the short alias d when calling the API, although discriminant is the clearest field name for saved code.
How enumeration stays exact and reproducible
The calculation uses no network, random source, clock, database, or hidden table, so it works equally in the browser and through the API for $0.002 per request.
Integration use cases
Build exact test fixtures
Generate deterministic reduced-form data for number-theory lessons, scripts, and regression tests.
Technical questions
What does it cost?
It runs free in the browser on this page, or costs $0.002 per API request.