Ticket #6816: trac_6816-tuples-in-integral.patch

File trac_6816-tuples-in-integral.patch, 2.1 KB (added by kcrisman, 10 years ago)

Based on 4.2.alpha0

  • sage/calculus/calculus.py

    # HG changeset patch
    # User Karl-Dieter Crisman <kcrisman@gmail.com>
    # Date 1256019703 14400
    # Node ID 8f79b8b62ff68fcdaf6f5c9611894cc0d38889a8
    # Parent  59d26b2eff2d5d112b6dfb04f6390ab63eb89876
    Allow tuple input for integration - trac 6816.
    
    diff -r 59d26b2eff2d -r 8f79b8b62ff6 sage/calculus/calculus.py
    a b  
    553553        sage: res.subs(y=.5).n()
    554554        -0.669511708873
    555555
     556    Check if #6816 is fixed::
     557
     558        sage: var('t,theta')
     559        (t, theta)
     560        sage: integrate(t*cos(-theta*t),t,-oo,oo)
     561        0
     562        sage: integrate(t*cos(-theta*t),(t,-oo,oo))
     563        0
     564        sage: integrate(t*cos(-theta*t),(t))
     565        (t*theta*sin(t*theta) + cos(t*theta))/theta^2
     566        sage: integrate(t*cos(-theta*t),(-oo,oo)) # probably shouldn't be allowed to work, but for now we let it
     567        0
     568        sage: integrate(x^2,(x)) # this worked before
     569        1/3*x^3
     570        sage: integrate(x^2,(x,)) # this didn't
     571        1/3*x^3
     572        sage: integrate(x^2,(1,2)) # this case should always be allowed to work
     573        7/3
     574        sage: integrate(x^2,(x,1,2))
     575        7/3
     576        sage: integrate(x^2,(x,1,2,3))
     577        Traceback (most recent call last):
     578        ...
     579        ValueError: (x, 1, 2, 3) is not valid input to integral()
     580
    556581    Check if #6189 is fixed (which, by the way, also
    557582    demonstrates it's not always good to expand)::
    558583
     
    579604            expression = expression(v)
    580605
    581606    elif not is_SymbolicVariable(v):
     607        if type(v) is tuple:
     608            if len(v)==1: # just a variable
     609                return integral(expression,v[0])
     610            elif len(v)==2: # just endpoints, no variable; could be dangerous
     611                return integral(expression,v[0],v[1])
     612            elif len(v)==3: # endpoints and variable
     613                return integral(expression,v[0],v[1],v[2])
     614            else:
     615                raise ValueError, "%s is not valid input to integral()"%repr(v)
    582616        v = var(repr(v))
    583617        #raise TypeError, 'must integrate with respect to a variable'
    584618