Seven-segment segment a from BCD with don’t-cares as assumptions
Segment a of a seven-segment display, given as the minterm list Σm(D, C, B, A; 0, 2, 3, 5, 6, 7, 8, 9) with the BCD assumption that codes 10 to 15 never occur. Six don't-care cells let the Karnaugh map derive a four-term expression.
The four inputs are the bits of a binary-coded decimal digit: D is bit 8, C is bit 4, B is bit 2, A is bit 1. Segment a, the top bar, lights for the digits 0, 2, 3, 5, 6, 7, 8 and 9 and stays dark for 1 and 4. The formula is written directly as that minterm list. The assumption k1, NOT (D AND (C OR B)), states that the four bits encode a digit 0 to 9, so the six codes 10 to 15 never occur. The table has sixteen rows; the assumption column is false on the last six.
The checks run on the full function: tautology violated with the counterexample D = FALSE, C = FALSE, B = FALSE, A = TRUE; satisfiable with the witness of all four inputs FALSE. The simplifier found no law to apply to a minterm list. The converter expands it into eight four-literal terms and eight four-literal clauses, 32 literals each; the gate converters report 407 NAND and 719 NOR for that expansion. The Karnaugh map, with 6 don't-care cells from the assumption, draws four groups, four prime implicants, and derives D OR (NOT C AND NOT A) OR (C AND A) OR B, labelled equivalent within the assumptions only.
Seven-segment decoders are the classic don't-care exercise because the hardware really never sees codes above 9. The same reasoning applies to any enum stored in more bits than it needs. The thing to watch is the label: the derived expression agrees with the minterm list on the ten BCD rows only, and the engine says so in its scope annotation. If a later change lets code 10 through, the shortened decoder is no longer guaranteed, and the full sixteen-row table is the only safe specification.
D: bit 8; C: bit 4; B: bit 2; A: bit 1;
segment_a := Σm(D, C, B, A; 0, 2, 3, 5, 6, 7, 8, 9) · output
Assumptions: NOT (D AND (C OR B)) (The four bits encode a decimal digit 0 to 9 (BCD); codes 10 to 15 never occur.)
Exact checks
Truth table (16 rows)
| # | D | C | B | A | segment_a | k1 | Scope |
|---|---|---|---|---|---|---|---|
| 0 | FALSE | FALSE | FALSE | FALSE | TRUE | TRUE | in scope |
| 1 | FALSE | FALSE | FALSE | TRUE | FALSE | TRUE | in scope |
| 2 | FALSE | FALSE | TRUE | FALSE | TRUE | TRUE | in scope |
| 3 | FALSE | FALSE | TRUE | TRUE | TRUE | TRUE | in scope |
| 4 | FALSE | TRUE | FALSE | FALSE | FALSE | TRUE | in scope |
| 5 | FALSE | TRUE | FALSE | TRUE | TRUE | TRUE | in scope |
| 6 | FALSE | TRUE | TRUE | FALSE | TRUE | TRUE | in scope |
| 7 | FALSE | TRUE | TRUE | TRUE | TRUE | TRUE | in scope |
| 8 | TRUE | FALSE | FALSE | FALSE | TRUE | TRUE | in scope |
| 9 | TRUE | FALSE | FALSE | TRUE | TRUE | TRUE | in scope |
| 10 | TRUE | FALSE | TRUE | FALSE | FALSE | FALSE | excluded |
| 11 | TRUE | FALSE | TRUE | TRUE | FALSE | FALSE | excluded |
| 12 | TRUE | TRUE | FALSE | FALSE | FALSE | FALSE | excluded |
| 13 | TRUE | TRUE | FALSE | TRUE | FALSE | FALSE | excluded |
| 14 | TRUE | TRUE | TRUE | FALSE | FALSE | FALSE | excluded |
| 15 | TRUE | TRUE | TRUE | TRUE | FALSE | FALSE | excluded |
Plain-language reading
Beginnersegment_a is true exactly when the truth-table row of (D, C, B, A) is one of the rows 0, 2, 3, 5, 6, 7, 8, and 9.
In every other case, segment_a is false.
About the operators:
- Σm lists the truth-table rows (minterms) where the formula is true. Rows are numbered from 0 with the first listed input as the most significant bit.
Intermediatesegment_a is true exactly when the truth-table row of (D, C, B, A) is one of the rows 0, 2, 3, 5, 6, 7, 8, and 9.
In every other case, segment_a is false.
Advancedsegment_a is true exactly when the truth-table row of (D, C, B, A) is one of the rows 0, 2, 3, 5, 6, 7, 8, and 9 [canonical sum of minterms (DNF)].
In every other case, segment_a is false.
Formal notation: Σm(D, C, B, A; 0, 2, 3, 5, 6, 7, 8, 9)
Logic diagram
Simplification, step by step
The engine found no law that shortens this expression; it is already as short as its rewriting laws can make it.
Σm(D, C, B, A; 0, 2, 3, 5, 6, 7, 8, 9)
Karnaugh map
- cells m8, m9, m10, m11, m12, m13, m14, m15
D - cells m0, m2, m8, m10
NOT C AND NOT A - cells m5, m7, m13, m15
C AND A - cells m2, m3, m6, m7, m10, m11, m14, m15
B
6 cells excluded by the confirmed assumptions (k1) are marked don't-care. An expression derived with them is equivalent only within the assumptions.
Minterms and maxterms
segment_a(D, C, B, A) = Σm(0, 2, 3, 5, 6, 7, 8, 9)segment_a(D, C, B, A) = ΠM(1, 4, 10, 11, 12, 13, 14, 15)Variable order: D, C, B, A · 16 rows
Normal forms
Conjunctive normal form (CNF)
(D OR C OR B OR NOT A) AND (D OR NOT C OR B OR A) AND (NOT D OR C OR NOT B OR A) AND (NOT D OR C OR NOT B OR NOT A) AND (NOT D OR NOT C OR B OR A) AND (NOT D OR NOT C OR B OR NOT A) AND (NOT D OR NOT C OR NOT B OR A) AND (NOT D OR NOT C OR NOT B OR NOT A)8 clauses, 32 literals · complete · Minterm expansion ×1
Disjunctive normal form (DNF)
(D AND NOT C AND NOT B AND A) OR (D AND NOT C AND NOT B AND NOT A) OR (NOT D AND C AND B AND A) OR (NOT D AND C AND B AND NOT A) OR (NOT D AND C AND NOT B AND A) OR (NOT D AND NOT C AND B AND A) OR (NOT D AND NOT C AND B AND NOT A) OR (NOT D AND NOT C AND NOT B AND NOT A)8 terms, 32 literals · complete · Minterm expansion ×1
NAND-only and NOR-only
NAND-only form
NAND(NAND(NAND(NAND(NAND(NAND(NAND(NAND(NAND(D, D), NAND(C, C)), NAND(NAND(D, D), NAND(C, C))), NAND(NAND(NAND(B, B), NAND(A, A)), NAND(NAND(B, B), NAND(A, A)))), NAND(NAND(NAND(NAND(D, D), NAND(C, C)), NAND(NAND(D, D), NAND(C, C))), NAND(NAND(B, NAND(A, A)), NAND(B, NAND(A, A))))), NAND(NAND(NAND(NAND(NAND(D, D), NAND(C, C)), NAND(NAND(D, D), NAND(C, C))), NAND(NAND(NAND(B, B), NAND(A, A)), NAND(NAND(B, B), NAND(A, A)))), NAND(NAND(NAND(NAND(D, D), NAND(C, C)), NAND(NAND(D, D), NAND(C, C))), NAND(NAND(B, NAND(A, A)), NAND(B, NAND(A, A)))))), NAND(NAND(NAND(NAND(NAND(NAND(D, D), NAND(C, C)), NAND(NAND(D, D), NAND(C, C))), NAND(NAND(B, A), NAND(B, A))), NAND(NAND(NAND(NAND(D, D), C), NAND(NAND(D, D), C)), NAND(NAND(NAND(B, B), A), NAND(NAND(B, B), A)))), NAND(NAND(NAND(NAND(NAND(D, D), NAND(C, C)), NAND(NAND(D, D), NAND(C, C))), NAND(NAND(B, A), NAND(B, A))), NAND(NAND(NAND(NAND(D, D), C), NAND(NAND(D, D), C)), NAND(NAND(NAND(B, B), A), NAND(NAND(B, B), A)))))), NAND(NAND(NAND(NAND(NAND(NAND(NAND(D, D), NAND(C, C)), NAND(NAND(D, D), NAND(C, C))), NAND(NAND(NAND(B, B), NAND(A, A)), NAND(NAND(B, B), NAND(A, A)))), NAND(NAND(NAND(NAND(D, D), NAND(C, C)), NAND(NAND(D, D), NAND(C, C))), NAND(NAND(B, NAND(A, A)), NAND(B, NAND(A, A))))), NAND(NAND(NAND(NAND(NAND(D, D), NAND(C, C)), NAND(NAND(D, D), NAND(C, C))), NAND(NAND(NAND(B, B), NAND(A, A)), NAND(NAND(B, B), NAND(A, A)))), NAND(NAND(NAND(NAND(D, D), NAND(C, C)), NAND(NAND(D, D), NAND(C, C))), NAND(NAND(B, NAND(A, A)), NAND(B, NAND(A, A)))))), NAND(NAND(NAND(NAND(NAND(NAND(D, D), NAND(C, C)), NAND(NAND(D, D), NAND(C, C))), NAND(NAND(B, A), NAND(B, A))), NAND(NAND(NAND(NAND(D, D), C), NAND(NAND(D, D), C)), NAND(NAND(NAND(B, B), A), NAND(NAND(B, B), A)))), NAND(NAND(NAND(NAND(NAND(D, D), NAND(C, C)), NAND(NAND(D, D), NAND(C, C))), NAND(NAND(B, A), NAND(B, A))), NAND(NAND(NAND(NAND(D, D), C), NAND(NAND(D, D), C)), NAND(NAND(NAND(B, B), A), NAND(NAND(B, B), A))))))), NAND(NAND(NAND(NAND(NAND(NAND(NAND(NAND(D, D), C), NAND(NAND(D, D), C)), NAND(NAND(B, NAND(A, A)), NAND(B, NAND(A, A)))), NAND(NAND(NAND(NAND(D, D), C), NAND(NAND(D, D), C)), NAND(NAND(B, A), NAND(B, A)))), NAND(NAND(NAND(NAND(NAND(D, D), C), NAND(NAND(D, D), C)), NAND(NAND(B, NAND(A, A)), NAND(B, NAND(A, A)))), NAND(NAND(NAND(NAND(D, D), C), NAND(NAND(D, D), C)), NAND(NAND(B, A), NAND(B, A))))), NAND(NAND(NAND(NAND(NAND(D, NAND(C, C)), NAND(D, NAND(C, C))), NAND(NAND(NAND(B, B), NAND(A, A)), NAND(NAND(B, B), NAND(A, A)))), NAND(NAND(NAND(D, NAND(C, C)), NAND(D, NAND(C, C))), NAND(NAND(NAND(B, B), A), NAND(NAND(B, B), A)))), NAND(NAND(NAND(NAND(D, NAND(C, C)), NAND(D, NAND(C, C))), NAND(NAND(NAND(B, B), NAND(A, A)), NAND(NAND(B, B), NAND(A, A)))), NAND(NAND(NAND(D, NAND(C, C)), NAND(D, NAND(C, C))), NAND(NAND(NAND(B, B), A), NAND(NAND(B, B), A)))))), NAND(NAND(NAND(NAND(NAND(NAND(NAND(D, D), C), NAND(NAND(D, D), C)), NAND(NAND(B, NAND(A, A)), NAND(B, NAND(A, A)))), NAND(NAND(NAND(NAND(D, D), C), NAND(NAND(D, D), C)), NAND(NAND(B, A), NAND(B, A)))), NAND(NAND(NAND(NAND(NAND(D, D), C), NAND(NAND(D, D), C)), NAND(NAND(B, NAND(A, A)), NAND(B, NAND(A, A)))), NAND(NAND(NAND(NAND(D, D), C), NAND(NAND(D, D), C)), NAND(NAND(B, A), NAND(B, A))))), NAND(NAND(NAND(NAND(NAND(D, NAND(C, C)), NAND(D, NAND(C, C))), NAND(NAND(NAND(B, B), NAND(A, A)), NAND(NAND(B, B), NAND(A, A)))), NAND(NAND(NAND(D, NAND(C, C)), NAND(D, NAND(C, C))), NAND(NAND(NAND(B, B), A), NAND(NAND(B, B), A)))), NAND(NAND(NAND(NAND(D, NAND(C, C)), NAND(D, NAND(C, C))), NAND(NAND(NAND(B, B), NAND(A, A)), NAND(NAND(B, B), NAND(A, A)))), NAND(NAND(NAND(D, NAND(C, C)), NAND(D, NAND(C, C))), NAND(NAND(NAND(B, B), A), NAND(NAND(B, B), A))))))))407 gates · verified equivalent on every row
NOR-only form
NOR(NOR(NOR(NOR(NOR(NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A)))), NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A))))), NOR(NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A)))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))), NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A)))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))))), NOR(NOR(NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A)))), NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A))))), NOR(NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A)))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))), NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A)))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A)))))))), NOR(NOR(NOR(NOR(NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A))))), NOR(NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A)))))), NOR(NOR(NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))), NOR(NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))))), NOR(NOR(NOR(NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A))))), NOR(NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A)))))), NOR(NOR(NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))), NOR(NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))))))), NOR(NOR(NOR(NOR(NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A)))), NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A))))), NOR(NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A)))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))), NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A)))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))))), NOR(NOR(NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A)))), NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A))))), NOR(NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A)))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))), NOR(NOR(NOR(NOR(D, C), NOR(D, C)), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A)))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A)))))))), NOR(NOR(NOR(NOR(NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A))))), NOR(NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A)))))), NOR(NOR(NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))), NOR(NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))))), NOR(NOR(NOR(NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A))))), NOR(NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), A), NOR(NOR(B, B), A))), NOR(NOR(NOR(D, NOR(C, C)), NOR(D, NOR(C, C))), NOR(NOR(NOR(B, B), NOR(A, A)), NOR(NOR(B, B), NOR(A, A)))))), NOR(NOR(NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))), NOR(NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, A), NOR(B, A))), NOR(NOR(NOR(NOR(D, D), C), NOR(NOR(D, D), C)), NOR(NOR(B, NOR(A, A)), NOR(B, NOR(A, A))))))))))719 gates · verified equivalent on every row
The same rule as code
Python
# -*- coding: utf-8 -*-
# Generated by Tangibool (tangibool.python/1). Do not edit by hand; regenerate from the source revision.
# Model: not stated
# Source revision: reference
# Interpretation status: not stated
"""Tangibool evaluator (decision model).
Generated deterministically from the validated Boolean model; it evaluates exactly that
model. It does not establish that the model is a complete, legal, or safe statement of a
real-world rule, and evaluating examples does not verify the rule.
Source revision: reference
Interpretation status: not stated
Exporter: 1.0.0 (format tangibool.python/1; engine 1.0.0; semantics tangibool-semantics/1)
Logic digest: fa0a837018d065810261a99bf9b01e2e337b932d2626d640db3cd91cd5f406dc
Assumptions digest: 358b5df2f94f91c39cac1783c9c1647a33fa8d02d2026300c71af6a6606a1a92
Inputs (dict keys, declared order) and generated parameter names:
'D' -> input_D
'C' -> input_C
'B' -> input_B
'A' -> input_A
Outputs (declared order) and their functions:
'segment_a' -> output_segment_a(inputs)
Assumptions (the declared scope, checked by in_scope(inputs)):
'k1': NOT (D AND (C OR B))
Input contract:
Every required input must be exactly True or False (type(value) is bool). Missing
inputs, None, strings, integers (including 0 and 1), and keys that are not declared
inputs raise InputError before anything is evaluated, including inputs that a
short-circuiting operator would never read. Results are always bool.
Scope:
Decision functions raise OutOfScopeError when the inputs violate an assumption; an
out-of-scope assignment is never turned into a False result. Pass check_scope=False
to evaluate without the scope check, and use in_scope(inputs) to test it separately.
Usage:
import tangibool_model as model
model.evaluate({'D': False, 'C': False, 'B': False, 'A': False})
# -> {'segment_a': True}
model.output_segment_a({'D': False, 'C': False, 'B': False, 'A': False})
# -> True
model.evaluate({'D': 1, 'C': False, 'B': False, 'A': False})
# raises InputError: 1 is an int, not a bool
"""
import collections.abc as _abc
from typing import Dict, Mapping, Tuple
__all__ = [
"MODEL_INFO",
"IDENTIFIER_MAP",
"INPUT_NAMES",
"OUTPUT_NAMES",
"ASSUMPTIONS",
"InputError",
"OutOfScopeError",
"minterm_index",
"in_scope",
"evaluate",
"output_segment_a",
"assumption_k1",
]
MODEL_INFO = {
"format": "tangibool.python/1",
"mode": "decision",
"model": None,
"revision": "reference",
"interpretation": None,
"exporter": "1.0.0",
"engine_version": "1.0.0",
"semantics_version": "tangibool-semantics/1",
"logic_digest": "fa0a837018d065810261a99bf9b01e2e337b932d2626d640db3cd91cd5f406dc",
"assumptions_digest": "358b5df2f94f91c39cac1783c9c1647a33fa8d02d2026300c71af6a6606a1a92",
"primary_output": "segment_a",
"unused_inputs": (),
"subcircuits": (),
}
# Stable ID -> generated identifier (reversible mapping; names are exact, escaped strings).
IDENTIFIER_MAP = {
"v_7da2abdb16e1": {"kind": "input", "name": "D", "identifier": "input_D"},
"v_564a2130f32e": {"kind": "input", "name": "C", "identifier": "input_C"},
"v_6de50780b905": {"kind": "input", "name": "B", "identifier": "input_B"},
"v_4270e4ecab98": {"kind": "input", "name": "A", "identifier": "input_A"},
"f_5b4b17b0dce7": {"kind": "output", "name": "segment_a", "identifier": "output_segment_a"},
"f_265ee8e74dc1": {"kind": "assumption", "name": "k1", "identifier": "assumption_k1"},
}
INPUT_NAMES = ("D", "C", "B", "A")
OUTPUT_NAMES = ("segment_a",)
ASSUMPTIONS = (
{"name": "k1", "id": "f_265ee8e74dc1", "formula": "NOT (D AND (C OR B))", "description": "The four bits encode a decimal digit 0 to 9 (BCD); codes 10 to 15 never occur."},
)
_DECLARED_INPUTS = frozenset(INPUT_NAMES)
_SCOPE_INPUTS = ("D", "C", "B")
_ASSUMPTION_FORMULAS = {entry["name"]: entry["formula"] for entry in ASSUMPTIONS}
class InputError(ValueError):
"""Raised when inputs are missing, undeclared, or not exactly True/False.
Every required input must satisfy type(value) is bool. Missing inputs, None, strings,
integers (including 0 and 1), and keys that are not declared inputs are rejected before
anything is evaluated. A missing input is never treated as False. The individual problems
are listed in the problems attribute.
"""
def __init__(self, problems):
self.problems = tuple(problems)
super().__init__("Invalid inputs: " + "; ".join(self.problems))
class OutOfScopeError(ValueError):
"""Raised when the inputs violate the model's assumptions (its declared scope).
Outside its assumptions the rule has no decision: this error is never a False result.
The names of the violated assumptions are in the violated attribute.
"""
def __init__(self, violated):
self.violated = tuple(violated)
details = ", ".join(name + " (" + _ASSUMPTION_FORMULAS.get(name, "?") + ")" for name in self.violated)
super().__init__(
"Out of scope: the inputs violate "
+ ("assumption " if len(self.violated) == 1 else "assumptions ")
+ details
+ ". The rule has no decision outside its assumptions; this is not a False result."
)
def _short_repr(value: object) -> str:
text = repr(value)
return text if len(text) <= 60 else text[:57] + "..."
def _checked_inputs(inputs: Mapping[str, bool], required: Tuple[str, ...], check_scope: bool) -> Dict[str, bool]:
"""Validate inputs strictly before anything is evaluated and return a plain copy."""
if type(check_scope) is not bool:
raise TypeError("check_scope must be True or False")
if not isinstance(inputs, _abc.Mapping):
raise InputError(["inputs must be a mapping from input names to True/False, got " + type(inputs).__name__])
problems = []
for key in inputs:
if type(key) is not str or key not in _DECLARED_INPUTS:
declared = ", ".join(repr(name) for name in INPUT_NAMES) or "none"
problems.append("undeclared input " + _short_repr(key) + " (declared inputs: " + declared + ")")
needed = tuple(required) + (_SCOPE_INPUTS if check_scope else ())
for name in needed:
if name not in inputs:
problems.append("missing required input " + repr(name))
for key, value in inputs.items():
if type(key) is str and key in _DECLARED_INPUTS and type(value) is not bool:
problems.append(
"input " + repr(key) + " must be True or False (type bool), got "
+ type(value).__name__ + " " + _short_repr(value)
)
if problems:
raise InputError(list(dict.fromkeys(problems)))
return dict(inputs.items())
def _require_bool_args(function: str, pairs: Tuple[Tuple[str, object], ...]) -> None:
problems = [
"argument " + repr(name) + " of " + function + " must be True or False (type bool), got "
+ type(value).__name__ + " " + _short_repr(value)
for name, value in pairs
if type(value) is not bool
]
if problems:
raise InputError(problems)
def minterm_index(*values: bool) -> int:
"""Row index of an assignment over a declared variable order.
The first value is the most significant bit, so all-False is row 0. Used for indexed
minterm (sum) and maxterm (product) forms.
"""
index = 0
for value in values:
if type(value) is not bool:
raise InputError(["minterm_index() takes True/False values, got " + type(value).__name__ + " " + _short_repr(value)])
index = index * 2 + (1 if value else 0)
return index
def _scope_values(values: Dict[str, bool]) -> Tuple[Tuple[str, bool], ...]:
"""Value of every enabled, confirmed assumption for validated inputs, in declared order."""
assumption_k1_value = _compute_assumption_k1(values["D"], values["C"], values["B"])
return (
("k1", assumption_k1_value),
)
def _require_in_scope(values: Dict[str, bool]) -> None:
violated = tuple(name for name, holds in _scope_values(values) if not holds)
if violated:
raise OutOfScopeError(violated)
def in_scope(inputs: Mapping[str, bool]) -> bool:
"""True when the inputs satisfy every assumption (the model's declared scope).
Requires the inputs the assumptions read; raises InputError for invalid inputs.
"""
values = _checked_inputs(inputs, (), True)
return all(holds for _, holds in _scope_values(values))
# ---- Formula bodies (inputs are validated by the public functions below) ----
def _compute_output_segment_a(input_D: bool, input_C: bool, input_B: bool, input_A: bool) -> bool:
"""Decision output 'segment_a': \u03a3m(D, C, B, A; 0, 2, 3, 5, 6, 7, 8, 9)"""
return minterm_index(input_D, input_C, input_B, input_A) in (0, 2, 3, 5, 6, 7, 8, 9)
def _compute_assumption_k1(input_D: bool, input_C: bool, input_B: bool) -> bool:
"""Assumption 'k1': NOT (D AND (C OR B))"""
return not (input_D and (input_C or input_B))
# ---- Public API ----
def output_segment_a(inputs: Mapping[str, bool], *, check_scope: bool = True) -> bool:
"""Decision output 'segment_a' (stable ID f_5b4b17b0dce7).
'segment_a' := \u03a3m(D, C, B, A; 0, 2, 3, 5, 6, 7, 8, 9)
Required inputs: 'D', 'C', 'B', 'A'; with check_scope=True also 'D', 'C', 'B' (read by the assumptions).
Raises InputError for missing, undeclared, or non-bool inputs, and OutOfScopeError
when check_scope is True and the inputs violate an assumption.
"""
values = _checked_inputs(inputs, ("D", "C", "B", "A"), check_scope)
if check_scope:
_require_in_scope(values)
output_segment_a_value = _compute_output_segment_a(values["D"], values["C"], values["B"], values["A"])
return output_segment_a_value
def evaluate(inputs: Mapping[str, bool], *, check_scope: bool = True) -> Dict[str, bool]:
"""Evaluate every output (declared order); each output is computed once.
Required inputs: 'D', 'C', 'B', 'A'; with check_scope=True also 'D', 'C', 'B' (read by the assumptions).
Raises InputError for missing, undeclared, or non-bool inputs, and OutOfScopeError
when check_scope is True and the inputs violate an assumption.
"""
values = _checked_inputs(inputs, ("D", "C", "B", "A"), check_scope)
if check_scope:
_require_in_scope(values)
output_segment_a_value = _compute_output_segment_a(values["D"], values["C"], values["B"], values["A"])
return {
"segment_a": output_segment_a_value,
}
def assumption_k1(inputs: Mapping[str, bool]) -> bool:
"""Assumption 'k1' (stable ID f_265ee8e74dc1).
'k1' := NOT (D AND (C OR B))
Description: The four bits encode a decimal digit 0 to 9 (BCD); codes 10 to 15 never occur.
Required inputs: 'D', 'C', 'B'.
Raises InputError for missing, undeclared, or non-bool inputs.
"""
values = _checked_inputs(inputs, ("D", "C", "B"), False)
assumption_k1_value = _compute_assumption_k1(values["D"], values["C"], values["B"])
return assumption_k1_value
PostgreSQL
-- Tangibool PostgreSQL export (tangibool.postgresql/1)
-- Target: PostgreSQL 16 or later with typed boolean inputs; tested with PostgreSQL 18.3 (PGlite 0.5.8).
-- Not a claim of compatibility with other SQL dialects.
-- Model: not stated
-- Source revision: reference
-- Interpretation status: not stated
-- Exporter: 1.0.0 (engine 1.0.0; semantics tangibool-semantics/1)
-- Logic digest: fa0a837018d065810261a99bf9b01e2e337b932d2626d640db3cd91cd5f406dc
-- Assumptions digest: 358b5df2f94f91c39cac1783c9c1647a33fa8d02d2026300c71af6a6606a1a92
-- Mode: decision
--
-- Read-only: this file contains only WITH / VALUES / SELECT statements. No DDL, DML,
-- procedures, credentials, network access, or database changes. The expressions are pure
-- Boolean expressions, so their result does not depend on SQL evaluation order.
--
-- NON-NULL INPUT PRECONDITION: NULL is not a truth value of this rule. Every fragment below
-- is defined only when every input column it reads is a non-NULL boolean. The guard template
-- (section 2) marks any NULL input as 'invalid_input' and any row that violates the
-- assumptions as 'out_of_scope', and fills output columns only for 'ok' rows; a NULL in an
-- output column of another row is an envelope marker, not a third truth value. Never wrap
-- the fragments in COALESCE(..., FALSE) or otherwise choose a meaning for unknown inputs.
-- This evaluates the supplied model; it does not show that the model is a complete, legal,
-- or safe statement of a real-world rule.
--
-- Input columns (stable ID: name -> column):
-- v_7da2abdb16e1: D -> "in_D"
-- v_564a2130f32e: C -> "in_C"
-- v_6de50780b905: B -> "in_B"
-- v_4270e4ecab98: A -> "in_A"
-- Output columns:
-- f_5b4b17b0dce7: segment_a -> "out_segment_a"
-- Assumptions (scope K; exported separately and never folded into an output):
-- f_265ee8e74dc1: k1 -> "assumption_k1": NOT (D AND (C OR B))
-- The four bits encode a decimal digit 0 to 9 (BCD); codes 10 to 15 never occur.
-- ----------------------------------------------------------------------------------------------
-- 1. Expression fragments (parenthesised; non-NULL boolean inputs required)
-- ----------------------------------------------------------------------------------------------
--
-- [out_segment_a] output segment_a (stable ID f_5b4b17b0dce7)
-- segment_a := \u03a3m(D, C, B, A; 0, 2, 3, 5, 6, 7, 8, 9)
-- PRECONDITION: "in_D", "in_C", "in_B", "in_A" are non-NULL booleans.
-- (((NOT "in_D") AND (NOT "in_C") AND (NOT "in_B") AND (NOT "in_A")) OR ((NOT "in_D") AND (NOT "in_C") AND "in_B" AND (NOT "in_A")) OR ((NOT "in_D") AND (NOT "in_C") AND "in_B" AND "in_A") OR ((NOT "in_D") AND "in_C" AND (NOT "in_B") AND "in_A") OR ((NOT "in_D") AND "in_C" AND "in_B" AND (NOT "in_A")) OR ((NOT "in_D") AND "in_C" AND "in_B" AND "in_A") OR ("in_D" AND (NOT "in_C") AND (NOT "in_B") AND (NOT "in_A")) OR ("in_D" AND (NOT "in_C") AND (NOT "in_B") AND "in_A"))
--
-- [assumption_k1] assumption k1 (stable ID f_265ee8e74dc1)
-- k1 := NOT (D AND (C OR B))
-- PRECONDITION: "in_D", "in_C", "in_B" are non-NULL booleans.
-- (NOT ("in_D" AND ("in_C" OR "in_B")))
--
-- [K] scope (conjunction of the assumptions):
-- (NOT ("in_D" AND ("in_C" OR "in_B")))
--
-- ----------------------------------------------------------------------------------------------
-- 2. Guard template (read-only SELECT over an inputs list)
-- ----------------------------------------------------------------------------------------------
-- Replace the example rows between the markers with your own rows, or replace the inputs
-- CTE with a SELECT that provides the boolean columns listed in the header. status is
-- 'invalid_input' when any input is NULL, 'out_of_scope' when the assumptions are false, and
-- 'ok' otherwise; output columns are filled only for 'ok' rows (NULL elsewhere is an
-- envelope marker). Assumption columns are shown for rows with complete inputs.
WITH inputs ("row_id", "in_D", "in_C", "in_B", "in_A") AS (
-- tangibool:example-rows:begin
VALUES
(1, FALSE, FALSE, FALSE, FALSE),
(2, FALSE, FALSE, FALSE, TRUE),
(3, FALSE, FALSE, TRUE, FALSE),
(4, FALSE, FALSE, TRUE, TRUE),
(5, FALSE, TRUE, FALSE, FALSE),
(6, FALSE, TRUE, FALSE, TRUE),
(7, FALSE, TRUE, TRUE, FALSE),
(8, FALSE, TRUE, TRUE, TRUE),
(9, TRUE, FALSE, FALSE, FALSE),
(10, TRUE, FALSE, FALSE, TRUE),
(11, TRUE, FALSE, TRUE, FALSE),
(12, TRUE, FALSE, TRUE, TRUE),
(13, TRUE, TRUE, FALSE, FALSE),
(14, TRUE, TRUE, FALSE, TRUE),
(15, TRUE, TRUE, TRUE, FALSE),
(16, TRUE, TRUE, TRUE, TRUE),
(17, NULL::boolean, FALSE, FALSE, FALSE)
-- tangibool:example-rows:end
),
checked AS (
SELECT
inputs.*,
CASE
WHEN "in_D" IS NULL OR "in_C" IS NULL OR "in_B" IS NULL OR "in_A" IS NULL THEN 'invalid_input'
WHEN NOT (NOT ("in_D" AND ("in_C" OR "in_B"))) THEN 'out_of_scope'
ELSE 'ok'
END AS "status"
FROM inputs
)
SELECT
"row_id",
"in_D",
"in_C",
"in_B",
"in_A",
"status",
CASE WHEN "status" <> 'invalid_input' THEN (NOT ("in_D" AND ("in_C" OR "in_B"))) END AS "assumption_k1",
CASE WHEN "status" = 'ok' THEN (((NOT "in_D") AND (NOT "in_C") AND (NOT "in_B") AND (NOT "in_A")) OR ((NOT "in_D") AND (NOT "in_C") AND "in_B" AND (NOT "in_A")) OR ((NOT "in_D") AND (NOT "in_C") AND "in_B" AND "in_A") OR ((NOT "in_D") AND "in_C" AND (NOT "in_B") AND "in_A") OR ((NOT "in_D") AND "in_C" AND "in_B" AND (NOT "in_A")) OR ((NOT "in_D") AND "in_C" AND "in_B" AND "in_A") OR ("in_D" AND (NOT "in_C") AND (NOT "in_B") AND (NOT "in_A")) OR ("in_D" AND (NOT "in_C") AND (NOT "in_B") AND "in_A")) END AS "out_segment_a"
FROM checked
ORDER BY "row_id";
SMT-LIB
; Tangibool SMT-LIB export (tangibool.smtlib/1) ; Profile: SMT-LIB 2.6 Boolean subset (QF_UF): Bool constants, define-fun, let, push/pop, assert, check-sat, echo. ; Tested with Z3 5.1.0 (z3-solver 5.2.0, WebAssembly build). ; Model: not stated ; Source revision: reference ; Interpretation status: not stated ; Exporter: 1.0.0 (engine 1.0.0; semantics tangibool-semantics/1) ; Logic digest: fa0a837018d065810261a99bf9b01e2e337b932d2626d640db3cd91cd5f406dc ; Assumptions digest: 358b5df2f94f91c39cac1783c9c1647a33fa8d02d2026300c71af6a6606a1a92 ; Mode: decision ; ; Reading results: each query block states what sat and unsat mean for its question. A sat ; answer comes with a witness or counterexample (ask for it with (get-model) after sat only); ; unsat settles that scoped query and is solver-checked, not an independently checked proof ; certificate; unknown settles nothing. Blocks are scoped with push/pop, so assertions never ; accumulate across questions. This checks the supplied model, not whether it is a complete, ; legal, or safe statement of a real-world rule. ; ; Symbols (stable ID: name -> symbol): ; v_7da2abdb16e1: D -> in_D ; v_564a2130f32e: C -> in_C ; v_6de50780b905: B -> in_B ; v_4270e4ecab98: A -> in_A ; f_5b4b17b0dce7: segment_a -> out_segment_a ; f_265ee8e74dc1: k1 -> assumption_k1 (set-option :produce-models true) (set-info :smt-lib-version 2.6) (set-logic QF_UF) ; ---- Inputs (declared order) (declare-const in_D Bool) ; D (declare-const in_C Bool) ; C (declare-const in_B Bool) ; B (declare-const in_A Bool) ; A ; ---- Outputs (dependencies first) ; output segment_a (stable ID f_5b4b17b0dce7): \u03a3m(D, C, B, A; 0, 2, 3, 5, 6, 7, 8, 9) (define-fun out_segment_a () Bool (or (and (not in_D) (not in_C) (not in_B) (not in_A)) (and (not in_D) (not in_C) in_B (not in_A)) (and (not in_D) (not in_C) in_B in_A) (and (not in_D) in_C (not in_B) in_A) (and (not in_D) in_C in_B (not in_A)) (and (not in_D) in_C in_B in_A) (and in_D (not in_C) (not in_B) (not in_A)) (and in_D (not in_C) (not in_B) in_A))) ; ---- Assumptions (the scope K; never folded into an output) ; assumption k1 (stable ID f_265ee8e74dc1): NOT (D AND (C OR B)) ; The four bits encode a decimal digit 0 to 9 (BCD); codes 10 to 15 never occur. (define-fun assumption_k1 () Bool (not (and in_D (or in_C in_B)))) ; K: conjunction of the enabled, confirmed assumptions (true when there are none) (define-fun K () Bool assumption_k1) ; ---- Definitions only: nothing is asserted and no check is run. ; Add (assert ...) and (check-sat) inside (push 1) ... (pop 1) to ask a question.
LaTeX
segment_a = \sum m_{(D, C, B, A)}(0, 2, 3, 5, 6, 7, 8, 9)The common slip
Reading the four-term result as equivalent to the original on all sixteen rows. It is not: the groups use the six don't-care cells, and the engine marks the result equivalent within the assumptions only. The scope annotation on the map is the warning; remove the assumption and the map must be redrawn.
Questions
Where do the don't-cares come from?
Only from the stated assumption k1. The engine never guesses don't-cares; it marks as don't-care exactly the cells the confirmed assumptions exclude, six here, and reports the count. Without an assumption the map works on all sixteen rows as given.
Why are the gate counts so large?
The converter builds gates from the expanded eight-term form, not from the map's four-term result, and the mechanical construction duplicates inverters. 407 NAND and 719 NOR gates are properties of that construction; they are not a claim about the fewest gates possible.
Related
Guides
Tools
- Truth table generator: any Boolean expression, up to 12 variables, with intermediate columns
- Boolean algebra calculator and simplifier with steps (every law named and verified)
- Karnaugh map solver: 2 to 4 variables, groups, SOP and POS, don’t-cares from assumptions
See also
- BCD digit greater than five: four-variable K-map with don’t-cares
- Don’t-care condition: meaning and examples
- Karnaugh map solver: 2 to 4 variables, groups, SOP and POS, don’t-cares from assumptions
- Assumption (domain constraint): meaning and examples
- Inconsistent assumptions make every test pass
- Minterm expansion: the canonical sum of products (Σm)
Worked examples
Generated from the Tangibool engine, semantics tangibool-semantics/1, engine 1.0.0, build . Every table, map, simplification and verdict on these pages was computed by the Tangibool engine when the site was built, and every claim was re-checked by the same exact checker the app uses. Limits are stated where they apply. © 2026 Foreranger LTD.