
    g/                         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 ZddZd ZddZd Zd Zd ZdS )    Tuple)Basic)Expr)AppliedUndef)
Relational)Dummy)sympify)BooleanFunction)ImageSet)	FiniteSet)Indexedc                 F   t          | t          t          t          f          s| g} t	          d | D                       rt                      S  t                      j        d | D              } |j        d | D              }|p t                      j        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              3   4   K   | ]}t          |          V  d S Ncallable.0es     P/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/plotting/utils.py	<genexpr>z$_get_free_symbols.<locals>.<genexpr>   s(      
&
&18A;;
&
&
&
&
&
&    c                 B    g | ]}|                     t                    S  )atomsr   r   s     r   
<listcomp>z%_get_free_symbols.<locals>.<listcomp>   s$    999a))999r   c                 B    g | ]}|                     t                    S r   )r   r   r   s     r   r   z%_get_free_symbols.<locals>.<listcomp>   s$    ===!--===r   c                     g | ]	}|j         
S r   free_symbolsr   s     r   r   z%_get_free_symbols.<locals>.<listcomp>   s     ? ? ?A ? ? ?r   )
isinstancelisttuplesetallunion)exprsfrees     r   _get_free_symbolsr*      s     edE3/00 

&
&
&
&
&&& uu355;995999:D4:==u===>D@;355; ? ? ? ? ?@@r   
   c                     |                      t                    }|D ]J}t          |          t          fdt	          d|          D              }|                     ||          } K| 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                 .    g | ]}t                    S r   )next)r   nits     r   r   z$extract_solution.<locals>.<listcomp>1   s    666QR666r   r   )findr   iterr   rangesubs)set_solr/   imagesimsr0   s        @r   extract_solutionr9   !   sq     \\(##F & &"XX6666%1++6667,,r1%%Nr   c                    t          | t                    r| S t          |           } t          |           D ]\  }}t          |t          t          f          rt          t          |          ddi| |<   >t          |t          t          f          sFt          |          s7|j
        j        dk    rt          |t                    rt          |          | |<   | 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as      r   r=   r=   6   s     $ ::D$ 
! 
!1a$'' 		!]1--=u==DGGQd,, 	! 	!
 %11:a;O;O1ajjDGKr    Nc                    d }t          |           }|'|                    |                                          }t          |          |k    rIt	          dd                    |          z   d                    t          |          |          z             t          |          |k    r"t	          dt          |          d|          t                                          d |D                       }t          |          t          |          k    rt	          d	          t          |          |k     r|                    |          }|t                      k    r#|D ] }	|                     ||	                     !t          |t          |          z
            D ],}
|                     |t                                           -t          |          |k    rt                                          d
 |D                       }t          |                    |                    dk    r;t	          dd                    |          z   d                    |          z             |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                 $    t          | dd          S )Nir+   r   )symbols    r   <lambda>z _create_ranges.<locals>.<lambda>l   s    uVS"'='= r   NzToo many free symbols.
zExpected {} free symbols.
zReceived {}: {}zToo many ranges. Received z, expected c                     g | ]
}|d          S r   r   r   rs     r   r   z"_create_ranges.<locals>.<listcomp>~   s    ,,,qt,,,r   z$Multiple ranges with the same symbolc                     g | ]
}|d          S rK   r   rL   s     r   r   z"_create_ranges.<locals>.<listcomp>   s    000A1Q4000r   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'   appendr3   r	   )r(   rangesnparlabelparamsget_default_ranger!   rfssymbolsr8   rC   s              r   _create_rangesr\   U   su   . >=$U++L#..v{{}}==
<4&+224889&&s<'8'8,GGH
 
 	
 6{{Tj;>v;;;;MO O 	O %%++,,V,,,
-
-C
3xx3v;;?@@@
6{{T))#..cee 4 4//223333tc&kk)** 	6 	6AMM++EGG445555
<D   eekk0000011|&&s++,,q00 9@@NNO 399#>>?   Mr   c                    t          | t                    oxt          |           dk    oet          | j        d         t                     oD| j        d         j        o2t          | j        d         t                     o| j        d         j        S )zUA range is defined as (symbol, start, end). start and end should
    be numbers.
             )r"   r   rQ   rB   r>   	is_number)rM   s    r   	_is_rangerb      s     	1e 	EVVq[	EAF1Is+++	E121D	E AF1Is+++	E 231D	r   c                      d | D             }d | D             }|sdn|d         }d | D             }|sdn|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                 0    g | ]}t          |          |S r   rb   r   ts     r   r   z _unpack_args.<locals>.<listcomp>   s#    ...A1.a...r   c                 <    g | ]}t          |t                    |S r   r"   r>   rf   s     r   r   z _unpack_args.<locals>.<listcomp>   s'    444AAs!3!34a444r   Nr   c                 <    g | ]}t          |t                    |S r   r"   r?   rf   s     r   r   z _unpack_args.<locals>.<listcomp>   s'    ;;;!z!T':':;A;;;r   c                 n    g | ]2}t          |          pt          |t          t          f          p|d u  3S r   )rb   r"   r>   r?   r   rD   s     r   r   z _unpack_args.<locals>.<listcomp>   s>    ]]]STIaLLMJq3+$>$>M19N]]]r   c                     g | ]	\  }}||
S r   r   )r   rD   bs      r   r   z _unpack_args.<locals>.<listcomp>   s!    33341a3Q333r   )zip)rB   rU   labelsrW   rendering_kwresultsr(   s          r   _unpack_argsrt      s    4 /....F44444F-DDF1IE;;t;;;L+@44aL ^]X\]]]G333tW--333E&%--r   c                    | sg S g }|                     dd          }t          d | d|         D                       rt          |  \  }}}}	 t                      j        d |D              }
t          |||||          }|dk    r#t          |          |k    rt          |          f}|D ]I}t          |t          t          t          f          }|r|fn|}|                    g ||||	R            Jnt          |  \  }}}}	|r|gng }t          |          t          |          z   |	t          |	          ndz   }|dk    r| d|          n| }t          |d         t          t          t          f          s|g}|D ]d D             }|s|}d D             }|s|                                }d	 D             }t          |          dk    r|	n|d         }fd
t!          |          D             t                      }
t          d D                       r |
j        d D              }
t          |          |k    rt          ||d|          }|sdn|d         }|                    g |||R            |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)]
    rX   Nc              3   Z   K   | ]&}t          |t          t          t          f          V  'd S r   )r"   r   r   r   rm   s     r   r   z#_check_arguments.<locals>.<genexpr>  s3      
T
T!:a$
O<==
T
T
T
T
T
Tr   c                     g | ]	}|j         
S r   r    r   s     r   r   z$_check_arguments.<locals>.<listcomp>	  s    $C$C$CQ^$C$C$Cr   r_   r   c                 <    g | ]}t          |t                    |S r   ri   rm   s     r   r   z$_check_arguments.<locals>.<listcomp>/  s'    666q:a#5#56666r   c                 0    g | ]}t          |          |S r   re   rm   s     r   r   z$_check_arguments.<locals>.<listcomp>2  s#    000q9Q<<0000r   c                 <    g | ]}t          |t                    |S r   rk   rm   s     r   r   z$_check_arguments.<locals>.<listcomp>5  s'    ===QAt)<)<=q===r   c                      g | ]
}|         S r   r   )r   rC   args     r   r   z$_check_arguments.<locals>.<listcomp>:  s    000a3q6000r   c              3   6   K   | ]}t          |           V  d S r   r   rm   s     r   r   z#_check_arguments.<locals>.<genexpr><  s*      00qx{{?000000r   c                     g | ]	}|j         
S r   r    rm   s     r   r   z$_check_arguments.<locals>.<listcomp>=  s    3P3P3PqAN3P3P3Pr   rE   )getr&   rt   r%   r'   r\   rQ   r$   r"   r   r   r   rT   r#   r   copyr3   )rB   nexprrV   kwargsoutputrX   r(   rU   rW   rr   r!   expris_exprr   _rq   r/   new_argslrM   rend_kwr|   s                        @r   _check_argumentsr      s!   `  	FZZ$''F

T
TtFUF|
T
T
TTT ?6
 .:4-@*vul"suu{$C$CU$C$C$CDvtUFCC199 5zzU""u 	> 	>D !j/'JKKG",AMM<A<<<|<<====	> +7*='66<#+& [[3v;;&".":SC !A4!994
 (1+eU';<< 	" zH  	6 	6C66C666A 00C000A "KKMM==#===G&)'lla&7&7llWQZG 10005<<000C55L00C00000 R1|13P3PC3P3P3PQ1vv~~"34V<< !+DDqtEMM4C4!4U4G445555Mr   )r+   )rE   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*   r9   r=   r\   rb   rt   r   r   r   r   <module>r      sV   ' ' ' ' ' ' " " " " " "             , , , , , , , , , , , , # # # # # # & & & & & & / / / / / / ) ) ) ) ) ) % % % % % % ( ( ( ( ( (A A A&   *  >C C C CL
 
 
#. #. #.Lu u u u ur   