Canonical form
A canonical form is a representation chosen so that expressions that are mathematically equal have the same representation[3][2]. With canonical forms, deciding whether two expressions are equal is a structural comparison rather than a search for a proof, equal expressions hash to the same value, and results can be cached reliably. The most important consequence is the zero test: almost every algorithm in computer algebra branches on whether some quantity is zero, a pivot in elimination, a leading coefficient in division, a remainder in a gcd, and it can do so only if zero is recognizable. A normal form is the weaker requirement that everything equal to zero is represented by 0; for classes closed under subtraction the two notions coincide, since exactly when is zero[3]. Canonical forms exist for polynomials and rational functions, and for polynomials modulo an ideal via Gröbner bases, but Richardson's theorem shows that for sufficiently rich classes of expressions no algorithm can even decide equality with zero[1].
Definitions
Let be a class of expressions and the relation of denoting the same function or value. A canonical simplifier is a computable map with and
where the equality on the right is syntactic identity. A normal simplifier only guarantees . Caviness formalized both notions in 1970[3], and Moses surveyed the choices a computer algebra system faces between aggressive and conservative simplification[4].
Polynomials and rational functions
For polynomials over a field or the integers, the expanded form with like terms collected and terms sorted by a fixed monomial order is canonical. For rational functions, the quotient of two such polynomials with their gcd cancelled and the denominator normalized, for instance monic or with positive leading coefficient, is canonical. Expressions containing other functions are handled by treating their non-polynomial parts, such as , as new variables, called kernels.
Four ways of writing one polynomial, as expression trees and in canonical form.
open Expr(* Four ways of writing the same polynomial, and their canonical forms. *)
Running it.
(x + y)^2 tree (x + y)^2 canonical x^2 + 2·x·y + y^2x^2 + 2xy + y^2 tree (x^2 + 2*x*y + y^2) canonical x^2 + 2·x·y + y^2(y + x)(x + y) tree (y + x)*(x + y) canonical x^2 + 2·x·y + y^2x(x + 2y) + y^2 tree (x*(x + 2*y) + y^2) canonical x^2 + 2·x·y + y^2all canonical forms equal: true
The trees differ; the canonical forms are identical. The price of this canonical form is expansion, which can be exponentially larger than the input: expands into terms.
Relations between kernels
Treating and as independent variables makes the polynomial form canonical as a polynomial in them, but not as a function of : it does not know that . When the relations between kernels form a polynomial ideal, the remainder modulo a Gröbner basis of that ideal is canonical for the quotient ring[9].
Reducing polynomials in s = sin x and c = cos x modulo s² + c² − 1.
(* With s = sin x and c = cos x as independent kernels, the polynomialform does not know that s^2 + c^2 = 1. Reducing modulo that relation,a Gröbner basis of one element, gives a canonical form that does. *)open Mpoly
Running it.
s^2 + c^2 - 1 polynomial form: s^2 + c^2 - 1 modulo s^2 + c^2 = 1: 0s^2 + 2sc + c^2 - 2sc - 1 polynomial form: s^2 + c^2 - 1 modulo s^2 + c^2 = 1: 0s^4 - c^4 polynomial form: s^4 - c^4 modulo s^2 + c^2 = 1: -2c^2 + 1s^2 - c^2 polynomial form: s^2 - c^2 modulo s^2 + c^2 = 1: -2c^2 + 1s^3 + sc^2 polynomial form: s^3 + sc^2 modulo s^2 + c^2 = 1: s
The remainder eliminates every power of beyond the first, and and are recognized as equal. Rewriting systems give normal forms in the same way when they are terminating and confluent, which the Knuth–Bendix completion procedure tries to achieve[10].
Richardson's theorem
Richardson proved in 1968 that there is no algorithm to decide whether an expression built from , rational numbers, , , addition, multiplication, composition, , and is identically zero[1]. The proof encodes Hilbert's tenth problem, whether a polynomial with integer coefficients has an integer root, into such expressions, using to force variables to be integers. Consequently no canonical or even normal simplifier exists for such a class, and practical systems keep canonical forms for well-behaved fragments, polynomials, rational functions and some algebraic and exponential extensions, and use heuristics outside them.
Randomized identity testing
When expansion is too expensive or no canonical form is available, an identity can be tested by evaluating both sides at random points. For polynomials, the Schwartz–Zippel lemma bounds the error: a nonzero polynomial of total degree vanishes at a point chosen uniformly from with probability at most [5][6][7].
Checking that the Vandermonde determinant is the product of differences, and rejecting a subtly wrong version, by evaluation at random points modulo a large prime.
(* Testing a polynomial identity by evaluation at random points modulo aprime: the Vandermonde determinant equals the product of differences.A wrong identity is caught with probability at least 1 - d/p. *)let p = 1_000_000_007let det m = (* Gaussian elimination mod p *)let n = Array.length m and m = Array.map Array.copy m and d = ref 1 in(try for k = 0 to n - 1 dolet piv = match List.find_opt (fun i -> m.(i).(k) <> 0) (List.init (n - k) (fun i -> k + i)) with| Some i -> i | None -> raise Exit inif piv <> k then (let t = m.(piv) in m.(piv) <- m.(k); m.(k) <- t; d := p - !d);d := !d * m.(k).(k) mod p;let inv = Modp.inv p m.(k).(k) infor i = k + 1 to n - 1 dolet f = m.(i).(k) * inv mod p infor j = k to n - 1 do m.(i).(j) <- Modp.md p (m.(i).(j) - f * m.(k).(j)) donedonedone with Exit -> d := 0);!d
Running it.
det = prod (x_j - x_i), 20 random points: truedet = (x_1 + x_0) prod over the other pairs: agreed at 0 of 20 random pointsthe expanded determinant has 12! = 479001600 terms
The determinant has degree 66, so each evaluation modulo a prime near misses a wrong identity with probability below , while the expanded determinant would have nearly half a billion terms. Whether such tests can be derandomized is a central open problem of complexity theory, tied to lower bounds for arithmetic circuits[8].
History
Early formula manipulation systems of the 1960s struggled with simplification, and the distinction between canonical and normal forms was clarified by Caviness in 1970[3] and discussed by Moses in 1971[4]. Richardson's undecidability theorem of 1968 marked the limits[1]. Buchberger's Gröbner bases and the Knuth–Bendix procedure supplied canonical forms modulo relations[10], and Buchberger and Loos surveyed algebraic simplification in 1982[2]. Probabilistic identity testing was introduced by DeMillo and Lipton, Zippel and Schwartz between 1978 and 1980[7][6][5].
see also
- KernelIn computer algebra, a kernel is a maximal subexpression that is not built from sums, products and integer powers, such as sin(x), exp(x + 1) or √x, which the system treats as an opaque variable so that polynomial and rational-function algorithms can operate on the expression around it. Expanding (sin x + 1)² treats sin x as a variable k and returns k² + 2k + 1 with k replaced by sin x. Equal kernels must be recognized as the same variable, which requires their arguments to be in canonical form. Kernels are not algebraically independent in general, as exp(2x) = exp(x)², and full simplification requires rewriting them into an independent set, which the structure theorems of Risch and Rosenlicht describe for elementary functions.
- Gröbner basisA Gröbner basis of an ideal of multivariate polynomials is a generating set with respect to which multivariate division behaves as in one variable: the remainder of any polynomial is unique, and it is zero exactly when the polynomial lies in the ideal. Formally, the leading terms of the basis, for a fixed monomial order, generate the ideal of all leading terms. Buchberger's algorithm computes one from any generating set by adding the remainders of S-polynomials until they all reduce to zero. Gröbner bases decide ideal membership, solve systems of polynomial equations, count their solutions and eliminate variables; Bruno Buchberger introduced them in 1965.
- Monomial orderA monomial order is a total order on the monomials of a polynomial ring that is compatible with multiplication and has 1 as its smallest element. It determines the leading term of every polynomial, and with it the result of multivariate division and the shape of Gröbner bases. The standard choices are lexicographic order, which compares exponents variable by variable and is used for eliminating variables; graded lexicographic order; and graded reverse lexicographic order, which usually gives the smallest Gröbner bases and the fastest computations. Dickson's lemma guarantees that every monomial order is a well-order, so that division and Buchberger's algorithm terminate.
- Risch algorithmThe Risch algorithm is a decision procedure for integration in finite terms: given an elementary function, it either finds an elementary antiderivative or proves that none exists. It rests on Liouville's theorem, which says that an elementary antiderivative, if one exists, is a function of the same field plus constant multiples of logarithms. The algorithm writes the integrand in a tower of logarithmic, exponential and algebraic extensions of the rational functions and works down it, using Hermite reduction, the Rothstein–Trager resultant and the Risch differential equation y′ + fy = g. Its transcendental case is completely algorithmic; its algebraic case is much harder; and both are decision procedures only relative to deciding whether a constant is zero.
- Gruntz algorithmThe Gruntz algorithm computes limits of exp-log functions, those built from x and constants by arithmetic, exp and log, as x tends to infinity. It finds the set of most rapidly varying subexpressions, rewrites the function as a power series in one of them, and reads the limit off the leading term, recursing when the leading coefficient is itself a function of x. It succeeds where expansions in powers of 1/x fail, because exponentially small terms are invisible to them, and it is the limit algorithm of SymPy and Maple. Like the Risch algorithm, it is complete relative to an oracle that decides whether an expression is identically zero.
further reading
- [1]D. Richardson, “Some undecidable problems involving elementary functions of a real variable”, Journal of Symbolic Logic 33 (1968).
- [2]B. Buchberger, R. Loos, “Algebraic simplification”, in B. Buchberger, G. E. Collins, R. Loos (eds.), Computer Algebra: Symbolic and Algebraic Computation, Springer (1982).
- [3]B. F. Caviness, “On canonical forms and simplification”, Journal of the ACM 17 (1970).
- [4]J. Moses, “Algebraic simplification: a guide for the perplexed”, Communications of the ACM 14 (1971).
- [5]J. T. Schwartz, “Fast probabilistic algorithms for verification of polynomial identities”, Journal of the ACM 27 (1980).
- [6]R. Zippel, “Probabilistic algorithms for sparse polynomials”, EUROSAM, Lecture Notes in Computer Science 72 (1979).
- [7]R. A. DeMillo, R. J. Lipton, “A probabilistic remark on algebraic program testing”, Information Processing Letters 7 (1978).
- [8]V. Kabanets, R. Impagliazzo, “Derandomizing polynomial identity tests means proving circuit lower bounds”, Computational Complexity 13 (2004).
- [9]D. Cox, J. Little, D. O’Shea, Ideals, Varieties, and Algorithms, ch. 2, Springer (4th ed., 2015).
- [10]D. E. Knuth, P. B. Bendix, “Simple word problems in universal algebras”, in Computational Problems in Abstract Algebra, Pergamon (1970).
last updated