o
    oh                     @   s   d 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mZmZ ddlmZ dd ZdddZdS )z'Tools for arithmetic error propagation.    )repeatcombinations)Add)Mul)Pow)S)Symbol)exp)simplify)RandomSymbolVariance
Covariance)	is_randomc                 C   s   t | jdkr| jd S | S )Nr   )lenargs)var r   j/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/stats/error_prop.py<lambda>       r   r   Fc           
      C   s  | j }t|dkr*| |v rtjS t| rt|  S t| tr'tt	|  S tjS t|}t
tt|t||t||}t| trZt| }|rXdd t|dD }|t| 7 }|S t| trdd t||D }t| d t|  }|rdd tt|dt|dD }|t| 7 }|S t| tr|d }|d | | |d  d  }	t|	}|S t| trt|d | d  }|S t| }|S )a  Symbolically propagates variance (`\sigma^2`) for expressions.
    This is computed as as seen in [1]_.

    Parameters
    ==========

    expr : Expr
        A SymPy expression to compute the variance for.
    consts : sequence of Symbols, optional
        Represents symbols that are known constants in the expr,
        and thus have zero variance. All symbols not in consts are
        assumed to be variant.
    include_covar : bool, optional
        Flag for whether or not to include covariances, default=False.

    Returns
    =======

    var_expr : Expr
        An expression for the total variance of the expr.
        The variance for the original symbols (e.g. x) are represented
        via instance of the Variance symbol (e.g. Variance(x)).

    Examples
    ========

    >>> from sympy import symbols, exp
    >>> from sympy.stats.error_prop import variance_prop
    >>> x, y = symbols('x y')

    >>> variance_prop(x + y)
    Variance(x) + Variance(y)

    >>> variance_prop(x * y)
    x**2*Variance(y) + y**2*Variance(x)

    >>> variance_prop(exp(2*x))
    4*exp(4*x)*Variance(x)

    References
    ==========

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

    r   c                 S   s*   g | ]\}}d t t|t|  qS    r   _arg0_or_varexpand).0xyr   r   r   
<listcomp>P   s    z!variance_prop.<locals>.<listcomp>r   c                 S   s   g | ]
\}}||d   qS r   r   )r   avr   r   r   r   T   r   c                 S   s:   g | ]\\}}\}}d t t|t|  ||  qS r   r   )r   r   br   r   r   r   r   r   W   s    &   )r   r   r   Zeror   r   doit
isinstancer   r   listmapvariance_propr   r   r   r   zipr
   r   r	   )
exprconstsinclude_covarr   nargsvar_argsvar_exprtermsr!   r    r   r   r   r(      sT   .






r(   N)r   F)__doc__	itertoolsr   r   sympy.core.addr   sympy.core.mulr   sympy.core.powerr   sympy.core.singletonr   sympy.core.symbolr   &sympy.functions.elementary.exponentialr	   sympy.simplify.simplifyr
    sympy.stats.symbolic_probabilityr   r   r   sympy.stats.rvr   r   r(   r   r   r   r   <module>   s    