Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lancejpollard/cnf.js
Convert Proposition Trees to Conjunctive Normal Form (CNF) or Disjunctive Normal Form (DNF)
https://github.com/lancejpollard/cnf.js
conjunctive-normal-form math proof-theory propositional-logic
Last synced: 25 days ago
JSON representation
Convert Proposition Trees to Conjunctive Normal Form (CNF) or Disjunctive Normal Form (DNF)
- Host: GitHub
- URL: https://github.com/lancejpollard/cnf.js
- Owner: lancejpollard
- Created: 2022-01-24T06:03:55.000Z (almost 3 years ago)
- Default Branch: make
- Last Pushed: 2022-01-25T03:13:49.000Z (almost 3 years ago)
- Last Synced: 2024-09-10T09:16:51.056Z (4 months ago)
- Topics: conjunctive-normal-form, math, proof-theory, propositional-logic
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# CNF.js
NOT WORKING, WORK IN PROGRESS.
Convert propositional formula trees into [Conjunctive Normal Form](https://en.wikipedia.org/wiki/Conjunctive_normal_form) (CNF). Might also convert [predicate formulae](https://en.wikipedia.org/wiki/First-order_logic) to CNF as well.
```js
const CNF = require('@lancejpollard/cnf.js')CNF.convert()
```## Data Structure
There are 2 main types, which are all subtypes of `formula`: `variable`, and `connective`. There are 3 types of `connective`: `negation`, `disjunction` and `conjunction`.
### Variable
Such as X.
```js
{
type: 'variable',
name: string,
value: boolean,
}
```### Negation
Such as ¬X.
```js
{
type: 'negation',
formula: formula
}
```### Disjunction
Such as (A ∨ B).
```js
{
type: 'disjunction',
base: formula,
head: formula,
}
```### Conjunction
Such as (A ∧ B).
```js
{
type: 'conjunction',
base: formula,
head: formula,
}
```## Equivalencies
Every propositional formula can be converted into an equivalent formula that is in CNF. This transformation is based on rules about [logical equivalences](https://en.wikipedia.org/wiki/Logical_equivalence): double negation elimination, De Morgan's laws, and the distributive law.
| Equivalency | Name |
|:---|:---|
| p∧⊤≡p
p∨⊥≡p | Identity laws |
| p∨⊤≡⊤
p∧⊥≡⊥ | Domination laws |
| p∨p≡p
p∧p≡p | Idempotent or tautology laws |
| ¬(¬p)≡p | Double negation law |
| p∨q≡q∨p
p∧q≡q∧p | Commutative laws |
| (p∨q)∨r≡p∨(q∨r)
(p∧q)∧r≡p∧(q∧r) | Associative laws |
| p∨(q∧r)≡(p∨q)∧(p∨r)
p∧(q∨r)≡(p∧q)∨(p∧r) | Distributive laws |
| ¬(p∧q)≡¬p∨¬q
¬(p∨q)≡¬p∧¬q | De Morgan's laws |
| p∨(p∧q)≡p
p∧(p∨q)≡p | Absorption laws |
| p∨¬p≡⊤
p∧¬p≡⊥ | Negation laws |## HT
- [How to convert a propositional formula to conjunctive normal form (CNF)?](https://stackoverflow.com/a/9533548/169992)
- [How to convert to conjunctive normal form?](https://math.stackexchange.com/questions/214338/how-to-convert-to-conjunctive-normal-form)