3.0.2 • Published 10 years ago

boolean-json-cnf v3.0.2

Weekly downloads
28
License
MIT
Repository
github
Last release
10 years ago
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' } ] } ] })
3.0.2

10 years ago

3.0.1

10 years ago

3.0.0

10 years ago

2.0.6

10 years ago

2.0.5

10 years ago

2.0.4

10 years ago

2.0.3

10 years ago

2.0.2

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago