npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

espresso-logic-minimizer

v2.0.3

Published

A NodeJS bridge to the Espresso heuristic logic minimizer

Downloads

3,146

Readme

espresso-logic-minimizer

A NodeJS bridge to the Espresso heuristic logic minimizer.

The original source code comes from the University of California, Berkeley.

Install

npm install espresso-logic-minimizer

API

minimize(truthTable)

Static method, minimize the input truth table directly. The truth table must be provided as an array of strings following the PLA format (see below).

Returns an array of strings containing the minimized conditions.

Espresso(inputSize, outputSize)

Constructor allowing to input the truth table progressively. inputSize is the number of input conditions, and outputSize is the number of output conditions. They match, respectively, the .i and .o parameters of PLA files.

A class instance can only process one PLA.

push(input, output)

Pushes into the current PLA a truth table entry. Both input and output are arrays of truthy/falsey values.

minimize()

Ends the current PLA and minimizes it. Subsequent calls will simple return the already computed result. Returns an array of strings containing the minimized conditions.

How to use: simple boolean minification

Take the following boolean conditions:

(NOT (cond1 AND cond2) OR cond3) AND cond4

Espresso is able to simplify such conditions to Disjunctive Normal Form (DNF).

To do so, start by creating a truth table describing the above boolean conditions:

|cond1|cond2|cond3|cond4|result| |-----|-----|-----|-----|------| |0|0|0|0|0| |0|0|0|1|1| |0|0|1|0|0| |0|0|1|1|1| |0|1|0|0|0| |0|1|0|1|1| |0|1|1|0|0| |0|1|1|1|1| |1|0|0|0|0| |1|0|0|1|1| |1|0|1|0|0| |1|0|1|1|1| |1|1|0|0|0| |1|1|0|1|0| |1|1|1|0|0| |1|1|1|1|1|

Passing the PLA data directory to espresso

Creating and maintaining a truth table entirely in memory can and will quickly fill up heap space. This way of minimizing PLAs is only to be used on small numbers of input conditions.

To use the in-memory PLA conversion, you first need to convert the truth table above into PLA format:

# there are 4 input variables
.i 4

# there is only 1 output result
.o 1

# the following is the truth table
0000 0
0001 1
0010 0
0011 1
0100 0
0101 1
0110 0
0111 1
1000 0
1001 1
1010 0
1011 1
1100 0
1101 0
1110 0
1111 1

# end of the PLA data
.e

Then simply store it into an array of strings, and feed it to espresso.

const espresso = require('espresso-logic-minimizer');

const pla = [
    '.i 4',
    '.o 1',
    '0000 0',
    '0001 1',
    '0010 0',
    '0011 1',
    '0100 0',
    '0101 1',
    '0110 0',
    '0111 1',
    '1000 0',
    '1001 1',
    '1010 0',
    '1011 1',
    '1100 0',
    '1101 0',
    '1110 0',
    '1111 1',
    '.e'
  ];

console.log('result = ', espresso.minimize(pla));

Input the truth table progressively

const Espresso = require('espresso-logic-minimizer').Espresso;

const espresso = new Espresso(4, 1);

espresso.push([0, 0, 0, 0], [0]);
espresso.push([0, 0, 0, 1], [1]);
espresso.push([0, 0, 1, 0], [0]);
espresso.push([0, 0, 1, 1], [1]);
espresso.push([0, 1, 0, 0], [0]);
espresso.push([0, 1, 0, 1], [1]);
espresso.push([0, 1, 1, 0], [0]);
espresso.push([0, 1, 1, 1], [1]);
espresso.push([1, 0, 0, 0], [0]);
espresso.push([1, 0, 0, 1], [1]);
espresso.push([1, 0, 1, 0], [0]);
espresso.push([1, 0, 1, 1], [1]);
espresso.push([1, 1, 0, 0], [0]);
espresso.push([1, 1, 0, 1], [0]);
espresso.push([1, 1, 1, 0], [0]);
espresso.push([1, 1, 1, 1], [1]);

console.log('result = ', espresso.minimize());

Interpreting the result

Both examples above output the following result:

result = [ '0--1 1', '-0-1 1', '--11 1' ]

As explained above, this result is expressed in disjunctive normal form: each array entry contains a set of AND conditions, and a OR condition must be used between entries.

Here is what you need to know to understand the result:

  • - => "DC" flag => Don't Care
  • 0 => "OFF" flag => this condition must be FALSE for the result to be true. This means we need to perform a "NOT" on this condition
  • 1 => "ON" flag => this condition must be TRUE for the result to be true.

So we have:

  • 0-–1 1 : NOT cond1 AND cond4
  • -0-1 1 : NOT cond2 AND cond4
  • –-11 1 : cond3 AND cond4

Final result:

NOT cond2 AND cond4 OR NOT cond1 AND cond4 OR cond3 AND cond4

Repository content

The original source code is stored in the espresso-src folder. The only changes made to this code allow it to be compiled using C99 standards, and a few warnings have also been fixed.

The original main.c and main.h are still present, even if unused in this NodeJS library. The original executable can still be compiled and executed by executing make in the espresso-src folder.
This will create a bin/ directory in the root of the repository containing the espresso executable.

The man directory contains the original man pages of Espresso:

  • espresso.1 contains the executable options documentation
  • espresso.5 details the PLA format and contains other, more complex PLA examples

The NodeJS bridge itself is contained in the bridge directory.

License

This library is published under the MIT License.