# Ticket #7377: fastcalculus.patch

File fastcalculus.patch, 14.0 KB (added by nbruin, 12 years ago)

Patch to get faster calculus routines

• ## sage/calculus/calculus.py

```# HG changeset patch
# User Nils Bruin <nbruin@sfu.ca>
# Date 1265693495 28800
# Node ID f74ac05eae85bb1150ced5c460a6e6bc5acd521a
# Parent  db5502ca296c8253c940ee9b9450d48234b61e46
Fast calculus interface

diff -r db5502ca296c -r f74ac05eae85 sage/calculus/calculus.py```
 a arc_functions =  ['asin', 'acos', 'atan', 'asinh', 'acosh', 'atanh', 'acoth', 'asech', 'acsch', 'acot', 'acsc', 'asec'] import sage.interfaces.maxima_lib maxima = sage.interfaces.maxima_lib.maxima maxima = sage.interfaces.maxima_lib.maxima #maxima = Maxima(init_code = ['display2d:false', 'domain: complex', 'keepfloat: true', 'load(to_poly_solver)', 'load(simplify_sum)'], script_subdirectory=None) ######################################################## def symbolic_sum(expression, v, a, b, algorithm='maxima'): raise ValueError, "summation limits must not depend on the summation variable" if algorithm == 'maxima': sum  = "'sum(%s, %s, %s, %s)" % tuple([repr(expr._maxima_()) for expr in (expression, v, a, b)]) try: result = maxima.simplify_sum(sum) result = result.ratsimp() return expression.parent()(result) return maxima.sr_sum(expression,v,a,b) except TypeError, error: s = str(error) if "divergent" in s or 'Pole encountered' in s: if algorithm == 'maxima': if a is None: result = expression._maxima_().integrate(v) result = maxima.sr_integral(expression,v) else: try: result = expression._maxima_().integrate(v, a, b) result = maxima.sr_integral(expression,v,a,b) except TypeError, error: s = str(error) if "divergent" in s or 'Principal Value' in s: if algorithm == 'maxima': if dir is None: l = ex._maxima_().limit(v, a) l = maxima.sr_limit(ex, v, a) elif dir == 'plus' or dir == 'above': l = ex._maxima_().limit(v, a, 'plus') l = maxima.sr_limit(ex, v, a, 'plus') elif dir == 'minus' or dir == 'below': l = ex._maxima_().limit(v, a, 'minus') l = maxima.sr_limit(ex, v, a, 'minus') elif algorithm == 'maxima_taylor': if dir is None: l = ex._maxima_().tlimit(v, a) l = maxima.sr_tlimit(ex, v, a) elif dir == 'plus' or dir == 'above': l = ex._maxima_().tlimit(v, a, 'plus') l = maxima.sr_tlimit(ex, v, a, 'plus') elif dir == 'minus' or dir == 'below': l = ex._maxima_().tlimit(v, a, 'minus') l = maxima.sr_tlimit(ex, v, a, 'minus') elif algorithm == 'sympy': if dir is None: import sympy
• ## sage/interfaces/maxima.py

`diff -r db5502ca296c -r f74ac05eae85 sage/interfaces/maxima.py`
 a """ return maxima_version() ##some helper functions to wrap tha calculus use of the maxima interface. ##these routines expect arguments living in the symbolic ring and return something ##that is hopefully coercible into the symbolic ring again. def sr_integral(self,*args): return args[0]._maxima_().integrate(*args[1:]) def sr_sum(self,expression,v,a,b): sum  = "'sum(%s, %s, %s, %s)" % tuple([repr(expr._maxima_()) for expr in (expression, v, a, b)]) result = self.simplify_sum(sum) result = result.ratsimp() return expression.parent()(result) def sr_limit(self,ex,*args): return ex._maxima_().limit(*args) def sr_tlimit(self,ex,*args): return ex._maxima_().tlimit(*args) ##     def display2d(self, flag=True): ##         """ ##         Set the flag that determines whether Maxima objects are def __doctest_cleanup(): import sage.interfaces.quit sage.interfaces.quit.expect_quitall()
• ## sage/interfaces/maxima_lib.py

`diff -r db5502ca296c -r f74ac05eae85 sage/interfaces/maxima_lib.py`
`diff -r db5502ca296c -r f74ac05eae85 sage/libs/ecl/ecl.pyx`