B
    dd                 @   sD
  d Z ddlmZmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZmZ ddlmZ ddlm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z'm(Z(m)Z) ddl*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZG ddlHmIZI ddlJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZT ddlUmVZV ddlWmXZXmYZY ddlZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZc ddldmeZe ddlfmgZg dd lhmiZi dd!ljmkZk dd"llmmZm dd#lnmoZo dd$lpmqZq dd%lrmsZs dd&ltmuZumvZvmwZwmxZx dd'lymzZz dd(l{m|Z| d6d*d+Z}e}d,d-Z~e}d.d/Ze}d0d1Ze}d2d3Ze}d4d5Ze}d6d7Ze}d8d9Ze}d:d;Ze}d<d1Ze}d=d>Ze}d?Ze}d@d>Ze}dAdBZe}dCZe}dDZe}dEdFZe}dGdHZe}dIdJZe}dKdLZe}dMdNZe}dOdNZe}dPdNZe}dQdRZe}dSdTZe}dUdVZe}dWdVZe}dXdVZe}dYdVZe}dZdVZe}d[dTZe}d\d]Ze}d^d]Ze}d_d]Ze}d`d]Ze}dad]Ze}dbdNZe}dcdNZe}dddNZe}ded]Ze}dfd]Ze}dgdhZe}didjZe}dkdjZedldmZi Zdndo Zdpdq Zdrds Zdtdu ZeDeCeBeEeFeGfZdvdw Zdxdy Zdzd{ Zd|d} Zd~dB Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zedd Zedd Zedd Zedd Zedd Zdd Zdd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zdd Zdd Zdd Zdd ZddÄ Zddń ZddǄ ZddɄ Zedd dd Zedd dd Zedd dd Zedd dd Zddӄ ZddՄ Zddׄ Zi ZeeZe'd؃Zddڄ Zee~dd܄ Zeeddބ Zeedd Zeedd Zeedd Zeedd Zeedd Zeedd Zeedd Zeedd Zeedd Zeedd Zeedd Zeedd Zeedd Zeedd Zeedd Zeedd Zeedd  Z eedd Zeedd Zeedd Zeedd Zeed	d
 Zeedd Zeedd Zeedd Zeedd Z	eedd Z
eedd Zeedd Zeedd Zeedd Zeedd Zeedd  Zeed!d" Zeed#d$ Zeed%d& Zeed'd( Zeed)d* Zeed+d, Zeed-d. Zeed/d0 Zd1d2 Zd3d4 Zd5S (7  a  Integration method that emulates by-hand techniques.

This module also provides functionality to get the steps used to evaluate a
particular integral, in the ``integral_steps`` function. This will return
nested namedtuples representing the integration rules used. The
``manualintegrate`` function computes the integral using those steps given
an integrand; given the steps, ``_manualintegrate`` will evaluate them.

The integrator can be extended with new heuristics and evaluation
techniques. To do so, write a function that accepts an ``IntegralInfo``
object and returns either a namedtuple representing a rule or
``None``. Then, write another function that accepts the namedtuple's fields
and returns the antiderivative, and decorate it with
``@evaluates(namedtuple_type)``.  If the new technique requires a new
match, add the key and call to the antiderivative function to integral_steps.
To enable simple substitutions, add the match to find_substitutions.

    )DictOptional)
namedtupledefaultdict)Mapping)reduce)Add)cacheit)r   )Expr)
Derivative)	fuzzy_not)Mul)IntegerNumberE)Pow)EqNeGtLt)S)DummySymbolWild)Abs)explog)coshsinhacoshasinhacothatanh)sqrt)	Piecewise)TrigonometricFunctioncossintancotcscsecacosasinatanacotacscasec)	Heaviside)
erferfifresnelcfresnelsCiChiSiShiEili)
uppergamma)
elliptic_e
elliptic_f)	
chebyshevt
chebyshevulegendrehermitelaguerreassoc_laguerre
gegenbauerjacobiOrthogonalPolynomial)polylog   )Integral)And)divisors)degree)fraction)simplify)solve)switchdo_one	null_safe	condition)iterable)debug c                s2   dd   fdd}t | |d } |_||_|S )Nc             S   s   | j |j kot| |S )N)	__class__tuple__eq__)selfother r^   l/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sympy/integrals/manualintegrate.pyr[   D   s    zRule.<locals>.__eq__c                s    | | S )Nr^   )r\   r]   )r[   r^   r_   <lambda>F       zRule.<locals>.<lambda>z context symbol)r   r[   __ne__)namepropsZ__neq__clsr^   )r[   r_   RuleB   s    rf   ConstantRuleconstantConstantTimesRulezconstant other substep	PowerRulezbase expAddRulesubstepsURulezu_var u_func constant substep	PartsRulezu dv v_step second_stepCyclicPartsRulezparts_rules coefficientTrigRulezfunc argExpRuleReciprocalRulefunc
ArcsinRuleInverseHyperbolicRuleAlternativeRulealternativesDontKnowRuleDerivativeRuleRewriteRulezrewritten substepPiecewiseRuleZsubfunctionsHeavisideRulezharg ibnd substepTrigSubstitutionRulez(theta func rewritten substep restriction
ArctanRuleza b cArccothRuleArctanhRule
JacobiRulezn a bGegenbauerRulezn aChebyshevTRulenChebyshevURuleLegendreRuleHermiteRuleLaguerreRuleAssocLaguerreRuleCiRuleza bChiRuleEiRuleSiRuleShiRuleErfRuleFresnelCRuleFresnelSRuleLiRulePolylogRuleUpperGammaRuleza eEllipticFRuleza dEllipticERuleIntegralInfozintegrand symbolc                s    fdd}|S )Nc                s    | _ | t < | S )N)rule
evaluators)rs   )r   r^   r_   
_evaluates}   s    zevaluates.<locals>._evaluatesr^   )r   r   r^   )r   r_   	evaluates|   s    r   c             C   sX   t | trdS xD| D ]<}t |tr0t|rPdS qt |trtdd |D rdS qW dS )NTc             s   s   | ]}t |V  qd S )N)contains_dont_know).0ir^   r^   r_   	<genexpr>   s    z%contains_dont_know.<locals>.<genexpr>F)
isinstancerx   rZ   r   listany)r   valr^   r^   r_   r      s    



r   c                s  | j r| j d }t| tr2| t|d  S t| trT|  t|d  S t| trx| t| t| S t| tr|  t| t| S t| trt fdd| j D S t| t	rt
| j dkrt| j d tr| j d t| j d   S |  S )a  Derivative of f in form expected by find_substitutions

    SymPy's derivatives for some trig functions (like cot) aren't in a form
    that works well with finding substitutions; this replaces the
    derivatives for those particular forms with something that works better.

    r      c                s   g | ]}t | qS r^   )manual_diff)r   arg)symbolr^   r_   
<listcomp>   s    zmanual_diff.<locals>.<listcomp>rJ   )argsr   r(   diffr+   r)   r*   r   sumr   lenr   r   )fr   r   r^   )r   r_   r      s     





"r   c                s   t |dkr>|d }t|ttfr,| }qZt|sZtdnt |dkrR|g}ntdg }xR|D ]J\} t|trd|jd | 	fdd fdd} |
t f qdW | t|| S )	zn
    A wrapper for `expr.subs(*args)` with additional logic for substitution
    of invertible functions.
    rJ   r   z(Expected an iterable of (old, new) pairsr   z$subs accepts either 1 or 2 argumentsc                s   | j o| j kS )N)is_Powbase)x)x0r^   r_   r`      ra   zmanual_subs.<locals>.<lambda>c                s   t | j   S )N)r   )r   )newr^   r_   r`      ra   )r   r   r   r   itemsrV   
ValueErrorr   r   replaceappendr   subsr   )exprr   sequenceZnew_subsoldr^   )r   r   r_   manual_subs   s"    



r   c       
         s   g } fdd}fddxl D ]`}|kr:q,t |}|||}|dk	r,|\}}| krpq,|||f}	|	|kr,||	 q,W |S )Nc                sn  |dkrdS | }|j kr"dS td||  t||  }|j krr|rtfdd D }tfdd| D }||krdS |jddS t	| t
rjd| j jrjt| jdk rjtd	gd
}tdgd
}| j| |   rj fdd||fD \}}|dkrj|dkrj|d| j  | | }|jddS dS )Nr   Fz!substituted: {}, u: {}, u_var: {}c                s   g | ]}t | qS r^   )rN   )r   t)r   r^   r_   r      s    z<find_substitutions.<locals>.test_subterm.<locals>.<listcomp>c                s   g | ]}t | qS r^   )rN   )r   r   )u_varr^   r_   r      s    )Zas_AddrJ   a)excludebc                s   g | ]}  |tjqS r^   )getr   Zero)r   r   )matchr^   r_   r      s    )free_symbolsrW   formatr   cancelis_rational_functionmaxas_numer_denomas_independentr   r   r   
is_Integerr   r   r   r   r   )uu_diffsubstitutedZ
deg_beforeZ	deg_afterr   r   )	integrandr   r   )r   r_   test_subterm   s4    

z(find_substitutions.<locals>.test_subtermc                s  t  tfttttfr$ jd gS t  ttt	t
tfrD jd gS t  ttfr^ jd gS t  trt jd gS t  trg }x& jD ]}|| || qW |S t  trbg } jd r| jd  n" jd r| jd   jd jr^| fddt jd D   jd jr^|dd  jd D  |S t  trg }x( jD ]}|| || qzW |S g S )Nr   rJ   r      c                s<   g | ]4}d |  k r&t  jd  k rn q jd | qS )rJ   r   )absr   )r   d)termr^   r_   r     s    zAfind_substitutions.<locals>.possible_subterms.<locals>.<listcomp>c             S   s   g | ]}|j r|qS r^   )r   )r   r   r^   r^   r_   r     s    )r   r%   inverse_trig_functionsr   r   r2   r   r@   rA   rB   rC   rD   rF   rE   rG   r   r   extendr   Zis_constantr   rM   Zis_Addr   )r   rr   r   )possible_subtermsr   )r   r_   r      sF    


"
z-find_substitutions.<locals>.possible_subtermsF)r   r   r   )
r   r   r   resultsr   r   r   Znew_integrandrh   substitutionr^   )r   r   r   r   r_   find_substitutions   s     "'


r   c                s    fdd}|S )z$Strategy that rewrites an integrand.c                s\   | \}}t d||  |  rX|  }||krXt||}t|tsX|rXt||||S d S )Nz/Integral: {} is rewritten with {} on symbol: {})rW   r   integral_stepsr   rx   rz   )integralr   r   	rewrittensubstep)rU   rewriter^   r_   	_rewriter*  s    
zrewriter.<locals>._rewriterr^   )rU   r   r   r^   )rU   r   r_   rewriter(  s    r   c                s    fdd}|S )zAStrategy that rewrites an integrand based on some other criteria.c                s`   | \} }|\}}t d|||  | t| } | r\| }||kr\t|t||||S d S )Nz@Integral: {} is rewritten with {} on symbol: {} and criteria: {})rW   r   r   rz   r   )criteriar   r   r   r   r   )rU   r   r^   r_   _proxy_rewriter:  s    z'proxy_rewriter.<locals>._proxy_rewriterr^   )rU   r   r   r^   )rU   r   r_   proxy_rewriter8  s    r   c                s    fdd}|S )z4Apply the rule that matches the condition, else Nonec                s*   x$   D ]\}}|| r
|| S q
W d S )N)r   )r   keyr   )
conditionsr^   r_   multiplexer_rlJ  s    z#multiplexer.<locals>.multiplexer_rlr^   )r   r   r^   )r   r_   multiplexerH  s    r   c                 s    fdd}|S )zHStrategy that makes an AlternativeRule out of multiple possible results.c                s   g }d}t d xT D ]L}|d }t d|| || }|rt|ts|| kr||kr|| qW t|dkrz|d S |rdd |D }|rt|f|  S t|f|  S d S )Nr   zList of Alternative RulesrJ   zRule {}: {}c             S   s   g | ]}t |s|qS r^   )r   )r   r   r^   r^   r_   r   a  s    z7alternatives.<locals>._alternatives.<locals>.<listcomp>)rW   r   r   rx   r   r   rv   )r   Zaltscountr   resultZdoable)rulesr^   r_   _alternativesR  s"    
z#alternatives.<locals>._alternativesr^   )r   r   r^   )r   r_   rw   P  s    c             C   s   t | jf|  S )N)rg   r   )r   r^   r^   r_   constant_ruleh  s    r   c             C   s   | \}}|  \}}||jkrRt|trRt|d dkrDt|||S t||||S ||jkrt|trt||||}tt	|j
r|S t	|j
rtdd|S t|tt	|dftdd|dfg||S d S )NrJ   r   T)as_base_expr   r   r   rP   rr   rj   rq   r   r   is_zerorg   r{   r   )r   r   r   r   Zexptr   r^   r^   r_   
power_rulek  s     
r   c             C   s0   | \}}t |jd tr,tt|jd ||S d S )Nr   )r   r   r   rq   r   )r   r   r   r^   r^   r_   exp_rule  s    r   c                s   t ttttttttt	t
ttttti}t dtdtdi}| \} xr|D ]j}t||rB||d}|j|  krBt fdd|jd | D sB|jd | | f }|| | S qBW d S )Nr   r   rJ   c             3   s   | ]}|  V  qd S )N)has)r   v)r   r^   r_   r     s    z'orthogonal_poly_rule.<locals>.<genexpr>)rG   r   rF   r   r@   r   rA   r   rB   r   rC   r   rD   r   rE   r   r   r   r   r   )r   Zorthogonal_poly_classesZorthogonal_poly_var_indexr   klassZ	var_indexr   r^   )r   r_   orthogonal_poly_rule  s&    

 r   c                sv  | \}}t d|gdd gd}t d|gd}t d|gd}t d|gd	d gd}t d
|gdd gd}|||||f}tt|| | | d tftt|| | | d tftt|| | | d tftt|| | | d t	ftt
|| | | d tftdt|| |  d tftt||d  ||  | d tftt||d  ||  | d tftt||d  ||  | d tft|| t||  d tftt||| | d tftdt||t|d    dd tftt||t|d   dd tff}	x||	D ]t}
t||
d r||
d   rt fdd|D }|
d d ksT|
d | r|||f }|
d | S qW d S )Nr   c             S   s   | j  S )N)r   )r   r^   r^   r_   r`     ra   z'special_function_rule.<locals>.<lambda>)r   
propertiesr   )r   cr   c             S   s   | j  S )N)r   )r   r^   r^   r_   r`     ra   ec             S   s   | j o
| j S )N)is_nonnegative
is_integer)r   r^   r^   r_   r`     ra   rJ   r   c             S   s   | |kS )Nr^   )r   r   r^   r^   r_   r`     ra   c             S   s   | |kS )Nr^   )r   r   r^   r^   r_   r`     ra   r   c             3   s&   | ]}  |d k	r  |V  qd S )N)r   )r   w)r   r^   r_   r     s    z(special_function_rule.<locals>.<genexpr>r   )r   r   r   r   r&   r   r   r   r'   r   r   r   r   r   r   r   r   r   r   rI   r   r#   r   r   r   r   rZ   )r   r   r   r   r   r   r   r   ZwildspatternspZ	wild_valsr   r^   )r   r_   special_function_rule  s>    """

r   c       	         s  | \  \ }tdgd}tdgd} ||d   sNd S dd }dd }d	d
 } fddfdd||fD \}}g }td| d dkr |t||d| dt|dk|dk f ||||d|dt|dk|dkf |||| d|dt|dk |dkf dd |D }|jrp|jrpdd |D }t|dkr|d d d  S n |rt	fdd|D S d S )Nr   )r   r   r   c             S   s   | j p|  S )N)is_negativeZcould_extract_minus_sign)r   r^   r^   r_   negative  s    z#inverse_trig_rule.<locals>.negativec             S   s   t t| |S )N)ru   r    )r   r   r^   r^   r_   ArcsinhRule  s    z&inverse_trig_rule.<locals>.ArcsinhRulec             S   s   t t| |S )N)ru   r   )r   r   r^   r^   r_   ArccoshRule  s    z&inverse_trig_rule.<locals>.ArccoshRulec                s  t d} }}d  }	 }
 }}}|dkrT|| }	||||  |d   }|| }|| dkrt||  }
t|| }|}|||d   }| || |}|
d k	r|dkr|d k	rt||| ||||  }t||
|||}|	d k	r|d k	rt|	||}|S )Nr   rJ   r   )r   r#   ri   rm   )Z	RuleClassZbase_expr   Zsign_ar   Zsign_br   Zcurrent_baseZcurrent_symbolrh   u_funcZ
u_constantr   Zfactored)r   r   r   r^   r_   make_inverse_trig  s0    
z,inverse_trig_rule.<locals>.make_inverse_trigc                s   g | ]}  |tjqS r^   )r   r   r   )r   r   )r   r^   r_   r     s    z%inverse_trig_rule.<locals>.<listcomp>rJ   r   c             S   s   g | ]}|d  t jk	r|qS )r  )r   false)r   r   r^   r^   r_   r     s    c             S   s   g | ]}|d  t jkr|qS )r  )r   true)r   r   r^   r^   r_   r     s    c                s$   g | ]} |d d  |d fqS )Nr  r^   )r   r   )r  r^   r_   r     s    )
r   r   r   rP   r   rt   rL   	is_numberr   r{   )	r   r   r   r   r  r  r  possibilitiesZpossibilityr^   )r   r   r  r   r   r_   inverse_trig_rule  s4    (&(r  c                s6   | \}  fdd|  D }d |kr*d S t|| S )Nc                s   g | ]}t | qS r^   )r   )r   g)r   r^   r_   r     s   zadd_rule.<locals>.<listcomp>)Zas_ordered_termsrk   )r   r   r   r^   )r   r_   add_rule	  s    
r  c             C   sD   | \}}| |\}}t||}|dkr@|d k	r@t|||||S d S )NrJ   )r   r   ri   )r   r   r   Zcoeffr   	next_stepr^   r^   r_   mul_rule  s    
r  c                s   fdd}dd }|t |t ||tt|tg}td}t| t ftrT||  } xt|D ]\}}|| }|r`|\}	}
 |	jkr|		|sd S |	
|d}	|

|d}
||kr|	 sd S t|	t rd|
 }| rt| dkrd S ||kr@t|
tr@t|
 }t|r d S |	 }t|}|	|
|||fS d}|dk rTd	}nv||kr|
jrtd
d |
jD rd	}nHxF||d d  D ]2}|| }|r|d 
|d|
rd	}P qW |r`|	 }tt|
 }t|s`t|}|	|
|||fS q`W d S )Nc                sR   |    } t| trg n fdd| jD }|rNt| }| |   }||fS d S )Nc                s   g | ]}|  r|qS r^   )Zis_algebraic_expr)r   r   )r   r^   r_   r   #  s    z;_parts_rule.<locals>.pull_out_algebraic.<locals>.<listcomp>)r   Ztogetherr   r$   r   r   )r   Z	algebraicr   dv)r   r^   r_   pull_out_algebraic  s    z'_parts_rule.<locals>.pull_out_algebraicc                 s    fdd}|S )Nc                sP   t  fddD rLfdd jD }|rLtdd |} | }||fS d S )Nc             3   s   | ]}  |V  qd S )N)r   )r   r   )r   r^   r_   r   +  s    zI_parts_rule.<locals>.pull_out_u.<locals>.pull_out_u_rl.<locals>.<genexpr>c                s&   g | ] t  fd dD r qS )c             3   s   | ]}t  |V  qd S )N)r   )r   re   )r   r^   r_   r   -  s    zT_parts_rule.<locals>.pull_out_u.<locals>.pull_out_u_rl.<locals>.<listcomp>.<genexpr>)r   )r   )	functions)r   r_   r   ,  s    zJ_parts_rule.<locals>.pull_out_u.<locals>.pull_out_u_rl.<locals>.<listcomp>c             S   s   | | S )Nr^   )r   r   r^   r^   r_   r`   /  ra   zH_parts_rule.<locals>.pull_out_u.<locals>.pull_out_u_rl.<locals>.<lambda>)r   r   r   )r   r   r   r  )r  )r   r_   pull_out_u_rl*  s    z6_parts_rule.<locals>.pull_out_u.<locals>.pull_out_u_rlr^   )r  r  r^   )r  r_   
pull_out_u)  s    	z_parts_rule.<locals>.pull_out_u	temporaryrJ   Fr   Tc             s   s   | ]}t |tttfV  qd S )N)r   r'   r&   r   )r   r   r^   r^   r_   r   e  s   z_parts_rule.<locals>.<genexpr>r   )r   r   r'   r&   r   r   r   	enumerater   r   r   is_polynomialrN   rH   r   r   r   _manualintegrater   allequalsrP   )r   r   r  r  Zliate_rulesdummyindexr   r   r   r  Zrec_dvv_stepdur   acceptZlruler   r^   )r   r_   _parts_rule  s`    









r   c                s
  | \}|  \}}t|}g }|r|\}}}}}	td|||||	 || t|trdd S t|ttt	t
tfr|ti}
t|
 dkrd S t|
  d7  < xtdD ]}td|||| || |  }|dkrP |jkr:tdd |D dt| | |}|dkr6|r6t||||| }|S ||   \}}t|}|r|\}}}}}	||9 }||9 }||||||	f qP qW  fd	d
 |r|d \}}}}}	t|||	 |dd  || |}|dkr|rt||||| }|S d S )Nz,u : {}, dv : {}, v : {}, du : {}, v_step: {}r   rJ      z7Cyclic integration {} with v: {}, du: {}, integrand: {}c          	   S   s(   g | ] \}}}}}t |||d d d qS )N)rn   )r   r   r  r   r  r  r^   r^   r_   r     s   zparts_rule.<locals>.<listcomp>r  c                sZ   | r:| d \}}}}}t ||| | dd  || |S t|} | rL| S t|S d S )Nr   rJ   )rn   r   rx   )stepsr   r   r  r   r  r  )make_second_stepr   r^   r_   r#    s    
z$parts_rule.<locals>.make_second_stepr   )Zas_coeff_Mulr   rW   r   r   r   rK   r'   r&   r   r   r   xreplace_cache_dummy_parts_u_cacheranger   r   ro   r   ri   rn   )r   r   rh   r   r"  r   r  r   r  r  cachekey_coefficientr   Znext_constantZnext_integrandr^   )r#  r   r_   
parts_rulew  s`    



r+  c             C   sl  | \}}t |ttfrP|jd }t |ts.d S t |tr>d}nd}t||||S |t|d krntd|||S |t|d krtd|||S t |trt|j t|j  }nt |t	rt|j t|j  }nt |tr|jd }t|d t|t|  t|t|  }nHt |trT|jd }t|d t	|t|  t|t	|  }nd S t
|t||||S )Nr   r'   r&   r   zsec**2zcsc**2)r   r'   r&   r   r   rp   r+   r*   r(   r)   rz   r   )r   r   r   r   rs   r   r^   r^   r_   	trig_rule  s<    






r,  c             C   s   | \}}t |t| }|| }||jkrXtd|||}|dkrT|rTt|||||}|S t| t| }|| }||jkrtd|||}|dkr|rt|||||}|S d S )Nzsec*tanrJ   zcsc*cot)r+   r(   r   rp   ri   r*   r)   )r   r   r   Zsectanqr   Zcsccotr^   r^   r_   trig_product_rule  s    

r.  c          	   C   s  | \}}t d|gd}t d|gd}t d|gd}||||d  |  }|r|| || ||   }}}|jr
|jr
tt|||||t|| dft|||||tt|d | | t|| dft	|||||tt|d | | t|| dfg||S t|||||S t d|gd}||||d  ||  |  }|r|| ||  }}|j
rnd S td}	||d|   }
|||	|d|   }t||	}|rt|	|
d |||S d S t d	|gd}||| | ||d  ||  |  }|r|| || || || || f\}}}}}|j
r:d S ||d  ||  | }|d|  }d| | | }| | | }td}	t|	||t|	d
 |	||}|dkrt||| ||| | |}|j
r|S t|| |}t||g||}|| | ||  }t||||S d S )Nr   )r   r   r   r   r   r   r   r   r  rJ   )r   r   is_extended_realr{   r~   r   r   rL   r   r   r   r   r   r   rm   ri   rk   rz   )r   r   r   r   r   r   r   r   Zmatch2r   r  Z
integrand2r  r   Zmatch3denominatorconstZnumer1Znumer2Zstep1Zstep2rl   Zrewritenr^   r^   r_   quadratic_denom_rule  sp    24"
*,

r2  c             C   s"  | \}}t d|gd}t d|gd}t d}|t|| | | }|sNd S || || ||   }}}t d|gd}t d|gd}t d}	|t|| | |	 }
|
rd S td}t|| | }|||}|||d	 | | }|d	 | | }t||}|rt||d |||S d S )
Nr   )r   r   r   r   r   r   r   r   )r   r   r#   r   r   r   rm   )r   r   r   r   r   r   r   r   r   r   Zrecursion_testr   r  r  r^   r^   r_   root_mul_ruleC  s,    
r3  c             C   sT   t d| gd}t d| gd}t d| gdd gd}t d| gd	d gd}||||fS )
Nr   )r   r   mc             S   s
   t | tS )N)r   r   )r   r^   r^   r_   r`   b  ra   zmake_wilds.<locals>.<lambda>)r   r   r   c             S   s
   t | tS )N)r   r   )r   r^   r^   r_   r`   c  ra   )r   )r   r   r   r4  r   r^   r^   r_   
make_wilds^  s
    r5  c             C   s>   t | \}}}}t||  | t||  |  }|||||fS )N)r5  r'   r&   )r   r   r   r4  r   patternr^   r^   r_   sincos_patterng  s     r7  c             C   s>   t | \}}}}t||  | t||  |  }|||||fS )N)r5  r(   r+   )r   r   r   r4  r   r6  r^   r^   r_   tansec_patternn  s     r8  c             C   s>   t | \}}}}t||  | t||  |  }|||||fS )N)r5  r)   r*   )r   r   r   r4  r   r6  r^   r^   r_   cotcsc_patternu  s     r9  c             C   sD   t d| gd}t d| gd}t d}t||  | | }||||fS )Nr4  )r   r   r  )r   r2   )r   r4  r   r  r6  r^   r^   r_   heaviside_pattern|  s
    r:  c                s    fdd}|S )Nc                s    |  S )Nr^   )r   )rs   r^   r_   
uncurry_rl  s    zuncurry.<locals>.uncurry_rlr^   )rs   r;  r^   )rs   r_   uncurry  s    r<  c                s    fdd}|S )Nc                sB   | \}}}}}} ||||||}||kr>t |t||||S d S )N)rz   r   )r   r   r   r4  r   r   r   r   )r   r^   r_   trig_rewriter_rl  s    z'trig_rewriter.<locals>.trig_rewriter_rlr^   )r   r=  r^   )r   r_   trig_rewriter  s    r>  c             C   s   |j o|j o|jo|jS )N)is_evenr   )r   r   r4  r   r   sr^   r^   r_   r`     s   r`   c             C   s@   dt d|  |  d |d  dt d| |  d |d   S )NrJ   r   )r&   )r   r   r4  r   r   r   r^   r^   r_   r`     s   c             C   s   |j o|dkS )Nr   )is_odd)r   r   r4  r   r   r@  r^   r^   r_   r`     ra   c             C   s<   dt | | d  |d d  t| |  t || |  S )NrJ   r   )r&   r'   )r   r   r4  r   r   r   r^   r^   r_   r`     s    *c             C   s   |j o|dkS )Nr   )rA  )r   r   r4  r   r   r@  r^   r^   r_   r`     ra   c             C   s<   dt || d  |d d  t||  t | | |  S )NrJ   r   )r'   r&   )r   r   r4  r   r   r   r^   r^   r_   r`     s    *c             C   s   |j o|dkS )Nr!  )r?  )r   r   r4  r   r   r@  r^   r^   r_   r`     ra   c             C   s@   dt || d  |d d  t|| d  t | | |  S )NrJ   r   )r(   r+   )r   r   r4  r   r   r   r^   r^   r_   r`     s    .c             C   s   |j S )N)rA  )r   r   r4  r   r   r@  r^   r^   r_   r`     ra   c             C   s<   t | | d d |d d  t| |  t || |  S )Nr   rJ   )r+   r(   )r   r   r4  r   r   r   r^   r^   r_   r`     s    *c             C   s   |dko|dkS )Nr   r   r^   )r   r   r4  r   r   r@  r^   r^   r_   r`     ra   c             C   s   t | | d d S )Nr   rJ   )r+   )r   r   r4  r   r   r   r^   r^   r_   r`     ra   c             C   s   |j o|dkS )Nr!  )r?  )r   r   r4  r   r   r@  r^   r^   r_   r`     ra   c             C   s@   dt || d  |d d  t|| d  t | | |  S )NrJ   r   )r)   r*   )r   r   r4  r   r   r   r^   r^   r_   r`     s    .c             C   s   |j S )N)rA  )r   r   r4  r   r   r@  r^   r^   r_   r`     ra   c             C   s<   t | | d d |d d  t| |  t || |  S )Nr   rJ   )r*   r)   )r   r   r4  r   r   r   r^   r^   r_   r`     s    *c                s   | \ }t  fddttfD rt|\}}}}} |sFd S ttttt	t
titfdd||||fD  |g S d S )Nc             3   s   | ]}  |V  qd S )N)r   )r   r   )r   r^   r_   r     s    z#trig_sincos_rule.<locals>.<genexpr>c                s   g | ]}  |tjqS r^   )r   r   r   )r   r   )r   r^   r_   r     s    z$trig_sincos_rule.<locals>.<listcomp>)r   r'   r&   r7  r   r   sincos_botheven_conditionsincos_bothevensincos_sinodd_conditionsincos_sinoddsincos_cosodd_conditionsincos_cosoddrZ   )r   r   r6  r   r   r4  r   r^   )r   r   r_   trig_sincos_rule  s    
rH  c                s   | \ }  dt| t|i t fddttfD rt|\}}}}} |s`d S ttt	t
tttitfdd||||fD  |g S d S )NrJ   c             3   s   | ]}  |V  qd S )N)r   )r   r   )r   r^   r_   r     s    z#trig_tansec_rule.<locals>.<genexpr>c                s   g | ]}  |tjqS r^   )r   r   r   )r   r   )r   r^   r_   r     s    z$trig_tansec_rule.<locals>.<listcomp>)r   r&   r+   r   r(   r8  r   r   tansec_tanodd_conditiontansec_tanoddtansec_seceven_conditiontansec_seceventan_tansquared_conditiontan_tansquaredrZ   )r   r   r6  r   r   r4  r   r^   )r   r   r_   trig_tansec_rule  s    
rO  c          	      s   | \ }  dt| t|dt| t|t|t| t|i t fddttfD rt|\}}}}} |sd S t	t
tttitfdd||||fD  |g S d S )NrJ   c             3   s   | ]}  |V  qd S )N)r   )r   r   )r   r^   r_   r     s    z#trig_cotcsc_rule.<locals>.<genexpr>c                s   g | ]}  |tjqS r^   )r   r   r   )r   r   )r   r^   r_   r     s    z$trig_cotcsc_rule.<locals>.<listcomp>)r   r'   r*   r(   r)   r&   r   r9  r   r   cotcsc_cotodd_conditioncotcsc_cotoddcotcsc_csceven_conditioncotcsc_cscevenrZ   )r   r   r6  r   r   r4  r   r^   )r   r   r_   trig_cotcsc_rule  s     
rT  c             C   sj   | \}}t dtd| gd}|td| | }|rfdt| t| td|  }t|| |S d S )Nr   r   )r   )r   r'   r   r&   r   )r   r   r   r   r   Z
sin_doubler^   r^   r_   trig_sindouble_rule  s     rU  c             C   s"   t tttttttt| S )N)rS   rT   rH  rO  rT  rU  )r   r^   r^   r_   trig_powers_products_rule
  s    rV  c          	   C   sh  | \}}t dd|gd}t dd|gd}td}|||d   }||}x|D ]}||}	|	|tj}
|	|tj}|
jr|
dkp|
j}|jr|dkp|j}|
jr|
dk p|
j	}|jr|dk p|j	}d }|r|rt
|
t
| t| }d}n~|r8|r8t
|
t
|  }|t| }t|| k||k }n>|rv|rvt
|
 t
| }|t| }t|| k||k }|rRi }xNttttttgD ]:}|||t
||d < d|| |t
||d	 < qW ||| }t||}||sR|t||9 }| }|dt| }|r:|dt| t|i}t||}t|sRt|||||||S qRW d S )
Nr   r   )r   r   thetar   TrJ   )r   r   findr   r   r   r   r	  Zis_positiver   r#   r(   r'   rL   r+   r&   r*   r)   r   trigsimpr   r   r   r$  r   r   r}   )r   r   r   ABrW  Ztarget_patternmatchesr   r   r   r   Z
a_positiveZ
b_positiveZ
a_negativeZ
b_negativeZx_funcrestrictionrh   substitutionsr   ZreplacedZsecantsr   r^   r^   r_   trig_substitution_rule  s\    

"



r`  c       
      C   s|   | \}}t |\}}}}||}|rxd|| krxt|| |}t|}	|| ||  }}t|| | | | |	||S d S )Nr   )r:  r   r   r  r|   )
r   r   r   r6  r4  r   r  r   r  r   r^   r^   r_   heaviside_ruleM  s    
ra  c          
   C   s  | \}}t d}t|||}d}|rrtd g }x|D ]\}}}	t|	|}
|d }td||
 t|
rrq:t|d dkr,| \}}|
rt||	|
|	|}
|j	r,g }g }t
|tr|j}n
|| x@|D ]8}t|jstt||d|}|r||t|df qW ||
df t||	|}
|t||||
|| q:W t|dkrbt|||S |r|d S nV|trt|}d}||| }	|	||}	||	j	krt|||t|	|||S d S )Nr   r   zList of Substitution RulesrJ   zRule {}: {}T)r   r   rW   r   r   r   rP   r   ri   r   r   r   r   r   r   r   r   r   r{   rm   r   rv   r   r   r   r   )r   r   r   r   r_  r   Zwaysr  r   r   Zsubruler)  denomZ	piecewiseZcould_be_zeror   r   r^   r^   r_   substitution_ruleX  s`    





rc  c             C   s   |   S )N)r   )r   r   r^   r^   r_   r`     ra   c             C   s
   |  |S )N)Zapart)r   r   r^   r^   r_   r`     ra   c             C   s   dS )NTr^   )r   r   r^   r^   r_   r`     ra   c             C   s   |   S )N)r   )r   r   r^   r^   r_   r`     ra   c                s,   t  fdd| jD p*t| tp*t| tS )Nc             3   s   | ]}|j p| V  qd S )N)r   r  )r   r   )r   r^   r_   r     s    z<lambda>.<locals>.<genexpr>)r  r   r   r   r   )r   r   r^   )r   r_   r`     s    
c             C   s   |   S )N)expand)r   r   r^   r^   r_   r`     ra   c             C   s   t dd | tD dkS )Nc             S   s   h | ]}|j d  qS )r   )r   )r   r   r^   r^   r_   	<setcomp>  s    z<lambda>.<locals>.<setcomp>rJ   )r   Zatomsr%   )r   r   r^   r^   r_   r`     s    c             C   s   | j ddS )NT)Ztrig)rd  )r   r   r^   r^   r_   r`     ra   c             C   sX   | d }|j }|j}|j}| j|krD| j|kr6t|  S t|| jS nt| jf|  S d S )Nr   )	variablesr   r   r   ry   rx   rg   r   )r   r   Zdiff_variablesZundifferentiated_functionZintegrand_variablesr^   r^   r_   derivative_rule  s    

rg  c             C   sJ   | \}}| dt| rF|dt| t|}t|t||||S d S )NrJ   )r   r&   r   r+   rz   r   )r   r   r   r   r^   r^   r_   rewrites_rule  s    rh  c             C   s   t |  S )N)rx   )r   r^   r^   r_   fallback_rule  s    ri  zc                sN  |  ti}|tkrBt| dkr,t| S t|  tfS ndt|< t| }fdd  fdd}ttttt t	ttt
tttttt
tttttttttttttttttttttttttti
ttttt t!t"t#|tt	t$t#|tt	t%t#|tt&ft' t(t#|tt	t)t*t+tt,t-|}t|= |S )a  Returns the steps needed to compute an integral.

    Explanation
    ===========

    This function attempts to mirror what a student would do by hand as
    closely as possible.

    SymPy Gamma uses this to provide a step-by-step explanation of an
    integral. The code it uses to format the results of this function can be
    found at
    https://github.com/sympy/sympy_gamma/blob/master/app/logic/intsteps.py.

    Examples
    ========

    >>> from sympy import exp, sin
    >>> from sympy.integrals.manualintegrate import integral_steps
    >>> from sympy.abc import x
    >>> print(repr(integral_steps(exp(x) / (1 + exp(2 * x)), x)))     # doctest: +NORMALIZE_WHITESPACE
    URule(u_var=_u, u_func=exp(x), constant=1,
    substep=PiecewiseRule(subfunctions=[(ArctanRule(a=1, b=1, c=1, context=1/(_u**2 + 1), symbol=_u), True),
        (ArccothRule(a=1, b=1, c=1, context=1/(_u**2 + 1), symbol=_u), False),
        (ArctanhRule(a=1, b=1, c=1, context=1/(_u**2 + 1), symbol=_u), False)],
    context=1/(_u**2 + 1), symbol=_u), context=exp(x)/(exp(2*x) + 1), symbol=x)
    >>> print(repr(integral_steps(sin(x), x)))     # doctest: +NORMALIZE_WHITESPACE
    TrigRule(func='sin', arg=x, context=sin(x), symbol=x)
    >>> print(repr(integral_steps((x**2 + 3)**2, x)))     # doctest: +NORMALIZE_WHITESPACE
    RewriteRule(rewritten=x**4 + 6*x**2 + 9,
    substep=AddRule(substeps=[PowerRule(base=x, exp=4, context=x**4, symbol=x),
        ConstantTimesRule(constant=6, other=x**2,
            substep=PowerRule(base=x, exp=2, context=x**2, symbol=x),
                context=6*x**2, symbol=x),
        ConstantRule(constant=9, context=9, symbol=x)],
    context=x**4 + 6*x**2 + 9, symbol=x), context=(x**2 + 3)**2, symbol=x)


    Returns
    =======

    rule : namedtuple
        The first step; most rules have substeps that must also be
        considered. These substeps can be evaluated using ``manualintegrate``
        to obtain a result.

    Nc                sf   | j } |jkrtS t|tr"tS t|tr0tS x0tttt	t
tftttfD ]}t||rL|S qLW d S )N)r   r   r   r   r%   r   r   r   r   r   r   r   r   r2   rH   )r   r   re   )r   r^   r_   r     s    




zintegral_steps.<locals>.keyc                 s    fdd}|S )Nc                s    | }|ot |S )N)
issubclass)r   k)r   klassesr^   r_   _integral_is_subclass   s    zKintegral_steps.<locals>.integral_is_subclass.<locals>._integral_is_subclassr^   )rm  rn  )r   )rm  r_   integral_is_subclass  s    z,integral_steps.<locals>.integral_is_subclass).r$  r%  _integral_cacherx   r   rS   rT   r   rR   r   r   r  r2  r   r   r   r   r  r   r  r.  ra  r3  r   rg  r%   r,  r2   rH   r   r   r   rw   rh  rc  rU   partial_fractions_rulecancel_ruler   r   r+  distribute_expand_rulerV  trig_expand_ruler`  ri  )r   r   optionsr(  r   ro  r   r^   )r   r   r_   r     sd    2



r   c             C   s   | | S )Nr^   )rh   r   r   r^   r^   r_   eval_constantQ  s    rv  c             C   s   | t | S )N)r  )rh   r]   r   r   r   r^   r^   r_   eval_constanttimesU  s    rw  c             C   s,   t | |d  |d  t|dft| dfS )NrJ   r  T)r$   r   r   )r   r   r   r   r^   r^   r_   
eval_powerY  s    rx  c             C   s   |t |  S )N)r   )r   r   r   r   r^   r^   r_   eval_exp`  s    ry  c             C   s   t tt| S )N)r   mapr  )rl   r   r   r^   r^   r_   eval_addd  s    r{  c             C   s<   t |}|jr0|jdkr0|t| t|j }|| |S )Nr  )r  r   r   r   r   r   )r   r  rh   r   r   r   r   r^   r^   r_   eval_uh  s    r|  c             C   s   t |}| | t | S )N)r  )r   r  r  Zsecond_stepr   r   r   r^   r^   r_   
eval_partsp  s    r}  c             C   sL   d| }g }d}x.| D ]&}| ||j t|j  |d9 }qW t| | S )NrJ   r  )r   r   r  r  r   )Zparts_rulesr*  r   r   r   signr   r^   r^   r_   eval_cyclicpartsv  s    
r  c             C   sh   | dkrt | S | dkr"t|S | dkr2t|S | dkrBt|S | dkrRt|S | dkrdt| S d S )Nr'   r&   zsec*tanzcsc*cotzsec**2zcsc**2)r&   r'   r+   r*   r(   r)   )rs   r   r   r   r^   r^   r_   	eval_trig  s    
r  c             C   s,   | | d t ||  t|t ||   S )NrJ   )r#   r.   )r   r   r   r   r   r^   r^   r_   eval_arctan  s    r  c             C   s2   |  | d t | |  t|t | |   S )NrJ   )r#   r!   )r   r   r   r   r   r^   r^   r_   eval_arccoth  s    r  c             C   s2   |  | d t | |  t|t | |   S )NrJ   )r#   r"   )r   r   r   r   r   r^   r^   r_   eval_arctanh  s    r  c             C   s   t | S )N)r   )rs   r   r   r^   r^   r_   eval_reciprocal  s    r  c             C   s   t |S )N)r-   )r   r   r^   r^   r_   eval_arcsin  s    r  c             C   s   | |S )Nr^   )rs   r   r   r^   r^   r_   eval_inversehyperbolic  s    r  c             C   s   t | d S )Nr   )r  )rw   r   r   r^   r^   r_   eval_alternative  s    r  c             C   s   t |S )N)r  )r   r   r   r   r^   r^   r_   eval_rewrite  s    r  c             C   s   t dd | D  S )Nc             S   s   g | ]\}}t ||fqS r^   )r  )r   r   condr^   r^   r_   r     s   z"eval_piecewise.<locals>.<listcomp>)r$   )rl   r   r   r^   r^   r_   eval_piecewise  s    r  c             C   s  | t| dt|  }| t| dt|  }| t| dt|  }t|t	}t
|dksft|d }t|| |}t
|dkstt|d \}	}
t|tr|	}|
}t|
d |	d  }t|d }njt|tr|	}|
}t|
d |	d  }t|d }n4t|tr:|	}|
}t|
d |	d  }t|d }t| || ft| || ft| || f| |fg}tt| | |fS )NrJ   r   r   )r   r+   r&   r*   r'   r)   r(   r   rY  r%   r   AssertionErrorrQ   rO   r   r#   r-   r,   r.   r$   r  rZ  )rW  rs   r   r   r^  r   r   Ztrig_functionZrelationZnumerrb  ZoppositeZ
hypotenuseadjacentZinverser   r^   r^   r_   eval_trigsubstitution  s<    

r  c             C   sN   t | j}x2t|D ]&\}\}}||kr||d f||< P qW t| jf| S )NrJ   )r   variable_countr  r   r   )r   r   r  r   varr   r^   r^   r_   eval_derivativerule  s    
r  c             C   s   t | ||||  S )N)r2   r   )ZhargZibndr   r   r   r^   r^   r_   eval_heaviside  s    r  c             C   s|   t dt| d |d |d | | | |  t| | | df|t| df|| d |d  d || | d  t| dfS )Nr   rJ   r   r!  )r$   rG   r   r   )r   r   r   r   r   r^   r^   r_   eval_jacobi  s    :r  c             C   sT   t t| d |d |d|d   t|dft| d || d  t| dftjdfS )NrJ   r   r  T)r$   rF   r   r@   r   r   )r   r   r   r   r^   r^   r_   eval_gegenbauer  s    (r  c             C   sP   t t| d || d  t| d || d   d tt| df|d d dfS )NrJ   r   T)r$   r@   r   r   )r   r   r   r^   r^   r_   eval_chebyshevt  s    (r  c             C   s,   t t| d || d  t| dftjdfS )NrJ   r  T)r$   r@   r   r   r   )r   r   r   r^   r^   r_   eval_chebyshevu  s    r  c             C   s(   t | d |t | d | d|  d  S )NrJ   r   )rB   )r   r   r   r^   r^   r_   eval_legendre	  s    r  c             C   s   t | d |d| d   S )NrJ   r   )rC   )r   r   r   r^   r^   r_   eval_hermite  s    r  c             C   s   t | |t | d | S )NrJ   )rD   )r   r   r   r^   r^   r_   eval_laguerre  s    r  c             C   s   t | d |d | S )NrJ   )rE   )r   r   r   r   r^   r^   r_   eval_assoclaguerre  s    r  c             C   s(   t |t| |  t|t| |   S )N)r&   r7   r'   r9   )r   r   r   r   r^   r^   r_   eval_ci  s    r  c             C   s(   t |t| |  t|t| |   S )N)r   r8   r   r:   )r   r   r   r   r^   r^   r_   eval_chi  s    r  c             C   s   t |t| |  S )N)r   r;   )r   r   r   r   r^   r^   r_   eval_ei!  s    r  c             C   s(   t |t| |  t|t| |   S )N)r'   r7   r&   r9   )r   r   r   r   r^   r^   r_   eval_si%  s    r  c             C   s(   t |t| |  t|t| |   S )N)r   r8   r   r:   )r   r   r   r   r^   r^   r_   eval_shi)  s    r  c             C   s   | j rtttj|   d t||d d|     td|  | | dt|     | dk fttj|  d t||d d|     td|  | | dt|    dfS ttj|  d t||d d|     td|  | | dt|    S d S )Nr   r!  rX  r   T)r/  r$   r#   r   Pir   r3   r4   )r   r   r   r   r   r^   r^   r_   eval_erf-  s    **(((r  c             C   s   t tjd|   t|d d|   | td|  | | t d|  tj   t|d d|   | td|  | | t d|  tj     S )Nr   r!  )r#   r   r  r&   r5   r'   r6   )r   r   r   r   r   r^   r^   r_   eval_fresnelc9  s    <r  c             C   s   t tjd|   t|d d|   | td|  | | t d|  tj   t|d d|   | td|  | | t d|  tj     S )Nr   r!  )r#   r   r  r&   r6   r'   r5   )r   r   r   r   r   r^   r^   r_   eval_fresnels?  s    <r  c             C   s   t | | | |  S )N)r<   )r   r   r   r   r^   r^   r_   eval_liE  s    r  c             C   s   t |d | | S )NrJ   )rI   )r   r   r   r   r^   r^   r_   eval_polylogI  s    r  c             C   s0   || |  | |   t |d |  |  |  S )NrJ   )r=   )r   r   r   r   r^   r^   r_   eval_uppergammaM  s    r  c             C   s   t |||  t|  S )N)r?   r#   )r   r   r   r   r^   r^   r_   eval_elliptic_fQ  s    r  c             C   s   t |||  t|  S )N)r>   r#   )r   r   r   r   r^   r^   r_   eval_elliptic_eU  s    r  c             C   s
   t | |S )N)rK   )r   r   r^   r^   r_   eval_dontknowruleY  s    r  c             C   s(   t | j}|s tdt|  ||  S )NzCannot evaluate rule %s)r   r   rY   r   repr)r   Z	evaluatorr^   r^   r_   r  ]  s    r  c             C   s   t t| |}t  t|trt|jdkr|jd d }t|tr|jd d dkr|	|jd d t
|j f|jd d df}|S )a$  manualintegrate(f, var)

    Explanation
    ===========

    Compute indefinite integral of a single variable using an algorithm that
    resembles what a student would do by hand.

    Unlike :func:`~.integrate`, var can only be a single symbol.

    Examples
    ========

    >>> from sympy import sin, cos, tan, exp, log, integrate
    >>> from sympy.integrals.manualintegrate import manualintegrate
    >>> from sympy.abc import x
    >>> manualintegrate(1 / x, x)
    log(x)
    >>> integrate(1/x)
    log(x)
    >>> manualintegrate(log(x), x)
    x*log(x) - x
    >>> integrate(log(x))
    x*log(x) - x
    >>> manualintegrate(exp(x) / (1 + exp(2 * x)), x)
    atan(exp(x))
    >>> integrate(exp(x) / (1 + exp(2 * x)))
    RootSum(4*_z**2 + 1, Lambda(_i, _i*log(2*_i + exp(x))))
    >>> manualintegrate(cos(x)**4 * sin(x), x)
    -cos(x)**5/5
    >>> integrate(cos(x)**4 * sin(x), x)
    -cos(x)**5/5
    >>> manualintegrate(cos(x)**4 * sin(x)**3, x)
    cos(x)**7/7 - cos(x)**5/5
    >>> integrate(cos(x)**4 * sin(x)**3, x)
    cos(x)**7/7 - cos(x)**5/5
    >>> manualintegrate(tan(x), x)
    -log(cos(x))
    >>> integrate(tan(x), x)
    -log(cos(x))

    See Also
    ========

    sympy.integrals.integrals.integrate
    sympy.integrals.integrals.Integral.doit
    sympy.integrals.integrals.Integral
    r   r   rJ   T)r  r   r&  clearr   r$   r   r   r   rs   r   )r   r  r   r  r^   r^   r_   manualintegrated  s    1r  N)rX   (  __doc__typingr   ZtDictr   collectionsr   r   collections.abcr   	functoolsr   Zsympy.core.addr   Zsympy.core.cacher	   Zsympy.core.containersZsympy.core.exprr
   Zsympy.core.functionr   Zsympy.core.logicr   Zsympy.core.mulr   Zsympy.core.numbersr   r   r   Zsympy.core.powerr   Zsympy.core.relationalr   r   r   r   Zsympy.core.singletonr   Zsympy.core.symbolr   r   r   Z$sympy.functions.elementary.complexesr   Z&sympy.functions.elementary.exponentialr   r   Z%sympy.functions.elementary.hyperbolicr   r   r   r    r!   r"   Z(sympy.functions.elementary.miscellaneousr#   Z$sympy.functions.elementary.piecewiser$   Z(sympy.functions.elementary.trigonometricr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   Z'sympy.functions.special.delta_functionsr2   Z'sympy.functions.special.error_functionsr3   r4   r5   r6   r7   r8   r9   r:   r;   r<   Z'sympy.functions.special.gamma_functionsr=   Z*sympy.functions.special.elliptic_integralsr>   r?   Z#sympy.functions.special.polynomialsr@   rA   rB   rC   rD   rE   rF   rG   rH   Z&sympy.functions.special.zeta_functionsrI   Z	integralsrK   Zsympy.logic.boolalgrL   Zsympy.ntheory.factor_rM   Zsympy.polys.polytoolsrN   Zsympy.simplify.radsimprO   Zsympy.simplify.simplifyrP   Zsympy.solvers.solversrQ   Zsympy.strategies.corerR   rS   rT   rU   Zsympy.utilities.iterablesrV   Zsympy.utilities.miscrW   rf   rg   ri   rj   rk   rm   rn   ro   rp   rq   rr   rt   ru   rv   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rw   r   r   r   r   r   r  r  r  r   r+  r,  r.  r2  r3  r5  r7  r8  r9  r:  r<  r>  rB  rC  rD  rE  rF  rG  rK  rL  rI  rJ  rM  rN  rR  rS  rP  rQ  rH  rO  rT  rU  rV  r`  ra  rc  rq  rr  rs  rt  rg  rh  ri  rp  intr&  r%  r   rv  rw  rx  ry  r{  r|  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r^   r^   r^   r_   <module>   s   <0,








































![(A[L)@		








=?



 '
