Skip to main content
Files added late

6 files were added to this release more than 14 days after its initial publication. Inspect the release files before installing.

pycosat: bindings to picosat (a SAT solver)

PicoSAT is a popular SAT solver written by Armin Biere in pure C. This package provides efficient Python bindings to picosat on the C level, i.e. when importing pycosat, the picosat solver becomes part of the Python process itself. For ease of deployment, the picosat source (namely picosat.c and picosat.h) is included in this project. These files have been extracted from the picosat source (picosat-957.tar.gz).

Usage

The pycosat module has two functions solve and itersolve, both of which take an iterable of clauses as an argument. Each clause is itself represented as an iterable of (non-zero) integers.

The function solve returns one of the following:
  • one solution (a list of integers)

  • the string “UNSAT” (when the clauses are unsatisfiable)

  • the string “UNKNOWN” (when a solution could not be determined within the propagation limit)

The function itersolve returns an iterator over solutions. When the propagation limit is specified, exhausting the iterator may not yield all possible solutions.

Both functions take the following keyword arguments:
  • prop_limit: the propagation limit (integer)

  • vars: number of variables (integer)

  • verbose: the verbosity level (integer)

Example

Let us consider the following clauses, represented using the DIMACS cnf format:

p cnf 5 3
1 -5 4 0
-1 5 3 4 0
-3 -4 0

Here, we have 5 variables and 3 clauses, the first clause being (x1 or not x5 or x4). Note that the variable x2 is not used in any of the clauses, which means that for each solution with x2 = True, we must also have a solution with x2 = False. In Python, each clause is most conveniently represented as a list of integers. Naturally, it makes sense to represent each solution also as a list of integers, where the sign corresponds to the Boolean value (+ for True and - for False) and the absolute value corresponds to ith variable:

>>> import pycosat
>>> cnf = [[1, -5, 4], [-1, 5, 3, 4], [-3, -4]]
>>> pycosat.solve(cnf)
[1, -2, -3, -4, 5]

This solution translates to: x1 = x5 = True, x2 = x3 = x4 = False

To find all solutions, use itersolve:

>>> for sol in pycosat.itersolve(cnf):
...     print sol
...
[1, -2, -3, -4, 5]
[1, -2, -3, 4, -5]
[1, -2, -3, 4, 5]
...
>>> len(list(pycosat.itersolve(cnf)))
18

In this example, there are a total of 18 possible solutions, which had to be an even number because x2 was left unspecified in the clauses.

The fact that itersolve returns an iterator, makes it very elegant and efficient for many types of operations. For example, using the itertools module from the standard library, here is how one would construct a list of (up to) 3 solutions:

>>> import itertools
>>> list(itertools.islice(pycosat.itersolve(cnf), 3))
[[1, -2, -3, -4, 5], [1, -2, -3, 4, -5], [1, -2, -3, 4, 5]]

Implementation of itersolve

How does one go from having found one solution to another solution? The answer is surprisingly simple. One adds the inverse of the already found solution as a new clause. This new clause ensures that another solution is searched for, as it excludes the already found solution. Here is basically a pure Python implementation of itersolve in terms of solve:

def py_itersolve(clauses): # don't use this function!
    while True:            # (it is only here to explain things)
        sol = pycosat.solve(clauses)
        if isinstance(sol, list):
            yield sol
            clauses.append([-x for x in sol])
        else: # no more solutions -- stop iteration
            return

This implementation has several problems. Firstly, it is quite slow as pycosat.solve has to convert the list of clauses over and over and over again. Secondly, after calling py_itersolve the list of clauses will be modified. In pycosat, itersolve is implemented on the C level, making use of the picosat C interface (which makes it much, much faster than the naive Python implementation above).

Metadata

Release files for pycosat 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Files added late

6 files were uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release files before installing.

Source distribution (sdist)

Source distribution for pycosat 0.6.1
File Size Uploaded
pycosat-0.6.1.tar.gz 59.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pycosat 0.6.1
File
pycosat-0.6.1-cp34-none-win_amd64.whl CPython 3.4 none Windows x86-64 Details
pycosat-0.6.1-cp34-none-win32.whl CPython 3.4 none Windows x86-32 Details
pycosat-0.6.1-cp33-none-win_amd64.whl CPython 3.3 none Windows x86-64 Details
pycosat-0.6.1-cp33-none-win32.whl CPython 3.3 none Windows x86-32 Details
pycosat-0.6.1-cp27-none-win_amd64.whl CPython 2.7 none Windows x86-64 Details
pycosat-0.6.1-cp27-none-win32.whl CPython 2.7 none Windows x86-32 Details

Total release size: 327.7 kB

Release files / pycosat-0.6.1.tar.gz

Download URL pycosat-0.6.1.tar.gz
Size 59.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d438c488da6dd7bbb23ca8ac10531f1fbbd117bdbc2e6245382c1fe202e483ce
BLAKE2b-256 checksum
How to use checksums
760f16edae7bc75b79376f2c260b7a459829785f08e463ecf74a8ccdef62dd4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pycosat-0.6.1-cp34-none-win_amd64.whl

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL pycosat-0.6.1-cp34-none-win_amd64.whl
Size 48.6 kB
Tags CPython 3.4 Windows x86-64
SHA-256 checksum
How to use checksums
238a1d8695ad894e40a70235d020d33ab0bfdc3901715bcc77c7dee522173def
BLAKE2b-256 checksum
How to use checksums
22df9ce078a789ef6e4028acd23076eca906ad30be8111815ca0a2efe5b2f6b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pycosat-0.6.1-cp34-none-win32.whl

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL pycosat-0.6.1-cp34-none-win32.whl
Size 41.9 kB
Tags CPython 3.4 Windows x86-32
SHA-256 checksum
How to use checksums
d874b86eadcc36f743d6bde9bd72608f6ca839ab02d72130725a195722f6060d
BLAKE2b-256 checksum
How to use checksums
fdb71d7da5b5983f7052f94c4705f43e0d7cfc5a54e34db4a7a669ed20f1fd44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pycosat-0.6.1-cp33-none-win_amd64.whl

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL pycosat-0.6.1-cp33-none-win_amd64.whl
Size 48.6 kB
Tags CPython 3.3 Windows x86-64
SHA-256 checksum
How to use checksums
e16021fd8343b45f75563d783ddfee228d627a38c0dfba0bd66845734ae80b9a
BLAKE2b-256 checksum
How to use checksums
95507354a9727fb27450308e047d07c782c1f04584f869c3199d03107a420d65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pycosat-0.6.1-cp33-none-win32.whl

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL pycosat-0.6.1-cp33-none-win32.whl
Size 41.9 kB
Tags CPython 3.3 Windows x86-32
SHA-256 checksum
How to use checksums
665d40accca8bb7098ea022578b36d242f72922c96cd109a614c3a7237f685ca
BLAKE2b-256 checksum
How to use checksums
d9e6c4b89af0f362fed3da895eaba3d91adbc51e2d61d596896ec2c05a51a121
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pycosat-0.6.1-cp27-none-win_amd64.whl

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL pycosat-0.6.1-cp27-none-win_amd64.whl
Size 47.0 kB
Tags CPython 2.7 Windows x86-64
SHA-256 checksum
How to use checksums
0597e8588ba9e01c63653814f3a8e7c9377c150fe09980036786a03c286d2f45
BLAKE2b-256 checksum
How to use checksums
4256e59d0ce4034a2f8772094b5aa2ea0f7857480826f48c21a86f36c0a82c0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pycosat-0.6.1-cp27-none-win32.whl

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL pycosat-0.6.1-cp27-none-win32.whl
Size 40.4 kB
Tags CPython 2.7 Windows x86-32
SHA-256 checksum
How to use checksums
c1ce640a2378f56599de6362423e1f98a1f9ef863bf2a94c393ab8e01514b46d
BLAKE2b-256 checksum
How to use checksums
32bef6ee46a171fac90bddd02bdc9362601732006e41166cdb92ebaf24df1d73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.6.6

1 release file

0.6.3

1 release file

This release

0.6.1 This release

7 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page