import math


def compensatoryAnd(m, g=0.5):
    """
       anding function
       m = list of membership values for x derived from n membership functions
       g = gamma value 0=product 1=algebraic sum

       returns compensatory AND value of x
    """
    g = float(g)

    product1 = 1
    product2 = 1
    for mem in m:
        product1 *= mem
        product2 *= (1 - mem)

    return math.pow(product1, 1 - g) * math.pow((1 - product2), g)