Chop Logic Core - v1.8.1
    Preparing search index...

    Function replaceAtomInFormula

    • 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.

      Parameters

      Returns PropFormula

      A new formula with all occurrences of the atom replaced by the substitute.

      // 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)