ForHosting KIT · Math

Imaginary quadratic class number calculator

Enter a squarefree d and get the exact class number of Q(√−d): for 23 the discriminant is −23 and the class number is 3, while 1 gives the Gaussian rationals, with class number 1. 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
D
23
You get
Discriminant
-23
Class number
3

This imaginary quadratic class number calculator takes a positive squarefree integer d and computes the class number of the field Q(sqrt(-d)). It first selects the field's fundamental discriminant, then deterministically counts the reduced primitive positive definite binary quadratic forms of that discriminant. The result is exact, reproducible, and accompanied by the discriminant used, making it suitable for checking number theory exercises, tables, and computational experiments without relying on a remote database.

From a squarefree radicand to a field discriminant

The input d identifies the imaginary quadratic field Q(sqrt(-d)), but the discriminant used for binary quadratic forms is not always simply -d. When d is congruent to 3 modulo 4, the fundamental discriminant is -d; in every other squarefree case it is -4d. That distinction is essential because form classes are organized by discriminant, and using the wrong one can count an order inside the field rather than the full ring of integers.

The calculator applies this rule automatically and returns the selected discriminant beside the class number, so the arithmetic convention is visible rather than hidden. The input must be a positive squarefree integer: no prime square may divide it. For example, 5 is squarefree, while 12 is not because 4 divides it.

Rejecting nonsquarefree inputs keeps the meaning unambiguous, since different radicands can otherwise describe the same quadratic field and would obscure which fundamental discriminant should govern the count. Inputs are also bounded to keep browser execution quick and predictable.

How reduced forms give the class number

For a negative fundamental discriminant D, the ideal class group of the imaginary quadratic field corresponds to equivalence classes of primitive positive definite integral binary quadratic forms ax^2+bxy+cy^2 with b^2-4ac=D. Every class has one reduced representative when the usual boundary convention is enforced. The algorithm enumerates integers a and b in finite bounds, derives c from the discriminant equation, and retains exactly the forms satisfying |b| less than or equal to a less than or equal to c.

On a boundary where |b|=a or a=c, it keeps only nonnegative b, preventing two equivalent boundary representatives from being counted twice. It also verifies gcd(a,b,c)=1, making primitivity explicit. The bound a less than or equal to sqrt(|D|/3) proves that the search terminates.

Counting the surviving representatives therefore produces the class number directly. No numerical approximation, random sampling, online table, or unproved heuristic enters the result; all tests use exact safe-integer arithmetic within the published input limit.

Check a number theory exercise

Verify a hand enumeration of reduced positive definite forms for a specified imaginary quadratic field.

Test an independent implementation

Compare deterministic results against code based on ideals, analytic formulas, or another reduced-form convention.

What inputs are accepted?

A positive squarefree integer d from 1 through 1,000,000,000.

Why must d be squarefree?

Squarefree d gives a canonical radicand for the field and lets the calculator select its fundamental discriminant without duplicate field descriptions.

Which discriminant is used?

It uses -d when d is 3 modulo 4 and -4d otherwise.

What exactly is being counted?

Primitive reduced positive definite integral binary quadratic forms of the field's fundamental discriminant, with the standard boundary convention.

Is the result approximate?

No. The finite enumeration and all divisibility tests are deterministic exact integer operations within the input limit.

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/class-number-imaginary

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/class-number-imaginary \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"d":23}'
{
  "d": 23
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.class_number_imaginary",
  "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.

max_d1000000000
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.

Reading and checking the result

A class number of one means every fractional ideal is principal; larger values measure the failure of unique factorization of ideals into principal generators, not a failure of unique factorization of ideals themselves. Its strength is transparent, deterministic counting for moderate inputs. The response contains the accepted radicand d, the fundamental discriminant, and class_number, the number of reduced form classes found. Familiar checks include d=1, whose field is the Gaussian rationals and has class number one, and d=23, whose discriminant is -23 and class number is three. These small cases are useful when testing a textbook derivation or a separate implementation. For research-scale computations, remember that this endpoint deliberately uses direct reduced-form enumeration rather than faster analytic or subexponential class-group methods. The API price is $0.002 per request, while the browser version runs the same pure calculation locally.

Build a small class-number table

Run squarefree radicands through a reproducible API and retain both the field discriminant and exact count.

What does an API call cost?

Each API request costs $0.002; the browser calculator runs locally for free.

Read the full KIT documentation →