UNPKG

chop-logic-core

Version:

Core classes, methods and functions for calculating logical formulas and constructing proofs within the Chop Logic project.

118 lines (117 loc) 4.8 kB
import type { NaturalDerivedPayload, PropAtom, PropFormula, PropProofStep } from "../../../models"; /** * Represents a complete proof in Natural Deduction style calculus. * Manages a sequence of proof steps where the final step is the goal formula. * Supports premises, assumptions (sub-proofs), and derived steps using natural deduction rules. * Tracks nesting levels to manage sub-proofs and ensures proofs are properly closed at level 0. * * @category Natural Calculus */ export declare class NaturalProof { private steps; private readonly goal; private currentLevel; /** * Creates a new Natural Deduction proof with a goal formula. * @param goal - The target formula to prove */ constructor(goal: PropFormula); /** * Gets all proof steps in order. * @returns Array of proof steps */ getSteps(): readonly PropProofStep[]; /** * Gets the goal formula of this proof. * @returns The target formula */ getGoal(): PropFormula; /** * Gets the number of steps in the proof. * @returns The current step count */ getStepCount(): number; /** * Gets a specific step by index (1-based). * @param index - The step number (1-based) * @returns The proof step, or undefined if not found */ getStep(index: number): PropProofStep | undefined; /** * Gets the current nesting level for sub-proofs. * @returns The current level (0 = main proof, > 0 = inside assumption) */ getCurrentLevel(): number; /** * Adds a premise (given assumption) to the proof at the current level. * @param formula - The premise formula * @param comment - Optional explanation for the premise * @returns The added proof step */ addPremise(formula: PropFormula, comment?: string): PropProofStep; /** * Adds an assumption (opens a sub-proof) at the next level. * Creates a new assumption that increases the nesting level. * @param formula - The assumption formula * @param comment - Optional explanation for the assumption * @returns The added proof step */ addAssumption(formula: PropFormula, comment?: string): PropProofStep; /** * Adds a derived step using a Natural Deduction rule. * Can be used to apply rules within the current level (including sub-proofs). * @param payload - The derived step payload containing formulas, rule, and step references * @param comment - Optional explanation for the derivation * @returns The array of added proof steps */ addDerivedStep(payload: NaturalDerivedPayload, comment?: string): PropProofStep[]; /** * Reiterates (repeats) a previously proved step at the current level (inside a sub-proof). * Allows referring to a formula from an outer level within an inner sub-proof. * @param fromIndex - The index of the step to reiterate (1-based) * @param comment - Optional explanation for the reiteration * @returns The added reiteration step * @throws {Error} if the step index is invalid */ reiterateStep(fromIndex: number, comment?: string): PropProofStep; /** * Finds the most recent assumption at the current level. * Used to identify the premise F when closing a sub-proof. * @returns The latest assumption step at the current level, or undefined if not found */ private findCurrentAssumption; /** * Closes a sub-proof by applying Implication Introduction. * Automatically takes the assumption (most recent step at current level) and the * derived conclusion (last step at current level) to create an implication F=>G, * then adds this implication at level-1. * @param comment - Optional explanation for the implication closure * @returns The added proof step */ closeSubProof(comment?: string): PropProofStep; /** * Gets the last step in the proof. * @returns The final proof step, or undefined if no steps exist */ getLastStep(): PropProofStep | undefined; /** * Checks if the proof is complete. * A proof is complete when: * 1. The last step's formula structurally equals the goal formula * 2. All sub-proofs are closed (current level is 0) * @returns True if the proof is complete */ isComplete(): boolean; /** * Clears all steps from the proof and resets the level to 0. */ clear(): void; /** * Replaces all occurrences of an atom with a formula or atom in all proof steps. * The goal formula is not modified. * * @param atom - The atomic proposition to replace * @param substitute - The formula or atom to substitute */ replace(atom: PropAtom, substitute: PropFormula | PropAtom): void; }