
    gFh                       U 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 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!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' d dl m(Z(m)Z)m*Z*m+Z+m,Z,m-Z- d dl m.Z.m/Z/m0Z0m1Z1m2Z2 d dl m3Z3m4Z4m5Z5m6Z6 d dl m7Z7m8Z8m9Z9m:Z: d dl;m<Z<m=Z=m>Z>m?Z?m@Z@ d dlAmBZB d dlCmDZDmEZE d dlFmGZG d dlHmIZImJZJ d dlKmLZL d dlMmNZNmOZO d dlPmQZQ d dlRmSZSmTZTmUZUmVZVmWZWmXZX d dlYmZZZ d dl[m\Z\ d dl]m^Z^ d d l_m`Z` d d!lambZb d d"lcmdZd d# Zei Zfd$egd%<   d& Zh	 	 	 d0d*Zi G d+ d,          Zjd(ak G d- d.          Zl	 	 	 d0d/Zmd(S )1    )annotations)defaultdict)reducepermutations)Add)Basic)Mul)WildDummySymbol)sympify)RationalpiI)EqNe)S)ordered)iterfreeargs)expsincostancotasinatan)logsinhcoshtanhcothasinh)sqrterferfiliEi)besseljbesselybesselibesselk)hankel1hankel2jnyn)Absreimsignarg)LambertW)floorceiling)	Piecewise)	Heaviside
DiracDelta)collect)AndOr)uniq)quogcdlcmfactor_listcancelPolynomialError)itermonomials)root_factors)PolyRing)solve_lin_sys)construct_domain)	integratec                f   t                      }|                     |          r| j        r| j        r|                    |            n| j        s| j        r3| j        D ]}|t          ||          z  }|                    |            n| j	        r|t          | j
        |          z  }| j        j        s^| j        j        r6|                    | j
        t          d| j        j                  z             n:|t          | j        |          | hz  z  }n| j        D ]}|t          ||          z  }|S )a  
    Returns a set of all functional components of the given expression
    which includes symbols, function applications and compositions and
    non-integer powers. Fractional powers are collected with
    minimal, positive exponents.

    Examples
    ========

    >>> from sympy import cos, sin
    >>> from sympy.abc import x
    >>> from sympy.integrals.heurisch import components

    >>> components(sin(x)*cos(x)**2, x)
    {x, sin(x), cos(x)}

    See Also
    ========

    heurisch
       )sethas_free	is_symbolis_commutativeaddis_Functionis_Derivativeargs
componentsis_Powbaser   
is_Integeris_Rationalr   q)fxresultgs       T/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/integrals/heurisch.pyrV   rV   -   s=   , UUFzz!}} +; 	+1+ 	+JJqMMMM] 	+ao 	+V + +*Q***JJqMMMMX 
	+j+++F5# 95$ 9JJqvx157';';;<<<<j22aS88FV + +*Q***M    zdict[str, list[Dummy]]_symbols_cachec           	         	 t           |          }n# t          $ r g }|t           | <   Y nw xY wt          |          |k     rG|                    t	          d| t          |          fz                       t          |          |k     G|d|         S )z*get vector of symbols local to this modulez%s%iN)rb   KeyErrorlenappendr   )namenlsymss      r`   _symbolsrj   `   s    %t$ % % %$t% e**q..eFdCJJ%7788::: e**q.. !9s    ))FN   c	                   ddl m}	m}
 t          |           } |                     |          s| |z  S t          | ||||||||	  	        }t          |t                    s|S g }t           |
|                    D ]&}	 | |	|gd|f          z  }# t          $ r Y #w xY w|s|S t          t          |                    }g  |
|           D ]&}	  |	|gd|f          z  # t          $ r Y #w xY wfd|D             }|s|S t          |          dk    rJg }|D ]3}|                    d |                                D                        4 |	|d|f          |z   }g }|D ]}t          |                     |          ||||||||	  	        }t!          d |                                D              }t#          d	 |                                D              }|#t%          |                     |          |          }|                    ||f           t          |          dk    r*t          | ||||||||	  	        |f|d         d         dfg}n,|                    t          | ||||||||	  	        df           t)          | S )
a  
    A wrapper around the heurisch integration algorithm.

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

    This method takes the result from heurisch and checks for poles in the
    denominator. For each of these poles, the integral is reevaluated, and
    the final integration result is given in terms of a Piecewise.

    Examples
    ========

    >>> from sympy import cos, symbols
    >>> from sympy.integrals.heurisch import heurisch, heurisch_wrapper
    >>> n, x = symbols('n x')
    >>> heurisch(cos(n*x), x)
    sin(n*x)/n
    >>> heurisch_wrapper(cos(n*x), x)
    Piecewise((sin(n*x)/n, Ne(n, 0)), (x, True))

    See Also
    ========

    heurisch
    r   )solvedenomsT)dictexcludec                    g | ]}|v|	S  rr   ).0sslns0s     r`   
<listcomp>z$heurisch_wrapper.<locals>.<listcomp>   s    ...!q~~A~~~ra   rM   c                4    g | ]\  }}t          ||          S rr   r   rs   keyvalues      r`   rv   z$heurisch_wrapper.<locals>.<listcomp>   s$    JJJ:33JJJra   c                4    g | ]\  }}t          ||          S rr   rx   ry   s      r`   rv   z$heurisch_wrapper.<locals>.<listcomp>   s$    GGG
URU^^GGGra   c                4    g | ]\  }}t          ||          S rr   )r   ry   s      r`   rv   z$heurisch_wrapper.<locals>.<listcomp>   s$    III*#ur#u~~IIIra   )sympy.solvers.solversrm   rn   r   rO   heurisch
isinstancer	   r   NotImplementedErrorlistr?   re   extenditemssubsr=   r>   rK   rf   r9   )r\   r]   rewritehintsmappingsretriesdegree_offsetunnecessary_permutations_try_heurischrm   rn   resslnsdeqssub_dictpairsexprcondgenericru   s                       @r`   heurisch_wrapperr   n   sm   : 43333333

A::a== s

1a%7M+]< <Cc5!! 
 DVVC[[!!  	EE1#D1$7777DD" 	 	 	D	 
T

DEVAYY  	UUA3TA48888EE" 	 	 	D	....t...D 

4yy1}} 	L 	LHJJJJ9I9IJJJKKKKuStaT222T9E # #x((!WeXw%'?%' ' GGhnn6F6FGGGHII8H8HIIIJ<QVVH--a00DdD\"""" 5zzQ1a%7+-E+- - &' (1+t$	& 	hq!WeXw+-E+- - #$ 	% 	% 	% es$   >B
BBC&&
C32C3c                  *    e Zd ZdZd Zd Zd Zd ZdS )BesselTablez~
    Derivatives of Bessel functions of orders n and n-1
    in terms of each other.

    See the docstring of DiffCache.
    c                    i | _         t          d          | _        t          d          | _        |                                  d S )Nrh   z)tabler   rh   r   _create_table)selfs    r`   __init__zBesselTable.__init__   s;    
ssra   c                    | j         | j        | j        }}}t          t          t
          t          fD ]L} ||dz
  |          | |||          z  |z  z
  |dz
   ||dz
  |          z  |z   |||          z
  f||<   Mt          } ||dz
  |          | |||          z  |z  z
  |dz
   ||dz
  |          z  |z   |||          z   f||<   t          } ||dz
  |           | |||          z  |z  z
  |dz
   ||dz
  |          z  |z   |||          z
  f||<   t          t          fD ]O} ||dz
  |          |dz    |||          z  |z  z
  |dz
   ||dz
  |          z  |z   |||          z
  f||<   Pd S )NrM   )r   rh   r   r)   r*   r-   r.   r+   r,   r/   r0   )tr   rh   r   r\   s        r`   r   zBesselTable._create_table   s   gqsAC!q7GW5 	5 	5A!A#q		Aaa1ggIaK/1aa!Qii)AAaGG35E!HH Aac1II!!Aq''	!+qS!!AaC))OA%!Q/1aQqsAYYJ11Q771,qS!!AaC))OA%!Q/1a b 	5 	5A!A#q		QqS!!Aq''M!O31aa!Qii)AAaGG35E!HH	5 	5ra   c                    || j         v rL| j         |         \  }}| j        |f| j        |fg}|                    |          |                    |          fS d S N)r   rh   r   r   )r   r\   rh   r   diff0diff1repls          r`   diffszBesselTable.diffs   s\    <<71:LE5S!HqsAh'DJJt$$ejj&6&677 <ra   c                    || j         v S r   )r   )r   r\   s     r`   haszBesselTable.has   s    AG|ra   N)__name__
__module____qualname____doc__r   r   r   r   rr   ra   r`   r   r      sZ           5 5 5"8 8 8    ra   r   c                      e Zd ZdZd Zd ZdS )	DiffCacheau  
    Store for derivatives of expressions.

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

    The standard form of the derivative of a Bessel function of order n
    contains two Bessel functions of orders n-1 and n+1, respectively.
    Such forms cannot be used in parallel Risch algorithm, because
    there is a linear recurrence relation between the three functions
    while the algorithm expects that functions and derivatives are
    represented in terms of algebraically independent transcendentals.

    The solution is to take two of the functions, e.g., those of orders
    n and n-1, and to express the derivatives in terms of the pair.
    To guarantee that the proper form is used the two derivatives are
    cached as soon as one is encountered.

    Derivatives of other functions are also cached at no extra cost.
    All derivatives are with respect to the same variable `x`.
    c                P    i | _         || _        t          st                      ad S d S r   )cacher]   _bessel_tabler   )r   r]   s     r`   r   zDiffCache.__init__  s1    
  	*'MMMMM	* 	*ra   c                   | j         }||v rnt          |d          rt                              |j                  s+t          |                    | j                            ||<   nj|j        \  }}t          	                    |j        ||          \  }}| 
                    |          }||z  ||<   ||z  ||                    |dz
  |          <   ||         S )NfuncrM   )r   hasattrr   r   r   rD   diffr]   rU   r   get_diff)r   r\   r   rh   r   d0d1dzs           r`   r   zDiffCache.get_diff  s    
::!V$$ 	*!!!&))	*affTVnn--E!HH6DAq"((A66FBq!!B"uE!H$&rEE!&&1a..!Qxra   N)r   r   r   r   r   r   rr   ra   r`   r   r      s<         ,* * *    ra   r   c	                h  ./0123456789:;<= t          |           } |durL|                     t          t          t          t
          t          t          t          t          t          	  	        rdS |                               s| z  S | j        s|                               \  }	} nt          j        }	t           t"          t$          ft&          t(          t*          t,          ft.          i}
|r1|
                                D ]\  }}|                     ||          } n%|
                                D ]} | j        | r nd}t7          |           }t9                    5|4|st;          dg          }t;          dg          }t;          dg          }t=          |          D ]}|j        rOtA          |tB                    r|j"        d         #                    ||z  z            }||$                    tC          ||         ||         z  z            ||         ||         z  z  d||         z  z  tK          ||         d	z   tM          ||         ||         z  z            z  ||         z            z  z
  z             tA          |tN                    r]|j"        d         #                    |d
z  z            }|||         j(        r9|$                    tS          tU          ||                   z                       n9|$                    tW          tU          ||                    z                       |j"        d         #                    |d
z  z  |z  z   |z             }|q||         j(        r|$                    tU          tX          dz  ||          z            tO          ||         ||         d
z  d||         z  z  z
            z  tS          tU          ||                   z  ||         d
tU          ||                   z  z  z             z             n||         j-        r|$                    tU          tX          dz  ||          z            tO          ||         ||         d
z  d||         z  z  z
            z  tW          tU          ||                    z  ||         d
tU          ||                    z  z  z
            z             |j"        d         #                    |tM                    d
z  z            }|||         j(        ra|$                    tS          tU          ||                   tM                    z  d	d
tU          ||                   z  z  z                        ||         j-        rc|$                    tW          tU          ||                    tM                    z  d	d
tU          ||                    z  z  z
                       Z|j.        ru|j'        j/        rh|j'        j0        d
k    rW|j1        #                    |d
z  z  |z             }|||         j(        r||         j(        rB|$                    te          tU          ||         ||         z            z                       nO||         j-        rB|$                    tg          tU          ||          ||         z            z                       |j1        #                    |d
z  z  |z
            }|a||         j(        rS||         j(        rd	tU          ||         d
z  z  ||         z
            z  }tM          d
tU          ||                   z  tU          ||         d
z  z  ||         z
            z  d
||         z  z  z             tU          ||                   z  .|5j4        .<   |$                    .           H||         j-        r|$                    ||          d
z  tU          ||                    z  tk          tU          ||                    z  tU          ||         d
z  z  ||         z
            z            z             n|t=          |          z  }t=          |          D ](}|t7          56                    |                    z  })to          dtq          |                    /ts          tu          ts          tw          ty          fdtw          |/          D                                  d	                             7d 7D             }|7d         d         k    sJ 7=                    d          g}t}          tr                    =7D ]*}=t          |                   @                    |           +=fd=D             77fd} |            }n|pg }7fd4|D ]t7ts          7          77|z   745fd|D             }d |D             }t          /fd|D                       r(  4|           jB        / rt          /fd|          6 n u|st          | d||          }||	|z  S dS 6fd|D             8/8fd1/01fd0/13fd3i }|D ]}|j        rtA          |t&                    rd|d	 4|          d
z  z   <   3tA          |t.                    r#d|d	 4|          z   <   d|d	 4|          z
  <   ktA          |t                    rd| 4|          <    4|           ..F                                \  }} 36          } 3|          }t=          ts          |          |d         gz   ts          |                                          z             } |d         t          d |                                D              z  }!/fd|!||fD             }"d|"v rdS d |"D             \  }}}|!|d         z   0|d	                   z  H                                :2fd2 2|           |t          ||          z   }$}#|#d	k    r:|$d	k    r4t          ty          t          /|#|$z   d	z
  |z                                 }%n0t          ty          t          /|#|$z   |z                                 }%to          d tq          |%                    9t          9fd!t          |%          D              ;t=                      <ty          |           D ]F}&t          |&g/R  \  }'}(<$                    |'           <O                    d" |(D                        Gd(./169:;<fd#	})t          d$ /D                       r.jP        t=          /          z
  }*n[.Q                                }+|+R                    t          tw          /d% /D                                           jP        |+jP        z  }*|*s |)d&          },|,
 |)            },n
 |)            },|,]|,T                    |          }-t          |-          V                                }-|-j        r|-                              d	         }-|	|-z  S |dk    r t          | ||||d	z
  |'          }||	|z  S dS ))a-
  
    Compute indefinite integral using heuristic Risch algorithm.

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

    This is a heuristic approach to indefinite integration in finite
    terms using the extended heuristic (parallel) Risch algorithm, based
    on Manuel Bronstein's "Poor Man's Integrator".

    The algorithm supports various classes of functions including
    transcendental elementary or special functions like Airy,
    Bessel, Whittaker and Lambert.

    Note that this algorithm is not a decision procedure. If it isn't
    able to compute the antiderivative for a given function, then this is
    not a proof that such a functions does not exist.  One should use
    recursive Risch algorithm in such case.  It's an open question if
    this algorithm can be made a full decision procedure.

    This is an internal integrator procedure. You should use top level
    'integrate' function in most cases, as this procedure needs some
    preprocessing steps and otherwise may fail.

    Specification
    =============

     heurisch(f, x, rewrite=False, hints=None)

       where
         f : expression
         x : symbol

         rewrite -> force rewrite 'f' in terms of 'tan' and 'tanh'
         hints   -> a list of functions that may appear in anti-derivate

          - hints = None          --> no suggestions at all
          - hints = [ ]           --> try to figure out
          - hints = [f1, ..., fn] --> we know better

    Examples
    ========

    >>> from sympy import tan
    >>> from sympy.integrals.heurisch import heurisch
    >>> from sympy.abc import x, y

    >>> heurisch(y*tan(x), x)
    y*log(tan(x)**2 + 1)/2

    See Manuel Bronstein's "Poor Man's Integrator":

    References
    ==========

    .. [1] https://www-sop.inria.fr/cafe/Manuel.Bronstein/pmint/index.html

    For more information on the implemented algorithm refer to:

    .. [2] K. Geddes, L. Stefanus, On the Risch-Norman Integration
       Method and its Implementation in Maple, Proceedings of
       ISSAC'89, ACM Press, 212-217.

    .. [3] J. H. Davenport, On the Parallel Risch Algorithm (I),
       Proceedings of EUROCAM'82, LNCS 144, Springer, 144-157.

    .. [4] J. H. Davenport, On the Parallel Risch Algorithm (III):
       Use of Tangents, SIGSAM Bulletin 16 (1982), 3-6.

    .. [5] J. H. Davenport, B. M. Trager, On the Parallel Risch
       Algorithm (II), ACM Transactions on Mathematical
       Software 11 (1985), 356-362.

    See Also
    ========

    sympy.integrals.integrals.Integral.doit
    sympy.integrals.integrals.Integral
    sympy.integrals.heurisch.components
    TNa)rp   bcr   rM         r]   c                V    g | ]%}|d                                         d         |f&S )r   rM   )as_independent)rs   r   r]   s     r`   rv   zheurisch.<locals>.<listcomp>  s5    ???A!A$

a
 
 
#Q	'???ra   c                    i | ]\  }}||	S rr   rr   rs   kvs      r`   
<dictcomp>zheurisch.<locals>.<dictcomp>  s    ,,,DAq1a,,,ra   c                     g | ]
}|         S rr   rr   )rs   itypess     r`   rv   zheurisch.<locals>.<listcomp>   s    +++58+++ra   c               3  L   K   t                    D ]} d | D             V  d S )Nc                    g | ]	}|D ]}|
S rr   rr   )rs   r   js      r`   rv   z4heurisch.<locals>._iter_mappings.<locals>.<listcomp>  s%    ///QQ//q////ra   r   )r   mappings    r`   _iter_mappingsz heurisch.<locals>._iter_mappings  sE      !'** 0 0//!///////0 0ra   c                .    |                                S r   )r   )r   r   s    r`   _substitutezheurisch.<locals>._substitute  s    yy!!!ra   c                L    g | ] }                      |                    !S rr   )r   )rs   r_   r   dcaches     r`   rv   zheurisch.<locals>.<listcomp>  s/    BBBa++fooa0011BBBra   c                B    g | ]}|                                 d          S )rM   )as_numer_denom)rs   r_   s     r`   rv   zheurisch.<locals>.<listcomp>  s)    999Q1##%%a(999ra   c              3  ,   K   | ]} |j          V  d S r   )is_polynomial)rs   hVs     r`   	<genexpr>zheurisch.<locals>.<genexpr>  s,      33qq"333333ra   c                     t          | |gR  S r   )rB   )pr[   r   s     r`   <lambda>zheurisch.<locals>.<lambda>  s    Aq1 ra   )r   r   r   c                4    g | ]}t          |z            S rr   )rD   )rs   r_   denoms     r`   rv   zheurisch.<locals>.<listcomp>  s#    ///1veAg///ra   c                L     t           fdt                    D              S )Nc                F    g | ]\  }}|                     |          z  S rr   )r   )rs   r   r   r   s      r`   rv   z1heurisch.<locals>._derivation.<locals>.<listcomp>  s+    @@@1a!&&))m@@@ra   )r   zip)r   r   numerss   `r`   _derivationzheurisch.<locals>._derivation  s,    @@@@FA@@@AAra   c                F   D ]}|                      |          s |           t          j        urm|                     |                                          \  }} |          t          ||                    |                                                    z  c S | S r   )r   r   Zeroas_poly	primitiverA   r   as_expr)r   yr   r[   r   
_deflationr   s       r`   r   zheurisch.<locals>._deflation   s     	A 	AA5588 {1~~QV++yy||--//1!z!}}SAFF1II%6%6%>%>%@%@@@@@ , ra   c           
        D ]I}|                      |          s 	|          t          j        ur|                     |                                          \  }}|                                }t          | 	|          |          }t          |t          ||                    |          |          |          } 
|          }|                    |          	                                dk    r|d         ||d         z  fc S  
t          ||z                      }|d         |d         z  |z  |d         |d         z  fc S Kt          j        | fS )Nr   rM   )r   r   r   r   r   r   rA   r@   r   degreerD   One)r   r   r   r[   r   rt   c_splitq_splitr   r   	_splitters           r`   r   zheurisch.<locals>._splitter+  sQ    	H 	HA5588 {1~~QV++yy||--//1IIKK;;q>>1--3q!&&))Q//33#)A,,99Q<<&&((A--#AJGAJ7777#)F1q5MM22
71:-a/GAJ1FGGGG ," qzra   Fc                    g | ]	\  }}||
S rr   rr   r   s      r`   rv   zheurisch.<locals>.<listcomp>X  s!    @@@$!QQ@A@@@ra   c                $    g | ]} |j          S rr   )r   )rs   r   r   s     r`   rv   zheurisch.<locals>.<listcomp>Y  s!    3331A333ra   c                6    g | ]}|                                 S rr   )total_degree)rs   r   s     r`   rv   zheurisch.<locals>.<listcomp>_  s"    444Q  444ra   c                R   | j         rp| j        j        rb| j        j        dk    rR| j        j        dk    r| j        j        | j        j        z   dz
  S t          | j        j        | j        j        z             S dS | j        s'| j        r t          fd| j        D                       S dS )NrM   r   c              3  .   K   | ]} |          V  d S r   rr   )rs   r   	_exponents     r`   r   z.heurisch.<locals>._exponent.<locals>.<genexpr>m  s+      44yy||444444ra   )	rW   r   rZ   r[   r   absis_AtomrU   max)r_   r   s    r`   r   zheurisch.<locals>._exponentc  s    8 	u  QUW\\57Q;;57QUW,q00quw0111q 	qv 	4444QV4444441ra   Ac                ,    g | ]\  }}|         |z  S rr   rr   )rs   r   monomialpoly_coeffss      r`   rv   zheurisch.<locals>.<listcomp>z  s6     / / /Ax #1~h. / / /ra   c              3      K   | ]	\  }}|V  
d S r   rr   )rs   factmuls      r`   r   zheurisch.<locals>.<genexpr>  s&      8894$888888ra   c                	   t                      }t                      }| dk    rt          %          }nt                    }t                      }t          %          D ]W}|t          t          |                    z  }t          |          D ]&}t          t          |||                     }||z  } Xg g }
}	t          |          D ]}t	          |t
          d          }|                    t
          t          j                  }|r|                    t          j	        t          j                  }|
                    t
                    s|
                    t
                    r|                    ||f           |                    |           |r|                                \  }}|| f|v rs|                    || f           |                                r| }|                    ||z  ||z  z              |                    t          ||z                       n |                    |t
          |z  z              |t!          dt#          |                    }t!          dt#          |                    }t%          t'          t)          t          |          |                              D ]I\  }} |j
         r:"                    |           |	                    |t-          |          z             Jt%          t'          t)          t          |          |                              D ]<\  }} |j
         r-"                    |           |
                    ||z             =$#z  t/          |	 z   t/          |
 z   }  |          !z  z
  }|                                d         }t          "          t                    z  t                      fd	  |           t3          d	
          \  }}n# t4          $ r Y d S w xY wt7          "|          }t7          |          }	 |                    |          }n# t:          $ r t4          w xY wt=          |                                |d          }|d S |                     |                               tC          t)          "t          j        gt#          "          z                                S )NQ)filterF)evaluateBCr   c                    | j         s| j        rd S | v rd S  | j         s                    |            d S | j        s| j        s| j        r$t          t          | j	                             d S t          r   )rY   rZ   rO   rR   is_Addis_MulrW   r   maprU   rE   )r   find_non_symsnon_symssymss    r`   r  z3heurisch.<locals>._integrate.<locals>.find_non_syms  s     &$"2 &"T]D) &T""""" & &t{ &S	2233333 &%ra   T)field)_raw)"rN   r   r   rG   r<   r   getr   r   r   r   rR   removepopcould_extract_minus_signr   rj   re   reversedr   r   rf   r   r   r   rJ   rE   rH   	from_expr
ValueErrorrI   coeffsxreplacero   )&r  atansr   irreduciblessetVpolyzVr   rt   log_part	atan_partmr   r]   r  r  r   r   	candidater   	raw_numerground_
coeff_ringringnumersolutionr  r  r  Fr   r   r   r   
poly_denom	poly_part
reducibless&                              @@@r`   
_integratezheurisch.<locals>._integrate  s   C<<z??LLq66D55L
++  CT 2 2333   ALq???@@A A%L ")L)) 	* 	*Da%000Aa  A *EE!%((5588 quuQxx 		1a&!!!##D))) 
	*99;;DAqA2w%a!W%%%--// A  1qs+++		$qs))$$$$  QqS)))  
	* S#l++,,S#e**%%  S)>)>%B%B C CDD 	/ 	/GD!tx| /""1%%%CII...S%;%; < <== 	+ 	+GD!tx| +""1%%%  T*** j(3>9COK	I&&..$$&&q)	 ;#a&&(55	& 	& 	& 	& 	& 	& 	&	?M)$$$ )>>>IFAA  	 	 	44	
 k622
:&&	"NN9--EE 	" 	" 	"!!	" %HHH4%%h//88Sqvhs;/?/?&?@@AAC C Cs   7P 
P%$P%	Q Q1c              3  @   K   | ]}t          |t                    V  d S r   )r   r   rs   r&  s     r`   r   zheurisch.<locals>.<genexpr>  s,      
,
,Q:a  
,
,
,
,
,
,ra   c              3  2   K   | ]}t                      V  d S r   )r   r1  s     r`   r   zheurisch.<locals>.<genexpr>  s&      ,@,@UWW,@,@,@,@,@,@ra   r  )r   r   r   r   r   r   )Wr   r   r1   r2   r3   r4   r:   r;   r7   r8   r5   rO   r
  r   r   r   r   r   r   r   r   r    r"   r!   r   r   keysrV   r   r   rN   rS   r   r'   rU   matchrR   r(   r   r   is_positiver&   r$   r%   r   is_negativerW   rZ   r[   rX   r#   r   r   r   r   rj   re   r   r  r   r   r  r   typerf   allis_rational_functionr   r   r6   r   r
   r   r   tuplerF   r   	enumeraterC   updatefree_symbolsas_dummyr  ro   r   rD   expand)>r\   r]   r   r   r   r   r   r   r   indeprewritables
candidatesruletermsr   r   r   r_   MdFrev_mappingr   r   r   rn   r^   specialtermPr  u_splitv_splitpolysrt   polifiedr   r  monomsr  coefffactorsr/  	more_freeFdr*  	antiderivr+  r   r   r   r   r   r   r   r   r   r   r   r,  r-  r.  r   s>    `                                            @@@@@@@@@@@@@@@@r`   r   r   (  s(   f 	

A
 D  55b"dIz5'3OO 	F::a== s
8 ##A&&qq 
c3	tTDK
   + 1 1 3 3 	, 	,J		*d++AA	, &**,, 	 	Jquj!  Gq!Eq\\F B	 S1#&&&AS1#&&&AS1#&&&AZZ :W :W= 9W!!R(( "WF1IOOAadF33=!IIq"QqT!QqT'\*:*:ad1ad7lbQRSTQUg=VWY[\]^[_`a[acfghijgklmopqroslsgsctctZtuvwxuyZyWzWz=z*z'{}}}
 $As++ WF1IOOAadF33= t/ > %		$tAaDzz!|*<*< = = = = %		#dAaD5kk!m*<*< = = =F1IOOAadFQqSL1,<=== t/ U %		$r!tadU|*<*<S1!aQRSTUVSWQWHXAX=Y=Y*Y*.tAaDzz!|adAd1Q4jjL>Q/Q*R*R+S !T !T !T !T!"1!1 U %		$r!tadU|*<*<S1!aQRSTUVSWQWHXAX=Y=Y*Y*-dAaD5kk!madAdAaD5kkM>R.R*S*S+T !U !U !U F1IOOAc!ffaiK88= t/ V %		$tAaDzz#a&&/@1aQqT

lCS/S*T*T U U U t/ W %		#dAaD5kk#a&&.@1aaPQdUmCT.T*U*U V V VX Wu( WQUW\\FLL1a4!44=QqT-== t/ D %		%QqT!A$Y0A*B*B C C C C!"1!1 D %		$tQqTE!A$J/?/?/A*B*B C C CFLL1a4!44=QqT-== t/ W%&tAaDAI!,<'='=%=$'$qt**T!A$q!t)ad:J5K5K(KaPQRSPTfUVh(V$W$WX\]^_`]aXbXb$b24Q %		!!"1!1 W %		1Q4%'$!u++*=+/adUAd1Q419qQRtCS>T>T0T+U+U+V !W !W !Ws:Wz SZZEZZ 3 3FOOA..222 	c%jj!!A 8Dg????UA???'A 'A "B C CCDF G G H HG,,G,,,Kr{1~""""$+KKOO#4  D!! 	% 	%A$q''N!!!$$$$++++U+++	0 	0 	0 	0 	0 ">###;#Ar " " " " "   w--44BBBBB5BBB99%9993333F33333 	8[A8[]^8_ 	5555v>>EE 	$aD)AC C CF !V|#t///////FB B B B B B	 	 	 	 	 	 	      0 G 2 2 	2$$$ 249KK--q0011D$'' 216KK---.16KK---..D(++ 2-1D))*AADAqiGillGW'!*.gllnn1E1EEFFE
S@@'--//@@@AAA3333Aq	333Hxt 54(444GAq!gaj.::gaj#9#99BBDDJ     9Q<<SAYYqA1uuQw}QA	M0IJJKKLLw}QA0EFFGGHH3F,,K / / / /$V,,/ / / 0I J 9 9$T.A...wu888888888hC hC hC hC hC hC hC hC hC hC hC hC hCT 
,
,!
,
,
,,, -NSVV+		ZZ\\KKS,@,@a,@,@,@%A%A B B  R_-	  :c??!z||H:<<MM+..	9%%,,..	 	7!0033A6IYa<<aXwe]dgh]h  D\  ]  ]  ]F!V|#tra   )FNNrk   r   NN)n
__future__r   collectionsr   	functoolsr   	itertoolsr   sympy.core.addr   sympy.core.basicr	   sympy.core.mulr
   sympy.core.symbolr   r   r   r   sympy.core.numbersr   r   r   sympy.core.relationalr   r   sympy.core.singletonr   sympy.core.sortingr   sympy.core.traversalr   sympy.functionsr   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   $sympy.functions.elementary.complexesr1   r2   r3   r4   r5   &sympy.functions.elementary.exponentialr6   #sympy.functions.elementary.integersr7   r8   $sympy.functions.elementary.piecewiser9   'sympy.functions.special.delta_functionsr:   r;   sympy.simplify.radsimpr<   sympy.logic.boolalgr=   r>   sympy.utilities.iterablesr?   sympy.polysr@   rA   rB   rC   rD   rE   sympy.polys.monomialsrF   sympy.polys.polyrootsrG   sympy.polys.ringsrH   sympy.polys.solversrI   sympy.polys.constructorrJ   sympy.integrals.integralsrK   rV   rb   __annotations__rj   r   r   r   r   r   rr   ra   r`   <module>rs     s2   " " " " " " " # # # # # #       " " " " " "       " " " " " "       1 1 1 1 1 1 1 1 1 1 $ $ $ $ $ $ . . . . . . . . . . ( ( ( ( ( ( ( ( " " " " " " & & & & & & - - - - - - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > > > > > > > > > > > > > > > 3 3 3 3 3 3 3 3 3 3 3 3 3 3 > > > > > > > > > > > > 4 4 4 4 4 4 4 4 4 4 4 4 G G G G G G G G G G G G G G ; ; ; ; ; ; > > > > > > > > : : : : : : I I I I I I I I * * * * * * ' ' ' ' ' ' ' ' * * * * * * K K K K K K K K K K K K K K K K / / / / / / . . . . . . & & & & & & - - - - - - 4 4 4 4 4 4 / / / / / /, , ,^ *, + + + +   NO?C#'^ ^ ^ ^@& & & & & & & &P . . . . . . . .` FG7;d d d d d dra   