
    wg/                         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y)    Tuple)Basic)Expr)AppliedUndef)
Relational)Dummy)sympify)BooleanFunction)ImageSet)	FiniteSet)Indexedc                    t        | t        t        t        f      s| g} t	        d | D              r
t               S  t               j
                  | D cg c]  }|j                  t               c} } |j
                  | D cg c]  }|j                  t               c} }|xs/  t               j
                  | D cg c]  }|j                   c} S c c}w c c}w c c}w )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   2   K   | ]  }t        |        y wNcallable).0es     Y/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/plotting/utils.py	<genexpr>z$_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

&
&&u35;;59a)9:D4::u=!-=>D@;35;; ?A ?@@ := ?s   CC?C c           	          | j                  t              }|D ]H  }t        |      }t        t	        d      D cg c]  }t        |       c} }| j                  ||      } J | S c c}w )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.
    r   )findr   iterr   rangenextsubs)set_solnimagesimitss         r   extract_solutionr/   !   se     \\(#F &"X%1+6QR67,,r1%& N 7s   A%
c                 x   t        | t              r| S t        |       } t        |       D ]  \  }}t        |t        t        f      rt        t        |      ddi| |<   4t        |t        t        f      rKt        |      rW|j                  j                  dk(  rt        |t              s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   r3   r3   6   s     $:D$ 
!1a$']1-=u=DGQd,
 %%1:a;OajDG
! K    Nc                     d }t        |       }||j                  |j                               }t        |      |kD  r9t	        ddj                  |      z   dj                  t        |      |      z         t        |      |kD  rt	        dt        |      d|      t               j                  |D cg c]  }|d   	 c}      }t        |      t        |      k7  rt	        d      t        |      |k  rw|j                  |      }	|	t               k7  r|	D ]  }
|j                   ||
              t        |t        |      z
        D ]!  }|j                   |t                            # t        |      |k(  rvt               j                  |D cg c]  }|d   	 c}      }t        |j                  |            dkD  r/t	        d	d
j                  |      z   dj                  |      z         |S c c}w c c}w )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   )symbols    r   <lambda>z _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.   r9   s               r   _create_rangesrO   U   s   . >$U+L#..v{{}=
<4&+22489&&s<'8,GH
 	
 6{T;>v;MO 	O %++V,qt,
-C
3x3v;?@@
6{T))#.ce 4/234 tc&k)* 	6AMM+EG45	6 <D  ekk0A1Q401|&&s+,q0 9@@NO 399#>?  M5 -$ 1s   6G6G;c                 .   t        | t              xr t        |       dk(  xrt t        | j                  d   t               xrT | j                  d   j
                  xr9 t        | j                  d   t               xr | j                  d   j
                  S )zUA range is defined as (symbol, start, end). start and end should
    be numbers.
             )r   r   rC   r8   r4   	is_number)rL   s    r   	_is_rangerU      s     	1e 	EVq[	EAFF1Is++	E121D1D	E AFF1Is++	E 231D1D	r;   c                     | D cg c]  }t        |      s| }}| D cg c]  }t        |t              s| }}|sdn|d   }| D cg c]  }t        |t              s| }}|sdn|d   }| D cg c],  }t        |      xs t        |t        t        f      xs |du  . }}t	        | |      D cg c]
  \  }}|s	| }	}}|	|||fS c c}w c c}w c c}w c c}w c c}}w )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)
    Nr   )rU   r   r4   r5   zip)
r8   trG   labelsrI   rendering_kwr:   resultsbr    s
             r   _unpack_argsr]      s    4 .A1a.F.4AAs!3a4F4DF1IE#;!z!T':A;L;+4aL Y]]STIaLMJq3+$>M19N]G]tW-341aQ3E3&%-- /4; ^3s2   CCCC	CC21C4
C ?C c                 &   | sg S g }|j                  dd      }t        d | d| D              rt        |  \  }}}}	 t               j                  |D 
cg c]  }
|
j
                   c}
 }t        |||||      }|dkD  rt        |      |k(  rt        |      f}|D ]>  }t        |t        t        t        f      }|r|fn|}
|j                  g |
|||	       @ |S t        |  \  }}}}	|r|gng }t        |      t        |      z   |	t        |	      ndz   }|dkD  r| d|  n| }t        |d   t        t        t        f      s|g}|D ]'  }|D cg c]  }t        |t               s| }}|s|}|D cg c]  }t#        |      s| }}|s|j%                         }|D cg c]  }t        |t&              s| }}t        |      dk(  r|	n|d   }t)        |      D cg c]  }||   	 }}t               }t        d |D              r' |j                  |D cg c]  }|j
                   c} }t        |      |k7  rt        |||d|      }|sdn|d   }|j                  g ||||       * |S c c}
w c c}w c c}w c c}w c c}w c c}w )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)]
    rJ   Nc              3   R   K   | ]  }t        |t        t        t        f       ! y wr   )r   r   r   r   r   r:   s     r   r   z#_check_arguments.<locals>.<genexpr>  s     
T!:a$
O<=
Ts   %'rR   r   c              3   4   K   | ]  }t        |         y wr   r   r`   s     r   r   z#_check_arguments.<locals>.<genexpr><  s     0qx{?0s    )getr   r]   r   r   r   rO   rC   r   r   r   r   r   rF   r   r   r4   rU   copyr5   r&   )r8   nexprrH   kwargsoutputrJ   r    rG   rI   rZ   r   r   expris_expr_rY   r*   new_argsargr:   lrL   rend_kwr9   s                           r   _check_argumentsro      s   ` 	FZZ$'F

TtFU|
TT
 .:4-@*vul"su{{U$CQ^^$CDvtUFC19 5zU"u 	>D !j/'JKG"AMM<A<<<|<=	>d MM +7*='66<#& [3v;&".":SC !A4!94
 (1+eU';< zH  	6C6q:a#56A60q9Q<0A0KKM"%=QAt)<q=G=&)'la&7lWQZG $)<0a3q60C05L0C001|11C3PqANN3PQ1v~"34V< !DqtEMM4C4!4U4G45+	6, Mu %DL 7 1 >
 1 4Qs6   I5I:&I:4I?I?!J7JJ	J
)r>   )rb   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"   r/   r3   rO   rU   r]   ro    r;   r   <module>r|      sN    ' "   , , # & / ) % (A&*>CL
#.Lur;   