-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex_logical.py
67 lines (59 loc) · 1.27 KB
/
ex_logical.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from utbp import UTBP
@UTBP
def logical_not(a):
"""
logical_not(1) == 0
logical_not(0) == 1
"""
@UTBP
def logical_or(a, b):
"""
logical_or(0, 0) == 0
logical_or(0, 1) == 1
logical_or(1, 0) == 1
logical_or(1, 1) == 1
"""
@UTBP
def logical_and(a, b):
"""
logical_and(0, 0) == 0
logical_and(0, 1) == 0
logical_and(1, 0) == 0
logical_and(1, 1) == 1
"""
@UTBP
def logical_nand(a, b):
"""
logical_nand(0, 0) == 1
logical_nand(0, 1) == 1
logical_nand(1, 0) == 1
logical_nand(1, 1) == 0
"""
@UTBP
def logical_xor(a, b):
"""
logical_xor(0, 0) == 0
logical_xor(0, 1) == 1
logical_xor(1, 0) == 1
logical_xor(1, 1) == 0
"""
@UTBP
def logical_parity(l):
"""
logical_parity((0,)) == 0
logical_parity((1,)) == 1
logical_parity((0, 0)) == 0
logical_parity((0, 1)) == 1
logical_parity((0, 0, 0)) == 0
logical_parity((0, 0, 1)) == 1
logical_parity((0, 1, 1)) == 0
"""
if __name__ == '__main__':
assert logical_not(1) == 0
assert logical_or(1, 1) == 1
assert logical_and(1, 1) == 1
assert logical_nand(1, 1) == 0
assert logical_xor(1, 1) == 0
assert logical_parity((1, 1, 1, 1, 0, 0, 1, 1)) == 0