<s> from __future__ import print_function , division <EOL> from sympy . concrete . expr_with_limits import AddWithLimits <EOL> from sympy . core . add import Add <EOL> from sympy . core . basic import Basic <EOL> from sympy . core . compatibility import is_sequence , range <EOL> from sympy . core . containers import Tuple <EOL> from sympy . core . expr import Expr <EOL> from sympy . core . function import diff <EOL> from sympy . core . mul import Mul <EOL> from sympy . core . numbers import oo <EOL> from sympy . core . relational import Eq <EOL> from sympy . core . singleton import S <EOL> from sympy . core . symbol import ( Dummy , Symbol , Wild ) <EOL> from sympy . core . sympify import sympify <EOL> from sympy . integrals . manualintegrate import manualintegrate <EOL> from sympy . integrals . trigonometry import trigintegrate <EOL> from sympy . integrals . meijerint import meijerint_definite , meijerint_indefinite <EOL> from sympy . matrices import MatrixBase <EOL> from sympy . utilities . misc import filldedent <EOL> from sympy . polys import Poly , PolynomialError <EOL> from sympy . functions import Piecewise , sqrt , sign <EOL> from sympy . functions . elementary . exponential import log <EOL> from sympy . series import limit <EOL> from sympy . series . order import Order <EOL> class Integral ( AddWithLimits ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = [ '<STR_LIT>' ] <EOL> def __new__ ( cls , function , * symbols , ** assumptions ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( function , '<STR_LIT>' ) : <EOL> return function . _eval_Integral ( * symbols , ** assumptions ) <EOL> obj = AddWithLimits . __new__ ( cls , function , * symbols , ** assumptions ) <EOL> return obj <EOL> def __getnewargs__ ( self ) : <EOL> return ( self . function , ) + tuple ( [ tuple ( xab ) for xab in self . limits ] ) <EOL> @ property <EOL> def free_symbols ( self ) : <EOL> """<STR_LIT>""" <EOL> return AddWithLimits . free_symbols . fget ( self ) <EOL> def _eval_is_zero ( self ) : <EOL> if self . function . is_zero : <EOL> return True <EOL> got_none = False <EOL> for l in self . limits : <EOL> if len ( l ) == <NUM_LIT:3> : <EOL> z = ( l [ <NUM_LIT:1> ] == l [ <NUM_LIT:2> ] ) or ( l [ <NUM_LIT:1> ] - l [ <NUM_LIT:2> ] ) . is_zero <EOL> if z : <EOL> return True <EOL> elif z is None : <EOL> got_none = True <EOL> free = self . function . free_symbols <EOL> for xab in self . limits : <EOL> if len ( xab ) == <NUM_LIT:1> : <EOL> free . add ( xab [ <NUM_LIT:0> ] ) <EOL> continue <EOL> if len ( xab ) == <NUM_LIT:2> and xab [ <NUM_LIT:0> ] not in free : <EOL> if xab [ <NUM_LIT:1> ] . is_zero : <EOL> return True <EOL> elif xab [ <NUM_LIT:1> ] . is_zero is None : <EOL> got_none = True <EOL> free . discard ( xab [ <NUM_LIT:0> ] ) <EOL> for i in xab [ <NUM_LIT:1> : ] : <EOL> free . update ( i . free_symbols ) <EOL> if self . function . is_zero is False and got_none is False : <EOL> return False <EOL> def transform ( self , x , u ) : <EOL> r"""<STR_LIT>""" <EOL> from sympy . solvers . solvers import solve , posify <EOL> d = Dummy ( '<STR_LIT:d>' ) <EOL> xfree = x . free_symbols . intersection ( self . variables ) <EOL> if len ( xfree ) > <NUM_LIT:1> : <EOL> raise ValueError ( <EOL> '<STR_LIT>' % self . variables ) <EOL> xvar = xfree . pop ( ) if xfree else d <EOL> if xvar not in self . variables : <EOL> return self <EOL> u = sympify ( u ) <EOL> if isinstance ( u , Expr ) : <EOL> ufree = u . free_symbols <EOL> if len ( ufree ) != <NUM_LIT:1> : <EOL> raise ValueError ( filldedent ( '''<STR_LIT>''' ) ) <EOL> uvar = ufree . pop ( ) <EOL> else : <EOL> u , uvar = u <EOL> if uvar not in u . free_symbols : <EOL> raise ValueError ( filldedent ( '''<STR_LIT>''' ) ) <EOL> if not isinstance ( uvar , Symbol ) : <EOL> raise ValueError ( filldedent ( '''<STR_LIT>''' % uvar ) ) <EOL> if x . is_Symbol and u . is_Symbol : <EOL> return self . xreplace ( { x : u } ) <EOL> if not x . is_Symbol and not u . is_Symbol : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if uvar == xvar : <EOL> return self . transform ( x , ( u . subs ( uvar , d ) , d ) ) . xreplace ( { d : uvar } ) <EOL> if uvar in self . limits : <EOL> raise ValueError ( filldedent ( '''<STR_LIT>''' ) ) <EOL> if not x . is_Symbol : <EOL> F = [ x . subs ( xvar , d ) ] <EOL> soln = solve ( u - x , xvar , check = False ) <EOL> if not soln : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> f = [ fi . subs ( uvar , d ) for fi in soln ] <EOL> else : <EOL> f = [ u . subs ( uvar , d ) ] <EOL> pdiff , reps = posify ( u - x ) <EOL> puvar = uvar . subs ( [ ( v , k ) for k , v in reps . items ( ) ] ) <EOL> soln = [ s . subs ( reps ) for s in solve ( pdiff , puvar ) ] <EOL> if not soln : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> F = [ fi . subs ( xvar , d ) for fi in soln ] <EOL> newfuncs = set ( [ ( self . function . subs ( xvar , fi ) * fi . diff ( d ) <EOL> ) . subs ( d , uvar ) for fi in f ] ) <EOL> if len ( newfuncs ) > <NUM_LIT:1> : <EOL> raise ValueError ( filldedent ( '''<STR_LIT>''' ) ) <EOL> newfunc = newfuncs . pop ( ) <EOL> def _calc_limit_1 ( F , a , b ) : <EOL> """<STR_LIT>""" <EOL> wok = F . subs ( d , a ) <EOL> if wok is S . NaN or wok . is_finite is False and a . is_finite : <EOL> return limit ( sign ( b ) * F , d , a ) <EOL> return wok <EOL> def _calc_limit ( a , b ) : <EOL> """<STR_LIT>""" <EOL> avals = list ( { _calc_limit_1 ( Fi , a , b ) for Fi in F } ) <EOL> if len ( avals ) > <NUM_LIT:1> : <EOL> raise ValueError ( filldedent ( '''<STR_LIT>''' ) ) <EOL> return avals [ <NUM_LIT:0> ] <EOL> newlimits = [ ] <EOL> for xab in self . limits : <EOL> sym = xab [ <NUM_LIT:0> ] <EOL> if sym == xvar : <EOL> if len ( xab ) == <NUM_LIT:3> : <EOL> a , b = xab [ <NUM_LIT:1> : ] <EOL> a , b = _calc_limit ( a , b ) , _calc_limit ( b , a ) <EOL> if a - b > <NUM_LIT:0> : <EOL> a , b = b , a <EOL> newfunc = - newfunc <EOL> newlimits . append ( ( uvar , a , b ) ) <EOL> elif len ( xab ) == <NUM_LIT:2> : <EOL> a = _calc_limit ( xab [ <NUM_LIT:1> ] , <NUM_LIT:1> ) <EOL> newlimits . append ( ( uvar , a ) ) <EOL> else : <EOL> newlimits . append ( uvar ) <EOL> else : <EOL> newlimits . append ( xab ) <EOL> return self . func ( newfunc , * newlimits ) <EOL> def doit ( self , ** hints ) : <EOL> """<STR_LIT>""" <EOL> if not hints . get ( '<STR_LIT>' , True ) : <EOL> return self <EOL> deep = hints . get ( '<STR_LIT>' , True ) <EOL> meijerg = hints . get ( '<STR_LIT>' , None ) <EOL> conds = hints . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> risch = hints . get ( '<STR_LIT>' , None ) <EOL> manual = hints . get ( '<STR_LIT>' , None ) <EOL> if conds not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:none>' ] : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' % conds ) <EOL> if risch and any ( len ( xab ) > <NUM_LIT:1> for xab in self . limits ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if self . is_zero : <EOL> return S . Zero <EOL> function = self . function <EOL> if deep : <EOL> function = function . doit ( ** hints ) <EOL> if function . is_zero : <EOL> return S . Zero <EOL> if isinstance ( function , MatrixBase ) : <EOL> return function . applyfunc ( lambda f : self . func ( f , self . limits ) . doit ( ** hints ) ) <EOL> undone_limits = [ ] <EOL> ulj = set ( ) <EOL> for xab in self . limits : <EOL> if len ( xab ) == <NUM_LIT:1> : <EOL> uli = set ( xab [ : <NUM_LIT:1> ] ) <EOL> elif len ( xab ) == <NUM_LIT:2> : <EOL> uli = xab [ <NUM_LIT:1> ] . free_symbols <EOL> elif len ( xab ) == <NUM_LIT:3> : <EOL> uli = xab [ <NUM_LIT:1> ] . free_symbols . union ( xab [ <NUM_LIT:2> ] . free_symbols ) <EOL> if xab [ <NUM_LIT:0> ] in ulj or any ( v [ <NUM_LIT:0> ] in uli for v in undone_limits ) : <EOL> undone_limits . append ( xab ) <EOL> ulj . update ( uli ) <EOL> function = self . func ( * ( [ function ] + [ xab ] ) ) <EOL> factored_function = function . factor ( ) <EOL> if not isinstance ( factored_function , Integral ) : <EOL> function = factored_function <EOL> continue <EOL> def try_meijerg ( function , xab ) : <EOL> ret = None <EOL> if len ( xab ) == <NUM_LIT:3> and meijerg is not False : <EOL> x , a , b = xab <EOL> try : <EOL> res = meijerint_definite ( function , x , a , b ) <EOL> except NotImplementedError : <EOL> from sympy . integrals . meijerint import _debug <EOL> _debug ( '<STR_LIT>' ) <EOL> res = None <EOL> if res is not None : <EOL> f , cond = res <EOL> if conds == '<STR_LIT>' : <EOL> ret = Piecewise ( ( f , cond ) , <EOL> ( self . func ( function , ( x , a , b ) ) , True ) ) <EOL> elif conds == '<STR_LIT>' : <EOL> if len ( self . limits ) != <NUM_LIT:1> : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ret = f , cond <EOL> else : <EOL> ret = f <EOL> return ret <EOL> meijerg1 = meijerg <EOL> if len ( xab ) == <NUM_LIT:3> and xab [ <NUM_LIT:1> ] . is_real and xab [ <NUM_LIT:2> ] . is_real and not function . is_Poly and ( xab [ <NUM_LIT:1> ] . has ( oo , - oo ) or xab [ <NUM_LIT:2> ] . has ( oo , - oo ) ) : <EOL> ret = try_meijerg ( function , xab ) <EOL> if ret is not None : <EOL> function = ret <EOL> continue <EOL> else : <EOL> meijerg1 = False <EOL> if meijerg1 is False and meijerg is True : <EOL> antideriv = None <EOL> else : <EOL> antideriv = self . _eval_integral ( <EOL> function , xab [ <NUM_LIT:0> ] , <EOL> meijerg = meijerg1 , risch = risch , manual = manual , <EOL> conds = conds ) <EOL> if antideriv is None and meijerg1 is True : <EOL> ret = try_meijerg ( function , xab ) <EOL> if ret is not None : <EOL> function = ret <EOL> continue <EOL> if antideriv is None : <EOL> undone_limits . append ( xab ) <EOL> function = self . func ( * ( [ function ] + [ xab ] ) ) . factor ( ) <EOL> factored_function = function . factor ( ) <EOL> if not isinstance ( factored_function , Integral ) : <EOL> function = factored_function <EOL> continue <EOL> else : <EOL> if len ( xab ) == <NUM_LIT:1> : <EOL> function = antideriv <EOL> else : <EOL> if len ( xab ) == <NUM_LIT:3> : <EOL> x , a , b = xab <EOL> elif len ( xab ) == <NUM_LIT:2> : <EOL> x , b = xab <EOL> a = None <EOL> else : <EOL> raise NotImplementedError <EOL> if deep : <EOL> if isinstance ( a , Basic ) : <EOL> a = a . doit ( ** hints ) <EOL> if isinstance ( b , Basic ) : <EOL> b = b . doit ( ** hints ) <EOL> if antideriv . is_Poly : <EOL> gens = list ( antideriv . gens ) <EOL> gens . remove ( x ) <EOL> antideriv = antideriv . as_expr ( ) <EOL> function = antideriv . _eval_interval ( x , a , b ) <EOL> function = Poly ( function , * gens ) <EOL> else : <EOL> def is_indef_int ( g , x ) : <EOL> return ( isinstance ( g , Integral ) and <EOL> any ( i == ( x , ) for i in g . limits ) ) <EOL> def eval_factored ( f , x , a , b ) : <EOL> args = [ ] <EOL> for g in Mul . make_args ( f ) : <EOL> if is_indef_int ( g , x ) : <EOL> args . append ( g . _eval_interval ( x , a , b ) ) <EOL> else : <EOL> args . append ( g ) <EOL> return Mul ( * args ) <EOL> integrals , others = [ ] , [ ] <EOL> for f in Add . make_args ( antideriv ) : <EOL> if any ( is_indef_int ( g , x ) <EOL> for g in Mul . make_args ( f ) ) : <EOL> integrals . append ( f ) <EOL> else : <EOL> others . append ( f ) <EOL> uneval = Add ( * [ eval_factored ( f , x , a , b ) <EOL> for f in integrals ] ) <EOL> try : <EOL> evalued = Add ( * others ) . _eval_interval ( x , a , b ) <EOL> function = uneval + evalued <EOL> except NotImplementedError : <EOL> undone_limits . append ( xab ) <EOL> function = self . func ( * ( [ function ] + [ xab ] ) ) <EOL> factored_function = function . factor ( ) <EOL> if not isinstance ( factored_function , Integral ) : <EOL> function = factored_function <EOL> return function <EOL> def _eval_derivative ( self , sym ) : <EOL> """<STR_LIT>""" <EOL> f , limits = self . function , list ( self . limits ) <EOL> limit = limits . pop ( - <NUM_LIT:1> ) <EOL> if len ( limit ) == <NUM_LIT:3> : <EOL> x , a , b = limit <EOL> elif len ( limit ) == <NUM_LIT:2> : <EOL> x , b = limit <EOL> a = None <EOL> else : <EOL> a = b = None <EOL> x = limit [ <NUM_LIT:0> ] <EOL> if limits : <EOL> f = self . func ( f , * tuple ( limits ) ) <EOL> def _do ( f , ab ) : <EOL> dab_dsym = diff ( ab , sym ) <EOL> if not dab_dsym : <EOL> return S . Zero <EOL> if isinstance ( f , Integral ) : <EOL> limits = [ ( x , x ) if ( len ( l ) == <NUM_LIT:1> and l [ <NUM_LIT:0> ] == x ) else l <EOL> for l in f . limits ] <EOL> f = self . func ( f . function , * limits ) <EOL> return f . subs ( x , ab ) * dab_dsym <EOL> rv = <NUM_LIT:0> <EOL> if b is not None : <EOL> rv += _do ( f , b ) <EOL> if a is not None : <EOL> rv -= _do ( f , a ) <EOL> if len ( limit ) == <NUM_LIT:1> and sym == x : <EOL> arg = f <EOL> rv += arg <EOL> else : <EOL> u = Dummy ( '<STR_LIT:u>' ) <EOL> arg = f . subs ( x , u ) . diff ( sym ) . subs ( u , x ) <EOL> rv += self . func ( arg , Tuple ( x , a , b ) ) <EOL> return rv <EOL> def _eval_integral ( self , f , x , meijerg = None , risch = None , manual = None , <EOL> conds = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> from sympy . integrals . deltafunctions import deltaintegrate <EOL> from sympy . integrals . heurisch import heurisch , heurisch_wrapper <EOL> from sympy . integrals . rationaltools import ratint <EOL> from sympy . integrals . risch import risch_integrate <EOL> if risch : <EOL> try : <EOL> return risch_integrate ( f , x , conds = conds ) <EOL> except NotImplementedError : <EOL> return None <EOL> if manual : <EOL> try : <EOL> result = manualintegrate ( f , x ) <EOL> if result is not None and result . func != Integral : <EOL> return result <EOL> except ( ValueError , PolynomialError ) : <EOL> pass <EOL> if isinstance ( f , Poly ) and not meijerg : <EOL> return f . integrate ( x ) <EOL> if f . func is Piecewise : <EOL> return f . _eval_integral ( x ) <EOL> if not f . has ( x ) : <EOL> return f * x <EOL> poly = f . as_poly ( x ) <EOL> if poly is not None and not meijerg : <EOL> return poly . integrate ( ) . as_expr ( ) <EOL> if risch is not False : <EOL> try : <EOL> result , i = risch_integrate ( f , x , separate_integral = True , conds = conds ) <EOL> except NotImplementedError : <EOL> pass <EOL> else : <EOL> if i : <EOL> return result + i . doit ( risch = False ) <EOL> else : <EOL> return result <EOL> parts = [ ] <EOL> args = Add . make_args ( f ) <EOL> for g in args : <EOL> coeff , g = g . as_independent ( x ) <EOL> if g is S . One and not meijerg : <EOL> parts . append ( coeff * x ) <EOL> continue <EOL> order_term = g . getO ( ) <EOL> if order_term is not None : <EOL> h = self . _eval_integral ( g . removeO ( ) , x ) <EOL> if h is not None : <EOL> h_order_expr = self . _eval_integral ( order_term . expr , x ) <EOL> if h_order_expr is not None : <EOL> h_order_term = order_term . func ( <EOL> h_order_expr , * order_term . variables ) <EOL> parts . append ( coeff * ( h + h_order_term ) ) <EOL> continue <EOL> return None <EOL> if g . is_Pow and not g . exp . has ( x ) and not meijerg : <EOL> a = Wild ( '<STR_LIT:a>' , exclude = [ x ] ) <EOL> b = Wild ( '<STR_LIT:b>' , exclude = [ x ] ) <EOL> M = g . base . match ( a * x + b ) <EOL> if M is not None : <EOL> if g . exp == - <NUM_LIT:1> : <EOL> h = log ( g . base ) <EOL> elif conds != '<STR_LIT>' : <EOL> h = g . base ** ( g . exp + <NUM_LIT:1> ) / ( g . exp + <NUM_LIT:1> ) <EOL> else : <EOL> h1 = log ( g . base ) <EOL> h2 = g . base ** ( g . exp + <NUM_LIT:1> ) / ( g . exp + <NUM_LIT:1> ) <EOL> h = Piecewise ( ( h1 , Eq ( g . exp , - <NUM_LIT:1> ) ) , ( h2 , True ) ) <EOL> parts . append ( coeff * h / M [ a ] ) <EOL> continue <EOL> if g . is_rational_function ( x ) and not meijerg : <EOL> parts . append ( coeff * ratint ( g , x ) ) <EOL> continue <EOL> if not meijerg : <EOL> h = trigintegrate ( g , x , conds = conds ) <EOL> if h is not None : <EOL> parts . append ( coeff * h ) <EOL> continue <EOL> h = deltaintegrate ( g , x ) <EOL> if h is not None : <EOL> parts . append ( coeff * h ) <EOL> continue <EOL> if risch is not False : <EOL> try : <EOL> h , i = risch_integrate ( g , x , separate_integral = True , conds = conds ) <EOL> except NotImplementedError : <EOL> h = None <EOL> else : <EOL> if i : <EOL> h = h + i . doit ( risch = False ) <EOL> parts . append ( coeff * h ) <EOL> continue <EOL> try : <EOL> if conds == '<STR_LIT>' : <EOL> h = heurisch_wrapper ( g , x , hints = [ ] ) <EOL> else : <EOL> h = heurisch ( g , x , hints = [ ] ) <EOL> except PolynomialError : <EOL> h = None <EOL> else : <EOL> h = None <EOL> if meijerg is not False and h is None : <EOL> try : <EOL> h = meijerint_indefinite ( g , x ) <EOL> except NotImplementedError : <EOL> from sympy . integrals . meijerint import _debug <EOL> _debug ( '<STR_LIT>' ) <EOL> res = None <EOL> if h is not None : <EOL> parts . append ( coeff * h ) <EOL> continue <EOL> if h is None and manual is not False : <EOL> try : <EOL> result = manualintegrate ( g , x ) <EOL> if result is not None and not isinstance ( result , Integral ) : <EOL> if result . has ( Integral ) : <EOL> result = result . func ( * [ <EOL> arg . doit ( manual = False ) if arg . has ( Integral ) else arg <EOL> for arg in result . args <EOL> ] ) . expand ( multinomial = False , <EOL> log = False , <EOL> power_exp = False , <EOL> power_base = False ) <EOL> if not result . has ( Integral ) : <EOL> parts . append ( coeff * result ) <EOL> continue <EOL> except ( ValueError , PolynomialError ) : <EOL> pass <EOL> if not h and len ( args ) == <NUM_LIT:1> : <EOL> f = f . expand ( mul = True , deep = False ) <EOL> if f . is_Add : <EOL> return self . _eval_integral ( f , x , meijerg = meijerg , risch = risch , conds = conds ) <EOL> if h is not None : <EOL> parts . append ( coeff * h ) <EOL> else : <EOL> return None <EOL> return Add ( * parts ) <EOL> def _eval_lseries ( self , x , logx ) : <EOL> expr = self . as_dummy ( ) <EOL> symb = x <EOL> for l in expr . limits : <EOL> if x in l [ <NUM_LIT:1> : ] : <EOL> symb = l [ <NUM_LIT:0> ] <EOL> break <EOL> for term in expr . function . lseries ( symb , logx ) : <EOL> yield integrate ( term , * expr . limits ) <EOL> def _eval_nseries ( self , x , n , logx ) : <EOL> expr = self . as_dummy ( ) <EOL> symb = x <EOL> for l in expr . limits : <EOL> if x in l [ <NUM_LIT:1> : ] : <EOL> symb = l [ <NUM_LIT:0> ] <EOL> break <EOL> terms , order = expr . function . nseries ( <EOL> x = symb , n = n , logx = logx ) . as_coeff_add ( Order ) <EOL> return integrate ( terms , * expr . limits ) + Add ( * order ) * x <EOL> def as_sum ( self , n , method = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> limits = self . limits <EOL> if len ( limits ) > <NUM_LIT:1> : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" ) <EOL> else : <EOL> limit = limits [ <NUM_LIT:0> ] <EOL> if len ( limit ) != <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if n <= <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if n == oo : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> sym , lower_limit , upper_limit = limit <EOL> dx = ( upper_limit - lower_limit ) / n <EOL> if method == '<STR_LIT>' : <EOL> l = self . function . limit ( sym , lower_limit ) <EOL> r = self . function . limit ( sym , upper_limit , "<STR_LIT:->" ) <EOL> result = ( l + r ) / <NUM_LIT:2> <EOL> for i in range ( <NUM_LIT:1> , n ) : <EOL> x = lower_limit + i * dx <EOL> result += self . function . subs ( sym , x ) <EOL> return result * dx <EOL> elif method not in ( '<STR_LIT:left>' , '<STR_LIT:right>' , '<STR_LIT>' ) : <EOL> raise NotImplementedError ( "<STR_LIT>" % method ) <EOL> result = <NUM_LIT:0> <EOL> for i in range ( n ) : <EOL> if method == "<STR_LIT>" : <EOL> xi = lower_limit + i * dx + dx / <NUM_LIT:2> <EOL> elif method == "<STR_LIT:left>" : <EOL> xi = lower_limit + i * dx <EOL> if i == <NUM_LIT:0> : <EOL> result = self . function . limit ( sym , lower_limit ) <EOL> continue <EOL> elif method == "<STR_LIT:right>" : <EOL> xi = lower_limit + i * dx + dx <EOL> if i == n : <EOL> result += self . function . limit ( sym , upper_limit , "<STR_LIT:->" ) <EOL> continue <EOL> result += self . function . subs ( sym , xi ) <EOL> return result * dx <EOL> def _sage_ ( self ) : <EOL> import sage . all as sage <EOL> f , limits = self . function . _sage_ ( ) , list ( self . limits ) <EOL> for limit in limits : <EOL> if len ( limit ) == <NUM_LIT:1> : <EOL> x = limit [ <NUM_LIT:0> ] <EOL> f = sage . integral ( f , <EOL> x . _sage_ ( ) , <EOL> hold = True ) <EOL> elif len ( limit ) == <NUM_LIT:2> : <EOL> x , b = limit <EOL> f = sage . integral ( f , <EOL> x . _sage_ ( ) , <EOL> b . _sage_ ( ) , <EOL> hold = True ) <EOL> else : <EOL> x , a , b = limit <EOL> f = sage . integral ( f , <EOL> ( x . _sage_ ( ) , <EOL> a . _sage_ ( ) , <EOL> b . _sage_ ( ) ) , <EOL> hold = True ) <EOL> return f <EOL> def integrate ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> meijerg = kwargs . pop ( '<STR_LIT>' , None ) <EOL> conds = kwargs . pop ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> risch = kwargs . pop ( '<STR_LIT>' , None ) <EOL> manual = kwargs . pop ( '<STR_LIT>' , None ) <EOL> integral = Integral ( * args , ** kwargs ) <EOL> if isinstance ( integral , Integral ) : <EOL> return integral . doit ( deep = False , meijerg = meijerg , conds = conds , <EOL> risch = risch , manual = manual ) <EOL> else : <EOL> return integral <EOL> def line_integrate ( field , curve , vars ) : <EOL> """<STR_LIT>""" <EOL> from sympy . geometry import Curve <EOL> F = sympify ( field ) <EOL> if not F : <EOL> raise ValueError ( <EOL> "<STR_LIT>" ) <EOL> if not isinstance ( curve , Curve ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not is_sequence ( vars ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( curve . functions ) != len ( vars ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if curve . parameter in vars : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> Ft = F <EOL> dldt = <NUM_LIT:0> <EOL> for i , var in enumerate ( vars ) : <EOL> _f = curve . functions [ i ] <EOL> _dn = diff ( _f , curve . parameter ) <EOL> dldt = dldt + ( _dn * _dn ) <EOL> Ft = Ft . subs ( var , _f ) <EOL> Ft = Ft * sqrt ( dldt ) <EOL> integral = Integral ( Ft , curve . limits ) . doit ( deep = False ) <EOL> return integral </s>
