**What is Fuzzy Set ?**

Fuzzy refers to something that is unclear or vague . Hence, Fuzzy Set is a Set where every key is associated with value, which is between 0 to 1 based on the certainity .This value is often called as degree of membership. Fuzzy Set is denoted with a Tilde Sign on top of the normal Set notation.

**Operations on Fuzzy Set with Code :**

**1. Union :**

Consider 2 Fuzzy Sets denoted by A and B, then let’s consider Y be the Union of them, then for every member of A and B, Y will be:

degree_of_membership(Y)= max(degree_of_membership(A), degree_of_membership(B))

**EXAMPLE :**

## Python3

`# Example to Demonstrate the ` `# Union of Two Fuzzy Sets ` `A ` `=` `dict` `() ` `B ` `=` `dict` `() ` `Y ` `=` `dict` `() ` ` ` `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` `} ` ` ` `print` `(` `'The First Fuzzy Set is :'` `, A) ` `print` `(` `'The Second Fuzzy Set is :'` `, B) ` ` ` ` ` `for` `A_key, B_key ` `in` `zip` `(A, B): ` ` ` `A_value ` `=` `A[A_key] ` ` ` `B_value ` `=` `B[B_key] ` ` ` ` ` `if` `A_value > B_value: ` ` ` `Y[A_key] ` `=` `A_value ` ` ` `else` `: ` ` ` `Y[B_key] ` `=` `B_value ` ` ` `print` `(` `'Fuzzy Set Union is :'` `, Y) ` |

*chevron_right*

*filter_none*

**Output**

The First Fuzzy Set is : {'a': 0.2, 'b': 0.3, 'c': 0.6, 'd': 0.6} The Second Fuzzy Set is : {'a': 0.9, 'b': 0.9, 'c': 0.4, 'd': 0.5} Fuzzy Set Union is : {'a': 0.9, 'b': 0.9, 'c': 0.6, 'd': 0.6}

**2. Intersection :**

Consider 2 Fuzzy Sets denoted by A and B, then let’s consider Y be the Intersection of them, then for every member of A and B, Y will be:

degree_of_membership(Y)= min(degree_of_membership(A), degree_of_membership(B))

**EXAMPLE :**

## Python3

`# Example to Demonstrate ` `# Intersection of Two Fuzzy Sets ` `A ` `=` `dict` `() ` `B ` `=` `dict` `() ` `Y ` `=` `dict` `() ` ` ` `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` `} ` ` ` `print` `(` `'The First Fuzzy Set is :'` `, A) ` `print` `(` `'The Second Fuzzy Set is :'` `, B) ` ` ` ` ` `for` `A_key, B_key ` `in` `zip` `(A, B): ` ` ` `A_value ` `=` `A[A_key] ` ` ` `B_value ` `=` `B[B_key] ` ` ` ` ` `if` `A_value < B_value: ` ` ` `Y[A_key] ` `=` `A_value ` ` ` `else` `: ` ` ` `Y[B_key] ` `=` `B_value ` `print` `(` `'Fuzzy Set Intersection is :'` `, Y) ` |

*chevron_right*

*filter_none*

**Output**

The First Fuzzy Set is : {'a': 0.2, 'b': 0.3, 'c': 0.6, 'd': 0.6} The Second Fuzzy Set is : {'a': 0.9, 'b': 0.9, 'c': 0.4, 'd': 0.5} Fuzzy Set Intersection is : {'a': 0.2, 'b': 0.3, 'c': 0.4, 'd': 0.5}

**3. Complement :**

Consider a Fuzzy Sets denoted by A , then let’s consider Y be the Complement of it, then for every member of A , Y will be:

degree_of_membership(Y)= 1 - degree_of_membership(A)

**EXAMPLE :**

## Python3

`# Example to Demonstrate the ` `# Difference Between Two Fuzzy Sets ` `A ` `=` `dict` `() ` `Y ` `=` `dict` `() ` ` ` `A ` `=` `{` `"a"` `: ` `0.2` `, ` `"b"` `: ` `0.3` `, ` `"c"` `: ` `0.6` `, ` `"d"` `: ` `0.6` `} ` ` ` `print` `(` `'The Fuzzy Set is :'` `, A) ` ` ` ` ` `for` `A_key ` `in` `A: ` ` ` `Y[A_key]` `=` `1` `-` `A[A_key] ` ` ` `print` `(` `'Fuzzy Set Complement is :'` `, Y) ` |

*chevron_right*

*filter_none*

**Output**

The Fuzzy Set is : {'a': 0.2, 'b': 0.3, 'c': 0.6, 'd': 0.6} Fuzzy Set Complement is : {'a': 0.8, 'b': 0.7, 'c': 0.4, 'd': 0.4}

**4. Difference : **

Consider 2 Fuzzy Sets denoted by A and B, then let’s consider Y be the Intersection of them, then for every member of A and B, Y will be:

degree_of_membership(Y)= min(degree_of_membership(A), 1- degree_of_membership(B))

**EXAMPLE :**

## Python3

`# Example to Demonstrate the ` `# Difference Between Two Fuzzy Sets ` `A ` `=` `dict` `() ` `B ` `=` `dict` `() ` `Y ` `=` `dict` `() ` ` ` `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` `} ` ` ` `print` `(` `'The First Fuzzy Set is :'` `, A) ` `print` `(` `'The Second Fuzzy Set is :'` `, B) ` ` ` ` ` `for` `A_key, B_key ` `in` `zip` `(A, B): ` ` ` `A_value ` `=` `A[A_key] ` ` ` `B_value ` `=` `B[B_key] ` ` ` `B_value ` `=` `1` `-` `B_value ` ` ` ` ` `if` `A_value < B_value: ` ` ` `Y[A_key] ` `=` `A_value ` ` ` `else` `: ` ` ` `Y[B_key] ` `=` `B_value ` ` ` `print` `(` `'Fuzzy Set Difference is :'` `, Y) ` |

*chevron_right*

*filter_none*

**Output **

The First Fuzzy Set is : {"a": 0.2, "b": 0.3, "c": 0.6, "d": 0.6} The Second Fuzzy Set is : {"a": 0.9, "b": 0.9, "c": 0.4, "d": 0.5} Fuzzy Set Difference is : {"a": 0.1, "b": 0.1, "c": 0.6, "d": 0.5}

Attention geek! Strengthen your foundations with the **Python Programming Foundation** Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the **Python DS** Course.

## Recommended Posts:

- Fuzzy Logic | Set 2 (Classical and Fuzzy Sets)
- Comparison Between Mamdani and Sugeno Fuzzy Inference System
- Fuzzy Logic | Introduction
- ML | Fuzzy Clustering
- Fuzzy Logic Control System
- Python code to print common characters of two Strings in alphabetical order
- Arithmetic Operations on Images using OpenCV | Set-2 (Bitwise Operations on Binary Images)
- Python | Ways to determine common prefix in set of strings
- Issues with using C code in Python | Set 1
- Issues with using C code in Python | Set 2
- Python set operations (union, intersection, difference and symmetric difference)
- Arithmetic Operations on Images using OpenCV | Set-1 (Addition and Subtraction)
- Python - Common list elements and dictionary values
- Python - Common keys in list and dictionary
- Packaging and Publishing Python code
- Understanding Code Reuse and Modularity in Python 3
- Different Python IDEs and Code Editors
- Debugging Python code using breakpoint() and pdb
- Top 10 Python IDE and Code Editors in 2020
- Python | Morphological Operations in Image Processing (Opening) | Set-1

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.