Fuzzy logic implementation, ported from http://www.havana7.com/dotfuzzy/