Logic & kernel theory

Polynomials

Formal polynomials are a type of their own, whose values are literals of the kernel's FORMAL_POLYNOMIAL kind. This page defines the ring and its canonical representation, states the kind's laws, and proves that the kind is conservative and that its literal equations are derivable.

The literal kind FORMAL_POLYNOMIAL is specified on the theory mechanisms page. Its laws are those of a commutative ring with a coefficient homomorphism from a base rational kind (Definition C-5P); with them, every model has exactly one interpretation of the polynomial literals that satisfies the literal scheme (Theorem C-11P), so the kind is conservative, as required of every literal kind. Evaluation peval is a constant of the polynomial theory over Scalar, not a kernel operation (evaluation and reification).

The ring

Definition P-1. Let \(X_i\), for \(i \in \mathbb Z\), be countably many indeterminates. A monomial is a finitely supported function \(m: \mathbb Z \to \mathbb N\), written \(X^m = \prod_i X_i^{m(i)}\). The ring \(\mathbb Q[X] = \mathbb Q[X_i: i \in \mathbb Z]\) consists of the finitely supported functions from monomials to \(\mathbb Q\), with pointwise addition and the convolution product \((PQ)(m) = \sum_{m' + m'' = m} P(m')\, Q(m'')\). It is a commutative ring with identity, and an integral domain [Cox, Little and O'Shea 2015, ch. 1].

Canonical representation

Definition P-2. A monomial is represented by the list of pairs \((i, m(i))\) with \(m(i) > 0\), sorted by \(i\). Monomials are ordered by comparing these lists lexicographically, pairs compared lexicographically and a proper prefix first. A polynomial \(P\) is represented by the list of pairs \((m, P(m))\) with \(P(m) \ne 0\), sorted by this order on monomials, each coefficient in the canonical rational encoding.

Proposition P-1. The monomial order is a strict total order, and every polynomial has exactly one representation. Hence two FORMAL_POLYNOMIAL literals are the same node exactly when they denote the same polynomial (requirement L1; the polynomials \(0\) and \(1\) are the constants bound to ZERO and ONE, as for every kind).

Proof. Lexicographic order on finite sequences over a totally ordered set, with a proper prefix first, is a strict total order. A representation lists the support of \(P\), which is unique, in the unique sorted order, with coefficients in their unique encodings. \(\square\)

The order is chosen for canonicity only. Gröbner-basis algorithms in the untrusted polynomials package use their own term orders. The byte encoding of the representation is K2.1's.

Requirement P-R1 (kernel arithmetic). The kernel's addition merges two sorted representations, adding the coefficients of equal monomials and dropping zeros; multiplication forms all products of pairs, adds exponent maps and multiplies coefficients, then sorts and combines; negation negates every coefficient; a power by a natural number \(n\) is computed by repeated squaring and may decline above a fixed limit (L3). Each returns the canonical representation of the mathematical result (L2). These are schoolbook algorithms, chosen so that the trusted code is simple; the fast algorithms are untrusted.

The kind's laws

Let P be the kind's carrier and \(b\) its base kind, of implementation EXACT_RATIONAL, with carrier \(B\), domain \(D_B\) (all of \(B\) if none), bound instances \(0_B, 1_B, +_B, \cdot_B, \le_B\), and exponent predicate \(E_B\) if bound. By Theorem C-11 there is exactly one embedding \(\iota_b: \mathbb Q \to \sem{D_B}\) in each model of \(b\)'s laws.

Definition C-5P (the polynomial kind's laws). The kind binds instances \(0, 1, +, \cdot, -\) on P, with \(+\) and \(\cdot\) ACU with units \(0\) and \(1\) (which states their associativity, commutativity, and unit laws), the cross-kind instances \(\mathrm{INDET}, \mathrm{COEFF}: B \to P\), and optionally \({}\hat{}{}: P \to B \to P\). Its laws, with \(p, q, r: P\) and \(a, c, n: B\), are:

Law Statement Required
Q1 \(\forall p.\; p + (-p) = 0\) always
Q2 \(\forall p\,q\,r.\; p \cdot (q + r) = p \cdot q + p \cdot r\) always
Q3, Q4 \(\mathrm{COEFF}(0_B) = 0\); \(\quad \mathrm{COEFF}(1_B) = 1\) always
Q5 \(\forall a\,c.\; D_B\,a \to D_B\,c \to \mathrm{COEFF}(a +_B c) = \mathrm{COEFF}(a) + \mathrm{COEFF}(c)\) always
Q6 \(\forall a\,c.\; D_B\,a \to D_B\,c \to \mathrm{COEFF}(a \cdot_B c) = \mathrm{COEFF}(a) \cdot \mathrm{COEFF}(c)\) always
Q7 \(\forall p.\; p \mathbin{\hat{}} 0_B = 1\) \({}\hat{}{}\) bound
Q8 \(\forall p\,n.\; E_B\,n \to 0_B \le_B n \to p \mathbin{\hat{}} (n +_B 1_B) = p \cdot p \mathbin{\hat{}} n\) \({}\hat{}{}\) bound

There are no laws for \(\mathrm{INDET}\): the indeterminates are free. There is no law that distinct polynomials are distinct, and no order.

Theorem C-11P (formal polynomials are definitional). Let \(M\) be an interpretation of the theory, without its polynomial literals, in which the base kind's literal laws (Definition C-5) and Q1 to Q8 hold. There is exactly one ring homomorphism \(\varphi_M: \mathbb Q[X_i: i \in \mathbb Z] \to \sem P\) with \(\varphi_M(c) = \sem{\mathrm{COEFF}}(\iota_b(c))\) for \(c \in \mathbb Q\) and \(\varphi_M(X_i) = \sem{\mathrm{INDET}}(\iota_b(i))\) for \(i \in \mathbb Z\). Interpreting each polynomial literal atom \(\mathsf{lit}(F)\) as \(\varphi_M(F)\) satisfies every (L) equation of the kind, and it is the only interpretation of the literal atoms that does. Hence the kind is a conservative extension.

Proof. \(\sem P\) with the bound operations is a commutative ring: the ACU laws give a commutative monoid for each operation, Q1 additive inverses, and Q2 with commutativity both distributive laws. The map \(\psi = \sem{\mathrm{COEFF}} \circ \iota_b: \mathbb Q \to \sem P\) is a ring homomorphism: \(\iota_b\) is a ring homomorphism into \(\sem{D_B}\) (Theorem C-11), and Q3 to Q6 make \(\sem{\mathrm{COEFF}}\) preserve \(0\), \(1\), sums, and products on \(\sem{D_B}\); a map between rings that preserves \(0\), \(1\), and sums preserves negation. So \(\sem P\) is a commutative \(\mathbb Q\)-algebra through \(\psi\), and the universal property of the polynomial ring \(\mathbb Q[X_i: i \in \mathbb Z]\) [Cox, Little and O'Shea 2015] gives exactly one ring homomorphism \(\varphi_M\) extending \(\psi\) with the prescribed values on the indeterminates.

The (L) equations hold: for ADD, MUL, and NEG because \(\varphi_M\) is a ring homomorphism and the implementation computes in \(\mathbb Q[X]\) (L2); for COEFF and INDET by the definition of \(\varphi_M\); for POW, where the implementation evaluates only natural exponents \(n\) (L5), because \(\iota_b(n) \in \sem{E_B}\) and \(0_B \le_B \iota_b(n)\) (laws E1, E2, O7 of the base, by induction), so Q7 and Q8 give \(\sem{{}\hat{}{}}(\varphi_M(F), \iota_b(n)) = \varphi_M(F)^n = \varphi_M(F^n)\) by induction on \(n\); and for EQ, which evaluates only two identical literals, to \(\mathsf{True}\).

Uniqueness: let the atoms denote any values satisfying the (L) equations. Every polynomial other than \(0\) and \(1\) is reached from constants and indeterminates by finitely many sums and products of literal arguments, and each step is an (L) equation: \(\mathsf{COEFF}(\underline c) = \underline c\), \(\mathsf{INDET}(\underline i) = \underline{X_i}\), and the MUL and ADD equations that build monomials and then sums of monomials from them. By induction on this construction, every atom's value is forced to be \(\varphi_M\) of its polynomial, starting from the fixed instances bound to ZERO and ONE. Expansion follows: every model of the theory without the literals has exactly one expansion satisfying the scheme. \(\square\)

Why EQ may not evaluate to False. The one-element ring satisfies Q1 to Q8 with every \(\mathrm{INDET}(i)\) and \(\mathrm{COEFF}(c)\) equal to \(0\), so \(\varphi_M(X_0) = \varphi_M(X_1)\) there. The equation \(\mathsf{eq}(\underline{X_0}, \underline{X_1}) = \mathsf{False}\) would be false in that model: evaluating it would make the kind non-conservative. Where distinctness is needed, it is a theorem of the theory that uses the kind: for scalar, evaluating both polynomials at a rational point where they differ, and comparing the two rational results by the base kind's EQ.

Lemma C-12aP (polynomial literal equations are derivable). Every (L) equation of the kind is derivable, without conversion, from Q1 to Q8, the ACU laws, and the base kind's literal laws.

Proof sketch. An equation between two polynomial expressions in the indeterminates and constants that holds in \(\mathbb Q[X]\) is derivable from the commutative-ring axioms together with the equations \(\mathrm{COEFF}(c) \cdot \mathrm{COEFF}(c') = \mathrm{COEFF}(cc')\) and \(\mathrm{COEFF}(c) + \mathrm{COEFF}(c') = \mathrm{COEFF}(c + c')\) for the coefficients involved: \(\mathbb Q[X]\) is the free commutative \(\mathbb Q\)-algebra, so its identities are those of commutative rings over the coefficient arithmetic (Birkhoff's completeness theorem for equational logic). The coefficient equations are instances of Q5 and Q6 with the base kind's literal equations (Lemma C-12a), which also provide the guards \(D_B\). The derivation follows the implementation's computation: distribute, collect monomials, combine coefficients. Powers unfold by Q7 and Q8. \(\square\)

Lemma C-12aP extends Theorem C-12 (conversion elimination) to theories with the polynomial kind; the conversion-eliminating export of judgment_store produces these derivations.

Evaluation and reification

Evaluation into the scalar carrier, the polynomial theory over Scalar with its axioms and model, and reification, which turns a polynomial expression into the evaluation of a literal so that a polynomial identity is decided by comparing literals, are on scalar's page Polynomials over Scalar. Its numbering continues this page's: Definitions P-3 to P-5 and Theorems P-2 to P-6.

judgment v1.0.0 for Mojo 1.2 · Apache License 2.0 with LLVM Exceptions · Source on GitHub