← LibrarySoftware Packages for Computational Number TheoryEngineering · MathematicsLesson 1/2← PrevNext →
GuidePublished 6 Aug 20264 min readBy Kevin JoginComputational Number TheoryResources & PolicyPARI/GPSageMath
Skip to the main content

MathematicsResources & Policy

Software Packages for Computational Number Theory

What to reach for, what each system is genuinely good at, and why implementing this layer yourself is almost always the wrong decision.

Executive summary

Use the library; verify across two of them

The algorithms in this knowledge stream are implemented, optimised and battle-tested in existing systems. Reimplementing them is justified for learning, for embedding in a constrained environment, or for genuinely novel research — and almost never otherwise. The more valuable discipline is cross-verification: computing an invariant in two independent systems catches errors that no single system will report, because the characteristic failure here is a plausible wrong answer rather than a crash.

Learning objectives

  • Select an appropriate system for a given class of computation.
  • Distinguish general systems from specialised arithmetic libraries.
  • Apply cross-verification as standard practice.
  • Record the conditionality attached to a computed result.

Section 01The main systems

Systems for algebraic number theory
SystemCharacterParticular strengthsConsiderations
PARI/GPSpecialised, open sourceNumber fields, class groups, units, elliptic curves; exceptionally fast for its domain; usable as the C library libpariDeliberately narrow scope; terse interface
SageMathIntegrating system, open sourcePython interface unifying PARI, FLINT, NTL, Singular and others; excellent for exploratory work and teachingLarge installation; some operations dispatch to a backend whose conventions differ
MagmaCommercialVery broad and deep algebraic coverage; often the reference implementation for advanced algorithmsLicence cost; closed source, so results cannot be independently audited
FLINTC library, open sourceFast polynomial and integer arithmetic; the arithmetic engine beneath several systemsA library, not a system — no interactive layer
GMPC library, open sourceThe reference multiprecision integer implementation; extensively hand-optimisedArithmetic only; no number-theoretic structures
NTLC++ library, open sourceLattice reduction, polynomial arithmetic over finite fieldsOverlaps with FLINT; choose by benchmark for the specific workload
Match the tool to the layer

For a class group, PARI/GP or Magma. For fast polynomial arithmetic inside a larger program, FLINT or NTL. For multiprecision integers alone, GMP. Using a full computer algebra system as an arithmetic library, or a bare arithmetic library for number field work, are both avoidable mismatches.

Section 02Cross-verification

The dominant failure mode in this subject is a well-formed wrong answer. Two independent systems agreeing is far stronger evidence than one system succeeding.

  1. Stage 01Compute in system ARecord the invariant, the exact input and any options set.
  2. Stage 02Compute in system BUse an independent implementation, ideally not sharing a backend — note that Sage frequently delegates to PARI, so that pair is not independent.
  3. Stage 03Compare invariantsClass number and structure, regulator to a stated precision, discriminant, unit rank, and the fundamental identity for prime decomposition.
  4. Stage 04Apply analytic checksVerify hR against the analytic class number formula, and check statistical agreement with the Cohen–Lenstra predictions across a family.
Convention mismatches masquerade as errors

Systems differ on the sign of the discriminant in some conventions, on whether the regulator includes a factor for the unit index, on row versus column Hermite normal form, and on proper versus improper equivalence of quadratic forms. A disagreement should prompt a convention check before an error report.

Section 03Recording a result

What to record with any computed invariant
FieldWhy
System and versionAlgorithms and defaults change between releases
Exact inputDefining polynomial, not just the field name
Options and boundsFactor base bound, precision, proof flags
ConditionalityWhether the result assumes GRH, and whether the discriminant was fully factored
Verification performedWhich independent checks were run and their outcome
PrecisionFor real quantities such as the regulator, the number of certified digits
Proof flags are not decorative

Several systems run class group computations under GRH by default and offer a certification option that is far slower. A result obtained with the default is conditional, and the flag setting must be recorded with it. Reporting such a value as unconditional is a factual error, not a stylistic one.

ReferenceFrequently asked questions

Should this layer ever be implemented from scratch?

For learning, yes — implementing LLL or Tonelli–Shanks teaches more than reading about them. For production, only when embedding in an environment where no library is available, or when the algorithm is genuinely new. Reimplementing a class group algorithm to use in research is a large project with a high probability of subtle error.

Are Sage and PARI independent for verification purposes?

Frequently not — Sage delegates much number field work to PARI, so agreement between them may reflect a single implementation. Genuine cross-verification requires systems with independent code paths, and checking which backend was used is part of the exercise.

How should precision be handled for real invariants?

Compute at increasing precision until successive results agree to the required number of digits, and record the certified precision alongside the value. A regulator quoted without its precision cannot be meaningfully compared with another computation.

NavigateContinue in this stream

Curated next steps from this page. The site also surfaces algorithmically related reading below.

ProvenanceSources and further reading

This page is an original KEVOS explanatory article. It presents the underlying mathematics — definitions, algorithms, complexity results and selection criteria — in KEVOS editorial voice. No text is reproduced from any copyrighted source. Where numerical tables are relevant, KEVOS links to live authoritative databases rather than republishing static values.

Page ID
KV-MATH-0057
Taxonomy
ENG-MATH — Engineering / Mathematics
Collection
COL-CANT-001
Topic stream
CANT-RESOURCES
Version
1.1.0 / content 2026.08
Last reviewed
2026-08-06

Continue learning

NEXT LESSON →Numerical Tables: KEVOS Sourcing PolicyGuide · MathematicsComputational Algebraic Number Theory: Discipline OverviewGuide · MathematicsMultiprecision Integer ArithmeticGuide · MathematicsModular Exponentiation and Powering AlgorithmsGuide · Mathematics