Common Operations on Fuzzy Set with Example and Code

Last Updated : 9 Jan, 2026

A Fuzzy Set is a set where each element has a value between 0 and 1 showing how much it belongs to the set. It is usually written with a tilde (~) on top of the set.

Operations on Fuzzy Set

1. Union

Let A and B be two fuzzy sets.The Union of A and B is denoted by A ∪ B and is defined as:

μA∪B​(x)= max(μA​(x), μB​(x))

Python
A = {"a":0.2, "b":0.3, "c":0.6, "d":0.6}
B = {"a":0.9, "b":0.9, "c":0.4, "d":0.5}

Y = {k: max(A[k], B[k]) for k in A} 
print("Fuzzy Set Union:", Y)

Output
Fuzzy Set Union: {'a': 0.9, 'b': 0.9, 'c': 0.6, 'd': 0.6}

2. Intersection

The Intersection of fuzzy sets A and B is denoted by A ∩ B and defined as:

μA∩B​(x)=min(μA​(x),μB​(x))

Python
A = {"a":0.2, "b":0.3, "c":0.6, "d":0.6}
B = {"a":0.9, "b":0.9, "c":0.4, "d":0.5}

Y = {k: min(A[k], B[k]) for k in A}  
print("Fuzzy Set Intersection:", Y)

Output
Fuzzy Set Intersection: {'a': 0.2, 'b': 0.3, 'c': 0.4, 'd': 0.5}

3. Complement

The Complement of a fuzzy set A is denoted by Ā and defined as:

μAˉ​(x)=1−μA​(x)

Python
A = {"a":0.2, "b":0.3, "c":0.6, "d":0.6}

Y = {k: 1 - A[k] for k in A}  # Subtract membership from 1
print("Fuzzy Set Complement:", Y)

Output
Fuzzy Set Complement: {'a': 0.8, 'b': 0.7, 'c': 0.4, 'd': 0.4}

4. Difference  

The Difference of fuzzy sets A and B (A − B) is defined as:

μA−B​(x)=min(μA​(x),1−μB​(x))

Python
A = {"a":0.2, "b":0.3, "c":0.6, "d":0.6}
B = {"a":0.9, "b":0.9, "c":0.4, "d":0.5}
Y = {k: min(A[k], 1 - B[k]) for k in A}  # Take min(A, complement(B))
print("Fuzzy Set Difference A - B:", Y)

Output
Fuzzy Set Difference A - B: {'a': 0.09999999999999998, 'b': 0.09999999999999998, 'c': 0.6, 'd': 0.5}

5. Class Implementation (Optional)

A class-based approach helps make fuzzy set operations reusable and modular.

Python
class FuzzySet:
    def __init__(self, A, B, nameA="A", nameB="B"):
        self.A = A
        self.B = B
        self.nameA = nameA
        self.nameB = nameB

    def union(self):
        return {k: max(self.A[k], self.B[k]) for k in self.A}

    def intersection(self):
        return {k: min(self.A[k], self.B[k]) for k in self.A}

    def complement(self, set_name="A"):
        S = self.A if set_name == "A" else self.B
        return {k: 1 - S[k] for k in S}

    def difference(self):
        return {k: round(min(self.A[k], 1 - self.B[k]), 2) for k in self.A}


A = {"a": 0.2, "b": 0.3, "c": 0.6, "d": 0.6}
B = {"a": 0.9, "b": 0.9, "c": 0.4, "d": 0.5}

fs = FuzzySet(A, B)
print("Union:", fs.union())
print("Intersection:", fs.intersection())
print("Complement of A:", fs.complement("A"))
print("Difference A - B:", fs.difference())

Output
Union: {'a': 0.9, 'b': 0.9, 'c': 0.6, 'd': 0.6}
Intersection: {'a': 0.2, 'b': 0.3, 'c': 0.4, 'd': 0.5}
Complement of A: {'a': 0.8, 'b': 0.7, 'c': 0.4, 'd': 0.4}
Difference A - B: {'a': 0.1, 'b': 0.1, ...
Comment