Appendix B

Glossary

The preceding chapters use vocabulary from three communities. The first is the proof theory of Miller and Nadathur’s bookDale Miller and Gopalan Nadathur. Programming with Higher-Order Logic. Cambridge University Press, Cambridge, 2012, where you find sequents, uniform proofs and eigenvariables. The second is the literature on unification of λ\lambda-terms (patterns, raising, pruning, universe levels). The third is miniKanren, with streams, interleaving, soft cut and reification, and in particular the engine (aux kanren micro) that we want to extend. The same word sometimes means different things in different communities (“suspension”, “level”, “scope extrusion”, “fresh”), and the same idea sometimes has three names (GENERIC, pi, all). This appendix collects all of them in one alphabetical list. Each entry gives a short, precise definition and tells you where the concept is treated in this document and in the book.

B.1How to read this glossary

Pointers. Most entries end with a pointer of the form “→\rightarrow Chapter 3; [MN p. 82]”. The first part is the chapter of this document where the concept is developed. The second part is a printed page of the bookDale Miller and Gopalan Nadathur. Programming with Higher-Order Logic. Cambridge University Press, Cambridge, 2012; most of these come from the book’s own index. Entries that come only from the miniKanren literature or from the aux sources have no book page; they cite the paper instead. Names of (aux kanren micro) procedures and macros are set in typewriter type. We describe only what exists today. The new operators are the subject of Chapter 11 and Chapter 12.

Notation. Table B.1 lists the symbols that occur most often in the entries.

Table B.1: Notation used throughout the glossary.
SymbolMeaning
Σ;𝒫⟶G\Sigma;\mathcal{P}\longrightarrow Gsequent: signature Σ\Sigma, program 𝒫\mathcal{P}, goal GG [MN p. 39]
Σ;𝒫→DA\Sigma;\mathcal{P} \xrightarrow{D} Afocused sequent: the clause DD is selected to prove the atom AA [MN p. 44]
GG, DDgoal formula, program clause (definite formula)
⊤,∧,∨,⊃,∀,∃\top,\wedge,\vee,\supset,\forall,\existslogical constants; concrete syntax true, & or ,, ;, => or :-, pi, sigma
λx. t\lambda x.\, tabstraction; λProlog x\ t
s[t/x]s[t/x]capture-avoiding substitution of tt for xx in ss [MN p. 85]
=βη=_{\beta\eta}, λ\lambda-conversionequality of terms modulo α\alpha, β\beta, η\eta [MN p. 100]
τ→σ\tau\to\sigma, 𝗈\mathsf{o}function type; type of formulas
Q1x1…Qnxn[ ⋀jtj=sj ]Q_1x_1\dots Q_nx_n[\,\bigwedge_j t_j=s_j\,]unification problem under a mixed prefix [MN p. 105]
a#ta\mathbin{\#}tnominal freshness: the atom aa does not occur free in tt
⟨ϕ;t⟩\langle\phi;t\ranglestatic closure of Ma and Friedman: term tt under the scope ϕ\phi
°, ª, §, δaux suffixes and glyphs: goal or relation, applicative form, stream, delay

Pitfall (one word, several meanings). Several terms below are overloaded across the sources. Keep the distinctions in mind when you read the papers.

  • Suspension. In (aux kanren micro), a suspension is a δ-promise, the immature part of a stream. In nominal unification, π⋅X\pi\cdot X is a permutation suspended on a variable. In Teyjus, the suspension [[t,ol,nl,e]][[t,ol,nl,e]] is an explicit-substitution term. In ELPI, a suspended goal is a syntactic constraint.
  • Level. A de Bruijn level numbers a bound variable from the root inwards. A universe level, or universe index, is the ∀\forall-nesting depth at which a variable or constant was created. ELPI makes the two coincide, but they are different ideas.
  • Scope extrusion. The book uses this name for a classical equivalence that moves an implication over a disjunction [MN p. 89]. In the π\pi-calculus it means sending a restricted name out of its scope. In implementation discussions it means an eigenvariable escaping into an older variable.
  • Fresh. In miniKanren, fresh is the existential quantifier and introduces logic variables. In αKanren, fresh introduces noms, which are names rather than variables.
  • Cut. The cut rule of the sequent calculus has no connection to Prolog’s pruning operator ! [MN p. 63].
  • Substitution and grafting. Instantiating a unification variable is capture-avoiding in standard higher-order unification. It is capture-permitting (grafting) in the Ma–Friedman and DHKP formulations.

B.2Terms from A to Z

A

Abstract datatype A module that exports a type constructor and the predicates over it but hides the data constructors, so other code can use only the exported operations (book Ch. 6). →\rightarrow [MN p. 165].

Abstract logic programming language A logic in which searching for uniform proofs is a complete proof procedure. This is the book’s criterion for a logic to count as a logic programming language. fohc, fohh, hohc and hohh all qualifyDale Miller, Gopalan Nadathur, Frank Pfenning, and Andre Scedrov. Uniform proofs as a foundation for logic programming. Annals of Pure and Applied Logic, 51:125–157, 1991. →\rightarrow Chapter 2; [MN p. 73].

Abstraction The term λx. t\lambda x.\, t (λProlog x\ t), the only binder of the term language. xx is the bound variable and tt the body. The quantifiers are the constants pi and sigma applied to abstractions. →\rightarrow Chapter 4; [MN p. 97].

Accumulation (module, signature) accumulate inlines the code of other modules after renaming their private names. accum_sig inserts the declarations of other signatures, either to re-export them or to declare a parameter that a later module supplies. →\rightarrow [MN p. 154], [MN p. 155].

Administrative redex A β\beta-redex that a program transformation (here the CPS transformation) introduces itself, as opposed to one present in the source. The two-phase CPS of book Ch. 10 marks these redexes and reduces them afterwards. →\rightarrow Chapter 8; [MN p. 257].

α\alpha-conversion Renaming bound variables. Terms that differ only by α\alpha-conversion are identified, so the names of bound variables are “a fiction” and an implementation may not represent them at all. →\rightarrow Chapter 4 and Chapter 6; [MN p. 100], [MN p. 183], [MN p. 205].

αKanren Byrd and Friedman’s nominal miniKanrenWilliam E. Byrd and Daniel P. Friedman. α\alphaKanren: A fresh name in nominal logic programming. In Proceedings of the 2007 Workshop on Scheme and Functional Programming, Université Laval Technical Report DIUL-RT-0701, pages 79–90, 2007; and William E. Byrd. Relational Programming in miniKanren: Techniques, Applications, and Implementations. PhD thesis, Indiana University, 2009. fresh introduces noms, (tie a t) binds the nom aa in tt, and (hash a t) asserts the freshness a#ta\mathbin{\#}t. Unification is nominal unification. The implementation does not support disequality constraints. →\rightarrow Chapter 9.

AND The goal-reduction rule for G1∧G2G_1\wedge G_2: prove both conjuncts with the same signature and program. →\rightarrow Chapter 2; [MN p. 39].

Anonymous variable _: each occurrence is a distinct variable, and its binding is not reported. →\rightarrow Chapter 2; [MN p. 47].

Answer substitution The bindings that a successful search reports for the free variables of a query. These variables are implicitly existential. The miniKanren counterpart is the reified answer. →\rightarrow Chapter 2; [MN p. 43].

Applicative form An aux naming convention. The suffix ª marks the procedure behind a goal macro: freshª behind fresh°, and andª, orª behind and°, or°. →\rightarrow Chapter 10.

assume, all The λKanren goals for D⊃GD\supset G and ∀x G\forall x\,G. See AUGMENT, GENERIC and λKanren. →\rightarrow Chapter 9.

Atom (nominal), nom, name In nominal logic and αKanren, a constant-like name that stands for an object-level variable. A nom unifies only with itself or with an unbound logic variable. →\rightarrow Chapter 9.

Atomic formula A term of type 𝗈\mathsf{o} whose head is a predicate symbol, that is, a constant with target type 𝗈\mathsf{o}. →\rightarrow Chapter 2; [MN p. 34].

AUGMENT The goal-reduction rule for D⊃GD\supset G: add DD to the program and prove GG. This rule is the basis of hypothetical reasoning; the clause is visible only during the proof of GG. λProlog writes D => G; λKanren calls it assume.

Σ;𝒫∪{D}⟶GΣ;𝒫⟶D⊃G  augment\dfrac{\Sigma;\mathcal{P}\cup\{D\}\longrightarrow G}{\Sigma;\mathcal{P}\longrightarrow D\supset G}\;\text{augment}

→\rightarrow Chapter 3; [MN p. 39], [MN p. 77].

Available level (Ma–Friedman) A de Bruijn level of a scope ϕ\phi whose binder name is not rebound further in. A shadowed binder’s level is unavailable, so λa.λa.X=?λc.λd.c\lambda a.\lambda a.X \stackrel{?}{=} \lambda c.\lambda d.c failsWeixi Ma and Daniel P. Friedman. A new higher-order unification algorithm for λ\lambdaKanren. In miniKanren and Relational Programming Workshop, 2021. →\rightarrow Chapter 9.

B

Backchaining Proving an atomic goal AA by selecting a program clause, possibly an assumed one, whose head matches AA, and then proving the clause’s body. It is the only phase of search that consults the program. The book formalises it with focused sequents and the rules decide, initial, ⊃\supsetL, ∧\wedgeL and ∀\forallL. →\rightarrow Chapter 2; [MN p. 3], [MN p. 44].

β\beta-conversion, β\beta-redex, β\beta-reduction A β\beta-redex is (λx. s) t(\lambda x.\, s)\,t, and it reduces to s[t/x]s[t/x]. β\beta-reduction is the computation of functional programming, and it is part of the equality of λProlog terms. →\rightarrow Chapter 4; [MN p. 100]–[MN p. 101].

β0\beta_0-conversion The special case (λx. s) x=s(\lambda x.\, s)\,x = s of β\beta. With α\alpha, it is equivalent to (λy. s) x=s[x/y](\lambda y.\, s)\,x=s[x/y] when xx is not free in λy. s\lambda y.\, s, so it only renames. It is the only β\beta needed in LλL_\lambda. →\rightarrow Chapter 6 and Chapter 7; [MN p. 206], [MN p. 220].

β\beta-normal form A term without β\beta-redexes. It has the shape λx1…λxn. (h t1…tm)\lambda x_1\dots\lambda x_n.\,(h\,t_1\dots t_m), with binder x1…xnx_1\dots x_n, head hh and arguments t1…tmt_1\dots t_m. →\rightarrow Chapter 4; [MN p. 101], [MN p. 111].

βη\beta\eta-long normal form A β\beta-normal form whose arguments are themselves in long form and whose body has primitive type. Every β\beta-normal form can be η\eta-expanded into an equal long one; for f:(i→i)→if:(i\to i)\to i, the long form of ff is λw. f (λu. w u)\lambda w.\,f\,(\lambda u.\,w\,u). Higher-order unification works on these forms. →\rightarrow Chapter 4; [MN p. 111].

Big-step / small-step semantics A big-step (natural) semantics relates a term to its final value. A small-step (structural operational) semantics relates a term to the result of one atomic step. →\rightarrow Chapter 8; [MN p. 250]–[MN p. 251].

Binary clause A clause whose body is at most one, possibly complex, atom. Every clause can be put in this form by threading a continuation goal K:𝗈K:\mathsf{o} (continuation-passing style). →\rightarrow Chapter 5; [MN p. 130].

Binder A syntactic construct that introduces a locally scoped name: a quantifier, λ\lambda, ∫\int, Σ\Sigma or a local declaration. In λ-tree syntax, object-level binders are encoded by meta-level λ\lambda. →\rightarrow Chapter 6.

Binder mobility The way a binder moves across levels during computation. A term-level λ\lambda becomes a formula-level ∀\forall (pi), which in turn becomes a proof-level eigenvariable. This movement lets λProlog programs descend under binders without managing names. →\rightarrow Chapter 6; [MN p. 184], [MN p. 205].

Binder-merging (Ma–Friedman) The implementation technique of renaming one side’s binders to the other side’s before comparing the bodies structurally. With name shadowing and a naive reading of levels back into names, it can make Church false λa.λa.a\lambda a.\lambda a.a unify with Church true λc.λd.c\lambda c.\lambda d.c. →\rightarrow Chapter 9.

Bisimulation, simulation Coinductive behavioural equivalence and preorder on processes. Book Ch. 11 shows that a simulation written with pi is incorrect, because pi is intensional. →\rightarrow Chapter 8; [MN p. 271].

C

Canonical substitution For a problem whose equations are all flex-flex: fix one new existential variable HσH^{\sigma} for each primitive type σ\sigma, and map every existential variable of type τ1→⋯→τn→σ\tau_1\to\dots\to\tau_n\to\sigma to λx1…λxn. Hσ\lambda x_1\dots\lambda x_n.\,H^{\sigma}. This substitution always unifies such a problem, which is why a flex-flex remainder counts as success. →\rightarrow Chapter 7; [MN p. 217]–[MN p. 218].

Capture-avoiding substitution s[t/x]s[t/x], carried out after renaming bound variables of ss so that no free variable of tt is captured. It is defined only up to α\alpha. Contrast grafting. →\rightarrow Chapter 3 and Chapter 4; [MN p. 85]–[MN p. 86], [MN p. 100].

Church numeral ⌜n⌝=λf.λx. fnx\ulcorner n\urcorner=\lambda f.\lambda x.\,f^n x. The book uses Church numerals to show β\beta-reduction as computation and to encode Diophantine equations as unification problems. →\rightarrow Chapter 4; [MN p. 102], [MN p. 115].

Clausal order The nesting depth of implications to the left in a formula, analogous to the order of a type. →\rightarrow Chapter 3; [MN p. 76].

Closed-world / open-world assumption Whether the world, that is, the signature–program pair, can grow. Under the open-world assumption that λProlog adopts, generic and universal judgments coincide. →\rightarrow Chapter 3; [MN p. 94].

Complete set of unifiers (CSU) A set of unifiers such that every unifier is an instance of some member. Higher-order problems have CSUs, possibly infinite, but in general no mgu. One might ask instead for a non-redundant CSU, in which no two members have a common instance, but the book notes that this cannot be guaranteed in general either. →\rightarrow Chapter 7; [MN p. 213].

Completeness (of a search strategy) In the book, completeness is a property of a proof system: uniform proofs exist whenever proofs do. A search strategy is a different matter. Depth-first search is incomplete. miniKanren’s interleaving search is complete for answers, meaning every answer with a finite derivation is eventually producedDmitry Rozplokhas, Andrey Vyatkin, and Dmitry Boulytchev. Certified semantics for relational programming. In Programming Languages and Systems (APLAS 2020), volume 12470 of LNCS, pages 167–185. Springer, 2020. It does not guarantee termination or finite failure. →\rightarrow Chapter 2 and Chapter 10.

Computation-as-deduction The view that computation is the construction or transformation of proofs. It comes in two forms: proof normalisation (functional programming) and proof search (logic programming). Computation-as-model instead uses logic to reason about computations. →\rightarrow Chapter 1; [MN p. 2].

cond° (aux kanren micro)’s conde: an interleaving disjunction of conjunctions of goals. There is no else keyword. →\rightarrow Chapter 10.

Consistent / inconsistent program A program is inconsistent if every formula is provable from it. Every fohc and fohh program is consistent. Clause heads must be rigid: with the two clauses P 5 :- q. and q., whose first head is flexible, any formula becomes provable. →\rightarrow Chapter 5; [MN p. 119].

Constant clash The failure of first-order unification on an equation whose two sides have distinct head constants. →\rightarrow Chapter 1; [MN p. 30].

Context (Ma–Friedman) The set of postponed equations between static closures of unification variables. A solution in their algorithm is a pair (grafting, context), much like Huet’s postponed flex-flex pairs. →\rightarrow Chapter 9.

Constraint store ((aux kanren micro)) Besides the substitution S, a state carries three stores: D for disequalities (≠°), A for type tags (symbol°, number°) and T for absento constraints (absent°), kept in records by variable. After a unification, the constraints of the variables it bound are posted again. →\rightarrow Chapter 10.

Constructive negation (Moiseenko) Negation for miniKanren that collects all the answers of gg and negates their disjunction. The states then contain universally quantified disequalities, which need a dedicated solver. It requires stratification, diverges on goals with infinitely many answers, and defines ∀\forall as ¬∃¬\neg\exists\negEvgenii Moiseenko. Constructive negation for miniKanren. In miniKanren and Relational Programming Workshop, 2019. →\rightarrow Chapter 9.

Contraction The structural rule that duplicates a hypothesis into a premise. It is the source of non-termination in naive provers for propositional intuitionistic logic. Contraction-free calculi such as Dyckhoff’s terminate. →\rightarrow Chapter 8; [MN p. 245].

Copy clauses Clauses copy that specify structural equality over an object signature, one clause per constructor. Adding the hypothesis copy c T for an eigenvariable c turns copying into object-level substitution, entirely inside LλL_\lambda. →\rightarrow Chapter 6; [MN p. 199].

CPS (continuation-passing style) In book Ch. 5, the threading of a continuation goal that yields binary clauses. In book Ch. 10, Fischer’s CPS transformation of functional programs. →\rightarrow Chapter 5 and Chapter 8; [MN p. 131], [MN p. 256].

Cut rule, cut elimination The cut rule is the lemma rule of the sequent calculus. Gentzen’s theorem shows it is admissibleGerhard Gentzen. Investigations into logical deductions. In M. E. Szabo, editor, The Collected Papers of Gerhard Gentzen, pages 68–131. North-Holland, Amsterdam, 1969. Translation of articles that appeared in 1934–35. Proof search looks only for cut-free proofs. The cut rule is unrelated to Prolog’s !. →\rightarrow Chapter 2; [MN p. 63], [MN p. 72].

Cut, Prolog’s ! The pruning operator. λProlog defines if and not with it, and it affects completeness. (aux kanren micro) has no !. Its closest tools are the soft cut if° and (take° 1 g). →\rightarrow Chapter 5 and Chapter 10; [MN p. 137].

D

D-formula, G-formula Program clauses and goals. Each language defines them by a pair of grammars. For fohc: G::=⊤∣A∣G∧G∣G∨G∣∃x GG ::= \top\mid A\mid G\wedge G\mid G\vee G\mid \exists x\,G and D::=A∣G⊃D∣D∧D∣∀x DD ::= A\mid G\supset D\mid D\wedge D\mid\forall x\,D. fohh adds D⊃GD\supset G and ∀x G\forall x\,G to the goals. →\rightarrow Chapter 2 and Chapter 3; [MN p. 43], [MN p. 76].

de Bruijn index, de Bruijn level Nameless representations of bound variablesN. G. de Bruijn. Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church–Rosser theorem. Indagationes Mathematicae, 34(5):381–392, 1972. An index counts binders outwards from the occurrence (1-based in the book). A level counts binders inwards from the root. In λc.λd.c\lambda c.\lambda d.c, cc has level 0 and index 1 when counting from 0. Teyjus uses indices in terms and levels in the context. ELPI uses levels throughout. →\rightarrow Chapter 6 and Chapter 9; [MN p. 192].

Decide, initial The two rules that start and end backchaining. decide picks a clause D∈𝒫D\in\mathcal{P} to focus on. initial closes a focused atom whose head matches the goal. →\rightarrow Chapter 2; [MN p. 45].

define-relation The (aux kanren micro) macro that defines a relation. It is inverse-η\eta-delayed: the body is built only when a state arrives, and then it suspends. →\rightarrow Chapter 10.

Definite formula A program formula that does not contain “indefinite information of the kind let in by disjunctions”. Disjunction (and, by the grammar, top-level ∃\exists) is banned from programs. →\rightarrow Chapter 2; [MN p. 42].

Delay, δ In (aux kanren micro), δ is CHICKEN’s memoising delay. A promise is an immature stream and is the unit of interleaving. →\rightarrow Chapter 10.

Delayed (postponed) equations Equations outside the decidable fragment, or flex-flex pairs, kept as constraints until further instantiation makes them tractable. Teyjus, DHKPGilles Dowek, Thérèse Hardin, Claude Kirchner, and Frank Pfenning. Unification via explicit substitutions: the case of higher-order patterns. In M. Maher, editor, Joint International Conference and Symposium on Logic Programming (JICSLP), pages 259–273. MIT Press, 1996 and the Ma–Friedman context postpone them. ELPI raises an error by default. The book’s version is dynamic LλL_\lambda. →\rightarrow Chapter 7 and Chapter 9; [MN p. 225]–[MN p. 226].

Delayed raising Instead of raising eagerly, keep with each existential variable the list of universals it may be raised over, and raise only when a binding needs it. These lists are initial segments of the prefix, so numerical indices represent themGopalan Nadathur and Natalie Linnell. Practical higher-order pattern unification with on-the-fly raising. In ICLP 2005: 21st International Logic Programming Conference, volume 3668 of LNCS, pages 371–386, Sitges, Spain, 2006. Springer. →\rightarrow Chapter 7; [MN p. 225].

Determinate type A type whose type variables are all transparent, that is, occur in the target type. →\rightarrow Chapter 2; [MN p. 67].

Difference list, functional difference list (dl L K) denotes LL minus its suffix KK. (fdl F), with F : list A -> list A, denotes F nil, and appending is function composition. →\rightarrow Chapter 5; [MN p. 140].

Disagreement set In nominal unification, the set of atoms on which two permutations differ. In Huet-style presentations, the multiset of pairs still to be unified. →\rightarrow Chapter 9.

Disequality constraint ≠° in (aux kanren micro), stored in the store D as the list of bindings that would make the two terms equal. Moiseenko’s constructive negation needs universally quantified disequalities insteadEvgenii Moiseenko. Constructive negation for miniKanren. In miniKanren and Relational Programming Workshop, 2019. →\rightarrow Chapter 10 and Chapter 9.

Disjunction / existence property In intuitionistic logic, ⊢F1∨F2\vdash F_1\vee F_2 implies ⊢Fi\vdash F_i for some ii, and ⊢∃x F\vdash\exists x\,F yields a witness. Harrop formulas guarantee these properties, which is why answer substitutions make sense. →\rightarrow Chapter 3; [MN p. 93].

Dynamic LλL_\lambda The practical regime in which LλL_\lambda is not imposed statically on clauses. Instead, the unification problems met at run time are expected to fall inside it, as in subst R N (R N) with R and N already instantiated. →\rightarrow Chapter 7; [MN p. 225]–[MN p. 226].

E

E-formula E::=D∣E∧E∣∃x EE ::= D\mid E\wedge E\mid\exists x\,E: a program formula with existentially quantified, local names. It gives modules with hidden constants a logical reading. →\rightarrow [MN p. 160]–[MN p. 162].

Eigenvariable, scoped constant The new constant that GENERIC (∀\forallR) introduces to prove ∀x G\forall x\,G. It is not in the current signature and is never instantiated. The eigenvariable condition says that no logic variable created before it may be bound to a term containing it. The book’s example is the sterile jar: to prove pi x\ bug x => in x j => dead x, pick a new bug constant and reason about it alone. →\rightarrow Chapter 3 and Chapter 4; [MN p. 82]–[MN p. 83].

eigen (Hemann, Byrd, Friedman) The operator of miniKanren-with-symbolic-constraints that creates eigen objects and installs an “eigen-absento” constraint over the list of all variables created so far. It is supported only together with ==Jason Hemann, William E. Byrd, and Daniel P. Friedman. The eigen operator of miniKanren-with-symbolic-constraints. Software, 2013. URL https://github.com/webyrd/miniKanren-with-symbolic-constraints. →\rightarrow Chapter 9.

Elementary substitution Huet’s partial bindings for a flex-rigid pair: imitation and projection. In Ma–Friedman’s reading, each unification variable takes every visible bound variable as an argument. →\rightarrow Chapter 7.

ELPI An embeddable λProlog interpreterCvetan Dunchev, Ferruccio Guidi, Claudio Sacerdoti Coen, and Enrico Tassi. ELPI: fast, embeddable, λ\lambdaProlog interpreter. In Logic for Programming, Artificial Intelligence, and Reasoning (LPAR-20), volume 9450 of LNCS, pages 460–468. Springer, 2015. It uses de Bruijn levels and annotates unification variables with levels XjX^j. It reports an error outside the pattern fragment by default, and it offers syntactic constraints. →\rightarrow Chapter 9.

Empty type A type with no closed inhabitant. Higher-order intuitionistic logic does not exclude empty types, and they matter for ∃\exists answers and for unification solutions. →\rightarrow Chapter 4; [MN p. 108].

eq?-invariant ((aux kanren micro)) A unification that adds no binding returns the very same state object. The disequality and entailment checks rely on this to recognise that nothing new was learned. →\rightarrow Chapter 10.

Essentially universal / essentially existential A classification of bound-variable occurrences. In a goal, an occurrence is essentially universal if it is bound by a positive ∀\forall, a negative ∃\exists, or a term-level λ\lambda. Otherwise it is essentially existential. Clauses use the dual classification. During search, essentially existential variables become logic variables and essentially universal ones become eigenvariables. →\rightarrow Chapter 6; [MN p. 205].

η\eta-conversion λx. (t x)=t\lambda x.\, (t\,x) = t when xx is not free in tt. →\rightarrow Chapter 4; [MN p. 101].

Evaluation context A term with a hole that marks where the next redex is. In book Ch. 10 it is a meta-level function tm -> tm. →\rightarrow Chapter 8; [MN p. 253].

Ex falso quodlibet From ⊥\bot, infer anything. Intuitionistic logic is minimal logic plus this rule. →\rightarrow Chapter 3; [MN p. 90].

Excluded middle B∨¬BB\vee\neg B: valid classically, rejected intuitionistically. It is one of the counterexamples that motivate banning disjunction from programs. →\rightarrow Chapter 2; [MN p. 42].

Existential generalisation From M(t)M(t) infer ∃x M(x)\exists x\,M(x). It explains the multiple answers of subst when run backwards. →\rightarrow Chapter 6; [MN p. 203].

Explicit substitution Calculi that make substitution a term constructor, so it can be delayed and composed. Examples are λσ\lambda\sigma (DHKP) and Teyjus’s suspension notation. →\rightarrow Chapter 9; [MN p. 209].

F

Flexible term, rigid term A βη\beta\eta-normal term is flexible if its head is an existential (unification) variable. It is rigid if its head is a constant or a universally bound or λ\lambda-bound variable. The names are suggestive: Ma and Friedman, following Huet, explain that a flexible term is one that “can be removed through a substitution (or a grafting)”, while a substitution never changes the head of a rigid termWeixi Ma and Daniel P. Friedman. A new higher-order unification algorithm for λ\lambdaKanren. In miniKanren and Relational Programming Workshop, 2021. →\rightarrow Chapter 4 and Chapter 7; [MN p. 111], [MN p. 214].

Flexible atom, rigid atom, flexible goal An atom is flexible if its head is a variable and rigid if its head is a non-logical constant. Clause heads must be rigid. A flexible goal whose head is still uninstantiated when it is called is underconstrained. →\rightarrow Chapter 5; [MN p. 119], [MN p. 132].

Flex-flex, flex-rigid, rigid-rigid The classification of equations by the heads of their two sides. Rigid-rigid pairs simplify by decomposition or fail by a clash. Flex-rigid pairs call for imitation or projection. Flex-flex pairs always have unifiers, though not necessarily solutions, and are postponed. →\rightarrow Chapter 7; [MN p. 113], [MN p. 217].

Focused proof Andreoli’s generalisation of the two-phase structure of goal reduction followed by backchaining. Focusing groups small rules into large onesJean-Marc Andreoli. Logic programming with focusing proofs in linear logic. Journal of Logic and Computation, 2(3):297–347, 1992. →\rightarrow Chapter 2; [MN p. 73].

fohc, fohh, hohc, hohh, hohh+^{+} The book’s languages: first-order Horn clauses [MN p. 43], first-order hereditary Harrop formulas [MN p. 76], higher-order Horn clauses [MN p. 122], higher-order hereditary Harrop formulas [MN p. 124], and hohh+^+, which additionally allows atomic clauses headed by an essentially universal variable [MN p. 125]. →\rightarrow Chapter 2, Chapter 3 and Chapter 5.

Free for tt is free for xx in BB if substituting tt for xx in BB captures no free variable of tt. →\rightarrow Chapter 3; [MN p. 85].

Fresh, fresh° miniKanren’s existential quantifier, which introduces logic variables. In (aux kanren micro), fresh° introduces them one at a time, and each allocation suspends once. For the αKanren meaning, see Atom (nominal). →\rightarrow Chapter 10.

Freshness constraint a#ta\mathbin{\#}t: the atom aa does not occur free in tt, also after later instantiation of the variables in tt. It is written hash in αKanrenChristian Urban, Andrew M. Pitts, and Murdoch J. Gabbay. Nominal unification. Theoretical Computer Science, 323(1–3):473–497, 2004. →\rightarrow Chapter 9.

G

Generic judgment, universal judgment A generic judgment is parametric in a new object and is proved once, with an eigenvariable. A universal judgment holds for all terms. The two coincide under the open-world assumption. They correspond to the intensional and the extensional readings of ∀\forall. →\rightarrow Chapter 3; [MN p. 83], [MN p. 94].

GENERIC The rule for ∀x G\forall x\,G: add a new constant cc to the signature and prove G[c/x]G[c/x]. It is pi x\ G in λProlog and all in λKanren.

Σ∪{c};𝒫⟶G[c/x]Σ;𝒫⟶∀x G  generic(c∉Σ)\dfrac{\Sigma\cup\{c\};\mathcal{P}\longrightarrow G[c/x]}{\Sigma;\mathcal{P}\longrightarrow\forall x\,G}\;\text{generic}\quad(c\notin\Sigma)

→\rightarrow Chapter 3; [MN p. 39], [MN p. 82].

Goal (miniKanren) In (aux kanren micro), a procedure from a state to a stream of states. ✓° succeeds once and ✗° fails. →\rightarrow Chapter 10.

Goal-directed search, goal reduction A non-atomic goal is decomposed by its top-level connective, independently of the program. This fixes the “search semantics” of the connectives. Only atomic goals consult the program. →\rightarrow Chapter 1 and Chapter 2; [MN p. 3], [MN p. 39].

Grafting First-order, capture-permitting replacement of a metavariable by a term, written {X↦t}\{X\mapsto t\}: grafting X↦aX\mapsto a into λa.X\lambda a.X gives λa.a\lambda a.a. DHKP “pre-cook” terms so that grafting respects scopes. Ma and Friedman combine grafting with de Bruijn levelsWeixi Ma and Daniel P. Friedman. A new higher-order unification algorithm for λ\lambdaKanren. In miniKanren and Relational Programming Workshop, 2021. →\rightarrow Chapter 9.

Grounding In (aux kanren micro), °->list/ground evaluates a reified answer, applying its λ\lambda to its own variable names. Constraints are dropped. →\rightarrow Chapter 10.

H

Harrop formula H::=⊤∣A∣H∧H∣B⊃H∣∀x HH ::= \top\mid A\mid H\wedge H\mid B\supset H\mid\forall x\,H. These formulas guarantee the disjunction and existence properties at the root of a proof. →\rightarrow Chapter 3; [MN p. 93].

Herbrand universe H1ΣH_1^{\Sigma}, H2ΣH_2^{\Sigma} The terms allowed as quantifier instances. H1ΣH_1^{\Sigma} (for hohc) contains the λ\lambda-normal terms over Σ\Sigma without ∀\forall and ⊃\supset. H2ΣH_2^{\Sigma} (for hohh) contains those without ⊃\supset. →\rightarrow Chapter 5; [MN p. 122].

Hereditary Harrop formula A D-formula of fohh or hohh. Equivalently, a formula with no positive occurrence of a disjunction or an existential. Unlike Horn clauses, these formulas let the signature and the program grow during search. →\rightarrow Chapter 3; [MN p. 4], [MN p. 76].

Higher-order abstract syntax (HOAS) The principle of encoding object-level binders by meta-level bindersFrank Pfenning and Conal Elliott. Higher-order abstract syntax. In Proceedings of the ACM-SIGPLAN Conference on Programming Language Design and Implementation, pages 199–208, New York, 1988. ACM Press. It is ambiguous between a functional reading, in which binders are host functions that cannot be analysed, and the logical reading, λ-tree syntax. →\rightarrow Chapter 6; [MN p. 204].

Higher-order logic The book distinguishes three senses: second-order model theory; proof theory with predicate quantification and comprehension; and Church’s simple theory of types, with λ\lambda-terms and quantification at higher types. The book works in the third. →\rightarrow Chapter 1; [MN p. 5].

Higher-order pattern A term in which every occurrence of an existential variable FF is applied to distinct variables, either essentially universal or λ\lambda-bound, whose binders lie within the scope of FF. For example, λx. λy. F y x\lambda x.\, \lambda y.\, F\,y\,x is a pattern, while λx. F x x\lambda x.\, F\,x\,x (repeated argument) and F cF\,c with cc a signature constant (not a bound variable) are not. →\rightarrow Chapter 6 and Chapter 7; [MN p. 205], [MN p. 220].

Higher-order pattern unification (LλL_\lambda-unification) Unification restricted to patterns. It is decidable, and unifiable problems have an mguDale Miller. A logic programming language with lambda-abstraction, function variables, and simple unification. Journal of Logic and Computation, 1(4):497–536, 1991; and Tobias Nipkow. Functional unification of higher-order patterns. In M. Vardi, editor, 8th Symposium on Logic in Computer Science, pages 64–74, New York, 1993. IEEE. Its steps include an occurs check and variable elimination with pruning. →\rightarrow Chapter 7; [MN p. 220]–[MN p. 223].

Higher-order programming Passing predicates as arguments, as in mappred and foldl. →\rightarrow Chapter 5; [MN p. 126].

Higher-order unification Unification of simply typed λ\lambda-terms modulo λ\lambda-conversion. It is undecidable (the book reduces Post’s correspondence problem and Hilbert’s tenth problem to it), has no mgus in general, and is semi-decided by Huet’s procedureGérard Huet. A unification algorithm for typed λ\lambda-calculus. Theoretical Computer Science, 1:27–57, 1975. →\rightarrow Chapter 4 and Chapter 7; [MN p. 111], [MN p. 114]–[MN p. 115], [MN p. 214].

Horn clauses The class of programs in which the signature and the program stay fixed during search: they are “flat and global”. →\rightarrow Chapter 2; [MN p. 43], [MN p. 46].

Huet’s procedure, pre-unification Repeated simplification, imitation and projection, stopping when only flex-flex pairs remainGérard Huet. A unification algorithm for typed λ\lambda-calculus. Theoretical Computer Science, 1:27–57, 1975. The result is a pre-unifier, whose search space is explored as a matching tree. →\rightarrow Chapter 7; [MN p. 218]–[MN p. 219].

Hypothetical reasoning Proving a goal under temporarily assumed clauses, by AUGMENT. The book’s example is the question “If person X took just one more course Y, will he or she graduate with a CS degree?”, posed as the query fact (finished X Y) => (fact (graduates X), fact (cs_major X)). →\rightarrow Chapter 3; [MN p. 79]–[MN p. 80].

I

if, not λProlog’s conditional and negation-as-failure, both defined with the cut. →\rightarrow Chapter 5; [MN p. 137].

if° (soft cut) (if° g? gt gf): if g? has at least one answer, every one of its answers continues with gt; otherwise gf runs. It corresponds to miniKanren’s conda and LogicT’s ifte. λProlog’s if becomes (if° (take° 1 P) Q R). →\rightarrow Chapter 10.

Imitation, projection Huet’s partial bindings for a flex-rigid pair. Imitation copies the rigid head: F:=λx¯. c (H1x¯)⋯(Hmx¯)F:=\lambda\bar x.\,c\,(H_1\bar x)\cdots(H_m\bar x). Projection selects an argument: F:=λx¯. xi (H1x¯)⋯(Hkx¯)F:=\lambda\bar x.\,x_i\,(H_1\bar x)\cdots(H_k\bar x), which requires matching target types. →\rightarrow Chapter 7; [MN p. 215].

Intensional / extensional equality Intensional equality compares the structure of λ\lambda-terms. Extensional equality compares what they denote. λProlog’s = is intensional (modulo λ\lambda-conversion). →\rightarrow Chapter 5; [MN p. 146].

Intensional / extensional ∀\forall pi is intensional: it requires one generic proof, so it cannot express “for all instances”. This is why book Ch. 11’s simulation is incorrect. Jin et al. implement an extensional ∀\forall in miniKanren, which is a different logicEnde Jin, Gregory Rosenblatt, Matthew Might, and Lisa Zhang. Universal quantification and implication in miniKanren. In miniKanren and Relational Programming Workshop, 2021. →\rightarrow Chapter 3 and Chapter 8; [MN p. 83], [MN p. 94].

Interleaving miniKanren’s search discipline. In (aux kanren micro), orª uses append§/interleaved/2, which swaps the two streams whenever the first one is a suspension, and conjunction (append-map§) interleaves too. The right-nested or° gives the first of three infinite branches about half of the answers. →\rightarrow Chapter 10.

Inverse-η\eta delay The wrapping (λ (s) (δ ((and° g …) s))) that define-relation puts around a body, so that a recursive relation without fresh° does not loop while the goal tree is built. →\rightarrow Chapter 10.

Inversion of a pattern substitution The core step of pattern unification. To solve X y¯=tX\,\bar y = t, where y¯\bar y are distinct bound variables, abstract tt over y¯\bar y, that is, X:=λy¯. tX:=\lambda\bar y.\,t. This works only if every bound variable free in tt is among y¯\bar y and XX does not occur in tt; otherwise pruning or the occurs check takes over. DHKP write the inverse as b[ξ]−1b[\xi]^{-1}, and Nipkow’s code remaps de Bruijn indices. →\rightarrow Chapter 7.

Invertible rule A rule whose premises are provable if and only if its conclusion is. Such rules can be applied eagerly without losing completeness. →\rightarrow Chapter 8; [MN p. 243].

Iterative deepening Retrying a search with bound N+1N+1 after failing with bound NN. In book Ch. 9 it bounds the multiplicity of ∃\exists-formulas. →\rightarrow Chapter 8; [MN p. 237], [MN p. 239].

K

Kind The “type” of a type constructor, of the form type -> ... -> type, introduced by a kind declaration. →\rightarrow Chapter 1; [MN p. 11]–[MN p. 12].

Kripke model The possible-worlds semantics of intuitionistic logic. Its worlds correspond to signature–program pairs. →\rightarrow Chapter 3; [MN p. 94].

L

LλL_\lambda The sublanguage of hohh in which quantification is never over predicate types, and every essentially existential variable is applied only to distinct essentially universal variables bound within its scope. Unification inside LλL_\lambda needs only β0\beta_0, is decidable and produces mgus. →\rightarrow Chapter 6 and Chapter 7; [MN p. 205]–[MN p. 206], [MN p. 220].

λ\lambda-conversion, λ\lambda-normal form λ\lambda-conversion is the closure of α\alpha, β\beta and η\eta, and it is the equality of the logic. The λ\lambda-normal form λnorm(s)\lambda norm(s) is the βη\beta\eta-normal form. →\rightarrow Chapter 4; [MN p. 100]–[MN p. 102].

λ-tree syntax HOAS with simply typed λ\lambda-terms, taken modulo α\alpha, a weak β\beta (β0\beta_0) and possibly η\eta, used as a data structure that unification can still analyse. →\rightarrow Chapter 6; [MN p. 204].

λKanren miniKanren extended with higher-order logic programming. The 2020 version has terms tie and app, goals assume (D⊃GD\supset G) and all (∀x G\forall x\,G), and Miller’s pattern unification over an explicit prefixWeixi Ma, Kuang-Chen Lu, and Daniel P. Friedman. Higher-order logic programming with λ\lambdaKanren. In miniKanren and Relational Programming Workshop, 2020. The 2021 paper proposes static closuresWeixi Ma and Daniel P. Friedman. A new higher-order unification algorithm for λ\lambdaKanren. In miniKanren and Relational Programming Workshop, 2021. →\rightarrow Chapter 9.

Left- and right-introduction rules Right rules introduce a connective on the right of ⟶\longrightarrow and implement goal reduction. Left rules decompose the clause in focus and implement backchaining. →\rightarrow Chapter 2; [MN p. 40], [MN p. 42], [MN p. 45].

Legitimate substitution For a problem ∀u¯ ∃x¯ ∀w¯ [… ]\forall\bar u\,\exists\bar x\,\forall\bar w\,[\dots], a substitution for x¯\bar x in whose range no wjw_j occurs free. Only legitimate substitutions can be unifiers. This is the eigenvariable condition, stated for unification. →\rightarrow Chapter 4; [MN p. 109].

Leibniz equality x=yx=y if and only if ∀P (P x⊃P y)\forall P\,(P\,x\supset P\,y). →\rightarrow Chapter 5; [MN p. 120].

Level of a unification variable The scope depth of a variable. ELPI’s XjX^j may mention only context names below jj. In Teyjus, a variable may be bound only to terms whose constants have a tag no larger than its own. Binding a variable must lower the levels of the variables in the bound term. →\rightarrow Chapter 7 and Chapter 9.

Locally nameless A representation with bound variables as de Bruijn indices and free variables as namesConor McBride and James McKinna. Functional pearl: I am not a number — I am a free variable. In Proceedings of the ACM SIGPLAN Workshop on Haskell, 2004; and Arthur Charguéraud. The locally nameless representation. Journal of Automated Reasoning, 49(3):363–408, 2012. Eigen constants would play the role of the names. →\rightarrow Chapter 9.

Logic variable A placeholder that search instantiates by unification. It is the operational device behind the delayed choice of terms in the ∃\existsR, ∀\forallL and initial rules. →\rightarrow Chapter 2; [MN p. 61].

M

Matching A unification problem in which only one side contains existential variables. Higher-order matching is decidable. →\rightarrow Chapter 7; [MN p. 227].

Matching tree The search tree of Huet’s procedure. Its nodes are multisets of equations and its arcs are substitutions. A failure node is a problem that obviously has no solution (for example, a rigid-rigid clash); a success node contains at most flex-flex pairs, and reaching one is a pre-unification. Some paths may be infinite. →\rightarrow Chapter 7; [MN p. 219].

Matrix The conjunction of equations t1=s1∧⋯∧tm=smt_1=s_1\wedge\dots\wedge t_m=s_m under the quantifier prefix of a unification problem. →\rightarrow Chapter 7; [MN p. 211].

May judgment, must judgment A may judgment asserts that some computation path exists. A must judgment states a property of all paths, and needs negation-as-failure or a meta-level ∀\forall. →\rightarrow Chapter 8; [MN p. 269].

Metalanguage, object language λProlog, the language in which we write, and the language encoded in it. →\rightarrow Chapter 1; [MN p. 22].

Minimal logic Logic in which ⊥\bot is an ordinary constant. Negation is defined as ¬B:=B⊃𝖿𝖺𝗅𝗌𝖾\neg B := B\supset\mathsf{false}. →\rightarrow Chapter 3; [MN p. 89]–[MN p. 90].

miniKanren A family of small relational languages embedded in a host languageDaniel P. Friedman, William E. Byrd, Oleg Kiselyov, and Jason Hemann. The Reasoned Schemer. MIT Press, 2nd edition, 2018; and William E. Byrd. Relational Programming in miniKanren: Techniques, Applications, and Implementations. PhD thesis, Indiana University, 2009. →\rightarrow Chapter 10.

Mixed prefix The quantifier prefix ∀∃∀…\forall\exists\forall\dots of a unification problem. In a ∀∃∀\forall\exists\forall problem the outer universals act as the signature and the inner ones as eigenvariables, and no raising is needed. →\rightarrow Chapter 4 and Chapter 7; [MN p. 105], [MN p. 211].

Module, signature (Teyjus) A module is a named collection of declarations and clauses. Its signature restricts what is visible from outside, and hidden constants are read as existentially quantified (book Ch. 6). →\rightarrow Chapter 1; [MN p. 152]–[MN p. 153], [MN p. 277].

Most general unifier (mgu) A unifier θ\theta such that every other unifier is θ\theta followed by a further substitution. In the first-order case an mgu exists whenever a unifier does, and it is unique up to renaming. Pattern problems have mgus too, but general higher-order problems do not. →\rightarrow Chapter 1 and Chapter 7; [MN p. 28], [MN p. 213], [MN p. 222].

μKanren Hemann and Friedman’s minimal miniKanren, in which goals are functions from a state to a stream of statesJason Hemann and Daniel P. Friedman. μ\muKanren: A minimal functional core for relational programming. In Proceedings of the 2013 Workshop on Scheme and Functional Programming (Scheme ’13), 2013. (aux kanren micro) is a μKanren with constraint stores. →\rightarrow Chapter 10.

Multiplicity In the classical prover of book Ch. 9, the number of times an ∃\exists-formula may be instantiated. Bounding it, and raising the bound after each failure, gives a complete semi-decision procedure. →\rightarrow Chapter 8; [MN p. 237].

N

∇\nabla (nabla) The Miller–Tiu generic quantifier for fresh names, in a logic with definitions (closed world). It is not part of λProlog. →\rightarrow Chapter 3 and Chapter 8; [MN p. 94], [MN p. 275].

Name shadowing An inner binder that reuses an outer binder’s name, so that the outer binder can no longer be named. →\rightarrow Chapter 9.

Natural deduction Introduction and elimination rules, with hypotheses discharged by ⊃\supsetI, ∨\veeE and ∃\existsE. Book Ch. 9 encodes it with => and pi. →\rightarrow Chapter 8; [MN p. 231].

Negation-as-failure not G succeeds if and only if G finitely fails. It is non-logical and unsound on non-ground goals. In (aux kanren micro) it is written (if° (take° 1 g) ✗° ✓°). Without the take° 1, it diverges whenever the search for further answers of g does not terminate, even if g has a single answer.Section B.3 runs an example. →\rightarrow Chapter 5 and Chapter 8; [MN p. 137], [MN p. 269].

Negation normal form, prenex normal form NNF has no implications and applies negation only to atoms. A prenex form has all its quantifiers in front. →\rightarrow Chapter 6; [MN p. 195].

Nominal logic, nominal unification A first-order treatment of binding with names, swappings and freshness. Nominal unification works modulo α\alpha and never generates new namesChristian Urban, Andrew M. Pitts, and Murdoch J. Gabbay. Nominal unification. Theoretical Computer Science, 323(1–3):473–497, 2004. →\rightarrow Chapter 9; [MN p. 210].

O

o The type of propositions, named after Church’s omicron. The quantifier names pi and sigma likewise follow Church’s Π\Pi and Σ\Sigma. →\rightarrow Chapter 1; [MN p. 74].

Object-level substitution Substituting into the body of an encoded binder. In λ-tree syntax it is meta-level β\beta-reduction, as in the clause subst R N (R N). with R : tm -> tm. That clause lies outside LλL_\lambda, but it is used only with R and N instantiated (dynamic LλL_\lambda). Copy clauses specify the same relation inside LλL_\lambda. →\rightarrow Chapter 6; [MN p. 180], [MN p. 199], [MN p. 225].

O-proof A derivation that uses only goal reduction (right rules) followed by backchaining (focused left rules). Every provable fohc sequent has an O-proof. →\rightarrow Chapter 2; [MN p. 45].

Occurs check x=tx=t fails when xx occurs properly in tt. In pattern unification, the corresponding failure is a flexible head occurring rigidly on the other side. (aux kanren micro) performs the check when it extends the substitution. →\rightarrow Chapter 1 and Chapter 7; [MN p. 30], [MN p. 223].

Order of a type 00 for non-functional types, and max⁡(ord τ1+1,ord τ2)\max(\mathrm{ord}\,\tau_1+1,\mathrm{ord}\,\tau_2) for τ1→τ2\tau_1\to\tau_2. →\rightarrow Chapter 1 and Chapter 4; [MN p. 13].

P

Pattern See Higher-order pattern. Ma and Friedman’s phrasing, for an application form F aF\,a: “if FF is a unification variable, then aa must be a list of zero or more distinct bound variables”.

Peirce’s formula ((p⊃q)⊃p)⊃p((p\supset q)\supset p)\supset p: valid classically but not intuitionistically. It has no O-proof. →\rightarrow Chapter 3; [MN p. 89].

Pervasive Built in and globally available: sorts such as int, constants such as nil and ::, and predicates such as is. →\rightarrow Chapter 1; [MN p. 14], [MN p. 49].

pi, sigma λProlog’s quantifiers, constants of type (A -> o) -> o. ∀x G\forall x\,G is written pi x\ G, the application of pi to the abstraction x\ G, so the term-level λ\lambda is the only binder. →\rightarrow Chapter 1 and Chapter 4; [MN p. 36], [MN p. 99].

π\pi-calculus Milner’s calculus of mobile processes, in which names are the only data. Book Ch. 11 encodes it in λ-tree syntax, using in and nu as binders. →\rightarrow Chapter 8; [MN p. 261].

Polarity, positive and negative occurrence An occurrence is positive if it lies to the left of an even number of implications and negative if odd. Cut-free search preserves polarity, unless implications appear inside atoms. →\rightarrow Chapter 3 and Chapter 5; [MN p. 76], [MN p. 121]–[MN p. 122].

Pre-cooking (DHKP) Translating a metavariable that occurs under nn binders into X[↑n]X[\uparrow^n], so that first-order grafting agrees with capture-avoiding substitutionGilles Dowek, Thérèse Hardin, Claude Kirchner, and Frank Pfenning. Unification via explicit substitutions: the case of higher-order patterns. In M. Maher, editor, Joint International Conference and Symposium on Logic Programming (JICSLP), pages 259–273. MIT Press, 1996. →\rightarrow Chapter 9.

Pre-unifier A substitution that reduces a problem to flex-flex pairs only. Such a remainder always has a unifier, the canonical substitution. →\rightarrow Chapter 7; [MN p. 217]–[MN p. 218].

project° (aux kanren micro)’s escape to Scheme: it binds Scheme variables to deep-walked values, in which unbound variables remain variable records, and then runs goals. It is non-relational. →\rightarrow Chapter 10.

Proof term A λ\lambda-term of type proof that records a derivation, as in the judgment P # A (“PP is a proof of AA”). →\rightarrow Chapter 8; [MN p. 233].

Pruning Removing from a variable its dependency on arguments that cannot occur in any solution: G:=λd¯. (G′ e¯)G:=\lambda\bar d.\,(G'\,\bar e), where e¯\bar e keeps only the allowed arguments. →\rightarrow Chapter 7; [MN p. 223].

Purification The step of (aux kanren micro)’s reification that drops constraints mentioning variables unreachable from the answer. →\rightarrow Chapter 10.

R

Raising ∀y ∃x G⇝∃h ∀y G[(h y)/x]\forall y\,\exists x\,G \rightsquigarrow \exists h\,\forall y\,G[(h\,y)/x]: an existential in the scope of a universal becomes the application of a new, higher-type existential quantified further out. Raising preserves LλL_\lambda. The book calls it a dual of Skolemization: Skolemization introduces a new constant of a raised type, raising a new existential variable of a raised type. →\rightarrow Chapter 4 and Chapter 7; [MN p. 108], [MN p. 208], [MN p. 212].

Reduction rules AND, OR, INSTAN, AUGMENT, GENERIC and TRUE: the search meaning of each logical symbol. →\rightarrow Chapter 2; [MN p. 39].

Reduction-free fragment LλβL^{\beta}_{\lambda} (ELPI) The patterns in which a unification variable XjX^j is applied exactly to the bound variables xj…xj+k−1x_j\dots x_{j+k-1} that follow its level. Binding such a variable needs no β\beta-reduction and takes constant time, but the fragment is not stable under resolutionCvetan Dunchev, Ferruccio Guidi, Claudio Sacerdoti Coen, and Enrico Tassi. ELPI: fast, embeddable, λ\lambdaProlog interpreter. In Logic for Programming, Artificial Intelligence, and Reasoning (LPAR-20), volume 9450 of LNCS, pages 460–468. Springer, 2015. →\rightarrow Chapter 9.

Reification Turning the final state into a presentable answer. (aux kanren micro) produces a closed Scheme expression (λ (α β …) constraint-form … term), naming free variables in order of first occurrence. αKanren prints noms as a.0, a.1, … and adds freshness constraints. →\rightarrow Chapter 10.

Relation ((aux kanren micro)) A procedure from terms to a goal, conventionally named name° and defined with define-relation. →\rightarrow Chapter 10.

Relative complement (Jin et al.) A goal that describes the values of a variable not covered by a state. It is used to implement an extensional ∀\forallEnde Jin, Gregory Rosenblatt, Matthew Might, and Lisa Zhang. Universal quantification and implication in miniKanren. In miniKanren and Relational Programming Workshop, 2021. →\rightarrow Chapter 9.

Representation independence Replacing a module by an equivalent one does not change the meaning of the larger program. →\rightarrow [MN p. 151].

Rigid See Flexible term, rigid term and Flexible atom.

S

Scope check, eigenvariable condition No variable older than an eigenvariable may reach it. The implementations differ: an explicit quantifier prefix (Miller; λKanren 2020), universe indices or levels (Teyjus, ELPI), an absento-like constraint over the variables in scope (eigen), or an end-of-scope check, which is fragile. →\rightarrow Chapter 9 and Chapter 10.

Scope extrusion The book’s name for the classical equivalence B1∨(B2⊃B3)≡B2⊃(B1∨B3)B_1\vee(B_2\supset B_3)\equiv B_2\supset(B_1\vee B_3), which moves the scope of an implication over a disjunction. It fails intuitionistically: p∨(p⊃q)p\vee(p\supset q) has no O-proof, although its classical equivalent p⊃(p∨q)p\supset(p\vee q) does. The term is borrowed from the π\pi-calculus, where it means sending a restricted name out and re-closing its scope at the receiver. →\rightarrow Chapter 3 and Chapter 8; [MN p. 89], [MN p. 95].

Scope restriction Ma and Friedman’s name for the eigenvariable condition in unification: a ∀\forall-bound variable may occur in the instantiation of an ∃\exists-variable only if it precedes that variable in the prefix. →\rightarrow Chapter 9.

Shallow embedding Implementing a logic language as host-language procedures and macros, as miniKanren does in Scheme, instead of writing an interpreter or compiler for it. λKanren keeps this styleWeixi Ma, Kuang-Chen Lu, and Daniel P. Friedman. Higher-order logic programming with λ\lambdaKanren. In miniKanren and Relational Programming Workshop, 2020. →\rightarrow Chapter 9 and Chapter 10.

Sequent Σ;𝒫⟶G\Sigma;\mathcal{P}\longrightarrow G: signature, program and goal. It is read both as the state of an interpreter and as a logical judgment. →\rightarrow Chapter 2; [MN p. 39].

Signature A set of typed non-logical constants. In Teyjus, a signature is also a module’s interface (sig). →\rightarrow Chapter 1; [MN p. 17], [MN p. 153].

Signature–program pair ⟨Σ,𝒫⟩\langle\Sigma,\mathcal{P}\rangle, the context in which queries are posed. Under the open-world assumption these pairs are the worlds of a Kripke model. →\rightarrow Chapter 2 and Chapter 3; [MN p. 39], [MN p. 94].

Simplification Repeated decomposition, or clash, of rigid-rigid pairs in higher-order unification. →\rightarrow Chapter 7; [MN p. 214].

Skolemization Replacing an existential in an assumption by a function of the enclosing universals, as in ∀x D[f x/y]\forall x\,D[f\,x/y]. It is the dual of raising. →\rightarrow Chapter 4; [MN p. 108].

Soft cut See if°. A soft cut is not complete in general.

Solution A unifier whose range has free variables only among the outer universals. A solution amounts to a proof of the quantified equation. →\rightarrow Chapter 4 and Chapter 7; [MN p. 109].

Solved form A set of equations x=tx=t in which each left-hand variable occurs nowhere else. It is read as an idempotent mgu. →\rightarrow Chapter 1; [MN p. 29].

Static closure ⟨ϕ;t⟩\langle\phi;t\rangle (Ma–Friedman): a term paired with the scope, the list of binder names around it, manipulated by ext\mathrm{ext} and db\mathrm{db}. The authors call the paper “a preview” and leave soundness and completeness to future workWeixi Ma and Daniel P. Friedman. A new higher-order unification algorithm for λ\lambdaKanren. In miniKanren and Relational Programming Workshop, 2021. →\rightarrow Chapter 9.

Stream (§) In aux, a stream is '(), a mature pair (state . §), or an immature promise. →\rightarrow Chapter 10.

Subject reduction Evaluation preserves types. →\rightarrow Chapter 6; [MN p. 191].

Substitution ((aux kanren micro)) The store S: a triangular substitution kept in a skew-binary random-access list indexed by variable number. →\rightarrow Chapter 10.

Subsumption ((aux kanren micro)) Dropping a constraint that another constraint implies, or that a type tag or an absento constraint makes vacuous. →\rightarrow Chapter 10.

Suspension Four different things, depending on the source; see the pitfall at the start of this appendix.

Swapping (a  b)(a\;b) exchanges the atoms aa and bb throughout a term. Permutations are lists of swappings. →\rightarrow Chapter 9.

Syntactic constraint (ELPI) A goal suspended on some variables with declare_constraint and resumed when one of them is assigned. It keeps its hypothetical context. →\rightarrow Chapter 9.

T

take° (take° n g) keeps the first n answers of g; a negative n keeps them all. It is a goal, so it nests, and (take° 1 g) is miniKanren’s once. μkanren-run is take° around a fresh° query. →\rightarrow Chapter 10.

Tactic, tactical A tactic is a relation goal -> goal -> o from a primitive goal to the goal of its premises. Tacticals such as then, orelse, repeat, try and maptac combine tactics. Book Ch. 9 recasts the LCF architecture relationally. →\rightarrow Chapter 8; [MN p. 241], [MN p. 243].

Target type τ0\tau_0 in τ1→⋯→τn→τ0\tau_1\to\dots\to\tau_n\to\tau_0. →\rightarrow Chapter 1; [MN p. 13].

Term reduction, variable elimination Two of the three transformations of first-order unification; the third is reorientation. Term reduction decomposes equal heads. Variable elimination replaces a variable by its value everywhere. →\rightarrow Chapter 1; [MN p. 28].

Teyjus The λProlog implementation used by the book, with compiler tjcc, linker tjlink and simulator tjsim. Teyjus 2 uses universe-level tags. →\rightarrow Chapter 1; [MN p. 277].

Trace, complete trace, trace equivalence A trace is a sequence of actions of a process, and a complete trace ends in a terminal process. Two processes are trace equivalent if no trace separates them. →\rightarrow Chapter 8; [MN p. 267], [MN p. 269], [MN p. 271].

Transparent type variable A type variable that occurs in the target type. →\rightarrow Chapter 2; [MN p. 67].

Type lowering A polarity-indexed translation from a relation at a higher type to formulas over base-type relations. It generates copy clauses. →\rightarrow Chapter 6; [MN p. 201]–[MN p. 202].

U

Unification problem, unifier In the first-order case, a problem is a finite multiset of equations, and a unifier is a type-preserving substitution that makes both sides of each equation equal. In general, a problem is a quantified formula Q1x1…Qnxn[⋀jtj=sj]Q_1x_1\dots Q_nx_n[\bigwedge_j t_j=s_j], and a unifier is a legitimate substitution (no inner universals in its range) that makes each pair λ\lambda-convertible. →\rightarrow Chapter 1 and Chapter 4; [MN p. 26], [MN p. 105], [MN p. 109].

Unification ((aux kanren micro)), =° First-order syntactic unification with occurs check. Pairs, vectors and records are decomposed slot by slot, so a vector and a record with the same slots unify. When two variables meet, the one with the lower index is bound to the other. →\rightarrow Chapter 10.

Uniform proof A cut-free sequent proof in which every sequent with a non-atomic goal is the conclusion of the right-introduction rule for that goal’s top-level connective. It formalises goal-directed searchDale Miller, Gopalan Nadathur, Frank Pfenning, and Andre Scedrov. Uniform proofs as a foundation for logic programming. Annals of Pure and Applied Logic, 51:125–157, 1991. →\rightarrow Chapter 2; [MN p. 73].

Universe index (Nadathur, Jayaraman, Kwon) A numeric tag on constants and logic variables that records the ∀\forall-nesting at their creation. Entering a universal goal increments the index. A variable may be bound only to terms whose constants have a tag no larger than its own, and the binding lowers the tags of the variables in the termGopalan Nadathur, Bharat Jayaraman, and Keehang Kwon. Scoping constructs in logic programming: implementation problems and their solution. Journal of Logic Programming, 25(2):119–161, 1995. The book mentions the idea as numerical indices on quantified variables [MN p. 225] and as universe level tags [MN p. 227]. →\rightarrow Chapter 7 and Chapter 9.

Universe level See Universe index and Level of a unification variable.

V

Vacuous quantifier A quantifier whose variable does not occur in its body. →\rightarrow Chapter 6; [MN p. 195].

Value constructor A constant of functional type used to build data, such as ::. →\rightarrow Chapter 1; [MN p. 14].

Variable elimination (patterns) The step of pattern unification that combines imitation, projection, the occurs check and pruning into one binding F:=λc¯. t′F:=\lambda\bar c.\,t'. →\rightarrow Chapter 7; [MN p. 223].

W

Walk Resolving a variable through the substitution. μkanren-state-find is the shallow walk: it follows the chain of variable bindings until it reaches a non-variable or an unbound variable. μkanren-state-find/value is the deep walk: it also walks inside pairs, vectors and records. →\rightarrow Chapter 10.

WAM The Warren Abstract Machine, the classical implementation model of Prolog. →\rightarrow [MN p. 74].

Working variable, reified variable In (aux kanren micro), a working variable has index ≥0\ge 0, lives during search and prints as _i. A reified variable has a negative index, appears only in answers and prints as α, β, … →\rightarrow Chapter 10.

B.3A vocabulary bridge

Table B.2 lines up the names that the three communities use for the same concept. Read it across a row: a cell left empty means the concept has no counterpart in that column today.

Book (λProlog)miniKanren literature(aux kanren micro) alone(aux kanren lambda)
logic variable, ∃\exists in goals (sigma)freshfresh°fresh°, with a level
backchaining on a clausecalling a relationa define-relation callalso a define-dynamic-relation call
∨\vee in goals (;)condeor°, cond°unchanged
first-order unification with occurs check===°=°, through the unify and post hooks
not, if (via !)conda, conduif°, take°unchanged
augment, D => Gassume (λKanren)—⊃°, define-dynamic-relation
generic, pi x\ G, eigenvariableall (λKanren), eigen—∀°, with universe levels
λ\lambda-terms, x\ ttie/app (λKanren), tie on noms (αKanren)first-order encodings only (e.g. records with de Bruijn indices)ƛ, @
pattern unification, raising, pruningλKanren 2020 unifier; static closures (2021)—the unify and post hooks with levels; non-patterns delayed in E
answer substitutionreified answerμkanren-project, °->list°->list/datum, °->pretty
Table B.2: The same concepts under three names, and in the module. The empty cells of the third column are what (aux kanren lambda) supplies (Chapter 12).

Kanren angle (what the glossary says about the missing pieces). The empty cells of Table B.2 are the λProlog features that (aux kanren micro) alone lacks: a dynamic clause database for AUGMENT, eigenvariables with a scope check for GENERIC, and terms with binders together with a unifier that respects them. The entries Universe index, Level of a unification variable, Scope check, Higher-order pattern unification and Delayed equations list the known ways to provide them. Chapter 11 chooses among them and Chapter 12 implements the choice.

Kanren angle (three entries checked on today’s engine). The following file exercises the entries Interleaving, Negation-as-failure and Reification. The relation num° enumerates 0,1,2,…0,1,2,\dots.

(import (aux kanren micro) (aux base) (aux stream))

; num° enumerates 0, 1, 2, ... (project° escapes to Scheme to add 1)
(define-relation (num° n)
  (or° (=° n 0) (fresh° (m) (num° m) (project° ((m* m)) (=° n (+ 1 m*))))))

; Interleaving: three infinite branches; the right-nested or° favours the first
(print (°->list/ground
         (take° 12 (fresh° (q n)
                     (or° (and° (num° n) (=° q (list 'a n)))
                          (and° (num° n) (=° q (list 'b n)))
                          (and° (num° n) (=° q (list 'c n))))))))

; Negation as failure: (take° 1 g) makes the test finite
(print (°->list/ground (fresh° (q) (=° q 1) (if° (take° 1 (num° q)) ✗° ✓°))))
(print (°->list/ground (fresh° (q) (=° q 1) (if° (=° q 2) ✗° ✓°))))
(print (°->list/ground (fresh° (q) (if° (=° q 2) ✗° ✓°))))

; Reification: free variables become α, β, ...; constraints first
(print (°->list #f (fresh° (q x) (=° q (list x 'a)) (≠° x 'b))))
((a 0) (b 0) (a 1) (c 0) (a 2) (b 1) (c 1) (a 3) (a 4) (b 2) (c 2) (a 5))
()
(1)
()
((λ (α) (begin (deny (equal? α (quote b)))) (cons α (cons (quote a) (quote ())))))

Read the lines in order. (1) Of the first twelve answers, six come from branch a and three each from b and c: the shares are 12,14,14\frac12,\frac14,\frac14, as the entry Interleaving says. (2) q=1q=1 is a number, so not (num° 1) fails. If you drop the take° 1, the run never returns: num° 1 has only one answer, but the search for a second one never ends. if° continues every answer of the test with ✗°, and over a stream that never ends this continuation never finishes either. (3) and (4) show negation-as-failure on a ground goal and on a non-ground one. With qq unbound, the test (=° q 2) succeeds by binding qq, so the negation fails, although q=1q=1 would satisfy it. This is the classic unsoundness. (5) The reified answer is a closed λ-expression whose body lists the constraint before the term.

B.4Summary

  • Proof-theoretic terms (sequent, uniform proof, AUGMENT, GENERIC, eigenvariable) describe what search must do. Unification terms (pattern, raising, pruning, level) describe how binders and quantifiers are respected. miniKanren terms (goal, stream, interleaving, reification) describe the engine the ideas must fit.
  • Watch out for overloaded words: suspension, level, scope extrusion, fresh, cut, substitution.
  • Every entry points to the chapter that develops it and to the book page where it is defined. Use the pointers to return to the full treatment.