propositional
Version:
Propositional logic symbolic computation library
71 lines (70 loc) • 2.62 kB
TypeScript
/**
* Representation of a propositional logic formula.
*/
export declare class Formula {
/**
* Abstract Syntax Tree (AST) expression representing the formula.
*/
ast: AST.Expression;
/**
* @param source The expression to construct the formula,
* either as a string or already parsed AST expression.
*
* @throws Will throw an error on a malformed string input.
*/
constructor(source: string | AST.Expression);
/**
* Converts the formula to a string.
*
* @param pretty Whether or not to use traditional, non-ascii symbols in the string for operators
* @returns String representation of the formula
*/
toString(pretty?: boolean): string;
/**
* Converts the formula to Conjunctive Normal Form.
*
* @returns The formula in CNF
*/
cnf(): import("./cnf/cnfExpression").CNFFormula;
/**
* Simplify a formula according to some equivalences involving constants (false, true) and
* syntactically equivalent expressions.
*
* @returns The formula transformed with simplifications
*/
simplify(): Formula;
/**
* Substitute a variable in the formula with either another variable or a constant
* (false, true).
* @param v1 Variable to substitute
* @param v2 Value to substitute the variable with
* @returns The formula with the substitution applied
*/
substitute(v1: string, v2: string | boolean): Formula;
/**
* Check whether the formula is an atom, ie an instance of either a single variable
* or a constant.
*/
isAtom(): boolean;
/**
* Evaluate whether an expression is true or false with a given combination of variable values.
*
* @param values An object mapping variables in the formula to boolean values
* (eg. `{ a: false, b: true }`)
* @returns The result of the formula evaluation, true or false
* @throws Will throw an error if not enough variables have been assigned to simplify a formula completely.
*/
evaluate(values: {
[key: string]: number | boolean;
}): boolean;
/**
* Generate a truth table string for the formula, evaluating it for every possible combination of variables.
* Includes sub-formulas in the output, unless otherwise specified.
*
* @param options Truth table formatting options.
* @returns A string containing the truth table for the formula.
*/
truthTable(options: TruthTableOptions): string;
}
import * as AST from './syntax/ast';
import { TruthTableOptions } from './truthtable/generateTruthTable';