# Ticket #12438: trac_12438_drop_variable_of_definite_integration.patch

File trac_12438_drop_variable_of_definite_integration.patch, 6.8 KB (added by Andrey Novoseltsev, 11 years ago)

Apply this patch only

• ## sage/calculus/calculus.py

```# HG changeset patch
# User Andrey Novoseltsev <novoselt@gmail.com>
# Date 1338240084 25200
# Node ID b151fdd7f9f6ec36d26ec1890e47210bc86236b0
# Parent  505e0f410c857bc634338329f7267c4ec31598c3
Drop the variable of definite integration from the list of arguments.

diff --git a/sage/calculus/calculus.py b/sage/calculus/calculus.py```
 a sage: f(x)=x sage: integrate(f,x,0,1) x |--> 1/2 1/2 Check that the problem with Taylor expansions of the gamma function (Trac #9217) is fixed::
• ## sage/symbolic/expression.pyx

`diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx`
 a -cos(3) + 1 sage: sin(x).integral(x) -cos(x) """ from sage.symbolic.integration.integral import integral from sage.symbolic.callable import is_CallableSymbolicExpressionRing if is_CallableSymbolicExpressionRing(self._parent): return self._parent(integral(ring.SR(self), *args, **kwds)) TESTS: We check that :trac:`12438` is resolved:: sage: f(x) = x; f x |--> x sage: integral(f, x) x |--> 1/2*x^2 sage: integral(f, x, 0, 1) 1/2 sage: f(x, y) = x + y sage: f (x, y) |--> x + y sage: integral(f, y, 0, 1) x |--> x + 1/2 sage: integral(f, x, 0, 1) y |--> y + 1/2 sage: _(3) 7/2 sage: var("z") z sage: integral(f, z, 0, 2) (x, y) |--> 2*x + 2*y sage: integral(f, z) (x, y) |--> (x + y)*z """ from sage.symbolic.integration.integral import \ integral, _normalize_integral_input from sage.symbolic.callable import \ CallableSymbolicExpressionRing, is_CallableSymbolicExpressionRing R = self._parent if is_CallableSymbolicExpressionRing(R): f = ring.SR(self) f, v, a, b = _normalize_integral_input(f, *args) # Definite integral with respect to a positional variable. if a is not None and v in R.arguments(): arguments = list(R.arguments()) arguments.remove(v) if arguments: arguments = tuple(arguments) R = CallableSymbolicExpressionRing(arguments, check=False) else:   # all arguments are gone R = ring.SR return R(integral(f, v, a, b, **kwds)) return integral(self, *args, **kwds) integrate = integral
• ## sage/symbolic/integration/integral.py

`diff --git a/sage/symbolic/integration/integral.py b/sage/symbolic/integration/integral.py`
 a definite_integral = DefiniteIntegral() def _normalize_integral_input(f, v=None, a=None, b=None): r""" Validate and return variable and endpoints for an integral. INPUT: - ``f`` -- an expression to integrate; - ``v`` -- a variable of integration or a triple; - ``a`` -- (optional) the left endpoint of integration; - ``b`` -- (optional) the right endpoint of integration. It is also possible to pass last three parameters in ``v`` as a triple. OUPUT: - a tuple of ``f``, ``v``, ``a``, and ``b``. EXAMPLES:: sage: from sage.symbolic.integration.integral import \ ...       _normalize_integral_input sage: _normalize_integral_input(x^2, x, 0, 3) (x^2, x, 0, 3) sage: _normalize_integral_input(x^2, [x, 0, 3], None, None) (x^2, x, 0, 3) sage: _normalize_integral_input(x^2, [0, 3], None, None) doctest:...: DeprecationWarning: Variable of integration should be specified explicitly. (x^2, x, 0, 3) sage: _normalize_integral_input(x^2, [x], None, None) (x^2, x, None, None) """ if isinstance(v, (list, tuple)) and a is None and b is None: if len(v) == 1: # bare variable in a tuple v = v[0] elif len(v) == 2: # endpoints only a, b = v v = None elif len(v) == 3: # variable and endpoints v, a, b = v else: raise ValueError("invalid input %s - please use variable, " "with or without two endpoints" % repr(v)) elif b is None and a is not None: # two arguments, must be endpoints v, a, b = None, v, a if v is None: from sage.misc.misc import deprecation deprecation("Variable of integration should be specified explicitly.") v = f.default_variable() if isinstance(f, Function):  # a bare function like sin f = f(v) if (a is None) ^ (b is None): raise TypeError('only one endpoint was given!') return f, v, a, b def integrate(expression, v=None, a=None, b=None, algorithm=None): r""" Returns the indefinite integral with respect to the variable sage: f(x) = sin(x) sage: f.integral(x, 0, pi/2) x |--> 1 1 The variable is required, but the endpoints are optional:: 4.32025625668262 """ if isinstance(v, (list, tuple)) and a is None and b is None: if len(v)==1: # bare variable in a tuple v=v[0] elif len(v)==3: # variable and endpoints v,a,b=v elif len(v)==2: # endpoints only a,b=v v=None elif len(v)==0: v=None else: raise ValueError, "invalid input %s - please use variable, with or without two endpoints"%repr(v) elif b is None and a is not None: # two arguments, must be endpoints a, b = v, a v = None if v is None: from sage.misc.misc import deprecation deprecation("Variable of integration should be specified explicitly.") v = expression.default_variable() if isinstance(expression, Function): # a bare function like sin expression = expression(v) if (a is None) ^ (b is None): raise TypeError, 'only one endpoint given' # Check algorithm expression, v, a, b = _normalize_integral_input(expression, v, a, b) if algorithm is not None: integrator = available_integrators.get(algorithm) if not integrator: raise ValueError, "Unknown algorithm: %s" % algorithm return integrator(expression, v, a, b) if a is None: return indefinite_integral(expression, v) else: