Skip to content

FuzzyInfer

Unix-compliant fuzzy logic inference with a beautiful fluent API.

PyPI Python License Tests

Why FuzzyInfer?

Real-world reasoning is rarely black and white. FuzzyInfer brings the power of fuzzy logic to Python with:

  • 🔧 Unix Philosophy: Composable tools that do one thing well
  • 🐍 Pythonic API: Beautiful, fluent interface that feels natural
  • 🚀 Stream-First: Process infinite streams of facts and rules
  • 📊 Degrees of Belief: Express uncertainty with values between 0.0 and 1.0
  • 🔗 Pipeline Ready: Chain with other Unix tools via JSONL

Quick Example

from fuzzy_infer import fuzzy

# Beautiful, chainable inference
results = (
    fuzzy()
    .fact("is-bird", ["robin"], 0.9)
    .fact("has-wings", ["robin"], 1.0)
    .rule(
        when=("is-bird", "?x"),
        then=("can-fly", "?x", 0.85)
    )
    .infer()
    .query("can-fly", ["robin"])
)
# Result: can-fly(robin) with degree 0.765
# Stream facts through inference pipeline
echo '{"type":"fact","pred":"is-bird","args":["robin"],"degree":0.9}' |
fuzzy-infer run rules.jsonl |
fuzzy-infer query "can-fly"
# Powerful pattern variables
fuzzy().rule(
    when=[
        ("parent", "?x", "?y"),    # ?x is parent of ?y
        ("parent", "?y", "?z")     # ?y is parent of ?z
    ],
    then=("grandparent", "?x", "?z")  # ?x is grandparent of ?z
)

Key Features

🎯 Forward-Chaining Inference

Automatically derive new facts from rules until no new knowledge can be inferred.

🔄 Stream Processing

Process infinite streams of facts and rules - perfect for real-time systems.

🎨 Fluent API

Chain operations naturally with Python's most beautiful inference API.

🐧 Unix Composability

Works seamlessly with grep, jq, awk, and other Unix tools via JSONL.

📐 Pattern Variables

Express complex relationships with pattern matching and variable binding.

💫 Fuzzy Operations

Built-in fuzzy logic operators (AND, OR, NOT) with configurable T-norms.

Installation

pip install fuzzy-infer

Or for development:

git clone https://github.com/queelius/fuzzy-infer.git
cd fuzzy-infer
pip install -e ".[dev]"

Next Steps

Philosophy

FuzzyInfer embraces the Unix philosophy:

  1. Do One Thing Well: Fuzzy inference, nothing more
  2. Text Streams: JSONL for universal compatibility
  3. Composable: Chain with any tool that speaks JSON
  4. Simple: Clear, minimal API that's easy to learn

License

MIT License - see LICENSE for details.