
    \h/                         S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S rSS jrS rSS jrS rS rS rg)    Tuple)Basic)Expr)AppliedUndef)
Relational)Dummy)sympify)BooleanFunction)ImageSet)	FiniteSet)Indexedc                    [        U [        [        [        45      (       d  U /n [	        S U  5       5      (       a
  [        5       $ [        5       R
                  " U  Vs/ s H  oR                  [        5      PM     sn6 nUR
                  " U  Vs/ s H  oR                  [        5      PM     sn6 nU=(       d1    [        5       R
                  " U  Vs/ s H  oR                  PM     sn6 $ s  snf s  snf s  snf )zReturns 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   8   #    U  H  n[        U5      v   M     g 7fNcallable).0es     L/var/www/auris/envauris/lib/python3.13/site-packages/sympy/plotting/utils.py	<genexpr>$_get_free_symbols.<locals>.<genexpr>   s     
&18A;;s   )

isinstancelisttuplesetallunionatomsr   r   free_symbols)exprsr   frees      r   _get_free_symbolsr#      s     edE3/00

&
&&&u5;;595a)59:D::u=u!-u=>D@35;; ?A ?@@ := ?s   C+C0C5c           	          U R                  [        5      nU HK  n[        U5      n[        [	        SW5       Vs/ s H  n[        U5      PM     sn6 nU R                  X55      n MM     U $ s  snf )ao  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.
r   )findr   iterr   rangenextsubs)set_solnimagesimitss         r   extract_solutionr0   !   sb     \\(#F"X%1+6+QR+67,,r%  N 7s   A)
c                    [        U [        5      (       a  U $ [        U 5      n [        U 5       H  u  p[        U[        [        45      (       a  [        [        U5      SS06X'   M8  [        U[        [        45      (       a  MU  [        U5      (       a  Mg  UR                  R                  S:X  a  [        U[        5      (       d  M  [        U5      X'   M     U $ )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   r4   r4   6   s     $:D$a$'']1-=u=DGQd,,
 %%1:a;O;OajDG   K    Nc                 $   S n[        U 5      nUb  UR                  UR                  5       5      n[        U5      U:  a9  [	        SSR                  U5      -   SR                  [        U5      U5      -   5      e[        U5      U:  a  [	        S[        U5      < SU< 35      e[        5       R                  U Vs/ s H  owS   PM	     sn5      n[        U5      [        U5      :w  a  [	        S5      e[        U5      U:  a|  UR                  U5      n	U	[        5       :w  a   U	 H  n
UR                  U" U
5      5        M     [        U[        U5      -
  5       H"  nUR                  U" [        5       5      5        M$     [        U5      U:X  ay  [        5       R                  U Vs/ s H  owS   PM	     sn5      n[        UR                  U5      5      S:  a/  [	        S	S
R                  U5      -   SR                  U5      -   5      eU$ s  snf s  snf )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                     [        U SS5      $ )Ni
   r   )symbols    r   <lambda> _create_ranges.<locals>.<lambda>l   s    uVS"'=r<   zToo many free symbols.
zExpected {} free symbols.
zReceived {}: {}zToo many ranges. Received z, expected r   z$Multiple ranges with the same symbolz>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   appendr'   r	   )r!   rangesnparlabelparamsget_default_ranger    rrfssymbolsr/   r:   s               r   _create_rangesrQ   U   s   . >$U+L#..v{{}=
<4&+22489&&s<'8,GH
 	
 6{T;>v;MO 	O %++V,VtV,
-C
3x3v;?@@
6{T))#.ce/23  tc&k)*AMM+EG45 + <D  ekk0AQ401|&&s+,q0 9@@NO 399#>?  M5 -$ 1s   ;H$Hc                 p   [        U [        5      =(       a    [        U 5      S:H  =(       a    [        U R                  S   [        5      (       + =(       ab    U R                  S   R
                  =(       aB    [        U R                  S   [        5      (       + =(       a    U R                  S   R
                  $ )zMA range is defined as (symbol, start, end). start and end should
be numbers.
         )r   r   rE   r9   r5   	is_number)rN   s    r   	_is_rangerW      s     	1e 	EVq[	EAFF1Is++	E121D1D	E AFF1Is++	E 231D1D	r<   c                  B   U  Vs/ s H  n[        U5      (       d  M  UPM     nnU  Vs/ s H  n[        U[        5      (       d  M  UPM     nnU(       d  SOUS   nU  Vs/ s H  n[        U[        5      (       d  M  UPM     nnU(       d  SOUS   nU  Vs/ s H;  n[        U5      =(       d!    [        U[        [        45      =(       d    USL (       + PM=     nn[	        X5       VVs/ s H  u  phU(       d  M  UPM     n	nnXXE4$ s  snf s  snf s  snf s  snf s  snnf )aR  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)
Nr   )rW   r   r5   r6   zip)
r9   trI   labelsrK   rendering_kwr;   resultsbr!   s
             r   _unpack_argsr_      s    4 .A1aF.4AAs!3aF4DF1IE#;t!z!T':AtL;+4aL Y]]X\STIaLMJq3+$>M19NX\G]t-3-41Q-E3%-- /4; ^3s4   DDDD D=DAD)D:Dc                    U (       d  / $ / nUR                  SS5      n[        S U SU  5       5      (       a  [        U 6 u  pgp[        5       R                  " U V
s/ s H  oR
                  PM     sn
6 n[        XgX(U5      nUS:  a  [        U5      U:X  a  [        U5      4nU HD  n[        U[        [        [        45      nU(       a  U4OUn
UR                  / U
QUQUPU	P75        MF     U$ [        U 6 u  ppU(       a  U/O/ n[        U5      [        U5      -   U	b  [        U	5      OS-   nUS:  a  U SU*  OU n[        US   [        [        [        45      (       d  U/nU GH_  nU Vs/ s H  n[        U[         5      (       d  M  UPM     nnU(       d  UnU Vs/ s H  n[#        U5      (       d  M  UPM     nnU(       d  UR%                  5       nU Vs/ s H  n[        U[&        5      (       d  M  UPM     nn[        U5      S:X  a  U	OUS   n[)        U5       Vs/ s H  nUU   PM
     nn[        5       n[        S U 5       5      (       a*  UR                  " U Vs/ s H  nUR
                  PM     sn6 n[        U5      U:w  a  [        UUUSU5      nU(       d  SOUS   nUR                  / UQUQUPUP75        GMb     U$ s  sn
f s  snf s  snf s  snf s  snf s  snf )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)]
rL   Nc              3   X   #    U  H   n[        U[        [        [        45      v   M"     g 7fr   )r   r   r   r   r   r;   s     r   r   #_check_arguments.<locals>.<genexpr>  s!     
T|!:a$
O<==|s   (*rT   r   c              3   B   #    U  H  n[        U5      (       + v   M     g 7fr   r   rb   s     r   r   rc   <  s     0Cqx{??Cs    )getr   r_   r   r   r    rQ   rE   r   r   r   r   r   rH   r   r   r5   rW   copyr6   r'   )r9   nexprrJ   kwargsoutputrL   r!   rI   rK   r\   r   r    expris_expr_r[   r+   new_argsargr;   lrN   rend_kwr:   s                           r   _check_argumentsrr      s   ` 	FZZ$'F

TtFU|
TTT
 .:4-@*uu{{U$CU^^U$CDtFC19 5zU"uD !j/'JKG"AMM<A<<<|<= d MM +7*='6#& [3v;&".":SC !A4!94
 (1+eU';<< zH C6Cq:a#5CA60Cq9Q<CA0KKM"%=#QAt)<q#G=&)'la&7lWQZG $)<0<a3q6<C05L0C000+11C3PCqANNC3PQ1v~"34V< !DqtEMM4C4!4U4G45+ , Mu %DL 7 1 >
 1 4Qs6   K	+KKK5KK5K K"K"
)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#   r0   r4   rQ   rW   r_   rr    r<   r   <module>r      sN    ' "   , , # & / ) % (A&*>CL
#.Lur<   