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

Commit 7a56004

Browse files
committed
17505: address reviewer's suggestions
1 parent 58119b0 commit 7a56004

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

src/sage/calculus/calculus.py

+24-10
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ def nintegral(ex, x, a, b,
809809

810810
nintegrate = nintegral
811811

812-
def symbolic_prod(expression, v, a, b, algorithm='maxima', hold=False):
812+
def symbolic_product(expression, v, a, b, algorithm='maxima', hold=False):
813813
r"""
814814
Return the symbolic product `\prod_{v = a}^b expression` with respect
815815
to the variable `v` with endpoints `a` and `b`.
@@ -837,21 +837,23 @@ def symbolic_prod(expression, v, a, b, algorithm='maxima', hold=False):
837837
EXAMPLES::
838838
839839
sage: i, k, n = var('i,k,n')
840-
sage: from sage.calculus.calculus import symbolic_prod
841-
sage: symbolic_prod(k, k, 1, n)
840+
sage: from sage.calculus.calculus import symbolic_product
841+
sage: symbolic_product(k, k, 1, n)
842842
factorial(n)
843-
sage: symbolic_prod(x + i*(i+1)/2, i, 1, 4)
843+
sage: symbolic_product(x + i*(i+1)/2, i, 1, 4)
844844
x^4 + 20*x^3 + 127*x^2 + 288*x + 180
845-
sage: symbolic_prod(i^2, i, 1, 7)
845+
sage: symbolic_product(i^2, i, 1, 7)
846846
25401600
847847
sage: f = function('f')
848-
sage: symbolic_prod(f(i), i, 1, 7)
848+
sage: symbolic_product(f(i), i, 1, 7)
849849
f(7)*f(6)*f(5)*f(4)*f(3)*f(2)*f(1)
850-
sage: symbolic_prod(f(i), i, 1, n)
850+
sage: symbolic_product(f(i), i, 1, n)
851851
product(f(i), i, 1, n)
852852
sage: assume(k>0)
853-
sage: symbolic_prod(integrate (x^k, x, 0, 1), k, 1, n)
853+
sage: symbolic_product(integrate (x^k, x, 0, 1), k, 1, n)
854854
1/factorial(n + 1)
855+
sage: symbolic_product(f(i), i, 1, n).log().log_expand()
856+
sum(log(f(i)), i, 1, n)
855857
"""
856858
if not is_SymbolicVariable(v):
857859
if isinstance(v, str):
@@ -869,11 +871,23 @@ def symbolic_prod(expression, v, a, b, algorithm='maxima', hold=False):
869871
if algorithm == 'maxima':
870872
return maxima.sr_prod(expression,v,a,b)
871873

874+
elif algorithm == 'mathematica':
875+
try:
876+
prod = "Product[%s, {%s, %s, %s}]" % tuple([repr(expr._mathematica_()) for expr in (expression, v, a, b)])
877+
except TypeError:
878+
raise ValueError("Mathematica cannot make sense of input")
879+
from sage.interfaces.mathematica import mathematica
880+
try:
881+
result = mathematica(prod)
882+
except TypeError:
883+
raise ValueError("Mathematica cannot make sense of: %s" % sum)
884+
return result.sage()
885+
872886
elif algorithm == 'giac':
873-
sum = "product(%s, %s, %s, %s)" % tuple([repr(expr._giac_()) for expr in (expression, v, a, b)])
887+
prod = "product(%s, %s, %s, %s)" % tuple([repr(expr._giac_()) for expr in (expression, v, a, b)])
874888
from sage.interfaces.giac import giac
875889
try:
876-
result = giac(sum)
890+
result = giac(prod)
877891
except TypeError:
878892
raise ValueError("Giac cannot make sense of: %s" % sum)
879893
return result.sage()

src/sage/functions/other.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -2593,8 +2593,10 @@ class Function_sum(BuiltinFunction):
25932593
EXAMPLES::
25942594
25952595
sage: from sage.functions.other import symbolic_sum as ssum
2596-
sage: ssum(x, x, 1, 10)
2596+
sage: r = ssum(x, x, 1, 10); r
25972597
sum(x, x, 1, 10)
2598+
sage: r.unhold()
2599+
55
25982600
"""
25992601
def __init__(self):
26002602
"""
@@ -2607,6 +2609,16 @@ def __init__(self):
26072609
BuiltinFunction.__init__(self, "sum", nargs=4,
26082610
conversions=dict(maxima='sum'))
26092611

2612+
def _print_latex_(self, x, var, a, b):
2613+
r"""
2614+
EXAMPLES::
2615+
2616+
sage: from sage.functions.other import symbolic_sum as ssum
2617+
sage: latex(ssum(x^2, x, 1, 10))
2618+
\sum_{x=1}^{10} x^2
2619+
"""
2620+
return r"\sum_{{{}={}}}^{{{}}} {}".format(var, a, b, x)
2621+
26102622
symbolic_sum = Function_sum()
26112623

26122624

src/sage/symbolic/expression_conversions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2009,13 +2009,13 @@ def composition(self, ex, operator):
20092009
0
20102010
"""
20112011
from sage.functions.other import Function_sum, Function_prod
2012-
from sage.calculus.calculus import symbolic_sum, symbolic_prod
2012+
from sage.calculus.calculus import symbolic_sum, symbolic_product
20132013
if not operator:
20142014
return self
20152015
if isinstance(operator, Function_sum):
20162016
return symbolic_sum(*map(self, ex.operands()))
20172017
if isinstance(operator, Function_prod):
2018-
return symbolic_prod(*map(self, ex.operands()))
2018+
return symbolic_product(*map(self, ex.operands()))
20192019
if operator in self._exclude:
20202020
return operator(*map(self, ex.operands()), hold=True)
20212021
else:

0 commit comments

Comments
 (0)