🧠 ANN Logic Gates — Complete Step-by-Step Mathematics
Every gate is calculated using all four possible binary input combinations: (0,0), (0,1), (1,0), (1,1).
1. Basic ANN Neuron Formula
y = Activation(z)
For this demonstration we use a Step Activation Function:
If z < 0 → y = 0
x₁, x₂ = inputs
w₁, w₂ = weights
b = bias
z = weighted sum
y = final output
2. Select a Logic Gate
🔵 AND Gate — ANN Mathematics
AND produces 1 only when both inputs are 1.
w₂ = 1
b = -1.5
z = x₁ + x₂ - 1.5
| x₁ | x₂ | Calculation | z | Output |
|---|---|---|---|---|
| 0 | 0 | (1×0)+(1×0)-1.5 | -1.5 | 0 |
| 0 | 1 | (1×0)+(1×1)-1.5 | -0.5 | 0 |
| 1 | 0 | (1×1)+(1×0)-1.5 | -0.5 | 0 |
| 1 | 1 | (1×1)+(1×1)-1.5 | 0.5 | 1 |
Step 1 — Weighted Sum
z = 0 + 0 - 1.5
z = -1.5
Step 2 — Activation
y = 0
Step 1 — Weighted Sum
z = 0 + 1 - 1.5
z = -0.5
Step 2 — Activation
y = 0
Step 1 — Weighted Sum
z = 1 + 0 - 1.5
z = -0.5
Step 2 — Activation
y = 0
Step 1 — Weighted Sum
z = 1 + 1 - 1.5
z = 0.5
Step 2 — Activation
y = 1
🟢 OR Gate — ANN Mathematics
OR produces 1 when at least one input is 1.
w₂ = 1
b = -0.5
z = x₁ + x₂ - 0.5
| x₁ | x₂ | Calculation | z | Output |
|---|---|---|---|---|
| 0 | 0 | 0+0-0.5 | -0.5 | 0 |
| 0 | 1 | 0+1-0.5 | 0.5 | 1 |
| 1 | 0 | 1+0-0.5 | 0.5 | 1 |
| 1 | 1 | 1+1-0.5 | 1.5 | 1 |
z = 0+0-0.5
z = -0.5
z < 0
y = 0
z = 0+1-0.5
z = 0.5
z ≥ 0
y = 1
z = 1+0-0.5
z = 0.5
y = 1
z = 1+1-0.5
z = 1.5
y = 1
🟡 NOT Gate — ANN Mathematics
NOT has only one actual input. Therefore, the four two-input combinations are not applicable to a standard NOT gate.
w₂ = 0
b = 0.5
z = -x₁ + 0x₂ + 0.5
| x₁ | x₂ | Calculation | z | Output |
|---|---|---|---|---|
| 0 | 0 | -(0)+(0×0)+0.5 | 0.5 | 1 |
| 0 | 1 | -(0)+(0×1)+0.5 | 0.5 | 1 |
| 1 | 0 | -(1)+(0×0)+0.5 | -0.5 | 0 |
| 1 | 1 | -(1)+(0×1)+0.5 | -0.5 | 0 |
z = 0.5
y = 1
z = 0.5
y = 1
z = -0.5
y = 0
z = -0.5
y = 0
🟠 NAND Gate — ANN Mathematics
NAND is the opposite of AND.
w₂ = -1
b = 1.5
z = -x₁ - x₂ + 1.5
| x₁ | x₂ | Calculation | z | Output |
|---|---|---|---|---|
| 0 | 0 | 0+0+1.5 | 1.5 | 1 |
| 0 | 1 | 0-1+1.5 | 0.5 | 1 |
| 1 | 0 | -1+0+1.5 | 0.5 | 1 |
| 1 | 1 | -1-1+1.5 | -0.5 | 0 |
z = 1.5
y = 1
z = 0-1+1.5
z = 0.5
y = 1
z = -1+0+1.5
z = 0.5
y = 1
z = -1-1+1.5
z = -0.5
y = 0
🔴 NOR Gate — ANN Mathematics
NOR produces 1 only when both inputs are 0.
w₂ = -1
b = 0.5
z = -x₁ - x₂ + 0.5
| x₁ | x₂ | Calculation | z | Output |
|---|---|---|---|---|
| 0 | 0 | 0+0+0.5 | 0.5 | 1 |
| 0 | 1 | 0-1+0.5 | -0.5 | 0 |
| 1 | 0 | -1+0+0.5 | -0.5 | 0 |
| 1 | 1 | -1-1+0.5 | -1.5 | 0 |
z = 0.5
y = 1
z = 0-1+0.5
z = -0.5
y = 0
z = -1+0+0.5
z = -0.5
y = 0
z = -1-1+0.5
z = -1.5
y = 0
🟣 XOR Gate — ANN Mathematics
XOR produces 1 when the two inputs are different.
H₂ = AND(x₁,x₂)
Final XOR:
XOR = AND(H₁, NOT(H₂))
| x₁ | x₂ | H₁ = OR | H₂ = AND | NOT(H₂) | XOR |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 |
z = (1×0)+(1×0)-0.5
z = -0.5
H₁ = 0
AND:
z = (1×0)+(1×0)-1.5
z = -1.5
H₂ = 0
NOT(H₂):
NOT(0) = 1
Final:
AND(0,1) = 0
z = (1×0)+(1×1)-0.5
z = 0.5
H₁ = 1
AND:
z = (1×0)+(1×1)-1.5
z = -0.5
H₂ = 0
NOT(H₂) = 1
Final:
AND(1,1) = 1
z = (1×1)+(1×0)-0.5
z = 0.5
H₁ = 1
AND:
z = (1×1)+(1×0)-1.5
z = -0.5
H₂ = 0
NOT(H₂) = 1
Final:
AND(1,1) = 1
z = (1×1)+(1×1)-0.5
z = 1.5
H₁ = 1
AND:
z = (1×1)+(1×1)-1.5
z = 0.5
H₂ = 1
NOT(H₂) = 0
Final:
AND(1,0) = 0
🔵 XNOR Gate — ANN Mathematics
XNOR produces 1 when both inputs are the same.
| x₁ | x₂ | XOR | XNOR |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
XNOR = NOT(0)
XNOR = 1
XNOR = NOT(1)
XNOR = 0
XNOR = NOT(1)
XNOR = 0
XNOR = NOT(0)
XNOR = 1
3. Final Truth Table Comparison
| x₁ | x₂ | AND | OR | NAND | NOR | XOR | XNOR |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
🎯 What This Demonstrates About ANN
For AND, OR, NAND and NOR, a single artificial neuron is sufficient because these functions are linearly separable.
For XOR and XNOR, a hidden layer is required in this basic perceptron-style construction because their patterns are not linearly separable.
No comments:
Post a Comment