JOVANA
Explore Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
All guides

Arbitrary Precision and Canonical Forms

Exact computing rests on two pillars: numbers that never round, and a way to recognise when two messy expressions are secretly the same. Meet arbitrary-precision arithmetic and canonical forms — and the surprisingly deep difficulty of deciding equality.

Numbers that refuse to round

The previous guide drew the line between exact symbolic and approximate numeric computation: the numeric world lives on a finite floating-point grid where 0.1 has no exact binary form and every operation costs a small relative rounding error, while the symbolic world insists on giving the answer exactly. But exactness needs a foundation. If a computer algebra system is going to claim that an answer is correct to the last digit, it cannot store its numbers in a 64-bit box. It needs numbers that grow as large as the truth demands.

Arbitrary-precision arithmetic is the answer. Instead of a fixed-width integer, the system stores a whole number as a list of machine words — as many as it takes. The integer 2^1000 is roughly 302 decimal digits long; a computer algebra system holds every one of those digits, not a rounded approximation. Adding, multiplying, and dividing such numbers is done with the same grade-school algorithms you learned by hand, just carried out on chunks of digits, so the cost grows with the size of the numbers rather than staying fixed at one machine operation.

Exact fractions, no rounding allowed

Big integers are the building block; exact rational arithmetic is what you build on top. A rational number is stored as a pair of arbitrary-precision integers, a numerator and a denominator, and every operation keeps that pair exact. So 1/3 is the pair (1, 3) — not the floating-point ghost 0.3333333333333333 that the numeric world is stuck with. Add 1/3 + 1/6 and you get exactly 1/2, where floating point would leave a faint smudge of error in the last bit.

There is a hidden cost, and it teaches the central tension of the whole subject. To keep fractions in lowest terms after every step, the system must divide numerator and denominator by their greatest common divisor, which is exactly the GCD computation you will meet in detail in the next guide (for integers it is the ordinary Euclidean algorithm). Skip that reduction and a long chain of additions produces fractions whose numerators and denominators balloon into thousands of digits even when the final answer is something tidy like 2/3. Exactness is bought with ever-growing storage — the first quiet sign of the expression swell that haunts this whole rung.

When are two expressions the same?

Exact numbers solve half the problem. The harder half is that symbolic answers are expressions, and the same value can wear a thousand disguises. Is (x + 1)^2 the same thing as x^2 + 2x + 1? Of course — but to the computer one is a squared sum and the other is a sum of three terms; the trees in memory look nothing alike. Is sin(x)^2 + cos(x)^2 equal to 1? Yes, but only if the system knows a trigonometric identity. The basic question "are these two expressions equal?" turns out to sit at the heart of computer algebra.

The elegant escape is a canonical form: a single, agreed-upon way to write every member of a family of equal expressions. If the system rewrites every polynomial as a sum of terms in descending degree with combined like terms — so (x + 1)^2 becomes x^2 + 2x + 1, and x^2 + 2x + 1 stays put — then two polynomials are equal exactly when their canonical forms are identical, character for character. Deciding equality collapses into a simple comparison. The whole craft of symbolic simplification is, in large part, the craft of dragging expressions into a canonical form.

expression           canonical polynomial form
-----------           -------------------------
(x + 1)^2          -> x^2 + 2 x + 1
x^2 + 2 x + 1      -> x^2 + 2 x + 1      (already canonical)
(x + 1)(x - 1)     -> x^2 - 1

equal?  compare canonical forms term by term:
   x^2 + 2 x + 1   ==   x^2 + 2 x + 1     ->  YES, identical
   x^2 + 2 x + 1   ==   x^2 - 1           ->  NO, differ in two terms
A canonical form makes equality a character-for-character comparison — once both sides are rewritten the same standard way.

Why a perfect canonical form is impossible

Here is the honest, humbling truth that beginners are rarely told: for rich enough expressions, no canonical form can exist at all. Polynomials are tame, but once you allow exponentials, logarithms, absolute values, and the constant pi mixed freely, a famous result (Richardson's theorem) proves that deciding whether such an expression is identically zero is undecidable — no algorithm can always answer correctly in finite time. So the dream of a universal "simplify to canonical form" button is mathematically unreachable, not merely unimplemented.

This is why every computer algebra system makes a pragmatic compromise. It carries canonical forms for the families where one provably exists — integers, rationals, polynomials, rational functions — and falls back on a toolbox of normal forms and rewrite rules for everything wilder. A normal form guarantees that anything truly zero is reported as zero (so you never get a false "nonzero"), but it may sometimes fail to recognise that two equal things are equal. Knowing which guarantee you actually have is the difference between trusting a `simplify` result and being quietly misled by it.

Putting it together: how an answer stays exact

Watch the two pillars cooperate in a single small calculation. Suppose you ask a system to add the fractions 1/2, 1/3, and 1/6 and confirm the result is 1. Behind the scenes the arbitrary-precision integers carry the numerators and denominators with no rounding, the GCD-based reduction keeps each intermediate fraction in lowest terms, and a canonical form lets the final 6/6 be recognised as the integer 1 rather than left as a fraction. No step ever approximates; the exactness is end to end.

  1. Store each input exactly: 1/2, 1/3, 1/6 become pairs of arbitrary-precision integers — no 0.5, 0.333..., 0.166... in sight.
  2. Add over a common denominator: 3/6 + 2/6 + 1/6 = 6/6, all arithmetic done on exact integers.
  3. Reduce with the GCD: gcd(6, 6) = 6, so 6/6 collapses to 1/1.
  4. Apply the canonical form: a rational with denominator 1 is written as the plain integer 1, so equality with 1 is now a trivial character match.

Two threads run from here into the rest of the rung. The reduction step in the middle is the GCD, and the next guide widens it from integers to whole polynomials and then to systems of them with Groebner bases. And every time you saw a fraction "balloon" before reduction, you saw a hint of expression swell — the relentless growth of exact intermediate results that, more than any clever trick, decides where symbolic computation can and cannot go. Exactness is a beautiful guarantee; its bill comes due in storage and time.