Alice in the Fuzzy Technologies laboratory, introducing FuzzyRoutines

Python · Fuzzy mathematics · Open source

Turn measurements into interpretable grades with membership functions, fuzzy sets and linguistic scales. Build models for expert systems, risk assessment and engineering decisions.

CPython 3.13–3.14 · Typed scalar API · No mandatory NumPy dependency · Apache-2.0

FuzzyRoutines 2.1.0 includes the historical scale factory, linguistic encoding, Mamdani/Sugeno inference, optional NumPy batches and neural examples. Version-aware installation and examples →

Technologies · Knowledge · Science

Quick start

How well does a room temperature of 24 °C fit the idea of “comfortable”? Define full comfort at 22 °C, decreasing to zero at 16 and 28 °C, then evaluate the measurement.

1 · Install

Use Python 3.13 or 3.14 in your project environment.

This example targets 2.1.0. Use the exact pin below. If that version is not yet available on PyPI, install the reviewed CI wheel using the agent guide. Published 2.0.0 remains available as the historical baseline; 1.x does not provide this API.

Terminal
python -m pip install fuzzyroutines==2.1.0

2 · Run the example

Save this as comfort.py and run python comfort.py.

Python · comfort.py
from fuzzyroutines import (
    ContinuousUniverse, ScalarFuzzySet, Triangle,
)

universe = ContinuousUniverse(
    0, 40, leftClosed=True, rightClosed=True,
)
comfort = ScalarFuzzySet(universe, Triangle(16, 22, 28))
temperature = 24
grade = comfort.Membership(temperature)

print(f"Temperature: {temperature} °C")
print(f"Comfort membership: {grade:.3f}")

3 · Read the result

Expected output
Temperature: 24 °C
Comfort membership: 0.667

The temperature is on the descending side of the triangle: (28 − 24) / (28 − 22) = 2/3. A grade of 0.667 describes partial membership in the comfort set, not a probability.

These thresholds are illustrative model choices. Add other terms to distinguish comfortable, warm and hot conditions in your application.

Continue with a two-term scale →
Comfort triangle and Warm shoulder, with the 24 °C observation marked
The full tutorial adds a Warm term with membership 0.125 at 24 °C.

Universal Fuzzy Scale

Build your fuzzy model

Define

Membership and sets

Eight membership families, explicit universes and immutable scalar fuzzy sets.

Choose a curve →
Combine

Fuzzy operations

Norms, negations, intersection, union and directed difference with explicit policies.

Worked scenarios →
Interpret

Scales and centroids

Linguistic classification, alpha-cuts and centroid computation with exact or numerical evidence.

API reference →

Documentation

Nine worked scenarios, reproducible graphs and a reference for the public API.

Scope and compatibility

Implemented in 2.0: the modern scalar API and historical compatibility facade, with explicit validation and documented numerical corrections.

Future work: additional defuzzification methods, executable convexity queries, symmetric difference and free-threaded Python support remain outside the 2.1 scope.