boolean-json-cnf
v3.0.2
Published
convert boolean-json to conjunctive normal form
Downloads
6
Maintainers
Readme
var cnf = require('boolean-json-cnf')
The package exports a function of one boolean-json object.
De Morgan's Laws
var assert = require('assert')
assert.deepEqual(
// ¬(p ∨ q)
cnf({ not: { or: [ 'p', 'q' ] } }),
// (¬p ∧ ¬q)
{ and: [ { not: 'p' }, { not: 'q' } ] })
assert.deepEqual(
// ¬(p ∧ q)
cnf({ not: { and: [ 'p', 'q' ] } }),
// (¬p ∨ ¬q)
{ or: [ { not: 'p' }, { not: 'q' } ] })
Double Negation
assert.deepEqual(
// ¬¬p
cnf({ not: { not: 'p' } }),
// p
'p')
Distribution of Disjunction over Conjunction
assert.deepEqual(
// (p ∨ (q ∧ r))
cnf({ or: [ 'p', { and: [ 'q', 'r' ] } ] }),
// ((p ∨ q) ∧ (p ∨ r))
{ and: [ { or: [ 'p', 'q' ] }, { or: [ 'p', 'r' ] } ] })
assert.deepEqual(
// ((q ∧ r) ∨ p)
cnf({ or: [ { and: [ 'q', 'r' ] }, 'p' ] }),
// ((p ∨ q) ∧ (p ∨ r))
{ and: [ { or: [ 'p', 'q' ] }, { or: [ 'p', 'r' ] } ] })
k-ary Conjunctions and Disjunctions
assert.deepEqual(
// ¬(p ∨ q ∨ r)
cnf({ not: { or: [ 'p', 'q', 'r' ] } }),
// (¬p ∧ (¬q ∧ ¬r))
{ and: [ { not: 'p' }, { and: [ { not: 'q' }, { not: 'r' } ] } ] })
assert.deepEqual(
// ¬(p ∧ q ∧ r)
cnf({ not: { and: [ 'p', 'q', 'r' ] } }),
// (¬p ∨ (¬q ∨ ¬r))
{ or: [ { not: 'p' }, { or: [ { not: 'q' }, { not: 'r' } ] } ] })