PIE: Prolog-Embedded Automated Reasoning
- PIE is a Prolog-embedded environment for automated reasoning based on first-order logic, employing formula macros and integration with various reasoning back-ends.
- It features a macro system that defines reusable logical templates and enables literate programming workflows by interweaving LaTeX documentation with Prolog predicates.
- PIE integrates external theorem provers with an internal Prolog-based tableau prover, supporting tasks such as Craig interpolation and second-order quantifier elimination.
PIE is a Prolog-embedded environment for automated reasoning on the basis of first-order logic. It is embedded in SWI-Prolog, supports automated reasoning on the basis of first-order logic augmented by Craig interpolation and second-order quantifier elimination, and is designed both as an interactive toolkit—where formulas are represented as Prolog terms and processed by Prolog predicates—and as a literate-programming style document processor that weaves together LaTeX text, formula macro definitions, and invocations of various reasoning back-ends (Wernhard, 2019). Its main focus is on formulas, as constituents of complex formalizations that are structured through formula macros, and as outputs of reasoning tasks such as second-order quantifier elimination and Craig interpolation (Wernhard, 2020).
1. Core architecture and representation
PIE is implemented as a library of Prolog predicates embedded in SWI-Prolog. The entire system is a library of Prolog predicates under SWI-Prolog; unification and backtracking implement pattern-matching and formula transformations; and the read–print loop allows interactive construction, transformation, and proving of formulas, with pretty-printing in both Prolog syntax and LaTeX (Wernhard, 2019).
First-order formulas are Prolog ground terms, with explicit quantifier functors such as all/2 and ex/2 distinguishing predicate-logic variables from Prolog variables. Clausal formulas are represented by lists of lists of literals, where each literal is a Prolog term with an optional polarity marker. PIE also provides a Prolog-readable syntax for first-order logic, with quantifiers represented by functors such as all/2 and ex2/2, and supports pretty-printing back into both Prolog syntax and LaTeX (Wernhard, 2020).
The driver predicates include ppl_elim/2 for elimination, ppl_ipol/2 for interpolation, and ppl_valid/2 for validity checking. These predicates can be invoked both interactively in the Prolog toplevel and “at print-time” when processing a PIE document. At print-time the same predicates insert their inputs and results, as first-order formulas, into a generated LaTeX file, producing a self-documenting “literate programming” style workflow (Wernhard, 2020).
This combination of formula representation, Prolog embedding, and print-time execution suggests that PIE treats formal reasoning not only as proof search but also as formula computation and presentation. A plausible implication is that the system is intended for workflows in which the generated formulas themselves are central research artifacts.
2. Formula macros and formal structuring
PIE’s macro system lets the user define parameterized formula templates that expand to first- or second-order formulas. Macros allow names or schemata for subformulas to be defined once and reused in complex formalizations. Each macro has the form def(Name(Param₁,…), ParametricBody) ::– OptionalPrologBody, and macros may be recursive, may carry Prolog bodies for computed expansions, and may rely on Prolog variables to generate fresh symbols (Wernhard, 2019).
A simple binary implication macro is given in LaTeX style as \defmacro{imp}(A,B) = \forall X\,(A(X)\to B(X)). Its usage in a formula is imp(p,q), and its expansion into first-order syntax is all(X, p(X)->q(X)) (Wernhard, 2019).
A zero-parameter knowledge-base label can be defined as:
8
The corresponding LaTeX-rendered expansion is a conjunction of the three implications (Wernhard, 2019). In the simpler formulation of the same idea, def(kb1) :: (sprinkler_was_on -> wet(grass)), …. binds the symbol kb1 to the conjunction of three implications (Wernhard, 2020).
Parameters may occur both in predicate-position and as subformula placeholders. Macros may carry Prolog bodies, introduced by ::-, to perform arbitrary pre- or post-processing, such as renaming or arity-lookup. At print time each invocation is expanded to its definiens (Wernhard, 2020).
A second-order example is the macro
9
Here all2/2 is a universal second-order quantifier. The invocation explanation(kb1,[wet],wet(shoes)) expands to a universal quantification over wet applied to the implication from kb1 to wet(shoes) (Wernhard, 2019).
The macro system bridges abstract logical schemas and concrete formulas (Wernhard, 2019). This suggests that PIE is particularly suited to formalizations where reusable logical patterns, rather than isolated formulas, are the main unit of development.
3. Reasoning back-ends and preprocessing
PIE interfaces to and includes multiple theorem-proving and model-search engines. External provers include TPTP-compliant provers; Otter, Prover9, and Mace4 via their native formats; and SAT/QBF solvers via DIMACS/QDIMACS. The default validity check is to try Mace4, with a short timeout, for a counter-model, and if none is found, try Prover9 for a proof (Wernhard, 2019).
The internal prover, CM, is a Prolog-based connection/tableau prover following the PTTP paradigm. It produces clausal tableau proofs as Prolog terms, usable for interpolant extraction, and is suitable for first-order proof search when tight integration with interpolation is needed (Wernhard, 2019).
PIE also includes preprocessing operations to simplify, clausify, or un-Skolemize formulas. These include normal-form conversions such as CNF, DNF, and structure-preserving conversions; purity simplification relative to a set of predicates; McCune’s un-Skolemization algorithm; and customizable predicate-preservation sets for equi-satisfiability and definability tasks (Wernhard, 2019).
| Component | Function |
|---|---|
| External provers | TPTP-compliant provers; Otter, Prover9, Mace4; SAT/QBF solvers |
| Internal prover (CM) | Prolog-based connection/tableau prover following the PTTP paradigm |
| Preprocessors | Simplify, clausify, un-Skolemize, and preserve predicates for specific tasks |
The coexistence of external provers and a tightly integrated internal prover is significant. External provers handle large clause sets efficiently, but require careful timeout and configuration management, while the internal CM prover is suitable for moderate-size interpolation tasks, given its tighter integration (Wernhard, 2019). A plausible implication is that PIE distinguishes between throughput-oriented proof search and proof-object-oriented computation.
4. Craig interpolation
Given two first-order formulas and with , a Craig interpolant satisfies three conditions: , , and the non-logical symbols of occur in both and (Wernhard, 2019). PIE implements a tableau-based adaptation of Smullyan’s method, and the internal prover CM builds a closed clausal tableau from which an interpolant is extracted (Wernhard, 2019, Wernhard, 2020).
PIE can produce Lyndon interpolants, respecting polarity constraints, and symmetric interpolation, building from both directions, is supported (Wernhard, 2019). The formulation in the later paper makes the same point as polarity-constrained interpolation using only the vocabulary common to 0 and 1, specifically Craig-Lyndon interpolation (Wernhard, 2020).
A propositional example is:
0
with input 2 and interpolant 3 (Wernhard, 2020).
A first-order example with mixed quantifiers has input
4
and interpolant
5
An example invocation in a PIE document is :- ppl_printtime(ppl_ipol((all(x,p(a,x)), q) -> (ex(x,p(x,b)) ; r))). (Wernhard, 2019).
PIE is also used for definability by interpolation. The macro
1
supports checking that 6 is definable in 7 by 8, and computing a formula 9 such that 0. The invocation :- ppl_printtime( ppl_ipol(definiens(p(a), kb2, [p,s])) ). yields 1 (Wernhard, 2020).
This use of interpolation for definientia and query reformulation indicates that, within PIE, interpolation is not confined to proof theory. It functions as a method for computing formulas that mediate between theories, vocabularies, and queries.
5. Second-order quantifier elimination and derived formalisms
PIE supports elimination of predicate quantifiers via the DLS algorithm. The procedure rewrites the input until second-order subformulas meet the Ackermann-lemma shape, performs one-step elimination by replacing quantified predicates with definitions, and applies postprocessing such as CNF, simplification, and un-Skolemization to yield a human-readable first-order result (Wernhard, 2019).
A basic example is:
2
whose result of elimination is
3
The corresponding PIE invocation is:
2
Another example task uses the formula
4
with the PIE goal :- ppl_printtime(ppl_elim(ex2(p, (p(a)->wet(shoes), p(b);rain))).) and output
5
Higher-level macros are defined on top of elimination. PIE defines macros such as circ(p, F) for circumscription and explanation(Kb,Na,Ob) for abductive explanations; elimination applied to these yields classical circumscription and weakest-sufficient-condition formulas (Wernhard, 2019). In the abduction example, elimination of explanation(kb1,[wet],wet(shoes)) computes the weakest explanation
6
A circumscription macro can be defined as:
3
The invocation :- ppl_printtime(ppl_elim(circ(wet,kb1))). yields a first-order formula where wet has been minimized under the kb1 axioms (Wernhard, 2020).
Second-order elimination in full first-order logic is only incomplete. The DLS-based engine works on many non-trivial cases but can fail or yield unwieldy outputs; research directions include heuristics for ordering elimination steps, better un-Skolemization, and hybrid approaches combining rewriting with SAT/QBF back-ends (Wernhard, 2020).
6. Documents, workflow, applications, and limitations
A PIE document is a text file mixing LaTeX fragments, macro definitions, and directives for reasoner invocations. A PIE source file is plain text mixing three kinds of lines: formula macro definitions, reasoner invocation directives, and arbitrary LaTeX fragments such as sectioning commands and prose (Wernhard, 2019, Wernhard, 2020).
A representative skeleton is:
4
When processed, PIE loads the macro, runs Prover9/Mace4 for the validity check, and emits LaTeX containing the original formulas plus a line such as “Valid” or a failure message, all interleaved with the author’s text (Wernhard, 2019). In the later description of the workflow, compiling the generated .tex yields a PDF with embedded inputs, proof-tableaux via Graphviz, and results (Wernhard, 2020).
Typical use cases include formalizing and experimenting with nonmonotonic reasoning, such as circumscription and abduction, in pure classical logic; computing definientia and query reformulations via interpolation; teaching logic by showing step-by-step expansions of macros, proofs, and elimination; and literate-programming style development of formal theories, with reproducible proof and transformation steps documented in LaTeX (Wernhard, 2019).
The principal limitations are also explicit. External provers require careful timeout and configuration management. Second-order elimination via DLS can blow up non-elementarily for some inputs, and there is no complete guarantee for second-order elimination on arbitrary formulas. Output-formula presentation sometimes remains verbose; post-simplification heuristics are an area of ongoing work. Integration with higher-performance SMT or superposition provers is via external calls only (Wernhard, 2019). Additional future directions include theory reasoning such as arithmetic in the tableau engine, interpolants obeying additional side-conditions such as quantifier structure and monotonicity, and macro-system extensions supporting parametric modules, automatic dependency tracking, and richer 7-abstractions (Wernhard, 2020).
PIE brings together the strengths of Prolog as a meta-programming and presentation environment with a suite of reasoning tools—proof search, interpolation, and elimination—all on a uniform first-order logic foundation (Wernhard, 2019). This suggests that its enduring significance lies not only in the individual algorithms it hosts, but in the unification of formula management, automated reasoning, and publication-oriented documentation within a single environment.