Public
Edited
Jan 18, 2024
Importers
Insert cell
Insert cell
html`<div style="display: grid; grid-template-columns: repeat(16, 1fr);">
${_.range(2 ** 8).map((i) => {
let conjClass = codeToClassMap[i];
return html`<div style="width:4rem; min-height:4rem; border: 1px solid black; font-size: .75rem; font-family: monospace; background-color: ${d3ScaleChromatic.interpolateRainbow(
conjClass / ternClasses.length
)};">
<div>${i.toString(2).padStart(8, "0")}</div>
${fnNamesList[conjClass].fnNames[i][0]}
</div>`;
})}
</div>`
Insert cell
Insert cell
incompleteClasses = foundClasses.filter((x) =>
Object.values(x.fnNames).some((list) => list.length !== 1)
)
Insert cell
fnNamesList[codeToClassMap[getCode(3, (a, b, c) => oddFn(a, b, b | c))]]
Insert cell
foundClasses = fnNamesList.filter((x) => x.repr)
Insert cell
fnNamesList = {
let list = ternClasses.map((classList) => {
return {
fnNames: Object.fromEntries([...classList].map((code) => [code, []]))
};
});
function setList(fn) {
let code = getCode(3, fn);
let index = codeToClassMap[code];
list[index].fnNames[code].push(fn.format("a", "b", "c"));
}
function setAsRepr(fn) {
let code = getCode(3, fn);
let index = codeToClassMap[code];
list[index].repr = fn.format("a", "b", "c");
}
populateNullary(setAsRepr, setList);
populateUnary(setAsRepr, setList, 3);
populateBinary(setAsRepr, setList, 3);

setRepsTernary(setAsRepr);
fillTernary(setList);
return list;
}
Insert cell
function setRepsTernary(setAsRepr) {
reprFns.map(setAsRepr);
}
Insert cell
reprFns = [
andFn,
oddFn,
orAnd,
andEq,
eqAnd,
eqFn,
countEq1,
countLeq1,
mux,
eqImpl
]
Insert cell
function fillTernary(setList) {
setList(oddFn);
setList(evenFn);

for (let i = 0; i < 2 ** 3; i++) {
for (let fn of [andFn, orFn, countEq1, countNeq1, countLeq1]) {
setList(applyNegations(fn, i));
}
}

for (let i of [0, 0b001, 0b010, 0b100]) {
setList(applyNegations(eqFn, i));
setList(applyNegations(neqFn, i));
}

for (let order of [
[0, 1, 2],
[1, 2, 0],
[2, 0, 1]
]) {
for (let i = 0; i < 2 ** 3; i++) {
for (let fn of [orAnd, andOr, mux, eqImpl, neqImpl]) {
setList(applyNegations(permuteFn(fn, order), i));
}
}
for (let i = 0; i < 2 ** 2; i++) {
setList(permuteFn(applyNegations(andEq, i), order));
setList(permuteFn(applyNegations(orEq, i), order));
}
for (let i = 0; i < 2; i++) {
for (let fn of [eqAnd, xorAnd, eqOr, xorOr]) {
setList(permuteFn(applyNegations(fn, i << 2), order));
}
}
}
}
Insert cell
populateTernary = getWidenedFn(setRepsTernary, fillTernary, 3)
Insert cell
## Ternary Functions
Insert cell
orAnd = And(Or(Var, Var), Var)
Insert cell
andOr = Or(And(Var, Var), Var)
Insert cell
andEq = Eq(And(Var, Var), Var)
Insert cell
orEq = Eq(Or(Var, Var), Var)
Insert cell
eqAnd = And(Eq(Var, Var), Var)
Insert cell
xorAnd = And(Xor(Var, Var), Var)
Insert cell
eqOr = Or(Eq(Var, Var), Var)
Insert cell
xorOr = Or(Xor(Var, Var), Var)
Insert cell
countEq1 = CountEq(1)(Var, Var, Var)
Insert cell
countNeq1 = CountNeq(1)(Var, Var, Var)
Insert cell
countLeq1 = CountLeq(1)(Var, Var, Var)
Insert cell
mux = Mux(Var, Var, Var)
Insert cell
Mux = makeCombinationFunction(
([a, b, c]) => (a && b) || (!a && c),
([a, b, c]) => `${a} ? ${b} : ${c}`
)
Insert cell
EquivImpl = makeCombinationFunction(
([a, b, c]) => !!a === !!b && (!b || c),
([a, b, c]) => `${a} == ${b} => ${c}`
)
Insert cell
NEquivImpl = makeNegated(EquivImpl)
Insert cell
eqImpl = EquivImpl(Var, Var, Var)
Insert cell
neqImpl = NEquivImpl(Var, Var, Var)
Insert cell
codeToClassMap = getClassIndexMap(ternClasses)
Insert cell
function getClassIndexMap(equivClasses) {
let map = [];
for (let [idx, cls] of equivClasses.entries()) {
for (let item of cls) {
map[item] = idx;
}
}
return map;
}
Insert cell
ternClasses = getConjugacyClasses(3)
Insert cell
_ = require("lodash")
Insert cell
import {
permutations,
getWidenedFn,
getConjugacyClasses,
getIndex,
getCode,
widen,
applyNegations,
permuteFn,
negateFn,
withFormat,
makeCombinationFunction,
makeNegated,
populateNullary,
populateUnary,
populateBinary,
andFn,
orFn,
evenFn,
oddFn,
eqFn,
neqFn,
CountEq,
CountNeq,
CountGeq,
CountLeq,
xor2,
eq2,
Var,
And,
Or,
Xor,
Eq
} from "@tesseralis/boolean-functions"
Insert cell
d3ScaleChromatic = require('d3-scale-chromatic')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more