@@ -809,7 +809,7 @@ def nintegral(ex, x, a, b,
809
809
810
810
nintegrate = nintegral
811
811
812
- def symbolic_prod (expression , v , a , b , algorithm = 'maxima' , hold = False ):
812
+ def symbolic_product (expression , v , a , b , algorithm = 'maxima' , hold = False ):
813
813
r"""
814
814
Return the symbolic product `\prod_{v = a}^b expression` with respect
815
815
to the variable `v` with endpoints `a` and `b`.
@@ -837,21 +837,23 @@ def symbolic_prod(expression, v, a, b, algorithm='maxima', hold=False):
837
837
EXAMPLES::
838
838
839
839
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)
842
842
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)
844
844
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)
846
846
25401600
847
847
sage: f = function('f')
848
- sage: symbolic_prod (f(i), i, 1, 7)
848
+ sage: symbolic_product (f(i), i, 1, 7)
849
849
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)
851
851
product(f(i), i, 1, n)
852
852
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)
854
854
1/factorial(n + 1)
855
+ sage: symbolic_product(f(i), i, 1, n).log().log_expand()
856
+ sum(log(f(i)), i, 1, n)
855
857
"""
856
858
if not is_SymbolicVariable (v ):
857
859
if isinstance (v , str ):
@@ -869,11 +871,23 @@ def symbolic_prod(expression, v, a, b, algorithm='maxima', hold=False):
869
871
if algorithm == 'maxima' :
870
872
return maxima .sr_prod (expression ,v ,a ,b )
871
873
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
+
872
886
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 )])
874
888
from sage .interfaces .giac import giac
875
889
try :
876
- result = giac (sum )
890
+ result = giac (prod )
877
891
except TypeError :
878
892
raise ValueError ("Giac cannot make sense of: %s" % sum )
879
893
return result .sage ()
0 commit comments