logicaffeine-proof
Backward-chaining proof engine with Socratic hints for the Logicaffeine project.
Part of the Logicaffeine project.
Overview
This crate implements a proof search engine that works backwards from goals to axioms, constructing derivation trees that can be certified by the kernel. It embodies the Curry-Howard correspondence: proofs are programs, and verification is type checking.
Architecture Invariant
This crate has no dependency on the language crate (Liskov boundary). The conversion from LogicExpr to ProofExpr lives in the language crate, ensuring the proof engine remains pure and reusable.
Core Concepts
Backward Chaining
The engine searches for proofs by working backwards:
- Start with the goal to prove
- Find rules whose conclusions unify with the goal
- Recursively prove the premises of those rules
- Build the derivation tree as proofs succeed
Goal: Mortal(Socrates)
Knowledge Base:
- Human(Socrates)
- ∀x(Human(x) → Mortal(x))
Search:
1. Goal matches conclusion of ∀x(Human(x) → Mortal(x)) with x=Socrates
2. New subgoal: Human(Socrates)
3. Human(Socrates) matches knowledge base fact
4. Build derivation tree: ModusPonens(UniversalInst, PremiseMatch)
Unification
Implements Robinson's algorithm with occurs check. Unification finds a substitution that makes two terms identical:
| Pattern | Target | Substitution |
|---|---|---|
Mortal(x) |
Mortal(Socrates) |
{x ↦ Socrates} |
Add(Succ(n), 0) |
Add(Succ(Zero), 0) |
{n ↦ Zero} |
f(x, x) |
f(a, b) |
Fails (x can't be both a and b) |
The occurs check prevents infinite terms: x = f(x) has no finite solution.
Curry-Howard Correspondence
The proof engine implements propositions-as-types:
- A proposition is a type — logical formulas correspond to types
- A proof is a program — derivation trees are proof terms
- Verification is type checking — the kernel validates proof terms
Module Structure
| Module | Purpose |
|---|---|
engine.rs |
BackwardChainer proof search implementation |
unify.rs |
Robinson's unification with occurs check and beta-reduction |
certifier.rs |
Curry-Howard conversion to kernel terms |
hints.rs |
Socratic pedagogical guidance for stuck proofs |
error.rs |
Error types (ProofError) |
Key Types
ProofTerm
Owned term representation decoupled from arena allocation:
ProofExpr
Owned expression/proposition representation supporting full FOL and extensions:
- Core FOL:
Predicate,Identity,Atom - Connectives:
And,Or,Implies,Iff,Not - Quantifiers:
ForAll,Exists - Lambda calculus:
Lambda,App - Inductive types:
Ctor,Match,Fixpoint - Modal/Temporal:
Modal,Temporal - Event semantics:
NeoEvent
InferenceRule
The logical moves available to the prover:
DerivationTree
The recursive proof structure returned by the prover:
ProofGoal
The target state for backward chaining:
Public API
Proof Search
use ;
// Create a prover
let mut prover = new;
// Add axioms
prover.add_axiom;
prover.add_axiom;
// Prove a goal
let result = prover.prove;
// Or prove with context
let goal = with_context;
let result = prover.prove_with_goal;
Unification
use ;
// Unify terms
let pattern = Function;
let target = Function;
let subst = unify_terms?;
// subst = { "x" ↦ Constant("Socrates") }
// Apply substitution
let result = apply_subst_to_term;
// result = Mortal(Socrates)
// Expression-level unification with alpha-equivalence
let subst = unify_exprs?;
Beta-Reduction
use beta_reduce;
// (λx. P(x))(Socrates) → P(Socrates)
let reduced = beta_reduce;
Certification
use ;
use Context;
let kernel_ctx = new;
let cert_ctx = new;
let kernel_term = certify?;
Socratic Hints
use ;
let hint = suggest_hint;
println!;
// e.g., "You have an implication that concludes your goal. Can you prove its antecedent?"
Usage Example
use ;
Dependencies
Internal
logicaffeine-base— Shared utilitieslogicaffeine-kernel— Type checking and term verification
External
None (zero external dependencies by design).
License
Business Source License 1.1 (BUSL-1.1)
- Free for individuals and organizations with <25 employees
- Commercial license required for organizations with 25+ employees offering Logic Services
- Converts to MIT on December 24, 2029
See LICENSE for full terms.