o
    oh/                     @   s   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mZ d d
lmZ d dlmZ dd ZdddZdd ZdddZdd Zdd Zdd ZdS )    Tuple)Basic)Expr)AppliedUndef)
Relational)Dummy)sympify)BooleanFunction)ImageSet)	FiniteSet)Indexedc                 C   sr   t | tttfs| g} tdd | D rt S t jdd | D  }|jdd | D  }|p8t jdd | D  S )a  Returns the free symbols of a symbolic expression.

    If the expression contains any of these elements, assume that they are
    the "free symbols" of the expression:

    * indexed objects
    * applied undefined function (useful for sympy.physics.mechanics module)
    c                 s   s    | ]}t |V  qd S Ncallable.0e r   h/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/plotting/utils.py	<genexpr>   s    z$_get_free_symbols.<locals>.<genexpr>c                 S      g | ]}| tqS r   )atomsr   r   r   r   r   
<listcomp>       z%_get_free_symbols.<locals>.<listcomp>c                 S   r   r   )r   r   r   r   r   r   r      r   c                 S      g | ]}|j qS r   free_symbolsr   r   r   r   r          )
isinstancelisttuplesetallunion)exprsfreer   r   r   _get_free_symbols   s   	r'   
   c                    sH   |  t}|D ]}t| t fddtd|D  }| ||} q| S )a  Extract numerical solutions from a set solution (computed by solveset,
    linsolve, nonlinsolve). Often, it is not trivial do get something useful
    out of them.

    Parameters
    ==========

    n : int, optional
        In order to replace ImageSet with FiniteSet, an iterator is created
        for each ImageSet contained in `set_sol`, starting from 0 up to `n`.
        Default value: 10.
    c                    s   g | ]}t  qS r   )next)r   nitr   r   r   1       z$extract_solution.<locals>.<listcomp>r   )findr   iterr   rangesubs)set_solr*   imagesimsr   r+   r   extract_solution!   s   
r6   c                 C   s   t | tr| S t| } t| D ]3\}}t |ttfr&tt|ddi| |< qt |ttfsBt	|sB|j
jdkr<t |trBt|| |< q| S )a  This function recursively loop over the arguments passed to the plot
    functions: the sympify function will be applied to all arguments except
    those of type string/dict.

    Generally, users can provide the following arguments to a plot function:

    expr, range1 [tuple, opt], ..., label [str, opt], rendering_kw [dict, opt]

    `expr, range1, ...` can be sympified, whereas `label, rendering_kw` can't.
    In particular, whenever a special character like $, {, }, ... is used in
    the `label`, sympify will raise an error.
    r	   FVector)r   r   r    	enumerater!   r   _plot_sympifystrdictr   	__class____name__r   r	   )argsiar   r   r   r9   6   s   
r9    Nc                 C   sT  dd }t | }|dur|| }t||kr*tdd| dt|| t||kr:tdt||f t dd	 |D }t|t|krQtd
t||k r||}|t krm|D ]	}	|||	 qct	|t| D ]
}
||t
  qut||krt dd	 |D }t||dkrtdd| d| |S )a  This function does two things:

    1. Check if the number of free symbols is in agreement with the type of
       plot chosen. For example, plot() requires 1 free symbol;
       plot3d() requires 2 free symbols.
    2. Sometime users create plots without providing ranges for the variables.
       Here we create the necessary ranges.

    Parameters
    ==========

    exprs : iterable
        The expressions from which to extract the free symbols
    ranges : iterable
        The limiting ranges provided by the user
    npar : int
        The number of free symbols required by the plot functions.
        For example,
        npar=1 for plot, npar=2 for plot3d, ...
    params : dict
        A dictionary mapping symbols to parameters for interactive plot.
    c                 S   s   t | ddS )Nir(   r   )symbolr   r   r   <lambda>l   s    z _create_ranges.<locals>.<lambda>NzToo many free symbols.
zExpected {} free symbols.
zReceived {}: {}z)Too many ranges. Received %s, expected %sc                 S      g | ]}|d  qS r   r   r   rr   r   r   r   ~   r-   z"_create_ranges.<locals>.<listcomp>z$Multiple ranges with the same symbolc                 S   rD   rE   r   rF   r   r   r   r      r-   r   z>Incompatible free symbols of the expressions with the ranges.
z$Free symbols in the expressions: {}
zFree symbols in the ranges: {})r'   
differencekeyslen
ValueErrorformatr"   r$   appendr0   r   )r%   rangesnparlabelparamsget_default_ranger   rfssymbolsr5   r?   r   r   r   _create_rangesU   sJ   

rU   c                 C   sR   t | to(t| dko(t | jd t o(| jd jo(t | jd t o(| jd jS )zUA range is defined as (symbol, start, end). start and end should
    be numbers.
             )r   r   rJ   r>   r:   	is_number)rG   r   r   r   	_is_range   s   



rZ   c                  G   sx   dd | D }dd | D }|sdn|d }dd | D }|s!dn|d }dd | D }dd t | |D }||||fS )	a  Given a list/tuple of arguments previously processed by _plot_sympify()
    and/or _check_arguments(), separates and returns its components:
    expressions, ranges, label and rendering keywords.

    Examples
    ========

    >>> from sympy import cos, sin, symbols
    >>> from sympy.plotting.utils import _plot_sympify, _unpack_args
    >>> x, y = symbols('x, y')
    >>> args = (sin(x), (x, -10, 10), "f1")
    >>> args = _plot_sympify(args)
    >>> _unpack_args(*args)
    ([sin(x)], [(x, -10, 10)], 'f1', None)

    >>> args = (sin(x**2 + y**2), (x, -2, 2), (y, -3, 3), "f2")
    >>> args = _plot_sympify(args)
    >>> _unpack_args(*args)
    ([sin(x**2 + y**2)], [(x, -2, 2), (y, -3, 3)], 'f2', None)

    >>> args = (sin(x + y), cos(x - y), x + y, (x, -2, 2), (y, -3, 3), "f3")
    >>> args = _plot_sympify(args)
    >>> _unpack_args(*args)
    ([sin(x + y), cos(x - y), x + y], [(x, -2, 2), (y, -3, 3)], 'f3', None)
    c                 S      g | ]}t |r|qS r   rZ   r   tr   r   r   r          z _unpack_args.<locals>.<listcomp>c                 S      g | ]	}t |tr|qS r   r   r:   r]   r   r   r   r          Nr   c                 S   r`   r   r   r;   r]   r   r   r   r      rb   c                 S   s,   g | ]}t |pt|ttfp|d u  qS r   )rZ   r   r:   r;   r   r@   r   r   r   r      s   , c                 S   s   g | ]\}}|r|qS r   r   )r   r@   br   r   r   r      r_   )zip)r>   rN   labelsrP   rendering_kwresultsr%   r   r   r   _unpack_args   s   rj   c                    s6  | sg S g }| dd}tdd | d| D rgt|  \}}}}	t jdd |D  }
t|||||}|dkrCt||krCt|f}|D ]}t|t	t
tf}|rT|fn|}|g ||||	R  qE|S t|  \}}}}	|rt|gng }t|t| |	durt|	nd }|dkr| d|  n| }t|d tttfs|g}|D ]t d	d  D }|s|}d
d  D }|s| }dd  D }t|dkr|	n|d } fddt|D  t }
tdd  D r|
jdd  D  }
t||krt ||d|}|sdn|d }|g  |||R  q|S )a,  Checks the arguments and converts into tuples of the
    form (exprs, ranges, label, rendering_kw).

    Parameters
    ==========

    args
        The arguments provided to the plot functions
    nexpr
        The number of sub-expression forming an expression to be plotted.
        For example:
        nexpr=1 for plot.
        nexpr=2 for plot_parametric: a curve is represented by a tuple of two
            elements.
        nexpr=1 for plot3d.
        nexpr=3 for plot3d_parametric_line: a curve is represented by a tuple
            of three elements.
    npar
        The number of free symbols required by the plot functions. For example,
        npar=1 for plot, npar=2 for plot3d, ...
    **kwargs :
        keyword arguments passed to the plotting function. It will be used to
        verify if ``params`` has ben provided.

    Examples
    ========

    .. plot::
       :context: reset
       :format: doctest
       :include-source: True

       >>> from sympy import cos, sin, symbols
       >>> from sympy.plotting.plot import _check_arguments
       >>> x = symbols('x')
       >>> _check_arguments([cos(x), sin(x)], 2, 1)
       [(cos(x), sin(x), (x, -10, 10), None, None)]

       >>> _check_arguments([cos(x), sin(x), "test"], 2, 1)
       [(cos(x), sin(x), (x, -10, 10), 'test', None)]

       >>> _check_arguments([cos(x), sin(x), "test", {"a": 0, "b": 1}], 2, 1)
       [(cos(x), sin(x), (x, -10, 10), 'test', {'a': 0, 'b': 1})]

       >>> _check_arguments([x, x**2], 1, 1)
       [(x, (x, -10, 10), None, None), (x**2, (x, -10, 10), None, None)]
    rQ   Nc                 s   s     | ]}t |tttfV  qd S r   )r   r   r   r
   rd   r   r   r   r     s    z#_check_arguments.<locals>.<genexpr>c                 S   r   r   r   r   r   r   r   r   	  r   z$_check_arguments.<locals>.<listcomp>rW   r   c                 S   r`   r   ra   rd   r   r   r   r   /  rb   c                 S   r[   r   r\   rd   r   r   r   r   2  r_   c                 S   r`   r   rc   rd   r   r   r   r   5  rb   c                    s   g | ]} | qS r   r   )r   r?   argr   r   r   :  r-   c                 s   s    | ]}t | V  qd S r   r   rd   r   r   r   r   <  s    c                 S   r   r   r   rd   r   r   r   r   =  r   rA   )getr#   rj   r"   r$   rU   rJ   r!   r   r   r   r
   rM   r    r   copyr0   )r>   nexprrO   kwargsoutputrQ   r%   rN   rP   rh   r   expris_exprr   _rg   r*   new_argslrG   rend_kwr   rk   r   _check_arguments   sT   0
-rx   )r(   )rA   N)sympy.core.containersr   sympy.core.basicr   sympy.core.exprr   sympy.core.functionr   sympy.core.relationalr   sympy.core.symbolr   sympy.core.sympifyr	   sympy.logic.boolalgr
   sympy.sets.fancysetsr   sympy.sets.setsr   sympy.tensor.indexedr   r'   r6   r9   rU   rZ   rj   rx   r   r   r   r   <module>   s$    

F&