Total Pageviews

Monday, August 31, 2026

🧠 ANN Logic Gates — Complete Step-by-Step Mathematics

🧠 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

z = w₁x₁ + w₂x₂ + b

y = Activation(z)

For this demonstration we use a Step Activation Function:

If z ≥ 0 → y = 1
If z < 0 → y = 0
Meaning:

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
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
Combination 1: (0,0)

Step 1 — Weighted Sum

z = (1×0) + (1×0) - 1.5
z = 0 + 0 - 1.5
z = -1.5

Step 2 — Activation

z = -1.5 < 0
y = 0
AND(0,0) = 0
Combination 2: (0,1)

Step 1 — Weighted Sum

z = (1×0) + (1×1) - 1.5
z = 0 + 1 - 1.5
z = -0.5

Step 2 — Activation

z = -0.5 < 0
y = 0
AND(0,1) = 0
Combination 3: (1,0)

Step 1 — Weighted Sum

z = (1×1) + (1×0) - 1.5
z = 1 + 0 - 1.5
z = -0.5

Step 2 — Activation

z = -0.5 < 0
y = 0
AND(1,0) = 0
Combination 4: (1,1)

Step 1 — Weighted Sum

z = (1×1) + (1×1) - 1.5
z = 1 + 1 - 1.5
z = 0.5

Step 2 — Activation

z = 0.5 ≥ 0
y = 1
AND(1,1) = 1

🟢 OR Gate — ANN Mathematics

OR produces 1 when at least one input is 1.

w₁ = 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
Combination 1: (0,0)
z = (1×0)+(1×0)-0.5
z = 0+0-0.5
z = -0.5

z < 0
y = 0
OR(0,0) = 0
Combination 2: (0,1)
z = (1×0)+(1×1)-0.5
z = 0+1-0.5
z = 0.5

z ≥ 0
y = 1
OR(0,1) = 1
Combination 3: (1,0)
z = (1×1)+(1×0)-0.5
z = 1+0-0.5
z = 0.5

y = 1
OR(1,0) = 1
Combination 4: (1,1)
z = (1×1)+(1×1)-0.5
z = 1+1-0.5
z = 1.5

y = 1
OR(1,1) = 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.

For completeness, the unused second input is shown as a dummy input with weight 0. This lets the same ANN formula be displayed for all four combinations.
w₁ = -1
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
(0,0)
z = -(0) + (0×0) + 0.5
z = 0.5
y = 1
NOT(0) = 1
(0,1)
z = -(0) + (0×1) + 0.5
z = 0.5
y = 1
NOT(0) = 1
(1,0)
z = -(1) + (0×0) + 0.5
z = -0.5
y = 0
NOT(1) = 0
(1,1)
z = -(1) + (0×1) + 0.5
z = -0.5
y = 0
NOT(1) = 0

🟠 NAND Gate — ANN Mathematics

NAND is the opposite of AND.

w₁ = -1
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
(0,0)
z = (-1×0)+(-1×0)+1.5
z = 1.5
y = 1
NAND(0,0) = 1
(0,1)
z = (-1×0)+(-1×1)+1.5
z = 0-1+1.5
z = 0.5
y = 1
NAND(0,1) = 1
(1,0)
z = (-1×1)+(-1×0)+1.5
z = -1+0+1.5
z = 0.5
y = 1
NAND(1,0) = 1
(1,1)
z = (-1×1)+(-1×1)+1.5
z = -1-1+1.5
z = -0.5
y = 0
NAND(1,1) = 0

🔴 NOR Gate — ANN Mathematics

NOR produces 1 only when both inputs are 0.

w₁ = -1
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
(0,0)
z = (-1×0)+(-1×0)+0.5
z = 0.5
y = 1
NOR(0,0) = 1
(0,1)
z = (-1×0)+(-1×1)+0.5
z = 0-1+0.5
z = -0.5
y = 0
NOR(0,1) = 0
(1,0)
z = (-1×1)+(-1×0)+0.5
z = -1+0+0.5
z = -0.5
y = 0
NOR(1,0) = 0
(1,1)
z = (-1×1)+(-1×1)+0.5
z = -1-1+0.5
z = -1.5
y = 0
NOR(1,1) = 0

🟣 XOR Gate — ANN Mathematics

XOR produces 1 when the two inputs are different.

Important: A single perceptron cannot correctly implement XOR because the XOR data is not linearly separable. Therefore, we use a small ANN with hidden neurons.
Hidden Neuron H₁ = OR(x₁,x₂)
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
Combination 1: (0,0)
OR:
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
XOR(0,0) = 0
Combination 2: (0,1)
OR:
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
XOR(0,1) = 1
Combination 3: (1,0)
OR:
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
XOR(1,0) = 1
Combination 4: (1,1)
OR:
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
XOR(1,1) = 0

🔵 XNOR Gate — ANN Mathematics

XNOR produces 1 when both inputs are the same.

XNOR = NOT(XOR)
x₁ x₂ XOR XNOR
0 0 0 1
0 1 1 0
1 0 1 0
1 1 0 1
Combination 1: (0,0)
XOR(0,0) = 0
XNOR = NOT(0)
XNOR = 1
XNOR(0,0) = 1
Combination 2: (0,1)
XOR(0,1) = 1
XNOR = NOT(1)
XNOR = 0
XNOR(0,1) = 0
Combination 3: (1,0)
XOR(1,0) = 1
XNOR = NOT(1)
XNOR = 0
XNOR(1,0) = 0
Combination 4: (1,1)
XOR(1,1) = 0
XNOR = NOT(0)
XNOR = 1
XNOR(1,1) = 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

Input ↓ Multiply by Weight ↓ Add Bias ↓ Calculate z ↓ Apply Activation Function ↓ Output 0 or 1

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