U
    —9%eÔ$  ã                   @   sÞ  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
 d dl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	„ Zd
d„ Zdd„ ZG dd„ dƒZeƒ Ze
dƒZe e¡dd„ ƒZe e¡dd„ ƒZe e¡dd„ ƒZe e¡dd„ ƒZe e¡dd„ ƒZe e¡dd„ ƒZe e¡dd„ ƒZe e¡dd„ ƒZe e¡dd„ ƒZe e¡dd„ ƒZejdd„ ej dd„ ej!dd„ ej"d d„ ej#d!d„ ej$d"d„ ej%d#d„ ej&d$d„ ej'd%d„ ej(d&d„ i
Z)e ee	e¡d'd„ ƒZd(S ))é    )Údefaultdict)ÚQ)ÚAddÚMulÚPowÚNumberÚNumberSymbolÚSymbol)ÚImaginaryUnit)ÚAbs)Ú
EquivalentÚAndÚOrÚImplies)ÚMatMulc                    s   t ‡ ‡fdd„|jD ƒŽ S )aú  
    Apply all arguments of the expression to the fact structure.

    Parameters
    ==========

    symbol : Symbol
        A placeholder symbol.

    fact : Boolean
        Resulting ``Boolean`` expression.

    expr : Expr

    Examples
    ========

    >>> from sympy import Q
    >>> from sympy.assumptions.sathandlers import allargs
    >>> from sympy.abc import x, y
    >>> allargs(x, Q.negative(x) | Q.positive(x), x*y)
    (Q.negative(x) | Q.positive(x)) & (Q.negative(y) | Q.positive(y))

    c                    s   g | ]}ˆ   ˆ|¡‘qS © ©Úsubs©Ú.0Úarg©ÚfactÚsymbolr   ú\/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/assumptions/sathandlers.pyÚ
<listcomp>(   s     zallargs.<locals>.<listcomp>)r   Úargs©r   r   Úexprr   r   r   Úallargs   s    r   c                    s   t ‡ ‡fdd„|jD ƒŽ S )a÷  
    Apply any argument of the expression to the fact structure.

    Parameters
    ==========

    symbol : Symbol
        A placeholder symbol.

    fact : Boolean
        Resulting ``Boolean`` expression.

    expr : Expr

    Examples
    ========

    >>> from sympy import Q
    >>> from sympy.assumptions.sathandlers import anyarg
    >>> from sympy.abc import x, y
    >>> anyarg(x, Q.negative(x) & Q.positive(x), x*y)
    (Q.negative(x) & Q.positive(x)) | (Q.negative(y) & Q.positive(y))

    c                    s   g | ]}ˆ   ˆ|¡‘qS r   r   r   r   r   r   r   D   s     zanyarg.<locals>.<listcomp>)r   r   r   r   r   r   Úanyarg+   s    r    c                    s8   ‡ ‡fdd„|j D ƒ‰t‡fdd„ttˆƒƒD ƒŽ }|S )aÿ  
    Apply exactly one argument of the expression to the fact structure.

    Parameters
    ==========

    symbol : Symbol
        A placeholder symbol.

    fact : Boolean
        Resulting ``Boolean`` expression.

    expr : Expr

    Examples
    ========

    >>> from sympy import Q
    >>> from sympy.assumptions.sathandlers import exactlyonearg
    >>> from sympy.abc import x, y
    >>> exactlyonearg(x, Q.positive(x), x*y)
    (Q.positive(x) & ~Q.positive(y)) | (Q.positive(y) & ~Q.positive(x))

    c                    s   g | ]}ˆ   ˆ|¡‘qS r   r   r   r   r   r   r   `   s     z!exactlyonearg.<locals>.<listcomp>c              	      s@   g | ]8}t ˆ | fd d„ ˆ d|… ˆ |d d…  D ƒžŽ ‘qS )c                 S   s   g | ]
}| ‘qS r   r   )r   Zlitr   r   r   r   a   s     z,exactlyonearg.<locals>.<listcomp>.<listcomp>Né   )r   )r   Úi)Ú	pred_argsr   r   r   a   s   ÿÿ)r   r   ÚrangeÚlen)r   r   r   Úresr   )r   r#   r   r   ÚexactlyoneargG   s
    
ÿr'   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚClassFactRegistrya¦  
    Register handlers against classes.

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

    ``register`` method registers the handler function for a class. Here,
    handler function should return a single fact. ``multiregister`` method
    registers the handler function for multiple classes. Here, handler function
    should return a container of multiple facts.

    ``registry(expr)`` returns a set of facts for *expr*.

    Examples
    ========

    Here, we register the facts for ``Abs``.

    >>> from sympy import Abs, Equivalent, Q
    >>> from sympy.assumptions.sathandlers import ClassFactRegistry
    >>> reg = ClassFactRegistry()
    >>> @reg.register(Abs)
    ... def f1(expr):
    ...     return Q.nonnegative(expr)
    >>> @reg.register(Abs)
    ... def f2(expr):
    ...     arg = expr.args[0]
    ...     return Equivalent(~Q.zero(arg), ~Q.zero(expr))

    Calling the registry with expression returns the defined facts for the
    expression.

    >>> from sympy.abc import x
    >>> reg(Abs(x))
    {Q.nonnegative(Abs(x)), Equivalent(~Q.zero(x), ~Q.zero(Abs(x)))}

    Multiple facts can be registered at once by ``multiregister`` method.

    >>> reg2 = ClassFactRegistry()
    >>> @reg2.multiregister(Abs)
    ... def _(expr):
    ...     arg = expr.args[0]
    ...     return [Q.even(arg) >> Q.even(expr), Q.odd(arg) >> Q.odd(expr)]
    >>> reg2(Abs(x))
    {Implies(Q.even(x), Q.even(Abs(x))), Implies(Q.odd(x), Q.odd(Abs(x)))}

    c                 C   s   t tƒ| _t tƒ| _d S ©N)r   Ú	frozensetÚsinglefactsÚ
multifacts)Úselfr   r   r   Ú__init__˜   s    
zClassFactRegistry.__init__c                    s   ‡ ‡fdd„}|S )Nc                    s   ˆj ˆ   | hO  < | S r)   )r+   )Úfunc©Úclsr-   r   r   Ú_   s    z%ClassFactRegistry.register.<locals>._r   )r-   r1   r2   r   r0   r   Úregisterœ   s    zClassFactRegistry.registerc                    s   ‡ ‡fdd„}|S )Nc                    s"   ˆ D ]}ˆj |  | hO  < q| S r)   )r,   )r/   r1   ©Úclassesr-   r   r   r2   £   s    z*ClassFactRegistry.multiregister.<locals>._r   )r-   r5   r2   r   r4   r   Úmultiregister¢   s    zClassFactRegistry.multiregisterc                 C   sd   | j | }| j D ]}t||ƒr|| j | O }q| j| }| jD ]}t||ƒr>|| j| O }q>||fS r)   )r+   Ú
issubclassr,   )r-   ÚkeyZret1ÚkZret2r   r   r   Ú__getitem__©   s    





zClassFactRegistry.__getitem__c                 C   sJ   t ƒ }| t|ƒ \}}|D ]}| ||ƒ¡ q|D ]}| ||ƒ¡ q2|S r)   )ÚsetÚtypeÚaddÚupdate)r-   r   ÚretZ	handlers1Z	handlers2Úhr   r   r   Ú__call__¶   s    zClassFactRegistry.__call__N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r.   r3   r6   r:   rA   r   r   r   r   r(   h   s   /r(   Úxc                 C   sd   | j d }t | ¡tt |¡ t | ¡ ƒt |¡t | ¡? t |¡t | ¡? t |¡t | ¡? gS )Nr   )r   r   Únonnegativer   ÚzeroÚevenÚoddÚinteger)r   r   r   r   r   r2   Ë   s    
ür2   c              
   C   s¤   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 | ¡ ? gS r)   )	r   rF   r   ÚpositiveÚnegativeÚrealÚrationalrK   r'   ©r   r   r   r   r2   Ø   s    ûc                 C   s:   t tt t¡| ƒ}ttt t¡| ƒ}t|t|t | ¡ƒƒS r)   ©r   rF   r   rN   r'   Ú
irrationalr   ©r   Zallargs_realZonearg_irrationalr   r   r   r2   â   s    c                 C   sÀ   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 | ¡? gS r)   )r   r   rH   r    rF   r   rL   rN   rO   rK   r'   ZcommutativerP   r   r   r   r2   ë   s    úc                 C   s$   t tt t¡| ƒ}t|t | ¡ ƒS r)   )r   rF   r   Úprimer   )r   Zallargs_primer   r   r   r2   ö   s    c                 C   sD   t tt t¡t t¡B | ƒ}ttt t¡| ƒ}t|t|t | ¡ƒƒS r)   )r   rF   r   Ú	imaginaryrN   r'   r   )r   Zallargs_imag_or_realZonearg_imaginaryr   r   r   r2   ÿ   s    c                 C   s:   t tt t¡| ƒ}ttt t¡| ƒ}t|t|t | ¡ƒƒS r)   rQ   rS   r   r   r   r2     s    c                 C   s:   t tt t¡| ƒ}ttt t¡| ƒ}t|t|t | ¡ƒƒS r)   )r   rF   r   rK   r    rI   r   r   )r   Zallargs_integerZanyarg_evenr   r   r   r2     s    c                 C   s:   t tt t¡| ƒ}t tt t¡| ƒ}t|tt | ¡|ƒƒS r)   )r   rF   r   ZsquareZ
invertibler   r   )r   Zallargs_squareZallargs_invertibler   r   r   r2     s    c              	   C   s¢   | j | j }}t |¡t |¡@ t |¡@ t | ¡? t |¡t |¡@ t |¡@ t | ¡? t |¡t |¡@ t |¡@ t | ¡? tt 	| ¡t 	|¡t 
|¡@ ƒgS r)   )ÚbaseÚexpr   rN   rI   rG   rJ   Únonpositiver   rH   rL   )r   rV   rW   r   r   r   r2   !  s    &&&üc                 C   s   | j S r)   )Zis_positive©Úor   r   r   Ú<lambda>/  ó    r[   c                 C   s   | j S r)   )Úis_zerorY   r   r   r   r[   0  r\   c                 C   s   | j S r)   )Zis_negativerY   r   r   r   r[   1  r\   c                 C   s   | j S r)   )Zis_rationalrY   r   r   r   r[   2  r\   c                 C   s   | j S r)   )Zis_irrationalrY   r   r   r   r[   3  r\   c                 C   s   | j S r)   )Zis_evenrY   r   r   r   r[   4  r\   c                 C   s   | j S r)   )Zis_oddrY   r   r   r   r[   5  r\   c                 C   s   | j S r)   )Zis_imaginaryrY   r   r   r   r[   6  r\   c                 C   s   | j S r)   )Zis_primerY   r   r   r   r[   7  r\   c                 C   s   | j S r)   )Zis_compositerY   r   r   r   r[   8  r\   c                 C   sB   g }t  ¡ D ]0\}}|| ƒ}|| ƒ}|d k	r| t||ƒ¡ q|S r)   )Ú_old_assump_gettersÚitemsÚappendr   )r   r?   ÚpÚgetterÚpredÚpropr   r   r   r2   ;  s    N)*Úcollectionsr   Zsympy.assumptions.askr   Z
sympy.corer   r   r   r   r   r	   Zsympy.core.numbersr
   Z$sympy.functions.elementary.complexesr   Zsympy.logic.boolalgr   r   r   r   Zsympy.matrices.expressionsr   r   r    r'   r(   Zclass_fact_registryrF   r6   r2   r3   rL   rH   rM   rO   rR   rI   rJ   rU   rT   Z	compositer^   r   r   r   r   Ú<module>   sn    !Y

	








          ö