§
    OŠ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 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     úR/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/plotting/utils.pyú	<genexpr>z$_get_free_symbols.<locals>.<genexpr>   s(   è è € Ð
&Ð
&˜1�8�A‰;Œ;Ð
&Ð
&Ð
&Ð
&Ð
&Ð
&ó    c                 óB   — g | ]}|                      t          ¦  «        ‘ŒS © )Úatomsr   r   s     r   ú
<listcomp>z%_get_free_symbols.<locals>.<listcomp>   s$   € Ð9Ð9Ð9¨a˜Ÿš¥Ñ)Ô)Ð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±   € õ �e�d¥E­3Ð/Ñ0Ô0ð Ø�ˆÝ
Ð
&Ð
& Ð
&Ñ
&Ô
&Ñ&Ô&ð Ý‰uŒuˆà�3‰5Œ5Œ;Ð9Ð9°5Ð9Ñ9Ô9Ð:€DØˆ4Œ:Ð=Ð=°uÐ=Ñ=Ô=Ð>€DØÐ@�;•3‘5”5”;Ð ?Ð ?¸Ð ?Ñ ?Ô ?Ð@Ð@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Ð6 Q�˜R™œÐ6Ð6Ð6r   r   )Úfindr   Úiterr   ÚrangeÚsubs)Úset_solr/   ÚimagesÚimÚsr0   s        @r   Úextract_solutionr9   !   sq   ø€ ð �\Š\�(Ñ#Ô#€FØð &ð &ˆÝ�"‰XŒXˆÝÐ6Ð6Ð6Ð6­%°°1©+¬+Ð6Ñ6Ô6Ð7ˆØ—,’,˜r 1Ñ%Ô%ˆˆØ€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�‰GˆGÝ˜Q¥¥d Ñ,Ô,ð 	!µ¸±´ð 	!ð
 ”Ô%¨Ò1Ð1½:ÀaÍÑ;OÔ;OÐ1å˜a‘j”jˆD�‰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    rŒt          ¦   «                              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 )Niöÿÿÿr+   r   )Úsymbols    r   ú<lambda>z _create_ranges.<locals>.<lambda>l   s   € ¥u¨V°S¸"Ñ'=Ô'=€ 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Ð0 A˜1˜Qœ4Ð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Ò2°4Ñ8Ô8ñ9à×&Ò&¥s¨<Ñ'8Ô'8¸,ÑGÔGñHñ
ô 
ð 	
õ ˆ6�{„{�TÒÐÝˆjÝ;>¸v¹;¼;¸;¸;ÈÈÐMñOô Oð 	Oõ ‰%Œ%�+Š+Ð,Ð, VÐ,Ñ,Ô,Ñ
-Ô
-€CÝ
ˆ3�x„x•3�v‘;”;ÒÐÝÐ?Ñ@Ô@Ð@å
ˆ6�{„{�TÒÐØ×)Ò)¨#Ñ.Ô.ˆØ•c‘e”eÒÐàð 4ð 4�Ø—’Ð/Ð/°Ñ2Ô2Ñ3Ô3Ð3Ð3å�t�c &™kœkÑ)Ñ*Ô*ð 	6ð 	6ˆAØ�MŠMÐ+Ð+­E©G¬GÑ4Ô4Ñ5Ô5Ð5Ð5å
ˆ<ÑÔ˜DÒ Ð õ ‰eŒe�kŠkÐ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‰   € õ 	�1•eÑÔð 	EÝ�‰VŒV�qŠ[ð	Eå˜AœF 1œI¥sÑ+Ô+Ð+ð	Eà12´¸´Ô1Dð	Eõ ˜AœF 1œI¥sÑ+Ô+Ð+ð	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Ð4�A¥¨A­sÑ!3Ô!3Ð4ˆaÐ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>   € Ð]Ð]Ð]ÐST•I˜a‘L”LÐM¥J¨qµ3½°+Ñ$>Ô$>ÐMÀ1ÈÀ9ÐNÐ]Ð]Ð]r   c                 ó   — g | ]	\  }}|¯|‘Œ
S r   r   )r   rD   Úbs      r   r   z _unpack_args.<locals>.<listcomp>Ê   s!   € Ð3Ð3Ð3‘4�1�a°Ð3ˆQÐ3Ð3Ð3r   )Úzip)rB   rU   ÚlabelsrW   Úrendering_kwÚresultsr(   s          r   Ú_unpack_argsrt   ¨   s¤   € ð4 /Ð.˜Ð.Ñ.Ô.€FØ4Ð4˜Ð4Ñ4Ô4€FØÐ-ˆDˆD F¨1¤I€EØ;Ð;˜tÐ;Ñ;Ô;€LØ+Ð@�4�4°¸a´€Lð ^Ð]ÐX\Ð]Ñ]Ô]€GØ3Ð3�3˜t WÑ-Ô-Ð3Ñ3Ô3€EØ�&˜% Ð-Ð-r   c                 ó  ‡— | sg S g }|                      dd¦  «        }t          d„ | d|…         D ¦   «         ¦  «        r¸t          | Ž \  }}}}	 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�nŽt          | Ž \  }}}}	|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Ð6�q¥:¨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Ð0�q¥9¨Q¡<¤<Ð0�Ð0Ð0Ð0r   c                 ó<   — g | ]}t          |t          ¦  «        ¯|‘ŒS r   rk   rm   s     r   r   z$_check_arguments.<locals>.<listcomp>5  s'   € Ð=Ð=Ð=˜Q­°AµtÑ)<Ô)<Ð=�qÐ=Ð=Ð=r   c                 ó    •— g | ]
}‰|         ‘ŒS r   r   )r   rC   Úargs     €r   r   z$_check_arguments.<locals>.<listcomp>:  s   ø€ Ð0Ð0Ð0˜a�3�q”6Ð0Ð0Ð0r   c              3   ó6   K  — | ]}t          |¦  «         V — Œd S r   r   rm   s     r   r   z#_check_arguments.<locals>.<genexpr><  s*   è è € Ð0Ð0 q•x ‘{”{�?Ð0Ð0Ð0Ð0Ð0Ð0r   c                 ó   — g | ]	}|j         ‘Œ
S r   r    rm   s     r   r   z$_check_arguments.<locals>.<listcomp>=  s   € Ð3PÐ3PÐ3PÀq°A´NÐ3PÐ3PÐ3Pr   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Ø�ZŠZ˜ $Ñ'Ô'€Få
Ð
TÐ
TÀtÈFÈUÈFÄ|Ð
TÑ
TÔ
TÑTÔTð ?6õ
 .:¸4Ð-@Ñ*ˆˆv�u˜lØ"•s‘u”u”{Ð$CÐ$C¸UÐ$CÑ$CÔ$CÐDˆÝ  v¨t°U¸FÑCÔCˆà�1Š9ˆ9õ �5‰zŒz˜UÒ"Ð"Ý˜u™œ˜�Øð 	>ð 	>ˆDõ ! ­­j½/Ð'JÑKÔKˆGØ"Ð,���¨ˆAØ�MŠMÐ<˜AÐ< Ð<¨Ð<¨|Ð<Ð<Ñ=Ô=Ð=Ð=ñ	>õ +7¸Ð*=Ñ'ˆˆ6�6˜<Ø#Ð+�&��¨ˆõ �‰[Œ[�3˜v™;œ;Ñ&Ø".Ð":�S�ÑÔÐÀñCˆà ! A¢ �4˜˜!˜˜”9�9¨4ˆõ
 ˜( 1œ+­­eµUÐ';Ñ<Ô<ð 	"Ø �zˆHð ð 	6ñ 	6ˆCà6Ð6˜CÐ6Ñ6Ô6ˆAØð Ø�Ø0Ð0˜CÐ0Ñ0Ô0ˆAØð "Ø—K’K‘M”M�Ø=Ð= #Ð=Ñ=Ô=ˆGÝ&)¨'¡l¤l°aÒ&7Ð&7�l�l¸WÀQ¼ZˆGð 1Ð0Ð0Ð0¥5¨¡<¤<Ð0Ñ0Ô0ˆCÝ™5œ5ˆLÝÐ0Ð0¨CÐ0Ñ0Ô0Ñ0Ô0ð RØ1˜|Ô1Ð3PÐ3PÈCÐ3PÑ3PÔ3PÐQ�Ý�1‰vŒv˜Š~ˆ~Ý" 3¨¨4°°VÑ<Ô<�à !Ð+�D�D q¨¤tˆEØ�MŠMÐ4˜CÐ4 !Ð4 UÐ4¨GÐ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   