{"id":27290800,"url":"https://github.com/hellman/quine-mccluskey","last_synced_at":"2025-04-11T21:39:02.299Z","repository":{"id":139782423,"uuid":"602002766","full_name":"hellman/Quine-McCluskey","owner":"hellman","description":"DenseQMC: A bit-slice implementation of the Quine-McCluskey algorithm","archived":false,"fork":false,"pushed_at":"2023-11-29T13:24:10.000Z","size":5666,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T11:05:52.459Z","etag":null,"topics":["boolean-minimization","cnf","dnf","quine-mccluskey","satisfiability"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hellman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-02-15T09:41:56.000Z","updated_at":"2025-03-20T14:57:06.000Z","dependencies_parsed_at":"2023-11-29T14:44:03.129Z","dependency_job_id":null,"html_url":"https://github.com/hellman/Quine-McCluskey","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellman%2FQuine-McCluskey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellman%2FQuine-McCluskey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellman%2FQuine-McCluskey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellman%2FQuine-McCluskey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hellman","download_url":"https://codeload.github.com/hellman/Quine-McCluskey/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248485437,"owners_count":21111856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boolean-minimization","cnf","dnf","quine-mccluskey","satisfiability"],"created_at":"2025-04-11T21:39:01.784Z","updated_at":"2025-04-11T21:39:02.282Z","avatar_url":"https://github.com/hellman.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DenseQMC: an efficient bit-slice implementation of the Quine-McCluskey algorithm\n\nThis repository contains an optimized bit-slice implementation of the Quine-McCluskey algorithm (for dense functions), as well as optimize classic Quine-McCluskey algorithm (for sparse functions). It covers the first step of the QMC algorithm - finding all prime implicants of the function (patterns like `01*11**0*` with maximal number of stars, fully included in the described set). In other words, code in this repository computes the [Blake canonical form](https://en.wikipedia.org/wiki/Blake_canonical_form) of a Boolean function. It is used to obtain small DNF or CNF formulas.\n\n**Important:** as the second part of the QMC method is not covered, the output formula will not directly have minimal size. Minimization requires solving a hard SetCover problem (NP-Complete), typically of a large size, and thus is feasible only for smaller values of `n`. Consider the [optimodel](https://github.com/hellman/optimodel) tool which includes some algorithms (integer optimization, heuristic greedy variants) to do that (for CNF/DNF/MILP models), or the standard [espresso](https://en.wikipedia.org/wiki/Espresso_heuristic_logic_minimizer) algorithm for very sparse functions.\n\n\u003cimg src=\"./benchmark.png\" alt=\"Benchmark summary\" height=\"400\"\u003e\n\n**License:** MIT\n\n**Note:** this is an early version, results of this implementation were not cross-tested with other tools, please make the necessary verifications.\n\n\n## Computing prime CNF/DNF clauses\n\nThe implementations must first be compiled (requires a C++ compiler):\n\n```sh\n$ make\n```\n\nThen, you can use one of the programs `./denseqmc`, `./sparseqmc` or `./sparseqmcext`. DenseQMC requires 12 GiB of RAM for $n=23$ (triples for each increase of n), 1 TiB of RAM for $n=27$, independently of the input function's density. SparseQMC may requires less if the instance is not too dense (in the DNF mode). In particular, SparseQMC seems to be better even for instances with 50% density but after $n\\approx24$. The limits on the number $n$ of variables are $n=27$ for `denseqmc` (requires 1 TiB of RAM), $n=31$ for `sparseqmc` (due to internal structures), $n=63$ for `sparseqmcext`. Note that the two SparseQMC programs require RAM depending on the density of the function, and for the CNF case the density is flipped and requires computing the full truth table of the function ($2^n$ elements). In other words, computing a CNF of sparse functions is slower and needs more RAM.\n\nBoth programs take as input two arguments:\n```sh\n$ ./denseqmc \u003cfile.in\u003e [file.out]\n$ ./sparseqmc \u003cfile.in\u003e [file.out]\n$ ./sparseqmcext \u003cfile.in\u003e [file.out]\n```\n\nThe input file has the following format:\n- The first line should contain the format letter and the dimension $n$:\n  `d` - usual Quine-McCluskey (DNF mode)\n  `c` - complement the input set and negate variables (CNF mode)\n- Each consequent line should consist of a bitstring of length $n$, containing only ASCII '0' or '1' characters. The vector corresponds to a preimage of 1 in the DNF mode, or to a preimage of 0 in the CNF mode.\n\nExample:\n\n```\nd 5\n00000\n00010\n01000\n01010\n00100\n```\n\nThe output file (stdout if not provided) follows the DIMACS format (adapted to the DNF case), with 0 instead of the actual number of clauses due to implementation issues. For example:\n\n```\np dnf 5 0\n-1 -2 -4 -5 0\n-1 -3 -5 0\n```\n\nEach line (after the header) defines a single clause by specifying variable index (1-based) and variable negation by index negation. E.g. -2 means (NOT x2) and 3 means (x3). The line is finished by the 0 symbol as the separator. The example above describes the DNF formula $x_1'x_2'x_4'x_5' \\lor x_1'x_3'x_5'$.\n\nRunning example:\n\n```sh\n$ cat tests2/cnf_and.in                                                                                                                                                                                                                (base)\nc 3\n000\n010\n100\n111\n\n$ ./denseqmc tests2/cnf_and.in                                                                                                                                                                                                         (base)\nn = 3 mode = c (CNF)\nbitslice alg needs RAM: 0.00 GiB\ninput size: 4/8 (density: 0.5%)\ninput checksum: c1c4e72ea429ad61\nstart n = 3\nfinished dense part\np cnf 3 0\n1 -3 0\n-1 -2 3 0\n2 -3 0\noutput checksum: cff7ffdafc1f800b\nout size: 3\nused RAM: 0.00 GiB\n```\n\n\n## Benchmarking\n\nThe benchmarking tools `./benchmark_denseqmc` and `./benchmark_sparseqmc` requires two parameters: the number of bits `n` and the density `d` in percents, 1 \u003c= n \u003c= 31 and 0 \u003c= d \u003c= 100.\n\nExample:\n\n```sh\n$ /usr/bin/time -v ./benchmark_sparseqmc 24 10\nn = 24 density = 10%\nbitslice alg needs RAM: 35.30 GiB\nwidening hash space from 20 to 25 bits\nchecksum: cbc104c5d92ec573\ninp size: 1676436\nstart n = 24\nweight 0 new minterms 2011003\nwidening hash space from 20 to 22 bits\nweight 1 new minterms 116186\nweight 2 new minterms 44\nweight 3 new minterms 0\nchecksum: 068e3a0c00b8c102\nout size: 1844240\nused RAM: 0.32 GiB  # memory usage (algorithm's view)\n\tCommand being timed: \"./benchmark_sparseqmc 24 10\"\n\tUser time (seconds): 1.76\n\tSystem time (seconds): 0.09\n\tPercent of CPU this job got: 99%\n\tElapsed (wall clock) time (h:mm:ss or m:ss): 0:01.86\n\tAverage shared text size (kbytes): 0\n\tAverage unshared data size (kbytes): 0\n\tAverage stack size (kbytes): 0\n\tAverage total size (kbytes): 0\n\tMaximum resident set size (kbytes): 369212  # total memory usage (system view)\n\tAverage resident set size (kbytes): 0\n\tMajor (requiring I/O) page faults: 0\n\tMinor (reclaiming a frame) page faults: 107075\n\tVoluntary context switches: 1\n\tInvoluntary context switches: 4\n\tSwaps: 0\n\tFile system inputs: 0\n\tFile system outputs: 0\n\tSocket messages sent: 0\n\tSocket messages received: 0\n\tSignals delivered: 0\n\tPage size (bytes): 4096\n\tExit status: 0\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellman%2Fquine-mccluskey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhellman%2Fquine-mccluskey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellman%2Fquine-mccluskey/lists"}