def __new__(cls, function, *symbols, **assumptions): # Any embedded piecewise functions need to be brought out to the # top level so that integration can go into piecewise mode at the # earliest possible moment. # # This constructor only differs from ExprWithLimits # in the application of the orientation variable. Perhaps merge? function = sympify(function) if hasattr(function, 'func') and function.func is C.Equality: lhs = function.lhs rhs = function.rhs return C.Equality(cls(lhs, *symbols, **assumptions), \ cls(rhs, *symbols, **assumptions)) function = piecewise_fold(function) if function is S.NaN: return S.NaN if symbols: limits, orientation = _process_limits(*symbols) else: # symbol not provided -- we can still try to compute a general form free = function.free_symbols if len(free) != 1: raise ValueError( " specify dummy variables for %s. If the integrand contains" " more than one free symbol, an integration variable should" " be supplied explicitly e.g., integrate(f(x, y), x)" % function) limits, orientation = [Tuple(s) for s in free], 1 # denest any nested calls while cls == type(function): limits = list(function.limits) + limits function = function.function obj = Expr.__new__(cls, **assumptions) arglist = [orientation * function] arglist.extend(limits) obj._args = tuple(arglist) obj.is_commutative = function.is_commutative # limits already checked return obj
def __new__(cls, function, *symbols, **assumptions): # Any embedded piecewise functions need to be brought out to the # top level so that integration can go into piecewise mode at the # earliest possible moment. function = sympify(function) if hasattr(function, 'func') and function.func is C.Equality: lhs = function.lhs rhs = function.rhs return C.Equality(cls(lhs, *symbols, **assumptions), \ cls(rhs, *symbols, **assumptions)) function = piecewise_fold(function) if function is S.NaN: return S.NaN if symbols: limits, orientation = _process_limits(*symbols) else: # symbol not provided -- we can still try to compute a general form free = function.free_symbols if len(free) != 1: raise ValueError("specify dummy variables for %s" % function) limits, orientation = [Tuple(s) for s in free], 1 # denest any nested calls while cls == type(function): limits = list(function.limits) + limits function = function.function # Only limits with lower and upper bounds are supported; the indefinite form # is not supported if any(len(l) != 3 or None in l for l in limits): raise ValueError( 'ExprWithLimits requires values for lower and upper bounds.') obj = Expr.__new__(cls, **assumptions) arglist = [function] arglist.extend(limits) obj._args = tuple(arglist) obj.is_commutative = function.is_commutative # limits already checked return obj