Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Implement a product() convenience function for symbolic products.
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelCharpentier committed May 21, 2017
1 parent 23dc762 commit 4c3d7f4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/sage/misc/all.py
Expand Up @@ -135,6 +135,7 @@
isqrt,
squarefree_part,
symbolic_sum as sum,
symbolic_prod as product,
transpose,
)

Expand Down
57 changes: 57 additions & 0 deletions src/sage/misc/functional.py
Expand Up @@ -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.
Expand Down

0 comments on commit 4c3d7f4

Please sign in to comment.