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 -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
“ 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.
| Symbol | Meaning |
|---|---|
| sequent: signature , program , goal [MN p. 39] | |
| focused sequent: the clause is selected to prove the atom [MN p. 44] | |
| , | goal formula, program clause (definite formula) |
logical constants; concrete syntax true, & or ,, ;, => or :-, pi, sigma | |
abstraction; λProlog x\ t | |
| capture-avoiding substitution of for in [MN p. 85] | |
| , -conversion | equality of terms modulo , , [MN p. 100] |
| , | function type; type of formulas |
| unification problem under a mixed prefix [MN p. 105] | |
| nominal freshness: the atom does not occur free in | |
| static closure of Ma and Friedman: term under the scope | |
°, ª, §, δ | 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, is a permutation suspended on a variable. In Teyjus, the suspension 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 -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 -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,
freshis the existential quantifier and introduces logic variables. In αKanren,freshintroduces 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). [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. Chapter 2; [MN p. 73].
Abstraction The term (λProlog x\ t), the only binder of the term language. is the
bound variable and the body. The quantifiers are the constants pi and sigma applied to
abstractions. 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. [MN p. 154], [MN p. 155].
Administrative redex A -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. Chapter 8; [MN p. 257].
-conversion Renaming bound variables. Terms that differ only by -conversion are identified, so the names of bound variables are “a fiction” and an implementation may not represent them at all. 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. Kanren: 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 in , and (hash a t) asserts the freshness
. Unification is nominal unification. The implementation does not support disequality
constraints. Chapter 9.
AND The goal-reduction rule for : prove both conjuncts with the same signature and program. Chapter 2; [MN p. 39].
Anonymous variable _: each occurrence is a distinct variable, and its binding is not reported.
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. 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°.
Chapter 10.
assume, all The λKanren goals for and . See AUGMENT,
GENERIC and λKanren. 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. Chapter 9.
Atomic formula A term of type whose head is a predicate symbol, that is, a constant with target type . Chapter 2; [MN p. 34].
AUGMENT The goal-reduction rule for : add to the program and prove . This rule is the basis
of hypothetical reasoning; the clause is visible only during the proof of . λProlog writes D => G;
λKanren calls it assume.
Chapter 3; [MN p. 39], [MN p. 77].
Available level (Ma–Friedman) A de Bruijn level of a scope whose binder name is not rebound further in. A shadowed binder’s level is unavailable, so failsWeixi Ma and Daniel P. Friedman. A new higher-order unification algorithm for Kanren. In miniKanren and Relational Programming Workshop, 2021. Chapter 9.
B#
Backchaining Proving an atomic goal by selecting a program clause, possibly an assumed one, whose head matches , 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, L, L and L. Chapter 2; [MN p. 3], [MN p. 44].
-conversion, -redex, -reduction A -redex is , and it reduces to . -reduction is the computation of functional programming, and it is part of the equality of λProlog terms. Chapter 4; [MN p. 100]–[MN p. 101].
-conversion The special case of . With , it is equivalent to when is not free in , so it only renames. It is the only needed in . Chapter 6 and Chapter 7; [MN p. 206], [MN p. 220].
-normal form A term without -redexes. It has the shape , with binder , head and arguments . Chapter 4; [MN p. 101], [MN p. 111].
-long normal form A -normal form whose arguments are themselves in long form and whose body has primitive type. Every -normal form can be -expanded into an equal long one; for , the long form of is . Higher-order unification works on these forms. 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. 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 (continuation-passing style). Chapter 5; [MN p. 130].
Binder A syntactic construct that introduces a locally scoped name: a quantifier, , , or a local declaration. In λ-tree syntax, object-level binders are encoded by meta-level . Chapter 6.
Binder mobility The way a binder moves across levels during computation. A term-level becomes a
formula-level (pi), which in turn becomes a proof-level eigenvariable. This movement lets
λProlog programs descend under binders without managing names. 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 unify with Church true . 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.
Chapter 8; [MN p. 271].
C#
Canonical substitution For a problem whose equations are all flex-flex: fix one new existential variable for each primitive type , and map every existential variable of type to . This substitution always unifies such a problem, which is why a flex-flex remainder counts as success. Chapter 7; [MN p. 217]–[MN p. 218].
Capture-avoiding substitution , carried out after renaming bound variables of so that no free variable of is captured. It is defined only up to . Contrast grafting. Chapter 3 and Chapter 4; [MN p. 85]–[MN p. 86], [MN p. 100].
Church numeral . The book uses Church numerals to show -reduction as computation and to encode Diophantine equations as unification problems. 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. 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. 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. 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. 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. Chapter 1; [MN p. 2].
cond° (aux kanren micro)’s conde: an interleaving disjunction of conjunctions of goals. There is no
else keyword. 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. Chapter 5; [MN p. 119].
Constant clash The failure of first-order unification on an equation whose two sides have distinct head constants. 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. 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. Chapter 10.
Constructive negation (Moiseenko) Negation for miniKanren that collects all the answers of 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 as Evgenii Moiseenko. Constructive negation for miniKanren. In miniKanren and Relational Programming Workshop, 2019. 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. 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 . 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. 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 !. 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). 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: and . fohh adds and to the goals. 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 , has level 0 and index 1 when counting from 0. Teyjus uses indices in terms and levels in the context. ELPI uses levels throughout. Chapter 6 and Chapter 9; [MN p. 192].
Decide, initial The two rules that start and end backchaining. decide picks a clause to focus on. initial closes a focused atom whose head matches the goal. Chapter 2; [MN p. 45].
define-relation The (aux kanren micro) macro that defines a relation. It is inverse--delayed: the body
is built only when a state arrives, and then it suspends. 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 ) is banned from programs. 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. 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 . 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. Chapter 7; [MN p. 225].
Determinate type A type whose type variables are all transparent, that is, occur in the target type. Chapter 2; [MN p. 67].
Difference list, functional difference list (dl L K) denotes minus its suffix .
(fdl F), with F : list A -> list A, denotes F nil, and appending is function composition.
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. 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. Chapter 10 and Chapter 9.
Disjunction / existence property In intuitionistic logic, implies for some , and yields a witness. Harrop formulas guarantee these properties, which is why answer substitutions make sense. Chapter 3; [MN p. 93].
Dynamic The practical regime in which 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. Chapter 7; [MN p. 225]–[MN p. 226].
E#
E-formula : a program formula with existentially quantified, local names. It gives modules with hidden constants a logical reading. [MN p. 160]–[MN p. 162].
Eigenvariable, scoped constant The new constant that GENERIC (R) introduces to prove
. 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. 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. 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. Chapter 7.
ELPI An embeddable λProlog interpreterCvetan Dunchev, Ferruccio Guidi, Claudio Sacerdoti Coen, and Enrico Tassi. ELPI: fast, embeddable, Prolog 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 . It reports an error outside the pattern fragment by default, and it offers syntactic constraints. Chapter 9.
Empty type A type with no closed inhabitant. Higher-order intuitionistic logic does not exclude empty types, and they matter for answers and for unification solutions. 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.
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 , a negative , or a term-level . Otherwise it is essentially existential. Clauses use the dual classification. During search, essentially existential variables become logic variables and essentially universal ones become eigenvariables. Chapter 6; [MN p. 205].
-conversion when is not free in . 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. Chapter 8; [MN p. 253].
Ex falso quodlibet From , infer anything. Intuitionistic logic is minimal logic plus this rule. Chapter 3; [MN p. 90].
Excluded middle : valid classically, rejected intuitionistically. It is one of the counterexamples that motivate banning disjunction from programs. Chapter 2; [MN p. 42].
Existential generalisation From infer . It explains the multiple answers of
subst when run backwards. Chapter 6; [MN p. 203].
Explicit substitution Calculi that make substitution a term constructor, so it can be delayed and composed. Examples are (DHKP) and Teyjus’s suspension notation. Chapter 9; [MN p. 209].
F#
Flexible term, rigid term A -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 -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 Kanren. In miniKanren and Relational Programming Workshop, 2021. 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. 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. 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. 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]. Chapter 2, Chapter 3 and Chapter 5.
Free for is free for in if substituting for in captures no free variable of . 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). Chapter 10.
Freshness constraint : the atom does not occur free in , also after later
instantiation of the variables in . 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.
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 . Chapter 3; [MN p. 83], [MN p. 94].
GENERIC The rule for : add a new constant to the signature and prove .
It is pi x\ G in λProlog and all in λKanren.
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. 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. Chapter 1 and Chapter 2; [MN p. 3], [MN p. 39].
Grafting First-order, capture-permitting replacement of a metavariable by a term, written : grafting into gives . 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 Kanren. In miniKanren and Relational Programming Workshop, 2021. Chapter 9.
Grounding In (aux kanren micro), °->list/ground evaluates a reified answer, applying its to its own
variable names. Constraints are dropped. Chapter 10.
H#
Harrop formula . These formulas guarantee the disjunction and existence properties at the root of a proof. Chapter 3; [MN p. 93].
Herbrand universe , The terms allowed as quantifier instances. (for hohc) contains the -normal terms over without and . (for hohh) contains those without . 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. 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. 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 -terms and quantification at higher types. The book works in the third. Chapter 1; [MN p. 5].
Higher-order pattern A term in which every occurrence of an existential variable is applied to distinct variables, either essentially universal or -bound, whose binders lie within the scope of . For example, is a pattern, while (repeated argument) and with a signature constant (not a bound variable) are not. Chapter 6 and Chapter 7; [MN p. 205], [MN p. 220].
Higher-order pattern unification (-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. Chapter 7; [MN p. 220]–[MN p. 223].
Higher-order programming Passing predicates as arguments, as in mappred and foldl.
Chapter 5; [MN p. 126].
Higher-order unification Unification of simply typed -terms modulo -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 -calculus. Theoretical Computer Science, 1:27–57, 1975. 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”. 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 -calculus. Theoretical Computer Science, 1:27–57, 1975. The result is a pre-unifier, whose search space is explored as a matching tree. 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)).
Chapter 3; [MN p. 79]–[MN p. 80].
I#
if, not λProlog’s conditional and negation-as-failure, both defined with the cut.
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).
Chapter 10.
Imitation, projection Huet’s partial bindings for a flex-rigid pair. Imitation copies the rigid head: . Projection selects an argument: , which requires matching target types. Chapter 7; [MN p. 215].
Intensional / extensional equality Intensional equality compares the structure of -terms.
Extensional equality compares what they denote. λProlog’s = is intensional (modulo -conversion).
Chapter 5; [MN p. 146].
Intensional / extensional 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 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.
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. Chapter 10.
Inverse- 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.
Chapter 10.
Inversion of a pattern substitution The core step of pattern unification. To solve , where are distinct bound variables, abstract over , that is, . This works only if every bound variable free in is among and does not occur in ; otherwise pruning or the occurs check takes over. DHKP write the inverse as , and Nipkow’s code remaps de Bruijn indices. 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. Chapter 8; [MN p. 243].
Iterative deepening Retrying a search with bound after failing with bound . In book Ch. 9 it bounds the multiplicity of -formulas. 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. Chapter 1; [MN p. 11]–[MN p. 12].
Kripke model The possible-worlds semantics of intuitionistic logic. Its worlds correspond to signature–program pairs. Chapter 3; [MN p. 94].
L#
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 needs only , is decidable and produces mgus. Chapter 6 and Chapter 7; [MN p. 205]–[MN p. 206], [MN p. 220].
-conversion, -normal form -conversion is the closure of , and , and it is the equality of the logic. The -normal form is the -normal form. Chapter 4; [MN p. 100]–[MN p. 102].
λ-tree syntax HOAS with simply typed -terms, taken modulo , a weak () and possibly , used as a data structure that unification can still analyse. Chapter 6; [MN p. 204].
λKanren miniKanren extended with higher-order logic programming. The 2020 version has terms tie
and app, goals assume () and all (), and Miller’s pattern
unification over an explicit prefixWeixi Ma, Kuang-Chen Lu, and Daniel P. Friedman. Higher-order logic programming with Kanren. 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 Kanren. In miniKanren and Relational Programming Workshop, 2021. Chapter 9.
Left- and right-introduction rules Right rules introduce a connective on the right of and implement goal reduction. Left rules decompose the clause in focus and implement backchaining. Chapter 2; [MN p. 40], [MN p. 42], [MN p. 45].
Legitimate substitution For a problem , a substitution for in whose range no occurs free. Only legitimate substitutions can be unifiers. This is the eigenvariable condition, stated for unification. Chapter 4; [MN p. 109].
Leibniz equality if and only if . Chapter 5; [MN p. 120].
Level of a unification variable The scope depth of a variable. ELPI’s may mention only context names below . 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. 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. Chapter 9.
Logic variable A placeholder that search instantiates by unification. It is the operational device behind the delayed choice of terms in the R, L and initial rules. Chapter 2; [MN p. 61].
M#
Matching A unification problem in which only one side contains existential variables. Higher-order matching is decidable. 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. Chapter 7; [MN p. 219].
Matrix The conjunction of equations under the quantifier prefix of a unification problem. 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 . Chapter 8; [MN p. 269].
Metalanguage, object language λProlog, the language in which we write, and the language encoded in it. Chapter 1; [MN p. 22].
Minimal logic Logic in which is an ordinary constant. Negation is defined as . 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. Chapter 10.
Mixed prefix The quantifier prefix of a unification problem. In a problem the outer universals act as the signature and the inner ones as eigenvariables, and no raising is needed. 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). Chapter 1; [MN p. 152]–[MN p. 153], [MN p. 277].
Most general unifier (mgu) A unifier such that every other unifier is 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. 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. Kanren: 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. Chapter 10.
Multiplicity In the classical prover of book Ch. 9, the number of times an -formula may be instantiated. Bounding it, and raising the bound after each failure, gives a complete semi-decision procedure. Chapter 8; [MN p. 237].
N#
(nabla) The Miller–Tiu generic quantifier for fresh names, in a logic with definitions (closed world). It is not part of λProlog. 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. Chapter 9.
Natural deduction Introduction and elimination rules, with hypotheses discharged by I, E and
E. Book Ch. 9 encodes it with => and pi. 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. 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. Chapter 6; [MN p. 195].
Nominal logic, nominal unification A first-order treatment of binding with names, swappings and freshness. Nominal unification works modulo and never generates new namesChristian Urban, Andrew M. Pitts, and Murdoch J. Gabbay. Nominal unification. Theoretical Computer Science, 323(1–3):473–497, 2004. 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 and . Chapter 1; [MN p. 74].
Object-level substitution Substituting into the body of an encoded binder. In λ-tree syntax it is meta-level
-reduction, as in the clause subst R N (R N). with R : tm -> tm. That clause lies outside
, but it is used only with R and N instantiated (dynamic ). Copy clauses specify the same
relation inside . 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. Chapter 2; [MN p. 45].
Occurs check fails when occurs properly in . 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. Chapter 1 and Chapter 7; [MN p. 30], [MN p. 223].
Order of a type for non-functional types, and for . Chapter 1 and Chapter 4; [MN p. 13].
P#
Pattern See Higher-order pattern. Ma and Friedman’s phrasing, for an application form : “if is a unification variable, then must be a list of zero or more distinct bound variables”.
Peirce’s formula : valid classically but not intuitionistically. It has no O-proof. 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. Chapter 1; [MN p. 14], [MN p. 49].
pi, sigma λProlog’s quantifiers, constants of type (A -> o) -> o.
is written pi x\ G, the application of pi to the abstraction x\ G, so the term-level
is the only binder. Chapter 1 and Chapter 4; [MN p. 36], [MN p. 99].
-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. 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. Chapter 3 and Chapter 5; [MN p. 76], [MN p. 121]–[MN p. 122].
Pre-cooking (DHKP) Translating a metavariable that occurs under binders into , 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. 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. 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.
Chapter 10.
Proof term A -term of type proof that records a derivation, as in the judgment P # A
(“ is a proof of ”). Chapter 8; [MN p. 233].
Pruning Removing from a variable its dependency on arguments that cannot occur in any solution: , where keeps only the allowed arguments. Chapter 7; [MN p. 223].
Purification The step of (aux kanren micro)’s reification that drops constraints mentioning variables unreachable from
the answer. Chapter 10.
R#
Raising : an existential in the scope of a universal becomes the application of a new, higher-type existential quantified further out. Raising preserves . 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. 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. Chapter 2; [MN p. 39].
Reduction-free fragment (ELPI) The patterns in which a unification variable is applied exactly to the bound variables that follow its level. Binding such a variable needs no -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, Prolog interpreter. In Logic for Programming, Artificial Intelligence, and Reasoning (LPAR-20), volume 9450 of LNCS, pages 460–468. Springer, 2015. 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. Chapter 10.
Relation ((aux kanren micro)) A procedure from terms to a goal, conventionally named name° and defined with
define-relation. 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 Ende Jin, Gregory Rosenblatt, Matthew Might, and Lisa Zhang. Universal quantification and implication in miniKanren. In miniKanren and Relational Programming Workshop, 2021. Chapter 9.
Representation independence Replacing a module by an equivalent one does not change the meaning of the larger program. [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. Chapter 9 and Chapter 10.
Scope extrusion The book’s name for the classical equivalence , which moves the scope of an implication over a disjunction. It fails intuitionistically: has no O-proof, although its classical equivalent does. The term is borrowed from the -calculus, where it means sending a restricted name out and re-closing its scope at the receiver. 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 -bound variable may occur in the instantiation of an -variable only if it precedes that variable in the prefix. 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 Kanren. In miniKanren and Relational Programming Workshop, 2020. Chapter 9 and Chapter 10.
Sequent : signature, program and goal. It is read both as the state of an interpreter and as a logical judgment. Chapter 2; [MN p. 39].
Signature A set of typed non-logical constants. In Teyjus, a signature is also a module’s interface
(sig). Chapter 1; [MN p. 17], [MN p. 153].
Signature–program pair , the context in which queries are posed. Under the open-world assumption these pairs are the worlds of a Kripke model. Chapter 2 and Chapter 3; [MN p. 39], [MN p. 94].
Simplification Repeated decomposition, or clash, of rigid-rigid pairs in higher-order unification. Chapter 7; [MN p. 214].
Skolemization Replacing an existential in an assumption by a function of the enclosing universals, as in . It is the dual of raising. 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. Chapter 4 and Chapter 7; [MN p. 109].
Solved form A set of equations in which each left-hand variable occurs nowhere else. It is read as an idempotent mgu. Chapter 1; [MN p. 29].
Static closure (Ma–Friedman): a term paired with the scope, the list of binder names around it, manipulated by and . 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 Kanren. In miniKanren and Relational Programming Workshop, 2021. Chapter 9.
Stream (§) In aux, a stream is '(), a mature pair (state . §), or an immature
promise. Chapter 10.
Subject reduction Evaluation preserves types. 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. Chapter 10.
Subsumption ((aux kanren micro)) Dropping a constraint that another constraint implies, or that a type tag or an
absento constraint makes vacuous. Chapter 10.
Suspension Four different things, depending on the source; see the pitfall at the start of this appendix.
Swapping exchanges the atoms and throughout a term. Permutations are lists of swappings. 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. 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. 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. Chapter 8; [MN p. 241], [MN p. 243].
Target type in . 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. 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. 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. Chapter 8; [MN p. 267], [MN p. 269], [MN p. 271].
Transparent type variable A type variable that occurs in the target type. 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. 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 , and a unifier is a legitimate substitution (no inner universals in its range) that makes each pair -convertible. 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. 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. Chapter 2; [MN p. 73].
Universe index (Nadathur, Jayaraman, Kwon) A numeric tag on constants and logic variables that records the -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]. 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. Chapter 6; [MN p. 195].
Value constructor A constant of functional type used to build data, such as ::.
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 . 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. Chapter 10.
WAM The Warren Abstract Machine, the classical implementation model of Prolog. [MN p. 74].
Working variable, reified variable In (aux kanren micro), a working variable has index , lives during search
and prints as _i. A reified variable has a negative index, appears only in answers and prints as α, β,
… 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, in goals (sigma) | fresh | fresh° | fresh°, with a level |
| backchaining on a clause | calling a relation | a define-relation call | also a define-dynamic-relation call |
in goals (;) | conde | or°, cond° | unchanged |
| first-order unification with occurs check | == | =° | =°, through the unify and post hooks |
not, if (via !) | conda, condu | if°, take° | unchanged |
augment, D => G | assume (λKanren) | — | ⊃°, define-dynamic-relation |
generic, pi x\ G, eigenvariable | all (λKanren), eigen | — | ∀°, with universe levels |
-terms, x\ t | tie/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 substitution | reified answer | μkanren-project, °->list | °->list/datum, °->pretty |
(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 .
(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 , as the entry Interleaving says.
(2) 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 unbound, the test (=° q 2) succeeds by binding , so the negation fails,
although 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.