# Re: Algorithm for fuzzy "OR" calculations?

Fred A Watkins (fwatkins@hyperlogic.com)
Mon, 2 Mar 1998 14:15:15 +0100 (MET)

bryce@albatross.co.nz wrote:

>Does anyone have an algorithm for calculating a fuzzy 'OR' on x number of
>values, given the formula X OR Y = x+y-xy (as opposed to the more standard
>fuzzy definition of X OR Y = max(x,y).
>
>As an example, a OR b OR c can be calculated given the idea that <a OR b OR
>c> is like <<a OR b> OR c>, ie:
>
> "(a + b -ab) + c -(a + b -ab)c"
>or
> "a + b + c -ab -bc -ac +abc"
>
>The tricky part is that I need this to work for any number of values, not
>just two or three. I am actually planning to use this in a Delphi
>application, but examples in C would be fine.
>

/*
| SumProductOR - calculate OR as difference of sum and product
|
| Returns value or -1.0 on error.
*/

double SumProductOR(unsigned int count, double *values) {

unsigned int n;
double acc, ftmp;

if (count == 0 || values == (double *)0) return (-1.0); /* error cases */

acc = values;
for (n = 1; n < count; ++n) {
ftmp = acc;
acc += values[n];
acc -= ftmp * values[n];
}

return (acc);
}