/** * inference.ts - AIQL v2.5.0 Inference Engine * * Implements logical inference, proof construction, and consistency checking * for the AIQL Logic & Reasoning system. * * Features: * - Forward chaining: Apply rules to derive new facts * - Backward chaining: Prove goals from existing knowledge * - Unification: Pattern matching for quantified variables * - Standard inference rules: Modus ponens, modus tollens, hypothetical syllogism, etc. * - Consistency checking: Detect contradictions in knowledge base * - Proof construction: Build proof trees for valid inferences * - Semantic contradiction detection: Ontology-aware conflict detection (v2.5.0) * - Lying detection: Trust-weighted credibility analysis (v2.5.0) */ import * as AST from '@aiql-org/core'; import { OntologyReasoner } from './ontology-reasoner.js'; import { TrustRegistry } from '@aiql-org/security'; /** * Variable substitution mapping * Maps variable names to their bound values */ export type Substitution = Map; /** * Proof step in a derivation */ export interface ProofStep { conclusion: AST.LogicalNode; rule: string; premises: AST.LogicalNode[]; substitution?: Substitution; } /** * Complete proof tree */ export interface Proof { goal: AST.LogicalNode; steps: ProofStep[]; valid: boolean; method: 'forward' | 'backward'; } /** * Consistency check result */ export interface ConsistencyResult { consistent: boolean; contradictions: Array<{ statement1: AST.LogicalNode; statement2: AST.LogicalNode; reason: string; }>; semanticContradictions?: SemanticContradiction[]; potentialLies?: LyingDetectionResult[]; } /** * Semantic contradiction with rich metadata (v2.5.0) */ export interface SemanticContradiction { statement1: AST.Statement; statement2: AST.Statement; conflictType: 'taxonomy' | 'property' | 'cardinality' | 'type' | 'disjoint_values'; reason: string; severity: 'critical' | 'major' | 'minor' | 'informational'; details: Record; } /** * Lying detection result (v2.5.0) */ export interface LyingDetectionResult { potentialLies: Array<{ statement: AST.Intent; contradicts: AST.Intent[]; trustDelta: number; weightedConfidenceDelta: number; reason: string; }>; } /** * Proof result with detailed information */ export interface ProofResult { provable: boolean; proof?: Proof; reason?: string; } export declare class InferenceEngine { private knowledgeBase; private rules; private derivedFacts; private ontologyReasoner; private trustRegistry; /** * Initialize the Inference Engine with an AIQL Program. * * Initialization Process: * 1. **Knowledge Base Loading**: Extracts all initial Facts (Intents) and Rules from the program body. * 2. **Fact Indexing**: Serializes facts for O(1) existence checks during reasoning. * 3. **Semantic Module bootstrapping** (v2.5.0): * - **Ontology Reasoner**: Learns class hierarchies and property definitions from statements. * - **Trust Registry**: Extracts trust scores and credibility metadata. * * @param program - The parsed AIQL program containing the initial knowledge state. */ constructor(program: AST.Program); /** * Initialize semantic reasoning modules from knowledge base (v2.5.0) */ private initializeSemanticModules; /** * Index facts for fast lookup */ private indexFacts; /** * Serialize a node to string for caching/comparison */ private serializeNode; /** * Check if two nodes are structurally equal */ private nodesEqual; /** * Apply forward chaining to derive new facts * * @param maxSteps Maximum number of inference steps (default: 100) * @returns Array of newly derived facts */ forwardChain(maxSteps?: number): AST.LogicalNode[]; /** * Match rule premises against knowledge base */ private matchPremises; /** * Apply standard inference rules (modus ponens, modus tollens, etc.) */ private applyStandardRules; /** * Modus Ponens: A, A → B ⊢ B */ private applyModusPonens; /** * Modus Tollens: ¬B, A → B ⊢ ¬A */ private applyModusTollens; /** * Hypothetical Syllogism: A → B, B → C ⊢ A → C */ private applyHypotheticalSyllogism; /** * Disjunctive Syllogism: A ∨ B, ¬A ⊢ B */ private applyDisjunctiveSyllogism; /** * Conjunction Introduction: A, B ⊢ A ∧ B */ private applyConjunctionIntroduction; /** * Conjunction Elimination: A ∧ B ⊢ A, A ∧ B ⊢ B */ private applyConjunctionElimination; /** * Prove a goal using backward chaining * * @param goal Goal to prove * @returns Proof object if provable, null otherwise */ backwardChain(goal: AST.LogicalNode): Proof | null; /** * Unify two logical nodes, finding variable substitutions that make them equal * * @param pattern Pattern node (may contain variables) * @param target Target node to match against * @returns Substitution mapping if unification succeeds, null otherwise */ unify(pattern: AST.LogicalNode, target: AST.LogicalNode): Substitution | null; /** * Unify two Intent nodes */ private unifyIntents; /** * Unify two Statement nodes */ private unifyStatements; /** * Unify two attribute values (v2.7.0) */ private unifyAttributeValue; /** * Unify a term (subject/relation/object) * Variables start with lowercase, constants with uppercase or special chars */ private unifyTerm; /** * Check if a term is a variable (heuristic: lowercase first letter, not wrapped in <>) */ private isVariable; /** * Apply substitution to a logical node */ private applySubstitution; /** * Apply substitution to an Intent node */ private applySubstitutionToIntent; /** * Check knowledge base for contradictions */ checkConsistency(): ConsistencyResult; /** * Detect semantic contradictions using ontology reasoning * Identifies conflicts beyond structural contradictions (A ∧ ¬A) */ detectSemanticContradictions(): SemanticContradiction[]; /** * Detect potential lies based on trust-weighted confidence analysis * Flags low-trust sources that contradict high-trust sources * * @param threshold Minimum confidence delta to flag as potential lie (default: 0.3) */ detectLying(threshold?: number): LyingDetectionResult; /** * Check if two Intents contain contradicting statements * Helper method for lying detection */ private checkIntentsContradict; /** * Generate contradiction relationship graph * Auto-generates !Relationship Intents for detected contradictions * * @param includeSemanticConflicts Include semantic contradictions (default: true) * @param includeLies Include potential lies (default: true) */ generateContradictionGraph(includeSemanticConflicts?: boolean, includeLies?: boolean): AST.RelationshipNode[]; /** * Get access to ontology reasoner (for external use) */ getOntologyReasoner(): OntologyReasoner; /** * Get access to trust registry (for external use) */ getTrustRegistry(): TrustRegistry; /** * Attempt to prove a goal and return detailed proof result */ prove(goal: AST.LogicalNode): ProofResult; /** * Query knowledge base with pattern matching */ query(pattern: AST.LogicalNode): AST.LogicalNode[]; /** * Meta-cognitive query: Query KB about its own epistemic state * Enables queries like: [has_knowledge_about] * * @param metaQuery - Statement with Self as subject and meta-relation * @returns Array of statements representing epistemic state */ queryMeta(metaQuery: AST.Statement): AST.Statement[]; /** * Get all statements mentioning a concept (as subject or object) * * @param conceptName - Concept to search for * @returns Array of statements mentioning the concept */ private getAllStatementsMentioning; /** * Find knowledge gaps - concepts referenced but not well-defined * A concept is a "gap" if it appears in fewer than 2 statements. * * @returns Array of gaps with concept name and confidence score */ private findKnowledgeGaps; /** * Infer agent capabilities from KB content structure * Analyzes what types of reasoning the KB supports based on: * - Presence of rules -> LogicalReasoning * - Affective relations -> AffectiveReasoning * - Self-references -> MetaCognition * * @returns Array of statements describing inferred capabilities */ private inferCapabilitiesFromKnowledge; /** * Query consciousness level - returns quantum coherence metrics * Handles: [has_consciousness_level] * * Returns a statement with coherence attributes indicating consciousness state * This is a placeholder that would integrate with SemanticRuntime in production * * @returns Array with single statement describing consciousness level */ private queryConsciousnessLevel; /** * Find concepts in superposition - contradictory beliefs coexisting * Handles: [in_superposition_about] * * Identifies concepts where KB contains multiple conflicting statements * Example: [is] and [is] * * @returns Array of statements identifying superposed concepts */ private findSuperpositions; /** * Query current coherence value * Handles: [has_coherence] * * Returns the current quantum coherence measure (0.0-1.0) * In production, this would read from SemanticRuntime * * @returns Array with single statement containing coherence value */ private queryCoherence; /** * Get current knowledge base */ getKnowledgeBase(): AST.LogicalNode[]; /** * Add a fact to the knowledge base */ addFact(fact: AST.LogicalNode): void; /** * Parse AIQL code and add to knowledge base */ addFromAIQL(code: string): void; } //# sourceMappingURL=inference.d.ts.map