diff --git a/src/sage/misc/all.py b/src/sage/misc/all.py index cd4652ad98a..1644b8dbc04 100644 --- a/src/sage/misc/all.py +++ b/src/sage/misc/all.py @@ -135,6 +135,7 @@ isqrt, squarefree_part, symbolic_sum as sum, + symbolic_prod as product, transpose, ) diff --git a/src/sage/misc/functional.py b/src/sage/misc/functional.py index 6395141fb61..c81410ddb75 100644 --- a/src/sage/misc/functional.py +++ b/src/sage/misc/functional.py @@ -568,6 +568,63 @@ def symbolic_sum(expression, *args, **kwds): return SR(expression).sum(*args, **kwds) +def symbolic_prod(expression, *args, **kwds): + r""" + Return the symbolic product `\prod_{v = a}^b expression` with respect + to the variable `v` with endpoints `a` and `b`. + + INPUT: + + - ``expression`` - a symbolic expression + + - ``v`` - a variable or variable name + + - ``a`` - lower endpoint of the product + + - ``b`` - upper endpoint of the prduct + + - ``algorithm`` - (default: ``'maxima'``) one of + + - ``'maxima'`` - use Maxima (the default) + + - ``'giac'`` - (optional) use Giac + + - ``'sympy'`` - use SymPy + + - ``hold`` - (default: ``False``) if ``True`` don't evaluate + + EXAMPLES:: + + sage: i, k, n = var('i,k,n') + sage: product(k,k,1,n) + factorial(n) + sage: product(x + i*(i+1)/2, i, 1, 4) + x^4 + 20*x^3 + 127*x^2 + 288*x + 180 + sage: product(i^2, i, 1, 7) + 25401600 + sage: f = function('f') + sage: product(f(i), i, 1, 7) + f(7)*f(6)*f(5)*f(4)*f(3)*f(2)*f(1) + sage: product(f(i), i, 1, n) + product(f(i), i, 1, n) + sage: assume(k>0) + sage: product(integrate (x^k, x, 0, 1), k, 1, n) + 1/factorial(n + 1) + sage: product(f(i), i, 1, n).log().log_expand() + sum(log(f(i)), i, 1, n) + + """ + from .misc_c import prod as c_prod + if hasattr(expression, 'prod'): + return expression.prod(*args, **kwds) + elif len(args) <= 1: + return c_prod(expression, *args) + else: + from sage.symbolic.ring import SR + return SR(expression).prod(*args, **kwds) + + + def integral(x, *args, **kwds): """ Returns an indefinite or definite integral of an object x.