Just as a side note, defined fuzzy regions don't necessarily have to be exactly the same. They can also be triangles and the slopes on each section can vary instead of the symmetric plateau-shaped polygons I am using in the examples. It all depends on how you want to look a the data.

## Boolean Operators

We can use basic Boolean operators on fuzzy numbers. The table below shows how they would be evaluated.

**Operator** |
**Boolean Logic** |
**Fuzzy Implementation** |

| (OR) |
Sort **OR** Somewhat Short |
MAX(Short, Somewhat short) |

& (And) |
Short **AND** Somewhat Short |
MIN(Short, Somewhat short) |

! (NOT) |
**NOT** Short |
1.0 - Short |

## Code Sample

The sample application consists of a bunch of points on a windows app. Each point has a momentum which is modified depending on how far from the center of the screen they are located. The momentum of each point is also modified by the relations with all other points. This gives us a chaotic system which is kind of fun to watch.

Here is our fuzzy number class which is pretty straightforward. Notice the overloaded Boolean operators:

public class FuzzyNumber

{

public FuzzyNumber(double value)

{

m_value = value;

}

private double m_value;

public double Value

{

get { return m_value; }

set { m_value = value; }

}

public bool IsTrue()

{

return m_value > 0.5;

}

public static FuzzyNumber operator | (FuzzyNumber A, FuzzyNumber B)

{

return new FuzzyNumber(Math.Max(A.m_value, B.m_value));

}

public static FuzzyNumber operator & (FuzzyNumber A, FuzzyNumber B)

{

return new FuzzyNumber(Math.Min(A.m_value, B.m_value));

}

public static FuzzyNumber operator !(FuzzyNumber A)

{

return new FuzzyNumber(1.0 - A.Value);

}

}

I have defined the distances and positions with enums as follows:

And so can define how the velocities of each point will changed based on these enums:

m_horizAdjustments = new Dictionary<HorizontalPosition, float>();

m_horizAdjustments.Add(HorizontalPosition.FarLeft, -.075F);

m_horizAdjustments.Add(HorizontalPosition.Left, -0.25F);

m_horizAdjustments.Add(HorizontalPosition.Center, 0.0F);

m_horizAdjustments.Add(HorizontalPosition.Right, 0.25F);

m_horizAdjustments.Add(HorizontalPosition.FarRight, 0.75F);

m_vertAdjustment = new Dictionary<VerticalPosition, float>();

m_vertAdjustment.Add(VerticalPosition.ExtremeHigh, 0.75F);

m_vertAdjustment.Add(VerticalPosition.High, 0.25F);

m_vertAdjustment.Add(VerticalPosition.Middle, 0.0F);

m_vertAdjustment.Add(VerticalPosition.Low, -0.25F);

m_vertAdjustment.Add(VerticalPosition.ExtremeLow, -0.75F);

m_distAdjustment = new Dictionary<Distance, float>();

m_distAdjustment.Add(Distance.VeryFar, 100.0F);

m_distAdjustment.Add(Distance.Far, 10.0F);

m_distAdjustment.Add(Distance.SlightlyFar, 1.0F);

m_distAdjustment.Add(Distance.Normal, 1.0F);

m_distAdjustment.Add(Distance.SlightlyClose, 1.0F);

m_distAdjustment.Add(Distance.Close, 1.0F);

m_distAdjustment.Add(Distance.VeryClose, 1.0F);

## In Conclusion

I'm not going to go through all the code for implementing the project because it would take too long, however it is pretty self-documenting and if you have any questions, let me know and I'll do my best to answer them.

Download the source and try ajusting the settings (above) to see how the points interact differently. If nothing else, it is a fun toy to play with.

In upcoming articles, I'll dig into other ways to implement fuzzy computing, but for now I hope you found this article interesting.

Until next time,

-Happy coding