Ternary logic: Difference between revisions
Content added Content deleted
MazenMokhtar (talk | contribs) (Switch from custom values to Javascript native values (false, undefined, true) which leads to a more usable library. Fix an error with the test output for the NOT function.) |
MazenMokhtar (talk | contribs) m (More consistent logical symbols in the test.) |
||
Line 3,099: | Line 3,099: | ||
nand = (a, b) => (a == false || b == false) ? true : (a == undefined || b == undefined) ? undefined : false |
nand = (a, b) => (a == false || b == false) ? true : (a == undefined || b == undefined) ? undefined : false |
||
not = (a) => nand(a, a) |
not = (a) => nand(a, a) |
||
same = (a, b) => (a == undefined || b == undefined) ? undefined : a === b |
|||
and = (a, b) => not(nand(a, b)) |
and = (a, b) => not(nand(a, b)) |
||
or = (a, b) => nand(not(a), not(b)) |
or = (a, b) => nand(not(a), not(b)) |
||
Line 3,110: | Line 3,109: | ||
<syntaxhighlight lang="javascript"> |
<syntaxhighlight lang="javascript"> |
||
trit = [false, undefined, true] |
trit = [false, undefined, true] |
||
functor = { |
functor = {nand, and, or, nor, implies, iff, xor} |
||
display = { |
display = {nand: '⊼', and: '∧', or: '∨', nor: '⊽', implies: '→', iff: '↔', xor: '⊻', not: '¬', false: 'F', undefined: '?', true: 'T'} |
||
log = 'NOT\n'; |
log = 'NOT\n'; |
||
for (let a of trit) log += `${display.not}${display[a]} = ${display[not(a)]}\n` |
for (let a of trit) log += `${display.not}${display[a]} = ${display[not(a)]}\n` |
||
log += '\ |
log += '\nNAND AND OR NOR IMPLIES IFF XOR' |
||
for (let a of trit) { |
for (let a of trit) { |
||
for (let b of trit) { |
for (let b of trit) { |