Fuzzy logic lets an AI system reason with "sort of true" instead of only true or false, which is closer to how people actually describe things like temperature, speed, or dirtiness.
What Is Fuzzy Logic?
Fuzzy logic is a form of reasoning where a statement can be partly true, measured as a degree between 0 and 1, instead of only fully true or fully false. It's built to handle the kind of vague, everyday categories — "warm," "fast," "a little dirty" — that don't have a sharp boundary.
Crisp Sets vs. Fuzzy Sets
Ordinary ("crisp") sets and fuzzy sets answer different questions about the same data.
A crisp set draws a hard line — 29.9°C is "not hot," 30°C is "hot." A fuzzy set instead gives every value a degree of membership between 0 and 1, so 28°C can be "hot" to a degree of 0.3, capturing the fact that it's warmer than most things but not scorching.
Membership Functions
A membership function is the rule that turns a raw value, like a temperature, into a degree of membership in a fuzzy set like "Cold," "Warm," or "Hot."
Example: Computing Membership Degrees
def triangular(x, a, b, c):
if x <= a or x >= c:
return 0.0
if x == b:
return 1.0
if x < b:
return (x - a) / (b - a)
return (c - x) / (c - b)
def cold(x): return triangular(x, 0, 0, 20)
def warm(x): return triangular(x, 10, 22, 34)
def hot(x): return triangular(x, 24, 40, 40)
for temp in [5, 18, 22, 28, 36]:
print(f"{temp}°C -> Cold: {cold(temp):.2f} Warm: {warm(temp):.2f} Hot: {hot(temp):.2f}")Output
5°C -> Cold: 0.75 Warm: 0.00 Hot: 0.00
18°C -> Cold: 0.10 Warm: 0.67 Hot: 0.00
22°C -> Cold: 0.00 Warm: 1.00 Hot: 0.00
28°C -> Cold: 0.00 Warm: 0.50 Hot: 0.25
36°C -> Cold: 0.00 Warm: 0.00 Hot: 0.75Explanation:
At 28°C, both Warm (0.50) and Hot (0.25) are nonzero at the same time — that overlap is the whole point of fuzzy sets. A crisp system would have to pick just one category; a fuzzy system keeps both degrees and can blend them later.
Fuzzy Rules
Fuzzy rules look like ordinary IF-THEN rules, but their conditions and results are fuzzy sets, like IF temperature is Hot THEN fan_speed is High. Since a temperature can partly match several conditions at once, several rules can fire at once, each with its own strength. The final crisp output — a single fan speed — is calculated by blending the outputs together, weighted by how strongly each rule fired. This blending step is called defuzzification.
Example: Evaluating Fuzzy Rules
rules = [
(cold, 20), # IF temp is Cold THEN fan_speed is Low (20%)
(warm, 50), # IF temp is Warm THEN fan_speed is Medium (50%)
(hot, 90), # IF temp is Hot THEN fan_speed is High (90%)
]
def fan_speed(temp):
weighted_sum = 0.0
total_weight = 0.0
degrees = []
for membership_fn, output_value in rules:
degree = membership_fn(temp)
degrees.append(degree)
weighted_sum += degree * output_value
total_weight += degree
if total_weight == 0:
return 0.0, degrees
return weighted_sum / total_weight, degrees
for temp in [5, 22, 28, 36]:
speed, degrees = fan_speed(temp)
print(f"{temp}°C -> degrees(Cold,Warm,Hot) = {[round(d,2) for d in degrees]} -> fan speed = {speed:.1f}%")Output
5°C -> degrees(Cold,Warm,Hot) = [0.75, 0.0, 0.0] -> fan speed = 20.0%
22°C -> degrees(Cold,Warm,Hot) = [0.0, 1.0, 0.0] -> fan speed = 50.0%
28°C -> degrees(Cold,Warm,Hot) = [0.0, 0.5, 0.25] -> fan speed = 63.3%
36°C -> degrees(Cold,Warm,Hot) = [0.0, 0.0, 0.75] -> fan speed = 90.0%Explanation:
At 28°C, the Warm and Hot rules both fire, so the fan speed (63.3%) lands between their outputs (50% and 90%) instead of jumping straight to one or the other. This smooth blending is exactly what a crisp on/off system can't do.
Real-World Use: Washing Machines & AC Systems
Fuzzy logic is popular in appliances because it lets a device respond smoothly to messy, real-world input instead of just switching fully on or off.
- Washing machines sense things like load size and how dirty the water looks, then use fuzzy rules to pick a wash time and water level that's neither wastefully long nor too short — rather than forcing every load into one of a few fixed cycles.
- Air conditioners sense the room temperature and how fast it's changing, then adjust compressor power smoothly, instead of just cycling hard on and off, which keeps the room more stable and often saves energy.
Quick Comparison
| Feature | Crisp Logic | Fuzzy Logic |
| Truth values | Only true (1) or false (0) | Any degree between 0 and 1 |
| Category boundaries | Sharp, hard cutoffs | Overlapping, gradual |
| Rule output | One fixed action | Blended from multiple partial matches |
| Good for | Clear-cut decisions | Smooth control of real-world, imprecise input |