Threads
python3 ( 828335 ) - python3 ( 828335 ) stack: <module>(boolean_algebra/karnaugh_map_simplification.py:7)
"""
https://en.wikipedia.org/wiki/Karnaugh_map
https://www.allaboutcircuits.com/technical-articles/karnaugh-map-boolean-algebraic-simplification-technique
"""
def simplify_kmap(kmap: list[list[int]]) -> str:
"""
Simplify the Karnaugh map.
>>> simplify_kmap(kmap=[[0, 1], [1, 1]])
"A'B + AB' + AB"
>>> simplify_kmap(kmap=[[0, 0], [0, 0]])
''
>>> simplify_kmap(kmap=[[0, 1], [1, -1]])
"A'B + AB' + AB"
>>> simplify_kmap(kmap=[[0, 1], [1, 2]])
"A'B + AB' + AB"
>>> simplify_kmap(kmap=[[0, 1], [1, 1.1]])
"A'B + AB' + AB"
>>> simplify_kmap(kmap=[[0, 1], [1, 'a']])
"A'B + AB' + AB"
"""
simplified_f = []
for a, row in enumerate(kmap):
for b, item in enumerate(row):
if item:
term = ("A" if a else "A'") + ("B" if b else "B'")
simplified_f.append(term)
return " + ".join(simplified_f)
def main() -> None:
"""
Main function to create and simplify a K-Map.
>>> main()
[0, 1]
[1, 1]
Simplified Expression:
A'B + AB' + AB
"""
kmap = [[0, 1], [1, 1]]
# Manually generate the product of [0, 1] and [0, 1]
for row in kmap:
print(row)
print("Simplified Expression:")
print(simplify_kmap(kmap))
if __name__ == "__main__":
main()
print(f"{simplify_kmap(kmap=[[0, 1], [1, 1]]) = }")
Variables All
| No. | From | Name | Value |
|---|---|---|---|
| NA | NA | NA | NA |
| Process | Thread Filter |
|---|---|
| 828335 python3 | 828335 python3 |
| No. | PN | PID | TID | TN | Message |
|---|---|---|---|---|---|
| 1 | python3 | 828335 | 828335 | python3 | [0, 1] |
| 2 | python3 | 828335 | 828335 | python3 | [1, 1] |
| 3 | python3 | 828335 | 828335 | python3 | Simplified Expression: |
| 4 | python3 | 828335 | 828335 | python3 | A'B + AB' + AB |
| 5 | python3 | 828335 | 828335 | python3 | simplify_kmap(kmap=[[0, 1], [1, 1]]) = "A'B + AB' + AB" |
| END | 0 | 0 | 0 | 0 | 0 |
×
Commands and Shortcuts
| No. | Command | Shortcuts | Description |
|---|---|---|---|
| 1 | GB | Alt + LEFT, Alt + A | Go Backward |
| 2 | GF | Alt + RIGHT, Alt + D | Go Foreward |
| 3 | PPE | Alt + UP, Alt + W | Previous Process End |
| 4 | NPS | Alt + DOWN, Alt + S | Next Process Start |
| 5 | PB | Ctrl + LEFT, Ctrl + A | current Process Backward |
| 6 | PF | Ctrl + RIGHT, Ctrl + D | current Process Foreward |
| 7 | PPTE | Ctrl + UP, Ctrl + W | go to current Process's Previous Thread's End |
| 8 | PNTS | Ctrl + DOWN, Ctrl + S | go to current Process's Next Thread's Start |
| 9 | TB | LEFT, A | current Thread Backward |
| 10 | TF | RIGHT, D | current Thread Foreward |
| 11 | LU | UP, W | go Line Up of current code block in current thread |
| 12 | LD | DOWN, S | go Line Down of current code block in current thread |
| 13 | LP | Shift + UP, Shift + W | go to the occurrence of current line in Previous Loop |
| 14 | LD | Shift + DOWN, Shift + S | go to the occurrence of current line in Next Loop |
| 15 | BS | Home | go to code Block Start |
| 16 | BE | End | go to code Block End |
| Project: | algorithms-py |
| Update: | 20240917 |
| Commit: | 77bbe584 |
| Source Code: | boolean_algebra.karnaugh_map_simplification |
| Runtime: | Python3.12 |
| System: | MySystemD |
| Kernel: | Linux5.10.211 |
| Cpu: | Intel:Corei7-7700K |
| Machine: | AwesomeMachine |