---
title: 'PIE: Prolog-Embedded Automated Reasoning'
url: https://www.emergentmind.com/topics/pie
type: topic
---

# PIE: Prolog-Embedded Automated Reasoning

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 [1908.11137]. 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 [2002.10892].

## 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 [1908.11137].

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 [2002.10892].

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 [2002.10892].

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 [1908.11137].

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))` [1908.11137].

A zero-parameter knowledge-base label can be defined as:

```prolog
def(kb1) :: 
  (sprinkler_on -> wet(grass)),
  (rained -> wet(grass)),
  (wet(grass) -> wet(shoes)).
```

The corresponding LaTeX-rendered expansion is a conjunction of the three implications [1908.11137]. 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 [2002.10892].

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 [2002.10892].

A second-order example is the macro

```prolog
def(explanation(Kb,Na,Ob)) :: 
  all2(Na, (Kb -> Ob)).
```

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)` [1908.11137].

The macro system bridges abstract logical schemas and concrete formulas [1908.11137]. 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 [1908.11137].

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 [1908.11137].

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 [1908.11137].

| 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 [1908.11137]. 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 \(F\) and \(G\) with \(F \vDash G\), a Craig interpolant \(H\) satisfies three conditions: \(F \vDash H\), \(H \vDash G\), and the non-logical symbols of \(H\) occur in both \(F\) and \(G\) [1908.11137]. 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 [1908.11137; 2002.10892].

PIE can produce Lyndon interpolants, respecting polarity constraints, and symmetric interpolation, building \(H\) from both directions, is supported [1908.11137]. The formulation in the later paper makes the same point as polarity-constrained interpolation using only the vocabulary common to \(F\) and \(G\), specifically Craig-Lyndon interpolation [2002.10892].

A propositional example is:

```prolog
:- ppl_printtime(
     ppl_ipol((p, q -> (p ; r)))
   ).
```

with input \(p\land q \models p\lor r\) and interpolant \(p\) [2002.10892].

A first-order example with mixed quantifiers has input

\[
\forall x\,p(a,x)\land q\;\models\;\exists y\,p(y,b)\lor r
\]

and interpolant

\[
\exists u\,\forall v\,p(u,v).
\]

An example invocation in a PIE document is `:- ppl_printtime(ppl_ipol((all(x,p(a,x)), q) -> (ex(x,p(x,b)) ; r))).` [1908.11137].

PIE is also used for definability by interpolation. The macro

```prolog
def(definiens(G,F,P)) :: 
  ex2(P, F ∧ G) -> all2(P, F -> G).
```

supports checking that \(p(a)\) is definable in \(kb_2\) by \(\{q,r\}\), and computing a formula \(H(x)\) such that \(kb_2 \models p(a)\leftrightarrow H(a)\). The invocation `:- ppl_printtime( ppl_ipol(definiens(p(a), kb2, [p,s])) ).` yields \(q(a)\land r(a)\) [2002.10892].

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 [1908.11137].

A basic example is:

\[
\exists p\;\bigl(\forall x\,(q(x)\to p(x))\land\forall x\,(p(x)\to r(x))\bigr)
\]

whose result of elimination is

\[
\forall x\,(q(x)\to r(x)).
\]

The corresponding PIE invocation is:

```prolog
:- ppl_printtime(
     ppl_elim(
       ex2(p, ( all(x,(q(x)->p(x))),
                all(x,(p(x)->r(x))) )),
       [simp_result=[c6]]
     )
   ).
``` 

[2002.10892]

Another example task uses the formula

\[
\exists p\bigl((p(a)\to wet(shoes))\land(p(b)\lor rain)\bigr)
\]

with the PIE goal `:- ppl_printtime(ppl_elim(ex2(p, (p(a)->wet(shoes), p(b);rain))).)` and output

\[
wet(shoes)\lor rain.
\]

[1908.11137]

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 [1908.11137]. In the abduction example, elimination of `explanation(kb1,[wet],wet(shoes))` computes the weakest explanation

\[
\mathit{rained\_last\_night}\;\lor\;\mathit{sprinkler\_was\_on}.
\]

[2002.10892]

A circumscription macro can be defined as:

```prolog
def(circ(P,F)) :: 
  F, ~ex2(P_p,
          (F_p, T1, ~T2)) ::-
    mac_rename_free_predicate(F,P,pn,F_p,P_p),
    mac_get_arity(P,F,A),
    mac_transfer_clauses([P/A-n],p,[P_p],T1),
    mac_transfer_clauses([P/A-n],n,[P_p],T2).
```

The invocation `:- ppl_printtime(ppl_elim(circ(wet,kb1))).` yields a first-order formula where `wet` has been minimized under the `kb1` axioms [2002.10892].

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 [2002.10892].

## 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 [1908.11137; 2002.10892].

A representative skeleton is:

```tex
\documentclass{article}
\usepackage{pie}  % hypothetical

In this section, we define our knowledge base.

\begin{verbatim}
def(kb1) ::
  (sprinkler_on -> wet(grass)),
  (rained -> wet(grass)),
  (wet(grass) -> wet(shoes)).
\end{verbatim}

Further commentary in LaTeX.

:- ppl_printtime(ppl_valid((kb1,rained->wet(shoes)))).

\end{document}
```

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 [1908.11137]. In the later description of the workflow, compiling the generated `.tex` yields a PDF with embedded inputs, proof-tableaux via Graphviz, and results [2002.10892].

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 [1908.11137].

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 [1908.11137]. 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 \(\lambda\)-abstractions [2002.10892].

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 [1908.11137]. 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.

Source: https://www.emergentmind.com/topics/pie