-
Notifications
You must be signed in to change notification settings - Fork 3
Propositions
Greg Swindle edited this page May 2, 2019
·
2 revisions
In Boolean logic (and archetypes-rules), anything that has a truth-value is called a Proposition.
We use Propositions all the time in source code. A variable with a Boolean value is a Proposition:
const socratesIsHuman = true
Because socratesIsHuman
has a Boolean value, it's a Proposition.
We explicitly declare Propositions in archetypes-rules:
const { Proposition } = require('archetypes-rules')
const proposition = new Proposition(
'socrates-is-human',
true)
console.log(proposition.toString())
// =>
// (Proposition statement = 'socrates-is-human', value = true)
console.log(JSON.stringify(proposition, null, ' '))
// =>
// {
// "name": "socrates-is-human",
// "type": "archetypes.rules.Proposition",
// "value": true
// }
archetypes-rules would express the following source code...
const humansAreMortal = true
const socratesIsHuman = true
const result = (humansAreMortal && socratesIsHuman)
...like this:
const { Proposition } = require('archetypes-rules')
const humansAreMortal = new Proposition('humans-are-mortal', true)
const socratesIsHuman = new Proposition('socrates-is-human', true)
const proposition = humansAreMortal.and(socratesIsHuman)
console.log(proposition.toString())
// =>
// Proposition name = (humans-are-mortal AND socrates-is-human), value = true
const p = new Proposition('p', true)
const q = new Proposition('q', false)
const proposition = p.or(q)
console.log(proposition.toString())
// => Proposition name = (p OR q), value = true
const p = new Proposition('p', true)
const proposition = p.not()
console.log(proposition.toString())
// => Proposition name = (NOT p), value = false
const p = new Proposition('p', true)
const q = new Proposition('q', false)
const proposition = p.xor(q)
console.log(proposition.toString())
// => Proposition name = (p XOR q), value = true