-
Notifications
You must be signed in to change notification settings - Fork 11
/
mathblool.py
64 lines (50 loc) · 1 KB
/
mathblool.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
#!/usr/bin/env python
# Arithmetric representation of boolean functions
# Author Dario Clavijo 2019
# The math will always work for input domain [0,1]
def AND(a, b):
print("AND", a, b)
return a * b
def XOR(a, b):
print("XOR", a, b)
return abs(a - b)
def NOT(a):
print("NOT", a)
return 1 - a
def OR(a, b):
print("OR", a, b)
return abs(a - b) + (a * b)
def NOR(a, b):
print("NOR", a, b)
return 1 - (abs(a - b) + (a * b))
def NAND(a, b):
print("NAND", a, b)
return 1 - (a * b)
print("----------")
print(NOT(0))
print(NOT(1))
print("----------")
print(AND(0, 0))
print(AND(0, 1))
print(AND(1, 0))
print(AND(1, 1))
print("----------")
print(XOR(0, 0))
print(XOR(0, 1))
print(XOR(1, 0))
print(XOR(1, 1))
print("----------")
print(OR(0, 0))
print(OR(0, 1))
print(OR(1, 0))
print(OR(1, 1))
print("----------")
print(NOR(0, 0))
print(NOR(0, 1))
print(NOR(1, 0))
print(NOR(1, 1))
print("----------")
print(NAND(0, 0))
print(NAND(0, 1))
print(NAND(1, 0))
print(NAND(1, 1))