logicng-go

module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2024 License: MIT

README

logo

Go Reference license

A Library for Creating, Manipulating, and Solving Boolean Formulas

THIS IS AN ALPHA VERSION! THE API MAY STILL CHANGE IN SIGNIFICANT WAYS! DO NOT USE IN PRODUCTION!

Introduction

This is LogicNG for Go. The original version of LogicNG is a Java Library for creating, manipulating and solving Boolean and Pseudo-Boolean formulas.

Its main focus lies on memory-efficient data-structures for Boolean formulas and efficient algorithms for manipulating and solving them. The library is designed and most notably used in industrial systems which have to manipulate and solve millions of formulas per day. The Java version of LogicNG is heavily used by the German automotive industry to validate and optimize their product documentation, support the configuration process of vehicles, and compute WLTP values for emission and consumption.

Implemented Algorithms

The Go version of LogicNG currently provides the following key functionalities:

  • Support for Boolean formulas, cardinality constraints, and pseudo-Boolean formulas
  • Parsing of Boolean formulas from strings or files
  • Transformations of formulas, like
    • Normal-Forms NNF, DNF, or CNF with various configurable algorithms
    • Substitution in formulas
    • Subsumption
    • Simplification of formulas
  • Encoding cardinality constraints and pseudo-Boolean formulas to purely Boolean formulas with a multitude of different algorithms
  • Solving formulas with an integrated SAT Solver including
    • Fast backbone computation on the solver
    • Incremental/Decremental solver interface
    • Proof generation
    • Optimization with incremental cardinality constraints
    • Fast model and projected model enumeration
  • Optimizing formulas with an integrated MaxSAT solver
  • Knowledge compilation with BDDs or DNNFs
  • Computation of minimum prime implicants and prime implicant covers
  • and many more...

Philosophy

The most important philosophy of the library is to avoid unnecessary object creation. Therefore, formulas can only be generated via formula factories. A formula factory assures that a formula is only created once in memory. If another instance of the same formula is created by the user, the already existing one is returned by the factory. This leads to a small memory footprint and fast execution of algorithms. Formulas can cache the results of algorithms executed on them and since every formula is hold only once in memory it is assured that the same algorithm on the same formula is also executed only once.

Whitepaper

If you want a high-level overview of LogicNG and how it is used in many applications in the area of product configuration, you can read our whitepaper.

First Steps

The following code creates the Boolean Formula A and not (B or not C) programmatically.

import "github.com/booleworks/logicng-go/formula"

fac := formula.NewFactory()
a := fac.Variable("A")
b := fac.Variable("B")
c := fac.Variable("C")
form := fac.And(a, fac.Or(b, fac.Not(c)))

Alternatively you can just parse the formula from a string:

import (
    "github.com/booleworks/logicng-go/formula"
    "github.com/booleworks/logicng-go/parser" 
)

fac := formula.NewFactory()
parser := parser.New(fac)
form, err := parser.Parse("A & (B | ~C)")

Once you created the formula you can for example convert it to NNF or CNF or solve it with a SAT solver:

import (
    "fmt"
    "github.com/booleworks/logicng-go/formula"
    "github.com/booleworks/logicng-go/normalform"
    "github.com/booleworks/logicng-go/parser"
    "github.com/booleworks/logicng-go/sat"
)

fac := formula.NewFactory()
parser := parser.New(fac)
form, err := parser.Parse("A & ~(B | ~C)")

nnf := normalform.NNF(fac, form)
cnf := normalform.CNF(fac, form)

fmt.Println(cnf.Sprint(fac)) // pretty-print the formula

solver := sat.NewSolver(fac)
solver.Add(form)
result := Solver.Sat() // is true

Directories

Path Synopsis
Package assignment provides a data structure for Boolean assignments in LogicNG, mapping Boolean variables to truth values.
Package assignment provides a data structure for Boolean assignments in LogicNG, mapping Boolean variables to truth values.
Package bdd provides data structures and algorithms on Binary Decision Diagrams (BDD) in LogicNG.
Package bdd provides data structures and algorithms on Binary Decision Diagrams (BDD) in LogicNG.
Package configuration provides the interface for configuration types in LogicNG.
Package configuration provides the interface for configuration types in LogicNG.
Package dnnf provides datastructures and algorithms for compiling and manipulation deterministic, decomposable negation normal forms, or short [DNNF] in LogicNG.
Package dnnf provides datastructures and algorithms for compiling and manipulation deterministic, decomposable negation normal forms, or short [DNNF] in LogicNG.
Package encoding provides data structures and algorithms for cardinality and pseudo-Boolean encodings in LogicNG.
Package encoding provides data structures and algorithms for cardinality and pseudo-Boolean encodings in LogicNG.
Package errorx contains LogicNG specific extensions to error types.
Package errorx contains LogicNG specific extensions to error types.
mus
Package mus provides data structures and algorithms for minimal unsatisfiable sets (MUS) in LogicNG.
Package mus provides data structures and algorithms for minimal unsatisfiable sets (MUS) in LogicNG.
smus
Package smus provides an algorithm to compute a smallest minimal unsatisfiable set (SMUS) of a set of propositions or formulas in LogicNG.
Package smus provides an algorithm to compute a smallest minimal unsatisfiable set (SMUS) of a set of propositions or formulas in LogicNG.
Package formula provides all the main data-structures for working with propositional formulas in LogicNG and generate them via a formula factory.
Package formula provides all the main data-structures for working with propositional formulas in LogicNG and generate them via a formula factory.
Package graph contains datastructures and algorithm for simple graph and hyper-graph implementations in LogicNG.
Package graph contains datastructures and algorithm for simple graph and hyper-graph implementations in LogicNG.
Package graphical provides types and methods to generate graphical representations of e.g.
Package graphical provides types and methods to generate graphical representations of e.g.
Package handler provides datastructures for handlers which can be used to abort potentially long-running computations in LogicNG.
Package handler provides datastructures for handlers which can be used to abort potentially long-running computations in LogicNG.
Package io gathers readers and writers for formulas in different formats in LogicNG.
Package io gathers readers and writers for formulas in different formats in LogicNG.
Package maxsat provides an implementation of a MAX-SAT solver with different solving algorithms in LogicNG.
Package maxsat provides an implementation of a MAX-SAT solver with different solving algorithms in LogicNG.
Package model provides a data structure for Boolean models in LogicNG.
Package model provides a data structure for Boolean models in LogicNG.
count
Package count provides algorithms for counting models on formulas in LogicNG.
Package count provides algorithms for counting models on formulas in LogicNG.
enum
Package enum provides algorithms to perform model enumeration on formulas in LogicNG.
Package enum provides algorithms to perform model enumeration on formulas in LogicNG.
iter
Package iter gathers functionality for model iteration in LogicNG.
Package iter gathers functionality for model iteration in LogicNG.
Package normalform provides algorithms for converting Boolean formulas into normal forms in LogicNG.
Package normalform provides algorithms for converting Boolean formulas into normal forms in LogicNG.
Package np provides reduction algorithms from known NP-complete problems to SAT in LogicNG.
Package np provides reduction algorithms from known NP-complete problems to SAT in LogicNG.
Package parser provides a parser for propositional and pseudo-Boolean formulas to LogicNG formula structures.
Package parser provides a parser for propositional and pseudo-Boolean formulas to LogicNG formula structures.
Package primeimplicant provides algorithms for computing minimum prime implicants and minimum prime implicant coverages in LogicNG.
Package primeimplicant provides algorithms for computing minimum prime implicants and minimum prime implicant coverages in LogicNG.
Package randomizer provides a formula randomizer which can be used for fuzzing in testing in LogicNG.
Package randomizer provides a formula randomizer which can be used for fuzzing in testing in LogicNG.
Package sat provides LogicNG's SAT solver with a rich interface.
Package sat provides LogicNG's SAT solver with a rich interface.
Package simplification gathers various simplification algorithms for Boolean formulas in LogicNG.
Package simplification gathers various simplification algorithms for Boolean formulas in LogicNG.
Package transformation gathers various transformations on formulas in LogicNG.
Package transformation gathers various transformations on formulas in LogicNG.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL