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

picosat

v1.2.0

Published

picosat SAT solver

Downloads

7

Readme

picosat for node

Node bindings to the PicoSAT solver release 965 by Armin Biere. The PicoSAT C code is distributed under a MIT style license and is bundled with this package.

Build Status npm version

Install

npm install picosat

Example

Suppose we want to test the following formula for satisfiability:

(A ⇒ B)∧(B ⇒ C)∧(C ⇒ A)

This can be formulated as a CNF (conjunctive normal form):

A ∨ B)∧(¬B ∨ C)∧(¬C ∨ A)

This library expects the following equivalent notation:

const fomula = [
  ['!A', 'B'],
  ['!B', 'C'],
  ['!C', 'A']
]

const {solveWithStrings} = require('picosat')
console.log(solveWithStrings(formula))

The result is an object:

{
  satisfiable: true,
  statusCode: 'satisfiable', // may also be 'unsatisfiable' or 'unknown'
  solution: [ // negative values means false, positive true.
    -1, // A
    -2, // B
    -3 // C
  ]
}

We can also test for satisfiability assuming that a certain variable is true or false:

const assumptions = [
  'A', // assume A is true
  '!C', // assume C is false
]
solveWithStrings(formula, assumptions)

Integer interface

If you want to use integers to define the input, like other PicoSAT bindings in other languages expect it (rpicosat, pycosat), you can use solve.

const solve = require('picosat')

const fomula = [
  [-1, 2], // !A, B
  [-2, 3], // !B, C
  [-3, 1] // !C, A
]
const assumptions = [
  -1 // assume A is false
]

const result = solve(formula, assumptions)
console.log('status code', result[0])
console.log('solution', result.slice(1))
statusCode 10 // 10: satisfiable, 20: unsatisfiable, otherwise unknown
solution [
  -1, // A
  -2, // B
  -3 // C
]

Low-level interface

This package also provides a low-level interface that works directly on Buffers, without encoding into/decoding from the format that PicoSAT works on:

const encodeInt32Array = require('picosat/lib/encode')
const {solveUnsafe} = require('picosat')

const encodedFomula = encodeInt32Array([
  -1, 2, // !A, B
  0, // separator
  -2, 3, // !B, C
  0, // separator
  -3, 1, // !C, A
  0 // separator
])
const encodedAssumptions = encodeInt32Array([
  -1 // assume A is false
])

const result = solveUnsafe(encodedFormula, encodedAssumptions)
console.log('status code', result[0])
console.log('solution', result.slice(1))
statusCode 10 // 10: satisfiable, 20: unsatisfiable, otherwise unknown
solution [
  -1, // A
  -2, // B
  -3 // C
]

License

This package is licensed under MIT.

The PicoSAT solver bundled with this package is licensed under MIT as well: Copyright (c) Armin Biere, Johannes Kepler University.