§
    PŠtj  ã                   óô   — 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mZmZmZmZ d dlmZm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   G d„ de¦  «        Z! G d„ dee¦  «        Z"dS )é    )ÚSum)ÚBasic)ÚLambda)ÚDummy)ÚIntegral)ÚNamedArgsMixinÚrandom_symbolsÚ_symbol_converterÚPSpaceÚRandomSymbolÚ	is_randomÚDistribution)ÚContinuousDistributionÚSingleContinuousPSpace)ÚDiscreteDistributionÚSingleDiscretePSpace)ÚSingleFiniteDistributionÚSingleFinitePSpace)ÚContinuousDistributionHandmade)ÚDiscreteDistributionHandmade)ÚFiniteDistributionHandmadec                   ó$  — e Zd ZdZd„ Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ed„ ¦   «         Z
ed„ ¦   «         Zed	„ ¦   «         Zed
„ ¦   «         Zed„ ¦   «         Zdd„Zd„ Zddœd„Zddœd„Zdd„Zddœd„Zddœd„ZdS )ÚCompoundPSpacez²
    A temporary Probability Space for the Compound Distribution. After
    Marginalization, this returns the corresponding Probability Space of the
    parent distribution.
    c                 óx  — t          |¦  «        }t          |t          ¦  «        rt          ||¦  «        S t          |t          ¦  «        rt          ||¦  «        S t          |t          ¦  «        rt          ||¦  «        S t          |t          ¦  «        st          d|z  ¦  «        ‚t          j        | ||¦  «        S )Nz2%s should be an isinstance of CompoundDistribution)r
   Ú
isinstancer   r   r   r   r   r   ÚCompoundDistributionÚ
ValueErrorr   Ú__new__)ÚclsÚsÚdistributions      úU/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/stats/compound_rv.pyr   zCompoundPSpace.__new__   s¾   € Ý˜aÑ Ô ˆÝ�lÕ$:Ñ;Ô;ð 	;Ý)¨!¨\Ñ:Ô:Ð:Ý�lÕ$8Ñ9Ô9ð 	9Ý'¨¨<Ñ8Ô8Ð8Ý�lÕ$<Ñ=Ô=ð 	7Ý% a¨Ñ6Ô6Ð6Ý˜,Õ(<Ñ=Ô=ð 	?Ýð /Ø0<ñ>ñ ?ô ?ð ?åŒ}˜S ! \Ñ2Ô2Ð2ó    c                 ó,   — t          | j        | ¦  «        S ©N)r   Úsymbol©Úselfs    r"   ÚvaluezCompoundPSpace.value$   s   € å˜DœK¨Ñ.Ô.Ð.r#   c                 ó   — | j         d         S ©Nr   ©Úargsr'   s    r"   r&   zCompoundPSpace.symbol(   ó   € àŒy˜Œ|Ðr#   c                 ó   — | j         j        S r%   )r!   Úis_Continuousr'   s    r"   r0   zCompoundPSpace.is_Continuous,   s   € àÔ Ô.Ð.r#   c                 ó   — | j         j        S r%   )r!   Ú	is_Finiter'   s    r"   r2   zCompoundPSpace.is_Finite0   s   € àÔ Ô*Ð*r#   c                 ó   — | j         j        S r%   )r!   Úis_Discreter'   s    r"   r4   zCompoundPSpace.is_Discrete4   s   € àÔ Ô,Ð,r#   c                 ó   — | j         d         S )Né   r,   r'   s    r"   r!   zCompoundPSpace.distribution8   r.   r#   c                 ó@   — | j                              | j        ¦  «        S r%   )r!   Úpdfr&   r'   s    r"   r8   zCompoundPSpace.pdf<   s   € àÔ ×$Ò$ T¤[Ñ1Ô1Ð1r#   c                 ó   — | j         j        S r%   )r!   Úsetr'   s    r"   r:   zCompoundPSpace.set@   s   € àÔ Ô$Ð$r#   c                 ó4   — |                       ¦   «         j        S r%   )Ú_get_newpspaceÚdomainr'   s    r"   r=   zCompoundPSpace.domainD   s   € à×"Ò"Ñ$Ô$Ô+Ð+r#   Fc                 ó  — t          d¦  «        }| j        j        d         }t          || j                             ||¦  «        ¦  «        }|                      | j        ||¦  «        }|�|S dt          |¦  «        z  }t          |¦  «        ‚)NÚxr   ú3Compound Distribution for %s is not implemented yet)	r   r!   r-   r   r8   Ú_transform_pspacer&   ÚstrÚNotImplementedError)r(   Úevaluater?   Úparent_distÚfuncÚ
new_pspaceÚmessages          r"   r<   zCompoundPSpace._get_newpspaceH   s„   € Ý�#‰JŒJˆØÔ'Ô,¨QÔ/ˆÝ�a˜Ô*×.Ò.¨q°(Ñ;Ô;Ñ<Ô<ˆØ×+Ò+¨D¬K¸ÀdÑKÔKˆ
ØÐ!ØÐØHÍ3È{ÑK[ÔK[Ñ[ˆÝ! 'Ñ*Ô*Ð*r#   c                 ó”  ‡— t          | ‰|¦  «        ¦  «        Š|j        }t          |t          ¦  «        rt	          |t          ‰|¦  «        ¦  «        S t          |t          ¦  «        rt          |t          ‰|¦  «        ¦  «        S t          |t          ¦  «        r+ˆfd„|D ¦   «         }t          |t          |¦  «        ¦  «        S dS )z�
        This function returns the new pspace of the distribution using handmade
        Distributions and their corresponding pspace.
        c                 ó(   •— i | ]}| ‰|¦  «        “ŒS © rK   )Ú.0Úkr8   s     €r"   ú
<dictcomp>z4CompoundPSpace._transform_pspace.<locals>.<dictcomp>^   s#   ø€ Ð,Ð,Ð, !�A�s�s˜1‘v”vÐ,Ð,Ð,r#   N)r   r:   r   r   r   r   r   r   r   r   r   r   )r(   ÚsymÚdistr8   Ú_setÚdenss      `  r"   rA   z CompoundPSpace._transform_pspaceR   sÔ   ø€ õ
 �S˜#˜#˜c™(œ(Ñ#Ô#ˆØŒxˆÝ�dÕ2Ñ3Ô3ð 	MÝ)¨#Õ/MÈcÐSWÑ/XÔ/XÑYÔYÐYÝ˜Õ2Ñ3Ô3ð 	MÝ'¨Õ-IÈ#ÈtÑ-TÔ-TÑUÔUÐUÝ˜Õ6Ñ7Ô7ð 	MØ,Ð,Ð,Ð, tÐ,Ñ,Ô,ˆDÝ% cÕ+EÀdÑ+KÔ+KÑLÔLÐLð	Mð 	Mr#   T)Úcompound_evaluatec                óŠ   — |                       |¦  «        }|                     | j        |j        i¦  «        } |j        |fi |¤ŽS r%   )r<   Úsubsr)   Úcompute_density©r(   ÚexprrS   ÚkwargsrG   s        r"   rV   zCompoundPSpace.compute_densitya   sL   € Ø×(Ò(Ð):Ñ;Ô;ˆ
Ø�yŠy˜$œ* jÔ&6Ð7Ñ8Ô8ˆØ)ˆzÔ)¨$Ð9Ð9°&Ð9Ð9Ð9r#   c                óŠ   — |                       |¦  «        }|                     | j        |j        i¦  «        } |j        |fi |¤ŽS r%   )r<   rU   r)   Úcompute_cdfrW   s        r"   r[   zCompoundPSpace.compute_cdff   sL   € Ø×(Ò(Ð):Ñ;Ô;ˆ
Ø�yŠy˜$œ* jÔ&6Ð7Ñ8Ô8ˆØ%ˆzÔ% dÐ5Ð5¨fÐ5Ð5Ð5r#   Nc                 ó  — |                       |¦  «        }|                     | j        |j        i¦  «        }|r!|                     | j        |j        i¦  «        }t          |t          ¦  «        r |j        ||fi |¤ŽS  |j        |||fi |¤ŽS r%   )r<   rU   r)   r   r   Úcompute_expectation)r(   rX   ÚrvsrD   rY   rG   s         r"   r]   z"CompoundPSpace.compute_expectationk   s£   € Ø×(Ò(¨Ñ2Ô2ˆ
Ø�yŠy˜$œ* jÔ&6Ð7Ñ8Ô8ˆØð 	;Ø—(’(˜DœJ¨
Ô(8Ð9Ñ:Ô:ˆCÝ�jÕ"4Ñ5Ô5ð 	GØ1�:Ô1°$¸ÐFÐF¸vÐFÐFÐFØ-ˆzÔ-¨d°C¸ÐLÐLÀVÐLÐLÐLr#   c                ó˜   — |                       |¦  «        }|                     | j        |j        i¦  «        }|                     |¦  «        S r%   )r<   rU   r)   Úprobability©r(   Ú	conditionrS   rY   rG   s        r"   r`   zCompoundPSpace.probabilityt   sE   € Ø×(Ò(Ð):Ñ;Ô;ˆ
Ø—N’N D¤J°
Ô0@Ð#AÑBÔBˆ	Ø×%Ò% iÑ0Ô0Ð0r#   c                ó˜   — |                       |¦  «        }|                     | j        |j        i¦  «        }|                     |¦  «        S r%   )r<   rU   r)   Úconditional_spacera   s        r"   rd   z CompoundPSpace.conditional_spacey   sE   € Ø×(Ò(Ð):Ñ;Ô;ˆ
Ø—N’N D¤J°
Ô0@Ð#AÑBÔBˆ	Ø×+Ò+¨IÑ6Ô6Ð6r#   ©F)NF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr)   r&   r0   r2   r4   r!   r8   r:   r=   r<   rA   rV   r[   r]   r`   rd   rK   r#   r"   r   r      sØ  € € € € € ðð ð3ð 3ð 3ð ð/ð /ñ „Xð/ð ðð ñ „Xðð ð/ð /ñ „Xð/ð ð+ð +ñ „Xð+ð ð-ð -ñ „Xð-ð ðð ñ „Xðð ð2ð 2ñ „Xð2ð ð%ð %ñ „Xð%ð ð,ð ,ñ „Xð,ð+ð +ð +ð +ðMð Mð Mð :>ð :ð :ð :ð :ð :ð
 6:ð 6ð 6ð 6ð 6ð 6ð
Mð Mð Mð Mð ;?ð 1ð 1ð 1ð 1ð 1ð
 AEð 7ð 7ð 7ð 7ð 7ð 7ð 7r#   r   c                   ó”   — e Zd ZdZd„ Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	dd„Z
d	„ Zed
„ ¦   «         ZdS )r   aÈ  
    Class for Compound Distributions.

    Parameters
    ==========

    dist : Distribution
        Distribution must contain a random parameter

    Examples
    ========

    >>> from sympy.stats.compound_rv import CompoundDistribution
    >>> from sympy.stats.crv_types import NormalDistribution
    >>> from sympy.stats import Normal
    >>> from sympy.abc import x
    >>> X = Normal('X', 2, 4)
    >>> N = NormalDistribution(X, 4)
    >>> C = CompoundDistribution(N)
    >>> C.set
    Interval(-oo, oo)
    >>> C.pdf(x, evaluate=True).simplify()
    exp(-x**2/64 + x/16 - 1/16)/(8*sqrt(pi))

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Compound_probability_distribution

    c                 óà   — t          |t          t          t          f¦  «        s!dt	          |¦  «        z  }t          |¦  «        ‚|                      |¦  «        s|S t          j        | |¦  «        S )Nr@   )	r   r   r   r   rB   rC   Ú_compound_checkr   r   )r   rP   rH   s      r"   r   zCompoundDistribution.__new__Ÿ   ss   € Ý˜$Õ!7Ý(Õ*>ð!@ñ Aô Að 	/àKÍcÐRVÉiÌiÑWˆGÝ% gÑ.Ô.Ð.Ø×"Ò" 4Ñ(Ô(ð 	ØˆKÝŒ}˜S $Ñ'Ô'Ð'r#   c                 ó&   — | j         d         j        S r+   )r-   r:   r'   s    r"   r:   zCompoundDistribution.set¨   s   € àŒy˜Œ|ÔÐr#   c                 óB   — t          | j        d         t          ¦  «        S r+   )r   r-   r   r'   s    r"   r0   z"CompoundDistribution.is_Continuous¬   s   € å˜$œ) Aœ,Õ(>Ñ?Ô?Ð?r#   c                 óB   — t          | j        d         t          ¦  «        S r+   )r   r-   r   r'   s    r"   r2   zCompoundDistribution.is_Finite°   s   € å˜$œ) Aœ,Õ(@ÑAÔAÐAr#   c                 óB   — t          | j        d         t          ¦  «        S r+   )r   r-   r   r'   s    r"   r4   z CompoundDistribution.is_Discrete´   s   € å˜$œ) Aœ,Õ(<Ñ=Ô=Ð=r#   Fc                 ój  — | j         d         }d„ |j         D ¦   «         }t          |t          ¦  «        r(t          ddd¬¦  «        }|                     |¦  «        }n$t          d¦  «        }|                     |¦  «        }|D ]}|                      |||¦  «        }Œ t          ||¦  «        |¦  «        S )Nr   c                 ó0   — g | ]}t          |¦  «        ¯|‘ŒS rK   )r   )rL   Úrvs     r"   ú
<listcomp>z,CompoundDistribution.pdf.<locals>.<listcomp>º   s#   € Ð;Ð;Ð;˜"­Y°r©]¬]Ð;�2Ð;Ð;Ð;r#   ÚyTF)ÚintegerÚnegative)r-   r   r   r   Úpmfr8   Ú_marginaliser   )r(   r?   rD   rP   Úrandomsrv   rX   rt   s           r"   r8   zCompoundDistribution.pdf¸   s´   € ØŒy˜Œ|ˆØ;Ð; ¤	Ð;Ñ;Ô;ˆÝ�dÕ4Ñ5Ô5ð 	Ý�c 4°%Ð8Ñ8Ô8ˆAØ—8’8˜A‘;”;ˆDˆDå�c‘
”
ˆAØ—8’8˜A‘;”;ˆDØð 	9ð 	9ˆBØ×$Ò$ T¨2¨xÑ8Ô8ˆDˆDØ�v�a˜‰Œ˜qÑ!Ô!Ð!r#   c                 óÂ  — t          |j        j        t          ¦  «        r |j        j                             |¦  «        }n|j        j                             |¦  «        }|j        j        j        }|j        j        s|j        j	        r!t          ||z  ||j        |j        f¦  «        }n t          ||z  ||j        |j        f¦  «        }|r|                     ¦   «         S |S r%   )r   Úpspacer!   r   ry   r8   r=   r:   r4   r2   r   Ú_infÚ_supr   Údoit)r(   rX   rt   rD   Úrv_densÚrv_doms         r"   rz   z!CompoundDistribution._marginaliseÅ   sÛ   € Ý�b”iÔ,Õ.FÑGÔGð 	5Ø”iÔ,×0Ò0°Ñ4Ô4ˆGˆGà”iÔ,×0Ò0°Ñ4Ô4ˆGØ”Ô!Ô%ˆØŒ9Ô ð 	" B¤IÔ$7ð 	"Ý�t˜G‘| b¨&¬+Ø”Kð&!ñ "ô "ˆDˆDõ ˜D ™L¨2¨v¬{Ø”Kð+!ñ "ô "ˆDàð 	Ø—9’9‘;”;ÐØˆr#   c                 óŒ   — g }|j         D ]$}|                     t          |¦  «        ¦  «         Œ%t          |¦  «        dk    rdS dS )zN
        Checks if the given distribution contains random parameters.
        r   FT)r-   Úextendr	   Úlen)r(   rP   r{   Úargs       r"   rm   z$CompoundDistribution._compound_checkÕ   sR   € ð
 ˆØ”9ð 	0ð 	0ˆCØ�NŠN�>¨#Ñ.Ô.Ñ/Ô/Ð/Ð/Ýˆw‰<Œ<˜1ÒÐØ�5Øˆtr#   Nre   )rf   rg   rh   ri   r   rj   r:   r0   r2   r4   r8   rz   Úclassmethodrm   rK   r#   r"   r   r      sÝ   € € € € € ðð ð>(ð (ð (ð ð ð  ñ „Xð ð ð@ð @ñ „Xð@ð ðBð Bñ „XðBð ð>ð >ñ „Xð>ð"ð "ð "ð "ðð ð ð  ð	ð 	ñ „[ð	ð 	ð 	r#   r   N)#Úsympy.concrete.summationsr   Úsympy.core.basicr   Úsympy.core.functionr   Úsympy.core.symbolr   Úsympy.integrals.integralsr   Úsympy.stats.rvr   r	   r
   r   r   r   r   Úsympy.stats.crvr   r   Úsympy.stats.drvr   r   Úsympy.stats.frvr   r   Úsympy.stats.crv_typesr   Úsympy.stats.drv_typesr   Úsympy.stats.frv_typesr   r   r   rK   r#   r"   ú<module>r”      s¼  ðØ )Ð )Ð )Ð )Ð )Ð )Ø "Ð "Ð "Ð "Ð "Ð "Ø &Ð &Ð &Ð &Ð &Ð &Ø #Ð #Ð #Ð #Ð #Ð #Ø .Ð .Ð .Ð .Ð .Ð .ðGð Gð Gð Gð Gð Gð Gð Gð Gð Gð Gð Gð Gð Gð Gð Gð Gð Gà JÐ JÐ JÐ JÐ JÐ JÐ JÐ JØ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FØ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HØ @Ð @Ð @Ð @Ð @Ð @Ø >Ð >Ð >Ð >Ð >Ð >Ø <Ð <Ð <Ð <Ð <Ð <ðl7ð l7ð l7ð l7ð l7�Vñ l7ô l7ð l7ð^`ð `ð `ð `ð `˜<¨ñ `ô `ð `ð `ð `r#   