The Proof Engine implements goal-directed backward chaining to establish whether a proposition can be derived from the knowledge base. It returns not just a boolean result, but a complete proof trace with confidence scores.
Goal: Given a goal G and knowledge base KB, determine if KB ⊢ G (KB entails G).
Approach: Backward chaining - start from the goal and work backward to known facts.
A goal is proven if it directly matches a KB fact, or if there exists a rule whose consequent matches G and whose premises can all be proven.
Every proof step produces a confidence score between 0 and 1:
| Proof Method | Confidence Formula | Typical Range |
|---|---|---|
| Direct KB match | similarity(goal, fact) | 0.95 - 1.0 |
| Transitive chain (n steps) | ∏ᵢ cᵢ × α^(n-1) | 0.7 - 0.95 |
| Rule application | min(c_premises) × c_rule | 0.6 - 0.9 |
| Weak/fuzzy match | similarity × β | 0.4 - 0.7 |
For a 3-step chain with all steps at 1.0 confidence: 1.0 × 1.0 × 1.0 × 0.95² = 0.9025
The engine returns a complete proof trace for debugging and explanation:
{
success: true,
goal: { operator: 'isA', args: ['Socrates', 'Mortal'] },
method: 'rule_application',
confidence: 0.95,
rule: '@r1: Implies (isA ?x Human) (isA ?x Mortal)',
bindings: { '?x': 'Socrates' },
premises: [
{
success: true,
goal: { operator: 'isA', args: ['Socrates', 'Human'] },
method: 'direct_kb',
confidence: 1.0,
matchedFact: 'isA Socrates Human'
}
],
depth: 1,
steps: 2
}
Unification finds substitutions that make two expressions identical:
Variables (prefixed with ?) can match any term. Constants must match exactly.
| Expression 1 | Expression 2 | Unification Result |
|---|---|---|
loves ?x Mary |
loves John Mary |
{ ?x → John } |
isA ?x ?y |
isA Cat Animal |
{ ?x → Cat, ?y → Animal } |
isA Dog ?x |
isA Cat Animal |
FAIL (Dog ≠ Cat) |
The proof engine handles compound logical structures:
prove(And(P, Q)) = prove(P) ∧ prove(Q)
confidence = min(c_P, c_Q)
prove(Or(P, Q)) = prove(P) ∨ prove(Q)
confidence = max(c_P, c_Q)
prove(Not(P)) = ¬prove(P)
confidence = 1.0 - c_P (if P provable)
confidence = 1.0 (if P not provable)
| Strategy | Description | Impact |
|---|---|---|
| Memoization | Cache proven/failed goals | Avoids redundant proof attempts |
| Depth limiting | Max recursion depth (default: 20) | Prevents infinite loops |
| Cycle detection | Track visited goals in current path | Detects circular proofs |
| Rule ordering | Try more specific rules first | Finds proofs faster |
| HDC pre-filtering | Use similarity to find candidates | Reduces search space |
isA Socrates Human
@r1 Implies (isA ?x Human) (isA ?x Mortal)
Goal: prove(isA Socrates Mortal)
Proof Trace:
import { ProofEngine } from 'agisystem2/reasoning';
const engine = new ProofEngine(session);
// Prove a goal
const result = await engine.prove({
operator: 'isA',
args: ['Socrates', 'Mortal']
});
// With options
const result = await engine.prove(goal, {
maxDepth: 10, // Limit recursion
minConfidence: 0.5, // Reject weak proofs
includeTrace: true, // Full proof trace
timeout: 5000 // Max time (ms)
});