Simplicial Stochastic Grammars of Molecules and the Compositional Semantics of Their Derivations
Full text from the PDF
This automated reading aid follows the original PDF pages. Small compressed images retain mathematical notation and complex visual material. Original PDF pages remain authoritative for quotation and layout.
PDF page 1
Simplicial Stochastic Grammars of Molecules and the Compositional Semantics of Their Derivations
Wanhong HUANG huangwanhong@serendip.ngo
Abstract
Chemistry has a syntax, the ways atoms may be joined, and a semantics, what a molecule so joined does. This paper measures how much of each a generative grammar holds when its letters are as small as they can be. A molecule is written one atom at a time, each atom the apex of a simplex of dimension one, two or three glued along a face of what is already there; a ring is a fan of triangles on edges that are no bonds. This is a normal form of hyperedge replacement at bounded rank, and of a tree decomposition of width three. The grammar is stated in full as a grammar of hyperedge replacement whose nonterminals are faces with a count of the cones they carry, and whose richer levels of context are application conditions; its derivations in the order of growth correspond one to one to words, and valence can be carried exactly in its nonterminals. A canonical derivation makes each molecule one word, two words being equal exactly when their constitutions are isomorphic; the alphabet is small (57 letters on MOSES, where a grammar whose letters are whole rings needs thousands of rules); and the molecules left out are counted exactly: 22 of 133,885 in QM9, 2 of 249,455 in ZINC250k and 4 of 1,936,962 in MOSES. On words a stochastic grammar is read at nested levels of context and judged in bits on molecules held out. A context-free grammar needs 82.1 bits for a molecule of MOSES; knowing the letter that opened a face, 58.1; knowing also the length of the ring a closure would make and the valence left, 47.5; knowing also how many atoms the molecule has so far, 42.9, which is 1.7 times the 25.6 bits reported for a chemical language model of 32 million parameters (Balaji et al., 2025). Every molecule drawn from the grammar conditioned on valence is valid; the grammars of local context draw molecules of the wrong sizes, and the number of atoms so far brings the body of the law of sizes to the collection’s, though not its tail. For semantics, eight properties of QM9 are read as sums over the parts of a derivation, rung by rung. Among molecules made of the very same atoms and bonds, the productions of the derivation together with the productions they came from tell 0.84 of the differences in atomisation energy and 0.47 of those in the HOMO–LUMO gap: how a molecule is put together carries meaning that its parts do not, more for energies than for frontier orbitals. How far a derivation can decide meaning is bounded by the equivalence the grammar quotients by. In QM9 the 87 pairs of molecules that share a whole canonical word agree to the archive’s last digit; in ZINC250k every one of the 1,644 groups that share a word is a group of stereoisomers, mirror images among them, which a grammar of constitutions cannot tell apart. Three variants are stated formally: letters that carry the orientation of the simplex they complete; nonterminals that are orbits of faces under the symmetries of the molecule so far, so that the choice between two enantiotopic faces is a recorded step; and letters that carry the rigid motion placing their apex. The first is built: its oriented words separate the 249,453 configurations of ZINC250k exactly, every pair of stereoisomers among them, and a sign held out costs 0.995 bits. An operator-algebraic formulation of the growth and other alphabets are discussed.
Keywords: hyperedge replacement grammar, stochastic grammar, simplicial complex, stereochemistry, compositional semantics
PDF page 2
Note
This paper reports a study made in one working session inside Noetarium, the Science and Humanity Infrastructure, an open repository of scientific software. The grammar is implemented there (the foundation library syntaxis, module stacked; the molecular-science domain, modules graphs and syntax), and every number in the paper is read from the record of the experiment by a script. It is a draft, circulated for discussion and criticism.
Conditions of Use
Research use. The manuscript is intended for scholarly discussion, criticism and revision; work that builds on it should state which definitions it adopts and which it alters.
Licence. Copyright © 2026 Wanhong HUANG. The author’s original text and diagrams are offered under the Creative Commons Attribution-NonCommercial 4.0 International licence (CC BY-NC 4.0): they may be shared and adapted for non-commercial purposes, with the author credit, the source and licence links, the supplied notices and an indication of modifications retained. The programs and results behind the paper are kept in the project repository under its MIT licence. Third-party materials retain their own terms: QM9 is in the public domain (CC0), ZINC250k as distributed in the repository of Gómez-Bombarelli et al. (2018) is under the Apache 2.0 licence, and MOSES is under the MIT licence; none is reproduced here.
Notice
Interpretive and evidential scope. The propositions are elementary and are proved in the text or in Appendix A. The measurements are of three public collections of small organic molecules and of one family of grammars; they say nothing of molecules of larger treewidth, of stereochemistry beyond what the oriented reading of Section 10.2 separates (no grammar of configurations or conformations was learned), or of materials, polymers and proteins. The comparison with other generative models is by numbers their authors report under protocols that differ; where the protocols differ the text says so.
Disclosure of AI Assistance
Claude (Anthropic), working as a coding agent in the author’s repository, did most of the work this paper reports, at the author’s direction. The ideas that started it are the author’s (Appendix D): that chemistry has a space of syntax and a space of semantics; that molecular structures arise by a generative procedure from which their semantics emerge, so that probabilistic context-free and context-sensitive grammars are worth trying, with an embedding of syntax and semantics on a space such as a smooth manifold; that an alphabet of simplices is a good one and one among others; and the hypothesis that the structure of the generation process, like a syntax tree, also decides the semantics. So are the corrections that gave the hypothesis its present form: that “identical” has no meaning until an equivalence is stated and the conditions under which it holds; that identical derivations must not end in structures that are isomorphic
PDF page 3
yet different, such as mirror images, without breaking the definition; that grammars carrying symmetry, isomorphism and transformation information are the valuable extension; and that the question bears on non-commutative operator algebras. On reading a draft, the author also required that the formal grammar be presented in full, as a main part of the paper, and that the variants carrying symmetry and transformation information be presented formally as well. The assistant proposed the formal construction (the stacked word, its canonical reading, the grammar of hyperedge replacement and its variants, the levels of context, the remark on what context can and cannot add), wrote the software and its checks, chose and ran the case studies, and drafted the text and figures. A further session of the same model surveyed the literature and corrected several claims of the first design. No part of the text was written by the author by hand at the time of this draft. A proof, a program or a reading of the literature produced with a model can contain mistakes; the checks described in Appendix C have limited evidential authority. The author directs the inquiry and retains responsibility for the claims, the references and the decision to circulate. Independent expert review remains appropriate.
Contents
Note 2
Conditions of Use 2
Notice 2
Disclosure of AI Assistance 2
1 Introduction 6 1.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.2 Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.3 Contributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.4 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 Related Work 8 2.1 Molecular Grammars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.2 Graph Grammars from Tree Decompositions . . . . . . . . . . . . . . . . . . . . . . 8 2.3 Treewidth of Molecular Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.4 Code-Length Evaluation of Probabilistic Grammars . . . . . . . . . . . . . . . . . . 9 2.5 Additive Property Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3 Simplicial Words for Molecular Graphs 9 3.1 Molecular Graph Convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.2 Definition of Stacked Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.3 Canonical Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.4 Validity Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4 Formal Grammar of Stacked Words 11 4.1 Signature of Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.2 Terminal Alphabet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.3 Nonterminals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.4 Sentential Forms and Productions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.5 Derivation Trees and the Order of Growth . . . . . . . . . . . . . . . . . . . . . . . . 14 4.6 Levels of Context as Context Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.7 Valence Carried in the Nonterminals . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4.8 Generative Capacity of the Context Levels . . . . . . . . . . . . . . . . . . . . . . . . 17
PDF page 4
4.9 Complete Derivation of Benzene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4.10 Grammars Learned from the Collections . . . . . . . . . . . . . . . . . . . . . . . . . 17
5 Stochastic Grammar 19 5.1 Probability Law and Estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 5.2 Code Length of Canonical Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 5.3 Branching-Process Structure of the Context-Free Level . . . . . . . . . . . . . . . . . 20
6 Corpora and Coverage 21 6.1 Corpus Sources and Splits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 6.2 Treewidth Distribution and Residue . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
7 Code-Length Evaluation of the Context Levels 22 7.1 Within-Collection Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 7.2 Cross-Collection Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 7.3 Learning Curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 7.4 Comparison with Other Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
8 Sampling Evaluation 24 8.1 Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 8.2 Agreement with the Independent Toolkit . . . . . . . . . . . . . . . . . . . . . . . . 25 8.3 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 8.4 Comparison with Published Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
9 Compositional Semantics of Derivations 27 9.1 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 9.2 Rungs of Derivation Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 9.3 Data and Regression Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 9.4 Held-Out Accuracy by Rung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 9.5 Within-Group Analysis at Fixed Atoms and Bonds . . . . . . . . . . . . . . . . . . . 29 9.6 Model-Free Class Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 9.7 Equivalence of Derivations and Duplicate Words . . . . . . . . . . . . . . . . . . . . 31 9.8 Grammatical Surprise and Strain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 9.9 Assessment of the Hypothesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
10 Variants of the Grammar 34 10.1 Equivalence Fixed by a Canonical Grammar . . . . . . . . . . . . . . . . . . . . . . . 34 10.2 Oriented Grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 10.3 Orbit Grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 10.4 Transformation-Labelled Grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 10.5 Composition of the Variants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
11 Discussion 41 11.1 Operator-Algebraic Formulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 11.2 Alternative Alphabets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 11.3 Historical Derivations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 11.4 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
12 Conclusion 44
A Proofs 49 A.1 Proof of Proposition 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 A.2 Proof of Proposition 18 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 A.3 Proof of Proposition 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
PDF page 5
B Conventions of the Reading 50
C Reproduction 51
D Preparation of This Study 52
E Productions of the Grammar Learned from MOSES 53
PDF page 6
1 Introduction
1.1 Motivation
A structural formula is a sentence. It is well formed or it is not (carbon takes four bonds, a ring must close), and when it is well formed it means something: the substance boils at some temperature, absorbs at some wavelength, binds or does not bind a protein. Chemists have long spoken of both sides. The rules of valence are a syntax in all but name, and group additivity (Benson and Buss, 1958) is a compositional semantics: a property of the whole is a sum over its parts, corrected where the parts are strained by how they are joined.
The question of this paper is how far a generative grammar carries both sides. A grammar says how well-formed sentences are made, step by step; a stochastic grammar says also which are likely; and a compositional semantics reads a meaning off the steps. For strings the theory is old. For molecules, which are graphs with cycles, three things have to be decided before the question can be put: what a letter is, what a derivation is, and which derivation is the derivation of a molecule.
1.2 Approach
Alphabet. A molecule is written one atom at a time. Each atom after the first is the apex of a cone over a face already present: one earlier atom, or two that are joined, or three that are pairwise joined. The cone joins the apex to each atom of its face by a bond, or by a virtual edge that is no bond. A cone over one atom is an edge, over two a triangle, over three a tetrahedron, so the molecule is a complex of simplices of dimension one to three glued along faces. A chain is a sequence of edges. A ring is a fan of triangles: benzene is one bond and four triangles, whose three chords are virtual. A cage is built with tetrahedra.
Derivation. Faces wait in a queue; at the face in front either a cone is glued or the face is closed. Those events, in order, are the derivation, and the context of an event is what can be read of the molecule so far.
Canonical form. Of the many ways to write a molecule, one is chosen by rules that depend only on the molecular graph, so that a molecule is one word and its probability under a grammar is a number that can be computed and compared.
1.3 Contributions
1. Normal form and residue. Molecules as words of simplices of dimension at most three, one atom to a production, with a canonical reading (Section 3). The exact treewidth of every molecule of three collections is computed, and the molecules that have no such reading are counted and explained (Section 6): the reading asks that the molecule stay connected while it is written, and a few cages of treewidth three, cubane among them, cannot meet that within faces of three atoms.
2. Formal grammar. The grammar that derives the words, stated as a grammar of hyperedge replacement: a terminal alphabet of simplices, nonterminals that are faces with a count,
PDF page 7
three schemata of productions (a root, a glue of one simplex on a face, the closing of a face), sentential forms, derivations and the language (Section 4). Derivations in a fixed order of growth correspond one to one to words, so that a molecule’s canonical reading is one derivation; the levels of context are functions on sentential forms; valence, read from the molecule as it grows, can instead be carried in the nonterminals as budgets, which gives the language of valid molecules by hyperedge replacement explicitly. The grammars learned from three collections are counted and listed.
3. Context levels evaluated by code length. A stochastic grammar at nested levels: the face alone, which is context-free; the letter that opened the face, a refinement that is still contextfree; the length of the ring a closure would make and the valence left on the face’s atoms, which read the state of the molecule; and the number of atoms so far, the one context that is not local. Each level is judged by the bits it needs for molecules it did not learn from, within a collection and across collections (Section 7). We say what those bits are a code of, and measure the slack.
4. Generative capacity of context. By Courcelle’s theorem the constraints of valence and of ring size keep a language of bounded treewidth context-free. Context therefore changes the probabilities and the size of the grammar, never the set of molecules that can be derived (Section 4.8). The ladder is a ladder of laws.
5. Sampling evaluation. Molecules drawn from each level are judged by an independent toolkit: their validity, their repetition, their sizes and how far their distribution lies from held-out molecules (Section 8). The grammars of local context get the sizes of molecules wrong, and we show why and what repairs it.
6. Compositional semantics by rung. Eight computed properties of QM9 are read as sums over the parts of a derivation, at levels that parallel the ladder (Section 9). The test of interest compares molecules made of exactly the same atoms and bonds: any difference between them is, by construction, a matter of how they are put together, and we measure how much of it the derivation’s productions tell.
7. Grammar variants. The grammar fixes an equivalence before it learns anything: renumbering, so that mirror images share a derivation. Three variants that carry more are stated formally, each a change to one part of the grammar (Section 10): letters that carry an orientation, nonterminals that are orbits under the symmetries of the molecule so far, and letters labelled by the rigid motion that places their apex. The first is built: on all of ZINC250k its words separate exactly the configurations RDKit separates, every pair of stereoisomers among them.
1.4 Scope
The grammar is not a competitive generative model. Its richest level needs 1.7 times the bits that a neural language model of SMILES strings needs (Section 7), and the paper says so with the numbers. The grammar is offered as an instrument: a small, exact description of local chemical syntax whose every probability is a ratio of counts, against which one can ask how much of a collection’s regularity is local, how much a given context is worth, and how much of a property follows from composition alone. Nor is it claimed that simplices are the right alphabet; Section 11 discusses others.
PDF page 8
2 Related Work
A survey made for this study is kept with the experiment’s record; it lists 143 references, each marked by how it was checked, and searches that found nothing. This section gives what bears on the claims.
2.1 Molecular Grammars
String grammars. Kusner et al. (2017) decode molecules through the productions of a contextfree grammar of SMILES (Weininger, 1988); the grammar guarantees the syntax of the string and not the chemistry. Dai et al. (2018) add attributes that carry ring-bond matching and valence, and SELFIES (Krenn et al., 2020) is a string language every word of which is a molecule, by rules whose state is the valence left. These are grammars of a linear notation of the graph.
Hypergraph grammars. Kajino (2019) is the nearest predecessor. A molecule is a hypergraph whose hyperedges are atoms and whose nodes are bonds; a hyperedge replacement grammar is read off tree decompositions of the molecules of a collection; valence holds by construction, since an atom is made by one rule that carries all its bonds. On ZINC the grammar has 2,031 rules and derives 99.68% of 5,000 test molecules; it has no probabilities and serves as the decoder of a variational autoencoder. Kraev and Harley (2019) make such a grammar probabilistic, with rule probabilities conditional on the parent rule, and use it as a prior for a neural policy; they report distributional scores of its samples and no likelihood. Guo et al. (2022) learn a grammar from tens of molecules by contracting hyperedges, Sun et al. (2024) a context-sensitive grammar over motifs, and Sun et al. (2025) build a clique tree of a triangulated molecule and turn it into a hyperedge replacement grammar. Two months before this study, Huang et al. (2026) presented a context-free grammar on combinatorial complexes whose cells are motifs, as a “higher-order” grammar of molecules, with benchmarks at scale.
Comparison. All of these, like the grammar here, come from a tree decomposition. In all of them a ring, or a larger motif, is one bag of the decomposition and so one letter; the width is unbounded and the alphabet is learned and open. Here the bags are simplices of at most four atoms, every production adds one atom, and a ring of any size is a sequence of triangles on virtual edges, so the alphabet is small and closed under ring systems never seen. None of the grammars above defines a canonical derivation, reports the code length of held-out molecules, or conditions a rule on the length of the ring it would close. Against Huang et al. (2026) in particular: simplices of a chordal completion against motif cells; a bounded width with a stated residue; an explicit probability law measured in bits against a grammar inside a neural model.
2.2 Graph Grammars from Tree Decompositions
2.3 Treewidth of Molecular Graphs
That molecules have small treewidth has been observed since Yamaguchi et al. (2003), who found all but one of 9,712 compounds of KEGG LIGAND within width three, and it is used for mining
PDF page 9
(Horváth et al., 2013) and for chemical descriptors, where Conrado et al. (2023) invoke Courcelle’s theorem and report heuristic widths for PubChem. Junction trees in molecular generation (Jin et al., 2018) use clusters of unbounded size, and Ahn et al. (2022) generate a spanning tree with residual ring-closing edges under valence masks, the neural form of a pending ring closure.
2.4 Code-Length Evaluation of Probabilistic Grammars
A probabilistic context-free grammar estimated by relative frequency is a subcritical branching process (Booth and Thompson, 1973; Chi, 1999), and annotating a nonterminal with its parent is a refinement that leaves the grammar context-free (Johnson, 1998). Rules with application conditions and with context are studied for graph grammars (Drewes and Hoffmann, 2015; Habel et al., 1996). For molecules, bits per molecule are reported for chemical language models by Balaji et al. (2025): 25.6 on MOSES at 32 million parameters. Graph diffusion models report a variational bound over ordered labelled graphs (Vignac et al., 2023), which is not comparable with a code on canonical descriptions.
2.5 Additive Property Models
Benson’s group additivity (Benson and Buss, 1958; Cohen and Benson, 1993) estimates thermochemical properties as sums over groups (an atom with its neighbours) with corrections for rings and for interactions between groups that are not neighbours. On quantum-chemical data the bag of bonds (Hansen et al., 2015) is the modern relative. The Fisher score of a generative model (Jaakkola and Haussler, 1998) embeds an object by the gradient of its log-likelihood; for a grammar with one derivation per object it is a reweighted vector of production counts, on which an additive property is a linear functional. Section 9 measures additive readings rung by rung and claims no more than that.
3 Simplicial Words for Molecular Graphs
3.1 Molecular Graph Convention
Convention 1 (molecular graph). A molecule is a connected graph whose vertices are its atoms other than hydrogen and whose edges are its bonds. A vertex is labelled by its element, its formal charge, its isotope where one is given, and its valence, the number of bonds it takes part in, hydrogens included: C:4, N+:4, O-:1. An edge is labelled by its order, 1, 2 or 3. Aromatic rings are written in one Kekulé form, chosen canonically. Stereochemistry is not read: the molecule is its constitution.
The number of hydrogens on an atom is its valence less the sum of the orders of its bonds, so hydrogens need no vertices. Two descriptions of one constitution that differ in where a ring’s double bonds are placed must not become two molecules; the implementation finds a Kekulé form as a perfect matching over the aromatic bonds and then places the double bonds that resonance moves by the first perfect matching in a canonical order of the molecule with those bonds left unsaid (Appendix B). It is held to RDKit (RDKit, 2026) on 1,305 molecules: the same formula, the same hydrogens, and the same classes of equal molecules.
3.2 Definition of Stacked Words
PDF page 10
far. The word spells the labelled graph of its labelled edges. It is attached when every cone has at least one labelled edge.
The proof is the classical correspondence between elimination orders and tree decompositions, recalled in Appendix A: the word read backwards is an elimination order of the graph with its virtual edges, and the virtual edges are its fill.
3.3 Canonical Reading
A graph has many words. The reading chooses one in three steps.
1. Ranking. The vertices are ranked by a canonical labelling of the labelled graph (a search of the kind of McKay and Piperno 2014), so that nothing below depends on how the atoms were numbered.
Proof. (a) and (b) hold by construction: every choice is made by canonical ranks or by labels. (c) A vertex eliminated from a connected graph on at least two vertices without disconnecting it has
PDF page 11
(a)
(b)
4
3
5
O C C
0
2
O:2 C:4 C:4 0/1 1/1
1
0/1 0,1/~,2 0,2/~,1 0,3/~,2 0,4/2,1
9
7
(c)
6
4
3
5
0
2
1
two fans, about atoms 0 and 4, glued along the bond 4–5
a neighbour among those that remain; that neighbour is in its base, joined by a labelled edge. (d) is what the search decides.
The rule of connection in step 2 is what makes (c) true, and (c) is wanted for a reason of grammar: a word every cone of which has a labelled edge spells a connected graph, so a grammar of attached words never draws a molecule in pieces. The rule has a price.
Caveat (residue). The rule of connection can cost width. Cubane has treewidth three and no reading of width three: whichever atom is written last, its three neighbours must already be pairwise joined, and no connected order within bases of three brings that about. The search proves this by exhaustion. Such molecules are refused, and Section 6 counts them.
3.4 Validity Condition
Let every vertex label carry its valence as a capacity and every bond its order as a weight; virtual edges weigh nothing. The load of an atom in a word is the weight of its bonds.
Proposition 6 (validity). An attached stacked word over the labels of Convention 1 spells a molecule if and only if no atom’s load exceeds its capacity. The hydrogens of each atom are then its capacity less its load.
This is immediate from the convention: a labelled graph with bonds of orders 1 to 3 is a molecular graph exactly when each atom’s bonds fit its valence, and the word is already in a Kekulé form. Its use is that validity becomes a local condition on growth: a cone fits when it overloads neither its apex nor an atom of its base.
4 Formal Grammar of Stacked Words
Section 3 defined stacked words as objects. This section defines the grammar that derives them. It is a grammar of hyperedge replacement (Drewes et al., 1997; Habel, 1992): a nonterminal is a hyperedge attached to the vertices of a face, and a production replaces it by a simplex glued on that face together with the faces the simplex opens. The section gives the signature of labels, the terminal alphabet, the nonterminals, the three schemata of productions, sentential forms, derivations and the language derived; it proves that derivations and words in their order of growth
PDF page 12
correspond one to one, so that the canonical reading of a molecule is one derivation; it states the levels of context as functions on sentential forms, and shows that valence can be carried in the nonterminals instead of being read from the molecule. It ends with a complete derivation and with the grammars learned from the three collections. Every object defined here is one the implementation holds; the code’s names are given where they differ.
4.1 Signature of Labels
4.2 Terminal Alphabet
4.3 Nonterminals
PDF page 13
4.4 Sentential Forms and Productions
PDF page 14
(a) root
(c) close
4.5 Derivation Trees and the Order of Growth
Because every left side is a single hyperedge, a derivation is determined, up to the order of its steps, by its derivation tree: a node for each hyperedge that ever appears, labelled by the production applied to it, with the hyperedges its right side creates (the continuing one first, then the opened ones in their order) as its children. The terminal form depends on the tree alone, up to isomorphism; this is the context-freeness of hyperedge replacement (Habel, 1992, ch. I). The contexts of Section 4.6, however, read the form as it stands, and for them the order of the steps matters. The grammar fixes it.
PDF page 15
The canonical reading orders the cones on one face by their letters and then by the rank of their apex, so a canonical derivation is a derivation whose glues on each face come in a fixed order. Many derivations spell one graph: they differ in the root, in how the graph was eliminated, and in the order of cones with equal letters. One of them is canonical, and by Proposition 5(b) two graphs have the same canonical derivation exactly when they are isomorphic. This is the sense in which the grammar’s derivations and molecules correspond, and the sense in which Section 9 asks whether a derivation decides what a molecule does.
4.6 Levels of Context as Context Functions
face
parent
PDF page 16
span
room
size
4.7 Valence Carried in the Nonterminals
The room is read from the form, and it is shared: an atom lies on several open faces, and what one of them takes the others cannot. That makes the valence context-sensitive in this grammar. It need not be: the share of each face can be decided when the face is opened and carried in its nonterminal.
PDF page 17
4.8 Generative Capacity of the Context Levels
The remark is an immediate corollary of a known theorem; we did not find it stated for molecules, and it fixes how the ladder should be read. What a level changes is the law, the number of counts the law needs, and whether what is drawn is well formed without rejection. The levels are therefore compared in bits and by what they draw, never by what they can derive.
Caveat. We make no claim that the language of valid SMILES strings fails to be context-free. With unboundedly many rings open at once the matching of ring-closure digits is not context-free, and the grammar of Kusner et al. (2017) does not enforce it; with a bounded number of ring labels it plausibly is. No proof either way was found.
4.9 Complete Derivation of Benzene
4.10 Grammars Learned from the Collections
Table 2 counts the grammar each collection’s training words use: its alphabet by arity, its face types, its nonterminals and its productions. The alphabet is small and mostly unused: of the letters the signature admits, a collection uses between a sixth and a quarter. The productions are a small fraction of the pairs of a nonterminal and a letter, because most letters are seen on few faces: a carbonyl’s face C:4,O:2|2, for instance, is closed every time it is served in MOSES and carries no letter at all. Table 3 shows four of MOSES’s nonterminals with the productions seen there and their relative frequencies, and Appendix E lists the grammar further; the complete grammars, every production with its count, are among the experiment’s results.
PDF page 18
step face served span room size production faces opened
QM9 ZINC250k MOSES
training words 120,911 223,261 1,584,659 atom labels 9 20 9 of them root letters 7 12 7 letters admitted 258 554 244 letters used 59 88 56 on a vertex (edges) 15 33 16 on an edge (triangles) 26 45 28 on a triangle (tetrahedra) 18 10 12 face types of arity 1, 2, 3 9, 70, 300 20, 184, 560 9, 76, 302 nonterminals (face type, count) 497 933 485 productions 478 732 407 rules, with closes and roots 1,011 1,744 942 contexts at the parent level 3,311 4,243 2,584
PDF page 19
root O:2
Figure 3: The derivation tree of ethanol. Each node is a hyperedge, with the production applied to it; its children are the hyperedges that production creates, the continuing one first. Served in the order of growth (the queue), the tree writes the canonical word O:2 C:4 C:4|0/1 1/1: eight steps, one root, two glues and five closes.
Table 3: Four nonterminals of the context-free grammar learned from MOSES, with the outcomes seen there (at most six shown), their relative frequencies and the faces each glue opens, separated by semicolons. On a carbon’s own face the grammar closes slightly more often than it glues; on a virtual edge of two carbons it nearly always glues, since a virtual edge is there to be closed by a ring; on a double bond of two carbons it mostly closes, and when it glues it begins the next triangle of a fan.
nonterminal and outcome relative frequency faces opened
5 Stochastic Grammar
PDF page 20
5.1 Probability Law and Estimation
A grammar may be conditioned on what fits: letters that would overload their apex or an atom of the face are given probability nought and the rest are renormalised. By Proposition 6 every complete word of a conditioned grammar is a molecule.
5.2 Code Length of Canonical Words
A grammar gives a probability to a word, and a molecule has many words, of which the reading is one. The bits of the reading therefore bound the bits of the molecule from above:
5.3 Branching-Process Structure of the Context-Free Level
Proposition 18. The context-free grammar estimated by relative frequency from a finite collection of words is a multitype Galton–Watson process whose types are the faces. Its mean matrix has spectral radius below one, and the expected number of atoms of a word and its expected bits are the collection’s means.
The first part is the theorem of Chi (1999) for probabilistic context-free grammars; the second follows from counting faces by the type that opened them (Appendix A). So the mean size is right by construction. The law of sizes is another matter: the total progeny of a branching process near criticality is broad, whatever the sizes in the collection were. A grammar that reads the span or the room is no longer a branching process, since events at two faces depend on each other through the molecule; but no face oversees the whole, and the same breadth is to be expected.
PDF page 21
Caveat. Valence here is read from the state of the molecule, not carried in the nonterminals as Proposition 17 could carry it. In the encoding of Kajino (2019), where atoms are hyperedges, an atom is made by one rule with all its bonds and valence costs nothing. With atoms as vertices, an atom lies on several faces waiting in the queue, and the valence it has left is shared among them: the law then depends on the order in which faces are served, which is why that order is fixed.
6 Corpora and Coverage
6.1 Corpus Sources and Splits
QM9 (Ramakrishnan et al., 2014) holds 133,885 molecules of at most nine atoms of C, N, O and F besides hydrogen, taken from the enumeration GDB-17 (Ruddigkeit et al., 2012), each with a geometry relaxed by density functional theory and computed properties; it is under CC0 1.0. It is close to an enumeration of what such atoms can make under GDB’s rules, so the novelty of a drawn molecule against it is no merit, and its regularities are the chemistry of small molecules rather than a chemist’s choices. Words are split at random into a part learned from (120,911) and a part held out (12,865), by a fixed hash of the molecule’s index.
ZINC250k (Gómez-Bombarelli et al., 2018) holds 249,455 drug-like molecules drawn from ZINC (Irwin et al., 2012), with up to 38 atoms besides hydrogen; it is distributed in a repository under Apache-2.0. It is split as QM9 is (223,261 and 24,541).
MOSES (Polykovskiy et al., 2020) holds 1,936,962 lead-like molecules in the benchmark’s own parts: 1,584,659 to learn from, 176,074 held out, and 176,225 held out whose Bemis–Murcko scaffolds occur in no other part (MIT licence).
All three are fetched by the data library of the infrastructure into a cache and never committed; each molecule is read from its SMILES by the reader of Section 3, stereochemistry ignored.
6.2 Treewidth Distribution and Residue
Table 4 gives, for each collection, the exact treewidth of every molecule (computed by the exact search of the reading, not by a heuristic), the number that have no reading of width three, and what the readings are made of.
Three things stand out. First, molecules are thin: in every collection all but a fraction of a per cent have treewidth at most two, and so are written with edges and triangles alone; tetrahedra are needed only for fused cages and bridged systems. Second, the alphabet is small and closed: 59, 88 and 57 letters, against the 2,031 rules that Kajino (2019) learn from ZINC with whole rings as letters. Third, the residue is tiny and has one cause.
Residue. All 22 molecules of QM9 without a reading are cages of treewidth three whose greedy connected order needs four: cubane (C12C3C4C1C1C2C3C41) and its aza and oxa analogues, cuneane-like and homocubane-like skeletons, and their methyl and hydroxy derivatives. ZINC250k has 2, a cubane diol and a polycyclic cage; MOSES has 4, two cages of treewidth three and the only two molecules of the three collections whose treewidth is four. In every case the exact search proves that no connected order within bases of three exists, and the cause is the one of the caveat in Section 3: the rule of connection, not the width, excludes the cages of treewidth three. A reading of width four would take all of them.
Duplicate words. 87 molecules of QM9 have the word of an earlier molecule. Each is the same molecule given twice in the collection under two Kekulé forms (2-methylpyrazine as CC1=CN=CC=N1 and as CC1=NC=CN=C1, and the like), computed twice; Section 9 uses them. The 1,651 molecules of ZINC250k with an earlier molecule’s word are stereoisomers, which the alphabet does not read (Section 9.7).
PDF page 22
Table 4: The three collections as words. Treewidth is exact. “No reading” counts molecules with no connected elimination order within bases of three atoms (Proposition 5(d)); “same word” counts molecules whose word equals that of an earlier molecule of the collection.
QM9 ZINC250k MOSES
molecules 133,885 249,455 1,936,962 read as words 133,776 247,802 1,936,958 the same word as an earlier one 87 1,651 0 no reading of width three 22 2 4
treewidth 1 (trees) 13,995 1,097 674 treewidth 2 107,111 245,505 1,931,173 treewidth 3 12,689 1,202 5,113 treewidth 4 0 0 2
atoms per molecule (mean) 8.8 23.2 21.7 atom labels 9 20 9 letters 59 88 57 cones over one atom (edges) 599,051 3,023,201 22,082,927 cones over two (triangles) 425,620 2,464,112 17,937,531 cones over three (tetrahedra) 18,230 2,630 11,765 virtual edges 247,061 1,787,631 12,955,981 molecules with a tetrahedron 12,669 1,201 5,112
7 Code-Length Evaluation of the Context Levels
7.1 Within-Collection Evaluation
Each grammar is learned from the words of a collection’s training part and prices the words of its held-out part. Table 5 gives the bits per held-out molecule at each level, and Figure 4 the same per atom. Within a collection a grammar conditioned on what fits prices held-out words as the unconditioned one does, to within a hundredth of a bit, since the unconditioned grammar already gives almost nothing to a letter that overloads an atom; the table shows the conditioned grammars.
Four findings are robust across the three collections.
2. Span and room. Told the parent, the length of the ring a closure would make saves 0.1, 2.6 and 2.5 bits a molecule (QM9, ZINC250k, MOSES); the valence left on the face’s atoms saves 3.4, 9.8 and 9.0; both together 3.5, 11.4 and 10.5. The parent already says much about where a fan stands; what it does not say is mostly how full the atoms are.
3. Size. It is the one context that is not local. Its value is not in the price of a typical event but in when to stop: Section 8 shows that grammars of local context draw molecules whose sizes are wrong, and that this level moves the body of the law of sizes to the collection’s, though not its tail.
4. Unseen scaffolds. MOSES’s scaffold test, whose ring systems occur in no molecule learned from, costs at most 1.4 bits a molecule more than the ordinary test at any level, and 0.3 at the richest; per atom the two differ by less than 0.017 bits. With rings as fans of triangles, a ring system never seen is a new arrangement of letters already seen, not a new letter.
PDF page 23
Table 5: Bits per held-out molecule, by level of context. Each level knows what the one before it knows. Below each collection, the number of contexts of the last level.
Figure 4: Bits per atom of held-out molecules at each level of context, within each collection. The step from the face to its parent is the largest in all three; the valence left (room) is worth more than the length of a ring (span); the number of atoms so far is worth 2.7, 4.2 and 4.6 bits per molecule.
7.2 Cross-Collection Evaluation
A grammar learned from one collection and asked to price another tells how much of what it learned is chemistry and how much is the collection. Table 6 gives the bits.
The ladder keeps its shape in one direction only. ZINC250k’s grammar prices MOSES at 45.5 bits at the richest level, every level saving bits, against MOSES’s own 42.9: MOSES’s lead-like molecules are a narrow region of what ZINC250k covers. MOSES’s grammar prices ZINC250k best at the parent and the room and worse at the span and the size. QM9’s grammar prices the drug-like collections best at the parent level and worse at every level that reads the span, the room or the size, and the drug-like grammars price QM9 worse at every level above the face: QM9’s molecules stop at nine atoms, ZINC250k’s begin near ten, and QM9 has none of the charged atoms, sulphur and halogens of the other two (9 atom labels against 20). Conditioning on what fits saves up to 1.3 bits a molecule across collections (QM9 to ZINC250k), where within one it saved less than a hundredth: a grammar learned elsewhere does give probability to letters that overload. The lesson is the familiar one of smoothing. A richer context is a sharper law, and a sharper law of another collection is worse than a blunter one. The ladder is a measurement of a collection’s regularities, not of chemistry’s.
PDF page 24
Table 6: Bits per molecule of one collection’s held-out part under grammars learned from another.
7.3 Learning Curve
Figure 5 gives the bits of MOSES’s held-out molecules under grammars learned from 1,000, 10,000, 100,000 and all 1,584,659 of its training words. The context-free grammar has learned almost all it can from a thousand molecules (it gains 3.1 bits more from the other million and a half); the richer levels keep improving, and the size level, with 78,970 contexts, is still improving at the full collection. From a thousand molecules the size level is worse than the level below it: it has more contexts than it has seen events to fill.
7.4 Comparison with Other Codes
The richest grammar prices a held-out molecule of MOSES at 42.9 bits, 1.98 bits per atom. Balaji et al. (2025) report 25.6 bits per molecule for a language model of SMILES with 32 million parameters on the same test, 1.7 times fewer. The two numbers are not of the same protocol, and the difference runs both ways: the language model codes one string of the molecule and is not charged for the other strings that spell it, which a canonical SMILES makes few; the grammar codes the canonical word and is charged for words that are not canonical (Section 5). The second correction can be measured. Of the words the richest grammar draws, 20.5% are complete, valid and canonical, so a code restricted to canonical words saves 2.29 bits a molecule and the grammar’s code on MOSES is 40.6 bits; on QM9 20.3 and on ZINC250k 48.2. A neural model still needs markedly fewer bits, and the paper claims nothing to the contrary: what the grammar offers is a law of a few thousand counted contexts in which every bit can be traced to a face and a letter.
8 Sampling Evaluation
8.1 Protocol
What the study wrote is then judged by an independent toolkit, RDKit (RDKit, 2026), which parses and sanitises every molecule again and computes the measures. Uniqueness and novelty are counted by RDKit’s canonical SMILES; novelty is against the whole training part. The drawn molecules are compared with 10,000 held-out molecules of the same collection by Wasserstein distances between the laws of their sizes, ring counts, log P and QED; by the total variation
PDF page 25
Figure 5: Bits per held-out molecule of MOSES against the number of molecules learned from, at four levels. The dashed line is the code length reported for a chemical language model of 32 million parameters on the same test (Balaji et al., 2025); its protocol (canonical SMILES, a byte-level code) differs from ours.
between the laws of ring sizes and of elements; by the cosine similarity of the counts of BRICS fragments (Degen et al., 2008) and of Bemis–Murcko scaffolds (Bemis and Murcko, 1996), the measures Frag and Scaf of MOSES (Polykovskiy et al., 2020), computed here rather than by the MOSES package; and by the Fréchet ChemNet distance (Preuer et al., 2018) between at most 10,000 drawn molecules and the reference. As a scale for each measure, a second set of 10,000 held-out molecules is compared with the first in the same way.
8.2 Agreement with the Independent Toolkit
RDKit accepts every one of the 457,533 molecules the study wrote, and its count of distinct molecules in each of the eighteen sets of samples equals the study’s own count by its key. For the conditioned grammars no complete word overloads an atom, as Proposition 6 requires; their only failures are words that are stopped unfinished.
8.3 Results
Table 7 gives the measures for each collection and grammar.
Sizes. The grammars of the lower levels draw molecules far too small: the context-free grammar’s molecules have 1.86 atoms on average where MOSES’s have 21.66. This is the breadth of Proposition 18 at work: the mean size is right only in expectation over a law dominated by words that close at once and a few that run on. Valence and ring length, read from the molecule so far, move the mean much closer (17.97) but leave the law broad (Figure 6). The size level moves the body of the law onto the collection’s: the Wasserstein distance of sizes falls from 11.46 to 3.93 atoms on MOSES, from 11.39 to 4.16 on ZINC250k and from 3.40 to 1.21 on QM9. It does not mend the tail. A word that has grown past every size seen in learning reads a size it has never been told about, the law backs off to the local levels, and nothing tells it to stop; 3.5% of MOSES’s words, 3.0% of ZINC250k’s and 2.0% of QM9’s are stopped at 200 atoms. A size that counts beyond forty, or a backoff that treats a size never seen as “past the largest”, would be the next repair.
Validity and repetition. Unconditioned grammars of the parent and the span levels overload an atom in between 27.6% (QM9) and 39.7% (MOSES) of their words, because the parent says where
PDF page 26
a fan stands but not how full its atoms are. Reading the valence left brings validity above nine tenths, and conditioning makes every complete word valid. The context-free grammar repeats itself (few distinct molecules, mostly of one or two atoms); uniqueness rises with the parent, with the valence left and most with the size, while the span alone leaves it as it was: 90.4% of MOSES’s valid molecules are distinct, and 99.8% of the distinct ones are not in the training part. On QM9 only 55.9% are novel, as expected of an enumeration whose molecules a good grammar of nine atoms must keep finding.
Distribution. The Fréchet ChemNet distance falls with each level of context (conditioning changes it little), to 7.80 on MOSES with the size level, against 0.26 between two sets of held-out molecules; Frag and Scaf rise towards the held-out values. In the drug-like collections the law of ring sizes is nearly right from the level of the span on (its total variation from the held-out law falls from 0.413 to 0.023 on MOSES), and the law of elements from the parent on, which is what a grammar that knows ring lengths should achieve. What remains is mostly the size law’s tail and the long-range composition of drug-like molecules (how many rings a molecule carries, and where its heteroatoms are), which no local context sees.
8.4 Comparison with Published Models
Vignac et al. (2023) report, under the MOSES protocol, validity, uniqueness, novelty and FCD of 97.7%, 99.8%, 69.5% and 0.57 for a SMILES variational autoencoder, 100%, 100%, 99.9% and 1.00 for the junction-tree autoencoder (Jin et al., 2018), and 85.7%, 100%, 95.0% and 1.19 for DiGress itself. The richest grammar here gives 96.5% valid (all of its complete words), 90.4% unique,
PDF page 27
QM9
held out span and room span, room and size
share of molecules
ZINC250k
MOSES
0 20 40 60 atoms other than hydrogen
0 10 20 30 atoms other than hydrogen
0 20 40 60 atoms other than hydrogen
Figure 6: The law of the number of atoms of molecules held out (grey), and of molecules drawn from the conditioned grammar of span and room (solid) and of span, room and size (dashed), up to 30 atoms for QM9 and 60 for the others; in those two panels the last point gathers the molecules of 60 atoms or more.
99.8% novel and an FCD of 7.80. The protocols differ (MOSES computes FCD on 30,000 molecules against its test set, here on at most 10,000 against 10,000 held-out ones, which scales FCD up), but not by enough to change the reading: in validity and novelty the grammar is comparable to the neural models; in uniqueness it is somewhat behind them, and in distribution far behind. That is consistent with the ladder of Section 7: a local grammar captures the syntax of molecules and not the long-range statistics of what chemists choose to make.
9 Compositional Semantics of Derivations
9.1 Problem Statement
The hypothesis that motivates this section is that the structure of the generation process, the derivation and not only what it produces, decides what a molecule means. Before it can be tested it has to be said what “the same derivation” and “the same molecule” are, since the hypothesis is a claim that one equivalence is finer than the other. Section 9.7 makes the equivalences explicit. Its conclusion, which shapes everything before it, is this: a canonical derivation is a function of the molecule’s constitution, so within one grammar two isomorphic molecules cannot have different derivations, and the hypothesis cannot be tested in its strongest form. What can be tested, and is, is the hypothesis in degrees. A derivation has parts, and coarser descriptions forget how the parts are put together. The question then becomes how much of a property is fixed by what a molecule is made of, how much by the productions that made it, and how much by the arrangement of those productions in the derivation.
9.2 Rungs of Derivation Parts
PDF page 28
formula
the counts of the elements, hydrogens among them (the “dressed atoms” of the literature);
bonds
the counts of the atom labels and of the bonds by the labels of their ends and their order: what the molecule is made of, however it is read;
productions
the events at rung face: at each face, the letter glued there or the closing;
parent
the events told also the letter that opened the face;
span
the events told also the distances between the ends of the face’s edges.
Proof. From span to parent to productions: forget part of the context and add the counts that become equal. From productions to bonds: a production names its face’s labels and its letter, which gives the apex’s label and the label and order of each bond it makes; summing over productions counts each atom once (as an apex, or as the root drawn by the first event) and each bond once. From bonds to formula: the elements are read off the labels, and the hydrogens total the valences less twice the sum of the bond orders.
So the rungs are an ascending chain of descriptions, each a coarsening of the next and all of them coarsenings of the derivation. The step from bonds to productions is the first that sees the derivation at all; the step from productions to parent is the first that sees how the productions are arranged, since a production’s parent is the production that made the face it acts on.
9.3 Data and Regression Protocol
9.4 Held-Out Accuracy by Rung
Table 8 gives the mean absolute error on held-out molecules at each rung.
PDF page 29
property s.d. formula bonds productions parent span
atomisation energy 996.51 83.73 47.51 31.81 16.66 16.22 zero-point energy 87.03 3.63 2.50 1.32 0.91 0.90 heat capacity 17.00 7.16 3.58 2.09 1.33 1.31 polarisability 8.18 2.15 1.35 1.07 0.78 0.77 dipole moment 1.50 0.99 0.85 0.80 0.74 0.74 HOMO 0.60 0.41 0.27 0.23 0.18 0.18 LUMO 1.27 0.76 0.45 0.39 0.31 0.31 HOMO–LUMO gap 1.28 0.82 0.52 0.48 0.36 0.36
Every property is read better at every rung than at the one below, and the span adds almost nothing to the parent. The atomisation energy falls from 47.51 kJ/mol with bonds, the level of a bond-additivity scheme, to 16.66 with the productions and their parents. These numbers are not a contest with learned models, which reach about 1 kJ/mol on the same data; they measure how much of each property is a sum over parts of a given kind.
9.5 Within-Group Analysis at Fixed Atoms and Bonds
The readings above confound two things: a richer rung may read a property better because it sees more of what the molecule is made of, or because it sees how the parts are put together. The second can be isolated. Group the molecules by their counts at rung bonds. By Proposition 20 no function of atoms and bonds, linear or not, tells two molecules of one group apart; whatever separates them is a matter of arrangement.
It is zero for every reading at rung bonds or below, one when a reading gets every difference within every group right, and may be negative.
The held-out molecules fall into 1,621 groups that hold at least two of them, 11,035 molecules in all. Figure 7 and Table 9 give the shares.
Three things are read off the table.
1. Magnitude. Among molecules made of exactly the same atoms and bonds, the atomisation energy still varies with a standard deviation of 50.20 kJ/mol. The productions of the derivation tell 0.52 of those differences, and the productions with their parents 0.84. For the zero-point energy and the heat capacity the parents tell 0.87 and 0.86.
2. Comparison with the best function of atoms and bonds. The mean of a group’s training members is the best that any function of atoms and bonds can do there. For the atomisation energy it errs by 38.95 kJ/mol; a linear reading of the productions errs by 31.67, and of the productions with their parents by 16.19. The same holds for the zero-point energy, the heat capacity and the polarisability. For the HOMO and the gap the productions alone do worse
PDF page 30
Figure 7: The share of the differences among held-out molecules made of the same atoms and bonds that the derivation’s parts tell, at the rungs productions (circles) and parent (squares). Properties are ordered by the second.
Table 9: Within groups of held-out molecules made of the same atoms and bonds: the standard deviation of each property within groups, and the share of it told at each rung. The last two columns compare, over the 12,118 held-out molecules whose group has members in the training part, the error of the best function of atoms and bonds (the group’s training mean) with that of the reading at rung parent.
s.d. within explained share, by rung mean absolute error
property groups productions parent span group mean parent
atomisation energy 50.20 0.52 0.84 0.85 38.95 16.19 zero-point energy 2.84 0.75 0.87 0.87 2.27 0.89 heat capacity 4.09 0.69 0.86 0.86 3.31 1.32 polarisability 1.43 0.23 0.60 0.61 1.16 0.77 dipole moment 0.82 0.06 0.17 0.17 0.70 0.72 HOMO 0.24 0.17 0.43 0.43 0.21 0.18 LUMO 0.37 0.11 0.40 0.41 0.30 0.31 HOMO–LUMO gap 0.45 0.09 0.47 0.47 0.38 0.36
than the group mean and the productions with their parents better; for the LUMO and the dipole neither beats it.
3. Order of properties. The energies and the heat capacity are told best; the polarisability, the frontier orbitals and the gap about half; the dipole moment least (0.17). The order is that of how local each property is (Section 11.1): a total energy is nearly a sum of local contributions; a frontier orbital energy is an edge of a spectrum and depends on how far a conjugated system reaches; a dipole moment is the magnitude of a vector sum whose directions a graph does not record.
9.6 Model-Free Class Analysis
PDF page 31
can only fall. The table gives the standard deviation pooled over the classes of several molecules, which need not fall (the molecules left alone in their classes leave the pool) and does. Table 10 and Figure 8 give it.
Table 10: Classes of QM9’s molecules with equal parts at each rung, and the standard deviation of each property within classes of several molecules (pooled). The last row of the upper part counts molecules that are alone in their class.
formula bonds productions parent
classes 616 7,308 55,932 109,879 classes of several molecules 522 5,686 22,126 13,452 largest class 6,094 1,496 91 17 molecules alone in their class 94 1,622 33,806 96,427
atomisation energy 101.04 51.82 20.85 9.32 zero-point energy 4.47 2.94 1.15 0.80 heat capacity 8.79 4.23 1.98 1.32 polarisability 2.82 1.67 1.27 0.92 dipole moment 1.28 0.90 0.68 0.59 HOMO 0.53 0.26 0.17 0.13 LUMO 0.92 0.38 0.27 0.25 HOMO–LUMO gap 0.97 0.48 0.33 0.24
Two observations follow. First, the multiset of productions with their parents almost names the molecule: within QM9, 73.8% of molecules are alone in their class at rung parent, against 1.2% at rung bonds. Second, where it does not, what is left is arrangement in the strict sense: the molecules of a class at rung parent have the same productions, each with the same parent, and differ only in how those pieces of tree are assembled. The spread left is small on the whole (the median range within a class is 9.84 kJ/mol for the atomisation energy and 0.22 eV for the gap) and large in places. The widest class in the gap holds C(CNCCO)(C=O)=O (QM9 122806, gap 3.12 eV) and C(C(NCCO)=O)C=O (QM9 121719, 6.01 eV): the same productions with the same parents, but in the first the two carbonyl groups are joined into a 1,2-dicarbonyl, a conjugated system, and in the second they are separated by a methylene. Conjugation is a relation between parts, made by where one production is attached relative to another, and the gap follows it. The widest class in the atomisation energy holds two tricyclic ethers, CC12C(C3CC1O3)CO2 and CC1CC23C(C1O3)OC2, which differ by 243.31 kJ/mol: the same pieces, closed into rings of different strain.
These pairs are not counterexamples to the hypothesis that the derivation decides the property. They are examples for it, in the sense of degrees: two molecules with the same multiset of steps, even counting each step with the step it came from, but with different derivation trees, and different properties because of the difference.
9.7 Equivalence of Derivations and Duplicate Words
constitution
configuration
constitutions with the handedness of each stereocentre and the sense of each stereogenic
PDF page 32
within-class standard deviation /
standard deviation over QM9
10−1
10−2
dipole moment 0.39
HOMO–LUMO gap 0.19
heat capacity 0.078
atomisation energy 0.009
formula atoms and bonds productions productions with parents
Figure 8: The spread of four properties among molecules that share all the parts of a rung, as a share of the property’s standard deviation over QM9 (logarithmic scale). Each step to the right refines the classes.
conformation
configurations with a geometry, up to the rigid motions of space.
Derivations have their own equivalences: equality of words; equality up to renumbering; and equality up to the order of events that do not depend on one another (Section 11.1).
Corollary 23. Within a grammar of canonical words, no two isomorphic molecules have different derivations. A difference of property between two molecules with the same constitution cannot be explained by their derivations; it is a difference in something the constitution forgets.
The corollary separates two readings of the hypothesis. As a statement about canonical derivations of constitutions it says that a property is a function of the constitution, which can only fail through what the alphabet does not read. As a statement about derivations that carry more than the constitution (orientation, symmetry, transformations in space, or the history by which a molecule was in fact made) it has content: two molecules isomorphic as graphs may then have different derivations, and the derivation may then tell their properties apart. Section 10 states
PDF page 33
grammars of that kind formally and builds the first of them. Here both ends of the present grammar are measured.
Duplicate words in QM9. 87 pairs of QM9’s molecules share a word (Section 6). RDKit, reading the SMILES of each relaxed geometry with its stereochemistry, finds every pair to be one and the same molecule, given twice under two Kekulé forms and computed twice. The two computations agree to the precision of the archive: at most 0.06 kJ/mol in the atomisation energy, 0.06 kJ/mol in the zero-point energy, 0.0027 D in the dipole and 0.0027 eV in the gap, one unit of the last digit kept. At the top of the ladder, then, the property is a function of the derivation, as Proposition 22 says it must be for a property of the constitution, and the canonical reading found a duplication that the collection’s own SMILES hid.
Duplicate words in ZINC250k. ZINC250k keeps stereochemistry in its SMILES, and 1,644 groups of its molecules (3,295 molecules) share a word. Every pair in them is a pair of stereoisomers: 842 pairs of enantiomers, and 816 of diastereomers (768 differing at stereocentres, 19 at double bonds, 28 at both, and 1 in which the two SMILES specify different numbers of marks). The collection’s computed descriptors do not tell them apart either: logP (Wildman and Crippen, 1999) and QED (Bickerton et al., 2012) agree within every pair, and the synthetic accessibility score differs in 11 pairs of diastereomers by at most 0.17. These pairs are where the present derivation is too coarse. Two molecules that are mirror images, and that may bind a protein quite differently, receive one derivation; if the derivation is to decide what a molecule does, as the hypothesis asks, then a grammar that gives mirror images one derivation breaks the hypothesis by its definition, not by the data. The remedy is in the letters: a cone over a face is a simplex, and an oriented simplex carries a sign. Section 10.2 builds the oriented reading and gives every one of these pairs two words.
9.8 Grammatical Surprise and Strain
A last reading asks whether the grammar’s probabilities themselves mean anything chemical. A grammar learned from ZINC250k prices each held-out molecule of QM9 in bits per atom; beside it is set the molecule’s strain, the part of its atomisation energy per atom that a reading at rung bonds does not account for. Of the 12,555 held-out molecules, 1,102 need a production never seen in ZINC250k. The correlation of price and strain is 0.25 (Pearson) and 0.28 (Spearman). Molecules in the cheapest tenth cost 2.74 bits per atom and lie −4.34 kJ/mol per atom below the bond sum; those in the dearest tenth cost 13.36 and lie 4.25 above it (Figure 9). Under QM9’s own grammar the correlation falls to 0.06 and 0.18: QM9 is an enumeration and prices its strained cages as ordinary, while a grammar of drug-like molecules, which rarely contain them, finds them surprising. The surprise of a molecule under a grammar of what chemists make is weakly but consistently a measure of its strain.
9.9 Assessment of the Hypothesis
Stated with its equivalences, the hypothesis that the derivation decides the semantics comes to three findings and a limit.
1. At the finest level of the present grammar it holds exactly for QM9: equal canonical words, equal properties. This is guaranteed for any property of the constitution and is no evidence for the hypothesis beyond that.
2. In degrees it holds strongly. A sum over the parts of the derivation tells 0.84 of the differences in atomisation energy among molecules made of the same atoms and bonds, more than any function of those atoms and bonds can, and the pieces of tree (a production with the production it came from) tell more than the productions alone for every property.
PDF page 34
Figure 9: QM9’s held-out molecules in tenths of their price under the grammar of ZINC250k, against their mean strain: the atomisation energy per atom that a sum over bonds does not account for (negative: more stable than the sum).
3. The degree depends on the property in an order that a theory of locality predicts: energies most, frontier orbitals about half, the dipole least.
4. The limit: two molecules that a chemist regards as different and a graph regards as the same, mirror images above all, receive one derivation. The hypothesis in the strong form in which it was put (isomorphic structures with different functions, told apart by their generation) needs derivations finer than constitutions. That is a requirement on the grammar, and Section 10 meets it for configurations and states how it would be met for symmetries and for conformations.
10 Variants of the Grammar
Section 9 ended at the boundary that the grammar’s equivalence sets: molecules that share a canonical word are one constitution, and in ZINC250k every group of molecules sharing a word is a group of stereoisomers. This section states three variants of the grammar of Section 4, each a change to one of its parts. The oriented grammar changes the letters: a glue may carry the orientation of the simplex it completes. The orbit grammar changes the nonterminals: an open face is replaced by its orbit under the symmetries of the molecule so far, and the choice of a representative is recorded. The transformation-labelled grammar changes the labels: a letter carries the rigid motion that places its apex, so that a derivation writes a conformation. The section begins with the equivalence any canonical grammar fixes, which is what the variants change. The oriented grammar’s reading is built and measured on all of ZINC250k; the other two are stated with worked examples.
10.1 Equivalence Fixed by a Canonical Grammar
PDF page 35
Remark. The canonical reading breaks a symmetry to choose one word. When a molecule has automorphisms, several numberings give the same word, and a grammar that summed over all derivations of a molecule instead of reading one would have to divide by the order of the automorphism group, as the symmetry factor of a Feynman graph does. Choosing the canonical word avoids the division and pays for it with the slack of Section 5.
10.2 Oriented Grammar
PDF page 36
The sign of a centre is fixed at the event that writes its third neighbour, because the fourth, if it comes later, can only take the remaining position of the tetrahedron. A sign therefore enters the derivation as one decoration on one glue, and a level of context that reads the signs already written near a face is the grammar’s account of diastereoselectivity. A configuration has several numberings that give its canonical word when its constitution has automorphisms, and the signs depend on the numbering; the reading takes the least.
Proposition 27 (oriented reading). (a) Two configurations have the same oriented reading if and only if they are isomorphic: there is an isomorphism of their constitutions that maps specified elements to specified elements and keeps every orientation and every cis or trans relation. (b) The oriented reading of a configuration’s mirror image is obtained from its own by reversing the sign of every centre and taking the least list again; a configuration is achiral exactly when its oriented reading is fixed by this operation. (c) The oriented reading does not depend on how the configuration is numbered or written.
The least list removes the proviso that a first design of this construction needed: there is no need to refine the canonical labelling by the stereodescriptors themselves, as rules of precedence such as CIP’s must, with their known difficulties of pseudo-asymmetry (Prelog and Helmchen, 1982). The cost is that the automorphisms of the word are enumerated, which for molecules is cheap.
Implementation and measurement. The reading is built (oriented.py in the experiment’s folder): the study’s program gives each word with the atom of the input each vertex is (study map), RDKit gives the specified elements and their orientations, and the automorphisms of the constitution are its self-matches that keep elements, charges, isotopes and hydrogens. Table 11 holds it to RDKit on all of ZINC250k. Its oriented words separate exactly the configurations that RDKit’s canonical isomeric SMILES separate: 249,453 oriented words for 249,453 configurations, none shared by two configurations and none of the configurations given two words. Every one of the 1,658 pairs of stereoisomers that shared a constitution word (Section 9.7) now has two words. The reflection of Proposition 27(b) is exact: of the molecules with signs, 1,684 have their mirror word held by another molecule of the collection, and in every case that molecule is their enantiomer. Rewriting the SMILES of 3,000 molecules three times at random never changes the oriented word, and on embedded conformers of 600 molecules all 946 centres have the sign the definition gives. Getting there found one error: the first version took a centre to need four neighbours or three and a hydrogen, so that a sulfoxide’s sulfur, whose fourth position is a lone pair, received no sign: nine groups of stereoisomers kept one word each, and sixteen mirror words were wrong. With the lone pair counted as the implicit fourth neighbour, all groups separate and every mirror word is right.
Examples. L-alanine and D-alanine have the constitution word O:2 C:4 C:4 O:2 C:4 N:3|0/2
PDF page 37
Table 11: Oriented words of ZINC250k held to RDKit. A configuration is a canonical isomeric SMILES of RDKit. Bits per sign: held-out signs priced by a model of each sign given the labels of the element and of its neighbours in the order of growth, learned on the training part with Krichevsky–Trofimov estimates and backoff.
measure value
molecules read 249,453 with a specified stereogenic element 157,335 specified tetrahedral centres 222,207 specified double bonds 17,447 numberings considered per molecule with signs, mean (largest) 3.14 (1,296)
oriented words 249,453 configurations 249,453 oriented words shared by two configurations 0 configurations given two oriented words 0 pairs of stereoisomers sharing a constitution word, separated 1,658 of 1,658
molecules whose oriented word is fixed by reflection 12,980 mirror words held by another molecule, and of them the enantiomer 1,684, 1,684 rewritten SMILES giving the same oriented word 9,000 of 9,000 centres whose sign agrees with an embedded conformer 946 of 946
signs held out 23,755 bits per sign held out 0.995
Cost and meaning. An orientation is at most one bit, so a grammar of configurations prices a molecule at most one bit per specified element above its constitution, and less wherever orientations are predictable from their context. In ZINC250k they are not: a held-out sign costs 0.995 bits given the labels of its element and its neighbours. The collection holds both hands of many compounds, and nothing local tells which a molecule has. In the language of the hypothesis, orientation is the smallest extension in which isomorphic graphs (enantiomers) have different derivations. Their derivations differ in signs alone, and their scalar properties in isolation are equal: energies, gaps, the magnitude of a dipole, and ZINC250k’s own logP and QED, which agree within every pair of enantiomers (Section 9.7). What differs is how they meet other chiral things: a receptor, polarised light, another enantiomer, an enzyme that makes one glycerol phosphate and not the other. The semantics that orientation carries is relational.
10.3 Orbit Grammar
At each step of a derivation the molecule so far has symmetries, and they act on its open faces. Faces in one orbit are equivalent for the constitution: gluing the same letter on any of them gives
PDF page 38
isomorphic results. The orbit grammar makes the orbit the nonterminal and the choice within it a recorded step.
The definition is the classification of Mislow and Raban (1967) made exact for the open faces of a form: two positions are homotopic if a rotation exchanges them, enantiotopic if only a reflection does, diastereotopic if they are equivalent in the constitution and no symmetry of the configuration, proper or improper, exchanges them.
PDF page 39
Requirements. The automorphism group of the form must be maintained as it grows, which for molecules is cheap (their groups are small; the oriented reading above met at most 1,296 numberings of a word) but must be done exactly; productions are then orbits of rules under a group, and parsing must bind group elements, as equivariant parsers do. The infrastructure in which this study was written already has grammars of that kind for nucleic acids, with rules that are orbits of a group acting on letters and an equivariant chart parser; carrying them to molecules means letting the group change from step to step, since the automorphisms of a growing molecule are not a fixed group acting on a fixed alphabet. The number of distinct molecules that the orbit grammar derives then follows from Burnside’s lemma applied step by step.
10.4 Transformation-Labelled Grammar
In quantum chemistry a molecule’s geometry is often written as a Z-matrix: each atom after the first is placed by its distance to one earlier atom, its angle with a second and its dihedral with a third (Cramer, 2004). A cone over a face of at most three earlier atoms is that, once its references are fixed.
PDF page 40
The closure condition is where rings live. A word that grows a tree of frames puts no condition on the transformations; a cone with two or three labelled edges closes a ring, and requires that the rigid motions composed around the ring return to where they began. In the word the condition is local to one glue, the one that closes the ring on a virtual edge: a flatness condition of the kind that the closure of loops in a graph of frames imposes, and an application condition in the sense of Section 4.6.
Proof. (a) Distances, angles and dihedrals are invariant under rotations and translations; a reflection keeps distances and angles and reverses the sign of every dihedral. (b) The positions are a function of the labels by Definition 32, and the sign is a function of the positions.
10.5 Composition of the Variants
The variants change different parts of the grammar and compose. Forgetting the transformations, keeping the signs they determine, maps transformation-labelled derivations onto oriented ones
PDF page 41
(Proposition 34); forgetting the signs maps oriented derivations onto derivations of the constitution grammar; and forgetting the representatives maps orbit derivations onto derivations of the constitution grammar, the canonical one choosing them by ranks:
Table 12: The constitution grammar and its three variants: the part each changes, its alphabet and nonterminals, the equivalence its canonical words respect, and what was done with it here.
part changed none letters nonterminals labels
equivalence of words renumbering: constitutions renumbering acting on signs: configurations
renumbering and rigid motions: conformations
renumbering, the symmetry breaking kept
status built, measured reading built, measured stated stated
11 Discussion
The grammar of Section 4 and its variants of Section 10 are points in a space of grammars. This section places them in three wider settings: the non-commutative algebra in which the growth, its quotient and its symmetries are naturally written; other alphabets, which decide what a letter can mean; and derivations that are histories rather than readings. Nothing in this section is built or measured unless it says so.
11.1 Operator-Algebraic Formulation
The quotient of Proposition 22, and the variants of Section 10, have a natural home in noncommutative algebra. Four correspondences are worth stating; each is a reading of known mathematics, not a result of this study.
on the Fock space of face types, in the representation of Doi (1976) and Peliti (1985). The levels that read the span, the room or the size break this form: an event’s rate then depends on the
PDF page 42
Trace monoid. Two events at faces that share no atom and whose contexts do not read each other could be performed in either order. Derivations modulo these commutations form a trace monoid, a partially commutative monoid (Cartier and Foata, 1969; Diekert and Rozenberg, 1995), and the canonical reading picks one linear order of each trace, first come, first served. The Foata normal form would instead group the derivation into steps of mutually independent events, a parallel derivation; its depth measures how far the molecule’s construction can be parallelised and is a property of the derivation that no multiset of parts sees.
11.2 Alternative Alphabets
Simplices of at most four atoms are one alphabet among several, and the choice decides what a letter can mean.
Hyperedge atoms. In Kajino (2019) an atom is a hyperedge with all its bonds as tentacles, so valence holds by construction and no context is needed for it. The price is that a ring is never made by one rule, and rings are recovered from how rules are glued. Our levels of room are what one pays for keeping atoms as vertices.
Cellular motifs. A ring can be one 2-cell, with a boundary of its length, rather than a fan of triangles, and a molecule a regular CW complex (Bodnar et al., 2021); a motif can be a cell of
PDF page 43
higher rank, as in the combinatorial complexes of Huang et al. (2026). The alphabet then grows with what is seen and a ring system never seen has no letter, but a letter means a ring, and an aromatic ring’s properties attach to one letter instead of four triangles and three virtual edges.
Linear notations. SMILES (Weininger, 1988) and SELFIES (Krenn et al., 2020) are linear words. Their derivations are left to right, their equivalence is equality of strings, and a molecule has many; a canonical SMILES plays the part of our canonical reading. Language models of strings learn the long-range regularities that a local grammar does not, and the gap in bits of Section 7 is a measure of how much that is.
Reaction rules. If the productions are reaction rules, a derivation is a synthesis: a route from purchasable molecules to a target, of the kind retrosynthetic analysis searches (Corey, 1991), and graph rewriting by double pushouts is its formal setting (Andersen et al., 2016). Here the equivalence of derivations is no longer the equivalence of the product, since many routes give one molecule, and the hypothesis acquires its historical reading (Section 11.3).
Geometric simplices and foams. Letters can be simplices of a triangulation of space rather than of the graph, with coordinates; and the events of a reaction network in time can be read as a foam, a typed 2-complex swept in time, whose grammars the same software holds for other domains. Both carry transformations in the sense of Section 10.4.
Width. A reading of width four would take every molecule of the residue; the price is letters over four atoms and a larger alphabet, for a few dozen cages in three collections.
11.3 Historical Derivations
11.4 Limitations
• Constitution. The grammar learned and measured is a grammar of constitutions. The oriented reading of Section 10.2 is built and held to RDKit on ZINC250k, but no grammar of configurations was learned over it beyond the local price of a sign; the orbit and transformation-labelled grammars are stated, with worked examples, and not built; no geometry and no conformers enter any measurement.
• Stereochemistry read. The oriented reading covers tetrahedral centres (lone pairs included) and double bonds, as RDKit specifies them; axial, planar and helical chirality,
PDF page 44
atropisomers and the stereochemistry of octahedral centres are not read.
• Semantic corpus. The properties are QM9’s, computed by one functional on one geometry per molecule, for molecules of at most nine heavy atoms. Whether the order of properties holds for larger molecules, or for measured properties, is untested.
• Solver tolerance. The additive readings are ridge regressions solved to a cap of steps; exact solutions would do at least as well.
• Code of readings. The code is an upper bound on the code of molecules, corrected by the measured canonical share but not by summing over derivations.
• Generative performance. A neural model of strings needs markedly fewer bits, and the grammars of local context draw sizes badly; the size level repairs the body of the law of sizes and not its tail.
• Residue. Cages without a connected order of width three are refused, not modelled.
• Status of the correspondences. The readings of Section 11.1 are interpretations; only the prediction about conjugation is stated in a form that a computation could refute.
12 Conclusion
A molecule of treewidth at most three can be written one atom at a time, each atom the apex of an edge, a triangle or a tetrahedron glued along a face of what is already there, with rings as fans of triangles on edges that are no bonds. Stated formally, this is a grammar of hyperedge replacement whose nonterminals are faces with a count of the cones they carry, with three schemata of productions (a root, a glue, a close); its derivations in the order of growth correspond one to one to words, its richer contexts are application conditions, and valence can be carried in its nonterminals exactly. With a canonical reading, a molecule is one word over an alphabet of a few dozen letters. Only cages of treewidth three that cannot stay connected while they are written are left out, 22, 2 and 4 molecules in collections of 133,885, 249,455 and 1,936,962.
On such words a stochastic grammar was read at nested levels of context and priced in bits on molecules it had not seen. Within a collection, each level saves bits: the parent of a face most, the valence left more than the length of a ring, and the number of atoms so far a few bits more. That last level also moves the body of the law of drawn sizes to the collection’s. Across collections the richer contexts cost bits, and a neural model of strings remains well ahead. By Courcelle’s theorem none of these contexts enlarges what can be derived: the ladder is a ladder of laws, not of languages.
On the side of meaning, eight properties of QM9 were read as sums over the parts of a derivation. Among molecules made of the same atoms and bonds, which no function of those parts can tell apart, the productions of the derivation together with the productions they came from tell 0.84 of the differences in atomisation energy and 0.47 of those in the HOMO–LUMO gap. In the energies they do better than any function of atoms and bonds could. Molecules sharing every production and every parent can still differ widely when their pieces are assembled differently, as when two carbonyls are conjugated in one and apart in the other. Molecules sharing a whole canonical word agree to the archive’s last digit.
The hypothesis that a derivation decides what a molecule means therefore holds in degrees, measured here, and is bounded by the equivalence the grammar quotients by. A grammar of constitutions gives mirror images one derivation, so the hypothesis in its strongest form, isomorphic structures told apart by their generation, needs a finer grammar. Three were stated formally: letters that carry the orientation of the simplex they complete, nonterminals that are orbits of faces
PDF page 45
under the symmetries of the molecule so far, and labels that carry the rigid motion placing each apex. The first is built: on ZINC250k its oriented words are exactly as many as the configurations, every pair of stereoisomers that shared a word now has two, a reflection reverses every sign, and a sign costs nearly its whole bit given its local context. In the second, the choice between two enantiotopic faces of a symmetric molecule is a recorded step of one bit, the bit that separates the glycerol phosphates of bacteria and of archaea. Learning grammars of configurations and of conformations on these readings, their algebra of operators, and the historical reading of derivations as syntheses or foldings, are the work this paper leaves open.
References
Salvador Aguiñaga, Rodrigo Palacios, David Chiang, and Tim Weninger. Growing graphs from hyperedge replacement graph grammars. In Proceedings of the 25th ACM International Conference on Information and Knowledge Management, pages 469–478, 2016. doi: 10.1145/2983323.2983826.
Salvador Aguinaga, David Chiang, and Tim Weninger. Learning hyperedge replacement grammars for graph generation. IEEE Transactions on Pattern Analysis and Machine Intelligence, 41(3): 625–638, 2019. doi: 10.1109/tpami.2018.2810877.
Sungsoo Ahn, Binghong Chen, Tianzhe Wang, and Le Song. Spanning tree-based graph generation for molecules. In International Conference on Learning Representations, 2022.
Shun-ichi Amari. Natural gradient works efficiently in learning. Neural Computation, 10(2):251– 276, 1998.
Jakob L. Andersen, Christoph Flamm, Daniel Merkle, and Peter F. Stadler. A software package for chemically inspired graph transformation. Lecture Notes in Computer Science, 9761:73–88, 2016.
Stefan Arnborg and Andrzej Proskurowski. Characterization and recognition of partial 3-trees. SIAM Journal on Algebraic and Discrete Methods, 7:305–314, 1986. doi: 10.1137/0607033.
Stefan Arnborg and Andrzej Proskurowski. Canonical representations of partial 2- and 3-trees. BIT, 32:197–214, 1992. doi: 10.1007/bf01994877.
Roshan Balaji, Kamran Chitsaz, Quentin Fournier, Nirav Pravinbhai Bhatt, and Sarath Chandar. A large scale investigation of scaling limits in chemical language models, 2025. arXiv:2508.13408.
Nicolas Behr, Vincent Danos, and Ilias Garnier. Stochastic mechanics of graph rewriting. In Proceedings of the 31st Annual ACM/IEEE Symposium on Logic in Computer Science (LICS 2016), pages 46–55, 2016.
Guy W. Bemis and Mark A. Murcko. The properties of known drugs. 1. molecular frameworks. Journal of Medicinal Chemistry, 39(15):2887–2893, 1996.
Sidney W. Benson and Jerry H. Buss. Additivity rules for the estimation of molecular properties. Thermodynamic properties. The Journal of Chemical Physics, 29:546–572, 1958. doi: 10.1063/1. 1744539.
G. Richard Bickerton, Gaia V. Paolini, Jérémy Besnard, Sorel Muresan, and Andrew L. Hopkins. Quantifying the chemical beauty of drugs. Nature Chemistry, 4(2):90–98, 2012.
Cristian Bodnar, Fabrizio Frasca, Nina Otter, Yu Guang Wang, Pietro Liò, Guido Montúfar, and
PDF page 46
Michael Bronstein. Weisfeiler and lehman go cellular: CW networks. In Advances in Neural Information Processing Systems 34, 2021. arXiv:2106.12575.
Taylor L. Booth and Richard A. Thompson. Applying probability measures to abstract languages. IEEE Transactions on Computers, C-22:442–450, 1973. doi: 10.1109/t-c.1973.223746.
Pierre Cartier and Dominique Foata. Problèmes combinatoires de commutation et réarrangements, volume 85 of Lecture Notes in Mathematics. Springer, Berlin, 1969.
Zhiyi Chi. Statistical properties of probabilistic context-free grammars. Computational Linguistics, 25(1):131–160, 1999.
N. Cohen and S. W. Benson. Estimation of heats of formation of organic compounds by additivity methods. Chemical Reviews, 93:2419–2438, 1993. doi: 10.1021/cr00023a005.
Giovanna Kobus Conrado, Amir Kafshdar Goharshady, Harshit Jitendra Motwani, and Sergei Novozhilov. Combinatorial parameterized algorithms for chemical descriptors based on molecular graph sparsity, 2023. arXiv:2303.13279.
Elias J. Corey. The logic of chemical synthesis: Multistep synthesis of complex carbogenic molecules (Nobel lecture). Angewandte Chemie International Edition in English, 30(5):455–465, 1991.
Bruno Courcelle. The monadic second-order logic of graphs. I. Recognizable sets of finite graphs. Information and Computation, 85:12–75, 1990. doi: 10.1016/0890-5401(90)90043-h.
Bruno Courcelle and Joost Engelfriet. Graph Structure and Monadic Second-Order Logic. Cambridge University Press, 2012. doi: 10.1017/cbo9780511977619.
Christopher J. Cramer. Essentials of Computational Chemistry: Theories and Models. Wiley, Chichester, 2 edition, 2004.
Hanjun Dai, Yingtao Tian, Bo Dai, Steven Skiena, and Le Song. Syntax-directed variational autoencoder for structured data. In International Conference on Learning Representations, 2018. arXiv:1802.08786.
Jörg Degen, Christof Wegscheid-Gerlach, Andrea Zaliani, and Matthias Rarey. On the art of compiling and using ‘drug-like’ chemical fragment spaces. ChemMedChem, 3(10):1503–1507, 2008.
Volker Diekert and Grzegorz Rozenberg, editors. The Book of Traces. World Scientific, Singapore, 1995.
Masao Doi. Second quantization representation for classical many-particle system. Journal of Physics A: Mathematical and General, 9(9):1465–1477, 1976.
Frank Drewes and Berthold Hoffmann. Contextual hyperedge replacement. Acta Informatica, 52: 497–524, 2015. doi: 10.1007/s00236-015-0223-4.
Frank Drewes, Hans-Jörg Kreowski, and Annegret Habel. Hyperedge replacement graph grammars. In Handbook of Graph Grammars and Computing by Graph Transformation, volume 1, pages 95–162. World Scientific, 1997. doi: 10.1142/9789812384720_0002.
Ernest L. Eliel and Samuel H. Wilen. Stereochemistry of Organic Compounds. Wiley, New York, 1994.
Rafael Gómez-Bombarelli, Jennifer N. Wei, David Duvenaud, José Miguel Hernández-Lobato, Benjamín Sánchez-Lengeling, Dennis Sheberla, Jorge Aguilera-Iparraguirre, Timothy D. Hirzel, Ryan P. Adams, and Alán Aspuru-Guzik. Automatic chemical design using a data-driven continuous representation of molecules. ACS Central Science, 4:268–276, 2018. doi: 10.1021/ac scentsci.7b00572.
PDF page 47
Minghao Guo, Veronika Thost, Beichen Li, Payel Das, Jie Chen, and Wojciech Matusik. Dataefficient graph grammar learning for molecular generation. In International Conference on Learning Representations, 2022. arXiv:2203.08031.
Ivan Gutman and Oskar E. Polansky. Mathematical Concepts in Organic Chemistry. Springer, Berlin, 1986.
Annegret Habel. Hyperedge Replacement: Grammars and Languages, volume 643 of Lecture Notes in Computer Science. Springer, 1992. doi: 10.1007/BFb0013875.
Annegret Habel, Reiko Heckel, and Gabriele Taentzer. Graph grammars with negative application conditions. Fundamenta Informaticae, 26:287–313, 1996. doi: 10.3233/fi-1996-263404.
Katja Hansen, Franziska Biegler, Raghunathan Ramakrishnan, Wiktor Pronobis, O. Anatole von Lilienfeld, Klaus-Robert Müller, and Alexandre Tkatchenko. Machine learning predictions of molecular properties: Accurate many-body potentials and nonlocality in chemical space. The Journal of Physical Chemistry Letters, 6:2326–2331, 2015. doi: 10.1021/acs.jpclett.5b00831.
Frank Harary and Edgar M. Palmer. On acyclic simplicial complexes. Mathematika, 15:115–122, 1968. doi: 10.1112/s002557930000245x.
Tamás Horváth, Keisuke Otaki, and Jan Ramon. Efficient frequent connected induced subgraph mining in graphs of bounded tree-width. In Machine Learning and Knowledge Discovery in Databases (ECML PKDD 2013), Lecture Notes in Computer Science, pages 622–637, 2013. doi: 10.1007/978-3-642-40988-2_40.
Yiming Huang, Yujie Zeng, Vijay Prakash Dwivedi, Simone Foti, Jianmin Wang, Jure Leskovec, and Tolga Birdal. Higher-order molecular grammars for generative and foundation models in chemistry, 2026. arXiv:2610.02186.
Erich Hückel. Quantentheoretische Beiträge zum Benzolproblem. I. Zeitschrift für Physik, 70: 204–286, 1931.
John J. Irwin, Teague Sterling, Michael M. Mysinger, Erin S. Bolstad, and Ryan G. Coleman. ZINC: A free tool to discover chemistry for biology. Journal of Chemical Information and Modeling, 52 (7):1757–1768, 2012. doi: 10.1021/ci3001277.
Tommi S. Jaakkola and David Haussler. Exploiting generative models in discriminative classifiers. In Advances in Neural Information Processing Systems 11, pages 487–493. MIT Press, Cambridge, MA, 1998.
Wengong Jin, Regina Barzilay, and Tommi Jaakkola. Junction tree variational autoencoder for molecular graph generation. In Proceedings of the 35th International Conference on Machine Learning, volume 80 of PMLR, pages 2323–2332, 2018. arXiv:1802.04364.
Mark Johnson. PCFG models of linguistic tree representations. Computational Linguistics, 24(4): 613–632, 1998.
Hiroshi Kajino. Molecular hypergraph grammar with its application to molecular optimization. In Proceedings of the 36th International Conference on Machine Learning, volume 97 of PMLR, pages 3183–3191, 2019. arXiv:1809.02745.
Donald E. Knuth. Semantics of context-free languages. Mathematical Systems Theory, 2(2):127–145, 1968. doi: 10.1007/BF01692511.
Walter Kohn. Density functional and density matrix method scaling linearly with the number of atoms. Physical Review Letters, 76(17):3168–3171, 1996.
Egor Kraev and Mark Harley. Probabilistic hypergraph grammars for efficient molecular optimization, 2019. arXiv:1906.01845.
PDF page 48
Mario Krenn, Florian Häse, AkshatKumar Nigam, Pascal Friederich, and Alán Aspuru-Guzik. Self-referencing embedded strings (SELFIES): a 100% robust molecular string representation. Machine Learning: Science and Technology, 1:045024, 2020. doi: 10.1088/2632-2153/aba947.
Matt J. Kusner, Brooks Paige, and José Miguel Hernández-Lobato. Grammar variational autoencoder. In Proceedings of the 34th International Conference on Machine Learning, volume 70 of PMLR, pages 1945–1954, 2017. arXiv:1703.01925.
Jonathan Lombard, Purificación López-García, and David Moreira. The early evolution of lipid membranes and the three domains of life. Nature Reviews Microbiology, 10(7):507–515, 2012. doi: 10.1038/nrmicro2815.
David J. C. MacKay and Linda C. Bauman Peto. A hierarchical Dirichlet language model. Natural Language Engineering, 1:289–308, 1995. doi: 10.1017/s1351324900000218.
Brendan D. McKay and Adolfo Piperno. Practical graph isomorphism, II. Journal of Symbolic Computation, 60:94–112, 2014. doi: 10.1016/j.jsc.2013.09.003.
Kurt Mislow and Morton Raban. Stereoisomeric relationships of groups in molecules. Topics in Stereochemistry, 1:1–38, 1967.
James R. Munkres. Elements of Algebraic Topology. Addison-Wesley, Menlo Park, 1984.
Maximilian Nickel and Douwe Kiela. Poincaré embeddings for learning hierarchical representations. In Advances in Neural Information Processing Systems 30, 2017. arXiv:1705.08039.
A. G. Ogston. Interpretation of experiments on metabolic processes, using isotopic tracer elements. Nature, 162(4129):963, 1948. doi: 10.1038/162963b0.
Luca Peliti. Path integral approach to birth–death processes on a lattice. Journal de Physique, 46 (9):1469–1483, 1985.
Daniil Polykovskiy, Alexander Zhebrak, Benjamin Sanchez-Lengeling, Sergey Golovanov, Oktai Tatanov, Stanislav Belyaev, Rauf Kurbanov, Aleksey Artamonov, et al. Molecular sets (MOSES): A benchmarking platform for molecular generation models. Frontiers in Pharmacology, 11:565644, 2020. doi: 10.3389/fphar.2020.565644.
Vladimir Prelog and Günter Helmchen. Basic principles of the CIP-system and proposals for a revision. Angewandte Chemie International Edition in English, 21(8):567–583, 1982.
Kristina Preuer, Philipp Renz, Thomas Unterthiner, Sepp Hochreiter, and Günter Klambauer. Fréchet ChemNet distance: A metric for generative models for molecules in drug discovery. Journal of Chemical Information and Modeling, 58:1736–1741, 2018. doi: 10.1021/acs.jcim.8b00234.
Stanley B. Prusiner. Prions. Proceedings of the National Academy of Sciences of the United States of America, 95(23):13363–13383, 1998.
Raghunathan Ramakrishnan, Pavlo O. Dral, Matthias Rupp, and O. Anatole von Lilienfeld. Quantum chemistry structures and properties of 134 kilo molecules. Scientific Data, 1:140022, 2014. doi: 10.1038/sdata.2014.22.
RDKit. RDKit: Open-source cheminformatics, 2026. Release 2026.09.3, https://www.rdkit. org.
Donald J. Rose. Triangulated graphs and the elimination process. Journal of Mathematical Analysis and Applications, 32:597–609, 1970. doi: 10.1016/0022-247x(70)90282-9.
Lars Ruddigkeit, Ruud van Deursen, Lorenz C. Blum, and Jean-Louis Reymond. Enumeration of 166 billion organic small molecules in the chemical universe database GDB-17. Journal of Chemical Information and Modeling, 52:2864–2875, 2012. doi: 10.1021/ci300415d.
PDF page 49
Jean-Pierre Serre. Linear Representations of Finite Groups, volume 42 of Graduate Texts in Mathematics. Springer, New York, 1977.
Michael Sun, Minghao Guo, Weize Yuan, Veronika Thost, Crystal Elaine Owens, Aristotle Franklin Grosz, Sharvaa Selvan, Katelyn Zhou, Hassan Mohiuddin, Benjamin J. Pedretti, Zachary P. Smith, Jie Chen, and Wojciech Matusik. Representing molecules as random walks over interpretable grammars. In Proceedings of the 41st International Conference on Machine Learning, 2024. arXiv:2403.08147.
Michael Sun, Weize Yuan, Gang Liu, Wojciech Matusik, and Jie Chen. Foundation molecular grammar: Multi-modal foundation models induce interpretable molecular graph languages. In Proceedings of the 42nd International Conference on Machine Learning, 2025. arXiv:2505.22948.
Clément Vignac, Igor Krawczuk, Antoine Siraudin, Bohan Wang, Volkan Cevher, and Pascal Frossard. DiGress: Discrete denoising diffusion for graph generation. In International Conference on Learning Representations, 2023. arXiv:2209.14734.
Xinyi Wang, Salvador Aguinaga, Tim Weninger, and David Chiang. Growing better graphs with latent-variable probabilistic graph grammars, 2018. arXiv:1806.07955.
David Weininger. SMILES, a chemical language and information system. 1. Introduction to methodology and encoding rules. Journal of Chemical Information and Computer Sciences, 28:31–36, 1988. doi: 10.1021/ci00057a005.
Scott A. Wildman and Gordon M. Crippen. Prediction of physicochemical parameters by atomic contributions. Journal of Chemical Information and Computer Sciences, 39(5):868–873, 1999.
Atsuko Yamaguchi, Kiyoko F. Aoki, and Hiroshi Mamitsuka. Graph complexity of chemical compounds in biological pathways. Genome Informatics, 14:376–377, 2003. doi: 10.11234/gi199 0.14.376.
A Proofs
A.1 Proof of Proposition 3
PDF page 50
A.2 Proof of Proposition 18
Remark. The grammars of Sections 7 and 8 are smoothed by the escape and the backoff of Section 5, so the proposition holds of them only approximately: the smoothing moves a little probability to letters never seen on a face, and the expectations move with it.
A.3 Proof of Proposition 6
B Conventions of the Reading
Kekulé forms. An aromatic atom needs one double bond in its ring system when the least normal valence that holds what it already carries leaves a place free. The double bonds are a perfect matching of the atoms that need one, over the aromatic bonds between them; when none exists the input is refused.
Resonance. Two Kekulé forms of one ring system must not be two molecules. The atoms that hold exactly one double bond in a ring, to an atom that also does, are matched again over the ring bonds between them, taking the first perfect matching in the canonical order of the molecule with those bonds left unsaid. The result is a function of the molecule up to isomorphism and up to the placing of such double bonds.
Caveat. This identifies bond-shift isomers such as the two forms of cyclooctatetraene, as writing bonds aromatic does, and does not move charges: the two resonance forms of an amide are two molecules.
Agreement with RDKit. On 1,305 molecules (a list made by hand and samples of QM9 and ZINC250k, some written in random atom order and some in Kekulé form), the reader agrees
PDF page 51
with RDKit (RDKit, 2026) on the formula, the hydrogens of every atom, and which molecules are equal.
C Reproduction
Software. The grammar is the module stacked of the foundation library syntaxis; molecules are read by the molecular-science domain’s graphs and turned into words by its syntax; the study is a C++20 program (study, with subcommands read, census, ladder, sample, semantics, grammar, derive and map) in the experiment’s folder, research/experiments/2026-12-03- grammar-of-molecules, built with CMake and Ninja (g++ 14.2 here). The checks: 19 of the module stacked, 10 of graphs and 13 of syntax, all passing, run by the libraries’ own harness on calx’s verification. Python scripts judge samples with RDKit 2026.09.3 and fcd_torch 1.0.7 (on PyTorch 2.15.0 for the CPU, NumPy 2.5.5 and SciPy 1.18.1); the Fréchet distance is computed in the script from fcd_torch’s ChemNet statistics, because fcd_torch’s own call of SciPy’s matrix square root no longer runs on SciPy 1.18.
Order of the run. run.py in the experiment’s folder performs every step:
1. the three collections are fetched into the data library’s cache by its script data/products/ molecular_corpora.py;
2. study read writes each molecule’s canonical word, with its exact treewidth and its part, into the cache; QM9 and ZINC250k are split by a hash of each molecule’s key, MOSES keeps its own parts;
3. study census writes Table 4’s counts;
4. study ladder learns every level from each collection’s training part and prices every collection’s held-out part, and the learning curve from 1,000, 10,000 and 100,000 molecules of MOSES;
5. study sample draws 30,000 words from each of six grammars with the seed 20261203, and judge_samples.py judges what they spell;
6. study semantics fits the additive readings and the within-group comparisons; with -- only classes, the classes of Table 10; identical_words.py the duplicate words of QM9 and ZINC250k;
7. study grammar writes each collection’s grammar at the context-free level, every production with its count and the faces it opens (Table 2 and Appendix E); study derive writes the canonical derivations of the molecules shown in Section 4, event by event;
8. study map writes, for each molecule of ZINC250k, its word and the atom of the input that each vertex is, and oriented_words.py (on oriented.py) gives every molecule its oriented word and holds the words to RDKit (Table 11);
9. figures.py draws the figures.
The run is deterministic. In this paper, values.py reads the results and writes every number the text sets, asserting the statements the text makes in words about them (that a level saves bits, that one rung tells more than another, that a pair is what it is said to be), so that a rerun that changed a finding stops the build; listings.py writes the tables that list a grammar or a derivation (Tables 1 and 3, Appendix E) row by row from the results.
Data. The collections are not redistributed with the paper; QM9 is CC0 1.0 (Ramakrishnan et al., 2014), ZINC250k is distributed under Apache 2.0 in the repository of Gómez-Bombarelli et al.
PDF page 52
(2018), and MOSES under the MIT licence (Polykovskiy et al., 2020).
D Preparation of This Study
The study was made in one working session of the author with Claude (Anthropic) acting as a coding agent in the author’s repository. Its course is recorded here because it explains choices in the paper.
1. The author proposed that chemistry has a space of syntax and one of semantics; that molecular structures arise by a generative procedure from which their semantics emerge; that probabilistic context-free and context-sensitive grammars, with an embedding on a space such as a smooth manifold, might model both; and asked whether the infrastructure already did so. It did not for molecules. Grammars whose words are geometric existed for other domains.
2. The author asked for both kinds of grammar and suggested an alphabet of simplices. The assistant proposed stacked words with a canonical reading and the levels of context, and implemented them in the foundation library syntaxis and in the molecular-science domain, which had been planned with no code and was founded with these modules.
3. The author asked for a survey of related work and a paper with serious case studies if the idea had not been published. The survey found close predecessors (molecular hypergraph grammars, grammars read from clique trees, recent higher-order molecular grammars) and no publication of the combination; Section 2 states the differences.
4. The author proposed that the structure of the generation process may also decide the semantics, explaining why isomorphic structures can have different functions, and that other alphabets belong in the discussion. The semantic study of Section 9 was designed to test the first in the form the grammar permits.
5. When the assistant described a pair of molecules with the same productions and different gaps, the author corrected the terms: the hypothesis concerns derivations that are equivalent, including the structure built on the steps, and identical derivations cannot end in isomorphic yet different structures such as mirror images without breaking the definition; then, that no equivalence had been defined, nor the conditions under which it is taken (isomorphism or strict equality), and that a grammar carrying symmetry, isomorphism or transformation information would change the question; and that the matter bears on non-commutative operator algebras. These corrections produced Section 9.7, the duplicateword analyses, and Sections 10.1 and 11.1.
6. The author asked for an AI disclosure and a CC BY-NC 4.0 licence, and that headings and table headers name the role of what they head rather than ask or assert.
7. On reading a draft, the author found that the formal grammar itself was not presented, though it is a main part of the paper, and asked that the grammar variants which carry symmetry or transformation information, mentioned in the discussion, be presented as well. Section 4 (the signature, the alphabet, the nonterminals, the productions, derivation trees, the order of growth, the levels of context as application conditions, valence carried in the nonterminals, and the grammars learned, listed in Appendix E) and Section 10 (the oriented, orbit and transformation-labelled grammars, each formally) were written in answer; the oriented reading was built and measured on ZINC250k for it.
Errors found and corrected in the course of the study. The grammars of local context drew molecules of the wrong sizes, which led to the size level. The first semantic run used one thread
PDF page 53
E Productions of the Grammar Learned from MOSES
Table 13: Productions of the context-free grammar learned from MOSES, as described in the text of Appendix E.
nonterminal (times served) right side relative frequency
PDF page 54
nonterminal (times served) right side relative frequency
PDF page 55
nonterminal (times served) right side relative frequency
PDF page 56
nonterminal (times served) right side relative frequency
PDF page 57
nonterminal (times served) right side relative frequency
PDF page 58
nonterminal (times served) right side relative frequency
PDF page 59
nonterminal (times served) right side relative frequency
PDF page 60
nonterminal (times served) right side relative frequency
PDF page 61
nonterminal (times served) right side relative frequency
PDF page 62
nonterminal (times served) right side relative frequency