Source code for sympy.concrete.products

[docs]classProduct(Expr):"""Represents unevaluated product. """__slots__=['is_commutative']def__new__(cls,function,*symbols,**assumptions):fromsympy.integrals.integralsimport_process_limits# 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=piecewise_fold(sympify(function))iffunctionisS.NaN:returnS.NaNifnotsymbols:raiseValueError("Product variables must be given")limits,sign=_process_limits(*symbols)# Only limits with lower and upper bounds are supported; the indefinite# Product is not supportedifany(len(l)!=3orNoneinlforlinlimits):raiseValueError('Product requires values for lower and upper bounds.')obj=Expr.__new__(cls,**assumptions)arglist=[sign*function]arglist.extend(limits)obj._args=tuple(arglist)obj.is_commutative=function.is_commutative# limits already checkedreturnobj@propertydefterm(self):returnself._args[0]function=term@propertydeflimits(self):returnself._args[1:]@property

[docs]deffree_symbols(self):""" This method returns the symbols that will affect the value of the Product when evaluated. This is useful if one is trying to determine whether a product depends on a certain symbol or not. >>> from sympy import Product >>> from sympy.abc import x, y >>> Product(x, (x, y, 1)).free_symbols set([y]) """fromsympy.concrete.summationsimport_free_symbolsifself.function.is_zeroorself.function==1:returnset()return_free_symbols(self.function,self.limits)

@property

[docs]defis_zero(self):"""A Product is zero only if its term is zero. """returnself.term.is_zero