Basics of Fuzzy Logic

Basics of Fuzzy Logic

8 mins read
Oct 31, 2025
Share
editor-page-cover
Content
Basics of fuzzy logic
Fuzzy sets
Membership functions and linguistic variables
Union of two fuzzy sets
Intersection of two fuzzy sets
Complement of a fuzzy set
De Morgan's law for fuzzy sets
From fuzzification to output: The fuzzy inference pipeline
Beyond min/max: t-norms, s-norms, and α-cuts
Mini worked example
Application areas of fuzzy logic

In the 1960s, Lotfi Zadeh introduced the science of fuzzy logic to analyze the systems where Boolean logic was not good enough. To capture the (lack of) precision, Boolean logic improvises only two options: true or false.

There are different scenarios in the real world that can be clearly marked as true or false. For example:

  • 1+1=21+1=2
  • 5>105>10
  • ChatGPT generates correct responses

The truthfulness of the first two statements can be captured by Boolean logic because the possible answer is either true or false. However, the truthfulness of the third statement is relatively harder to capture using Boolean logic. Labelling it as a true or false statement won’t capture the ground reality. The actual answer lies somewhere between true and false. Fuzzy logic takes care of such situations. Let’s first understand the basics of fuzzy logic.

Basics of fuzzy logic#

Fuzzy logic improvises a continuous line to represent the magnitude of the truthfulness of a given statement. For completely true or false statements, it will take the extreme points of the line: 1 or 0. However, the magnitude of truthfulness of a statement or concept can be represented using any appropriate membership value between 0 and 1, as shown in the following figure:

Boolean vs fuzzy truth values
Boolean vs fuzzy truth values

There are certain situations where we need to capture the notion of partial truth. For example, “Sara is a tall person.” It depends on how we define the concept of someone’s height. If we define a strict threshold like anyone having a height of more than 5 feet is tall, then this point can serve as the cutoff to categorize someone as tall or not tall. If Alice has a height less than 5 feet (say 4.9 feet), then we’ll say that Alice is not tall. We’ll output the same answer for any smaller number. If Bob has a height greater than 5 feet (say 5.1 feet), then we’ll treat Bob as a tall person. We’ll do the same for a person whose height is significantly higher than 5 feet. The absolute difference between the heights of Alice and Bob is 0.2 feet, but we’re classifying them into two mutually exclusive categories because of the strict cutoff. This is what a Boolean decision is. The same phenomenon has been shown in the following figure:

Boolean representation of the variable "isTall"
Boolean representation of the variable "isTall"

Fuzzy logic is the superset of Boolean logic. It captures the notion of partial truthfulness beyond capturing absolute true or false answers. Each linguistic concept is modeled as a fuzzy variable. Values of fuzzy variables are represented as membership functions. Fuzzy membership functions capture the notion of continuity and partial truthfulness. Moreover, they can overlap with each other. For example, the concept of tallness has been modeled as a fuzzy variable in the following figure. The variable can have three possible values: short, medium and tall. Each fuzzy value is modeled as a membership function. The membership value μ\mu for each membership function is computed based on the actual height. These fuzzy membership functions representing their respective linguistic values can overlap with each other as shown below:

Fuzzy representation of the variable "height"
Fuzzy representation of the variable "height"

Let’s compute the membership values μ\mu for the height of Alice as shown in the following figure:

Membership of Alice in the membership functions
Membership of Alice in the membership functions

The figure above shows:

  • μshort(Alice)=0.09\mu_{short}(Alice) = 0.09
  • μmedium(Alice)=0.16\mu_{medium}(Alice) = 0.16
  • μtall(Alice)=1.0\mu_{tall}(Alice) = 1.0

Let’s repeat the same experiment for the height of Bob as shown in the following figure:

Membership of Bob in the membership functions
Membership of Bob in the membership functions

The figure above shows:

  • μshort(Bob)=0\mu_{short}(Bob) = 0
  • μmedium(Bob)=0.33\mu_{medium}(Bob) = 0.33
  • μtall(Bob)=0.98\mu_{tall}(Bob) = 0.98

In both figures, the coloured lines show membership of the heights of Alice and Bob in each of the membership functions. For instance, the height of Alice has a membership value of 1.0 in the membership function mediummedium and Bob has a membership value of 0.98 in the same function. Comparing both of them reveals that they’re quite close to each other. The same is true for the other two membership functions. The membership value in a particular membership function represents the degree of truthfulness of belonging to that particular concept or fuzzy value.

Fuzzy sets#

In conventional sets, the membership of each element to a set is either 0 or 1. We interpret it as an element belonging to a set or not. For example, the following set

can be represented as follows:

In this notation, each element of the set is notated as xy\frac{x}{y} where xx is an element and yy is the membership value μ\mu of that element in the set. If μ\mu is 1 then the element is present in the set. If μ\mu is 0 then the element is not present in the set. For conventional sets, we may omit writing the explicit value of μ\mu, as shown above.

Fuzzy sets capture the partial membership of an element to a set too. For example, if we have to create a set named mediummedium to notate the membership of Alice and Bob, we can write it as follows:

The fundamental principles of set theory remain the same. Let’s take an example of two fuzzy sets AA and BB, as shown below, and exercise the fundamental properties of sets:

Membership functions and linguistic variables#

A practical way to continue the basics of fuzzy logic is to define linguistic variables (e.g., Temperature = {cold, warm, hot}) and assign each linguistic value a membership function (MF) over the universe of discourse.

Common MF shapes:

  • Triangular: simple, three points define the peak and support.

  • Trapezoidal: flat top; great for “about this range”.

  • Gaussian: smooth, differentiable; useful when you want gentle transitions.

Guidelines:

  • Let adjacent MFs overlap so inputs can partially belong to neighboring terms.

  • Cover the full range; avoid gaps where all memberships are near zero unless you intend an “unknown” zone.

  • Start with triangles/trapezoids; move to Gaussian only if you need smoother control.

This grounding helps when you later build rules like IF temperature is warm AND humidity is high THEN fan\_speed is medium.

Union of two fuzzy sets#

The union of the two fuzzy sets is computed by taking the maximum of the two membership values of an element in both sets. For example,

Intersection of two fuzzy sets#

The intersection of the two fuzzy sets is computed by taking the minimum of the two membership values of an element in both sets. For example,

Complement of a fuzzy set#

The complement of a fuzzy set is computed by subtracting the membership value of each element from 1. For example,

Python
A = dict()
B = dict()
Union_of_A_B = dict()
Intersection_of_A_B = dict()
Complement_of_A = dict()
Complement_of_B = dict()
A = {"red":0.8, "green":0.5, "blue":0.2}
B = {"red":0.6, "green":0.9, "blue":0.7}
for a,b in zip(A,B):
Union_of_A_B[a] = max(A[a], B[a])
Intersection_of_A_B[a] = max(A[a], B[a])
Complement_of_A[a] = round(1 - A[a],1)
Complement_of_B[b] = round(1 - B[b],1)
print "Union of A and B = ", Union_of_A_B
print "Intersection of A and B = ", Intersection_of_A_B
print "Complement of A = ", Complement_of_A
print "Complement of B = ", Complement_of_B

De Morgan's law for fuzzy sets#

Let’s apply these basic operations to verify that De Morgan’s law holds for fuzzy sets:

Hence,

Similarly,

Hence,

Let’s verify these results:

Python
def intersection(A, B):
Intersection_of_A_B = dict()
for a,b in zip(A,B):
Intersection_of_A_B[a] = min(A[a], B[a])
return Intersection_of_A_B
def union(A, B):
Union_of_A_B = dict()
for a,b in zip(A,B):
Union_of_A_B[a] = max(A[a], B[b])
return Union_of_A_B
def complement(A):
Complement_of_A = dict()
for a in A:
Complement_of_A[a] = round(1 - A[a],1)
return Complement_of_A
A = dict()
B = dict()
A = {"red":0.8, "green":0.5, "blue":0.2}
B = {"red":0.6, "green":0.9, "blue":0.7}
print "Union of A and B = ", union(A, B)
print "Intersection of A and B = ", intersection(A, B)
print "Complement of A = ", complement(A)
print "Complement of B = ", complement(B)
print "Rule-1: ", complement(intersection(A, B)), " = ", union(complement(A), complement(B))
print "Rule-2: ", complement(union(A, B)), " = ", intersection(complement(A), complement(B))

From fuzzification to output: The fuzzy inference pipeline #

Most controllers implement this four-stage flow, which is at the heart of the basics of fuzzy logic:

  1. Fuzzification Convert crisp inputs (e.g., temperature = 27 °C, humidity = 70%) into degrees of membership for each input MF.

  2. Rule evaluation (inference) Evaluate rules using a conjunction operator (a t-norm, often min or product) for AND, a disjunction operator (an s-norm, often max or probabilistic sum) for OR, and compute each rule’s firing strength.

  3. Aggregation Combine the consequents from all fired rules into a single fuzzy set for the output variable (typical choice: max aggregation across rules for the same output MFs).

  4. Defuzzification Convert the aggregated fuzzy output to a crisp number. The most common method is centroid (center of area). Alternatives include bisector, mean of maxima, smallest of maxima, and largest of maxima.

Two popular families:

  • Mamdani: consequents are fuzzy sets; intuitive and widely taught.

  • Sugeno: consequents are constants or linear functions; often better for optimization and integration with control theory.

Beyond min/max: t-norms, s-norms, and α-cuts#

Your union/intersection used max/min, which is a great start. In practice, designers sometimes choose:

  • t-norms (AND):

    • Minimum: fast, intuitive.

    • Algebraic product: multiplies memberships; yields smoother, stricter conjunctions.

  • s-norms (OR):

    • Maximum: classic choice.

    • Probabilistic sum: a + b − ab; avoids exceeding 1 while reflecting combined evidence.

Another handy concept in the basics of fuzzy logic is the α-cut: for a fuzzy set A and α∈\[0,1\], the α-cut is the crisp set of elements whose membership ≥ α. α-cuts help analyze and visualize where “confidence” is at least α, and can be used to simplify reasoning or to clip outputs before defuzzification.

Mini worked example#

Consider a simple fan controller to cement the basics of fuzzy logic:

  • Inputs Temperature (°C): {cool, warm, hot} with trapezoidal/triangular MFs over [10, 40]. Humidity (%): {dry, humid} over [20, 90].

  • Output FanSpeed (%): {low, medium, high} with triangular MFs over [0, 100].

  • Rules R1: IF temperature is cool THEN FanSpeed is low R2: IF temperature is warm AND humidity is dry THEN FanSpeed is medium R3: IF temperature is warm AND humidity is humid THEN FanSpeed is high R4: IF temperature is hot THEN FanSpeed is high

  • Evaluation For input temp=27, humidity=70: fuzzify → warm≈0.8, hot≈0.1; dry≈0.1, humid≈0.9 R2 firing = min(0.8, 0.1)=0.1 → medium clipped at 0.1 R3 firing = min(0.8, 0.9)=0.8 → high clipped at 0.8 R1 contributes little (cool≈0), R4 contributes 0.1 via hot. Aggregate medium(0.1) ∪ high(0.8), then defuzzify (centroid) → FanSpeed ≈ high but moderated (e.g., ~75–80%).

Design notes:

  • Start with 3–5 terms per variable; too many terms inflate rules and complicate tuning.

  • Tune by adjusting MF overlaps or swapping min/product and centroid/mean-of-maxima to match response smoothness and latency.

  • Validate with edge cases (lowest/highest inputs) and mid-range transitions to ensure monotonic, intuitive outputs.

Application areas of fuzzy logic#

Example application domains of fuzzy logic are listed below:

  • Automatic speed control system of vehicles
  • Altitude control of spacecrafts
  • Intelligent decision support system in business intelligence
  • Evaluation system to grant financial support and loan in financial organizations
  • Optimization in manufacturing industry
  • Medical diagnostic support systems
  • Handwriting recognition systems

For a deeper dive into the relevant subject areas and applications, you may explore:

Getting Started with Image Classification with PyTorch

Cover
Getting Started with Image Classification with PyTorch

PyTorch is a machine learning framework used in a wide array of popular applications, including Tesla’s Autopilot and Pyro, Uber’s probabilistic modeling engine. This course is an introduction to image classification using PyTorch’s computer vision models for training and tuning your own model. You’ll start with the fundamental concepts of applying machine learning and its applications to image classification before exploring the process of training your AI model. You’ll prepare data for intake by the computer vision model with image pre-processing, set up pipelines for training your model, and fine-tune the variables to improve predictive performance. You’ll finish by deploying the image classification model by converting to ONNX format and serving it via REST API. By the end of this course, you’ll be able to build and deploy your own image classification models from scratch.

6hrs
Beginner
110 Playgrounds
6 Quizzes


Written By:
Malik Jahan