def penalty(x): #NOTE: not built as a 'penalty function' (loses functionality) sum = 0.0 for i in range(1,10): for j in range(1,10): for k in range(1,10): p = lambda v: ((v[0]-i)**2 + (v[1]-j)**2 + (v[2]-k)**2 - 48.0) p = with_penalty(quadratic_inequality, k=1e2)(p) sum += p(x) return sum