Ë
    7^(h  ã                   óæ   — 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"y)é    )Ú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y)ÚCompoundPSpacez²
    A temporary Probability Space for the Compound Distribution. After
    Marginalization, this returns the corresponding Probability Space of the
    parent distribution.
    c                 ó*  — 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/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/stats/compound_rv.pyr   zCompoundPSpace.__new__   sŒ   € Ü˜aÓ ˆÜ�lÔ$:Ô;Ü)¨!¨\Ó:Ð:Ü�lÔ$8Ô9Ü'¨¨<Ó8Ð8Ü�lÔ$<Ô=Ü% a¨Ó6Ð6Ü˜,Ô(<Ô=Üð /Ø0<ñ>ó ?ð ?ä�}‰}˜S ! \Ó2Ð2ó    c                 ó.   — t        | j                  | «      S ©N)r   Úsymbol©Úselfs    r"   ÚvaluezCompoundPSpace.value$   s   € ä˜DŸK™K¨Ó.Ð.r#   c                 ó    — | j                   d   S ©Nr   ©Úargsr'   s    r"   r&   zCompoundPSpace.symbol(   ó   € à�y‰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                 óL   — | j                   j                  | j                  «      S r%   )r!   Úpdfr&   r'   s    r"   r8   zCompoundPSpace.pdf<   s   € à× Ñ ×$Ñ$ T§[¡[Ó1Ð1r#   c                 ó.   — | j                   j                  S r%   )r!   Úsetr'   s    r"   r:   zCompoundPSpace.set@   s   € à× Ñ ×$Ñ$Ð$r#   c                 ó6   — | j                  «       j                  S r%   )Ú_get_newpspaceÚdomainr'   s    r"   r=   zCompoundPSpace.domainD   s   € à×"Ñ"Ó$×+Ñ+Ð+r#   c                 ó
  — t        d«      }| j                  j                  d   }t        || j                  j	                  ||«      «      }| 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ˆØ×'Ñ'×,Ñ,¨QÑ/ˆÜ�a˜×*Ñ*×.Ñ.¨q°(Ó;Ó<ˆØ×+Ñ+¨D¯K©K¸ÀdÓKˆ
ØÐ!ØÐØHÌ3È{ÓK[Ñ[ˆÜ! 'Ó*Ð*r#   c                 óX  — t        | ||«      «      }|j                  }t        |t        «      rt	        |t        ||«      «      S t        |t        «      rt        |t        ||«      «      S t        |t        «      r+|D �ci c]  }| ||«      “Œ }}t        |t        |«      «      S yc c}w )z�
        This function returns the new pspace of the distribution using handmade
        Distributions and their corresponding pspace.
        N)r   r:   r   r   r   r   r   r   r   r   r   r   )r(   ÚsymÚdistr8   Ú_setÚkÚdenss          r"   rA   z CompoundPSpace._transform_pspaceR   sŸ   € ô
 �S™#˜c›(Ó#ˆØ�x‰xˆÜ�dÔ2Ô3Ü)¨#Ô/MÈcÐSWÓ/XÓYÐYÜ˜Ô2Ô3Ü'¨Ô-IÈ#ÈtÓ-TÓUÐUÜ˜Ô6Ô7Ø'+Ö, !�A‘s˜1“v‘IÐ,ˆDÐ,Ü% cÔ+EÀdÓ+KÓLÐLð 8ùÚ,s   Á?B'T)Úcompound_evaluatec                ó˜   — | j                  |«      }|j                  | j                  |j                  i«      } |j                  |fi |¤ŽS r%   )r<   Úsubsr)   Úcompute_density©r(   ÚexprrO   ÚkwargsrG   s        r"   rR   zCompoundPSpace.compute_densitya   sH   € Ø×(Ñ(Ð):Ó;ˆ
Ø�y‰y˜$Ÿ*™* j×&6Ñ&6Ð7Ó8ˆØ)ˆz×)Ñ)¨$Ñ9°&Ñ9Ð9r#   c                ó˜   — | j                  |«      }|j                  | j                  |j                  i«      } |j                  |fi |¤ŽS r%   )r<   rQ   r)   Úcompute_cdfrS   s        r"   rW   zCompoundPSpace.compute_cdff   sH   € Ø×(Ñ(Ð):Ó;ˆ
Ø�y‰y˜$Ÿ*™* j×&6Ñ&6Ð7Ó8ˆØ%ˆz×%Ñ% dÑ5¨fÑ5Ð5r#   Nc                 ó6  — | j                  |«      }|j                  | j                  |j                  i«      }|r'|j                  | j                  |j                  i«      }t        |t        «      r |j
                  ||fi |¤ŽS  |j
                  |||fi |¤ŽS r%   )r<   rQ   r)   r   r   Úcompute_expectation)r(   rT   ÚrvsrD   rU   rG   s         r"   rY   z"CompoundPSpace.compute_expectationk   s�   € Ø×(Ñ(¨Ó2ˆ
Ø�y‰y˜$Ÿ*™* j×&6Ñ&6Ð7Ó8ˆÙØ—(‘(˜DŸJ™J¨
×(8Ñ(8Ð9Ó:ˆCÜ�jÔ"4Ô5Ø1�:×1Ñ1°$¸ÑF¸vÑFÐFØ-ˆz×-Ñ-¨d°C¸ÑLÀVÑLÐLr#   c                ó”   — | j                  |«      }|j                  | j                  |j                  i«      }|j                  |«      S r%   )r<   rQ   r)   Úprobability©r(   Ú	conditionrO   rU   rG   s        r"   r\   zCompoundPSpace.probabilityt   sA   € Ø×(Ñ(Ð):Ó;ˆ
Ø—N‘N D§J¡J°
×0@Ñ0@Ð#AÓBˆ	Ø×%Ñ% iÓ0Ð0r#   c                ó”   — | j                  |«      }|j                  | j                  |j                  i«      }|j                  |«      S r%   )r<   rQ   r)   Úconditional_spacer]   s        r"   r`   z CompoundPSpace.conditional_spacey   sA   € Ø×(Ñ(Ð):Ó;ˆ
Ø—N‘N D§J¡J°
×0@Ñ0@Ð#AÓBˆ	Ø×+Ñ+¨IÓ6Ð6r#   ©F)NF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr)   r&   r0   r2   r4   r!   r8   r:   r=   r<   rA   rR   rW   rY   r\   r`   © r#   r"   r   r      sû   „ ñò3ð ñ/ó ð/ð ñó ðð ñ/ó ð/ð ñ+ó ð+ð ñ-ó ð-ð ñó ðð ñ2ó ð2ð ñ%ó ð%ð ñ,ó ð,ó+òMð :>ô :ð
 6:ô 6ó
Mð ;?ô 1ð
 AEõ 7r#   r   c                   ót   — 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y
)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        |«      ‚| j                  |«      s|S t        j                  | |«      S )Nr@   )	r   r   r   r   rB   rC   Ú_compound_checkr   r   )r   rK   rH   s      r"   r   zCompoundDistribution.__new__Ÿ   sZ   € Ü˜$Ô!7Ü(Ô*>ð!@ô AàKÌcÐRVËiÑWˆGÜ% gÓ.Ð.Ø×"Ñ" 4Ô(ØˆKÜ�}‰}˜S $Ó'Ð'r#   c                 ó4   — | j                   d   j                  S r+   )r-   r:   r'   s    r"   r:   zCompoundDistribution.set¨   s   € à�y‰y˜‰|×ÑÐr#   c                 ó<   — t        | j                  d   t        «      S r+   )r   r-   r   r'   s    r"   r0   z"CompoundDistribution.is_Continuous¬   s   € ä˜$Ÿ)™) A™,Ô(>Ó?Ð?r#   c                 ó<   — t        | j                  d   t        «      S r+   )r   r-   r   r'   s    r"   r2   zCompoundDistribution.is_Finite°   s   € ä˜$Ÿ)™) A™,Ô(@ÓAÐAr#   c                 ó<   — t        | j                  d   t        «      S r+   )r   r-   r   r'   s    r"   r4   z CompoundDistribution.is_Discrete´   s   € ä˜$Ÿ)™) A™,Ô(<Ó=Ð=r#   c                 ód  — | j                   d   }|j                   D �cg c]  }t        |«      sŒ|‘Œ }}t        |t        «      r t	        ddd¬«      }|j                  |«      }nt	        d«      }|j                  |«      }|D ]  }| j                  |||«      }Œ  t        ||«      |«      S c c}w )Nr   ÚyTF)ÚintegerÚnegative)	r-   r   r   r   r   Úpmfr8   Ú_marginaliser   )r(   r?   rD   rK   ÚrvÚrandomsrp   rT   s           r"   r8   zCompoundDistribution.pdf¸   s£   € Ø�y‰y˜‰|ˆØ $§	¡	Ö;˜"¬Y°r­]’2Ð;ˆÐ;Ü�dÔ4Ô5Ü�c 4°%Ô8ˆAØ—8‘8˜A“;‰Dä�c“
ˆAØ—8‘8˜A“;ˆDØò 	9ˆBØ×$Ñ$ T¨2¨xÓ8‰Dð	9àŒv�a˜‹˜qÓ!Ð!ùò <s
   žB-¯B-c                 ó:  — t        |j                  j                  t        «      r&|j                  j                  j	                  |«      }n%|j                  j                  j                  |«      }|j                  j                  j                  }|j                  j                  s|j                  j                  r't        ||z  ||j                  |j                  f«      }n&t        ||z  ||j                  |j                  f«      }|r|j                  «       S |S r%   )r   Úpspacer!   r   rs   r8   r=   r:   r4   r2   r   Ú_infÚ_supr   Údoit)r(   rT   ru   rD   Úrv_densÚrv_doms         r"   rt   z!CompoundDistribution._marginaliseÅ   s×   € Ü�b—i‘i×,Ñ,Ô.FÔGØ—i‘i×,Ñ,×0Ñ0°Ó4‰Gà—i‘i×,Ñ,×0Ñ0°Ó4ˆGØ—‘×!Ñ!×%Ñ%ˆØ�9‰9× Ò  B§I¡I×$7Ò$7Ü�t˜G‘| b¨&¯+©+Ø—K‘Kð&!ó "‰Dô ˜D ™L¨2¨v¯{©{Ø—K‘Kð+!ó "ˆDáØ—9‘9“;ÐØˆr#   c                 ó|   — g }|j                   D ]  }|j                  t        |«      «       Œ t        |«      dk(  ryy)zN
        Checks if the given distribution contains random parameters.
        r   FT)r-   Úextendr	   Úlen)r(   rK   rv   Úargs       r"   rj   z$CompoundDistribution._compound_checkÕ   s?   € ð
 ˆØ—9‘9ò 	0ˆCØ�N‰Nœ>¨#Ó.Õ/ð	0äˆw‹<˜1ÒØØr#   Nra   )rb   rc   rd   re   r   rf   r:   r0   r2   r4   r8   rt   Úclassmethodrj   rg   r#   r"   r   r      s~   „ ñò>(ð ñ ó ð ð ñ@ó ð@ð ñBó ðBð ñ>ó ð>ó"òð  ñ	ó ñ	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   rg   r#   r"   ú<module>r�      sW   ðÝ )Ý "Ý &Ý #Ý .÷G÷ Gñ Gç Jß Fß HÝ @Ý >Ý <ôl7�Vô l7ô^`˜<¨õ `r#   