Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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)

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)