UNPKG

chop-logic-core

Version:

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

32 lines (31 loc) 1.47 kB
import type { PropAtom, PropFormula } from "../../models"; /** * Recursively replaces all occurrences of a specified atom in a formula with a substitute formula or atom. * * This function traverses the formula tree and replaces every instance of the target atom with the * provided substitute. If the atom is not present in the formula, the original formula is returned unchanged. * * @param {Object} params - Function parameters: * @param params.formula - The propositional formula in which substitution will occur. * @param params.atom - The atomic proposition (variable) to be replaced. * @param params.substitute - The formula or atom to replace the target atom with. * @returns A new formula with all occurrences of the atom replaced by the substitute. * @category Converters * * @example * // Replace q with s in (p => (q => r)) * const formula: PropFormula = { operator: Operator.Implies, values: [ * { operator: Operator.Var, values: [['p']] }, * { operator: Operator.Implies, values: [ * { operator: Operator.Var, values: [['q']] }, * { operator: Operator.Var, values: [['r']] } * ]} * ]}; * const result = replaceAtomInFormula({ formula, atom: ['q'], substitute: { operator: Operator.Var, values: [['s']] } }); * // Result: p => (s => r) */ export declare function replaceAtomInFormula({ formula, atom, substitute, }: { formula: PropFormula; atom: PropAtom; substitute: PropFormula | PropAtom; }): PropFormula;