Ternary logic: Difference between revisions
Content added Content deleted
Line 2,967: | Line 2,967: | ||
Here is a compact solution |
Here is a compact solution |
||
<lang Javascript> |
<lang Javascript> |
||
trit = {false: 'F', maybe: 'U', true: 'T'} |
trit = {false: 'F', maybe: 'U', true: 'T'} |
||
nand = (a, b) => (a == trit.false || b == trit.false) ? trit.true : (a == trit.maybe || b == trit.maybe) ? trit.maybe : trit.false |
nand = (a, b) => (a == trit.false || b == trit.false) ? trit.true : (a == trit.maybe || b == trit.maybe) ? trit.maybe : trit.false |
||
not = (a) => nand(a, a) |
not = (a) => nand(a, a) |
||
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)) |
||
nor = (a, b) => not(or(a, b)) |
nor = (a, b) => not(or(a, b)) |
||
implies = (a, b) => nand(a, not(b)) |
implies = (a, b) => nand(a, not(b)) |
||
iff = (a, b) => or(and(a, b), nor(a, b)) |
iff = (a, b) => or(and(a, b), nor(a, b)) |
||
xor = (a, b) => not(iff(a, b)) |
xor = (a, b) => not(iff(a, b)) |
||
</lang> |
</lang> |
||
... to test it |
... to test it |