Ticket #12438: trac_12438_drop_variable_of_definite_integration.patch

File trac_12438_drop_variable_of_definite_integration.patch, 6.8 KB (added by novoselt, 10 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 b  
    339339
    340340    sage: f(x)=x
    341341    sage: integrate(f,x,0,1)
    342     x |--> 1/2
     342    1/2
    343343
    344344Check that the problem with Taylor expansions of the gamma function
    345345(Trac #9217) is fixed::
  • sage/symbolic/expression.pyx

    diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
    a b  
    87428742            -cos(3) + 1
    87438743            sage: sin(x).integral(x)
    87448744            -cos(x)
    8745         """
    8746         from sage.symbolic.integration.integral import integral
    8747         from sage.symbolic.callable import is_CallableSymbolicExpressionRing
    8748         if is_CallableSymbolicExpressionRing(self._parent):
    8749             return self._parent(integral(ring.SR(self), *args, **kwds))
     8745           
     8746        TESTS:
     8747
     8748        We check that :trac:`12438` is resolved::
     8749       
     8750            sage: f(x) = x; f
     8751            x |--> x
     8752            sage: integral(f, x)
     8753            x |--> 1/2*x^2
     8754            sage: integral(f, x, 0, 1)
     8755            1/2
     8756
     8757            sage: f(x, y) = x + y
     8758            sage: f
     8759            (x, y) |--> x + y
     8760            sage: integral(f, y, 0, 1)
     8761            x |--> x + 1/2
     8762            sage: integral(f, x, 0, 1)
     8763            y |--> y + 1/2
     8764            sage: _(3)
     8765            7/2
     8766            sage: var("z")
     8767            z
     8768            sage: integral(f, z, 0, 2)
     8769            (x, y) |--> 2*x + 2*y
     8770            sage: integral(f, z)
     8771            (x, y) |--> (x + y)*z
     8772        """
     8773        from sage.symbolic.integration.integral import \
     8774            integral, _normalize_integral_input
     8775        from sage.symbolic.callable import \
     8776            CallableSymbolicExpressionRing, is_CallableSymbolicExpressionRing
     8777        R = self._parent
     8778        if is_CallableSymbolicExpressionRing(R):
     8779            f = ring.SR(self)
     8780            f, v, a, b = _normalize_integral_input(f, *args)
     8781            # Definite integral with respect to a positional variable.
     8782            if a is not None and v in R.arguments():
     8783                arguments = list(R.arguments())
     8784                arguments.remove(v)
     8785                if arguments:
     8786                    arguments = tuple(arguments)
     8787                    R = CallableSymbolicExpressionRing(arguments, check=False)
     8788                else:   # all arguments are gone
     8789                    R = ring.SR
     8790            return R(integral(f, v, a, b, **kwds))
    87508791        return integral(self, *args, **kwds)
    87518792
    87528793    integrate = integral
  • sage/symbolic/integration/integral.py

    diff --git a/sage/symbolic/integration/integral.py b/sage/symbolic/integration/integral.py
    a b  
    248248
    249249definite_integral = DefiniteIntegral()
    250250
     251
     252def _normalize_integral_input(f, v=None, a=None, b=None):
     253    r"""
     254    Validate and return variable and endpoints for an integral.
     255   
     256    INPUT:
     257   
     258    - ``f`` -- an expression to integrate;
     259   
     260    - ``v`` -- a variable of integration or a triple;
     261   
     262    - ``a`` -- (optional) the left endpoint of integration;
     263   
     264    - ``b`` -- (optional) the right endpoint of integration.
     265   
     266    It is also possible to pass last three parameters in ``v`` as a triple.
     267   
     268    OUPUT:
     269   
     270    - a tuple of ``f``, ``v``, ``a``, and ``b``.
     271   
     272    EXAMPLES::
     273   
     274        sage: from sage.symbolic.integration.integral import \
     275        ...       _normalize_integral_input
     276        sage: _normalize_integral_input(x^2, x, 0, 3)
     277        (x^2, x, 0, 3)
     278        sage: _normalize_integral_input(x^2, [x, 0, 3], None, None)
     279        (x^2, x, 0, 3)
     280        sage: _normalize_integral_input(x^2, [0, 3], None, None)
     281        doctest:...: DeprecationWarning:
     282        Variable of integration should be specified explicitly.
     283        (x^2, x, 0, 3)
     284        sage: _normalize_integral_input(x^2, [x], None, None)
     285        (x^2, x, None, None)
     286    """
     287    if isinstance(v, (list, tuple)) and a is None and b is None:
     288        if len(v) == 1: # bare variable in a tuple
     289            v = v[0]
     290        elif len(v) == 2: # endpoints only
     291            a, b = v
     292            v = None
     293        elif len(v) == 3: # variable and endpoints
     294            v, a, b = v
     295        else:
     296            raise ValueError("invalid input %s - please use variable, "
     297                             "with or without two endpoints" % repr(v))
     298    elif b is None and a is not None:
     299        # two arguments, must be endpoints
     300        v, a, b = None, v, a
     301    if v is None:
     302        from sage.misc.misc import deprecation
     303        deprecation("Variable of integration should be specified explicitly.")
     304        v = f.default_variable()
     305        if isinstance(f, Function):  # a bare function like sin
     306            f = f(v)
     307    if (a is None) ^ (b is None):
     308        raise TypeError('only one endpoint was given!')
     309    return f, v, a, b
     310
    251311def integrate(expression, v=None, a=None, b=None, algorithm=None):
    252312    r"""
    253313    Returns the indefinite integral with respect to the variable
     
    306366
    307367        sage: f(x) = sin(x)
    308368        sage: f.integral(x, 0, pi/2)
    309         x |--> 1
     369        1
    310370
    311371    The variable is required, but the endpoints are optional::
    312372
     
    603663        4.32025625668262
    604664
    605665    """
    606     if isinstance(v, (list, tuple)) and a is None and b is None:
    607         if len(v)==1: # bare variable in a tuple
    608             v=v[0]
    609         elif len(v)==3: # variable and endpoints
    610             v,a,b=v
    611         elif len(v)==2: # endpoints only
    612             a,b=v
    613             v=None
    614         elif len(v)==0:
    615             v=None
    616         else:
    617             raise ValueError, "invalid input %s - please use variable, with or without two endpoints"%repr(v)
    618     elif b is None and a is not None:
    619         # two arguments, must be endpoints
    620         a, b = v, a
    621         v = None
    622 
    623     if v is None:
    624         from sage.misc.misc import deprecation
    625         deprecation("Variable of integration should be specified explicitly.")
    626         v = expression.default_variable()
    627         if isinstance(expression, Function):
    628             # a bare function like sin
    629             expression = expression(v)
    630 
    631     if (a is None) ^ (b is None):
    632         raise TypeError, 'only one endpoint given'
    633 
    634     # Check algorithm
     666    expression, v, a, b = _normalize_integral_input(expression, v, a, b)
    635667    if algorithm is not None:
    636668        integrator = available_integrators.get(algorithm)
    637669        if not integrator:
    638670            raise ValueError, "Unknown algorithm: %s" % algorithm
    639671        return integrator(expression, v, a, b)
    640 
    641672    if a is None:
    642673        return indefinite_integral(expression, v)
    643674    else: