# binary-decision-diagram

> A library to create, minimize and optimize binary decision diagrams

Latest version **4.0.0** (published 2026-03-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install binary-decision-diagram
pnpm add binary-decision-diagram
yarn add binary-decision-diagram
bun add binary-decision-diagram
```

## Health

**Score 70/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2026-03-16 |
| First published | 2020-02-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 0 |
| Unpacked size | 238.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 36 |
| Author | pubkey |
| Maintainers | pubkey |
| Keywords | binary decision diagram, bdd, bdds, binary-decision-diagrams, binary-decision-tree, robdd, mtbdd, truth-table, truth table |

## Links

- npm: https://www.npmjs.com/package/binary-decision-diagram
- Repository: https://github.com/pubkey/binary-decision-diagram
- Homepage: https://github.com/pubkey/binary-decision-diagram#readme
- Issues: https://github.com/pubkey/binary-decision-diagram/issues
- npm.io page: https://npm.io/package/binary-decision-diagram

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2026-03-16
- 3.2.0 — 2023-12-04
- 3.1.0 — 2023-11-23
- 3.0.6 — 2023-10-16
- 3.0.5 — 2023-10-09
- 3.0.4 — 2023-10-08
- 3.0.3 — 2023-10-08
- 3.0.2 — 2023-10-08
- 3.0.1 — 2023-10-07
- 3.0.0 — 2023-10-07
- 2.0.1 — 2023-01-17
- 2.0.0 — 2023-01-17
- 1.4.0 — 2021-09-29
- 1.3.1 — 2020-04-29
- 1.3.0 — 2020-04-29
- … 8 more at https://npm.io/package/binary-decision-diagram/versions

## README

# binary decision diagram

A library to **create**, **minimize** and **optimize** binary decision diagrams in JavaScript.



A binary decision diagram is a data structure that represents a set of boolean function in an efficient way. To learn more about it, follow these links:

- [Introduction on BDDs](https://web.archive.org/web/20110304135553/http://configit.com/fileadmin/Configit/Documents/bdd-eap.pdf)
- [Presentation on BDDs](https://de.slideshare.net/RajeshYadav49/reduced-ordered-binary-decision-diagram-devi)
- [Implementation of ROBDD](https://pdfs.semanticscholar.org/788d/ed39ca36300753bcb20c43762972b00f9b80.pdf)


### Installation

```bash
npm install binary-decision-diagram --save
```

### createBddFromTruthTable()

Creates a BDD from a truth table.
The Truth-Table is a `Map<string, number>` where the string is a truth-set like `1101` and the number is the value.

```typescript
const truthTable = new Map();
truthTable.add('00', 1);
truthTable.add('01', 3);
truthTable.add('10', 2);
truthTable.add('11', 1);

const bdd = createBddFromTruthTable(
    truthTable
);
```

### minimize()

Reduces the nodes of a BDD by applying the reduction- and elimination rules.

```typescript
bdd.minimize(
    false // if true, logs stuff (optional)
);
```

### countNodes()

Returns the amount of nodes of the BDD.

```typescript
bdd.countNodes(); // returns a number
```

### removeIrrelevantLeafNodes()

Removes all irrelevant leaf-nodes with the given value.

```typescript
// this will remove all leaf-nodes with the value of 5
bdd.removeIrrelevantLeafNodes(5);
```


### resolve()

Resolves a state by calling the boolean functions through the nodes.

The resolve-functions is an object with the truth-table-value as key and a boolean function as value.

```typescript
const resolvers: ResolverFunctions = {
    1: (i) => true,
    2: (i) => true,
    3: (i) => false
};
```

```typescript
const bddValue = bdd.resolve(
    resolvers, 
    i // input that is passed to the resolvers
); // returns a value from the truth table
```

### bddToMinimalString()

Returns a string-representation of the BDD which can be used in the client side to have a small javascript-bundle.
BDDs can be very big so an effective storage format was needed.

```typescript
const minimalString = bddToMinimalString(bdd)
```

### minimalStringToSimpleBdd()

Parses the minimal string into an `SimpleBdd`. The `SimpleBdd` very small and only can resolve stuff.

```typescript
const simpleBdd = minimalStringToSimpleBdd(str);
```

### resolveWithMinimalBdd()

Resolves a value with the `SimpleBdd` and the `ResolverFunctions`.

```typescript
resolveWithSimpleBdd(
    simpleBdd,
    resolvers,
    key
);
```

### optimizeBruteForce()

Optimizes the sorting of the boolean functions to get an optimal BDD. Returns a promise with the best found BDD.

```typescript
const optimizedResult = await optimizeBruteForce({
    truthTable,
    iterations: 10000,
    // hook that runs whenever a bdd is created (optional)
    afterBddCreation: (bdd: RootNode) => {
        bdd.removeIrrelevantLeafNodes(unknownValueActionId);
    },
    // hook that is triggered whenever a better bdd was found (optional)
    onBetterBdd: (res: OptimisationResult) => {
        const bddMinimalString = bddToMinimalString(res.bdd);
        console.log('new string: ' + bddMinimalString);
        console.log('value mapping:');
        console.dir(res.mapping);
    },
    // (optional) start with this BDD to optimize. If not set, will create an own one.
    initialBdd: myBdd
});
```

---
_Source: https://npm.io/package/binary-decision-diagram · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
