This project is part of the @thi.ng/umbrella monorepo.
Assorted digital logic gates and ops for boolean values to compose complex logic in a more functional manner, e.g. for DSL or simulation purposes. Truth tables and references are provided in the doc strings of each function.
Also see @thi.ng/binary for binary versions of most of the ops provided by this package.
STABLE - used in production
Search or submit any issues for this package
pnpm i @thi.ng/dlogic
ES module import:
<script type="module" src="https://cdn.skypack.dev/@thi.ng/dlogic"></script>
For Node.js REPL:
const dlogic = await import("@thi.ng/dlogic");
Package sizes (brotli'd, pre-treeshake): ESM: 378 bytes
import { nand } from "@thi.ng/dlogic";
// XOR construction only using NAND gates
const xor = (a: boolean, b: boolean) => {
const ab = nand(a,b);
return nand(nand(a, ab), nand(b, ab));
};
xor(false, false)
// false
xor(false, true)
// true
xor(true, false)
// true
xor(true, true)
// false
If this project contributes to an academic publication, please cite it as:
@misc{thing-dlogic,
title = "@thi.ng/dlogic",
author = "Karsten Schmidt",
note = "https://thi.ng/dlogic",
year = 2017
}
© 2017 - 2023 Karsten Schmidt // Apache License 2.0