noorani-mm / math-implies
This package facilitates the solution of discrete mathematical problems.
Requires (Dev)
- phpunit/phpunit: ^9.0
README
This package facilitates the solution of discrete mathematical problems.
How to install
composer require noorani-mm/math-implies
How to use
Provide your desired logical statement as the parameter to the Implies class.
$implies = new \Math\Implies\Implies('p->q');
From now on, you can retrieve the required outputs.
Table
It constructs a truth table by placing the column headers in the first row and sequentially adding rows to represent logical conditions.
$result = $implies->table /** [ ["p", "q", "(p -> q)"], This is columns and others are value ["0", "0", "1" ], ["0", "1", "1" ], ["1", "0", "0" ], ["1", "1", "1" ], ] */
Columns
It displays the computed logical expressions.
$test1 = $implies->columns(); // ['p', 'q', '(p -> q)'] $test2 = $implies->columns; // ['p', 'q', '(p -> q)']
Rows
It returns the result of the truth table computation.
$test1 = $implies->rows(); // ["001", "011", "100", "111"] $test2 = $implies->rows; // ["001", "011", "100", "111"]
PDNF
The pdnf
function returns a string representing the sum of products of the logical statement, obtained by multiplying the components of the logical expression.
Meanwhile, the pdnf
property returns an array representing individual product terms of the logical expression, where each element corresponds to a specific term obtained by multiplying the components of the logical statement.
$string = $implies->pdnf(); // "(~p^~q)v(~p^q)v(p^q)" $array = $implies->pdnf; // ["(~p^~q)", "(~p^q)", "(p^q)"]
PCNF
The pcnf
function returns a string representing the Product of Sums Normalized (PCNF) for a logical statement by adding its components.
Meanwhile, the pcnf
property returns an array representing individual sum terms of the logical expression, with each element corresponding to a specific term obtained by adding the components of the logical statement.
$string = $implies->pcnf(); // "(pv~q)" $array = $implies->pcnf; // ["(pv~q)"]
minterm
The minterm function computes minterms for a logical statement, providing a summarized string representation. The minterm property returns an array of individual minterms, enhancing clarity on the logical conditions.
$string = $implies->minterm(); // "Σ(0,1,3)" $array = $implies->minterm; // [0,1,3];
maxterm
The maxterm function calculates maxterms for a logical statement, presenting a concise string representation. The maxterm property returns an array of individual maxterms, contributing to a clear understanding of the logical conditions.
$string = $implies->maxterm(); // "π(2)" $array = $implies->maxterm; // [2]