Skip to main content

Build Status Readthedocs Python Versions PyPI License

nnf is a Python package for creating and manipulating logical sentences written in the negation normal form (NNF).

NNF sentences make statements about any number of variables. Here's an example:

>>> from nnf import Var
>>> a, b = Var('a'), Var('b')
>>> sentence = (a & b) | (a & ~b)
>>> sentence
Or({And({a, b}), And({a, ~b})})

This sentence says that either a is true and b is true, or a is true and b is false.

You can do a number of things with such a sentence. For example, you can ask whether a particular set of values for the variables makes the sentence true:

>>> sentence.satisfied_by({'a': True, 'b': False})
True
>>> sentence.satisfied_by({'a': False, 'b': False})
False

You can also fill in a value for some of the variables:

>>> sentence.condition({'b': True})
Or({And({a, true}), And({a, false})})

And then reduce the sentence:

>>> _.simplify()
a

This package takes much of its data model and terminology from A Knowledge Compilation Map.

Complete documentation can be found at readthedocs.

Installing

At least Python 3.4 is required.

Recommended

Install with support for a variety of SAT solvers.

pip install nnf[pysat]

Vanilla

pip install nnf

Serialization

A parser and serializer for the DIMACS sat format are implemented in nnf.dimacs, with a standard load/loads/dump/dumps interface.

DSHARP interoperability

DSHARP is a program that compiles CNF sentences to (s)d-DNNF sentences. The nnf.dsharp module contains tools for parsing its output format and for invoking the compiler.

Algebraic Model Counting

nnf.amc has a basic implementation of Algebraic Model Counting.

Command line interface

Some functionality is available through a command line tool, pynnf, including a (slow) SAT solver and a sentence visualizer. For more information, see the documentation.

Credits

python-nnf up to version 0.2.1 was created by Jan Verbeek under mentorship of Ronald de Haan at the University of Amsterdam. It was the subject of an undergraduate thesis, Developing a Python Package for Reasoning with NNF Sentences.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nnf-0.4.1.tar.gz (593.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nnf-0.4.1-py3-none-any.whl (598.8 kB view details)

Uploaded Python 3

File details

Details for the file nnf-0.4.1.tar.gz.

File metadata

  • Download URL: nnf-0.4.1.tar.gz
  • Upload date:
  • Size: 593.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for nnf-0.4.1.tar.gz
Algorithm Hash digest
SHA256 e972e7c1130d9e457241c8096e45ad3f16311c66e810e8c227deb3a43b4a3537
MD5 60c0163496e128d2980ec4c3086bf4cf
BLAKE2b-256 821612221f3c9d21340ca8378df5c047545e3e01ffb088b5177620e5bc8dd128

See more details on using hashes here.

File details

Details for the file nnf-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: nnf-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 598.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for nnf-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 96d0d5797b829941cbbb816304690849cbfefd5361b4d78b378a6bd989c66ba2
MD5 6c72abb1179adc5fa73c51aa4d9f067c
BLAKE2b-256 6601e82d4848bc67cd02b11cd274dbe352f3f4490149361d83456ee63a766959

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page