
    Edd                      (   d dl mZ d dl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Zd dlZd dlmZ  ed          Zer:d dlmZmZ d dlm Z m!Z!m"Z" d dl#m$Z$m%Z%  ed          d             Z& e!e          Z' G d d          Z( ed          d             Z) ed          d             Z* ed          dd            Z+ ed          dd            Z, ed          d             Z-dS )     )import_module)doctest_depends_on)IntegerFloat)Add)Function)Mul)E)Pow)S)Integral)expN)powsimpmatchpy)ManyToOneReplacerManyToOneMatcher)rubi_exprubi_unevaluated_exprprocess_trig)op_iterop_len)r   )modulesc                     ddl m}  ddlm} ddlm} ddlm} ddlm	} ddl
m} ddlm} dd	lm} dd
lm} ddlm}	 ddlm}
 ddlm} ddlm} ddlm} ddlm} ddlm} ddl m!} g }| |             z  }| |            z  }| |            z  }| |            z  }| |            z  }| |            z  }| |            z  }| |            z  }| |            z  }| |            z  }| |	            z  }| |
            z  }| |            z  }| |            z  }| |            z  }| |            z  }| |            z  }tE          | }||fS )a9  
        Returns rubi ManyToOneReplacer by adding all rules from different modules.

        Uncomment the lines to add integration capabilities of that module.

        Currently, there are parsing issues with special_function,
        derivative and miscellaneous_integration. Hence they are commented.
        r   )integrand_simplification)linear_products)quadratic_products)binomial_products)trinomial_products)miscellaneous_algebraic)exponential)
logarithms)sine)tangent)secant)miscellaneous_trig)inverse_trig)
hyperbolic)inverse_hyperbolic)special_functions)miscellaneous_integration)#3sympy.integrals.rubi.rules.integrand_simplificationr   *sympy.integrals.rubi.rules.linear_productsr   -sympy.integrals.rubi.rules.quadratic_productsr   ,sympy.integrals.rubi.rules.binomial_productsr   -sympy.integrals.rubi.rules.trinomial_productsr   2sympy.integrals.rubi.rules.miscellaneous_algebraicr   &sympy.integrals.rubi.rules.exponentialr    %sympy.integrals.rubi.rules.logarithmsr!   sympy.integrals.rubi.rules.siner"   "sympy.integrals.rubi.rules.tangentr#   !sympy.integrals.rubi.rules.secantr$   -sympy.integrals.rubi.rules.miscellaneous_trigr%   'sympy.integrals.rubi.rules.inverse_trigr&   %sympy.integrals.rubi.rules.hyperbolicr'   -sympy.integrals.rubi.rules.inverse_hyperbolicr(   ,sympy.integrals.rubi.rules.special_functionsr)   4sympy.integrals.rubi.rules.miscellaneous_integrationr*   r   )r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   rulesrubis                      =lib/python3.11/site-packages/sympy/integrals/rubi/rubimain.pyget_rubi_objectr?      s    	a`````NNNNNNTTTTTTRRRRRRTTTTTT^^^^^^FFFFFFDDDDDD888888>>>>>><<<<<<TTTTTTHHHHHHDDDDDDTTTTTTRRRRRR 	cbbbbb))+++"""##%%%""$$$##%%%((***""$$$##%%%##%%%**,,, %(U{    c                   :    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
dS )	LoadRubiReplacerz-
    Class trick to load RUBI only once.
    Nc                     t           t          d           d S t          j        t          j        S t                              |           }d |_        d |_        |t          _        |S )NzMatchPy library not found)r   printrB   	_instanceobject__new___rubi_rules)clsobjs     r>   rG   zLoadRubiReplacer.__new__X   s_     	-...4% 	.#--nnS!!	
%("
r@   c                 `    | j         | j         S t                      \  }}|| _         || _        |S N)rH   r?   rI   )selfr=   r<   s      r>   loadzLoadRubiReplacer.loadd   s6    : 	:%''e
r@   c                     dd l }|                                 }t          |d          5 }|                    ||           d d d            d S # 1 swxY w Y   d S Nr   wb)picklerO   opendump)rN   filenamerS   r=   fouts        r>   	to_picklezLoadRubiReplacer.to_picklel   s    yy{{(D!! 	$TKKd###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$   AAAc                     dd l }|                                 }t          |d          5 }|                    ||           d d d            d S # 1 swxY w Y   d S rQ   )dillrO   rT   rU   )rN   rV   r[   r=   rW   s        r>   to_dillzLoadRubiReplacer.to_dillr   s    yy{{(D!! 	"TIIdD!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"rY   c                     dd l }t          |d          5 }|                    |          | _        d d d            n# 1 swxY w Y   | j        S Nr   rb)rS   rT   rO   rH   )rN   rV   rS   fins       r>   from_picklezLoadRubiReplacer.from_picklex   s    (D!! 	*SS))DJ	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*z   <A A c                     dd l }t          |d          5 }|                    |          | _        d d d            n# 1 swxY w Y   | j        S r^   )r[   rT   rO   rH   )rN   rV   r[   r`   s       r>   	from_dillzLoadRubiReplacer.from_dill~   s    (D!! 	(S3DJ	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(zrb   )__name__
__module____qualname____doc__rE   rG   rO   rX   r\   ra   rd    r@   r>   rB   rB   Q   s          I
 
 
  $ $ $" " "      r@   rB   c                 z    |                      t                    r |                     t          t                    } | S )a  
    Rubi's `rubi_exp` need to be replaced back to SymPy's general `exp`.

    Examples
    ========
    >>> from sympy import Function, E, Integral
    >>> from sympy.integrals.rubi.rubimain import process_final_integral
    >>> from sympy.integrals.rubi.utility_function import rubi_unevaluated_expr
    >>> from sympy.abc import a, x
    >>> _E = rubi_unevaluated_expr(E)
    >>> process_final_integral(Integral(a, x))
    Integral(a, x)
    >>> process_final_integral(_E**5)
    exp(5)

    )has_Ereplacer
   )exprs    r>   process_final_integralro      s.    $ xx|| #||B""Kr@   c                 &   g }g }t          | t                    rw| j        D ]O}t          |t          t          t
          f          r|                    |           :|                    |           Pt          t          |           t          | z  S | S )a@  
    This function is needed to preprocess an expression as done in matchpy
    `x^a*x^b` in matchpy auotmatically transforms to `x^(a+b)`

    Examples
    ========

    >>> from sympy.integrals.rubi.rubimain import rubi_powsimp
    >>> from sympy.abc import a, b, x
    >>> rubi_powsimp(x**a*x**b)
    x**(a + b)

    )
isinstancer	   argsr   r   sym_expappendr   )rn   lst_powlst_non_powis       r>   rubi_powsimprx      s     GK$ 8 	& 	&A!c8W566 &q!!!!""1%%%%sG}%%c;&777Kr@   Fc                 6   t                                                      }|                     t          t                    } t          |           } t          |           } t          | t          t          t          t          f          rt          |           |z  S t          | t                    rAd}| j        D ](}||                    t          ||                    z  })t!          |          S t#          t          | |                    }t!          |          S )aW  
    Rule based algorithm for integration. Integrates the expression by applying
    transformation rules to the expression.

    Returns `Integrate` if an expression cannot be integrated.

    Parameters
    ==========
    expr : integrand expression
    var : variable of integration

    Returns Integral object if unable to integrate.
    r   )rB   rO   rm   rs   r   r   rx   rq   intr   floatr   r   r   rr   r   ro   util_rubi_integrate)rn   var	showstepsr=   resultsexs         r>   rubi_integrater      s     ""$$D<<**DDD$gue455 wws{$ /) 	7 	7Bt||HR$5$5666GG%g...!(4"5"566G!'***r@   
   c                    t                                                      t          |           } |                     t          t
                    } t          |          D ]&}|                     d fd          }| |k    r|c S '|S )Nc                 ,    t          | t                    S rM   )rq   r   )xs    r>   <lambda>z%util_rubi_integrate.<locals>.<lambda>   s    jH-- r@   c                 2                         | d          S )Nr   )	max_count)rm   )r   r=   s    r>   r   z%util_rubi_integrate.<locals>.<lambda>   s    dll1l33 r@   )rB   rO   r   rm   rs   r   range)rn   r~   max_looprw   r   r=   s        @r>   r|   r|      s    ""$$DD<<**D8__  ,,--3333
 
 7? 	NNN	Nr@   c                    t                      }|j        }|                    t          | |                    }|D ]\  }}t	          d           t	          t          j        |                     t          j        |          \  }}t	          d|           t	          d                    |                     t	          d           t          t          j        d|d                                       d                    }	t	          |j        |	dz
                      t	          |           t	                       dS )	z
    Prints the list or rules which match to `expr`.

    Parameters
    ==========
    expr : integrand expression
    var : variable of integration
    zRule matching: z	On line: 
zPattern matching: z^\s*rule(\d+)r      N)rB   matchermatchr   rD   inspectgetsourcefilegetsourcelinesjoinrz   regrouppatterns)
rn   r}   r=   r   miterfunecodelinenopattnos
             r>   get_matching_rule_definitionr      s    DlGMM(4--..E 
 
Q   g#C(()))-c22fk6"""diioo"###RX.Q88>>qAABBgvax()))a
 
r@   )F)Fr   ).sympy.externalr   sympy.utilities.decoratorr   
sympy.corer   r   sympy.core.addr   sympy.core.functionr   sympy.core.mulr	   sympy.core.numbersr
   sympy.core.powerr   sympy.core.singletonr   sympy.integrals.integralsr   sympy.functionsr   rs   r   r   sympy.simplify.powsimpr   r   r   r   %sympy.integrals.rubi.utility_functionr   r   r   !sympy.utilities.matchpy_connectorr   r   r?   rl   rB   ro   rx   r   r|   r   ri   r@   r>   <module>r      s   ( ( ( ( ( ( 8 8 8 8 8 8 % % % % % % % %       ( ( ( ( ( (                               " " " " " " . . . . . . * * * * * *  				 * * * * * *
-	
"
"
 =";;;;;;;;          BAAAAAAA---3 3 .-3h 
	q	!	!B1 1 1 1 1 1 1 1h L)))  *), L)))  *)4 L)))+ + + *)+< L)))   *) L)))  *)  r@   