├── requirements.txt ├── pyeda ├── test │ └── __init__.py ├── logic │ ├── test │ │ ├── __init__.py │ │ ├── test_sudoku.py │ │ ├── test_graycode.py │ │ └── test_addition.py │ ├── __init__.py │ ├── graycode.py │ ├── addition.py │ └── sudoku.py ├── boolalg │ ├── test │ │ ├── __init__.py │ │ └── test_picosat.py │ └── __init__.py ├── parsing │ ├── test │ │ ├── __init__.py │ │ ├── test_pla.py │ │ ├── test_dimacs.py │ │ └── test_boolexpr.py │ ├── __init__.py │ └── token.py ├── __init__.py ├── inter.py └── util.py ├── doc ├── requirements.txt └── source │ ├── image │ ├── bdd_xor3.png │ ├── sudoku1.png │ ├── bdd_order1.png │ ├── bdd_order2.png │ ├── bdd_rename.png │ └── bdd_majority3.png │ ├── reference │ ├── util.rst │ └── boolalg │ │ ├── minimization.rst │ │ ├── bdd.rst │ │ ├── boolfunc.rst │ │ ├── bfarray.rst │ │ ├── espresso.rst │ │ └── picosat.rst │ ├── reference.rst │ ├── index.rst │ └── overview.rst ├── thirdparty ├── picosat │ ├── VERSION │ └── LICENSE └── espresso │ ├── .gitignore │ ├── test │ ├── maj.pla │ ├── ha.pla │ ├── bb_all.out │ │ ├── bb_50x5x50_20%_0.pla.out │ │ ├── bb_50x5x50_20%_5.pla.out │ │ ├── bb_50x5x50_20%_3.pla.out │ │ ├── bb_50x5x50_20%_4.pla.out │ │ ├── bb_50x5x50_20%_1.pla.out │ │ ├── bb_50x5x50_20%_2.pla.out │ │ ├── bb_50x5x50_20%_7.pla.out │ │ ├── bb_50x5x50_20%_9.pla.out │ │ ├── bb_50x5x50_20%_6.pla.out │ │ ├── bb_50x5x50_20%_8.pla.out │ │ ├── bb_100x5x50_20%_4.pla.out │ │ ├── bb_100x5x50_20%_8.pla.out │ │ ├── bb_100x5x50_20%_7.pla.out │ │ ├── bb_100x5x50_20%_5.pla.out │ │ ├── bb_100x5x50_20%_9.pla.out │ │ ├── bb_50x5x50_50%_7.pla.out │ │ ├── bb_50x5x50_50%_1.pla.out │ │ ├── bb_50x5x50_50%_8.pla.out │ │ ├── bb_100x5x50_20%_0.pla.out │ │ ├── bb_100x5x50_20%_2.pla.out │ │ ├── bb_100x5x50_20%_3.pla.out │ │ ├── bb_50x5x50_50%_3.pla.out │ │ ├── bb_50x5x50_50%_5.pla.out │ │ ├── bb_50x5x50_50%_6.pla.out │ │ ├── bb_50x5x50_50%_0.pla.out │ │ ├── bb_100x5x50_20%_1.pla.out │ │ ├── bb_100x5x50_20%_6.pla.out │ │ ├── bb_50x5x50_50%_2.pla.out │ │ ├── bb_50x5x50_50%_4.pla.out │ │ └── bb_50x5x50_50%_9.pla.out │ └── bb_all │ │ ├── bb_50x5x50_20%_0.pla │ │ ├── bb_50x5x50_20%_1.pla │ │ ├── bb_50x5x50_20%_2.pla │ │ ├── bb_50x5x50_20%_3.pla │ │ └── bb_50x5x50_20%_4.pla │ ├── Makefile │ ├── src │ ├── utility.h │ ├── sminterf.c │ ├── backup │ │ ├── signature.h │ │ ├── signature_exact.c │ │ ├── canonical.c │ │ ├── sigma.c │ │ └── equiv.c │ ├── mincov_int.h │ ├── solution.c │ ├── set.h │ ├── cvrmisc.c │ ├── dominate.c │ ├── globals.c │ ├── part.c │ ├── indep.c │ └── gimpel.c │ └── test.py ├── extension └── boolexpr │ ├── .gitignore │ ├── test │ ├── main.cpp │ ├── test_vector.cpp │ ├── boolexprtest.hpp │ ├── test_nnf.cpp │ ├── test_array.cpp │ ├── test_flatten.cpp │ ├── test_product.cpp │ ├── boolexprtest.cpp │ ├── test_bubble.cpp │ └── test_compose.cpp │ ├── util.h │ ├── share.h │ ├── primes-inl.c │ ├── memcheck.h │ ├── array.c │ ├── util.c │ ├── product.c │ ├── vector.c │ ├── compose.c │ ├── bubble.c │ └── binary.c ├── .travis.yml ├── requirements_dev.txt ├── MANIFEST.in ├── .gitignore ├── .coveragerc ├── Makefile └── LICENSE /requirements.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pyeda/test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pyeda/logic/test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | pillow 2 | -------------------------------------------------------------------------------- /pyeda/boolalg/test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pyeda/parsing/test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /thirdparty/picosat/VERSION: -------------------------------------------------------------------------------- 1 | 960 2 | -------------------------------------------------------------------------------- /thirdparty/espresso/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | espresso 3 | -------------------------------------------------------------------------------- /pyeda/logic/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | PyEDA Logic 3 | """ 4 | 5 | -------------------------------------------------------------------------------- /extension/boolexpr/.gitignore: -------------------------------------------------------------------------------- 1 | # Filename: .gitignore 2 | 3 | bld/ 4 | -------------------------------------------------------------------------------- /pyeda/boolalg/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | PyEDA Boolean Algebra 3 | """ 4 | 5 | -------------------------------------------------------------------------------- /pyeda/parsing/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | PyEDA Parsing Utilities 3 | """ 4 | 5 | -------------------------------------------------------------------------------- /pyeda/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Python EDA Package 3 | """ 4 | 5 | __version__ = "0.29.0" 6 | 7 | -------------------------------------------------------------------------------- /doc/source/image/bdd_xor3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cjdrake/pyeda/HEAD/doc/source/image/bdd_xor3.png -------------------------------------------------------------------------------- /doc/source/image/sudoku1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cjdrake/pyeda/HEAD/doc/source/image/sudoku1.png -------------------------------------------------------------------------------- /doc/source/image/bdd_order1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cjdrake/pyeda/HEAD/doc/source/image/bdd_order1.png -------------------------------------------------------------------------------- /doc/source/image/bdd_order2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cjdrake/pyeda/HEAD/doc/source/image/bdd_order2.png -------------------------------------------------------------------------------- /doc/source/image/bdd_rename.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cjdrake/pyeda/HEAD/doc/source/image/bdd_rename.png -------------------------------------------------------------------------------- /doc/source/image/bdd_majority3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cjdrake/pyeda/HEAD/doc/source/image/bdd_majority3.png -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Filename: .travis.yml 2 | 3 | language: python 4 | 5 | python: 6 | - "3.3" 7 | - "3.4" 8 | 9 | # command to run tests 10 | script: make test 11 | 12 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/maj.pla: -------------------------------------------------------------------------------- 1 | # Filename: maj.pla 2 | 3 | # Majority function 4 | .i 3 5 | .o 1 6 | .type fr 7 | 000 0 8 | 001 0 9 | 010 0 10 | 011 1 11 | 100 0 12 | 101 1 13 | 110 1 14 | 111 1 15 | .e 16 | 17 | -------------------------------------------------------------------------------- /extension/boolexpr/test/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: main.cpp 3 | ** 4 | ** Entry point for all unit tests. 5 | */ 6 | 7 | 8 | #include 9 | 10 | 11 | int 12 | main(int argc, char * argv[]) { 13 | ::testing::InitGoogleTest(&argc, argv); 14 | return RUN_ALL_TESTS(); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /requirements_dev.txt: -------------------------------------------------------------------------------- 1 | # Development Requirements 2 | # To install: pip install -r requirements_dev.txt 3 | 4 | # Include runtime requirements 5 | -r requirements.txt 6 | 7 | build 8 | twine 9 | 10 | # PyLint: https://pylint.org 11 | pylint 12 | 13 | # PyTest: https://pytest.org 14 | pytest 15 | pytest-cov 16 | 17 | # Sphinx 18 | sphinx 19 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include Makefile 2 | include LICENSE 3 | include README.rst 4 | include requirements.txt 5 | 6 | recursive-include doc * 7 | 8 | include extension/boolexpr/* 9 | 10 | include thirdparty/espresso/src/* 11 | include thirdparty/picosat/* 12 | 13 | include pyeda/logic/test/top95.txt 14 | include pyeda/logic/test/top95_solns.txt 15 | 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Filename: .gitignore 2 | 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Packages 9 | *.egg 10 | *.egg-info 11 | dist 12 | build 13 | eggs 14 | parts 15 | bin 16 | var 17 | sdist 18 | develop-eggs 19 | .installed.cfg 20 | lib 21 | lib64 22 | 23 | # Unit test / coverage reports 24 | .coverage 25 | cover 26 | 27 | # Other 28 | .ipynb* 29 | 30 | -------------------------------------------------------------------------------- /doc/source/reference/util.rst: -------------------------------------------------------------------------------- 1 | .. reference/util.rst 2 | 3 | *********************************** 4 | :mod:`pyeda.util` --- Utilities 5 | *********************************** 6 | 7 | .. automodule:: pyeda.util 8 | 9 | Interface Functions 10 | =================== 11 | 12 | .. autofunction:: pyeda.util.bit_on 13 | 14 | .. autofunction:: pyeda.util.clog2 15 | 16 | .. autofunction:: pyeda.util.parity 17 | -------------------------------------------------------------------------------- /extension/boolexpr/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: util.h 3 | */ 4 | 5 | 6 | void _bx_free_exprs(int length, struct BoolExpr **exprs); 7 | 8 | struct BoolExpr * _bx_op_transform(struct BoolExpr *op, 9 | struct BoolExpr * (*fn)(struct BoolExpr *)); 10 | 11 | void _bx_mark_flags(struct BoolExpr *ex, BX_Flags f); 12 | 13 | bool _bx_is_clause(struct BoolExpr *op); 14 | 15 | -------------------------------------------------------------------------------- /doc/source/reference.rst: -------------------------------------------------------------------------------- 1 | .. _reference: 2 | 3 | ************* 4 | Reference 5 | ************* 6 | 7 | .. toctree:: 8 | :maxdepth: 1 9 | 10 | reference/util.rst 11 | reference/boolalg/boolfunc.rst 12 | reference/boolalg/bdd.rst 13 | reference/boolalg/expr.rst 14 | reference/boolalg/bfarray.rst 15 | reference/boolalg/minimization.rst 16 | reference/boolalg/picosat.rst 17 | reference/boolalg/espresso.rst 18 | 19 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | # Filename: .coveragerc 2 | 3 | [run] 4 | branch = true 5 | 6 | [report] 7 | # Regexes for lines to exclude from consideration 8 | exclude_lines = 9 | # Have to re-enable the standard pragma 10 | pragma: no cover 11 | 12 | # Don't complain if tests don't hit defensive assertion code: 13 | raise AssertionError 14 | raise NotImplementedError 15 | 16 | ignore_errors = true 17 | 18 | [html] 19 | directory = cover 20 | 21 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/ha.pla: -------------------------------------------------------------------------------- 1 | # Filename: ha.pla 2 | 3 | # 2-bit by 2-bit binary adder (with no carry input) 4 | .i 4 5 | .o 3 6 | .ilb a1 a0 b1 b0 7 | .ob s2 s1 s0 8 | #.pair 2 (a1 b1) (a0 b0) 9 | #.phase 011 10 | .type fr 11 | 0000 000 12 | 0001 001 13 | 0010 010 14 | 0011 011 15 | 0100 001 16 | 0101 010 17 | 0110 011 18 | 0111 100 19 | 1000 010 20 | 1001 011 21 | 1010 100 22 | 1011 101 23 | 1100 011 24 | 1101 100 25 | 1110 101 26 | 1111 110 27 | .e 28 | 29 | -------------------------------------------------------------------------------- /doc/source/reference/boolalg/minimization.rst: -------------------------------------------------------------------------------- 1 | .. reference/boolalg/minimization.rst 2 | 3 | ************************************************************ 4 | :mod:`pyeda.boolalg.minimization` --- Logic Minimization 5 | ************************************************************ 6 | 7 | .. automodule:: pyeda.boolalg.minimization 8 | 9 | Interface Functions 10 | =================== 11 | 12 | .. autofunction:: pyeda.boolalg.minimization.espresso_exprs 13 | 14 | .. autofunction:: pyeda.boolalg.minimization.espresso_tts 15 | 16 | -------------------------------------------------------------------------------- /thirdparty/espresso/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile 2 | 3 | VPATH := src utility 4 | 5 | CC := clang 6 | CFLAGS := 7 | 8 | # espresso 9 | OBJS := cofactor cols compl contain cubestr cvrin cvrm cvrmisc cvrout dominate espresso essen exact expand gasp gimpel globals hack indep irred main matrix mincov opo pair part primes reduce rows set setc sharp sminterf solution sparse unate verify 10 | 11 | espresso: $(addsuffix .o,$(OBJS)) 12 | $(CC) -o $@ $^ 13 | 14 | %.o: %.c 15 | $(CC) -c $(CFLAGS) $< 16 | 17 | .PHONY: test 18 | test: espresso 19 | @./test.py 20 | 21 | .PHONY: clean 22 | clean: 23 | rm -f *.o 24 | rm -f espresso 25 | -------------------------------------------------------------------------------- /pyeda/logic/graycode.py: -------------------------------------------------------------------------------- 1 | """ 2 | Logic functions for gray code 3 | 4 | Interface Functions: 5 | bin2gray 6 | gray2bin 7 | """ 8 | 9 | 10 | # Disable 'invalid-name', b/c 'logic' package uses unconventional names 11 | # pylint: disable=C0103 12 | 13 | 14 | from pyeda.boolalg.bfarray import farray, fcat 15 | 16 | 17 | def bin2gray(B): 18 | """Convert a binary-coded vector into a gray-coded vector.""" 19 | return fcat(B[:-1] ^ B[1:], B[-1]) 20 | 21 | 22 | def gray2bin(G): 23 | """Convert a gray-coded vector into a binary-coded vector.""" 24 | return farray([G[i:].uxor() for i, _ in enumerate(G)]) 25 | 26 | -------------------------------------------------------------------------------- /pyeda/logic/test/test_sudoku.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test logic functions for Sudoku 3 | """ 4 | 5 | 6 | import os 7 | 8 | from pyeda.logic.sudoku import SudokuSolver 9 | 10 | SOLVER = SudokuSolver() 11 | 12 | cwd, _ = os.path.split(__file__) 13 | top95_txt = os.path.join(cwd, "top95.txt") 14 | top95_solns_txt = os.path.join(cwd, "top95_solns.txt") 15 | with open(top95_txt, encoding="utf-8") as fin: 16 | GRIDS = [line.strip() for line in fin] 17 | with open(top95_solns_txt, encoding="utf-8") as fin: 18 | SOLNS = [line.strip() for line in fin] 19 | 20 | 21 | def test_sudoku(): 22 | for i, grid in enumerate(GRIDS): 23 | assert SOLVER.display_solve(grid) == SOLNS[i] 24 | -------------------------------------------------------------------------------- /pyeda/logic/test/test_graycode.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test logic functions for gray code 3 | """ 4 | 5 | 6 | from pyeda.boolalg.bfarray import exprvars, uint2exprs 7 | from pyeda.logic.graycode import bin2gray, gray2bin 8 | 9 | 10 | def test_bin2gray(): 11 | B = exprvars("B", 4) 12 | G = bin2gray(B) 13 | gnums = [G.vrestrict({B: uint2exprs(i, 4)}).to_uint() for i in range(16)] 14 | assert gnums == [0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8] 15 | 16 | 17 | def test_gray2bin(): 18 | G = exprvars("G", 4) 19 | B = gray2bin(G) 20 | gnums = [0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8] 21 | bnums = [B.vrestrict({G: uint2exprs(i, 4)}).to_uint() for i in gnums] 22 | assert bnums == list(range(16)) 23 | -------------------------------------------------------------------------------- /extension/boolexpr/share.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: share.h 3 | ** 4 | ** Private functions shared between C files 5 | */ 6 | 7 | 8 | /* array.c */ 9 | struct BX_Array * _bx_array_from(size_t length, struct BoolExpr **exprs); 10 | 11 | /* boolexpr.c */ 12 | extern struct BoolExpr * _bx_identity[16]; 13 | extern struct BoolExpr * _bx_dominator[16]; 14 | 15 | struct BoolExpr * _bx_op_from(BX_Kind kind, size_t n, struct BoolExpr **xs); 16 | struct BoolExpr * _bx_op_new(BX_Kind kind, size_t n, struct BoolExpr **xs); 17 | struct BoolExpr * _bx_orandxor_new(BX_Kind kind, size_t n, struct BoolExpr **xs); 18 | 19 | /* nnf.c */ 20 | struct BoolExpr * _bx_to_nnf(struct BoolExpr *ex); 21 | 22 | /* simple.c */ 23 | struct BoolExpr * _bx_simplify(struct BoolExpr *ex); 24 | 25 | -------------------------------------------------------------------------------- /extension/boolexpr/test/test_vector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: test_vector.cpp 3 | ** 4 | ** Test the BX_Vector data type. 5 | */ 6 | 7 | 8 | #include "boolexprtest.hpp" 9 | 10 | 11 | class BX_Vector_Test: public BoolExpr_Test {}; 12 | 13 | 14 | TEST_F(BX_Vector_Test, Vector) 15 | { 16 | struct BX_Vector *vec; 17 | 18 | // Initial length=0, capacity=64 19 | vec = BX_Vector_New(); 20 | EXPECT_EQ(vec->length, 0); 21 | EXPECT_EQ(vec->capacity, 64); 22 | 23 | // Resize a couple times 24 | for (int i = 0; i < N; ++i) { 25 | BX_Vector_Append(vec, xns[i]); 26 | BX_Vector_Append(vec, xs[i]); 27 | } 28 | EXPECT_EQ(vec->length, 2*N); 29 | EXPECT_GE(vec->capacity, 2*N); 30 | 31 | BX_Vector_Del(vec); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/utility.h: -------------------------------------------------------------------------------- 1 | // Filename: utility.h 2 | 3 | #ifndef UTILITY_H 4 | #define UTILITY_H 5 | 6 | #include 7 | 8 | #define NIL(type) ((type *) 0) 9 | 10 | #define ALLOC(type, num) ((type *) malloc(sizeof(type) * (num))) 11 | 12 | #define REALLOC(type, obj, num) \ 13 | (obj) ? ((type *) realloc((char *) obj, sizeof(type) * (num))) \ 14 | : ((type *) malloc(sizeof(type) * (num))) 15 | 16 | #define FREE(obj) if ((obj)) { free((char *) (obj)); (obj) = 0; } 17 | 18 | #ifndef MAX 19 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) 20 | #endif 21 | 22 | #ifndef MIN 23 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 24 | #endif 25 | 26 | #ifndef ABS 27 | #define ABS(a) ((a) > 0 ? (a) : -(a)) 28 | #endif 29 | 30 | #endif // UTILITY_H 31 | 32 | -------------------------------------------------------------------------------- /extension/boolexpr/test/boolexprtest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: boolexprtest.hpp 3 | */ 4 | 5 | 6 | #include 7 | 8 | #include "boolexpr.h" 9 | 10 | 11 | /* 12 | ** Return true if two expressions are similar. 13 | ** 14 | ** This is just a cheap way to check expression transformations against 15 | ** expected values. 16 | ** It does not check function equality or isomorphism. 17 | */ 18 | bool Similar(BoolExpr * const, BoolExpr * const); 19 | 20 | 21 | class BoolExpr_Test: public ::testing::Test 22 | { 23 | 24 | protected: 25 | 26 | virtual void SetUp(); 27 | virtual void TearDown(); 28 | 29 | static const int N = 1024; 30 | 31 | struct BX_Vector *lits; 32 | 33 | BoolExpr *xns[N]; 34 | BoolExpr *xs[N]; 35 | 36 | BoolExpr *ops[N]; 37 | 38 | BoolExpr *exps[N]; 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /pyeda/boolalg/test/test_picosat.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test the PicoSAT interface 3 | """ 4 | 5 | 6 | import pytest 7 | 8 | from pyeda.boolalg import picosat 9 | from pyeda.boolalg.expr import expr, expr2dimacscnf 10 | 11 | 12 | def test_basic(): 13 | assert picosat.COPYRIGHT == "Copyright (c) 2006 - 2014 Armin Biere JKU Linz" 14 | assert picosat.VERSION == "960" 15 | 16 | 17 | def test_satisfy_one_errors(): 18 | with pytest.raises(TypeError): 19 | picosat.satisfy_one(6, ((1, -2, "bad_lit"), (-4, 5, -6))) 20 | with pytest.raises(ValueError): 21 | picosat.satisfy_one(5, ((1, -2, 3), (-4, 5, -6))) 22 | 23 | 24 | def test_satisfy_one(): 25 | _, cnf = expr2dimacscnf(expr("And(a, b, c)")) 26 | assert picosat.satisfy_one(cnf.nvars, cnf.clauses) == (1, 1, 1) 27 | assert list(picosat.satisfy_all(cnf.nvars, cnf.clauses)) == [(1, 1, 1)] 28 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/sminterf.c: -------------------------------------------------------------------------------- 1 | // Filename: sminterf.c 2 | 3 | #include "espresso.h" 4 | 5 | set * 6 | do_sm_minimum_cover(set_family_t *A) 7 | { 8 | sm_matrix *M; 9 | sm_row *sparse_cover; 10 | sm_element *pe; 11 | set *cover; 12 | int i, base, rownum; 13 | unsigned val; 14 | set *last, *p; 15 | 16 | M = sm_alloc(); 17 | rownum = 0; 18 | foreach_set(A, last, p) { 19 | foreach_set_element(p, i, val, base) { 20 | sm_insert(M, rownum, base); 21 | } 22 | rownum++; 23 | } 24 | 25 | sparse_cover = sm_minimum_cover(M, NIL(int), 1, 0); 26 | sm_free(M); 27 | 28 | cover = set_new(A->sf_size); 29 | sm_foreach_row_element(sparse_cover, pe) { 30 | set_insert(cover, pe->col_num); 31 | } 32 | sm_row_free(sparse_cover); 33 | 34 | return cover; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Filename: Makefile 2 | 3 | PYLINT := pylint 4 | PYTHON := python3 5 | 6 | PIP_INSTALL_FLAGS := -r requirements.txt 7 | 8 | .PHONY: help 9 | help: 10 | @printf "Usage: make [options] [target] ...\n" 11 | @printf "\n" 12 | @printf "Valid targets:\n" 13 | @printf "\n" 14 | @printf " help Display this help message\n" 15 | @printf " test Run unit test suite\n" 16 | @printf " lint Run lint checks\n" 17 | @printf " cover Collect coverage\n" 18 | @printf " html Build Sphinx documentation\n" 19 | 20 | .PHONY: test 21 | test: 22 | @pytest --doctest-modules --ignore=doc 23 | 24 | .PHONY: lint 25 | lint: 26 | @$(PYLINT) pyeda --rcfile .pylintrc 27 | 28 | .PHONY: cover 29 | cover: 30 | @pytest --doctest-modules --ignore=doc --cov=pyeda --cov-report=html 31 | 32 | .PHONY: html 33 | html: 34 | @$(PYTHON) setup.py build_sphinx 35 | 36 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/backup/signature.h: -------------------------------------------------------------------------------- 1 | // Filename: signature.h 2 | 3 | /* black_white.c */ 4 | void setup_bw(); 5 | void free_bw(); 6 | int black_white(); 7 | void split_list(); 8 | void merge_list(); 9 | void print_bw(); 10 | void variable_list_alloc(); 11 | void variable_list_delete(); 12 | void variable_list_insert(); 13 | int variable_list_empty(); 14 | void get_next_variable(); 15 | void print_variable_list(); 16 | 17 | /* canonical.c */ 18 | int is_minterm(); 19 | set_family_t *find_canonical_cover(); 20 | 21 | /* essentiality.c */ 22 | set_family_t *etr_order(); 23 | void aux_etr_order(); 24 | set_family_t *get_mins(); 25 | int ascending(); 26 | 27 | /* sigma.c */ 28 | set *get_sigma(); 29 | void set_not(); 30 | 31 | /* signature.c */ 32 | void cleanup(); 33 | set_family_t *signature(); 34 | set_family_t *generate_primes(); 35 | 36 | /* signature_exact.c */ 37 | set_family_t *signature_minimize_exact(); 38 | sm_matrix *signature_form_table(); 39 | -------------------------------------------------------------------------------- /doc/source/reference/boolalg/bdd.rst: -------------------------------------------------------------------------------- 1 | .. reference/boolalg/bdd.rst 2 | 3 | ********************************************************* 4 | :mod:`pyeda.boolalg.bdd` --- Binary Decision Diagrams 5 | ********************************************************* 6 | 7 | .. automodule:: pyeda.boolalg.bdd 8 | 9 | Interface Functions 10 | =================== 11 | 12 | .. autofunction:: pyeda.boolalg.bdd.bddvar 13 | 14 | .. autofunction:: pyeda.boolalg.bdd.expr2bdd 15 | 16 | .. autofunction:: pyeda.boolalg.bdd.bdd2expr 17 | 18 | .. autofunction:: pyeda.boolalg.bdd.upoint2bddpoint 19 | 20 | .. autofunction:: pyeda.boolalg.bdd.ite 21 | 22 | Interface Classes 23 | ----------------- 24 | 25 | .. autoclass:: pyeda.boolalg.bdd.BDDNode 26 | 27 | .. autoclass:: pyeda.boolalg.bdd.BinaryDecisionDiagram 28 | :members: dfs_preorder, 29 | dfs_postorder, 30 | bfs, 31 | equivalent, 32 | to_dot 33 | :member-order: bysource 34 | 35 | .. autoclass:: pyeda.boolalg.bdd.BDDConstant 36 | 37 | .. autoclass:: pyeda.boolalg.bdd.BDDVariable 38 | 39 | -------------------------------------------------------------------------------- /thirdparty/picosat/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006 - 2014, Armin Biere, Johannes Kepler University. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | IN THE SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /extension/boolexpr/primes-inl.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: primes-inl.c 3 | */ 4 | 5 | static size_t _primes[] = { 6 | /* (2^0, 2^1) */ 2, 7 | /* (2^1, 2^2) */ 3, 8 | /* (2^2, 2^3) */ 7, 9 | /* (2^3, 2^4) */ 13, 10 | /* (2^4, 2^5) */ 23, 11 | 12 | /* From: http://planetmath.org/goodhashtableprimes */ 13 | 14 | /* (2^5, 2^6) */ 53, 15 | /* (2^6, 2^7) */ 97, 16 | /* (2^7, 2^8) */ 193, 17 | /* (2^8, 2^9) */ 389, 18 | /* (2^9, 2^10) */ 769, 19 | /* (2^10, 2^11) */ 1543, 20 | /* (2^11, 2^12) */ 3079, 21 | /* (2^12, 2^13) */ 6151, 22 | /* (2^13, 2^14) */ 12289, 23 | /* (2^14, 2^15) */ 24593, 24 | /* (2^15, 2^16) */ 49157, 25 | /* (2^16, 2^17) */ 98317, 26 | /* (2^17, 2^18) */ 196613, 27 | /* (2^18, 2^19) */ 393241, 28 | /* (2^19, 2^20) */ 786433, 29 | /* (2^20, 2^21) */ 1572869, 30 | /* (2^21, 2^22) */ 3145739, 31 | /* (2^22, 2^23) */ 6291469, 32 | /* (2^23, 2^24) */ 12582917, 33 | /* (2^24, 2^25) */ 25165843, 34 | /* (2^25, 2^26) */ 50331653, 35 | /* (2^26, 2^27) */ 100663319, 36 | /* (2^27, 2^28) */ 201326611, 37 | /* (2^28, 2^29) */ 402653189, 38 | /* (2^29, 2^30) */ 805306457, 39 | /* (2^30, 2^31) */ 1610612741, 40 | }; 41 | 42 | -------------------------------------------------------------------------------- /extension/boolexpr/memcheck.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: memcheck.h 3 | ** 4 | ** Convenience macros for checking memory allocation 5 | */ 6 | 7 | 8 | #ifndef MEMCHECK_H 9 | #define MEMCHECK_H 10 | 11 | 12 | #define CHECK_NULL(y, x) \ 13 | do { \ 14 | if ((y = x) == NULL) \ 15 | return NULL; \ 16 | } while (0) 17 | 18 | 19 | #define CHECK_NULL_1(y, x, temp) \ 20 | do { \ 21 | if ((y = x) == NULL) { \ 22 | BX_DecRef(temp); \ 23 | return NULL; \ 24 | } \ 25 | } while (0) 26 | 27 | 28 | #define CHECK_NULL_2(y, x, t0, t1) \ 29 | do { \ 30 | if ((y = x) == NULL) { \ 31 | BX_DecRef(t0); \ 32 | BX_DecRef(t1); \ 33 | return NULL; \ 34 | } \ 35 | } while (0) 36 | 37 | 38 | #define CHECK_NULL_3(y, x, t0, t1, t2) \ 39 | do { \ 40 | if ((y = x) == NULL) { \ 41 | BX_DecRef(t0); \ 42 | BX_DecRef(t1); \ 43 | BX_DecRef(t2); \ 44 | return NULL; \ 45 | } \ 46 | } while (0) 47 | 48 | 49 | #define CHECK_NULL_N(y, x, n, temps) \ 50 | do { \ 51 | if ((y = x) == NULL) { \ 52 | for (size_t i = 0; i < n; ++i) \ 53 | BX_DecRef(temps[i]); \ 54 | free(temps); \ 55 | return NULL; \ 56 | } \ 57 | } while (0) 58 | 59 | 60 | #endif // MEMCHECK_H 61 | 62 | -------------------------------------------------------------------------------- /doc/source/index.rst: -------------------------------------------------------------------------------- 1 | .. index.rst 2 | 3 | Python EDA Documentation 4 | ======================== 5 | 6 | :Release: |version| 7 | :Date: |today| 8 | 9 | PyEDA is a Python library for electronic design automation. 10 | 11 | Fork PyEDA: https://github.com/cjdrake/pyeda 12 | 13 | Features: 14 | 15 | * Symbolic Boolean algebra with a selection of function representations: 16 | 17 | * Logic expressions 18 | * Truth tables, with three output states (0, 1, "don't care") 19 | * Reduced, ordered binary decision diagrams (ROBDDs) 20 | 21 | * SAT solvers: 22 | 23 | * Backtracking 24 | * `PicoSAT `_ 25 | 26 | * `Espresso `_ logic minimization 27 | * Formal equivalence 28 | * Multi-dimensional bit vectors 29 | * DIMACS CNF/SAT parsers 30 | * Logic expression parser 31 | 32 | Contents 33 | -------- 34 | 35 | .. toctree:: 36 | :maxdepth: 2 37 | 38 | overview.rst 39 | install.rst 40 | boolalg.rst 41 | bdd.rst 42 | expr.rst 43 | farray.rst 44 | 2llm.rst 45 | sudoku.rst 46 | queens.rst 47 | relnotes.rst 48 | reference.rst 49 | 50 | Indices and Tables 51 | ------------------ 52 | 53 | * :ref:`genindex` 54 | * :ref:`modindex` 55 | * :ref:`search` 56 | 57 | -------------------------------------------------------------------------------- /thirdparty/espresso/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | import re 5 | from multiprocessing import Pool 6 | from subprocess import check_output 7 | 8 | PLAS = [ 9 | 'bb_50x5x50_20%_0.pla', 10 | 'bb_50x5x50_20%_1.pla', 11 | 'bb_50x5x50_20%_2.pla', 12 | 'bb_50x5x50_20%_3.pla', 13 | 'bb_50x5x50_20%_4.pla', 14 | 'bb_50x5x50_20%_5.pla', 15 | 'bb_50x5x50_20%_6.pla', 16 | 'bb_50x5x50_20%_7.pla', 17 | 'bb_50x5x50_20%_8.pla', 18 | 'bb_50x5x50_20%_9.pla', 19 | 20 | 'bb_50x5x50_50%_0.pla', 21 | 'bb_50x5x50_50%_1.pla', 22 | 'bb_50x5x50_50%_2.pla', 23 | 'bb_50x5x50_50%_3.pla', 24 | 'bb_50x5x50_50%_4.pla', 25 | 'bb_50x5x50_50%_5.pla', 26 | 'bb_50x5x50_50%_6.pla', 27 | 'bb_50x5x50_50%_7.pla', 28 | 'bb_50x5x50_50%_8.pla', 29 | 'bb_50x5x50_50%_9.pla', 30 | ] 31 | 32 | def test(pla): 33 | pla_in = os.path.join('test', 'bb_all', pla) 34 | espresso_output = check_output(['./espresso', pla_in]) 35 | pla_out = os.path.join('test', 'bb_all.out', pla + '.out') 36 | with open(pla_out) as fin: 37 | print("checking:", pla_in) 38 | return fin.read().encode('utf-8') == espresso_output 39 | 40 | def main(): 41 | p = Pool(4) 42 | assert all(p.map(test, PLAS)) 43 | 44 | if __name__ == '__main__': 45 | main() 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Chris Drake 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | -------------------------------------------------------------------------------- /pyeda/parsing/token.py: -------------------------------------------------------------------------------- 1 | """ 2 | Token types used by lex and parse operations 3 | 4 | Interface Classes: 5 | Token 6 | EndToken 7 | KeywordToken 8 | NameToken 9 | LiteralToken 10 | StringToken 11 | NumberToken 12 | IntegerToken 13 | FloatToken 14 | OperatorToken 15 | PunctuationToken 16 | """ 17 | 18 | import collections 19 | 20 | Token = collections.namedtuple('Token', ['value', 'lineno', 'offset']) 21 | 22 | 23 | class EndToken(Token): 24 | """Special token for end of buffer""" 25 | 26 | class KeywordToken(Token): 27 | """Base class for keyword tokens""" 28 | 29 | class NameToken(Token): 30 | """Base class for name tokens""" 31 | 32 | class LiteralToken(Token): 33 | """Base class for literal tokens""" 34 | 35 | class StringToken(LiteralToken): 36 | """literal.string tokens, eg 'hello world'""" 37 | 38 | class NumberToken(LiteralToken): 39 | """Base class for literal.number tokens""" 40 | 41 | class IntegerToken(NumberToken): 42 | """literal.number.integer tokens, eg 42""" 43 | 44 | class FloatToken(NumberToken): 45 | """literal.number.float tokens, eg 6.0221413e+23""" 46 | 47 | class OperatorToken(Token): 48 | """literal.operator tokens, eg +-*/""" 49 | 50 | class PunctuationToken(Token): 51 | """literal.punctuation tokens, eg !@#$""" 52 | 53 | -------------------------------------------------------------------------------- /pyeda/parsing/test/test_pla.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test PLA parsing functions 3 | """ 4 | 5 | 6 | import pytest 7 | 8 | from pyeda.boolalg.espresso import FTYPE, RTYPE 9 | from pyeda.parsing.pla import Error, parse 10 | 11 | BASIC = """ 12 | # Filename: basic.pla 13 | 14 | .i 4 15 | .o 2 16 | .ilb x y z 17 | .ob f g 18 | .p 3 19 | .type fr 20 | 0001 00 21 | 0010 01 22 | 0100 10 23 | 1000 11 24 | .e 25 | """ 26 | 27 | 28 | def test_errors(): 29 | # General syntax error 30 | with pytest.raises(Error): 31 | parse("foo\nbar\nfiz\nbuz\n") 32 | # .i declared more than once 33 | with pytest.raises(Error): 34 | parse(".i 1\n.i 2\n") 35 | # .o declared more than once 36 | with pytest.raises(Error): 37 | parse(".o 1\n.o 2\n") 38 | # .ilb declared more than once 39 | with pytest.raises(Error): 40 | parse(".ilb a b\n.ilb c d\n") 41 | # .ob declared more than once 42 | with pytest.raises(Error): 43 | parse(".ob a b\n.ob c d\n") 44 | # .type declared more than once 45 | with pytest.raises(Error): 46 | parse(".type f\n.type r\n") 47 | 48 | 49 | def test_basic(): 50 | d = parse(BASIC) 51 | assert d == { 52 | "ninputs": 4, 53 | "noutputs": 2, 54 | "input_labels": ["x", "y", "z"], 55 | "output_labels": ["f", "g"], 56 | "intype": FTYPE | RTYPE, 57 | "cover": { 58 | ((1, 1, 1, 2), (0, 0)), 59 | ((1, 1, 2, 1), (0, 1)), 60 | ((1, 2, 1, 1), (1, 0)), 61 | ((2, 1, 1, 1), (1, 1)) 62 | }, 63 | } 64 | -------------------------------------------------------------------------------- /extension/boolexpr/test/test_nnf.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: test_nnf.cpp 3 | */ 4 | 5 | 6 | #include "boolexprtest.hpp" 7 | 8 | 9 | class BX_NNF_Test: public BoolExpr_Test {}; 10 | 11 | 12 | TEST_F(BX_NNF_Test, Basic) 13 | { 14 | ops[0] = BX_NorN(2, xs[0], xs[1]); 15 | ops[1] = BX_ToNNF(ops[0]); 16 | exps[0] = BX_AndN(2, xns[0], xns[1]); 17 | EXPECT_TRUE(Similar(ops[1], exps[0])); 18 | 19 | ops[2] = BX_NandN(2, xs[0], xs[1]); 20 | ops[3] = BX_ToNNF(ops[2]); 21 | exps[1] = BX_OrN(2, xns[0], xns[1]); 22 | EXPECT_TRUE(Similar(ops[3], exps[1])); 23 | 24 | ops[4] = BX_XorN(2, xs[0], xs[1]); 25 | ops[5] = BX_ToNNF(ops[4]); 26 | exps[2] = BX_AndN(2, xns[0], xs[1]); 27 | exps[3] = BX_AndN(2, xs[0], xns[1]); 28 | exps[4] = BX_OrN(2, exps[2], exps[3]); 29 | EXPECT_TRUE(Similar(ops[5], exps[4])); 30 | 31 | ops[6] = BX_EqualN(3, xs[0], xs[1], xs[2]); 32 | ops[7] = BX_ToNNF(ops[6]); 33 | exps[5] = BX_AndN(3, xns[0], xns[1], xns[2]); 34 | exps[6] = BX_AndN(3, xs[0], xs[1], xs[2]); 35 | exps[7] = BX_OrN(2, exps[5], exps[6]); 36 | EXPECT_TRUE(Similar(ops[7], exps[7])); 37 | 38 | ops[8] = BX_Implies(xs[0], xs[1]); 39 | ops[9] = BX_ToNNF(ops[8]); 40 | exps[8] = BX_OrN(2, xns[0], xs[1]); 41 | EXPECT_TRUE(Similar(ops[9], exps[8])); 42 | 43 | ops[10] = BX_ITE(xs[0], xs[1], xs[2]); 44 | ops[11] = BX_ToNNF(ops[10]); 45 | exps[9] = BX_AndN(2, xs[0], xs[1]); 46 | exps[10] = BX_AndN(2, xns[0], xs[2]); 47 | exps[11] = BX_OrN(2, exps[9], exps[10]); 48 | EXPECT_TRUE(Similar(ops[11], exps[11])); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /extension/boolexpr/array.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: array.c 3 | */ 4 | 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "boolexpr.h" 11 | 12 | 13 | struct BX_Array * 14 | _bx_array_from(size_t length, struct BoolExpr **exprs) 15 | { 16 | struct BX_Array *array; 17 | 18 | array = malloc(sizeof(struct BX_Array)); 19 | if (array == NULL) 20 | return NULL; // LCOV_EXCL_LINE 21 | 22 | array->length = length; 23 | array->items = exprs; 24 | 25 | for (size_t i = 0; i < length; ++i) 26 | BX_IncRef(array->items[i]); 27 | 28 | return array; 29 | } 30 | 31 | 32 | struct BX_Array * 33 | BX_Array_New(size_t length, struct BoolExpr **exprs) 34 | { 35 | struct BoolExpr **exprs_copy; 36 | 37 | exprs_copy = malloc(length * sizeof(struct BoolExpr *)); 38 | if (exprs_copy == NULL) 39 | return NULL; // LCOV_EXCL_LINE 40 | 41 | for (size_t i = 0; i < length; ++i) 42 | exprs_copy[i] = exprs[i]; 43 | 44 | return _bx_array_from(length, exprs_copy); 45 | } 46 | 47 | 48 | void 49 | BX_Array_Del(struct BX_Array *array) 50 | { 51 | for (size_t i = 0; i < array->length; ++i) 52 | BX_DecRef(array->items[i]); 53 | free(array->items); 54 | free(array); 55 | } 56 | 57 | 58 | bool 59 | BX_Array_Equal(struct BX_Array *self, struct BX_Array *other) 60 | { 61 | if (self->length != other->length) 62 | return false; 63 | 64 | for (size_t i = 0; i < self->length; ++i) { 65 | if (self->items[i] != other->items[i]) 66 | return false; 67 | } 68 | 69 | return true; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /extension/boolexpr/test/test_array.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: test_array.cpp 3 | ** 4 | ** Test the BX_Array data type. 5 | */ 6 | 7 | 8 | #include "boolexprtest.hpp" 9 | 10 | 11 | class BX_Array_Test: public BoolExpr_Test {}; 12 | 13 | 14 | TEST_F(BX_Array_Test, Basic) 15 | { 16 | struct BoolExpr *items[] = {xs[0], xs[1], xs[2], xs[3]}; 17 | 18 | struct BX_Array *array = BX_Array_New(4, items); 19 | 20 | // BX_Array_Length 21 | EXPECT_EQ(array->length, 4); 22 | 23 | // BX_Array_GetItem 24 | for (int i = 0; i < array->length; ++i) 25 | EXPECT_EQ(array->items[i], xs[i]); 26 | 27 | BX_Array_Del(array); 28 | } 29 | 30 | 31 | TEST_F(BX_Array_Test, Equal) 32 | { 33 | struct BoolExpr *itemsA[] = {xs[0], xs[1], xs[2], xs[3]}; 34 | struct BoolExpr *itemsB[] = {xs[0], xs[1], xs[2], xs[3]}; 35 | 36 | struct BX_Array *a = BX_Array_New(4, itemsA); 37 | struct BX_Array *b = BX_Array_New(4, itemsB); 38 | 39 | EXPECT_TRUE(BX_Array_Equal(a, b)); 40 | 41 | BX_Array_Del(a); 42 | BX_Array_Del(b); 43 | } 44 | 45 | 46 | TEST_F(BX_Array_Test, NotEqual) 47 | { 48 | struct BoolExpr *itemsA[] = {xs[0], xs[1], xs[2], xs[3]}; 49 | struct BoolExpr *itemsB[] = {xs[0], xs[1], xs[3], xs[2]}; 50 | struct BoolExpr *itemsC[] = {xs[0], xs[1]}; 51 | 52 | struct BX_Array *a = BX_Array_New(4, itemsA); 53 | struct BX_Array *b = BX_Array_New(4, itemsB); 54 | struct BX_Array *c = BX_Array_New(2, itemsC); 55 | 56 | // Unequal items 57 | EXPECT_FALSE(BX_Array_Equal(a, b)); 58 | // Unequal lengths 59 | EXPECT_FALSE(BX_Array_Equal(a, c)); 60 | 61 | BX_Array_Del(a); 62 | BX_Array_Del(b); 63 | BX_Array_Del(c); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /doc/source/reference/boolalg/boolfunc.rst: -------------------------------------------------------------------------------- 1 | .. reference/boolalg/boolfunc.rst 2 | 3 | ******************************************************* 4 | :mod:`pyeda.boolalg.boolfunc` --- Boolean Functions 5 | ******************************************************* 6 | 7 | .. automodule:: pyeda.boolalg.boolfunc 8 | 9 | Interface Functions 10 | =================== 11 | 12 | .. autofunction:: pyeda.boolalg.boolfunc.num2point 13 | 14 | .. autofunction:: pyeda.boolalg.boolfunc.num2upoint 15 | 16 | .. autofunction:: pyeda.boolalg.boolfunc.num2term 17 | 18 | .. autofunction:: pyeda.boolalg.boolfunc.point2upoint 19 | 20 | .. autofunction:: pyeda.boolalg.boolfunc.point2term 21 | 22 | .. autofunction:: pyeda.boolalg.boolfunc.iter_points 23 | 24 | .. autofunction:: pyeda.boolalg.boolfunc.iter_upoints 25 | 26 | .. autofunction:: pyeda.boolalg.boolfunc.iter_terms 27 | 28 | .. autofunction:: pyeda.boolalg.boolfunc.vpoint2point 29 | 30 | Interface Classes 31 | ================= 32 | 33 | .. autoclass:: pyeda.boolalg.boolfunc.Variable 34 | :members: __lt__, 35 | name, 36 | qualname 37 | :member-order: bysource 38 | 39 | .. autoclass:: pyeda.boolalg.boolfunc.Function 40 | :members: __invert__, __or__, __and__, __xor__, 41 | __add__, __mul__, 42 | support, usupport, inputs, top, 43 | degree, cardinality, 44 | iter_domain, iter_image, iter_relation, 45 | restrict, vrestrict, compose, 46 | satisfy_one, satisfy_all, satisfy_count, 47 | iter_cofactors, cofactors, 48 | smoothing, consensus, derivative, 49 | is_zero, is_one, 50 | box, unbox 51 | :member-order: bysource 52 | 53 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/mincov_int.h: -------------------------------------------------------------------------------- 1 | // Filename: mincov_int.h 2 | 3 | #include "utility.h" 4 | #include "sparse.h" 5 | 6 | typedef struct stats_struct stats_t; 7 | struct stats_struct { 8 | int debug; /* 1 if debugging is enabled */ 9 | int max_print_depth; /* dump stats for levels up to this level */ 10 | int max_depth; /* deepest the recursion has gone */ 11 | int nodes; /* total nodes visited */ 12 | int component; /* currently solving a component */ 13 | int comp_count; /* number of components detected */ 14 | int gimpel_count; /* number of times Gimpel reduction applied */ 15 | int gimpel; /* currently inside Gimpel reduction */ 16 | long start_time; /* cpu time when the covering started */ 17 | int no_branching; 18 | int lower_bound; 19 | }; 20 | 21 | typedef struct solution_struct solution_t; 22 | struct solution_struct { 23 | sm_row *row; 24 | int cost; 25 | }; 26 | 27 | solution_t *solution_alloc(void); 28 | void solution_free(solution_t *sol); 29 | solution_t *solution_dup(solution_t *sol); 30 | void solution_accept(solution_t *sol, sm_matrix *A, int *weight, int col); 31 | void solution_reject(solution_t *sol, sm_matrix *A, int *weight, int col); 32 | void solution_add(solution_t *sol, int *weight, int col); 33 | solution_t *solution_choose_best(solution_t *best1, solution_t *best2); 34 | 35 | solution_t *sm_maximal_independent_set(sm_matrix *A, int *weight); 36 | solution_t *sm_mincov(sm_matrix *A, solution_t *select, int *weight, int lb, int bound, int depth, stats_t *stats); 37 | int gimpel_reduce(sm_matrix *A, solution_t *select, int *weight, int lb, int bound, int depth, stats_t *stats, solution_t **best); 38 | 39 | #define WEIGHT(weight, col) (weight == NIL(int) ? 1 : weight[col]) 40 | 41 | -------------------------------------------------------------------------------- /extension/boolexpr/test/test_flatten.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: test_flatten.cpp 3 | */ 4 | 5 | 6 | #include "boolexprtest.hpp" 7 | 8 | 9 | class BX_Flatten_Test: public BoolExpr_Test {}; 10 | 11 | 12 | TEST_F(BX_Flatten_Test, Atoms) 13 | { 14 | ops[0] = BX_ToDNF(&BX_Zero); 15 | EXPECT_EQ(ops[0], &BX_Zero); 16 | 17 | ops[1] = BX_ToCNF(&BX_Zero); 18 | EXPECT_EQ(ops[1], &BX_Zero); 19 | 20 | ops[2] = BX_ToDNF(xs[0]); 21 | EXPECT_EQ(ops[2], xs[0]); 22 | 23 | ops[3] = BX_ToCNF(xs[0]); 24 | EXPECT_EQ(ops[3], xs[0]); 25 | } 26 | 27 | 28 | TEST_F(BX_Flatten_Test, Clauses) 29 | { 30 | ops[0] = BX_OrN(3, xs[0], xs[1], xs[2]); 31 | ops[1] = BX_Simplify(ops[0]); 32 | ops[2] = BX_ToDNF(ops[1]); 33 | EXPECT_EQ(ops[2], ops[1]); 34 | ops[3] = BX_ToCNF(ops[1]); 35 | EXPECT_EQ(ops[3], ops[1]); 36 | 37 | ops[4] = BX_AndN(3, xs[0], xs[1], xs[2]); 38 | ops[5] = BX_Simplify(ops[4]); 39 | ops[6] = BX_ToDNF(ops[5]); 40 | EXPECT_EQ(ops[6], ops[5]); 41 | ops[7] = BX_ToCNF(ops[5]); 42 | EXPECT_EQ(ops[7], ops[5]); 43 | } 44 | 45 | 46 | TEST_F(BX_Flatten_Test, Basic) 47 | { 48 | ops[0] = BX_XorN(4, xs[0], xs[1], xs[2], xs[3]); 49 | 50 | ops[1] = BX_ToDNF(ops[0]); 51 | EXPECT_EQ(ops[1]->kind, BX_OP_OR); 52 | EXPECT_EQ(ops[1]->data.xs->length, 8); 53 | 54 | ops[2] = BX_ToCNF(ops[1]); 55 | EXPECT_EQ(ops[2]->kind, BX_OP_AND); 56 | EXPECT_EQ(ops[2]->data.xs->length, 8); 57 | } 58 | 59 | 60 | // Only for coverage and memory leak checking 61 | TEST_F(BX_Flatten_Test, FIXME) 62 | { 63 | ops[0] = BX_AndN(2, xs[1], xs[2]); 64 | ops[1] = BX_AndN(3, xs[3], xs[4], xs[5]); 65 | ops[2] = BX_OrN(3, xs[0], ops[0], ops[1]); 66 | ops[3] = BX_ToCNF(ops[2]); 67 | ops[4] = BX_CompleteSum(ops[2]); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_20%_0.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 25 6 | 0-------------------------1-----1----------0----1- 00110 7 | ----------------0------------0-0-0--------1------- 00101 8 | ------------1-------0---------------1------1-0---- 10100 9 | -------------0---------0-0-0--------------------1- 10001 10 | --------------1--------0-1--------1---------0----- 00101 11 | -------0----------0---1--1--0---0----------------- 11011 12 | ---------------------------11------------01---1--- 10010 13 | ----------------0-------------------0----01---0--- 01001 14 | -----------01-----------------------------0---1--1 11000 15 | --------0----------------------------101-1-------- 00111 16 | --------1--------------------------1--------0---01 11100 17 | -1---1--------1----------------------------------0 00001 18 | -----------0-------------0----0-----------0------- 10000 19 | -------------------------1-------1-0-------------1 10000 20 | ------1---------------0-----0----1--------1------- 11001 21 | 0-------------------------1-0----------------1---- 00100 22 | --------0--------1----------0-------0------------- 00010 23 | --------------------0-----------0-----------1-0--- 00100 24 | --------------------0----1---1----------------0--- 00100 25 | -------------00------------------------11--------- 11000 26 | -----------------1----------------------0-----0-1- 01010 27 | ----------------------------0-1---------0-0---1--- 11110 28 | --------------------------0-0---0---------0------- 00011 29 | ---------------------------1--------1---0------0-- 01011 30 | ----------------------0-----1---0------0---------- 01110 31 | .e 32 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_20%_5.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 25 6 | --------0---------1---------------------------1-00 01010 7 | -------------------------------0---1---01------0-- 00110 8 | --------1--1------------------1-------------0----- 00011 9 | --------------------1-----------1------0---1---0-- 10100 10 | --------------------------------1----0-1-1----0--- 10100 11 | ----------1--------0------------------------01---- 00110 12 | --------------------0---1--------0-------1-------0 10001 13 | -------------0-----1---0-------------------1-----1 10011 14 | -----0----------0------------------------0------0- 01000 15 | --------1-------------------0-----------0--------0 10100 16 | -----0----------1-----------1---------1--------1-- 11000 17 | -------1----------------------00--------00-------- 00101 18 | 1-----0-----------------------------1-------1-1--- 01001 19 | --------1--10--------------1----------1----------- 00011 20 | --------0-----------0--------------------11--1---- 01100 21 | ----1-------------0----------------------1--0----1 00001 22 | -0-------------0------0-----------1--------------- 10010 23 | -----------0-----------------------0-0---0-------- 10000 24 | --1----0--------1----------0-------------------1-- 10101 25 | ---0---1---------------1-----------------1-------- 01110 26 | ---------------------------1----0------------11--- 01100 27 | --0--------1--0--------------------------------1-- 10010 28 | --------1--------------------0------0------------- 10010 29 | -------------1-----1-1------1--------------------- 00100 30 | -----1--0---------------0----------------0-------- 00001 31 | .e 32 | -------------------------------------------------------------------------------- /extension/boolexpr/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: util.c 3 | */ 4 | 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "boolexpr.h" 12 | #include "memcheck.h" 13 | #include "share.h" 14 | 15 | 16 | void 17 | _bx_free_exprs(size_t length, struct BoolExpr **exprs) 18 | { 19 | for (size_t i = 0; i < length; ++i) 20 | BX_DecRef(exprs[i]); 21 | 22 | free(exprs); 23 | } 24 | 25 | 26 | struct BoolExpr * 27 | _bx_op_transform(struct BoolExpr *op, struct BoolExpr * (*fn)(struct BoolExpr *)) 28 | { 29 | size_t length = op->data.xs->length; 30 | struct BoolExpr **xs; 31 | unsigned int mod_count = 0; 32 | struct BoolExpr *y; 33 | 34 | xs = malloc(length * sizeof(struct BoolExpr *)); 35 | if (xs == NULL) 36 | return NULL; // LCOV_EXCL_LINE 37 | 38 | for (size_t i = 0; i < length; ++i) { 39 | CHECK_NULL_N(xs[i], fn(op->data.xs->items[i]), i, xs); 40 | mod_count += (xs[i] != op->data.xs->items[i]); 41 | } 42 | 43 | if (mod_count) 44 | y = _bx_op_new(op->kind, length, xs); 45 | else 46 | y = BX_IncRef(op); 47 | 48 | _bx_free_exprs(length, xs); 49 | 50 | return y; 51 | } 52 | 53 | 54 | void 55 | _bx_mark_flags(struct BoolExpr *ex, BX_Flags f) 56 | { 57 | if ((ex->flags & f) != f) { 58 | for (size_t i = 0; i < ex->data.xs->length; ++i) 59 | _bx_mark_flags(ex->data.xs->items[i], f); 60 | ex->flags |= f; 61 | } 62 | } 63 | 64 | 65 | /* Return true if the operator is a clause, containing only literals */ 66 | bool 67 | _bx_is_clause(struct BoolExpr *op) 68 | { 69 | for (size_t i = 0; i < op->data.xs->length; ++i) { 70 | if (!BX_IS_LIT(op->data.xs->items[i])) 71 | return false; 72 | } 73 | 74 | return true; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /doc/source/reference/boolalg/bfarray.rst: -------------------------------------------------------------------------------- 1 | .. reference/boolalg/bfarray.rst 2 | 3 | ************************************************************ 4 | :mod:`pyeda.boolalg.bfarray` --- Boolean Function Arrays 5 | ************************************************************ 6 | 7 | .. automodule:: pyeda.boolalg.bfarray 8 | 9 | Interface Functions 10 | =================== 11 | 12 | .. autofunction:: pyeda.boolalg.bfarray.bddzeros 13 | 14 | .. autofunction:: pyeda.boolalg.bfarray.bddones 15 | 16 | .. autofunction:: pyeda.boolalg.bfarray.bddvars 17 | 18 | .. autofunction:: pyeda.boolalg.bfarray.exprzeros 19 | 20 | .. autofunction:: pyeda.boolalg.bfarray.exprones 21 | 22 | .. autofunction:: pyeda.boolalg.bfarray.exprvars 23 | 24 | .. autofunction:: pyeda.boolalg.bfarray.ttzeros 25 | 26 | .. autofunction:: pyeda.boolalg.bfarray.ttones 27 | 28 | .. autofunction:: pyeda.boolalg.bfarray.ttvars 29 | 30 | .. autofunction:: pyeda.boolalg.bfarray.uint2bdds 31 | 32 | .. autofunction:: pyeda.boolalg.bfarray.uint2exprs 33 | 34 | .. autofunction:: pyeda.boolalg.bfarray.uint2tts 35 | 36 | .. autofunction:: pyeda.boolalg.bfarray.int2bdds 37 | 38 | .. autofunction:: pyeda.boolalg.bfarray.int2exprs 39 | 40 | .. autofunction:: pyeda.boolalg.bfarray.int2tts 41 | 42 | .. autofunction:: pyeda.boolalg.bfarray.fcat 43 | 44 | Interface Classes 45 | ================= 46 | 47 | .. autoclass:: pyeda.boolalg.bfarray.farray 48 | :members: __invert__, __or__, __and__, __xor__, 49 | __lshift__, __rshift__, 50 | __add__, __mul__, 51 | restrict, vrestrict, compose, 52 | size, offsets, ndim, reshape, flat, 53 | to_uint, to_int, 54 | zext, sext, 55 | uor, unor, uand, unand, uxor, uxnor, 56 | lsh, rsh, arsh, 57 | decode 58 | :member-order: bysource 59 | 60 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_20%_3.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 26 6 | -------------------0-----------------------01-1--0 00010 7 | ------------------------------------101--------0-0 01000 8 | -0------1---------------------------01---0-------- 00101 9 | ----------------------1-1---1--------1-0---------- 00101 10 | ------1---------------0----------1-------1-0------ 01100 11 | --------------1------0-----------------------0--01 10001 12 | ---------------0---1-----------0-1------------0--- 00011 13 | -----------------0----0------1------------0-0----- 10010 14 | -------------0------------------------1--0--01---- 10010 15 | -------1-----------0---------------------1-----01- 00110 16 | -------------0----------11-------------------1---0 10100 17 | --------------1------------------0---0----0-----0- 10001 18 | --------------------------------0-0-----1--10----- 01110 19 | --------------------------------------0-----0--111 10100 20 | -1-------------------------------0--0-----1-1----- 01101 21 | ---------------0-------1---1----------0--------0-- 11100 22 | --------0-----------0--------0------------------1- 01000 23 | -10----------------------------------00---0------- 10011 24 | ------------------------0----------0-------0-----0 10000 25 | -----------------------01-------1-------------0--- 01100 26 | -------------------------------------0--0-------10 10000 27 | -----------------------------0-0--1------------1-- 01010 28 | --------------------------1--------0----01-------- 10100 29 | --------------------------0---1--0-------------1-- 10001 30 | ---------------0---------------0---------------10- 00011 31 | ---------0---1----------------------------1-----1- 01011 32 | .e 33 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_20%_4.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 26 6 | --------------------0-----------------1--0-----0-1 01010 7 | ---------------1----------------------1------0---0 00100 8 | -------1--1--0-------------0------------------0--- 10100 9 | ----1-----1--0---------0----------------------1--- 10111 10 | ------1---1-------------------------1------------- 10000 11 | ------1-----------------------------------0----11- 11100 12 | ---------------1-----------------0-----0---------1 01000 13 | ----1-------0--------0-------------------1------1- 01001 14 | -----------1--------0---------------0-1----------- 00001 15 | ---------------------0------10----------1---1----- 01110 16 | ----1------1----1-------------------------0----1-- 10001 17 | 1----------00----------------------1-------------- 00001 18 | ---------------------0-0----1--0---1-------------- 10101 19 | ---------------------0-----------0--1--------0-10- 01111 20 | ----------------0-----------1------------0-----1-- 10010 21 | --0-----------0----------------0-----0------------ 00001 22 | ----------0-1------0--------------1--0------------ 10010 23 | -----------0--------------0----------0----0---0--- 00111 24 | -0------------------0-0------------------------10- 11100 25 | -------10------------0------------------0---1-0--- 10001 26 | -10-----------------------0------------0--1------- 00011 27 | 0-------0---------------------0---------0------0-- 00010 28 | ----0---------0----------1--------------------1-0- 01101 29 | -0--------------------------1-1-----------1------- 10010 30 | -1----------------------11-------1---------------- 00100 31 | --0-0------------------------------1-0----1------- 01101 32 | .e 33 | -------------------------------------------------------------------------------- /extension/boolexpr/product.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: product.c 3 | */ 4 | 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "boolexpr.h" 11 | #include "memcheck.h" 12 | #include "share.h" 13 | 14 | 15 | static struct BX_Array * 16 | _multiply(BX_Kind kind, struct BX_Array *a, struct BX_Array *b) 17 | { 18 | size_t length = a->length * b->length; 19 | struct BoolExpr **exprs; 20 | struct BX_Array *prod; 21 | 22 | exprs = malloc(length * sizeof(struct BoolExpr *)); 23 | if (exprs == NULL) 24 | return NULL; // LCOV_EXCL_LINE 25 | 26 | for (size_t i = 0, index = 0; i < a->length; ++i) { 27 | for (size_t j = 0; j < b->length; ++j, ++index) { 28 | struct BoolExpr *xs[2] = {a->items[i], b->items[j]}; 29 | CHECK_NULL_N(exprs[index], _bx_op_new(kind, 2, xs), index, exprs); 30 | } 31 | } 32 | 33 | prod = _bx_array_from(length, exprs); 34 | 35 | for (size_t i = 0; i < length; ++i) 36 | BX_DecRef(exprs[i]); 37 | 38 | return prod; 39 | } 40 | 41 | 42 | static struct BX_Array * 43 | _product(BX_Kind kind, size_t n, struct BX_Array **arrays) 44 | { 45 | if (n == 0) { 46 | struct BoolExpr *items[] = {_bx_identity[kind]}; 47 | return BX_Array_New(1, items); 48 | } 49 | 50 | struct BX_Array *prev; 51 | struct BX_Array *prod; 52 | 53 | prev = _product(kind, n-1, arrays); 54 | if (prev == NULL) 55 | return NULL; // LCOV_EXCL_LINE 56 | 57 | prod = _multiply(kind, arrays[n-1], prev); 58 | if (prod == NULL) { 59 | BX_Array_Del(prev); // LCOV_EXCL_LINE 60 | return NULL; // LCOV_EXCL_LINE 61 | } 62 | 63 | BX_Array_Del(prev); 64 | 65 | return prod; 66 | } 67 | 68 | 69 | struct BX_Array * 70 | BX_Product(BX_Kind kind, size_t length, struct BX_Array **arrays) 71 | { 72 | return _product(kind, length, arrays); 73 | } 74 | 75 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_20%_1.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 27 6 | --0----------------1-----0--------0-----0-1------- 11000 7 | -------------------------0-----1--0--11-1--------- 10010 8 | --------------1-----------00------1---1----------- 10000 9 | ------1-1----0--------------1--------------------0 11000 10 | --------0-0---1-----0-----------------1----------- 01010 11 | -----------------0------1-1----------0-------1---- 10100 12 | ---------------------------1---1-----0-------0--0- 00011 13 | ----11-------------------0--------1-1------------- 01001 14 | -------------------------00----------------1---1-1 00110 15 | ---------01----------1----1---------0------------- 10101 16 | ----0-------0-------------------1-------1-------0- 11100 17 | -----------0------0-0------0------------------1--- 01101 18 | ----------------------1-1----------------1-1---0-- 01110 19 | ---------------0-----0------1----------1--------1- 00111 20 | ------------------------------1---1------0----1--- 00010 21 | ------------------1----0------------11-----------1 01110 22 | -------------------------1-----1--------0--------1 00010 23 | ---------------------------------0------11-1--0--- 10110 24 | -------1-----------------0----------0-----0-----0- 00111 25 | ----1--------------0--------0--------------------0 01001 26 | ------------------1---1-----0---------------1----- 10100 27 | ---------------------------0----------0--0-----1-- 01001 28 | ---------------------0-----------0---0--0--------- 10001 29 | --------1---------1------------------------1-0---- 00101 30 | ---------------------0-------1----1------------1-- 00101 31 | ----------------------------------0-------1-----1- 10000 32 | -------1-------------0--------------1---1--------- 01011 33 | .e 34 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_20%_2.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 27 6 | ---------------0-1----------010------------------- 10100 7 | -----------------1-101-------------------0-------- 10001 8 | -----1----1-1----------------1-------------1------ 11000 9 | ----1---0-----1-----------------0----------------0 00110 10 | --------0--------------------0-0-------1--------1- 00011 11 | ------------------------0-----1---1---------1----0 00110 12 | ------------1-------1-------------1---1----------0 10001 13 | -------------0-----1-----1---1--0----------------- 11010 14 | -----1--------1------------------------------0-11- 11100 15 | -------------------------0----01----------------0- 00100 16 | -------------------------------1-------1-0--1--1-- 10101 17 | ------------0------------0---------------------0-- 00010 18 | ------------1---------------0---------1--0-------- 00001 19 | --------------------0--------1--------------10---- 00100 20 | -------------------010-------0-------------------- 01100 21 | --------------------0-0--------------------1----0- 10001 22 | ---------00------------------------0---------0---- 00101 23 | ----------------------0---0--------0-------------0 01001 24 | ----------------------------1-----------1------01- 01010 25 | ------------1--------------------0----0-1--------- 00011 26 | ------------------------0---1-----------10-------- 10010 27 | -------------------0---------------0--------1----0 00011 28 | ---------------0----1------------------0-----1---- 01110 29 | --------1--------0--------------------------00---- 11001 30 | -----------------0-0------------------------0----- 01000 31 | ----------1-----------1----------------0---------- 00010 32 | ----------1-------------------------------------11 00010 33 | .e 34 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_20%_7.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 27 6 | --------1---0--------------0--------1---1--------1 10101 7 | -------------0-------------------1--0---1-1------- 01100 8 | -----------1---------------110---------------1---- 00110 9 | 0---------0-------------1---------------00-------- 00101 10 | --0--------------------------------1--10-------0-- 10001 11 | --0------0-----------------0-----0---0------------ 10001 12 | -----1----------1---0------------------------0-1-- 01001 13 | --0------------------------0-----0----1---1------- 01100 14 | --------0--------------------------01----------1-- 10010 15 | ---------------1---------1------------------1-0--- 01000 16 | ----------------1-----------0----0-1-----------1-- 00110 17 | ---0--------------1-----------------------------00 00010 18 | --1-------------1---0--------------------1-------1 11100 19 | -------------0--1------------------------1-----1-- 01000 20 | --1---------------1----11------------------------- 00010 21 | --------1--0------------1-----------1-1----------- 10110 22 | ---0-------------0------0---1--------------------- 01100 23 | -0---------1----------------0---------0---0------- 11110 24 | -------------------------------------0--01-1------ 10010 25 | -----------------------------------0--0---0-0----- 10010 26 | ------------------------1-0------------------0-0-- 00011 27 | ------------------------1-----------------0-1-1--- 00110 28 | -------------1-----------------------1-------0---- 00001 29 | --------------------------1--------11------0------ 01011 30 | ------------------------1-----0----1-------------1 11001 31 | --------0-----1------------------0---------------- 10000 32 | ---01------0-------------------------------------- 00100 33 | .e 34 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_20%_9.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 27 6 | ----------1----1--------1--------------0--1--1---- 00101 7 | ----------00------------0---------------1-11------ 10100 8 | ------------1-----0--------1------0-------------0- 00010 9 | ----------------------------1--1---1--------11---- 00001 10 | -------1----0-0-1----------------1---------------- 00011 11 | -----------------------------------1-0------11---1 00010 12 | -0----------------------------------1--0--1-----0- 01100 13 | -----------0----0---------------1-------1------1-- 01001 14 | -------1---------------0-----------1---1---0------ 01100 15 | ----------0--------0--------1--------------1-1---- 10100 16 | ------------------10--------------0-----1--0------ 01010 17 | --------0----------1-----------1---0-----------1-- 10011 18 | ------------0------------1-----0-----0------------ 10000 19 | -----------------------------------------00--0---1 10000 20 | ----------0-----0-1----------------------1-------- 00100 21 | ------------------------0---1-----0--0------------ 00100 22 | -----------------1-----------------0---11------1-- 01110 23 | 1-1-0-----------------------------------0--------- 01001 24 | ----------------------00----1----0--------------0- 11101 25 | ------------------0---0----1------------0----1---- 11011 26 | -----------------1-----------------0--1--1-------- 01001 27 | ---------------1-----------------0-----0--0------- 11000 28 | ----------1----------------------0-------1-----1-- 11000 29 | ------------------------1---------0---1----0------ 01010 30 | ------------1---------------------------0--11----- 01010 31 | ----------------------------------------0--10----1 10110 32 | ------------------------1--------------1-----0---- 01000 33 | .e 34 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_20%_6.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 28 6 | -----010----------1-------0--------------------1-- 01110 7 | -------------------0---------0-----1------10----0- 01100 8 | ---------1-------0---------1---------0----------1- 10000 9 | ------------------------0-0---11------1--0-------- 10110 10 | --0----1-------------1------------------0----0---- 01000 11 | -----------1-------0----1-----------------1--0---- 00100 12 | --------------------------1-1------0----0------0-0 01011 13 | ---0----------------1----------------------1--0-0- 10001 14 | -------------------0---0---------------11------1-- 00101 15 | -----------------------1-----0-11----0-----0------ 10111 16 | ----0---------1--------------1---1------0--------- 11000 17 | --0---------1----------------1-0-------1---------- 11000 18 | ---------------------0--------------1-----0-0--0-- 01100 19 | ------------1------------0------------1--------0-0 10010 20 | 0------------------------0------0-1--------------1 11010 21 | ------------------0------------1-------0------1--- 00100 22 | --------0----01--------------------------1-------0 11001 23 | ---1--------------------1------1----------0------- 00010 24 | -------1----------------------------1-----00------ 00001 25 | ------------------------1-------0--------0-----0-0 10110 26 | ---------1----1---------0------------------0------ 00001 27 | ------------1--------0----1-----0--------------0-- 11100 28 | ------------------------0----0--0-----0--------0-- 01101 29 | -----1--------------0------------1----0----------- 10001 30 | ----------------------------------11-0--1--------- 01010 31 | -------------------0--------10-----1-------------- 00011 32 | -------------------------0-----0---------1-------- 01000 33 | ------------------------0-----------1--0---------- 00001 34 | .e 35 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_20%_8.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 28 6 | ------------------1---0---1---1--------1----1----- 11000 7 | -------------0--0-------------00-------0----0----- 01110 8 | ------0-------------------------1----0-0---0------ 10010 9 | 1--------0-----------0--------1---------------10-- 10101 10 | --1--------------1-------------------------10----0 00110 11 | ------------------------------0---------11---11--- 01001 12 | --1---1-----------------0--1------1--------------- 10001 13 | -----------10--0-------0------------------------0- 10001 14 | -----------0----0-----------0-0-----------1------- 00110 15 | ---0------------------------------1-0-------0-1--- 01100 16 | ---------0-----------------0-------------------110 10100 17 | 1---------------------0-1---------------------10-- 10001 18 | 0----------------0-0------1----------------------- 00010 19 | -------------1-------0--------0---------------0-0- 10100 20 | --------------1------------------0-----1-0------0- 01011 21 | ---------------------00-----------00-------------- 01000 22 | -------------0-----1---------------1--11---------- 11001 23 | ---0-------------1--1------------------1--------1- 01110 24 | ----1------1--0-0--------------------------0------ 10110 25 | ---------------------------0-1--0--------------1-- 00100 26 | ----------------------------00-------0------1-0--- 10101 27 | 1-------------------------------------01--------1- 01000 28 | 1-------------------0---1---1-----1--------------- 11100 29 | ----0------0----0-----------------1--------------- 00100 30 | --0--0---------1----------0-------------0--------- 10111 31 | ----------------0----------------1----------1---0- 00101 32 | --------00-------------------1-1------------------ 11001 33 | ---------------1----------0---------------------0- 00001 34 | .e 35 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/backup/signature_exact.c: -------------------------------------------------------------------------------- 1 | #include "espresso.h" 2 | #include "signature.h" 3 | 4 | 5 | /* 6 | * signature_minimize_exact: 7 | * What does it do: forms and solves the covering table whose rows are 8 | * essential signature cubes (ESCubes) and whose columns are 9 | * union of essential signature sets (ESSet) 10 | * Input: 11 | * ESCubes: essential signature cubes 12 | * ESSet: union of essential signature sets 13 | * Output: 14 | * COVER: exact cover 15 | */ 16 | 17 | set_family_t * 18 | signature_minimize_exact(ESCubes,ESSet) 19 | set_family_t *ESCubes, *ESSet; 20 | { 21 | set *p; 22 | sm_matrix *table; 23 | sm_row *cover; 24 | sm_element *pe; 25 | set_family_t *COVER; 26 | int index; 27 | int *weights,heur,level; 28 | 29 | /* number ESCubes, ESSet */ 30 | foreachi_set(ESCubes,index,p){ 31 | PUTSIZE(p,index); 32 | } 33 | foreachi_set(ESSet,index,p){ 34 | PUTSIZE(p,index); 35 | } 36 | 37 | /* form the covering table */ 38 | table = signature_form_table(ESCubes, ESSet); 39 | 40 | /* solve the covering problem */ 41 | weights = NIL(int); heur = FALSE; level = 0; 42 | cover = sm_minimum_cover(table,weights,heur,level); 43 | 44 | /* form the cover */ 45 | COVER = sf_new(100, cube.size); 46 | sm_foreach_row_element(cover, pe) { 47 | COVER = sf_addset(COVER, GETSET(ESSet, pe->col_num)); 48 | } 49 | 50 | sm_free(table); 51 | sm_row_free(cover); 52 | 53 | return COVER; 54 | } 55 | 56 | sm_matrix * 57 | signature_form_table(ESCubes, ESSet) 58 | set_family_t *ESCubes, *ESSet; 59 | { 60 | sm_matrix *table; 61 | int row,column; 62 | set *c, *p; 63 | int col_deleted; 64 | 65 | table = sm_alloc(); 66 | 67 | col_deleted = 0; 68 | foreachi_set(ESSet,column,p){ 69 | if(column%1000 == 0){ 70 | col_deleted += sm_col_dominance(table,NULL); 71 | } 72 | foreachi_set(ESCubes,row,c){ 73 | if(setp_implies(c,p)){ 74 | sm_insert(table,row,column); 75 | } 76 | } 77 | } 78 | col_deleted += sm_col_dominance(table,NULL); 79 | 80 | return table; 81 | } 82 | -------------------------------------------------------------------------------- /pyeda/inter.py: -------------------------------------------------------------------------------- 1 | """ 2 | Interactive Use 3 | 4 | To prepare a terminal for interactive use: 5 | 6 | >>> from pyeda.inter import * 7 | """ 8 | 9 | 10 | # Disable "unused-import", since that's basically all this module is for. 11 | # pylint: disable=W0611 12 | 13 | 14 | from pyeda.boolalg.bdd import (BDDConstant, BDDNode, BDDVariable, 15 | BinaryDecisionDiagram, bdd2expr, bddvar, 16 | expr2bdd, ite, upoint2bddpoint) 17 | from pyeda.boolalg.bfarray import (bddones, bddvars, bddzeros, exprones, 18 | exprvars, exprzeros, farray, fcat, int2bdds, 19 | int2exprs, int2tts, ttones, ttvars, ttzeros, 20 | uint2bdds, uint2exprs, uint2tts) 21 | from pyeda.boolalg.boolfunc import (Function, Variable, iter_points, 22 | iter_terms, iter_upoints, num2point, 23 | num2term, num2upoint, point2term, 24 | point2upoint, vpoint2point) 25 | from pyeda.boolalg.expr import (ITE, AchillesHeel, And, ConjNormalForm, 26 | DimacsCNF, DisjNormalForm, Equal, Exists, 27 | Expression, ForAll, Implies, Majority, Mux, 28 | Nand, NHot, Nor, NormalForm, Not, OneHot, 29 | OneHot0, Or, Unequal, Xnor, Xor, ast2expr, 30 | expr, expr2dimacscnf, expr2dimacssat, exprvar, 31 | upoint2exprpoint) 32 | from pyeda.boolalg.minimization import espresso_exprs, espresso_tts 33 | from pyeda.boolalg.table import (TruthTable, TTConstant, TTVariable, 34 | expr2truthtable, truthtable, truthtable2expr, 35 | ttvar) 36 | from pyeda.parsing.boolexpr import parse as parse_expr 37 | from pyeda.parsing.dimacs import parse_cnf, parse_sat 38 | from pyeda.util import clog2, parity 39 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/backup/canonical.c: -------------------------------------------------------------------------------- 1 | // Filename: canonical.c 2 | // 3 | // Routines for finding the canonical cover of the incompletely specified 4 | // logic function. 5 | // 6 | // Routine: 7 | // set_family_t *find_canonical_cover(): 8 | // Finds canonical cover of the incompletely specified logic function 9 | // by iteratively calling ess_test_and_reduction for each cube in the 10 | // ON-set. 11 | // 12 | 13 | #include "espresso.h" 14 | #include "signature.h" 15 | 16 | // 17 | // find_canonical_cover 18 | // 19 | // Objective: find canonical cover of the essential signature cube 20 | // Input: 21 | // F: ONSET cover; 22 | // D: DC cover; 23 | // R: OFFSET cover; 24 | // Output: 25 | // Return canonical cover of the essential signature cube 26 | // 27 | 28 | set_family_t * 29 | find_canonical_cover(set_family_t *F1, set_family_t *D, set_family_t *R) 30 | { 31 | set_family_t *F; 32 | set_family_t *E, *ESC; 33 | set_family_t *COVER; 34 | set *last, *p, *s; 35 | set *c; 36 | int count = 0; 37 | int last_fcount = F1->count; 38 | set *d, **extended_dc; 39 | set *sigma_c; 40 | 41 | F = sf_save(F1); 42 | E = sf_new(D->count, cube.size); 43 | E->count = D->count; 44 | sf_copy(E, D); 45 | 46 | ESC = sf_new(F->count, cube.size); 47 | 48 | while (F->count) { 49 | c = GETSET(F, --F->count); 50 | RESET(c,NONESSEN); 51 | extended_dc = cube2list(E, F); 52 | d = reduce_cube(extended_dc, c); 53 | free_cubelist(extended_dc); 54 | if (setp_empty(d)) { 55 | set_free(d); 56 | continue; 57 | } 58 | c = get_sigma(R, d); 59 | COVER = etr_order(F, E, R, c, d); 60 | set_free(d); 61 | if (TESTP(c, NONESSEN)) { 62 | sf_append(F, COVER); 63 | } else { 64 | sf_free(COVER); 65 | sf_addset(E, c); 66 | sf_addset(ESC, c); 67 | } 68 | set_free(c); 69 | } 70 | sf_free(F); 71 | sf_free(E); 72 | 73 | return ESC; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /extension/boolexpr/test/test_product.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: test_product.cpp 3 | ** 4 | ** Test BoolExpr cross products. 5 | */ 6 | 7 | 8 | #include "boolexprtest.hpp" 9 | 10 | 11 | class BX_Product_Test: public BoolExpr_Test {}; 12 | 13 | 14 | TEST_F(BX_Product_Test, Product) 15 | { 16 | struct BoolExpr *A[] = {xs[0]}; 17 | struct BoolExpr *B[] = {xs[1], xs[2]}; 18 | struct BoolExpr *C[] = {xs[3], xs[4], xs[5]}; 19 | 20 | struct BX_Array *arrays[3]; 21 | 22 | arrays[0] = BX_Array_New(1, A); 23 | arrays[1] = BX_Array_New(2, B); 24 | arrays[2] = BX_Array_New(3, C); 25 | 26 | struct BX_Array *prod = BX_Product(BX_OP_OR, 3, arrays); 27 | 28 | EXPECT_EQ(prod->length, 1 * 2 * 3); 29 | 30 | for (int i = 0; i < prod->length; ++i) 31 | EXPECT_EQ(prod->items[i]->kind, BX_OP_OR); 32 | 33 | // [x0+x1+x3, x0+x2+x3, x0+x1+x4, x0+x2+x4, x0+x1+x5, x0+x2+x5] 34 | int p[6][3] = { 35 | {0, 1, 3}, {0, 2, 3}, {0, 1, 4}, 36 | {0, 2, 4}, {0, 1, 5}, {0, 2, 5} 37 | }; 38 | 39 | for (int i = 0; i < 6; ++i) { 40 | EXPECT_EQ(prod->items[i]->data.xs->items[1]->data.xs->items[1]->data.xs->items[1], &BX_Zero); 41 | EXPECT_EQ(prod->items[i]->data.xs->items[1]->data.xs->items[1]->data.xs->items[0], xs[p[i][0]]); 42 | EXPECT_EQ(prod->items[i]->data.xs->items[1]->data.xs->items[0], xs[p[i][1]]); 43 | EXPECT_EQ(prod->items[i]->data.xs->items[0], xs[p[i][2]]); 44 | } 45 | 46 | BX_Array_Del(prod); 47 | 48 | for (int i = 0; i < 3; ++i) 49 | BX_Array_Del(arrays[i]); 50 | } 51 | 52 | 53 | TEST_F(BX_Product_Test, Identity) 54 | { 55 | struct BX_Array **arrays; 56 | 57 | struct BX_Array *prod_and = BX_Product(BX_OP_AND, 0, arrays); 58 | 59 | EXPECT_EQ(prod_and->length, 1); 60 | EXPECT_EQ(prod_and->items[0], &BX_One); 61 | 62 | BX_Array_Del(prod_and); 63 | 64 | struct BX_Array *prod_or = BX_Product(BX_OP_OR, 0, arrays); 65 | 66 | EXPECT_EQ(prod_or->length, 1); 67 | EXPECT_EQ(prod_or->items[0], &BX_Zero); 68 | 69 | BX_Array_Del(prod_or); 70 | } 71 | 72 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/solution.c: -------------------------------------------------------------------------------- 1 | // Filename: solution.c 2 | 3 | #include "mincov_int.h" 4 | 5 | solution_t * 6 | solution_alloc(void) 7 | { 8 | solution_t *sol; 9 | 10 | sol = ALLOC(solution_t, 1); 11 | sol->cost = 0; 12 | sol->row = sm_row_alloc(); 13 | 14 | return sol; 15 | } 16 | 17 | void 18 | solution_free(solution_t *sol) 19 | { 20 | sm_row_free(sol->row); 21 | FREE(sol); 22 | } 23 | 24 | solution_t * 25 | solution_dup(solution_t *sol) 26 | { 27 | solution_t *new_sol; 28 | 29 | new_sol = ALLOC(solution_t, 1); 30 | new_sol->cost = sol->cost; 31 | new_sol->row = sm_row_dup(sol->row); 32 | 33 | return new_sol; 34 | } 35 | 36 | void 37 | solution_add(solution_t *sol, int *weight, int col) 38 | { 39 | sm_row_insert(sol->row, col); 40 | sol->cost += WEIGHT(weight, col); 41 | } 42 | 43 | void 44 | solution_accept(solution_t *sol, sm_matrix *A, int *weight, int col) 45 | { 46 | sm_element *p, *pnext; 47 | sm_col *pcol; 48 | 49 | solution_add(sol, weight, col); 50 | 51 | // delete rows covered by this column 52 | pcol = sm_get_col(A, col); 53 | for (p = pcol->first_row; p != 0; p = pnext) { 54 | pnext = p->next_row; // grab it before it disappears 55 | sm_delrow(A, p->row_num); 56 | } 57 | } 58 | 59 | void 60 | solution_reject(solution_t *sol, sm_matrix *A, int *weight, int col) 61 | { 62 | sm_delcol(A, col); 63 | } 64 | 65 | solution_t * 66 | solution_choose_best(solution_t *best1, solution_t *best2) 67 | { 68 | if (best1 != NIL(solution_t)) { 69 | if (best2 != NIL(solution_t)) { 70 | if (best1->cost <= best2->cost) { 71 | solution_free(best2); 72 | return best1; 73 | } 74 | else { 75 | solution_free(best1); 76 | return best2; 77 | } 78 | } 79 | else { 80 | return best1; 81 | } 82 | } 83 | else { 84 | if (best2 != NIL(solution_t)) { 85 | return best2; 86 | } else { 87 | return NIL(solution_t); 88 | } 89 | } 90 | } 91 | 92 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/backup/sigma.c: -------------------------------------------------------------------------------- 1 | /* Module: sigma.c 2 | * Purpose: 3 | * Contains routines for computing the signature cube of the given cube. 4 | * Routines: 5 | * set *get_sigma(): 6 | * Computes signature cube of the given cube d. 7 | * void set_not(): 8 | */ 9 | 10 | #include 11 | #include "espresso.h" 12 | #include "signature.h" 13 | 14 | // 15 | // get_sigma: 16 | // Objective: computes signature cube corresponding to the cube c 17 | // Input: 18 | // R: OFFSET cover; 19 | // c: ONSET cube; 20 | // Output: 21 | // signature cube 22 | // 23 | 24 | set * 25 | get_sigma(set_family_t *R, set *c) 26 | { 27 | set_family_t *BB; 28 | set *out_part_r, *s; 29 | set *r, *b; 30 | int i; 31 | int w, last; 32 | unsigned int x; 33 | 34 | out_part_r = set_new(cube.size); 35 | s = set_new(cube.size); 36 | 37 | BB = sf_new(R->count, cube.size); 38 | BB->count = R->count; 39 | /* BB = get_blocking_matrix(R,c); */ 40 | foreachi_set(R, i, r) { 41 | b = GETSET(BB, i); 42 | if ((last = cube.inword) != -1) { 43 | /* Check the partial word of binary variables */ 44 | x = r[last] & c[last]; 45 | x = ~(x | x >> 1) & cube.inmask; 46 | b[last] = r[last] & (x | x << 1); 47 | /* Check the full words of binary variables */ 48 | for(w = 1; w < last; w++) { 49 | x = r[w] & c[w]; 50 | x = ~(x | x >> 1) & DISJOINT; 51 | b[w] = r[w] & (x | x << 1); 52 | } 53 | } 54 | PUTLOOP(b,LOOP(r)); 55 | set_and(b,b,cube.binary_mask); 56 | set_and(out_part_r,cube.mv_mask,r); 57 | if (!setp_implies(out_part_r,c)) { 58 | set_or(b,b,out_part_r); 59 | } 60 | } 61 | set_free(out_part_r); 62 | BB = unate_compl(BB); 63 | 64 | set_copy(s,cube.emptyset); 65 | foreachi_set(BB, i, b) { 66 | set_or(s,s,b); 67 | } 68 | sf_free(BB); 69 | set_not(s); 70 | return s; 71 | } 72 | 73 | // set_not: flip 0 to 1 and 1 to 0 74 | 75 | void 76 | set_not(set *c) 77 | { 78 | set_diff(c,cube.fullset,c); 79 | } 80 | 81 | -------------------------------------------------------------------------------- /extension/boolexpr/test/boolexprtest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: boolexprtest.cpp 3 | ** 4 | ** Entry point for all unit tests. 5 | */ 6 | 7 | 8 | #include "boolexprtest.hpp" 9 | 10 | 11 | bool 12 | Similar(BoolExpr * const self, BoolExpr * const other) 13 | { 14 | if (self->kind != other->kind) 15 | return false; 16 | 17 | if (BX_IS_CONST(self)) { 18 | return true; 19 | } 20 | else if (BX_IS_LIT(self)) { 21 | return (self->data.lit.lits == other->data.lit.lits) && 22 | (self->data.lit.uniqid == other->data.lit.uniqid); 23 | } 24 | else { 25 | if (self->data.xs->length == other->data.xs->length) { 26 | for (size_t i = 0; i < self->data.xs->length; ++i) { 27 | if (!Similar(self->data.xs->items[i], 28 | other->data.xs->items[i])) 29 | return false; 30 | } 31 | return true; 32 | } 33 | else { 34 | return false; 35 | } 36 | } 37 | } 38 | 39 | 40 | void 41 | BoolExpr_Test::SetUp() 42 | { 43 | lits = BX_Vector_New(); 44 | 45 | // Initialize local literals 46 | for (int i = 0; i < N; ++i) { 47 | long uniqid = (long) (i + 1); 48 | xns[i] = BX_Literal(lits, -uniqid); 49 | xs[i] = BX_Literal(lits, uniqid); 50 | } 51 | 52 | // Initialize scratchpad operators 53 | for (int i = 0; i < N; ++i) 54 | ops[i] = (BoolExpr *) NULL; 55 | 56 | // Initialize expected operators 57 | for (int i = 0; i < N; ++i) 58 | exps[i] = (BoolExpr *) NULL; 59 | } 60 | 61 | 62 | void 63 | BoolExpr_Test::TearDown() 64 | { 65 | // Clear local literals 66 | for (int i = 0; i < N; ++i) { 67 | BX_DecRef(xns[i]); 68 | BX_DecRef(xs[i]); 69 | } 70 | BX_Vector_Del(lits); 71 | 72 | // Clear scratchpad operators 73 | for (int i = 0; i < N; ++i) { 74 | if (ops[i] != (BoolExpr *) NULL) 75 | BX_DecRef(ops[i]); 76 | } 77 | 78 | // Clear expected operators 79 | for (int i = 0; i < N; ++i) { 80 | if (exps[i] != (BoolExpr *) NULL) 81 | BX_DecRef(exps[i]); 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /doc/source/reference/boolalg/espresso.rst: -------------------------------------------------------------------------------- 1 | .. reference/boolalg/espresso.rst 2 | 3 | ********************************************************** 4 | :mod:`pyeda.boolalg.espresso` --- Espresso C Extension 5 | ********************************************************** 6 | 7 | Constants 8 | ========= 9 | 10 | .. data:: FTYPE 11 | 12 | .. data:: DTYPE 13 | 14 | .. data:: RTYPE 15 | 16 | Exceptions 17 | ========== 18 | 19 | .. exception:: espresso.Error 20 | 21 | An error happened inside Espresso. 22 | 23 | Interface Functions 24 | =================== 25 | 26 | .. function:: get_config() 27 | 28 | Return a dict of Espresso global configuration values. 29 | 30 | .. function:: set_config(single_expand=0, remove_essential=0, force_irredundant=0, unwrap_onset=0, recompute_onset=0, use_super_gasp=0, skip_make_sparse=0) 31 | 32 | Set Espresso global configuration values. 33 | 34 | .. function:: espresso(ninputs, noutputs, cover, intype=FTYPE|DTYPE) 35 | 36 | Return a logically equivalent, (near) minimal cost set of product-terms 37 | to represent the ON-set and optionally minterms that lie in the DC-set, 38 | without containing any minterms of the OFF-set. 39 | 40 | Parameters 41 | 42 | ninputs : posint 43 | Number of inputs in the implicant in-part vector. 44 | 45 | noutputs : posint 46 | Number of outputs in the implicant out-part vector. 47 | 48 | cover : iter(((int), (int))) 49 | The iterator over multi-output implicants. 50 | A multi-output implicant is a pair of row vectors of dimension 51 | *ninputs*, and *noutputs*, respectively. 52 | The input part contains integers in positional cube notation, 53 | and the output part contains entries in {0, 1, 2}. 54 | 55 | * '0' means 0 for R-type covers, otherwise has no meaning. 56 | * '1' means 1 for F-type covers, otherwise has no meaning. 57 | * '2' means \"don't care\" for D-type covers, otherwise has no meaning. 58 | 59 | intype : int 60 | A flag field that indicates the type of the input cover. 61 | F-type = 1, D-type = 2, R-type = 4 62 | 63 | Returns 64 | 65 | set of implicants in the same format as the input cover 66 | 67 | -------------------------------------------------------------------------------- /pyeda/util.py: -------------------------------------------------------------------------------- 1 | """ 2 | The :mod:`pyeda.util` module contains top-level utilities, 3 | such as fundamental functions and decorators. 4 | 5 | Interface Functions: 6 | 7 | * :func:`bit_on` --- Return the value of a number's bit position 8 | * :func:`clog2` --- Return the ceiling log base two of an integer 9 | * :func:`parity` --- Return the parity of an integer 10 | """ 11 | 12 | 13 | def bit_on(num: int, bit: int) -> int: 14 | """Return the value of a number's bit position. 15 | 16 | For example, since :math:`42 = 2^1 + 2^3 + 2^5`, 17 | this function will return 1 in bit positions 1, 3, 5: 18 | 19 | >>> [bit_on(42, i) for i in range(clog2(42))] 20 | [0, 1, 0, 1, 0, 1] 21 | """ 22 | return (num >> bit) & 1 23 | 24 | 25 | def clog2(num: int) -> int: 26 | r"""Return the ceiling log base two of an integer :math:`\ge 1`. 27 | 28 | This function tells you the minimum dimension of a Boolean space with at 29 | least N points. 30 | 31 | For example, here are the values of ``clog2(N)`` for :math:`1 \le N < 18`: 32 | 33 | >>> [clog2(n) for n in range(1, 18)] 34 | [0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5] 35 | 36 | This function is undefined for non-positive integers: 37 | 38 | >>> clog2(0) 39 | Traceback (most recent call last): 40 | ... 41 | ValueError: expected num >= 1 42 | """ 43 | if num < 1: 44 | raise ValueError("expected num >= 1") 45 | accum, shifter = 0, 1 46 | while num > shifter: 47 | shifter <<= 1 48 | accum += 1 49 | return accum 50 | 51 | 52 | def parity(num: int) -> int: 53 | """Return the parity of a non-negative integer. 54 | 55 | For example, here are the parities of the first ten integers: 56 | 57 | >>> [parity(n) for n in range(10)] 58 | [0, 1, 1, 0, 1, 0, 0, 1, 1, 0] 59 | 60 | This function is undefined for negative integers: 61 | 62 | >>> parity(-1) 63 | Traceback (most recent call last): 64 | ... 65 | ValueError: expected num >= 0 66 | """ 67 | if num < 0: 68 | raise ValueError("expected num >= 0") 69 | par = 0 70 | while num: 71 | par ^= (num & 1) 72 | num >>= 1 73 | return par 74 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/set.h: -------------------------------------------------------------------------------- 1 | // Filename: set.h 2 | 3 | #include 4 | 5 | bool set_andp(set *r, set *a, set *b); 6 | bool set_orp(set *r, set *a, set *b); 7 | bool setp_disjoint(set *a, set *b); 8 | bool setp_empty(set *a); 9 | bool setp_equal(set *a, set *b); 10 | bool setp_full(set *a, int size); 11 | bool setp_implies(set *a, set *b); 12 | int *sf_count(set_family_t *A); 13 | int *sf_count_restricted(set_family_t *A, set *r); 14 | int bit_index(unsigned int a); 15 | int set_dist(set *a, set *b); 16 | int set_ord(set *a); 17 | void set_adjcnt(set *a, int *count, int weight); 18 | 19 | set *set_and(set *r, set *a, set *b); 20 | set *set_clear(set *r, int size); 21 | set *set_copy(set *r, set *a); 22 | set *set_diff(set *r, set *a, set *b); 23 | set *set_fill(set *r, int size); 24 | set *set_merge(set *r, set *a, set *b, set *mask); 25 | set *set_or(set *r, set *a, set *b); 26 | set *set_xor(set *r, set *a, set *b); 27 | 28 | set *sf_and(set_family_t *A); 29 | set *sf_or(set_family_t *A); 30 | set_family_t *sf_active(set_family_t *A); 31 | set_family_t *sf_addcol(set_family_t *A, int firstcol, int n); 32 | set_family_t *sf_addset(set_family_t *A, set *s); 33 | set_family_t *sf_append(set_family_t *A, set_family_t *B); 34 | set_family_t *sf_bm_read(FILE *fp); 35 | set_family_t *sf_compress(set_family_t *A, set *c); 36 | set_family_t *sf_copy(set_family_t *R, set_family_t *A); 37 | set_family_t *sf_copy_col(set_family_t *dst, int dstcol, set_family_t *src, int srccol); 38 | set_family_t *sf_delc(set_family_t *A, int first, int last); 39 | set_family_t *sf_delcol(set_family_t *A, int firstcol, int n); 40 | set_family_t *sf_inactive(set_family_t *A); 41 | set_family_t *sf_join(set_family_t *A, set_family_t *B); 42 | set_family_t *sf_new(int num, int size); 43 | set_family_t *sf_permute(set_family_t *A, int *permute, int npermute); 44 | set_family_t *sf_read(FILE *fp); 45 | set_family_t *sf_save(set_family_t *A); 46 | set_family_t *sf_transpose(set_family_t *A); 47 | 48 | void set_write(FILE *fp, set *a); 49 | void sf_bm_print(set_family_t *A); 50 | void sf_cleanup(void); 51 | void sf_delset(set_family_t *A, int i); 52 | void sf_free(set_family_t *A); 53 | void sf_print(set_family_t *A); 54 | void sf_write(FILE *fp, set_family_t *A); 55 | 56 | int sf_equal(set_family_t *F1, set_family_t *F2); 57 | void print_cover(set_family_t *F, char *name); 58 | 59 | -------------------------------------------------------------------------------- /extension/boolexpr/vector.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: vector.c 3 | */ 4 | 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "boolexpr.h" 11 | 12 | 13 | /* Minimum capacity */ 14 | #define MIN_CAP 64 15 | 16 | /* Scale factor for resize */ 17 | #define SCALE_FACTOR 2.0 18 | 19 | 20 | struct BX_Vector * 21 | BX_Vector_New(void) 22 | { 23 | struct BX_Vector *vec; 24 | 25 | vec = malloc(sizeof(struct BX_Vector)); 26 | if (vec == NULL) 27 | return NULL; // LCOV_EXCL_LINE 28 | 29 | vec->length = 0; 30 | vec->capacity = MIN_CAP; 31 | vec->items = malloc(MIN_CAP * sizeof(struct BoolExpr *)); 32 | if (vec->items == NULL) { 33 | free(vec); // LCOV_EXCL_LINE 34 | return NULL; // LCOV_EXCL_LINE 35 | } 36 | 37 | /* Initialize items to NULL */ 38 | for (size_t i = 0; i < vec->capacity; ++i) 39 | vec->items[i] = (struct BoolExpr *) NULL; 40 | 41 | return vec; 42 | } 43 | 44 | 45 | void 46 | BX_Vector_Del(struct BX_Vector *vec) 47 | { 48 | for (size_t i = 0; i < vec->length; ++i) { 49 | if (vec->items[i] != (struct BoolExpr *) NULL) 50 | BX_DecRef(vec->items[i]); 51 | } 52 | free(vec->items); 53 | free(vec); 54 | } 55 | 56 | 57 | bool 58 | BX_Vector_Insert(struct BX_Vector *vec, size_t index, struct BoolExpr *ex) 59 | { 60 | /* Required length and capacity */ 61 | size_t req_len = index + 1; 62 | size_t req_cap = vec->capacity; 63 | 64 | /* Scale up until we have enough capacity */ 65 | while (req_cap < req_len) 66 | req_cap = (size_t) (SCALE_FACTOR * req_cap); 67 | 68 | if (req_cap > vec->capacity) { 69 | vec->items = realloc(vec->items, req_cap * sizeof(struct BoolExpr *)); 70 | if (vec->items == NULL) 71 | return false; // LCOV_EXCL_LINE 72 | 73 | /* Initialize new items to NULL */ 74 | for (size_t i = vec->capacity; i < req_cap; ++i) 75 | vec->items[i] = (struct BoolExpr *) NULL; 76 | 77 | vec->capacity = req_cap; 78 | } 79 | 80 | vec->items[index] = BX_IncRef(ex); 81 | if (req_len > vec->length) 82 | vec->length = req_len; 83 | 84 | return true; 85 | } 86 | 87 | 88 | bool 89 | BX_Vector_Append(struct BX_Vector *vec, struct BoolExpr *ex) 90 | { 91 | return BX_Vector_Insert(vec, vec->length, ex); 92 | } 93 | 94 | -------------------------------------------------------------------------------- /extension/boolexpr/test/test_bubble.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: test_bubble.cpp 3 | ** 4 | ** Test bubbling of NOT operators 5 | ** 6 | */ 7 | 8 | 9 | #include "boolexprtest.hpp" 10 | 11 | 12 | class BX_Bubble_Test: public BoolExpr_Test {}; 13 | 14 | 15 | TEST_F(BX_Bubble_Test, Atoms) 16 | { 17 | ops[0] = BX_PushDownNot(&BX_Zero); 18 | EXPECT_EQ(ops[0], &BX_Zero); 19 | 20 | ops[1] = BX_PushDownNot(&BX_One); 21 | EXPECT_EQ(ops[1], &BX_One); 22 | 23 | ops[2] = BX_PushDownNot(xns[0]); 24 | EXPECT_EQ(ops[2], xns[0]); 25 | 26 | ops[3] = BX_PushDownNot(xs[0]); 27 | EXPECT_EQ(ops[3], xs[0]); 28 | } 29 | 30 | 31 | TEST_F(BX_Bubble_Test, NothingToDo) 32 | { 33 | // OR/AND with no NOT operators 34 | ops[0] = BX_AndN(2, xs[0], xs[1]); 35 | ops[1] = BX_AndN(2, xs[2], xs[3]); 36 | ops[2] = BX_OrN(2, ops[0], ops[1]); 37 | ops[3] = BX_PushDownNot(ops[2]); 38 | EXPECT_EQ(ops[3], ops[2]); 39 | 40 | } 41 | 42 | 43 | TEST_F(BX_Bubble_Test, DeMorganL1) 44 | { 45 | ops[0] = BX_NorN(2, xs[0], xs[1]); 46 | ops[1] = BX_PushDownNot(ops[0]); 47 | exps[0] = BX_AndN(2, xns[0], xns[1]); 48 | EXPECT_TRUE(Similar(ops[1], exps[0])); 49 | 50 | ops[2] = BX_NandN(2, xs[0], xs[1]); 51 | ops[3] = BX_PushDownNot(ops[2]); 52 | exps[1] = BX_OrN(2, xns[0], xns[1]); 53 | EXPECT_TRUE(Similar(ops[3], exps[1])); 54 | } 55 | 56 | 57 | TEST_F(BX_Bubble_Test, DeMorganL2) 58 | { 59 | ops[0] = BX_AndN(2, xs[0], xs[1]); 60 | ops[1] = BX_AndN(2, xs[2], xs[3]); 61 | ops[2] = BX_OrN(2, ops[0], ops[1]); 62 | ops[3] = BX_AndN(2, xs[4], xs[5]); 63 | ops[4] = BX_AndN(2, xs[6], xs[7]); 64 | ops[5] = BX_OrN(2, ops[3], ops[4]); 65 | ops[6] = BX_AndN(2, ops[2], ops[5]); 66 | ops[7] = BX_Not(ops[6]); 67 | ops[8] = BX_PushDownNot(ops[7]); 68 | 69 | exps[0] = BX_OrN(2, xns[0], xns[1]); 70 | exps[1] = BX_OrN(2, xns[2], xns[3]); 71 | exps[2] = BX_AndN(2, exps[0], exps[1]); 72 | exps[3] = BX_OrN(2, xns[4], xns[5]); 73 | exps[4] = BX_OrN(2, xns[6], xns[7]); 74 | exps[5] = BX_AndN(2, exps[3], exps[4]); 75 | exps[6] = BX_OrN(2, exps[2], exps[5]); 76 | 77 | EXPECT_TRUE(Similar(ops[8], exps[6])); 78 | } 79 | 80 | 81 | TEST_F(BX_Bubble_Test, IfThenElseDuality) 82 | { 83 | ops[0] = BX_ITE(xs[0], xs[1], xs[2]); 84 | ops[1] = BX_Not(ops[0]); 85 | ops[2] = BX_PushDownNot(ops[1]); 86 | exps[0] = BX_ITE(xs[0], xns[1], xns[2]); 87 | EXPECT_TRUE(Similar(ops[2], exps[0])); 88 | } 89 | 90 | -------------------------------------------------------------------------------- /doc/source/overview.rst: -------------------------------------------------------------------------------- 1 | .. _overview: 2 | 3 | ************ 4 | Overview 5 | ************ 6 | 7 | What is Electronic Design Automation (EDA)? 8 | =========================================== 9 | 10 | The Intel 4004, the world's first commercially available microprocessor, 11 | was built from approximately 2300 transistors, 12 | and had a clock frequency of 740 kilohertz (thousands of cycles per second) 13 | [#f1]_ [#f2]_. 14 | A modern Intel microprocessor can contain over 1.5 billion transistors, 15 | and will typically have a clock frequency ranging from two to four gigahertz 16 | (billions of cycles per second). 17 | 18 | In 1971 it took less than one hundred people to manufacture the 4004. 19 | That is approximately 23 transistors per employee. 20 | If that ratio stayed the same between 1971 and 2012, 21 | Intel would need to employ about 65 *million* people just to 22 | produce the latest Core i7 processor. 23 | That is **one fifth** the entire population of the United States! 24 | 25 | Clearly, companies that design and manufacture integrated circuits have found 26 | ways to be more productive since then. 27 | 28 | Simply stated, 29 | electronic design automation (EDA) is the science of optimizing productivity in 30 | the design and manufacture of electronic components. 31 | 32 | Goals 33 | ===== 34 | 35 | After reading the previous section, EDA sounds like a vast field. 36 | The way we have defined it covers everything from controlling robotic arms in 37 | the fabrication plant to providing free coffee to keep interns busy. 38 | We need to narrow our focus a bit. 39 | 40 | PyEDA is primarily concerned with implementing the data structures and 41 | algorithms necessary for performing logic synthesis and verification. 42 | These tools form the theoretical foundation for the implementation of CAD tools 43 | for designing VLSI (Very Large Scale Integrated circuit). 44 | 45 | PyEDA is a hobby project, 46 | and is very unlikely to ever be a competitor to state-of-the-art EDA industry 47 | technology. 48 | It should be useful for academic exploration and experimentation. 49 | If you use PyEDA, please email the author with your success/failure stories. 50 | 51 | Free Software 52 | ============= 53 | 54 | PyEDA is free software; you can use it or redistribute it under the terms of 55 | the "two-clause" BSD License. 56 | 57 | Repository 58 | ========== 59 | 60 | View the PyEDA source code on 61 | `GitHub `_. 62 | 63 | .. [#f1] `Wikipedia: Intel 4004 `_ 64 | .. [#f2] `The Story of the Intel 4004 `_ 65 | 66 | -------------------------------------------------------------------------------- /pyeda/logic/addition.py: -------------------------------------------------------------------------------- 1 | """ 2 | Logic functions for addition 3 | 4 | Interface Functions: 5 | ripple_carry_add 6 | kogge_stone_add 7 | brent_kung_add 8 | """ 9 | 10 | 11 | # Disable 'invalid-name', b/c 'logic' package uses unconventional names 12 | # pylint: disable=C0103 13 | 14 | 15 | from math import floor, log 16 | 17 | from pyeda.boolalg.bfarray import farray 18 | from pyeda.util import clog2 19 | 20 | 21 | def ripple_carry_add(A, B, cin=0): 22 | """Return symbolic logic for an N-bit ripple carry adder.""" 23 | if len(A) != len(B): 24 | raise ValueError("expected A and B to be equal length") 25 | ss, cs = [], [] 26 | for i, a in enumerate(A): 27 | c = (cin if i == 0 else cs[i-1]) 28 | ss.append(a ^ B[i] ^ c) 29 | cs.append(a & B[i] | a & c | B[i] & c) 30 | return farray(ss), farray(cs) 31 | 32 | 33 | def kogge_stone_add(A, B, cin=0): 34 | """Return symbolic logic for an N-bit Kogge-Stone adder.""" 35 | if len(A) != len(B): 36 | raise ValueError("expected A and B to be equal length") 37 | N = len(A) 38 | # generate/propagate logic 39 | gs = [A[i] & B[i] for i in range(N)] 40 | ps = [A[i] ^ B[i] for i in range(N)] 41 | for i in range(clog2(N)): 42 | start = 1 << i 43 | for j in range(start, N): 44 | gs[j] = gs[j] | ps[j] & gs[j-start] 45 | ps[j] = ps[j] & ps[j-start] 46 | # sum logic 47 | ss = [A[0] ^ B[0] ^ cin] 48 | ss += [A[i] ^ B[i] ^ gs[i-1] for i in range(1, N)] 49 | return farray(ss), farray(gs) 50 | 51 | 52 | def brent_kung_add(A, B, cin=0): 53 | """Return symbolic logic for an N-bit Brent-Kung adder.""" 54 | if len(A) != len(B): 55 | raise ValueError("expected A and B to be equal length") 56 | N = len(A) 57 | # generate/propagate logic 58 | gs = [A[i] & B[i] for i in range(N)] 59 | ps = [A[i] ^ B[i] for i in range(N)] 60 | # carry tree 61 | for i in range(floor(log(N, 2))): 62 | step = 2**i 63 | for start in range(2**(i+1)-1, N, 2**(i+1)): 64 | gs[start] = gs[start] | ps[start] & gs[start-step] 65 | ps[start] = ps[start] & ps[start-step] 66 | # inverse carry tree 67 | for i in range(floor(log(N, 2))-2, -1, -1): 68 | start = 2**(i+1)-1 69 | step = 2**i 70 | while start + step < N: 71 | gs[start+step] = gs[start+step] | ps[start+step] & gs[start] 72 | ps[start+step] = ps[start+step] & ps[start] 73 | start += step 74 | # sum logic 75 | ss = [A[0] ^ B[0] ^ cin] 76 | ss += [A[i] ^ B[i] ^ gs[i-1] for i in range(1, N)] 77 | return farray(ss), farray(gs) 78 | -------------------------------------------------------------------------------- /pyeda/logic/test/test_addition.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test logic functions for addition 3 | """ 4 | 5 | 6 | import random 7 | 8 | import pytest 9 | 10 | from pyeda.boolalg.bfarray import exprvars, fcat, int2exprs, uint2exprs 11 | from pyeda.logic.addition import brent_kung_add as bka 12 | from pyeda.logic.addition import kogge_stone_add as ksa 13 | from pyeda.logic.addition import ripple_carry_add as rca 14 | 15 | NVECS = 100 16 | 17 | 18 | def uadd(S, A, B, aval, bval): 19 | N = len(A) 20 | R = S.vrestrict({A: uint2exprs(aval, N), B: uint2exprs(bval, N)}) 21 | return R.to_uint() 22 | 23 | 24 | def sadd(S, A, B, aval, bval): 25 | N = len(A) 26 | R = S.vrestrict({A: int2exprs(aval, N), B: int2exprs(bval, N)}) 27 | return R.to_int() 28 | 29 | 30 | def test_errors(): 31 | A = exprvars('A', 7) 32 | B = exprvars('B', 9) 33 | 34 | for adder in (rca, ksa, bka): 35 | with pytest.raises(ValueError): 36 | adder(A, B) 37 | 38 | 39 | def test_unsigned_add(): 40 | N = 9 41 | 42 | A = exprvars('A', N) 43 | B = exprvars('B', N) 44 | 45 | for adder in (rca, ksa, bka): 46 | S, C = adder(A, B) 47 | S = fcat(S, C[-1]) 48 | 49 | # 0 + 0 = 0 50 | assert uadd(S, A, B, 0, 0) == 0 51 | # 255 + 255 = 510 52 | assert uadd(S, A, B, 2**N-1, 2**N-1) == (2**(N+1)-2) 53 | # 255 + 1 = 256 54 | assert uadd(S, A, B, 2**N-1, 1) == 2**N 55 | 56 | # unsigned random vectors 57 | for _ in range(NVECS): 58 | ra = random.randint(0, 2**N-1) 59 | rb = random.randint(0, 2**N-1) 60 | assert uadd(S, A, B, ra, rb) == ra + rb 61 | 62 | 63 | def test_signed_add(): 64 | A = exprvars('A', 8) 65 | B = exprvars('B', 8) 66 | 67 | for adder in (rca, ksa, bka): 68 | S, C = adder(A, B) 69 | 70 | # 0 + 0 = 0 71 | assert sadd(S, A, B, 0, 0) == 0 72 | # -64 + -64 = -128 73 | assert sadd(S, A, B, -64, -64) == -128 74 | # -1 + 1 = 0 75 | assert sadd(S, A, B, -1, 1) == 0 76 | # -64 + 64 = 0 77 | assert sadd(S, A, B, -64, 64) == 0 78 | 79 | # signed random vectors 80 | for _ in range(NVECS): 81 | ra = random.randint(-2**6, 2**6-1) # -64..63 82 | rb = random.randint(-2**6, 2**6) # -64..64 83 | assert sadd(S, A, B, ra, rb) == ra + rb 84 | 85 | # 64 + 64, overflow 86 | R = C.vrestrict({A: int2exprs(64, 8), B: int2exprs(64, 8)}) 87 | assert R[7] != R[6] 88 | # -65 + -64, overflow 89 | R = C.vrestrict({A: int2exprs(-65, 8), B: int2exprs(-64, 8)}) 90 | assert R[7] != R[6] 91 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/cvrmisc.c: -------------------------------------------------------------------------------- 1 | // Filename: cvrmisc.c 2 | 3 | #include "espresso.h" 4 | 5 | // cost -- compute the cost of a cover 6 | void 7 | cover_cost(set_family_t *F, cost_t *cost) 8 | { 9 | set *p, *last; 10 | set **T; 11 | int var; 12 | 13 | // use the routine used by cofactor to decide splitting variables 14 | massive_count(T = cube1list(F)); 15 | free_cubelist(T); 16 | 17 | cost->cubes = F->count; 18 | cost->total = cost->in = cost->out = cost->mv = cost->primes = 0; 19 | 20 | // Count transistors (zeros) for each binary variable (inputs) 21 | for (var = 0; var < CUBE.num_binary_vars; var++) 22 | cost->in += CDATA.var_zeros[var]; 23 | 24 | // Count transistors for each mv variable based on sparse/dense 25 | for (var = CUBE.num_binary_vars; var < CUBE.num_vars - 1; var++) 26 | if (CUBE.sparse[var]) 27 | cost->mv += F->count * CUBE.part_size[var] - CDATA.var_zeros[var]; 28 | else 29 | cost->mv += CDATA.var_zeros[var]; 30 | 31 | // Count the transistors (ones) for the output variable 32 | if (CUBE.num_binary_vars != CUBE.num_vars) { 33 | var = CUBE.num_vars - 1; 34 | cost->out = F->count * CUBE.part_size[var] - CDATA.var_zeros[var]; 35 | } 36 | 37 | // Count the number of nonprime cubes 38 | foreach_set(F, last, p) 39 | cost->primes += TESTP(p, PRIME) != 0; 40 | 41 | // Count the total number of literals 42 | cost->total = cost->in + cost->out + cost->mv; 43 | } 44 | 45 | // fmt_cost -- return a string which reports the "cost" of a cover 46 | char * 47 | fmt_cost(cost_t *cost) 48 | { 49 | static char s[200]; 50 | 51 | if (CUBE.num_binary_vars == CUBE.num_vars - 1) 52 | sprintf(s, "c=%d(%d) in=%d out=%d tot=%d", 53 | cost->cubes, cost->cubes - cost->primes, cost->in, 54 | cost->out, cost->total); 55 | else 56 | sprintf(s, "c=%d(%d) in=%d mv=%d out=%d", 57 | cost->cubes, cost->cubes - cost->primes, cost->in, 58 | cost->mv, cost->out); 59 | return s; 60 | } 61 | 62 | char * 63 | print_cost(set_family_t *F) 64 | { 65 | cost_t cost; 66 | cover_cost(F, &cost); 67 | return fmt_cost(&cost); 68 | } 69 | 70 | // copy_cost -- copy a cost function from s to d 71 | void 72 | copy_cost(cost_t *s, cost_t *d) 73 | { 74 | d->cubes = s->cubes; 75 | d->in = s->in; 76 | d->out = s->out; 77 | d->mv = s->mv; 78 | d->total = s->total; 79 | d->primes = s->primes; 80 | } 81 | 82 | // fatal -- report fatal error message and take a dive 83 | void 84 | fatal(char *s) 85 | { 86 | fprintf(stderr, "espresso: %s\n", s); 87 | exit(1); 88 | } 89 | 90 | -------------------------------------------------------------------------------- /pyeda/parsing/test/test_dimacs.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test DIMACS load/dump methods 3 | """ 4 | 5 | 6 | import pytest 7 | 8 | from pyeda.parsing.dimacs import Error, parse_cnf, parse_sat 9 | 10 | 11 | def test_cnf_errors(): 12 | # lexical error 13 | with pytest.raises(Error): 14 | parse_cnf("#a") 15 | # unexpected token 16 | with pytest.raises(Error): 17 | parse_cnf("p cnf cnf 0 0\n") 18 | with pytest.raises(Error): 19 | parse_cnf("p cnf 1 1\n1 x 0") 20 | # formula has fewer clauses than specified 21 | with pytest.raises(Error): 22 | parse_cnf("p cnf 0 1\n") 23 | # formula has more clauses than specified 24 | with pytest.raises(Error): 25 | parse_cnf("p cnf 0 0\n0") 26 | # formula literal too large 27 | with pytest.raises(Error): 28 | parse_cnf("p cnf 0 1\n1 0") 29 | with pytest.raises(Error): 30 | parse_cnf("p cnf 0 1\n-1 0") 31 | # incomplete clause 32 | with pytest.raises(Error): 33 | parse_cnf("p cnf 1 1\n1") 34 | 35 | 36 | def test_parse_cnf(): 37 | # Empty formula corner cases 38 | assert parse_cnf("p cnf 0 0\n") == ("and", ) 39 | assert parse_cnf("p cnf 1 0\n") == ("and", ) 40 | 41 | # Empty clause corner cases 42 | assert parse_cnf("p cnf 0 1\n0") == ("and", ("or", ),) 43 | assert parse_cnf("p cnf 1 2\n0 0") == ("and", ("or", ),("or", )) 44 | 45 | assert parse_cnf("p cnf 2 2\n-1 2 0 1 -2 0") == ("and", ("or", ("not", ("var", ("x", ), (1, ))), ("var", ("x", ), (2, ))), ("or", ("var", ("x", ), (1, )), ("not", ("var", ("x", ), (2, ))))) 46 | 47 | 48 | #def test_sat_errors(): 49 | # assert_raises(Error, parse_sat, "#a") 50 | # assert_raises(Error, parse_sat, "p sat 0\n") 51 | # assert_raises(Error, parse_sat, "p sat 2\n0") 52 | # assert_raises(Error, parse_sat, "p sat 2\n3") 53 | # assert_raises(Error, parse_sat, "p sat 2\n-3") 54 | # assert_raises(Error, parse_sat, "p sat 2\n-(0)") 55 | # assert_raises(Error, parse_sat, "p sat 2\n-(3)") 56 | 57 | 58 | def test_parse_sat(): 59 | assert parse_sat("p sat 1\n(-1)") == ("not", ("var", ("x", ), (1, ))) 60 | assert parse_sat("p sat 2\n-(+(*(-1 2) *(1 -2)))") == ("not", ("or", ("and", ("not", ("var", ("x", ), (1, ))), ("var", ("x", ), (2, ))), ("and", ("var", ("x", ), (1, )), ("not", ("var", ("x", ), (2, )))))) 61 | assert parse_sat("p satx 2\nxor(-1 2)") == ("xor", ("not", ("var", ("x", ), (1, ))), ("var", ("x", ), (2, ))) 62 | assert parse_sat("p sate 2\n=(-1 2)") == ("equal", ("not", ("var", ("x", ), (1, ))), ("var", ("x", ), (2, ))) 63 | assert parse_sat("p satex 2\n+(xor(-1 2) =(1 -2))") == ("or", ("xor", ("not", ("var", ("x", ), (1, ))), ("var", ("x", ), (2, ))), ("equal", ("var", ("x", ), (1, )), ("not", ("var", ("x", ), (2, ))))) 64 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/backup/equiv.c: -------------------------------------------------------------------------------- 1 | // Filename: equiv.c 2 | 3 | #include "espresso.h" 4 | 5 | void find_equiv_outputs(PLA_t *PLA) 6 | { 7 | int i, j, ipart, jpart, some_equiv; 8 | set_family_t **R, **F; 9 | 10 | some_equiv = FALSE; 11 | 12 | makeup_labels(PLA); 13 | 14 | F = ALLOC(set_family_t *, cube.part_size[cube.output]); 15 | R = ALLOC(set_family_t *, cube.part_size[cube.output]); 16 | 17 | for (i = 0; i < cube.part_size[cube.output]; i++) { 18 | ipart = cube.first_part[cube.output] + i; 19 | R[i] = cof_output(PLA->R, ipart); 20 | F[i] = complement(cube1list(R[i])); 21 | } 22 | 23 | for (i = 0; i < cube.part_size[cube.output]-1; i++) { 24 | for (j = i+1; j < cube.part_size[cube.output]; j++) { 25 | ipart = cube.first_part[cube.output] + i; 26 | jpart = cube.first_part[cube.output] + j; 27 | 28 | if (check_equiv(F[i], F[j])) { 29 | printf("# Outputs %d and %d (%s and %s) are equivalent\n", 30 | i, j, PLA->label[ipart], PLA->label[jpart]); 31 | some_equiv = TRUE; 32 | } else if (check_equiv(F[i], R[j])) { 33 | printf("# Outputs %d and NOT %d (%s and %s) are equivalent\n", 34 | i, j, PLA->label[ipart], PLA->label[jpart]); 35 | some_equiv = TRUE; 36 | } else if (check_equiv(R[i], F[j])) { 37 | printf("# Outputs NOT %d and %d (%s and %s) are equivalent\n", 38 | i, j, PLA->label[ipart], PLA->label[jpart]); 39 | some_equiv = TRUE; 40 | } else if (check_equiv(R[i], R[j])) { 41 | printf("# Outputs NOT %d and NOT %d (%s and %s) are equivalent\n", 42 | i, j, PLA->label[ipart], PLA->label[jpart]); 43 | some_equiv = TRUE; 44 | } 45 | } 46 | } 47 | 48 | if (! some_equiv) { 49 | printf("# No outputs are equivalent\n"); 50 | } 51 | 52 | for (i = 0; i < cube.part_size[cube.output]; i++) { 53 | sf_free(F[i]); 54 | sf_free(R[i]); 55 | } 56 | FREE(F); 57 | FREE(R); 58 | } 59 | 60 | int 61 | check_equiv(set_family_t *f1, set_family_t *f2) 62 | { 63 | set **f1list, **f2list; 64 | set *p, *last; 65 | 66 | f1list = cube1list(f1); 67 | foreach_set(f2, last, p) { 68 | if (! cube_is_covered(f1list, p)) { 69 | return FALSE; 70 | } 71 | } 72 | free_cubelist(f1list); 73 | 74 | f2list = cube1list(f2); 75 | foreach_set(f1, last, p) { 76 | if (! cube_is_covered(f2list, p)) { 77 | return FALSE; 78 | } 79 | } 80 | free_cubelist(f2list); 81 | 82 | return TRUE; 83 | } 84 | 85 | -------------------------------------------------------------------------------- /pyeda/parsing/test/test_boolexpr.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test Boolean expression parsing 3 | """ 4 | 5 | 6 | import pytest 7 | 8 | from pyeda.boolalg.expr import (ITE, AchillesHeel, And, Equal, Implies, 9 | Majority, Nand, Nor, Not, OneHot, OneHot0, Or, 10 | Unequal, Xnor, Xor, expr, exprvar) 11 | from pyeda.parsing.boolexpr import Error 12 | 13 | 14 | def test_expr_error(): 15 | # lexical error 16 | with pytest.raises(Error): 17 | expr("#a") 18 | # incomplete expression 19 | with pytest.raises(Error): 20 | expr("a &") 21 | # unexpected token 22 | with pytest.raises(Error): 23 | expr("a ,") 24 | with pytest.raises(Error): 25 | expr("a a") 26 | with pytest.raises(Error): 27 | expr("a ? b ,") 28 | with pytest.raises(Error): 29 | expr("a | 42") 30 | 31 | 32 | def test_basic(): 33 | a, b, c, d, p, q, s = map(exprvar, "abcdpqs") 34 | assert expr("a & ~b | b & ~c").equivalent(a & ~b | b & ~c) 35 | assert expr("p => q").equivalent(~p | q) 36 | assert expr("a <=> b").equivalent(~a & ~b | a & b) 37 | assert expr("s ? a : b").equivalent(s & a | ~s & b) 38 | assert expr("Not(a)").equivalent(Not(a)) 39 | assert expr("Or(a, b, c)").equivalent(Or(a, b, c)) 40 | assert expr("And(a, b, c)").equivalent(And(a, b, c)) 41 | assert expr("Xor(a, b, c)").equivalent(Xor(a, b, c)) 42 | assert expr("Xnor(a, b, c)").equivalent(Xnor(a, b, c)) 43 | assert expr("Equal(a, b, c)").equivalent(Equal(a, b, c)) 44 | assert expr("Unequal(a, b, c)").equivalent(Unequal(a, b, c)) 45 | assert expr("Implies(p, q)").equivalent(Implies(p, q)) 46 | assert expr("ITE(s, a, b)").equivalent(ITE(s, a, b)) 47 | assert expr("Nor(a, b, c)").equivalent(Nor(a, b, c)) 48 | assert expr("Nand(a, b, c)").equivalent(Nand(a, b, c)) 49 | assert expr("OneHot0(a, b, c)").equivalent(OneHot0(a, b, c)) 50 | assert expr("OneHot(a, b, c)").equivalent(OneHot(a, b, c)) 51 | assert expr("Majority(a, b, c)").equivalent(Majority(a, b, c)) 52 | assert expr("AchillesHeel(a, b, c, d)").equivalent(AchillesHeel(a, b, c, d)) 53 | 54 | 55 | def test_misc(): 56 | a, b, c = map(exprvar, "abc") 57 | assert expr("a & b & c").equivalent(a & b & c) 58 | assert expr("a ^ b ^ c").equivalent(a ^ b ^ c) 59 | assert expr("a | b | c").equivalent(a | b | c) 60 | assert expr("a & (b | c)").equivalent(a & (b | c)) 61 | assert expr("a | (b & c)").equivalent(a | b & c) 62 | assert expr("Or()").is_zero() 63 | 64 | a_0 = exprvar("a", 0) 65 | b_a = exprvar(("a", "b")) 66 | a_0_1 = exprvar("a", (0, 1)) 67 | b_a_0_1 = exprvar(("a", "b"), (0, 1)) 68 | assert expr("a[0] | b.a | a[0,1] | b.a[0,1]").equivalent(a_0 | b_a | a_0_1 | b_a_0_1) 69 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_100x5x50_20%_4.pla.out: -------------------------------------------------------------------------------- 1 | .i 100 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 x50 x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 x61 x62 x63 x64 x65 x66 x67 x68 x69 x70 x71 x72 x73 x74 x75 x76 x77 x78 x79 x80 x81 x82 x83 x84 x85 x86 x87 x88 x89 x90 x91 x92 x93 x94 x95 x96 x97 x98 x99 4 | .ob y0 y1 y2 y3 y4 5 | .p 21 6 | --------------------------------------------------0-----0-----------------0--0--------0-----1------- 00110 7 | --------1---------0----------------0-------1------0-----------------------------------------------0- 11000 8 | -----------------------------1------------------------1----------0--------------0-----0------1------ 01110 9 | -----------------------------------------------------------------------------------1-------1-000--0- 11010 10 | --------0-------------------------------------0---------------0--------------------1------------1--- 10000 11 | ----1-----------------0------------------------------------1-----0-----------------------------1---- 00110 12 | --------------------------------------------------------------------0------01-----------1---1------- 10010 13 | --------------------------------0-----1-------------1--------------1---------------------1---------- 01101 14 | -----0-----1----------0----------------------------------------------1------------------------------ 01000 15 | ------------------------------------------1--00------------------1--------------1------------------- 01101 16 | --------------1------------------------------0---------------------------------------------1------0- 00001 17 | ---------------------------------1---------------------------------------------------1--1-------1--- 01000 18 | ------------------------------------------------------------------------------1-0------1---0-------- 00011 19 | -----------------------0-------1--------------------1------------------------1---------------------- 10100 20 | -----------------------------------1--------1---------------------0----------1---------------------- 10001 21 | -----------------------1-----------------------------------------1-------------------1---------0---- 01001 22 | -----------------------1--------------------1---------------------0----------1---------------------- 10001 23 | --------------------1----1----------0--------------1------------------------------------------------ 10011 24 | --------------------1---1---------------------0-1---------------------------0----------------------- 11111 25 | ------------1--------------------1------------------------------------------------------------1----- 00100 26 | -----------------------0--------01----------------------------------------------------------0------- 11100 27 | .e 28 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_100x5x50_20%_8.pla.out: -------------------------------------------------------------------------------- 1 | .i 100 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 x50 x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 x61 x62 x63 x64 x65 x66 x67 x68 x69 x70 x71 x72 x73 x74 x75 x76 x77 x78 x79 x80 x81 x82 x83 x84 x85 x86 x87 x88 x89 x90 x91 x92 x93 x94 x95 x96 x97 x98 x99 4 | .ob y0 y1 y2 y3 y4 5 | .p 21 6 | ------------------------------1---------------------------------------------------------1-1-------11 00100 7 | --------------------------------------------------------------1--------------1----------1-------0--- 01001 8 | ----------------------------------------------------------------0-------------------------0-----0-01 10100 9 | 0-------------------------------------------------------------1----------------0-0-------0---------- 01100 10 | --------------------------------0-----------1------------------------------------0----------1---0--- 01010 11 | ---------------------------------------------------------1-----------1-1-----------0---------------- 00011 12 | ----------------------------------1------------------------0----------------------0----------------1 00111 13 | ---------------------------------------------------1--------------------0-0-1-----------------1----- 11101 14 | ------------------------------------------------------------------------------0--1--------1--------- 00010 15 | ------------------------------------0----0---------------0---1-------------------------------------- 00010 16 | --------------------------------------------1--0-11----------------1-------------------------------- 01000 17 | ------------------------0------------------1-----------0------------------1---0--------------------- 01110 18 | -----------------------------------1--------------0---------1--------1----------------------------1- 11111 19 | ------------------------1------------------1-----------0---1--------------------1------------1------ 11011 20 | --------------------------1-----0--------1----------------------0----------------------------------- 01000 21 | --------------1-----------------------------------------------------1------------1------------00---- 00101 22 | ------------------------1--0----------------------------------------------------------------1------- 10000 23 | ---------------------------------------------------1------------0---------------------------1----0-- 00100 24 | -------------------------------------0------------------------------1------------------10----------- 10100 25 | ----------0---------------------1------------------------0-1--------------------------------------1- 10001 26 | --------------------------------------1-----1-----1-------------0----------------------------------- 00011 27 | .e 28 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/dominate.c: -------------------------------------------------------------------------------- 1 | // Filename: dominate.c 2 | 3 | #include "mincov_int.h" 4 | 5 | int 6 | sm_row_dominance(sm_matrix *A) 7 | { 8 | sm_row *prow, *prow1; 9 | sm_col *pcol, *least_col; 10 | sm_element *p, *pnext; 11 | int rowcnt; 12 | 13 | rowcnt = A->nrows; 14 | 15 | // Check each row against all other rows 16 | for (prow = A->first_row; prow != 0; prow = prow->next_row) { 17 | 18 | // Among all columns with a 1 in this row, choose smallest 19 | least_col = sm_get_col(A, prow->first_col->col_num); 20 | for (p = prow->first_col->next_col; p != 0; p = p->next_col) { 21 | pcol = sm_get_col(A, p->col_num); 22 | if (pcol->length < least_col->length) { 23 | least_col = pcol; 24 | } 25 | } 26 | 27 | // Only check for containment against rows in this column 28 | for (p = least_col->first_row; p != 0; p = pnext) { 29 | pnext = p->next_row; 30 | prow1 = sm_get_row(A, p->row_num); 31 | if ((prow1->length > prow->length) || 32 | (prow1->length == prow->length && prow1->row_num > prow->row_num)) { 33 | if (sm_row_contains(prow, prow1)) { 34 | sm_delrow(A, prow1->row_num); 35 | } 36 | } 37 | } 38 | } 39 | 40 | return rowcnt - A->nrows; 41 | } 42 | 43 | int 44 | sm_col_dominance(sm_matrix *A, int *weight) 45 | { 46 | sm_row *prow; 47 | sm_col *pcol, *pcol1; 48 | sm_element *p; 49 | sm_row *least_row; 50 | sm_col *next_col; 51 | int colcnt; 52 | 53 | colcnt = A->ncols; 54 | 55 | // Check each column against all other columns 56 | for (pcol = A->first_col; pcol != 0; pcol = next_col) { 57 | next_col = pcol->next_col; 58 | 59 | // Check all rows to find the one with fewest elements 60 | least_row = sm_get_row(A, pcol->first_row->row_num); 61 | for (p = pcol->first_row->next_row; p != 0; p = p->next_row) { 62 | prow = sm_get_row(A, p->row_num); 63 | if (prow->length < least_row->length) { 64 | least_row = prow; 65 | } 66 | } 67 | 68 | // Only check for containment against columns in this row 69 | for (p = least_row->first_col; p != 0; p = p->next_col) { 70 | pcol1 = sm_get_col(A, p->col_num); 71 | if (weight != 0 && weight[pcol1->col_num] > weight[pcol->col_num]) 72 | continue; 73 | if ((pcol1->length > pcol->length) || 74 | (pcol1->length == pcol->length && pcol1->col_num > pcol->col_num)) { 75 | if (sm_col_contains(pcol, pcol1)) { 76 | sm_delcol(A, pcol->col_num); 77 | break; 78 | } 79 | } 80 | } 81 | } 82 | 83 | return colcnt - A->ncols; 84 | } 85 | 86 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_100x5x50_20%_7.pla.out: -------------------------------------------------------------------------------- 1 | .i 100 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 x50 x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 x61 x62 x63 x64 x65 x66 x67 x68 x69 x70 x71 x72 x73 x74 x75 x76 x77 x78 x79 x80 x81 x82 x83 x84 x85 x86 x87 x88 x89 x90 x91 x92 x93 x94 x95 x96 x97 x98 x99 4 | .ob y0 y1 y2 y3 y4 5 | .p 22 6 | ----------------------------------------------------------1-----------------0-0--------------------1 00010 7 | ------------------------------------------------------------------------0----1------------1--0-1-1-- 10100 8 | ------------------------------------------------0---------------------------0----------1-------0---- 00001 9 | -----------------------------------1-------------1-------------------------1-0---------0-------1---- 01101 10 | --------------1--------------------------------------------------1---0----------1---1--------------- 10010 11 | -----------------------------------------------1---------------------------1-------------1--1------- 10100 12 | ----1------------------------------------------------0-----------1----------------------------0----0 00110 13 | -------------------------------------------------------1------1--------------------------0----0----- 10000 14 | ----------------------0--------1-----------------------0------------1-------------------1----------- 01001 15 | --------------------------------------------------------0-----------0---------------------1--------- 10000 16 | ----------------------------------------------------1-0--1--------------------0-----0-----------0--- 11000 17 | ------------------------------------------------------------0-----------------1--------------------1 00100 18 | -------------------------0-------1--------------------------------------------0--------------------1 11011 19 | ------------------------01---------------------0----------------------------------------1--------1-0 01010 20 | -1-------------0--1-------------------------0-------------------------------------------0----------- 11010 21 | --------1------------------------1-------------------------1----0----------------------------------- 10010 22 | ----1-----------------------1----------------------------------0---------------------------1--1----- 00010 23 | -----------------------------------------1-----------0----------1---------------0------------------- 00101 24 | -----0-----------------0--------------------------------1----0-------------------------------------- 01100 25 | ---------------0-------------------------------------------1---------0----0-1--------0-------------- 11100 26 | ----------------------1-----0----------------------------------------------0---------------------1-- 00001 27 | -----1----------------------------------------------------------------1-----1--------------1-------- 01000 28 | .e 29 | -------------------------------------------------------------------------------- /pyeda/logic/sudoku.py: -------------------------------------------------------------------------------- 1 | """ 2 | Logic functions for Sudoku 3 | """ 4 | 5 | 6 | # Disable 'invalid-name', b/c 'logic' package uses unconventional names 7 | # pylint: disable=C0103 8 | 9 | 10 | from pyeda.boolalg.bfarray import exprvars 11 | from pyeda.boolalg.expr import And, OneHot, expr2dimacscnf 12 | 13 | DIGITS = "123456789" 14 | 15 | 16 | class SudokuSolver: 17 | """Logical constraints for 3x3 Sudoku""" 18 | def __init__(self): 19 | self.X = exprvars("x", (1, 10), (1, 10), (1, 10)) 20 | 21 | V = And(*[And(*[OneHot(*[self.X[r, c, v] for v in range(1, 10)]) 22 | for c in range(1, 10)]) 23 | for r in range(1, 10)]) 24 | R = And(*[And(*[OneHot(*[self.X[r, c, v] for c in range(1, 10)]) 25 | for v in range(1, 10)]) 26 | for r in range(1, 10)]) 27 | C = And(*[And(*[OneHot(*[self.X[r, c, v] for r in range(1, 10)]) 28 | for v in range(1, 10)]) 29 | for c in range(1, 10)]) 30 | B = And(*[And(*[OneHot(*[self.X[3*br+r, 3*bc+c, v] 31 | for r in range(1, 4) 32 | for c in range(1, 4)]) 33 | for v in range(1, 10)]) 34 | for br in range(3) for bc in range(3)]) 35 | 36 | self.litmap, self.S = expr2dimacscnf(And(V, R, C, B)) 37 | 38 | def solve(self, grid): 39 | """Return a solution point for a Sudoku grid.""" 40 | soln = self.S.satisfy_one(assumptions=self._parse_grid(grid)) 41 | return self.S.soln2point(soln, self.litmap) 42 | 43 | def display_solve(self, grid): 44 | """Return a solution point for a Sudoku grid as a string.""" 45 | return self._soln2str(self.solve(grid)) 46 | 47 | def _parse_grid(self, grid): 48 | """Return the input constraints for a Sudoku grid.""" 49 | chars = [c for c in grid if c in DIGITS or c in "0."] 50 | if len(chars) != 9**2: 51 | raise ValueError("expected 9x9 grid") 52 | return [self.litmap[self.X[i // 9 + 1, i % 9 + 1, int(c)]] 53 | for i, c in enumerate(chars) if c in DIGITS] 54 | 55 | def _soln2str(self, soln, fancy=False): 56 | """Convert a Sudoku solution point to a string.""" 57 | chars = [] 58 | for r in range(1, 10): 59 | for c in range(1, 10): 60 | if fancy and c in (4, 7): 61 | chars.append("|") 62 | chars.append(self._get_val(soln, r, c)) 63 | if fancy and r != 9: 64 | chars.append("\n") 65 | if r in (3, 6): 66 | chars.append("---+---+---\n") 67 | return "".join(chars) 68 | 69 | def _get_val(self, soln, r, c): 70 | """Return the string value for a solution coordinate.""" 71 | for v in range(1, 10): 72 | if soln[self.X[r, c, v]]: 73 | return DIGITS[v-1] 74 | return "X" 75 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/globals.c: -------------------------------------------------------------------------------- 1 | #include "espresso.h" 2 | 3 | // 4 | // Global Variable Declarations 5 | // 6 | 7 | unsigned int debug; // debug parameter 8 | bool verbose_debug; // -v: whether to print a lot 9 | 10 | bool echo_comments; // turned off by -eat option 11 | bool echo_unknown_commands; // always true ?? 12 | bool force_irredundant; // -nirr command line option 13 | bool skip_make_sparse; 14 | bool kiss; // -kiss command line option 15 | bool pos; // -pos command line option 16 | bool print_solution; // -x command line option 17 | bool recompute_onset; // -onset command line option 18 | bool remove_essential; // -ness command line option 19 | bool single_expand; // -fast command line option 20 | bool unwrap_onset; // -nunwrap command line option 21 | bool use_random_order; // -random command line option 22 | bool use_super_gasp; // -strong command line option 23 | char *filename; // filename PLA was read from 24 | 25 | struct pla_types_struct pla_types[] = { 26 | "-f", F_type, 27 | "-r", R_type, 28 | "-d", D_type, 29 | "-fd", FD_type, 30 | "-fr", FR_type, 31 | "-dr", DR_type, 32 | "-fdr", FDR_type, 33 | "-fc", F_type | CONSTRAINTS_type, 34 | "-rc", R_type | CONSTRAINTS_type, 35 | "-dc", D_type | CONSTRAINTS_type, 36 | "-fdc", FD_type | CONSTRAINTS_type, 37 | "-frc", FR_type | CONSTRAINTS_type, 38 | "-drc", DR_type | CONSTRAINTS_type, 39 | "-fdrc", FDR_type | CONSTRAINTS_type, 40 | "-pleasure", PLEASURE_type, 41 | "-eqn", EQNTOTT_type, 42 | "-eqntott", EQNTOTT_type, 43 | "-kiss", KISS_type, 44 | "-cons", CONSTRAINTS_type, 45 | "-scons", SYMBOLIC_CONSTRAINTS_type, 46 | 0, 0 47 | }; 48 | 49 | struct cube_struct CUBE; 50 | struct cdata_struct CDATA; 51 | 52 | int bit_count[256] = { 53 | 0, 1, 1, 2, 1, 2, 2, 3, 54 | 1, 2, 2, 3, 2, 3, 3, 4, 55 | 1, 2, 2, 3, 2, 3, 3, 4, 56 | 2, 3, 3, 4, 3, 4, 4, 5, 57 | 1, 2, 2, 3, 2, 3, 3, 4, 58 | 2, 3, 3, 4, 3, 4, 4, 5, 59 | 2, 3, 3, 4, 3, 4, 4, 5, 60 | 3, 4, 4, 5, 4, 5, 5, 6, 61 | 62 | 1, 2, 2, 3, 2, 3, 3, 4, 63 | 2, 3, 3, 4, 3, 4, 4, 5, 64 | 2, 3, 3, 4, 3, 4, 4, 5, 65 | 3, 4, 4, 5, 4, 5, 5, 6, 66 | 2, 3, 3, 4, 3, 4, 4, 5, 67 | 3, 4, 4, 5, 4, 5, 5, 6, 68 | 3, 4, 4, 5, 4, 5, 5, 6, 69 | 4, 5, 5, 6, 5, 6, 6, 7, 70 | 71 | 1, 2, 2, 3, 2, 3, 3, 4, 72 | 2, 3, 3, 4, 3, 4, 4, 5, 73 | 2, 3, 3, 4, 3, 4, 4, 5, 74 | 3, 4, 4, 5, 4, 5, 5, 6, 75 | 2, 3, 3, 4, 3, 4, 4, 5, 76 | 3, 4, 4, 5, 4, 5, 5, 6, 77 | 3, 4, 4, 5, 4, 5, 5, 6, 78 | 4, 5, 5, 6, 5, 6, 6, 7, 79 | 80 | 2, 3, 3, 4, 3, 4, 4, 5, 81 | 3, 4, 4, 5, 4, 5, 5, 6, 82 | 3, 4, 4, 5, 4, 5, 5, 6, 83 | 4, 5, 5, 6, 5, 6, 6, 7, 84 | 3, 4, 4, 5, 4, 5, 5, 6, 85 | 4, 5, 5, 6, 5, 6, 6, 7, 86 | 4, 5, 5, 6, 5, 6, 6, 7, 87 | 5, 6, 6, 7, 6, 7, 7, 8 88 | }; 89 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_100x5x50_20%_5.pla.out: -------------------------------------------------------------------------------- 1 | .i 100 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 x50 x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 x61 x62 x63 x64 x65 x66 x67 x68 x69 x70 x71 x72 x73 x74 x75 x76 x77 x78 x79 x80 x81 x82 x83 x84 x85 x86 x87 x88 x89 x90 x91 x92 x93 x94 x95 x96 x97 x98 x99 4 | .ob y0 y1 y2 y3 y4 5 | .p 23 6 | -----------------------------------0--------1----0--1----------0------------------------0----------- 10111 7 | -----------------------------------------------------------------0-----------------0-------1--11---- 00110 8 | -----------0--1--------------------------------------0-------------------------------------0-----0-- 10010 9 | ------------------------------------------1------------------1----------------0-0---0--------------- 10010 10 | --------------------------------------------------------------------1----1--1-----0--------0-------- 10001 11 | ---------------0---------------------------------------------1-----------1----------------1--0------ 10100 12 | -------------------------0--------------------0-----------------------1--0-----0-------------------- 11100 13 | ---------------------------------0-0-------------------1-0------------------------1----------------- 01011 14 | ---------------------------------0-------------------------0-------1------------------------------1- 00010 15 | --------------------------------0----------------------------0--------0------------1----------0----- 01101 16 | --------------------------------------------------------------0--------0-1------------------1---1--- 11001 17 | ------------------------------------------------------------1----------1-0---------0---------------- 10000 18 | --------------1-----------------------------------------------------------0---0------------------1-- 01000 19 | ------------------------------------------------1--------1-------------------------1-------0-------- 01000 20 | ------------------------------------------1---------------------------------------1---0-----0------- 01010 21 | -------------------------------------1------------------1---------------------------------------10-- 10001 22 | ---------------------------------------------1-------------------1-----------------------0---1------ 00101 23 | --------0--------------------------------------------------------------1----------------1--------1-- 01100 24 | ---------------------------------------------------------------------------------0-----0--1--------- 00100 25 | -----------------------------------------------------------------1-----0------0--------------------- 00001 26 | -----------------------------------------------------------------------------------1------1----1---- 00100 27 | -----------------------1------1-----------0--------------------------------------------------------- 01001 28 | -----------------------------------1-----------------------------------1------1--------------------- 00111 29 | .e 30 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_100x5x50_20%_9.pla.out: -------------------------------------------------------------------------------- 1 | .i 100 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 x50 x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 x61 x62 x63 x64 x65 x66 x67 x68 x69 x70 x71 x72 x73 x74 x75 x76 x77 x78 x79 x80 x81 x82 x83 x84 x85 x86 x87 x88 x89 x90 x91 x92 x93 x94 x95 x96 x97 x98 x99 4 | .ob y0 y1 y2 y3 y4 5 | .p 23 6 | --------------------------------------------------------1--1-----1-0-----------------------------1-- 10100 7 | ------------0--------1----------------------------------1-------------------------------------1----- 10000 8 | ---------------------1----------------------------------------------------------1-1------------1---- 01001 9 | ------------------------------------1--0-0-----------------------------------------0-----------0---- 11000 10 | -----------------------------------1---------------------------------00--0-------------------------- 10000 11 | --------------------------------------------------------------------------10---------1----------1--- 00010 12 | --------------------------------------------------------------------0------0-----0--------11-------- 10101 13 | ------------------------------1----------------------------------1------0---------0----------------- 00100 14 | --------------------------------------------------1------------------------11--------0------1--0---- 01010 15 | --------------------------------1-----0----------0-----0-----------------------------------------0-- 11001 16 | -------------------------------------------1-----0---------------------------------1--1----1-------- 00101 17 | --------------------------------------------------------0--------------------11--------------------- 00100 18 | ----0----------------------------------1-------------1---------------------1---------1-------------- 10001 19 | --------------------------1------------1--------------------------------------0--1----------1------- 00010 20 | -------------------------------------0------------------0----0---------------------------0---------- 00010 21 | ----------------0-------1--0---------1--0----------------------------------------------------------- 01100 22 | ------------------------------1-----------------------------------------------0--1------1----------- 00110 23 | ----------------------------0----------0------------------------0-------1--------------------------- 00101 24 | -----------------------------0------------------------------0-------------------0---------1--------- 01000 25 | 1----------------0--------0----------------------------------------------------------------------1-- 01010 26 | ----------------------------------0-0-------------1---------------------0------------------0-------- 01001 27 | ---------------------------------1----------------0------------------1--0-----------0--------------- 00111 28 | ----------1------------------------------------------------11--0--------------0--------------------- 11000 29 | .e 30 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_50%_7.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 45 6 | ---1-----------01---------1---1---------0000------ 10001 7 | --------1--0--10----------1------0----------010--- 01110 8 | -----10-----------------------1---1--0--1----1---0 01010 9 | ------1-0-------1--0---------------------1---11--- 00100 10 | ------1--0--------1-0-------1--0--------1----1---- 11100 11 | ------0---------------0-----1---0--1---------10--1 10110 12 | 1------1----------------------------1----0001----- 10010 13 | -----------0-------0-------0------------10--10---- 01000 14 | ------1------------------1----1------0-0--1-1----- 01100 15 | ------------1-----11--0--1---------1----1-----1--- 11101 16 | ---1--0---0----0------0-------0----0-------------- 11010 17 | ----------01---------0-------------10---1--------- 00001 18 | 1-------1----------------0--------------1--0-----0 00100 19 | -----------------11-110----1---1------------------ 11001 20 | --1--------0-------0-----0-0----1------1---------- 01011 21 | ---0------------1-----------1------1-0----1------1 01110 22 | 0---------------------0--------11----1--1-----0--- 11001 23 | --------1----1-0----------1---1-----0----1-------0 11111 24 | --1-----------------1----0-0--------1----0-------- 10100 25 | --------------1-------1---------11-----01--------- 10001 26 | -----------0----1-----0-------1-------11----1----- 01101 27 | ---------1----0------1---1----0--1--------1------- 11110 28 | 0-----------------------0----00-----0---1--------- 10100 29 | -----------1--1---0--0-------0----1------1-------- 11110 30 | -1-0-----1--------0---0----1---------0------------ 11110 31 | ----------1-0------------------1-0--0--------1---- 00110 32 | 0----------0--------0-1------------------0-1------ 00101 33 | ----------------------1--10----------0-----00--0-- 11011 34 | --------0-1-----1---------------0------0--1--0---- 10111 35 | -----------1------0--1-----0-0-----0--------0----- 11101 36 | 1-----0--------1---------------------------1--0--- 00010 37 | -------------------------1----11-0---------0-0---- 00101 38 | ----------------------1-0----0------0-1----------- 00001 39 | 1------------0-------1---------0-----1--0--------- 01011 40 | 0-------------------1-1----------0-------0-------1 11001 41 | --1-------------0------------------------1--10--0- 01011 42 | ----------------0---------------------10010------- 01011 43 | --0--0--------------01------------------0----1---- 01101 44 | ----------------1---------------0---0-----1--00--- 00111 45 | ----------0---------------1-1----------1-1----1--- 01101 46 | ----------------0---1-0--0-1-----------------0---- 01011 47 | -----------0---------------00-----------0---01---- 01011 48 | ----------0---------------10-------------1-0--1--- 01101 49 | ----------1-0--------------------0-----0-----1---- 00110 50 | ----------------------0-0------------0-------0---- 01000 51 | .e 52 | -------------------------------------------------------------------------------- /extension/boolexpr/compose.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: compose.c 3 | ** 4 | ** Function Composition 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "boolexpr.h" 13 | #include "memcheck.h" 14 | #include "share.h" 15 | #include "util.h" 16 | 17 | 18 | static struct BoolExpr * 19 | _const_compose(struct BoolExpr *c, struct BX_Dict *var2ex) 20 | { 21 | return BX_IncRef(c); 22 | } 23 | 24 | 25 | static struct BoolExpr * 26 | _var_compose(struct BoolExpr *var, struct BX_Dict *var2ex) 27 | { 28 | struct BoolExpr *ex; 29 | 30 | ex = BX_Dict_Search(var2ex, var); 31 | 32 | if (ex == (struct BoolExpr *) NULL) 33 | return BX_IncRef(var); 34 | 35 | return BX_IncRef(ex); 36 | } 37 | 38 | 39 | static struct BoolExpr * 40 | _comp_compose(struct BoolExpr *comp, struct BX_Dict *var2ex) 41 | { 42 | struct BoolExpr *var; 43 | struct BoolExpr *temp; 44 | struct BoolExpr *y; 45 | 46 | CHECK_NULL(var, BX_Not(comp)); 47 | 48 | CHECK_NULL_1(temp, _var_compose(var, var2ex), var); 49 | BX_DecRef(var); 50 | 51 | CHECK_NULL_1(y, BX_Not(temp), temp); 52 | BX_DecRef(temp); 53 | 54 | return y; 55 | } 56 | 57 | 58 | static struct BoolExpr * 59 | _op_compose(struct BoolExpr *op, struct BX_Dict *var2ex) 60 | { 61 | size_t n = op->data.xs->length; 62 | struct BoolExpr **xs; 63 | unsigned int mod_count = 0; 64 | struct BoolExpr *y; 65 | 66 | xs = malloc(n * sizeof(struct BoolExpr *)); 67 | if (xs == NULL) 68 | return NULL; // LCOV_EXCL_LINE 69 | 70 | for (size_t i = 0; i < n; ++i) { 71 | CHECK_NULL_N(xs[i], BX_Compose(op->data.xs->items[i], var2ex), i, xs); 72 | mod_count += (xs[i] != op->data.xs->items[i]); 73 | } 74 | 75 | if (mod_count) 76 | y = _bx_op_new(op->kind, n, xs); 77 | else 78 | y = BX_IncRef(op); 79 | 80 | _bx_free_exprs(n, xs); 81 | 82 | return y; 83 | } 84 | 85 | 86 | static struct BoolExpr * 87 | (*_compose[16])(struct BoolExpr *ex, struct BX_Dict *var2ex) = { 88 | _const_compose, 89 | _const_compose, 90 | _const_compose, 91 | _const_compose, 92 | 93 | _comp_compose, 94 | _var_compose, 95 | NULL, 96 | NULL, 97 | 98 | _op_compose, 99 | _op_compose, 100 | _op_compose, 101 | _op_compose, 102 | 103 | _op_compose, 104 | _op_compose, 105 | _op_compose, 106 | NULL, 107 | }; 108 | 109 | 110 | struct BoolExpr * 111 | BX_Compose(struct BoolExpr *ex, struct BX_Dict *var2ex) 112 | { 113 | return _compose[ex->kind](ex, var2ex); 114 | } 115 | 116 | 117 | struct BoolExpr * 118 | BX_Restrict(struct BoolExpr *ex, struct BX_Dict *var2const) 119 | { 120 | struct BoolExpr *temp; 121 | struct BoolExpr *y; 122 | 123 | CHECK_NULL(temp, BX_Compose(ex, var2const)); 124 | CHECK_NULL_1(y, BX_Simplify(temp), temp); 125 | BX_DecRef(temp); 126 | 127 | return y; 128 | } 129 | 130 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/part.c: -------------------------------------------------------------------------------- 1 | // Filename: part.c 2 | 3 | #include "mincov_int.h" 4 | 5 | static int visit_row(sm_matrix *A, sm_row *prow, int *rows_visited, int *cols_visited); 6 | static int visit_col(sm_matrix *A, sm_col *pcol, int *rows_visited, int *cols_visited); 7 | 8 | static void 9 | copy_row(sm_matrix *A, sm_row *prow) 10 | { 11 | sm_element *p; 12 | 13 | for (p = prow->first_col; p != 0; p = p->next_col) { 14 | sm_insert(A, p->row_num, p->col_num); 15 | } 16 | } 17 | 18 | static int 19 | visit_row(sm_matrix *A, sm_row *prow, int *rows_visited, int *cols_visited) 20 | { 21 | sm_element *p; 22 | sm_col *pcol; 23 | 24 | if (! prow->flag) { 25 | prow->flag = 1; 26 | (*rows_visited)++; 27 | if (*rows_visited == A->nrows) { 28 | return 1; 29 | } 30 | for (p = prow->first_col; p != 0; p = p->next_col) { 31 | pcol = sm_get_col(A, p->col_num); 32 | if (! pcol->flag) { 33 | if (visit_col(A, pcol, rows_visited, cols_visited)) { 34 | return 1; 35 | } 36 | } 37 | } 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | static int 44 | visit_col(A, pcol, rows_visited, cols_visited) 45 | sm_matrix *A; 46 | sm_col *pcol; 47 | int *rows_visited; 48 | int *cols_visited; 49 | { 50 | sm_element *p; 51 | sm_row *prow; 52 | 53 | if (! pcol->flag) { 54 | pcol->flag = 1; 55 | (*cols_visited)++; 56 | if (*cols_visited == A->ncols) { 57 | return 1; 58 | } 59 | for(p = pcol->first_row; p != 0; p = p->next_row) { 60 | prow = sm_get_row(A, p->row_num); 61 | if (! prow->flag) { 62 | if (visit_row(A, prow, rows_visited, cols_visited)) { 63 | return 1; 64 | } 65 | } 66 | } 67 | } 68 | return 0; 69 | } 70 | 71 | int 72 | sm_block_partition(sm_matrix *A, sm_matrix **L, sm_matrix **R) 73 | { 74 | int cols_visited, rows_visited; 75 | sm_row *prow; 76 | sm_col *pcol; 77 | 78 | // Avoid the trivial case 79 | if (A->nrows == 0) { 80 | return 0; 81 | } 82 | 83 | // Reset the visited flags for each row and column 84 | for (prow = A->first_row; prow != 0; prow = prow->next_row) { 85 | prow->flag = 0; 86 | } 87 | for (pcol = A->first_col; pcol != 0; pcol = pcol->next_col) { 88 | pcol->flag = 0; 89 | } 90 | 91 | cols_visited = rows_visited = 0; 92 | if (visit_row(A, A->first_row, &rows_visited, &cols_visited)) { 93 | // we found all of the rows 94 | return 0; 95 | } 96 | else { 97 | *L = sm_alloc(); 98 | *R = sm_alloc(); 99 | for (prow = A->first_row; prow != 0; prow = prow->next_row) { 100 | if (prow->flag) { 101 | copy_row(*L, prow); 102 | } 103 | else { 104 | copy_row(*R, prow); 105 | } 106 | } 107 | return 1; 108 | } 109 | } 110 | 111 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_50%_1.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 46 6 | ------10--------1---0-------------00---0--01------ 11100 7 | 1----------01-1-------0--------------1-1--0------- 11000 8 | ---0-----1-1------1----------------1-0------1---0- 01010 9 | -------0----------0---1--------0--1-----1---11---- 01010 10 | ---------------1-----1-------0---0------0--0-----1 01001 11 | -----------------0---------0---1-0---010----0----- 11110 12 | -----11-----11-------------------------01--1--1--- 01111 13 | ---0------------0----------------------101-0----11 10111 14 | -----1-------0--0-------0----1---------1---------- 10000 15 | --------1--1-0--1-----------------------11-------- 00010 16 | -0--------------0------10--1--------0----------0-- 10101 17 | -----------------1---------0---1--1---1---------10 01101 18 | ---------0-----------0------1-1-----------10--0--- 10110 19 | -------1---1---------0---1---1------0-------1----- 01101 20 | 0---------1-----0-0--0------1-----------------0--0 11111 21 | ----------------------1-----00--1---1----0-1------ 00111 22 | ---0-------------------0-----0-0--1----------00--- 10011 23 | ---------------------0-------0---0----1-----101--- 01011 24 | ----01-----0-----------------1-------0----------0- 10010 25 | -0----0-1-----1------------0----------------0----- 11000 26 | -----------------------1-------0--0--------011-0-- 10011 27 | ----------------1----------10----1-------0--1----- 10001 28 | -0-------------------------0-----------1-101------ 00110 29 | ----------0------0-------------1-----1-----00----- 00110 30 | ---0----1---------------------1------1---0--1----- 00101 31 | ---0--------1-----1-------------1-----0----0------ 00011 32 | ----1-------------0---------------1------0-10----- 01010 33 | ------0----1--1------------0---------------01-1--- 11101 34 | ----1-------------0-----1------------0---0-------- 01000 35 | -----------------1---------10--0------------0----- 00100 36 | ---0--------------1--0---------------------01--0-- 00011 37 | ----------0------------1-------0--0--1------------ 00001 38 | -------1--1-----1-----10-----1------------1------- 11111 39 | -----------1----0-----------------0-----------00-- 10000 40 | ------1---------------------0----0---1------0--1-- 01101 41 | --------------------------1-----1-----00---1--1--- 01011 42 | ------------------1--1------------1--1---------10- 01110 43 | -----------------------------0-0--1-----1---0----- 00010 44 | -0--------------0------0----00----0--------------- 01110 45 | -----------1------0---------------1---0--1--1----- 10011 46 | --1------------------1------------01-------0---1-- 11101 47 | ---0-----0---------------------1-----------1--0--- 01010 48 | ------------------------0-----1------------1---0-- 10000 49 | -----0---------------1---------------0----1---1--- 01101 50 | ----------1-----0-10--------------0--------------- 10110 51 | ------------1-----------1-------------0---1-1----- 10101 52 | .e 53 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_50%_8.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 46 6 | ------0-01-------------0-----0------------0--0---0 10001 7 | --------------------1---1----1----10----------1-1- 00100 8 | ---0--------------------1---------10-----0--01-1-- 01110 9 | -----0--1-------0---------1-1------1---------00--- 10011 10 | ---1-----------------11---1----1-1--------------0- 00101 11 | ----------0-----1--------1-1--1-----------0------0 01100 12 | -----1-------1--------------1----0-0-----11------- 01001 13 | --------10-----0---------1-----11-0--------------1 10111 14 | -----01---------0-----------1--00-----------0----- 10010 15 | -----------------1-----------1---1---1--1---0-0--- 01001 16 | ----------0-1---1--------1---------------0---0---0 00011 17 | -----0------------------11----00-------------0-1-- 00110 18 | ---0--------1-------------------1--0---10------1-- 11000 19 | -------------0----1-----11--1---0------------1-0-- 11110 20 | -----1------0--------------1-1---------1-----0-1-- 00011 21 | ----1---------------------0--------1---1--1-11-1-- 11011 22 | ----------0---------------0---1--1----0----0---0-- 01011 23 | --------0--0-----------0--01------------0------1-- 11100 24 | ---01-------1-------------------1------1--0----0-- 01110 25 | ----------0--------0----1----1-----0----------1--- 00010 26 | -----------1-----1--0-----------0-----0-----0----1 10110 27 | -------0-----------------------------1--10--1-0--- 00001 28 | -------------1------------0--0-1-1-1----------1--- 00111 29 | --------------------------------------1-1-0-110--- 00100 30 | ---------------------------0-00-1-------01-1------ 11011 31 | ---------------1-------10-1-0------------------0-- 10100 32 | -----------1-1------0--------------1-------0--1--- 00011 33 | ------------10-------------10---0---------1------- 01010 34 | ------1---------0-----------1--00---------0------- 01001 35 | --0--------------1---------0-1----0---------1----- 10100 36 | -------1---1-----------0------------------0--0---1 10001 37 | ------------1------------0--0------0----1-------0- 10001 38 | ----------1------0-----------1----10---------1---- 10100 39 | ----1---0-1-----------------11-----------------1-- 00011 40 | -------------1---1-----0---1------------0----1-0-- 01111 41 | ----------0-------------0---0------0---11--------- 10100 42 | ------------------------------1--10------1----00-- 00110 43 | ----------------------------------0---0-0--1-1-1-- 00101 44 | --------1-----1------------0------0--0---0-------- 11100 45 | ----0-1------------------------------1------1-0--1 10101 46 | ----------------------------1----1-----0----1----0 00100 47 | -----------11---------------0---0---------1-----1- 10101 48 | ----------------------------------------10--1-0--1 10000 49 | -----10---------------01------1---------0--------- 11110 50 | ----------------------------1-0--1------0---00---- 11011 51 | -------1----------1----------------1------1------- 10000 52 | .e 53 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/indep.c: -------------------------------------------------------------------------------- 1 | // Filename: indep.c 2 | 3 | #include "mincov_int.h" 4 | 5 | static sm_matrix *build_intersection_matrix(sm_matrix *A); 6 | 7 | solution_t * 8 | sm_maximal_independent_set(sm_matrix *A, int *weight) 9 | { 10 | sm_row *best_row, *prow; 11 | sm_element *p; 12 | int least_weight; 13 | sm_row *save; 14 | sm_matrix *B; 15 | solution_t *indep; 16 | 17 | indep = solution_alloc(); 18 | B = build_intersection_matrix(A); 19 | 20 | while (B->nrows > 0) { 21 | // Find the row which is disjoint from a maximum number of rows 22 | best_row = B->first_row; 23 | for (prow = B->first_row->next_row; prow != 0; prow = prow->next_row) { 24 | if (prow->length < best_row->length) { 25 | best_row = prow; 26 | } 27 | } 28 | 29 | // Find which element in this row has least weight 30 | if (weight == NIL(int)) { 31 | least_weight = 1; 32 | } else { 33 | prow = sm_get_row(A, best_row->row_num); 34 | least_weight = weight[prow->first_col->col_num]; 35 | for (p = prow->first_col->next_col; p != 0; p = p->next_col) { 36 | if (weight[p->col_num] < least_weight) { 37 | least_weight = weight[p->col_num]; 38 | } 39 | } 40 | } 41 | indep->cost += least_weight; 42 | sm_row_insert(indep->row, best_row->row_num); 43 | 44 | // Discard the rows which intersect this row 45 | save = sm_row_dup(best_row); 46 | for (p = save->first_col; p != 0; p = p->next_col) { 47 | sm_delrow(B, p->col_num); 48 | sm_delcol(B, p->col_num); 49 | } 50 | sm_row_free(save); 51 | } 52 | 53 | sm_free(B); 54 | 55 | return indep; 56 | } 57 | 58 | static sm_matrix * 59 | build_intersection_matrix(sm_matrix *A) 60 | { 61 | sm_row *prow, *prow1; 62 | sm_element *p, *p1; 63 | sm_col *pcol; 64 | sm_matrix *B; 65 | 66 | // Build row-intersection matrix 67 | B = sm_alloc(); 68 | for (prow = A->first_row; prow != 0; prow = prow->next_row) { 69 | 70 | // Clear flags on all rows we can reach from row 'prow' 71 | for (p = prow->first_col; p != 0; p = p->next_col) { 72 | pcol = sm_get_col(A, p->col_num); 73 | for (p1 = pcol->first_row; p1 != 0; p1 = p1->next_row) { 74 | prow1 = sm_get_row(A, p1->row_num); 75 | prow1->flag = 0; 76 | } 77 | } 78 | 79 | // Now record which rows can be reached 80 | for (p = prow->first_col; p != 0; p = p->next_col) { 81 | pcol = sm_get_col(A, p->col_num); 82 | for (p1 = pcol->first_row; p1 != 0; p1 = p1->next_row) { 83 | prow1 = sm_get_row(A, p1->row_num); 84 | if (! prow1->flag) { 85 | prow1->flag = 1; 86 | sm_insert(B, prow->row_num, prow1->row_num); 87 | } 88 | } 89 | } 90 | } 91 | 92 | return B; 93 | } 94 | 95 | -------------------------------------------------------------------------------- /thirdparty/espresso/src/gimpel.c: -------------------------------------------------------------------------------- 1 | // Filename: gimpel.c 2 | 3 | #include "mincov_int.h" 4 | 5 | /* 6 | * check for: 7 | * 8 | * c1 c2 rest 9 | * -- -- --- 10 | * 1 1 0 0 0 0 <-- primary row 11 | * 1 0 S1 <-- secondary row 12 | * 0 1 T1 13 | * 0 1 T2 14 | * 0 1 Tn 15 | * 0 0 R 16 | */ 17 | 18 | int 19 | gimpel_reduce(sm_matrix *A, solution_t *select, int *weight, int lb, int bound, int depth, stats_t *stats, solution_t **best) 20 | { 21 | sm_row *prow, *save_sec; 22 | sm_col *c1, *c2; 23 | sm_element *p, *p1; 24 | int c1_col_num, c2_col_num, primary_row_num, secondary_row_num; 25 | int reduce_it; 26 | 27 | reduce_it = 0; 28 | for (prow = A->first_row; prow != 0; prow = prow->next_row) { 29 | if (prow->length == 2) { 30 | c1 = sm_get_col(A, prow->first_col->col_num); 31 | c2 = sm_get_col(A, prow->last_col->col_num); 32 | if (c1->length == 2) { 33 | reduce_it = 1; 34 | } 35 | else if (c2->length == 2) { 36 | c1 = sm_get_col(A, prow->last_col->col_num); 37 | c2 = sm_get_col(A, prow->first_col->col_num); 38 | reduce_it = 1; 39 | } 40 | if (reduce_it) { 41 | primary_row_num = prow->row_num; 42 | secondary_row_num = c1->first_row->row_num; 43 | if (secondary_row_num == primary_row_num) { 44 | secondary_row_num = c1->last_row->row_num; 45 | } 46 | break; 47 | } 48 | } 49 | } 50 | 51 | if (reduce_it) { 52 | c1_col_num = c1->col_num; 53 | c2_col_num = c2->col_num; 54 | save_sec = sm_row_dup(sm_get_row(A, secondary_row_num)); 55 | sm_row_remove(save_sec, c1_col_num); 56 | 57 | for (p = c2->first_row; p != 0; p = p->next_row) { 58 | if (p->row_num != primary_row_num) { 59 | // merge rows S1 and T 60 | for (p1 = save_sec->first_col; p1 != 0; p1 = p1->next_col) { 61 | sm_insert(A, p->row_num, p1->col_num); 62 | } 63 | } 64 | } 65 | 66 | sm_delcol(A, c1_col_num); 67 | sm_delcol(A, c2_col_num); 68 | sm_delrow(A, primary_row_num); 69 | sm_delrow(A, secondary_row_num); 70 | 71 | stats->gimpel_count++; 72 | stats->gimpel++; 73 | *best = sm_mincov(A, select, weight, lb-1, bound-1, depth, stats); 74 | stats->gimpel--; 75 | 76 | if (*best != NIL(solution_t)) { 77 | // is secondary row covered ? 78 | if (sm_row_intersects(save_sec, (*best)->row)) { 79 | // yes, actually select c2 80 | solution_add(*best, weight, c2_col_num); 81 | } 82 | else { 83 | solution_add(*best, weight, c1_col_num); 84 | } 85 | } 86 | 87 | sm_row_free(save_sec); 88 | return 1; 89 | } 90 | else { 91 | return 0; 92 | } 93 | } 94 | 95 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_100x5x50_20%_0.pla.out: -------------------------------------------------------------------------------- 1 | .i 100 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 x50 x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 x61 x62 x63 x64 x65 x66 x67 x68 x69 x70 x71 x72 x73 x74 x75 x76 x77 x78 x79 x80 x81 x82 x83 x84 x85 x86 x87 x88 x89 x90 x91 x92 x93 x94 x95 x96 x97 x98 x99 4 | .ob y0 y1 y2 y3 y4 5 | .p 24 6 | ----------1--------------------------------------------0------0--------1---0--------------------1--- 11000 7 | -----------------------------------------------------------1------------0---0----0---------1-------- 00001 8 | ------------------------------------------------0------------1----------1-------1-------1----------0 11100 9 | ----------------------------------------0---1---------------------1---------------------------0----0 01000 10 | ---------------1-1----------1------------------------------1-------------------------------1-------- 10000 11 | -------------------1--------------0---------------------1----0----------------------0--------------- 10100 12 | -------------------------1--------1-0--------------------1-----------------------------------1------ 01010 13 | ------------------------------------0---------------------00-----1--------------1------------------- 11000 14 | -------------------------0-----------------------------0------------0-----------0---------0--------- 00011 15 | ---0---------------------------------------1---------------------1------------0----------------1---- 00011 16 | -----------------------------------1-------------------------------------------1-0-1-------1-------- 00011 17 | ------------0--------------------------0------------------1---------------------------0----------1-- 01101 18 | -----------------------------------------0------0------------0------------------------0--------0---- 10101 19 | -------------------------1----------------------------------------0-----0-1--------1---------------- 00111 20 | --0---------------0-----------------------------------0--------------------------------------------0 00100 21 | -------------------------------------0----0-----------------------------1------1-------------------- 10000 22 | ------------0-------0-------------------------0-------0--------------------------------------------- 01000 23 | -------------------------------0--------------------------------------1-----------------1------1---- 00010 24 | --1--------------------------0------------------------------------------0---0----------------------- 00001 25 | ---------------------------------------1--------0--------------------------------0----0------------- 10000 26 | ------------------------------------1-----------------------------------------------1----------1---1 10010 27 | ----0----------------------1------------------------------1-------------------------0--------------- 01101 28 | ------------------------------1-----------------------------------------0---1--------------------0-- 01011 29 | ------------------------------------------------------------------------------------0-----00-------- 00010 30 | .e 31 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_100x5x50_20%_2.pla.out: -------------------------------------------------------------------------------- 1 | .i 100 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 x50 x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 x61 x62 x63 x64 x65 x66 x67 x68 x69 x70 x71 x72 x73 x74 x75 x76 x77 x78 x79 x80 x81 x82 x83 x84 x85 x86 x87 x88 x89 x90 x91 x92 x93 x94 x95 x96 x97 x98 x99 4 | .ob y0 y1 y2 y3 y4 5 | .p 24 6 | ---------1--------0-------------------------------------------------------0-----------------0----1-- 00010 7 | ------------------------------------------10--------------------------1----------------------------1 10001 8 | -------0--------0---------------------------------0----1-------------------------------------------0 10010 9 | 0----------------------0-----------------------------------------------1---------------------1-----1 11100 10 | ---------------------------0--------------------1------------------------------0---------1--0------- 10110 11 | ----------------------------------------------------1------0--1----------1---1---------------------- 10011 12 | --------------------0--------------------------0-------------------------0------------------------1- 00001 13 | -------------------------------------------------------------------------11-1--------------0-------- 00001 14 | ---------------------------0---------------------------------------------1----1----------1---------- 00100 15 | ---------1--------------------------------------1----------------------------------------1-0-------- 00010 16 | -------------------------------------------1-------------------------------------000---------0------ 11011 17 | ---------------------------------------0-0-------------------------------------------1----------0--- 01010 18 | ----------------------------------------------------------------------0-------------1--0---------0-- 00101 19 | -------1----------------------------1-0---------------------0--------------------------------------- 00101 20 | ------------1-----------------------1-------------------------1------------------------0------------ 01100 21 | ------------------------------------0-----------0------------------------0------1------------------- 00011 22 | -----------------------------0--------------------1----------------1--0----------------------------- 11000 23 | -------0-----------1-------1----------------------0------------------------------------------------- 01010 24 | --------------------0--------------------------1------------0----------------1---------------------- 10100 25 | -------0----------------------------0---------1----------------------------------------------------0 11000 26 | -1------------------------1------------------0---------------------------------------0-------------- 11001 27 | ----------------------------------------------------------------0--------------1-----------1-------- 01000 28 | -----------------------------------------------------------------------11-----------------------1--- 00100 29 | ----------------------------------1---------1----------1-------------------------------------------- 10000 30 | .e 31 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_100x5x50_20%_3.pla.out: -------------------------------------------------------------------------------- 1 | .i 100 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 x50 x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 x61 x62 x63 x64 x65 x66 x67 x68 x69 x70 x71 x72 x73 x74 x75 x76 x77 x78 x79 x80 x81 x82 x83 x84 x85 x86 x87 x88 x89 x90 x91 x92 x93 x94 x95 x96 x97 x98 x99 4 | .ob y0 y1 y2 y3 y4 5 | .p 24 6 | ------------------------0------0----------------0---1---------------0-------1----------------------- 01101 7 | -------------------------1------------------------------------------------------1-01-0------1------- 00111 8 | 0-------------------------------------------------------------------------------------------1-1--0-0 00010 9 | --------------------------------------------1------------------------------------------------0-00--1 10000 10 | -------------------------------------------------------------------------0-------------------0--11-1 01000 11 | --------------------------1------1---------------------------------------------1-----------1---1---- 01010 12 | ------------1---1----------------------0--------------------------------1-------1------------------- 10010 13 | -------------------1----------------1---------------------1----------------------------0---------1-- 01001 14 | --0----------------------------------------------------------------------1--------0-------1-----1--- 10100 15 | ------------1-------------------------------------------------------------0--1-------------00------- 01100 16 | ---------1---1---------------------------------------------01----------------------1---------------- 11000 17 | -------1--------------1-0--------------------------0--1--------------------------------------------- 10100 18 | --------------------------1-0---------------------------0------1------------------------1----------- 01110 19 | -------------1-----0-------------------------------0-----------------------1----------------0------- 11010 20 | ---------1-----------------------------------------------------1--1------------------1-------------- 00001 21 | 0---------------------------------------------11------------1--------------------------------------- 00001 22 | -----------------------------------00---------------------------1----------------------------1------ 00100 23 | --------------1-----------------------------1-----0------------------------------------0------------ 10000 24 | -------------------------1----------------------------------------------------------1---------0-0--- 00100 25 | -------------------0-------------------------------0------------1--------0-------------------------- 01000 26 | ----------------------------------------------------------------------------0----------01---1------- 10000 27 | --------------------------------------------1------1--------------0------------0------------1------- 11101 28 | -------------------------1-1---1----------------------------------------1--------------------------- 00110 29 | ------------------0--0--1----0---------------------------------------------------------------------- 10101 30 | .e 31 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_50%_3.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 47 6 | 1--01-----------1---------------------------1----1 00001 7 | -------------0-----01---------1----0--1----1-----1 10010 8 | 1--01----1------10----------------0--------------- 01000 9 | ---------------------------11---1------101---0---- 01010 10 | 1---------------------1---1----1-----0-----0-----0 00110 11 | --------0-------------0--1---1----1--1---------1-- 01001 12 | -----------1--0--1---------------1--0-00--------1- 01111 13 | --0---------1-------------1-1--------------0----11 00110 14 | -------10-------0--------1---1-----------------00- 10010 15 | ----1----------10--1------0-----0-----------1----- 01100 16 | -------1----0----------1--0-----------0-------101- 11101 17 | ------------1---10----1-----1-------0------------0 11000 18 | 1-----------------0-----0----------------01--0--0- 01011 19 | ---------0-----0-----11----1-----0------0--------- 01011 20 | -------11------------1-1----0------0-------1------ 10011 21 | ------------1---------0------------0--1--1--11---- 10101 22 | -----------------0------11--------------1-1--0--0- 01101 23 | ------0---0--------------0-------1-----------0--11 10011 24 | -0---01---------------1--00--------------1-------- 11001 25 | -----------------1--------0-0--1-0---1------1----0 11111 26 | --------1------0----------0----10----1-----0------ 10101 27 | --------1----------------0--0-------0-0--1-------1 11001 28 | ---------------00--------0001--------------------0 10101 29 | -1------0----------1-----0------------------0---0- 11000 30 | -----1---------0----0-1------------1----0--------- 10100 31 | 1----0--1-------------------0----01-------------11 11111 32 | --------1-------0-1------1----------00------------ 10010 33 | ---------0----------------0--0--10---------------1 11000 34 | -----0-----------------------0--1-------00-------0 10001 35 | ------1--------0------------0-----1-1-------1----- 00101 36 | ------------1---0---------1-1-1------------0------ 00011 37 | --------1---1----0-------------------1--1----0---- 10100 38 | -----------1---10----------------------0-0----0-1- 01111 39 | ------------00-1------1--1----------------------0- 10100 40 | ---1----0--------------------0---00--------0------ 01110 41 | 01-----1---1---------------------0---------------- 10000 42 | ------1------00-1-------------1------------------- 00001 43 | -----1--0------1----------------1---1------------- 10000 44 | --------------------001-----0------0------------1- 01101 45 | ------------0---0----------1-----1--------------10 01101 46 | ----------------00-1-----1----------1-----------1- 01101 47 | ----------------1-----1------1-------------01---0- 10101 48 | --------1-0----------------------0-------1---0---- 00101 49 | -----0-11-------0----------------------------1---- 10001 50 | -----1---------1-------------0------------------0- 00010 51 | -----1---------1----------------0---------------1- 00100 52 | -------------------------0--111-----0--0---------- 11111 53 | .e 54 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_50%_5.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 47 6 | -1-1-----0---------1-0-----------1------1-----0--- 01001 7 | ---------------0------------------1-01-11---1----- 10000 8 | --0---0------------0-0---------11---------1-0----- 11010 9 | ------1------------------------1-01--0-1---01----- 01101 10 | ------------1---0------0---------1---0--0-1---1--- 10011 11 | --1----0------10---1-----------0--0--------------- 00110 12 | -1------------1---10-00--------1------------------ 01100 13 | ---------1-----------0--------0-----00---1-1------ 01010 14 | ---1---------00----------------1---------1--0----0 10010 15 | -------0-----------0----1-----0--0-0-1------------ 00011 16 | -1---------------1------0--------1--0----01------- 11000 17 | ----------------------01-1---0-----------1-01----0 10111 18 | 0------------1--1----------0--1--------1---------- 10000 19 | ----------0----1--------------1---------11--0-1--- 10001 20 | 1--------1--------1--1---0-------0--------1------- 10110 21 | ---------------------11-1----------0----011------0 11011 22 | ------1--------1---1-----0-------00------0-------- 10110 23 | -----------------01------------0----11---0-----0-- 11001 24 | ----------0-------------0----1------1---11--1----- 01110 25 | ------101-------------1-------------1-------0----- 00001 26 | ----------------1-----0-1--0--10---------1-------- 10011 27 | ---1-----------------110-------1-1-------0-------- 10101 28 | --0---------1--1------1--------0-------0-10------- 11111 29 | ---------------1-------0---------1------0---1---10 11010 30 | ----------------------------1----0-----1-110------ 00001 31 | -----------------1--01-------------1---0-----0---- 01010 32 | ---------------0---1--0------0------1-0----------- 00101 33 | ---------------1----------0---------0----0--0---0- 01100 34 | -------------------------------0-1-0--1----0-1-1-- 11101 35 | 0------0---------0-0-------------------0------1--- 00101 36 | -----0---0---------------------0---1---00-----0--- 01111 37 | ---------------------0--------0-0------1-00------- 01100 38 | ------------------------------0--0-101-----------0 00110 39 | -------------0-1-----0--------------------1--01--- 00011 40 | -------------------------0-------0--1--0----110--- 10111 41 | --------10------------0---------0----------------1 01000 42 | -------------------0---1------------1---01--1----- 01001 43 | ----------0----------0-----------------0--1-1-1--0 01111 44 | --1-------------------0----1-----1----------0----- 01000 45 | --1-------------------1------------0-------00----- 10000 46 | ------------------------------0--1------0-----1--1 00001 47 | ---------------------11-------------1--1----0----- 10000 48 | --1----------------0-------------1--------1-1----- 10000 49 | --------0-1-----1-------------1-----10------------ 11110 50 | ---0-------------0----1-----1-------------0------- 11000 51 | ----0---------------00----------0----1------------ 00011 52 | ----------------------------1------1----0---1----1 00101 53 | .e 54 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_50%_6.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 47 6 | -------------1--1--0----------------0------0010--- 01101 7 | -----------------------01--------1------------11-0 00001 8 | -------------1----------1---0-------0-0---10-0---- 11001 9 | --1------------------1-------1----1----------00--0 10001 10 | 1-----0--------------0--1-0--------------------1-0 01100 11 | --1-------------------0-0------1----0--00-------0- 01111 12 | --1---1-------------0-------0-------10----------1- 00110 13 | ------1-----0-0-----1----1-------0--1-1----------- 11011 14 | -0---------------0-0--1----1----------0----1------ 11000 15 | ------1-------------0-------0-------10---------01- 11000 16 | ---1-------------------0----0------1--------0-1-1- 10001 17 | ------1-------1--------1------------------00--1-1- 01001 18 | --1------------------------0-0-------------11---11 11000 19 | ----0-000---------------1-------0----------------- 00001 20 | --------0-----1-------------0---10----1---1------- 01110 21 | -----------1------------0---0---------0-1----0--0- 10110 22 | ---0--------------------00--1-------------1------1 01000 23 | ----1-0------------00------------------0-11------- 01011 24 | ------0----------------0--------1----------0010--- 10011 25 | -0-0-----------------1-----1-----------1---1-----1 01011 26 | ------0--------------0------0------01-----1------1 11100 27 | --------10---------1-----0------0---------------0- 10010 28 | ------10---------------------------1------0-0-1--1 00111 29 | -1-----0----------00--------0-------------0---10-- 11111 30 | ------------0-01----1-------1-----0--------------- 01001 31 | ----------------00----------1--1--------------1--1 00110 32 | -----------0---0--------1--0-0-----1------------1- 10111 33 | -------0-----------------1-01----0---------01----- 11101 34 | ---1--------0-------------------------0------00-0- 11000 35 | -00---1--------------------1-----------1--------1- 01001 36 | -----------01------1--1-------------------0------- 00010 37 | ----------------------1----1----0-------0--1-----1 01010 38 | ---1--1----1--------1--------------0-------------- 10000 39 | -------------------0---------------------1--1--010 01001 40 | ------------1---1-----------------1-----------010- 10110 41 | ------1------0---------------------1----1---01---- 00111 42 | -----1----------------------0---0-0--------------1 00010 43 | ------0--------------0--0------1---------0-1------ 01011 44 | ------------------------------1---1--------1--110- 10101 45 | -------------1---------------------------1-1-1-0-0 01011 46 | ----------------------------1---------0----111---0 01101 47 | --0----------------------0-------1-------------1-0 10010 48 | -----------------------------01---1--------1--100- 11111 49 | --------------0---------0-------0-------0------1-0 10111 50 | ---------1-----------------11------0--------1----1 11101 51 | ----1-------------------1--0----------0-------10-- 11110 52 | ---------------------0----------1-------------0-0- 01000 53 | .e 54 | -------------------------------------------------------------------------------- /extension/boolexpr/bubble.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: bubble.c 3 | ** 4 | ** Bubbling the NOT operator 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "boolexpr.h" 13 | #include "memcheck.h" 14 | #include "share.h" 15 | #include "util.h" 16 | 17 | 18 | /* ~(a | b | ...) = ~a & ~b & ... */ 19 | static struct BoolExpr * 20 | _inv_or(struct BoolExpr *op) 21 | { 22 | size_t length = op->data.xs->length; 23 | struct BoolExpr **xs; 24 | struct BoolExpr *temp; 25 | struct BoolExpr *y; 26 | 27 | xs = malloc(length * sizeof(struct BoolExpr *)); 28 | if (xs == NULL) 29 | return NULL; // LCOV_EXCL_LINE 30 | 31 | for (size_t i = 0; i < length; ++i) { 32 | temp = BX_Not(op->data.xs->items[i]); 33 | if (temp == NULL) { 34 | free(xs); // LCOV_EXCL_LINE 35 | return NULL; // LCOV_EXCL_LINE 36 | } 37 | CHECK_NULL_N(xs[i], BX_PushDownNot(temp), i, xs); 38 | BX_DecRef(temp); 39 | } 40 | 41 | y = BX_And(length, xs); 42 | 43 | _bx_free_exprs(length, xs); 44 | 45 | return y; 46 | } 47 | 48 | 49 | static struct BoolExpr * 50 | _inv_and(struct BoolExpr *op) 51 | { 52 | size_t length = op->data.xs->length; 53 | struct BoolExpr **xs; 54 | struct BoolExpr *temp; 55 | struct BoolExpr *y; 56 | 57 | xs = malloc(length * sizeof(struct BoolExpr *)); 58 | if (xs == NULL) 59 | return NULL; // LCOV_EXCL_LINE 60 | 61 | for (size_t i = 0; i < length; ++i) { 62 | temp = BX_Not(op->data.xs->items[i]); 63 | if (temp == NULL) { 64 | free(xs); // LCOV_EXCL_LINE 65 | return NULL; // LCOV_EXCL_LINE 66 | } 67 | CHECK_NULL_N(xs[i], BX_PushDownNot(temp), i, xs); 68 | BX_DecRef(temp); 69 | } 70 | 71 | y = BX_Or(length, xs); 72 | 73 | _bx_free_exprs(length, xs); 74 | 75 | return y; 76 | } 77 | 78 | 79 | static struct BoolExpr * 80 | _inv_ite(struct BoolExpr *op) 81 | { 82 | struct BoolExpr *d1, *d0; 83 | struct BoolExpr *temp; 84 | struct BoolExpr *y; 85 | 86 | CHECK_NULL(temp, BX_Not(op->data.xs->items[1])); 87 | CHECK_NULL_1(d1, BX_PushDownNot(temp), temp); 88 | BX_DecRef(temp); 89 | 90 | CHECK_NULL_1(temp, BX_Not(op->data.xs->items[2]), d1); 91 | CHECK_NULL_2(d0, BX_PushDownNot(temp), d1, temp); 92 | BX_DecRef(temp); 93 | 94 | CHECK_NULL_2(y, BX_ITE(op->data.xs->items[0], d1, d0), d1, d0); 95 | BX_DecRef(d1); 96 | BX_DecRef(d0); 97 | 98 | return y; 99 | } 100 | 101 | 102 | struct BoolExpr * 103 | BX_PushDownNot(struct BoolExpr *ex) 104 | { 105 | if (BX_IS_ATOM(ex)) 106 | return BX_IncRef(ex); 107 | 108 | if (BX_IS_NOR(ex)) 109 | return _inv_or(ex->data.xs->items[0]); 110 | 111 | if (BX_IS_NAND(ex)) 112 | return _inv_and(ex->data.xs->items[0]); 113 | 114 | if (BX_IS_NOT(ex) && BX_IS_ITE(ex->data.xs->items[0])) 115 | return _inv_ite(ex->data.xs->items[0]); 116 | 117 | return _bx_op_transform(ex, BX_PushDownNot); 118 | } 119 | 120 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_50%_0.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 48 6 | -------------------0-----------1-000------1--0-1-- 10010 7 | --------1--------1-------------10--0----1----11--- 11000 8 | ---------------------------1--1---0-0-----1-----10 00010 9 | -00-----------0--------1--------0------0-----01--- 10011 10 | ----1---0-----0--0--------------1---0-----------0- 00101 11 | -------------------10---------0-------1----10----0 01100 12 | -----------------0----0-00------------------1-1-1- 10100 13 | ----------1--00---0-----------1-----1---------1--- 11000 14 | 1---1----------------1---1-----0--------10----1--- 11101 15 | --------------------------01--01-----0-10-------0- 11110 16 | ---------1-------1-----------11--1--0---------1--- 01001 17 | ----1--------1--------------------10-----1--00---- 01001 18 | ------------------------010--1---1-------1--0----- 00110 19 | --1-----1-------------1---------0---------01------ 01000 20 | -1-----------------------10--------010----------10 11110 21 | ------------10-----1------------011--------------- 00100 22 | ---10-------------------0---0--------------0--0--- 00010 23 | ------------------0-----1--------------------10-00 00100 24 | ---0-------0--1----------------1-1-------1-------1 11100 25 | --0--0-----1---------------0---------1---1-0------ 01011 26 | -1-----------------0----------0--1--------1-1--1-- 11010 27 | -----------1-----------0-10---------------00----0- 10110 28 | -0-1--------1--------1-----1-----------------1--1- 01011 29 | ---------1---1--------1------------------1---11--1 01011 30 | ------------1-1--1-----------0---1---0------------ 10100 31 | --------1----------0-------0---0-0-0----------1--1 11111 32 | 1-------------------1---10--------11----1--------- 11011 33 | 0-00----0---------1------------------------0------ 00011 34 | --1---------------------11---------------00-----1- 00110 35 | ---------0--1-0---------------------0-----0--1---- 00101 36 | -------00--0---------0----0--------------0-0------ 11011 37 | ----0-------------1-------1--1-0--0-----------0--- 01111 38 | -----------1------------00-------------------00--1 00110 39 | ---11---0---------------------------1--------10--- 10001 40 | -------------01------1-----------0------0-----1--- 01010 41 | ------------------1----1---01----0-------1-0------ 10111 42 | -------------------------1--1-0-----------0-1-0--- 11000 43 | 0-----------------------0--------00-1--0--------0- 01111 44 | ---------------------------01-0--1------------0--0 01100 45 | ----------------1----------0-----010----------1--- 00011 46 | --------------------11--0-0---0---0-1------------- 10111 47 | ---0--------------------------1---1---0---1------- 00001 48 | ------------------0----00---111------------------- 01011 49 | --------------------------0-----1----0------1-0-1- 10011 50 | --1---------1---0----0-------0-----0---------1---- 11111 51 | ---0--------1----------------------01------1-1---- 11100 52 | -----------------------0-----------0-----1-1-00--- 11001 53 | --------------0-----0--0------0------------------- 01000 54 | .e 55 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_100x5x50_20%_1.pla.out: -------------------------------------------------------------------------------- 1 | .i 100 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 x50 x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 x61 x62 x63 x64 x65 x66 x67 x68 x69 x70 x71 x72 x73 x74 x75 x76 x77 x78 x79 x80 x81 x82 x83 x84 x85 x86 x87 x88 x89 x90 x91 x92 x93 x94 x95 x96 x97 x98 x99 4 | .ob y0 y1 y2 y3 y4 5 | .p 25 6 | --------------------------------------------------------0------------------------10-1------------0-- 10000 7 | ----1----------------------------------------0---------------------0-----------------------0---0---- 00100 8 | -------------------------------------------------1---1------------------1----------1--1------------1 11110 9 | ---1----------------------------------1-----0----------0-----------1-------------------------------- 10100 10 | -----------------------0------------------------------------------------1---------0-------0---1----- 01010 11 | ---0------------------------------------------------------1--------------------1-------------1--1--- 01100 12 | ------------------1-----------0-0-------------------------0---------------------------------------0- 01001 13 | --------------------------------0----0-------------0----------------------------------1------------1 00011 14 | ----------------------------------1------------0----------1-------------------------0---------0----- 10110 15 | -----1------1------11------------------------------------------------------------------------------- 00010 16 | ---1--------------------------------0------------------0---1--------------------------1------------- 11001 17 | -------------------------------1------------------------------------1-------0------1---------------- 00100 18 | --------------------------------0------------------0--1-------------------------------------1------- 10000 19 | ------------1---------------------------------------------------------------------------------0---1- 01000 20 | ------------------1--------------------------------------------------------1---1-------------------1 00010 21 | ---------------------------------------------------------------1---0-------0--1--------------------- 01000 22 | ------------------------------------------------------------------10------1-------------------1----- 00100 23 | ----------------------------------------------------1----------------------0---------------------1-1 00001 24 | --0---1-------------------------------------------------------------------------------------0---1--- 00011 25 | ------------------------1--1----------------------------------------------------0---------------0--- 01100 26 | -------------------------0----------------------------------------0-----0------------1-------------- 00101 27 | ----------------------------------------1--------1-----------------1-----1-------------------------- 10001 28 | -------------------------------0-------------00-----------------------------------------------1----- 01001 29 | ------------------------------------------------11----------------------------------1--0------------ 11001 30 | -----------------------------0-----0--------------------------------------------1------------------- 00001 31 | .e 32 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_100x5x50_20%_6.pla.out: -------------------------------------------------------------------------------- 1 | .i 100 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 x50 x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 x61 x62 x63 x64 x65 x66 x67 x68 x69 x70 x71 x72 x73 x74 x75 x76 x77 x78 x79 x80 x81 x82 x83 x84 x85 x86 x87 x88 x89 x90 x91 x92 x93 x94 x95 x96 x97 x98 x99 4 | .ob y0 y1 y2 y3 y4 5 | .p 25 6 | ----------------1---------1---------------------------------------1-------------------------0--1--1- 11000 7 | --------------------------1------------------------------------------1----------------------0--1--1- 00011 8 | -------1-----------0-------------------------------0-----------------0------------1----------------- 10000 9 | -0-----1-----------0-------0--------------------------------------0--------1------------------------ 00111 10 | -----------1--------------------------------------1-----------------------------0----1----------1--- 10000 11 | ----------0-------------------------------------------------0----0--------------0------------------0 00010 12 | -------------------0----------------------1----------------------------0-0----------1-------------1- 11101 13 | ----0-0--1----------0---------------------------------------------------1--------------------------- 00110 14 | ---0-----------------1------------------------------------0---------------------------------1-1----- 01001 15 | ----------------------------------0----------1-0-------0----------------------------------------1--- 01010 16 | --------------------------------------0-------------1----1---1---------0---------------------------- 10110 17 | ---0--------------1---------0-----------------------------0----------------------------------------- 10000 18 | ----------------0----------------------------------------0-1-----------------1--------0------------- 01110 19 | --------------------------------------------1---------1--1----------------------0---------0--------- 01110 20 | --------------------------0-----------------------------0------------------------0-------1---------- 00001 21 | --------------------------0--------------------1-----------1---------------------0------------------ 00001 22 | ---1-------------------------------------------------------1---------------------1--------------0--- 00100 23 | ----------------------------------------------------------0----------1----------0---0-----------0--- 01101 24 | -----------------------------------1-------------------1-0--1---------------------------1----------- 11110 25 | --------------------------------0---------1----------------------------------------0-------------0-- 01001 26 | ------------------------------------------------1--------------------------------------1-0---------1 01010 27 | ---1-------------------0------------1----------------------------------------------------------1---- 00011 28 | --------------------------------------------------------------------------------0-------01------0--- 00101 29 | -----------------------0-----------------------------0-----------------------------------1---------- 01000 30 | -----------------1--------------------------------------------------------------------0-----0------- 00010 31 | .e 32 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_50%_2.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 49 6 | -------1---10----------------------------0---01-00 00101 7 | ---------0----------------0-111--0------------0--- 00010 8 | --0-------0--------0-1--------------1-1--0---0---- 11100 9 | --------0---------------1--1-----0------1---1-1-0- 11010 10 | --0--0-------1-------------1-----------0------01-- 10100 11 | ------------------1-------111--------1-----1--0--- 10010 12 | -----------0-----------0-1-------0-----1-0---1---- 10001 13 | --------1--0-----1--0-0-------0---0--------------- 11100 14 | -------1---0-----------------------1---1--0--0---1 00011 15 | ---------0--------1--------11--------11-------1-1- 11011 16 | ---------0----1-0-------------1--0--------------0- 00010 17 | ---------0-------------1--0----------1-1--1------- 00010 18 | ---------------------1----1--------0--0---0----00- 10001 19 | --------------------0------1-------0--------001-0- 10100 20 | ----------------------101-0-0--0-------------10--- 11111 21 | -------1---0----1-1----------1----------------0--- 00001 22 | ------------0-------------100----1--------0-----1- 01110 23 | ------------1----------1--10-1-----1------------1- 10110 24 | -----------0--------------0--0-------1-0----1---1- 11010 25 | ---------------------------1---------0-1-1-1----00 10101 26 | -0-------1-----------1--------------0--0--0-----0- 11001 27 | ---------------------0--------0-------01--0--1--1- 11001 28 | 0----------------------------0--1---1-----1------0 00101 29 | -----------------0-----------1---1-0-0-----0----1- 11001 30 | -----------1----0----0-----0----0--0-------------- 01010 31 | ---------1----0-----1--1----------111------------- 01111 32 | -----------------------------------0--1--0-0-01-0- 11100 33 | ---------0--1-------------0------1-1------0------- 10100 34 | ---0------------------------1-------0---1----01--- 00101 35 | -----------1----0------0---------1-0--0--0-------- 01111 36 | -------1-------0-0--------1--------0--0---------1- 01111 37 | ------0-----0----------0-----------0---0-----0---- 11000 38 | -----------------------1-----------10-11------1--- 01001 39 | --------0--0----0------------------0-1-------0-0-- 11011 40 | -------------1-----1------1----------------0---0-- 10000 41 | ----------01-1------------------------------0---0- 00100 42 | --------0-----0-----------------1------0---------0 00001 43 | 0-------------------0----1-------0-----0--------1- 11010 44 | --------------0-----1------------0--------0---0--- 00001 45 | 1------------------0----0----0---0--------------1- 11001 46 | -------------------1---1-------00--0-0------------ 01101 47 | -----------1-------1---0-----------1---------0-1-- 01101 48 | 0----------------------1-------------0-1---1-0---- 01101 49 | ---------1---------------0---1-0------------01---- 01111 50 | -----------0-----0---0-------0--1---------------0- 10111 51 | ---------1----------1--------------1-------1-0---- 01100 52 | -----1-----0-----0--------11---------------------- 10001 53 | --------------1---------------------------00---0-- 01000 54 | -----------------0-----0----------------------1-1- 01000 55 | .e 56 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_50%_4.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 49 6 | ---------------------00----10---------0------001-1 01110 7 | ---------------1--0-1------0-1--1----1------1-1--- 10110 8 | -----0--------1--0---1--------1-------------1--1-0 01110 9 | --------------0--0-------0-----0----1-1--1----1--- 10101 10 | -----0------1--1-------------1-0-----1---1------0- 10110 11 | -------1---1---------------0--0-1---0-----0---1--- 10011 12 | -----------------1------------0-01-0---10----0---- 11110 13 | ---------1--1--------------------1-0---1--------10 01010 14 | -----------------0-0-1-------1-1--------1--1------ 01100 15 | ---------0----0----------0--0------------0-1-----0 10100 16 | -----------11-0--------------1----------1-0----0-- 10100 17 | --------------11----1------0----0--1-------1---0-- 11011 18 | -----------------------0----0--0-------0---1-1---- 10000 19 | ----------0--------1------0--0-0------0---------0- 10110 20 | --------1---------1----------0------1-------1--0-1 01101 21 | --0------------------------0--------------100---1- 10000 22 | --------1------------------0--------0----0-0--0--1 11100 23 | ----------01---1-----------0--------------00------ 00001 24 | 0----1-1---1---------0------0--------------------- 10100 25 | -----1-1---------------------1-01--------1---0---- 11011 26 | --------0-----10--0-------------------10---------- 10010 27 | --1-------0-----1-------------------0------1------ 10001 28 | ----------00--------------0--0-----------------00- 00101 29 | ---0----0--------------------0-------0-11-0------- 01111 30 | ---------------------1---0-----1-1--------1-----1- 00101 31 | ---------------------------0----1------0---00---1- 00101 32 | ----10--------1-----------01------------------1--- 00110 33 | ----------------0----------1---------01---10----1- 11101 34 | --------0-----0------------1--------------1---1-1- 10001 35 | --------------11-----------1-0---1-1-------------- 01001 36 | --------------1---1----0-------1---------0-------0 11010 37 | ---------------------------11--------0----10--1--- 00101 38 | ---------------1--0--------1-1---0---------1--0--- 11101 39 | ----0----------0-----------------1---1-1-------1-- 01011 40 | -----------0------10---------1--0-------------0--- 01110 41 | -------0-1--------------------0------------10-1--- 01011 42 | ----11--1---------0-----------------------0---0--- 01101 43 | --------0--0--0------0--------------------00------ 01011 44 | 0-----------0-1------0------10-------------------- 00111 45 | --1-------1---0--------------0---0--0------------- 00111 46 | -----0--------01-----------1--------------1------- 00100 47 | ----------------1----------11----1--------11------ 01110 48 | --1-------0----01-------------------0------------- 01010 49 | ------00-0----1------------1---------------------- 10010 50 | -------0----------0-----------0--------1--0------- 00011 51 | --1------------1-------------0----0-------------1- 00101 52 | -0-----------------------1-----------0----1------- 00010 53 | -------------1---0---------0-----1---------------- 00100 54 | ------------------0------------------0-----1-----1 00001 55 | .e 56 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all.out/bb_50x5x50_50%_9.pla.out: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 4 | .ob y0 y1 y2 y3 y4 5 | .p 49 6 | ----------1------1--1--10-0---1------------1------ 10010 7 | -----------1---------------------11------0-1--0--1 01000 8 | 0----------0---1------------1----------0------1-0- 10000 9 | ----------------------0------------1-01-1---0-1--- 01100 10 | -1---------------------0---------0---1-1---1--1--- 01001 11 | ------1----------0----------1-----1-----0--1-1-1-- 11011 12 | -------------------------1-----------0-1-00---1-0- 00110 13 | -0----------------1------------0---1---1-----1---- 00100 14 | -------------1------------1---111-00--1----------- 11110 15 | -----------------0---1----1----------------0-0---- 01000 16 | --------------------011---------0-----10-----1---- 10101 17 | ----------------1-----1--------0--0-10---------1-- 10101 18 | -----0--0--------------01-0---------0----------0-- 11001 19 | --1--------------0------------------1-----0--0-00- 10110 20 | -------------00-0--------------------0---0-1---0-- 10110 21 | ----------------------1--10-0----1-----0--1------- 11001 22 | --1-----------------------0----00---------1-1---10 11111 23 | -------0-1--------------0-0-0-----1----0-----1---- 11111 24 | -------------------------11---1---1--0----10------ 10011 25 | --------01---------1---0------0---------------01-- 11011 26 | -------------1---0----1-------0-----------0-----1- 11000 27 | --------0-----1----------------0-------1-0---0---- 00110 28 | -----------------1-------------0-------1--000----- 00110 29 | 0----------------1----1-----1--1-------0---------- 10100 30 | -----------------------1-01------0--------00------ 10001 31 | -------------0-----1---1-------------------0-0-01- 11011 32 | 0------------1---------1----------------011-----0- 11101 33 | -----------------------1-------11-----1-0--------- 00010 34 | --------------------------1------11----1--1-----1- 10001 35 | -------------0------1--110--------------------0--- 01101 36 | --------0-----------------0-----------00------1--- 00001 37 | --------------------------1---1---11------10--0--- 10111 38 | --------1-----------------1------1-0-------1------ 00010 39 | ------------0------0-----01---------0-----------0- 01110 40 | ----------------------0-------0------0---111------ 10011 41 | -------------1-----0-----00-1-1------------------- 11100 42 | -----------------1------1-1------------0---1-0---- 01110 43 | --1----------------0---01-10--------------------0- 11111 44 | -------------------------0--0--1--11-0---------1-- 11111 45 | -------------1------------10--1------------1---0-- 11100 46 | -------------0----0-------------0------1-1-------- 10001 47 | --------------------------0------------1----1-10-- 01001 48 | ------0-1--------------0------------0-00---------- 11110 49 | ----------------------------0--1--0-----01------1- 11011 50 | --------------------------------0--0-1-1----1---0- 01111 51 | --------------------------1-1-1------00----------- 00110 52 | -----0--0--------------0----0--------------------- 00010 53 | --------1-------------------0--0--0--------------- 00100 54 | --------1----1-----------------------1----------0- 00100 55 | .e 56 | -------------------------------------------------------------------------------- /doc/source/reference/boolalg/picosat.rst: -------------------------------------------------------------------------------- 1 | .. reference/boolalg/picosat.rst 2 | 3 | ******************************************************** 4 | :mod:`pyeda.boolalg.picosat` --- PicoSAT C Extension 5 | ******************************************************** 6 | 7 | Interface to PicoSAT SAT solver C extension 8 | 9 | Constants 10 | ========= 11 | 12 | .. data:: VERSION 13 | 14 | PicoSAT version string 15 | 16 | .. data:: COPYRIGHT 17 | 18 | PicoSAT copyright statement 19 | 20 | Exceptions 21 | ========== 22 | 23 | .. exception:: picosat.Error 24 | 25 | An error happened inside PicoSAT. 26 | Examples include initialization errors, and unexpected return codes. 27 | 28 | Interface Functions 29 | =================== 30 | 31 | .. function:: satisfy_one(nvars, clauses, assumptions, verbosity=0, default_phase=2, propagation_limit=-1, decision_limit=-1) 32 | 33 | If the input CNF is satisfiable, return a satisfying input point. 34 | A contradiction will return None. 35 | 36 | Parameters 37 | 38 | nvars : posint 39 | Number of variables in the CNF 40 | 41 | clauses : iter of iter of (nonzero) int 42 | The CNF clauses 43 | 44 | assumptions : iter of (nonzero) int 45 | Add assumptions (unit clauses) to the CNF 46 | 47 | verbosity : int, optional 48 | Set verbosity level. A verbosity level of 1 and above prints more and 49 | more detailed progress reports to stdout. 50 | 51 | default_phase : {0, 1, 2, 3} 52 | 53 | Set default initial phase: 54 | * 0 = false 55 | * 1 = true 56 | * 2 = Jeroslow-Wang (default) 57 | * 3 = random 58 | 59 | progagation_limit : int 60 | Set a limit on the number of propagations. A negative value sets no 61 | propagation limit. 62 | 63 | decision_limit : int 64 | Set a limit on the number of decisions. A negative value sets no 65 | decision limit. 66 | 67 | Returns 68 | 69 | tuple of {-1, 0, 1} 70 | * -1 : zero 71 | * 0 : dont-care 72 | * 1 : one 73 | 74 | .. function:: satisfy_all(nvars, clauses, verbosity=0, default_phase=2, propagation_limit=-1, decision_limit=-1) 75 | 76 | Iterate through all satisfying input points. 77 | 78 | Parameters 79 | 80 | nvars : posint 81 | Number of variables in the CNF 82 | 83 | clauses : iter of iter of (nonzero) int 84 | The CNF clauses 85 | 86 | verbosity : int, optional 87 | Set verbosity level. A verbosity level of 1 and above prints more and 88 | more detailed progress reports to stdout. 89 | 90 | default_phase : {0, 1, 2, 3} 91 | Set default initial phase: 92 | * 0 = false 93 | * 1 = true 94 | * 2 = Jeroslow-Wang (default) 95 | * 3 = random 96 | 97 | progagation_limit : int 98 | Set a limit on the number of propagations. A negative value sets no 99 | propagation limit. 100 | 101 | decision_limit : int 102 | Set a limit on the number of decisions. A negative value sets no 103 | decision limit. 104 | 105 | Returns 106 | 107 | iter of tuple of {-1, 0, 1} 108 | * -1 : zero 109 | * 0 : dont-care 110 | * 1 : one 111 | 112 | -------------------------------------------------------------------------------- /extension/boolexpr/test/test_compose.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: test_compose.cpp 3 | ** 4 | ** Test function composition 5 | */ 6 | 7 | 8 | #include "boolexprtest.hpp" 9 | 10 | 11 | class BX_Compose_Test: public BoolExpr_Test {}; 12 | 13 | 14 | // Test composition on atoms 15 | TEST_F(BX_Compose_Test, Atoms1) 16 | { 17 | struct BX_Dict *var2ex = BX_Dict_New(); 18 | 19 | BX_Dict_Insert(var2ex, xs[0], &BX_Zero); 20 | BX_Dict_Insert(var2ex, xs[1], &BX_One); 21 | BX_Dict_Insert(var2ex, xs[2], xs[12]); 22 | BX_Dict_Insert(var2ex, xs[3], xs[13]); 23 | 24 | ops[0] = BX_Compose(&BX_Zero, var2ex); 25 | EXPECT_EQ(ops[0], &BX_Zero); 26 | 27 | ops[1] = BX_Compose(&BX_One, var2ex); 28 | EXPECT_EQ(ops[1], &BX_One); 29 | 30 | ops[2] = BX_Compose(xs[0], var2ex); 31 | EXPECT_EQ(ops[2], &BX_Zero); 32 | 33 | ops[3] = BX_Compose(xns[0], var2ex); 34 | EXPECT_EQ(ops[3], &BX_One); 35 | 36 | ops[4] = BX_Compose(xs[2], var2ex); 37 | EXPECT_EQ(ops[4], xs[12]); 38 | 39 | ops[5] = BX_Compose(xns[2], var2ex); 40 | EXPECT_EQ(ops[5], xns[12]); 41 | 42 | ops[6] = BX_Compose(xs[10], var2ex); 43 | EXPECT_EQ(ops[6], xs[10]); 44 | 45 | ops[7] = BX_Compose(xns[10], var2ex); 46 | EXPECT_EQ(ops[7], xns[10]); 47 | 48 | BX_Dict_Del(var2ex); 49 | } 50 | 51 | 52 | // Test restriction on atoms 53 | TEST_F(BX_Compose_Test, Atoms2) 54 | { 55 | struct BX_Dict *var2const = BX_Dict_New(); 56 | 57 | BX_Dict_Insert(var2const, xs[0], &BX_Zero); 58 | BX_Dict_Insert(var2const, xs[1], &BX_One); 59 | BX_Dict_Insert(var2const, xs[2], &BX_Zero); 60 | BX_Dict_Insert(var2const, xs[3], &BX_One); 61 | 62 | ops[0] = BX_Restrict(&BX_Zero, var2const); 63 | EXPECT_EQ(ops[0], &BX_Zero); 64 | 65 | ops[1] = BX_Restrict(&BX_One, var2const); 66 | EXPECT_EQ(ops[1], &BX_One); 67 | 68 | ops[2] = BX_Restrict(xs[0], var2const); 69 | EXPECT_EQ(ops[2], &BX_Zero); 70 | 71 | ops[3] = BX_Restrict(xns[0], var2const); 72 | EXPECT_EQ(ops[3], &BX_One); 73 | 74 | ops[4] = BX_Compose(xs[10], var2const); 75 | EXPECT_EQ(ops[4], xs[10]); 76 | 77 | ops[5] = BX_Compose(xns[10], var2const); 78 | EXPECT_EQ(ops[5], xns[10]); 79 | 80 | BX_Dict_Del(var2const); 81 | } 82 | 83 | 84 | TEST_F(BX_Compose_Test, Basic) 85 | { 86 | ops[0] = BX_AndN(2, xs[0], xs[1]); 87 | ops[1] = BX_XorN(2, xs[2], xs[3]); 88 | ops[2] = BX_OrN(2, ops[0], ops[1]); 89 | 90 | struct BX_Dict *var2const = BX_Dict_New(); 91 | BX_Dict_Insert(var2const, xs[0], &BX_Zero); 92 | BX_Dict_Insert(var2const, xs[2], &BX_One); 93 | 94 | ops[3] = BX_Restrict(ops[2], var2const); 95 | EXPECT_EQ(ops[3], xns[3]); 96 | 97 | BX_Dict_Del(var2const); 98 | } 99 | 100 | 101 | // In which I try to close 100% coverage 102 | TEST_F(BX_Compose_Test, Misc) 103 | { 104 | ops[0] = BX_OrN(4, xs[0], xs[1], xs[2], xs[3]); 105 | ops[1] = BX_Simplify(ops[0]); 106 | 107 | struct BX_Dict *var2const = BX_Dict_New(); 108 | BX_Dict_Insert(var2const, xs[8], &BX_Zero); 109 | BX_Dict_Insert(var2const, xs[9], &BX_Zero); 110 | 111 | ops[2] = BX_Compose(ops[1], var2const); 112 | EXPECT_EQ(ops[2], ops[1]); 113 | 114 | BX_Dict_Del(var2const); 115 | } 116 | 117 | -------------------------------------------------------------------------------- /extension/boolexpr/binary.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Filename: binary.c 3 | ** 4 | ** Convert all N-ary operators to binary operators 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "boolexpr.h" 13 | #include "memcheck.h" 14 | #include "share.h" 15 | #include "util.h" 16 | 17 | 18 | static struct BoolExpr * 19 | _commutative_binify(struct BoolExpr *op) 20 | { 21 | if (op->data.xs->length == 2) 22 | return BX_IncRef(op); 23 | 24 | size_t mid = op->data.xs->length / 2; 25 | size_t n0 = mid; 26 | size_t n1 = op->data.xs->length - mid; 27 | struct BoolExpr **left = op->data.xs->items; 28 | struct BoolExpr **right = op->data.xs->items + mid; 29 | struct BoolExpr *xs[2]; 30 | struct BoolExpr *temp; 31 | struct BoolExpr *y; 32 | 33 | if (n0 == 1) { 34 | xs[0] = BX_IncRef(left[0]); 35 | } 36 | else { 37 | CHECK_NULL(temp, _bx_op_new(op->kind, n0, left)); 38 | CHECK_NULL_1(xs[0], _commutative_binify(temp), temp); 39 | BX_DecRef(temp); 40 | } 41 | 42 | CHECK_NULL_1(temp, _bx_op_new(op->kind, n1, right), xs[0]); 43 | CHECK_NULL_2(xs[1], _commutative_binify(temp), xs[0], temp); 44 | BX_DecRef(temp); 45 | 46 | CHECK_NULL_2(y, _bx_op_new(op->kind, 2, xs), xs[0], xs[1]); 47 | BX_DecRef(xs[0]); 48 | BX_DecRef(xs[1]); 49 | 50 | return y; 51 | } 52 | 53 | 54 | static struct BoolExpr * 55 | _eq_binify(struct BoolExpr *op) 56 | { 57 | if (op->data.xs->length == 2) 58 | return BX_IncRef(op); 59 | 60 | size_t length; 61 | struct BoolExpr **xs; 62 | struct BoolExpr *temp; 63 | struct BoolExpr *y; 64 | 65 | length = (op->data.xs->length * (op->data.xs->length - 1)) >> 1; 66 | xs = malloc(length * sizeof(struct BoolExpr *)); 67 | 68 | for (size_t i = 0, index = 0; i < (op->data.xs->length - 1); ++i) { 69 | for (size_t j = i + 1; j < op->data.xs->length; ++j, ++index) { 70 | CHECK_NULL_N(xs[index], BX_EqualN(2, op->data.xs->items[i], 71 | op->data.xs->items[j]), index, xs); 72 | } 73 | } 74 | 75 | CHECK_NULL_N(temp, BX_And(length, xs), length, xs); 76 | 77 | _bx_free_exprs(length, xs); 78 | 79 | CHECK_NULL_1(y, _commutative_binify(temp), temp); 80 | BX_DecRef(temp); 81 | 82 | return y; 83 | } 84 | 85 | 86 | static struct BoolExpr * 87 | _fixed_binify(struct BoolExpr *op) 88 | { 89 | return BX_IncRef(op); 90 | } 91 | 92 | 93 | static struct BoolExpr * 94 | (*_op_binify[16])(struct BoolExpr *ex) = { 95 | NULL, NULL, NULL, NULL, 96 | NULL, NULL, NULL, NULL, 97 | 98 | _commutative_binify, 99 | _commutative_binify, 100 | _commutative_binify, 101 | _eq_binify, 102 | 103 | _fixed_binify, 104 | _fixed_binify, 105 | _fixed_binify, 106 | NULL, 107 | }; 108 | 109 | 110 | struct BoolExpr * 111 | BX_ToBinary(struct BoolExpr *ex) 112 | { 113 | if (BX_IS_ATOM(ex)) 114 | return BX_IncRef(ex); 115 | 116 | struct BoolExpr *temp; 117 | struct BoolExpr *y; 118 | 119 | CHECK_NULL(temp, _bx_op_transform(ex, BX_ToBinary)); 120 | CHECK_NULL_1(y, _op_binify[temp->kind](temp), temp); 121 | BX_DecRef(temp); 122 | 123 | return y; 124 | } 125 | 126 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all/bb_50x5x50_20%_0.pla: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .p 50 4 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 5 | .ob y0 y1 y2 y3 y4 6 | .type fr 7 | 001011110--00--0100-0010-10-01010101-010--01011111 00011 8 | 0-1-1010-01000100--11011-0110001010-10001010-1-1-0 00100 9 | 0111010111110110110-100101101010010001111----1-011 10000 10 | 01-0010011-001110--000-011--11--1-0100-01101--1000 00001 11 | 001011010-1100000001101--10100-010-001100111110010 00101 12 | 011-01010-10-1101110-00-1-11001-1-0000--1-1-00-000 00011 13 | 0000000011001-0000010-000110-11011001110--100-1-10 00110 14 | 00-111111-00100-100111101000-11101100--0-1110-1-10 10001 15 | -1-10011011000011--00-0011011101-1-1101110--1-001- 11100 16 | -0101100-110111-010-01110-0110011-1-1---1001011111 11000 17 | 0-111011101000-11-1--10-0001001101000010-11-111101 11001 18 | 11000000-1-01--1111-10111111----0010--1-0--1--0111 01010 19 | 00-101000011-1-10101101-1101011-0101000-111111011- 11011 20 | 1-00-11111-0010-0---000--0110-0010111--000001-0001 11011 21 | -1-1100100001--00--00001000-1-1--100-0111-00011011 11000 22 | 0-0000-010-11-1100-101-00101000111-01--11-0010-011 10000 23 | 11-1-0001100101-10-0-1-0-1100010101111-1111000-101 11101 24 | 10-01--10011111-11011-001001101100110010010-000-0- 01110 25 | 1-11010-00011101-010--101010--0111010101-11-101--1 00111 26 | 11--111-111-111-000-11000-101-1-011--1000--1111100 01111 27 | 0---0-10011101000--11001-1100-10-000011-0100011100 11110 28 | -01--11-010-1001011-0-101000100000--10111---100-1- 11101 29 | 11-1-000010--00110-011101--11-10-1-0000110100-1101 11010 30 | -0111110-100-11-110001001100001-100011110001001100 11110 31 | 11--00100-01--00-10---11-0001-00011101001011-01110 00000 32 | 1--010011-001-0000--0-11-001010001110-00-01-110-11 01101 33 | 100011--0101--1-1-0-101--001-0-101-1-1011101011-01 00111 34 | 0--0-01-10101-11-0100111111000-1-1011100-111-01111 10100 35 | 0-0110010--11101-0---1001-1001--001-110000---1011- 00100 36 | 0-1000-0--00000010-0--1011-1001011-01-00-011001111 10000 37 | 111-1101111-01001101-111--00-01011111000001-001001 11100 38 | 0--100111-1010001-0111-0-000--00-0111101111-101100 11000 39 | 00001101100-001001-1010010010011-1101-110-10-110-1 01011 40 | 0101-01-0100101000010111--0011-0011011110-111100-0 00100 41 | 000-1--100-00-1001-10-000000100-001100-10101010001 10000 42 | 10001001-0001011-1-1-0-00101110-10100---0010001--- 10111 43 | 01011000000100100000---1--11-0001011111101-01-1011 01111 44 | 1--01--00100110001-110-0-00001011---01001000110--- 10010 45 | 0-0001--01--11101010100000000010011001000-01100001 00011 46 | 0-0100110-00111100-001--11--00-1001-00-0-11-1-0-1- 00100 47 | 101-1-100-001001-010111-01--010-1-1011-01101001001 11000 48 | 0110-111011--1-010101-011-1-00100110-00-1111000-11 11001 49 | 011001011---010011-10-00-11-001000000101101101-0-1 00100 50 | 1001111-1-1111-1001-000111010-100--0111110011000-1 10111 51 | 1-1010-1-100111110010-101011-1001000111-0000--11-1 11000 52 | -00110001000010000010100010010-0-0-100-1-0111011-1 00101 53 | 1110-01100111111-1-1-110-0-110--011--01-11-0000-01 00000 54 | -01010101010-1-1-00-1111010100-1001111110110--0-00 11011 55 | 110-10000001--0-0-01001111-0011-0110110100010--111 11111 56 | 101-10111000011110000-1001-001-01111-011-0001-0100 00100 57 | .e 58 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all/bb_50x5x50_20%_1.pla: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .p 50 4 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 5 | .ob y0 y1 y2 y3 y4 6 | .type fr 7 | 1--0000-111100100100-001-00-110-0001100101-1011100 10001 8 | 0100110-100--00-00011111101--1-001101-11110000-110 01001 9 | 101000-00-001010010001100-00-100-111001000--111-01 11111 10 | 00100100-1100--011--00001001-0-1011101100-01-111-1 00110 11 | 001-10-0001100-100-0110-1-10101-00100---110101101- 10101 12 | 01011001101110111-000100-01-10-11100111011--1----0 10010 13 | 1-110-101-0-01101-1-100-1000111-0-11-00111-110100- 00101 14 | 01000-111110010011011111111110-1111-0101110100-011 01110 15 | 1-001111-00011-000-1-01110000110110-001001110100-0 11110 16 | 100-0011100010000000100-011-10-101111--01---100010 11011 17 | 01110-00-0-101-0-11100--000-100101001001001100-010 10111 18 | 1011001-1--01110001110-10--1101-10100101-0-1100010 00111 19 | 1101-10101-111-101000-01-000011-01000101-010-1-10- 01001 20 | 10-0---1-1110010-0011100110010110110111101-1000001 10010 21 | -010110-0-010101000--10-11-1--110-1-01-10001100-01 00010 22 | 011000-1111100-11110101110110-0-0101000111000-110- 00111 23 | 0---001-101-011-1---01-00-1-000011--0-111-11101-01 11101 24 | 111-1--00-0-111100-00001001101-11101-1111110-01-11 11010 25 | -1101-1101-00011101000100001-10101-1100111010110-- 01011 26 | -111-1000001--0---100011-1-001-00-10-010011-100101 10101 27 | 1-01101-1010-01010-1110-1-100-111-00100-100--11010 10100 28 | 00-011-01-01-111101-11-1000011-1-11-1-01-0-1110001 01001 29 | -00-1-1111101000-01-0100-01001-1--0-11-00001-0-0-1 01111 30 | -10-0101111-11010011-10-1-11-01010-010101000110001 10100 31 | 10100-00100-0--101101101010100--1-0--1-11-0000-10- 11100 32 | 101011010011-0111011-01-1100000---111-111111-10011 11111 33 | -000---1--101000-100-01100-0010-0010010--0111001-0 01101 34 | 0100001--0-0-101-1011-010-000--11000001-11-100011- 10110 35 | 010-11-10-11-0--0111-01--0100-000100-1-100111-1000 11100 36 | 011111000-000111-1000-100--001-00100--0-1001101001 01101 37 | 0001-0010-1101101-0-110-0101-00101-10-1000-101-101 00010 38 | 001-01-00-111-10100111110001-101-110-0-111-000-000 00011 39 | -1-000111-1-100011001101110111-1110100-100101-1-10 11000 40 | 11010010000-10-1101-10-0-0101110011111-0-10001-011 01110 41 | 010-0110--00-000111--011-1-00-010--011-001100-1001 00010 42 | 1-0101-111010-1111111-1000111-0111001101001000-100 11000 43 | -11---0-01001-00000-1010111110-000-100011-1101-110 10111 44 | 01-11--100-010100-001-00000000001-1101100001111001 10111 45 | -110101-1111101-111-110-00-01101-001-001011--111-0 11000 46 | 00-1-111100-0---0110-010-0-101-010-101-00100010101 00111 47 | 0-0111100101010----00001001-110--0111-1111-0011100 01101 48 | --00110001-1100-0-000-000-000010-00001110010000111 10000 49 | 11-01010000--011011101011-1100000101-11110011-1100 01010 50 | 100--01011-0110-1001000-10-00-00100-01100-10-01111 11101 51 | 1001-11000101101010000010101110-0-0--111101111-01- 10000 52 | --1100-0001--00-011001000000011001100111101-101000 00010 53 | 111-10-100-10001011--10101-0111110-0110-11011000-0 10110 54 | 010110011-011----010-101-001-111111--1111010011--1 00010 55 | 00-01-101101--1---10-101--0-0--1-0011010--11011100 01001 56 | 0101101000-011110010-00000111-010101-001101--0--00 00011 57 | .e 58 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all/bb_50x5x50_20%_2.pla: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .p 50 4 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 5 | .ob y0 y1 y2 y3 y4 6 | .type fr 7 | -000101111001010-100-1010--00-1--0-1100010--001011 00011 8 | -1000111100010010111000000-----011010-0-011100--00 10001 9 | 1-0-110111-01-000110-11000000011-0001101101--01001 00011 10 | 1-000--1111110000-100011001110-10-10-0100--0110011 00010 11 | 000000110-10110--11011-1001-001-1-10001-000010-000 10111 12 | 1-00-0-00110101-011-1100-000101010-110010100010010 00011 13 | 111110-111--0--0-1101001110-11-101-0-0100011111--1 01110 14 | 011010-010-00010001110-10100-1010011-01----000111- 11011 15 | 1-1-11-1000-00101111000-11-000-0001-001110-0-11111 00011 16 | 00100111--1111-10010110001100111101-01100-11011--0 11001 17 | 01010-0001110-01111-110100010101--01-00-10010-110- 00100 18 | 110-0-11-10101-01111-00101001001101011-101101-00-0 01001 19 | 10000101-0000-1-0111-010001-100000110--1101-1-1-00 10010 20 | -1-111-10-11111011101-0--00100000000010000-01---00 01111 21 | --01-11--101001011--1100-01001011--01-1-10-010-011 10110 22 | 101000-001--001100-01111-10100101111-1-1-001010111 01011 23 | 101111-01000011000-0011-00--0111-1-11001101010100- 00110 24 | 1010100100110010-0-100-1000110-000011-10010-010010 00110 25 | 000-0101-1101111010-0-11-0-011-10001-111-1-1101001 11100 26 | 10--1000000001111-11-01-0-0-01010-11-010--10100110 00110 27 | 11-0001-0-1010110-1001-0--00-000-0-001001101101111 00011 28 | 110111--11100-101101101000111001--0--001100111-111 10111 29 | 1000110011100001-101111-111111110100-001-0-00-1101 11010 30 | 010--0--110--10110------0-00-110--1101010011110110 00110 31 | 1-11001-111-0--0-1111101010010-11--1011101-00-1011 00010 32 | 0-0-110000011101-11-10-0010-01-0-1011-1-0001001011 00001 33 | 0-11-1-1101101010-010110101100101--10-10110-1110-0 00010 34 | 0-0010-0111--1110011010111111010000100010-100001-0 11001 35 | -111000110-000-101010001000-001-1--011-0-00111-101 10001 36 | 1111-0101111111011000010100-0-1--1-00010-0--01-101 00011 37 | 01-00001101010000100100-01-1100011-1--010111---010 01100 38 | -0001-011111000101101011101--0-0100011-00-101-1100 01111 39 | 101-011101101111-0100010--01-000-110-01111100-001- 01011 40 | -1-00110--01011011-10010-100010-000-111110-0011-10 10100 41 | -0010-1-0-1100-111-11100001101101011101-0000111-00 00110 42 | 111--11-01011-1-0001-11-0110000110-10-10-110000111 11100 43 | 0-10001-10010--0100----10-0011-11110001-01--001101 11101 44 | 0110-110000000011010110-0110-111011101--000-00-110 01000 45 | 0001-0111001110-01-1--11-0-1000-000011-001-1100010 00101 46 | --000100----0-110-111010101-110111-010111110010101 00100 47 | 10-10001010100111100-1001-0100011011010101-00-0111 00000 48 | -0-00001000-00-0010101111-0010000--1-00010001-1101 10001 49 | 00-0001-011001-1-1100101-01-0111101001011100100100 00111 50 | 01111001001-00101--1111-1-0100010-1010-0100001-1-1 01110 51 | 1011-0-010001100-1--0110-1001100-11111--11--11-011 01010 52 | 0111-001-01111-1-0111-11001-0-101101-010-0-01-1000 00011 53 | 111110-0110-0110-1110001101000-100--011100101111-0 10101 54 | 0010010111111011-110110010100110-11100010-11-1-000 11000 55 | 01-01110--1--100-10-011000-01--0-01010-001000000-- 00010 56 | 01-11001--000010101101-111-0010-1011111110-010-0-0 00100 57 | .e 58 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all/bb_50x5x50_20%_3.pla: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .p 50 4 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 5 | .ob y0 y1 y2 y3 y4 6 | .type fr 7 | -11100--11110-010-1011-1-110-0-11011-00-11--001111 10100 8 | 00--10001-01100-11-01-1110101-111100-1101110--00-0 00101 9 | 1010-001010110111100000011101-011-0---1101---00001 11101 10 | 00-100100-10000110110-00--000111-10001010100011010 11110 11 | 0010000100--1011-11-1010110110-000-0110000--000010 00101 12 | 0000111--1111-010-01-0110-0-1110001010100-000000-0 11000 13 | -0110-0-1--0011--100-001010-11000111001-010-010110 10000 14 | 001100--11110100-0--1--00001-100111101-110110-100- 00101 15 | 00100011000101110100--0111-001--11-000--11001-1000 01110 16 | 1-100-10011--1111-11001-000-011001001-001100101000 10000 17 | 0001010-010-100100111-110-1111110-0101001001001-01 01110 18 | 01111110--10110--00101000001-10010-110011000000000 10010 19 | 1--1111100-111010-01-1101-0010101001101-101101110- 10001 20 | 001-0110111-1-1-11-101-1000-001110100111-0011001-- 10101 21 | 0111100-1--110111-01110---100-101100000101--1010-0 10100 22 | 1001-001100--1010110111-110-0-10001--1110110-1-010 01111 23 | 1-00--11100110---11--01111010001-10-1111001-01--10 10110 24 | --1-0101000010-0-000-1011101100011101-0001-1110000 11100 25 | 00-0010-000-111110-101100000111011-00--00-00011010 10000 26 | 0101-10011000000110001-000-101111--0-000-000010101 10011 27 | 00-111010111000-11-00111-1100011--11-11-000011--11 01000 28 | ---00-010-001-00-110-1-00010-0000-1-0101-0000-1111 11110 29 | -1-100001-1-1-1110110011011-01001-1011100001-00-01 10001 30 | -0010011-101100011--0--1110-0111000100100101-111-1 10001 31 | 000001-11111101-010--0--110-01110110000-1--101-100 10100 32 | 0100001101001101-0101-1111--01--100-0001000001-110 10011 33 | 00-100-00--111-01-11010-10110-100-0-10-10011000101 00011 34 | 111-011111110-111101010--00000--101-0000-11110100- 01101 35 | -0-00-1-10-10000--11011-0--1001011100-101101--00-0 00011 36 | 11-10001-100-1000--10-1-10000011000-000-111101001- 01110 37 | 0100110000-0-0010-0-1001-0--100---111000--011-00-- 10011 38 | 10--0-011011011011-100001011-0-10-1100110101100001 10001 39 | 000101111010-0000-00-000-0011101110-00101110100111 01100 40 | --1011010---1010100000111001101-01110101011-0-001- 11110 41 | 11-0010-001011-011011110-0110-0-100111-00-10111111 01011 42 | 1111011-01-1101101001-10110---0000000001100111-100 10101 43 | --10000-010-11-110---0111101100101-0--01-1-001-00- 00000 44 | 011110-1101001011-1-00001000-0011010---0-011000-00 01100 45 | 111-1-110111001111-1110-0000110000--0-000-1010-101 01101 46 | 011001-1-00010100-1010010-0010-111-001011--110-101 10001 47 | 010--010-10-0010-0011001-1--10-0-110-011000110-100 01011 48 | -01000--00-11010111000011-0-001-00-1-0110001-0-010 11000 49 | 111001-10010100-1-11---11110011-100100010010110111 01101 50 | 0-0010000111-011-00101-000-01010101110101-10000010 01000 51 | 0001-0000010-0001-1010001110-1-1-1--0011-000-110-0 10110 52 | 01101111010-0-11100-10100-001010001-10101100011001 10001 53 | 000011--110--00--11111000010011-1--000-100-0111110 10000 54 | 101011010---10111-110110000001001--10110-0-101-0-0 10010 55 | -01-1--011-111000-0-0-01-00100-00--0010111-1101010 11100 56 | 01-011111-1-11100000110-0-0011-110010-11110-0-0010 10110 57 | .e 58 | -------------------------------------------------------------------------------- /thirdparty/espresso/test/bb_all/bb_50x5x50_20%_4.pla: -------------------------------------------------------------------------------- 1 | .i 50 2 | .o 5 3 | .p 50 4 | .ilb x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 5 | .ob y0 y1 y2 y3 y4 6 | .type fr 7 | 10001-10000-1-1-001110101-1-11111001-0110011111010 10010 8 | 1111100011-10100--1100-000-00-1011-10100111100111- 01001 9 | 110-0--100-11-01111-10-111111-10110-0-1--011011001 01101 10 | 010101--010--001-0011-01111001-0-111010-101000-010 00100 11 | 00--0101--111100010-0000-1100011110--11-000000110- 11101 12 | 0-1-0-1--10---111--1000----00-1010101110111-100-11 01000 13 | 10110-0-00101101011010011101100010001000001100-101 11111 14 | 0-101101-1-1-0-11101100--0010-0-10--1100-01-000100 01111 15 | 110000-011010-1--0-1111-0101-101101100-1001001101- 01101 16 | 10111001--10011-111-10011111101000-1-0100110-11-10 11011 17 | 1001-0--110000-11010-0--01000-10101110011-011-000- 00111 18 | 00-100--1111101001100-11000-01101--0001-111---11-- 00001 19 | 1--1111111100---110--1-1101-10011--1110--1101010-0 10001 20 | 011-100--00-0011001-110000001001-1110-010001-0111- 10010 21 | -1110-0111010001-0-0000010--1010-00110-00100-11-10 10101 22 | 001-00-000-01011-1--01101001-000100001101101010001 01000 23 | 11-1010111001011110000001-00-0101010101110110110-0 10010 24 | 000110100-10010110--101--0001001010101011-0111--01 01110 25 | 001111011-01-00110-11-10-100-11111-0-001100--0-100 10001 26 | 101011000111100011-10000-100011100-11100111-10101- 10111 27 | -1011111101-111-00111010-1-1110011-100-1001-110000 10101 28 | 1-1---1-11-00000100010001001-1-0101000110000-10001 00111 29 | 01001-110000000--00-1010100-01100-11-001001000011- 00001 30 | -0110001111100100101000-01-110111100-100111-0-110- 11110 31 | 011-000110100010-00-01110--0011111111-00101--000-0 10100 32 | 010-0-01-0100011001-011-0--0100--01-11-110111-0101 10110 33 | 01--100-00-1101101-0111111-11-00010-011-0-000--0-1 00110 34 | 01-101000-00110010-1-000-11--1000-00--0-0110111000 01111 35 | 0100110011101-011101-011000-1--0001-11011101100100 01111 36 | 10-0-01-1101-011110111000-01001111010111--0000-011 00000 37 | 00001-0-1000000100011---0-1010001110-00000-0-101-0 10011 38 | 110-0-101--001-111110-011-11-111--00---01101000110 11100 39 | 01-01011001-111110010011001-01-100-1-1000001110100 10001 40 | 11111--01100001100-----0110-010--101-001101--01110 00101 41 | 101-1-11-111-110-0001011101-01-0--1111-0--1000-000 10000 42 | -01-11-00-00111110100101101-1-10111100001-1-111100 11110 43 | 010101--1--1--0-101--11-10110111-1010-010000-10100 00000 44 | -100000-0010010--1100-1100--001010-11011011-111-1- 01101 45 | 000-0-0-1001100011-00--111100--00010101110--010111 10011 46 | 1100110-01110011101101-0-1111111-10-1001-0001011-- 10111 47 | --1-100--0111-1110-10001-0-10-10---00110110000-0-0 00101 48 | -1010100-01010-00-01-0--01000-00-1-10000--10--0-00 01111 49 | 110--0111101-100-0101011000-11-11-1-11-0101-1110-1 00011 50 | 111100010-1-10011-100011-11-101-0-10101111-11-1110 01110 51 | 1101100-11001010101100010-10-1-00-10001-1001010001 01010 52 | 0--101010000---0100-001-000-10000-1000--000-1-01-0 10111 53 | 00011-001001-111100011-0-01-10---11-1110010-11111- 10001 54 | 110-0-110-0111010--101010010011-001-11-000001-011- 11100 55 | 0-0011110100100-1010111-1-01-010001-00-0-0-0111000 10011 56 | 00011111010-10-00--1-0101-110-001110010-011-10001- 10011 57 | .e 58 | --------------------------------------------------------------------------------