Skip to main content

Operators & hedges

Fuzzy AND, OR and NOT are families of operators, not single formulas. ferrifuzz ships six t-norms, six t-conorms and three complements. Each works on a type-1 degree (f64) and on an interval type-2 degree ((lower, upper)). The math is explained in Concepts → Fuzzy operators.

use ferrifuzz::prelude::*;

assert_eq!(TNorm::Product.apply(0.5, 0.4), 0.2);
assert_eq!(TConorm::Max.apply(0.5, 0.4), 0.5);
assert_eq!(TNorm::Min.apply_interval((0.6, 0.8), (0.5, 0.9)), (0.5, 0.8));
assert!((Complement::Standard.apply(0.3) - 0.7).abs() < 1e-12);

In a FuzzySystem, the t-norm (with_and) combines the clauses inside an AND-group, and the t-conorm (with_or) combines the OR-groups of a rule. See FuzzySystem.

TNorm: fuzzy AND​

VariantFormula T(a,b)T(a, b)Accepted names
Min (default)min⁡(a,b)\min(a, b)min, godel, zadeh, standard
Productababproduct, prod, algebraic
Lukasiewiczmax⁡(0, a+b−1)\max(0,\ a + b - 1)lukasiewicz, luk, bounded
Drasticbb if a=1a = 1; aa if b=1b = 1; else 00drastic
Einsteinab2−(a+b−ab)\dfrac{ab}{2 - (a + b - ab)}einstein
Hamacheraba+b−ab\dfrac{ab}{a + b - ab} (0 when a=b=0a = b = 0)hamacher

TConorm: fuzzy OR​

VariantFormula S(a,b)S(a, b)Accepted names
Max (default)max⁡(a,b)\max(a, b)max, godel, zadeh, standard
Probabilistica+b−aba + b - abprobor, prob, probabilistic, algebraic
Lukasiewiczmin⁡(1, a+b)\min(1,\ a + b)lukasiewicz, luk, bounded
Drasticbb if a=0a = 0; aa if b=0b = 0; else 11drastic
Einsteina+b1+ab\dfrac{a + b}{1 + ab}einstein
Hamachera+b−2ab1−ab\dfrac{a + b - 2ab}{1 - ab} (1 when a=b=1a = b = 1)hamacher

Methods (both enums)​

ItemDescription
apply(self, a, b) -> f64Type-1 degrees.
apply_interval(self, a, b) -> (f64, f64)Applies the operator bound-wise to two (lower, upper) intervals.
FromStrCase-insensitive; the names in the tables above. Unknown names give InvalidParameter with a "did you mean" suggestion and the valid list.
name(self) -> &'static str, DisplayCanonical name ("probor" for TConorm::Probabilistic).
ALL: &[Self]Every variant, in table order.

Both enums are Copy, Eq, Hash and Default.

let s: TConorm = "Probabilistic".parse()?;
assert_eq!(s, TConorm::Probabilistic);
assert_eq!(s.to_string(), "probor");
for t in TNorm::ALL {
println!("{:<12} {:.3}", t.name(), t.apply(0.7, 0.6));
}

Complement: fuzzy NOT​

VariantFormula c(μ)c(\mu)Parameter
Standard (default)1−μ1 - \munone
Sugeno(λ)1−μ1+λμ\dfrac{1 - \mu}{1 + \lambda\mu}λ>−1\lambda > -1
Yager(w)(1−μw)1/w(1 - \mu^{w})^{1/w}w>0w > 0

Sugeno(0.0) and Yager(1.0) both reduce to the standard complement.

ItemDescription
Complement::from_name(kind, param) -> Result<Complement>kind is "standard" (alias "zadeh"), "sugeno" or "yager", case-insensitive. Checks λ > -1 or w > 0. param is ignored for standard.
apply(self, mu) -> f64Type-1 degree.
apply_interval(self, (l, u)) -> (f64, f64)Returns (c(u), c(l)). The bounds swap so that lower ≤ upper still holds.
let yager = Complement::from_name("yager", 2.0)?;
assert!((yager.apply(0.3) - 0.9539).abs() < 1e-4);
assert_eq!(Complement::Standard.apply_interval((0.2, 0.6)), (0.4, 0.8));
note

IS NOT in a rule always uses the standard complement 1−μ1 - \mu. Complement is for your own calculations on degrees.

Hedge: linguistic modifiers​

A hedge reshapes a degree with a power: μ↦μp\mu \mapsto \mu^{p}. If p>1p > 1 it concentrates the set ("very hot" is stricter than "hot"). If p<1p < 1 it dilates the set ("somewhat hot" is looser).

ConstructorPowerRule words that map to it
Hedge::very()2.0very
Hedge::extremely()3.0extremely
Hedge::somewhat()0.5somewhat, more_or_less (also moreorless), slightly
Hedge::plus()1.25plus
Hedge::minus()0.75minus
Hedge::new(p)any pnone
MethodDescription
Hedge::from_word(word) -> Option<Hedge>Looks up the hedge for a rule word (case-insensitive). Returns None if the word is unknown.
power() -> f64The exponent.
apply(mu) -> f64μp\mu^{p}
apply_interval((l, u)) -> (f64, f64)Bound-wise. Powers are monotone, so the order is kept.
assert_eq!(Hedge::very().apply(0.5), 0.25);
assert_eq!(Hedge::from_word("More_Or_Less"), Some(Hedge::somewhat()));
assert_eq!(Hedge::very().apply_interval((0.5, 0.8)), (0.25, 0.8 * 0.8));

In rules you normally write the hedge word (temp IS very hot) instead of building a Hedge yourself. See Rules.