Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

horn-sat

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

horn-sat

Solves HORNSAT

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

horn-sat

HORNSAT is a restricted version of the boolean satisfiability problem where all clauses are written in Horn normal form. The programming lanugage Prolog uses HORNSAT internally to solve many constraint problems. This modules implements Dowling and Gallier's linear time algorithm:

  • Dowling W., Gallier J. "Linear time algorithms for testing the satisfiability of propositional Horn formulae" (1984) Journal of Logic Programming

This code should work both in node.js and in the browser via browserify.

Example

var hornSAT = require("horn-sat")

// Horn clauses are encoded as pairs.  For example, the clause:
//  (x1 & x2 => x3)    
// Becomes:
//  [ [0,1], 2 ]
// For clauses that map to false, use -1 for the head of the clause:
//  (x1 => 0)
// Becomes:
//  [[0], -1]
//
//
// For example, let's solve the problem:
//
//  x1 & (x1 & x3 => x2) & (x1 => x2) & (x1 & x2 & x3 => 0) & (x1 & x3 & x4 => 0) & (x3 & x2 => x4) & (x4 & x5 => 0)
//

console.log(hornSAT(5,
  [ 
    [[], 0],        // x1
    [[0,2], 1],     // x1 & x3 => x2
    [[0], 1],       // x1 => x2
    [[0,1,2], -1],  // x1 & x2 & x3 => 0
    [[0,2,3], -1],  // x1 & x3 & x4 => 0
    [[2,1], 3],     // x3 & x2 => x4
    [[3,4], -1]     // x4 & x5 => 0
  ]
))

// Prints out:
// 
//  [ true, true, false, false, false ]
//

Install

npm install horn-sat

API

require("horn-sat")(numVariables, clauses)

Finds a satisfying assignment of variables to the HORNSAT instance

  • numVariables is the number of variables in the problem
  • clauses is an array of clauses, encoded as described in the example

Returns An assignment of variables that solves the Horn SAT instance, or else false if the problem is not satisfiable.

Credits

(c) 2013 Mikola Lysenko. MIT License

Keywords

FAQs

Package last updated on 01 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc