Skip to content

Lexicons: polymorphic entries, lexical rules, and refinements

This page states what the lexical surface of a deduction means, as a rewriting of the deduction into one without it. The surface is described in the lexicon reference; the deductions it rewrites into are those of weighted deduction.

1. Categories as terms

Fix a deduction with atoms \(\Sigma\). Its categories, items, and lexical meanings are first-order terms over \(\Sigma\), and a name outside \(\Sigma\) in a rule or an entry is a variable. A substitution \(\theta\) maps variables to terms; \(t\theta\) is its application, a match of a pattern \(p\) against a term \(t\) is a \(\theta\) with \(p\theta = t\), and a unifier of \(p\) and \(q\) is a \(\theta\) with \(p\theta = q\theta\), computed most general by first-order unification with the occurs check.

2. Category sets

A declaration categories A = m1, ..., mk is a production \(A \to m_1 \mid \dots \mid m_k\) of a regular tree grammar whose nonterminals are the declared sets. Its language \(L(A)\) is the least set of ground terms with \(m_i[B_1 := t_1, \dots] \in L(A)\) whenever each \(t_j \in L(B_j)\) for the sets \(B_j\) the member names. A set reached from itself through bare members only is refused, so membership \(t \in L(A)\) is decided by structural recursion on \(t\). \(A\) is finite when no set reaches itself from \(A\); its language is then enumerated.

3. Instances of a polymorphic entry

An entry \(w : \forall X_1 \in A_1, \dots, X_n \in A_n.\ C = M\) denotes the coproduct of its instances: one axiom \(w : C\theta = M\theta\) for every \(\theta\) with \(X_i\theta \in R(A_i)\), where the range \(R(A)\) is \(L(A)\) for a finite set and, for an infinite one, \(R(A) = L(A) \cap U_d\), the members of the attested categories \(U_d\) up to a depth bound \(d\) (the entry's bound, else the deduction's depth). \(U_d\) is the least set containing the categories of the deduction's monomorphic entries (closed under its compiled lexical rules) and closed under its rules read on categories (each span rule \(p_1, \dots, p_m \vdash q\) adds \(q\theta\) when each \(p_i\theta \in U_d\) and \(q\theta\) has depth at most \(d\)), together with every subterm of a member: every category a chart of the monomorphic part of the grammar holds within the bound, with positions and meanings ignored.

All instances of one entry read one learned weight \(\omega_w\): an instance's axiom weight is \(\omega_w\), so a derivation using any instance contributes to the gradient of \(\omega_w\). An entry marked per_instance instead has a family of weights indexed by its instantiations: the instance \(\theta\) reads \(\omega_w[\theta]\), and only derivations using \(\theta\) contribute to its gradient.

A meaning \(g[X]\) is the value of the meta computation \(g\) at \(\tau(X\theta)\), where \(\tau\) is the semantic type of §5, computed in the module's meta phase (The meta phase).

4. Lazy instantiation

Lazy instantiation is a way of running the deduction of §3, not a different deduction: the deduction, its item family \(\mathrm{Item}_D\), and every reader of either have the bounded instances as entries. The agenda engine runs a plan instead. Each token of the entry's word is an axiom \(\mathrm{span}(i, i{+}1, \lambda_w)\) with a fresh atom \(\lambda_w\). For every rule \(r : p_1, \dots, p_m \vdash q\), every nonempty set \(P\) of its premise positions, and every choice of instances \(\theta_k\) for \(k \in P\) such that the premises \(p_k\) and the instances' items have a joint most general unifier \(\sigma\), the specialized rule \(r_\sigma : p'_1, \dots, p'_m \vdash q\sigma\) has \(p'_k = \mathrm{span}(I_k\sigma, J_k\sigma, \lambda_w)\) for \(k \in P\) and \(p'_k = p_k\sigma\) otherwise. Its weight is \(r\)'s weight on the binding \(\beta \cup \sigma|_{\mathrm{vars}(r)}\), where \(\beta\) is the specialized rule's own match, and so are its guard and its computed weight: \(r_\sigma\) fires on \(\beta\) exactly when \(r\)'s guard holds of \(\beta \cup \sigma|_{\mathrm{vars}(r)}\), and multiplies in \(r\)'s computed weight there. The axiom \(\mathrm{span}(i, i{+}1, \lambda_w)\) weighs \(\omega_w\), which every instance reads; for a per_instance entry it weighs \(1\), and \(r_\sigma\) multiplies in \(\omega_w[\theta_k]\) for each \(k \in P\), the weight the axiom of \(\theta_k\) carries in the bounded chart. A premise \(p_k\) that is a bare variable, or whose category is one, unifies with every instance, so its specializations are \(r\) at every instance. A bare variable \(p_k = X\) then stands for the item \(\mathrm{span}(I_k, J_k, C\theta)\) itself, so where a term of \(r\) also holds \(X\), \(q\sigma\) would hold the positions \(I_k, J_k\) inside a term; positions and terms are disjoint sorts of the pattern language, so such an \(r\) is refused beside a lazy entry.

The plan's run is read back through the reveal \(\rho\), a map from the plan's items and applications to the deduction's: \(\rho\) sends \(\mathrm{span}(i, i{+}1, \lambda_w)\) to the items \(\mathrm{span}(i, i{+}1, C\theta)\) of every instance \(\theta\), each with the placeholder's weight (times \(\omega_w[\theta]\) for a per_instance entry), and an application of \(r_\sigma\) to the application of \(r\) whose premise \(k \in P\) is the instance \(\theta_k\)'s item. The engine applies \(\rho\) to every result before it leaves the engine. Since \(\lambda_w\) occurs in no rule but the specialized ones, \(\rho\) of the lazy chart is the bounded chart, its hyperedges, axiom occurrences, and goal items included, provided no rule takes the item of \(\lambda_w\) but at a position \(P\) wrote it into: the engine runs each rule with the side condition that no variable binds \(\lambda_w\), nor, where the variable is a premise or a premise's argument, an item of category \(\lambda_w\), so the rule as written takes only the instances its specializations do not. No value of \(\mathrm{Item}_D\) is built from \(\lambda_w\), so a fold or case over \(\mathrm{Item}_D\) is total without a clause for it.

5. Semantic types and the typing check

The clauses \(c_1 \Rightarrow T_1, \dots\) define \(\tau(C) = T_i\,[\,Y := \tau(Y\theta)\,]\) for the first clause \(i\) with \(c_i\theta = C\). Every entry's meaning \(M\) at category \(C\) must satisfy \(\vdash_{\mathrm{Ty}} \cdot \vdash M : \tau(C)\) in the declared judgment (Judgments); a synthesized meaning is checked like a written one, so an ill-typed synthesis is a check-time error at the entry.

6. Lexical rules

A lexical rule \(\ell : \mathrm{span}(I, J, C_p, M_p) \vdash \mathrm{span}(I, J, C_c, M_c)\) with learned weight \(\omega_\ell\) is read in one of two ways. Compiled, it adds for each entry \((w, C, M, \omega)\) with a match \(\theta\) of \((C_p, M_p)\) against \((C, M)\) the entry \((w, C_c\theta, M_c\theta, \omega \otimes \omega_\ell)\), closed under up to bound applications. In the chart, with \(n\) the largest bound of the chart's lexical rules, every entry's item is wrapped as \(\mathrm{span}(i, i{+}1, \iota(C, 0), M)\), a rule \(\mathrm{span}(I, J, \iota(X, L), F) \vdash \mathrm{span}(I, J, X, F)\) of unit weight unwraps it at any level \(L\), and \(\ell\) becomes, for each level \(d < n\), \(\mathrm{span}(I, J, \iota(C_p, d), M_p) \vdash \mathrm{span}(I, J, \iota(C_c, d{+}1), M_c)\) of weight \(\omega_\ell\). In both, each lexical derivation through \(\ell\) weighs \(\omega \otimes \omega_\ell\), and a chain of lexical rules is at most \(n\) long, so the two give the same item weights, and both differentiate \(\omega_\ell\). The chart reading, like lazy instantiation, is a plan of the deduction the compiled reading gives with bound \(n\): its reveal sends a wrapped item to nothing, an application of \(\ell\) to none, and the conclusion of the unwrapping rule to an axiom occurrence of the lexical item it unwraps, so the revealed chart is the compiled one and \(\iota\) is no constructor of \(\mathrm{Item}_D\). A rule of the deduction takes no wrapped item: a variable bound to one, where it is a premise or a premise's argument, fails the side condition of §4. Under normalize=lhs a derived entry's weight is the normalized weight of its own production, which no factor of its source item's weight enters, so the plan reads each derived entry as an entry.

7. Refinements as ornaments

A refinement \(R\) of a base \(B\) declares atoms \(a[F_1, \dots, F_k]\) with finite sets of atoms \(F_i\). Its atoms are \(B\)'s, with each such \(a\) joined by the atoms \(a[v_1, \dots, v_k]\) for \(v_i \in F_i\). The erasure \(\epsilon : \mathrm{Item}_R \to \mathrm{Item}_B\), sending \(a[\vec v]\) to \(a\) and commuting with every constructor, makes \(\mathrm{Item}_R\) an ornament of \(\mathrm{Item}_B\) (Dagand and McBride, 2014): the same constructors, with feature information added at the atoms.

Restriction. For every rule \(r\) of \(R\) there is a rule \(b\) of \(B\) and a substitution \(\theta\) with \(\epsilon(r) = b\theta\), and for every entry \((w, C, M)\) of \(R\) the entry \((w, \epsilon(C), M)\) is in \(B\). By induction on derivations, \(\epsilon\) then sends every derivation of \(R\) to a derivation of \(B\) with the same yield, so \(L(R) \subseteq L(B)\).

Transport. A fold \(f_\alpha : \mathrm{Item}_B \to T\) given by an algebra \(\alpha\) (a signature morphism) transports to \(\mathrm{Item}_R\) as the fold whose clause at each constructor \(c\) is \(\alpha\)'s clause at \(\epsilon(c)\). Since \(\epsilon\) is itself a fold that commutes with the constructors, the transported fold equals \(f_\alpha \circ \epsilon\), which the generated law states and qvr test checks; any other function \(g\) over \(\mathrm{Item}_B\) transports as \(g \circ \epsilon\).

8. Generalized conjunction

With \(\tau\) as in §5 and a conjunction \(\wedge : t \times t \to t\), generalized conjunction (Partee and Rooth, 1983) is defined on every type ending in \(t\) by \(p \sqcap_t q = p \wedge q\) and \(p \sqcap_{a \to b} q = \lambda x.\ (p\,x) \sqcap_b (q\,x)\). The meta computation coord of the reference builds \(\lambda q.\lambda p.\ p \sqcap_{\tau(X)} q\) by recursion on \(\tau(X)\), so one polymorphic entry gives exactly the entries a grammar would write for each conjoinable category (Steedman, 2000).

Cited sources

Pierre-Évariste Dagand and Conor McBride. Transporting Functions across Ornaments. Journal of Functional Programming, 24(2-3):316–383, 2014. doi:10.1017/S0956796814000069.

Barbara Partee and Mats Rooth. Generalized Conjunction and Type Ambiguity. In Meaning, Use, and Interpretation of Language, pages 361–383. De Gruyter, 1983. doi:10.1515/9783110852820.361.

Mark Steedman. The Syntactic Process. MIT Press, 2000. URL: https://direct.mit.edu/books/book/4283/The-Syntactic-Process, doi:10.7551/mitpress/6591.001.0001.