a
    <bd                      @   sn  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rd 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dd Z&e!eZ'G dd dZ(edddd Z)edddd Z*eddd$ddZ+eddd%d d!Z,edd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                  C   s  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 }||  7 }|| 7 }|| 7 }|| 7 }|| 7 }|| 7 }|| 7 }|| 7 }|| 7 }|| 7 }||	 7 }||
 7 }|| 7 }|| 7 }|| 7 }|| 7 }|| 7 }t"| }||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)#Z3sympy.integrals.rubi.rules.integrand_simplificationr   Z*sympy.integrals.rubi.rules.linear_productsr   Z-sympy.integrals.rubi.rules.quadratic_productsr   Z,sympy.integrals.rubi.rules.binomial_productsr   Z-sympy.integrals.rubi.rules.trinomial_productsr   Z2sympy.integrals.rubi.rules.miscellaneous_algebraicr   Z&sympy.integrals.rubi.rules.exponentialr   Z%sympy.integrals.rubi.rules.logarithmsr   Zsympy.integrals.rubi.rules.siner    Z"sympy.integrals.rubi.rules.tangentr!   Z!sympy.integrals.rubi.rules.secantr"   Z-sympy.integrals.rubi.rules.miscellaneous_trigr#   Z'sympy.integrals.rubi.rules.inverse_trigr$   Z%sympy.integrals.rubi.rules.hyperbolicr%   Z-sympy.integrals.rubi.rules.inverse_hyperbolicr&   Z,sympy.integrals.rubi.rules.special_functionsr'   Z4sympy.integrals.rubi.rules.miscellaneous_integrationr(   r   )r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   rulesrubi r+   m/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/sympy/integrals/rubi/rubimain.pyget_rubi_object   sJ    

















r-   c                   @   sD   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dS )LoadRubiReplacerz-
    Class trick to load RUBI only once.
    Nc                 C   sD   t d u rtd d S tjd ur$tjS t| }d |_d |_|t_|S )NzMatchPy library not found)r   printr.   	_instanceobject__new___rubi_rules)clsobjr+   r+   r,   r2   X   s    

zLoadRubiReplacer.__new__c                 C   s*   | j d ur| j S t \}}|| _ || _|S N)r3   r-   r4   )selfr*   r)   r+   r+   r,   loadd   s    

zLoadRubiReplacer.loadc                 C   sJ   dd l }|  }t|d}||| W d    n1 s<0    Y  d S Nr   wb)pickler9   opendump)r8   filenamer<   r*   foutr+   r+   r,   	to_picklel   s    zLoadRubiReplacer.to_picklec                 C   sJ   dd l }|  }t|d}||| W d    n1 s<0    Y  d S r:   )dillr9   r=   r>   )r8   r?   rB   r*   r@   r+   r+   r,   to_dillr   s    zLoadRubiReplacer.to_dillc                 C   sD   dd l }t|d}||| _W d    n1 s40    Y  | jS Nr   rb)r<   r=   r9   r3   )r8   r?   r<   finr+   r+   r,   from_picklex   s    *zLoadRubiReplacer.from_picklec                 C   sD   dd l }t|d}||| _W d    n1 s40    Y  | jS rD   )rB   r=   r9   r3   )r8   r?   rB   rF   r+   r+   r,   	from_dill~   s    *zLoadRubiReplacer.from_dill)__name__
__module____qualname____doc__r0   r2   r9   rA   rC   rG   rH   r+   r+   r+   r,   r.   Q   s   r.   c                 C   s   |  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)

    )Zhas_Ereplacer	   )exprr+   r+   r,   process_final_integral   s    
rP   c                 C   s\   g }g }t | trX| jD ]*}t |tttfr8|| q|| qtt| t|  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   )rO   Zlst_powZlst_non_powir+   r+   r,   rubi_powsimp   s    

rV   Fc                 C   s   t   }| tt} t| } t| } t| tt	t
tfrDt| | S t| trzd}| jD ]}||t||7 }qXt|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   )r.   r9   rN   rS   r   r   rV   rQ   intr   floatr   r   r   rR   r   rP   util_rubi_integrate)rO   var	showstepsr*   resultsexr+   r+   r,   rubi_integrate   s    


r^   
   c                    sX   t    t| } | tt} t|D ],}| dd  fdd}| |kr&|  S q&|S )Nc                 S   s
   t | tS r7   )rQ   r   xr+   r+   r,   <lambda>       z%util_rubi_integrate.<locals>.<lambda>c                    s    j | ddS )Nr_   )	max_count)rN   r`   r*   r+   r,   rb      rc   )r.   r9   r   rN   rS   r   range)rO   r[   Zmax_looprU   r\   r+   re   r,   rY      s    


rY   c           
      C   s   t  }|j}|t| |}|D ]\}}td tt| t|\}}td| td| td t	t
d|d d}	t|j|	d   t| t  q 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)r.   matchermatchr   r/   inspectgetsourcefilegetsourcelinesjoinrW   regrouppatterns)
rO   rZ   r*   ri   ZmiterZfunecodelinenoZpattnor+   r+   r,   get_matching_rule_definition   s    

ru   )F)Fr_   ).Zsympy.externalr   Zsympy.utilities.decoratorr   Z
sympy.corer   r   Zsympy.core.addr   Zsympy.core.functionr   Zsympy.core.mulr   Zsympy.core.numbersr	   Zsympy.core.powerr
   Zsympy.core.singletonr   Zsympy.integrals.integralsr   Zsympy.functionsr   rS   rk   ro   Zsympy.simplify.powsimpr   r   r   r   Z%sympy.integrals.rubi.utility_functionr   r   r   Z!sympy.utilities.matchpy_connectorr   r   r-   rM   r.   rP   rV   r^   rY   ru   r+   r+   r+   r,   <module>   s@   
44

