Identity across kernels¶
A kernel's handles mean nothing outside it. A stored theorem must name its declarations in a way that every kernel agrees on, and its size must grow no faster than the kernel's own representation of it.
Canonical serialization¶
The kernel stores terms and types as a hash-consed graph: each distinct node once, shared by every term that contains it (the kernel's termbank specification, S-R2). The serialization keeps that sharing, as the architecture note asks of portable bundles (section 26.1: a serialized syntax DAG, with bundle-local references). An object (a declaration, or a statement's key) is written as two tables followed by its own fields: a reference table of the declarations it cites, and a node table of the distinct nodes of its terms and types. Fields cite declarations by their position in the reference table and nodes by their position in the node table.
Definition I-1 (serialization).
-
Node table. Let \(r_1, \dots, r_m\) be the roots an object writes (the terms and types of its fields, in the order of its fields). Traverse the graph below them in post-order: each node's children in their order in the kernel's node (a constant's type arguments before its term arguments, a binder's type before its body), the roots in order. The node table lists each node at the step where the traversal first finishes it, so each distinct node appears once and every child precedes its parent. Each entry is one of these forms, with its children written as their positions in the table:
Node Entry type variable \(\alpha^S\) TVAR, its name, the classes of its sort \(S\) in the kernel's order (none for the empty sort)\(\kappa(\tau_1, \dots, \tau_n)\) TCON, \(\kappa\), \(n\), the arguments\(\tau \to \tau'\) ARROW, the two typesbound variable \(\#i\) BVAR, \(i\)\(c[\tau_1, \dots, \tau_k](a_1, \dots, a_n)\) CONST, \(c\), \(k\), the type arguments, \(n\), the term arguments\(f(a_1, \dots, a_n)\), \(f\) not a constant APP, \(f\), \(n\), the arguments\(\lambda{:}\tau.\, b\) LAM, \(\tau\), \(b\)\(\mathsf{let}{:}\tau = v \;\mathsf{in}\; b\) LET, \(\tau\), \(v\), \(b\)literal \(\mathsf{lit}_k(v)\) LIT, \(k\), the kernel's encoding bytes of \(v\)
Declarations in an entry (\(\kappa\), \(c\), \(k\), the classes) are written as their positions in the reference table.
-
Reference table. A reference names a declaration as a pair: an identity (Definition I-2) and a part number, 0 for the declaration itself and \(i \ge 1\) for the \(i\)-th part of a declaration made of several (a block):
Declaration Its parts, in order type definition of \(\kappa\) 1 abs, 2rep, 3 the theorem \(\forall a.\, \mathsf{abs}(\mathsf{rep}\, a) = a\), 4 the theorem \(\forall r.\, P\, r = (\mathsf{rep}(\mathsf{abs}\, r) = r)\)specification of \(c_1, \dots, c_k\) \(1\) to \(k\) the constants, in the order of their names; \(k + 1\) its theorem class \(c\) 1 its predicate \(\mathsf{of\_class}_c\)
The reference table lists the distinct references the object cites, each once, in the order in which they are first cited when the bytes that follow the table are written from left to right. This order is that of declarations and statements.
- Declarations. A declaration is written as its form's tag, its
reference table, its node table (with roots its fields' terms and
types, in field order), and its fields: names, flags, and numbers as
themselves; terms and types as node positions; declarations as
reference positions. The fields of each form are those the kernel's
Declarationholds for it (K1.3, K2.6 to K2.9), its type parameters in order, and for aProventheorem its statement, not its proof. AProventheorem's statement with at most six type variables is written as its key (Definition I-5), and the type parameters as those of the key; with more, as declared. AnAxiomis written as declared. A declaration's parts are not written: the kernel derives them from the declaration.
\(\operatorname{ser}(d)\) denotes these bytes; the design of ST1.4 fixes their layout.
Definition I-2 (identity). The identity of a declaration \(d\) is
[NIST 2015]: the digest of a fixed prefix, a zero byte, and the serialization. A declaration of the logic core, which every kernel holds and no bundle writes, has the identity \(\mathrm{SHA\text{-}256}(\mathtt{judgment/core/1} \,\|\, 0 \,\|\, \mathit{name})\). Because \(\operatorname{ser}(d)\) contains the identities of the declarations \(d\) refers to, identities form a Merkle DAG [Merkle 1987].
The prefixes separate domains: a declaration and a core name never share an identity, and a later version of the serialization, with its own prefix, never reuses an identity of this one. Identities are permanent, so the prefix is fixed with the first format.
Proposition I-1 (identities are kernel-independent). Kernels that use
the same termbank format (the kernel's termbank specification, T1.2 and
T1.6) give \(\operatorname{ser}\) and \(\operatorname{id}\) that depend only on
the content of a declaration and, recursively, of the declarations it
refers to; not on DeclIds, TermIds, banks, or commit order.
Proof. The roots are the declaration's fields, which are content. They
are the kernel's canonical forms, which depend only on content for terms
without locals; a Proven's statement is a closure, which does not depend
on how its locals are bound or named (Theorem Q-3a); the order of an ACU
application's arguments is
the bank's structural order, which depends on content through the
format's hash functions and names (T1.6), hence the hypothesis on the
format. The node table's order is fixed by the graph's structure and the
roots' order, and two nodes are the same entry exactly when they are the
same node, that is, structurally equal (S-R2). The reference table's order
is fixed by the bytes after it, and each reference is an identity, by
induction content-determined, and a part number fixed by the form. Every
other field is content: names, tags, numbers, encodings. \(\square\)
Proposition I-2 (identities are keys, not evidence). Let an import resolve each reference by identity and compare, for each declaration it reads, the bytes recorded with the serialization of what it declared.
- Soundness does not depend on SHA-256: every declaration an import makes is validated by the kernel, and every proof is checked again (ground rule SG1), whatever the identities.
- Identification: if no two distinct serializations involved in the import have the same identity, every reference resolves to a declaration whose content is the one the writer serialized.
Proof. (1) By Algorithm BU-2 and Theorem BU-3: only the checker's rules make declarations and judgments, and a load checks every row it commits (Algorithm L-5). (2) By induction along the order in which the declarations are declared. A reference resolves to the bank's declaration with the referenced identity, whose serialization was compared byte for byte with a recorded one when it was loaded or declared. Equal bytes mean equal fields and equal identities of its own references, which by induction name the same contents. A resolution to another content therefore needs two distinct serializations with one identity, a SHA-256 collision. \(\square\)
A collision could thus bind a name to an unintended declaration, which the kernel would still validate; it could never make the kernel accept an invalid declaration or proof.
Theorem I-5 (linear size). Let an object write roots whose subgraph of the bank has \(N\) nodes, \(A\) argument edges, and \(P\) pooled bytes (type variables' names and literal encodings), cite \(R\) distinct references, and hold fields of \(F\) bytes (names, flags, numbers, and the 4-byte positions of its roots and references). Then its node table has at most \(13N + 4A + P + 4\) bytes, its reference table at most \(36R + 4\) bytes, and \(R \le N + A + F\). Its serialization is therefore linear in \(N + A + P + F\): the size of the kernel's own representation of the object.
Proof. The node table has at most one entry per node: a class atom of
a sort is cited as a reference, not written as an entry. An entry is one
tag byte; at most three 4-byte fields that are not children (a reference
and two counts for CONST; a reference and a count for TCON; a name's
length and a class count for TVAR; a reference and a length for LIT;
a count for APP; an index for BVAR and LOCAL); 4 bytes per child or
class, each an argument edge of the node; and its pooled bytes. Hence at
most \(13N + 4A + P\) bytes, plus the 4-byte count. Each reference is 36
bytes (a 32-byte identity and a 4-byte part number), written once, plus
the count. A reference is first cited by an entry's head (a constant, a
type constructor, a literal kind: at most one per entry), by a class
(an argument edge), or by a field (at most one per 4 bytes of fields),
so \(R \le N + A + F\). \(\square\)
Writing visits each node once, with a map from nodes to positions, and reading is one pass in table order, since every position points to an earlier entry; both are linear in the serialization's size, apart from the kernel's own work in rebuilding.
Remark (why not trees). A serialization by structure, which writes a term as a tree, writes a shared node once per path to it. The term \(t_n\), with \(t_0 = a\) and \(t_{i+1} = f(t_i, t_i)\), has \(n + 1\) nodes in the bank and \(2^{n+1} - 1\) nodes as a tree. Canonical construction, ACU normalization, and stored proofs, whose consecutive steps repeat the same large terms, share nodes routinely; a tree serialization of them would be exponential in the worst case and could exceed any budget for terms the kernel holds in linear space.
Declaration order¶
Definition I-3 (declaration order). A partition lists its own declarations in the writer's commit order (ST8.1, section 2): the order in which its bank declared them. A declaration with parts is listed once, not its parts.
Proposition I-3 (the order is a dependency order, and loading keeps it). (1) Every own declaration that a declaration's syntax references or its proof cites precedes it in commit order. (2) A load declares a partition's own declarations in its listed order, so writing the loaded bank lists them in the same order.
Proof. (1) A bank interns a row only over rows it has committed, so a
declaration's references and its proof's citations are committed before it.
(2) The loader requires the DECL rows in section-2 order and declares each
at its row (ST9.8), so the bank's commit order of the partition's own
declarations is section 2's; the writer lists a bank's declarations in that
order. \(\square\)
The order is not canonical: two banks holding the same declarations, made in different orders, list them differently. A library's determinism (ground rule SG6) is that writing one bank twice gives the same bytes.
Theorem I-4 (re-declaring preserves content). Let \(d\) be a declaration
of a kernel \(K\), with its reconstruction prerequisites already
re-declared in a kernel \(K'\), of the same termbank format, with the same
identities and recorded support restored. Declaring in \(K'\) the content
of \(\operatorname{ser}(d)\), with references mapped, either fails or yields a declaration \(d'\) with
\(\operatorname{ser}(d') = \operatorname{ser}(d)\), whose parts, if any, are
those of \(d\) in the same order.
Proof. The kernel validates a declaration from its content and from the contents of the declarations it cites, and builds its statement canonically from the same content (stored contents are lifted to the signature where they are used). With references mapped to declarations of equal content and the canonical signature restored before constructing nodes, the same canonical construction produces terms of equal structure, and so, by Proposition I-1, equal node and reference tables and equal serializations. A declaration with parts derives them from its content in the order of Definition I-1. \(\square\)
Statements up to renaming¶
A theorem's type variables are implicitly universally quantified, so two
statements that differ by a renaming of type variables state the same
theorem: each is an instance of the other by use. Libraries and replays
identify statements this way.
Definition I-5 (statement key). Let \(\varphi\) be a closed statement of
a theory, with type variables \(\alpha_1, \dots, \alpha_n\) in order of first
occurrence (Definition S-3) and sorts \(S_1, \dots, S_n\). For a permutation
\(\pi\) of \(1, \dots, n\), let \(\varphi_\pi\) be the canonical form of
\(\varphi[\alpha_{\pi(i)} := {?(i-1)}^{S_{\pi(i)}}]\), where \({?j}^{S}\) is the
type variable named ?j (the decimal digits of \(j\)) of sort \(S\), so the
variables are named ?0 to ?(n-1). When \(n \le 6\), the key of \(\varphi\) is the
least \(\varphi_\pi\) in the structural order (T1.6); otherwise it is the one
for the identity permutation. The key's order lists
\(\alpha_{\pi(1)}, \dots, \alpha_{\pi(n)}\) for the chosen \(\pi\).
A Proven's statement is \(K(s)\) of its proof's sequent \(s\), the canonical
closure (Definition Q-3d), which is its own key for one to six type
variables (Theorem Q-3e).
Proposition I-5 (keys identify renamings). Two closed statements with equal keys are equal up to a bijective, sort-preserving renaming of their type variables. With at most six type variables, the converse holds.
Proof. Equal keys mean \(\varphi_\pi = \psi_\rho\) for some permutations.
Each side is a bijective, sort-preserving renaming of its statement into the
?i, and a renaming of a canonical form canonicalizes to a unique term, so
renaming back gives \(\psi\) as a renaming of \(\varphi\). Conversely, if \(\psi\)
is a renaming \(\sigma\) of \(\varphi\), every renaming of \(\psi\) into the ?i
is one of \(\varphi\) composed with \(\sigma\), so the two sets
\(\{\varphi_\pi\}\) and \(\{\psi_\pi\}\) are equal and have the same least
element. \(\square\)
With more than six type variables, the first-occurrence renaming is kept.
Canonical sorting of ACU arguments can make it depend on names; two such
statements may then get different keys and be kept apart, which never
identifies different statements. If \(\varphi\) and \(\psi\) have equal keys
with orders \(o\) and \(o'\), a declaration \(d\) of \(\varphi\) states \(\psi\)
exactly by use at the type arguments that map each parameter of \(d\),
\(o_i\), to \(o'_i\).
Writing a theorem's statement as its key makes a declaration's identity
independent of the names of its type variables: two proofs of one
statement whose variables are named differently give declarations with one
identity. The bytes then omit the names, so a container that stores such a
theorem records them beside it, for its aliases
(ST8.1): the bank
holds the theorem as its key, which is \(K\) of its proof's sequent whatever
that sequent's type variables are named (Theorems Q-3a and Q-3e), so the
proof is cited as it is. An axiom has no proof to agree with, so it is
written as declared; a library declares its assumptions stating the
canonical closures of their sequents, which are their keys
(Proof libraries). The key is idempotent with at most six type variables: a key's
renamings into the ?i are those of the statement it came from, composed
with a bijection, so they have the same least element. A reader that
rechecks a proof and serializes the declared theorem therefore reproduces
the written bytes. With more variables the key need not be idempotent, so
such statements are written as declared.
Definition I-6 (statement identity). The statement identity of a closed statement \(\varphi\) is
where \(\kappa(\varphi)\) is its key (Definition I-5) in the theory that declares the statement, and \(\operatorname{ser}(\kappa(\varphi))\) is the serialization of Definition I-1 of an object with one root, \(\kappa(\varphi)\), and no fields: its reference table and then its node table, whose last entry is the root.
The key is a canonical form, so it depends on the canonical signature of
that theory: a statement about an operator keyed before and after the
operator is declared ACU has two canonical forms, which the kernel treats
as different terms, and so two identities. Like declaration identities,
statement identities are fixed for one termbank format, which the
containers that record them name.
Statement identities are defined for termbank's production hash. T1.6
decides by structural hash first, so under weak_hash (T1.2) statement
keys and canonical closures, and with them identities, differ; a
weak_hash build is for tests.
Proposition I-6 (statement identities).
- Kernels with one
termbankformat give a statement the same identity. - Statements equal up to a bijective, sort-preserving renaming of at most six type variables have one identity.
- If no two distinct serializations involved have one SHA-256, and no two declarations involved have one identity, statements with one identity are equal up to such a renaming.
Proof. (1) The key is chosen in the structural order T1.6 among
canonical forms with the fixed names ?i, so it depends only on content,
and Proposition I-1 applies to its serialization. (2) Proposition I-5.
(3) Equal digests of distinct inputs are a collision. Equal
serializations cite declarations of equal identities, which are the same
declarations by the second hypothesis (the kernel allows sibling theories
to hold equal-content declarations, which are different constants), so
they are equal keys, and equal keys are renamings (Proposition I-5).
\(\square\)
As with Proposition I-2, soundness never rests on (3): every proof is rechecked. The prefix separates statement identities from declaration identities and core names.