
    wg)s                       d dl mZ ddlmZmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZ ddlmZmZ dd	lmZ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m Z  d dl!m"Z" d dl#Z#d dl$Z%d dl&Z&d dl'm(Z( d dl)m*Z*  G d de      Z+d Z,d%dZ-de.dfdZ/e/Z0 G d dee      Z1 G d de1      Z2 G d de1      Z3 e%jh                  d       Z5e1d!d&d"Z6d# Z7d$ Z8y)'    )annotations   )	StdFactKB_assume_defined)BasicAtom)cacheit)Tuple)Expr
AtomicExpr)AppliedUndefFunctionClass)
NumberKindUndefinedKind)
fuzzy_bool)S)ordered)sympify)Boolean)siftis_sequence)
filldedentN)product)Anyc                  &    e Zd ZdZdZd Zd Zd Zy)Stra.  
    Represents string in SymPy.

    Explanation
    ===========

    Previously, ``Symbol`` was used where string is needed in ``args`` of SymPy
    objects, e.g. denoting the name of the instance. However, since ``Symbol``
    represents mathematical scalar, this class should be used instead.

    namec                    t        |t              s t        dt        t	        |            z        t        j                  | fi |}||_        |S )Nname should be a string, not %s)
isinstancestr	TypeErrorreprtyper   __new__r   )clsr   kwargsobjs       V/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/core/symbol.pyr&   zStr.__new__'   sE    $$=T$Z@PPQQll3)&)
    c                    | j                   fS Nr   selfs    r*   __getnewargs__zStr.__getnewargs__.       		|r+   c                    | j                   fS r-   r   r.   s    r*   _hashable_contentzStr._hashable_content1   r1   r+   N)__name__
__module____qualname____doc__	__slots__r&   r0   r3    r+   r*   r   r      s    
 Ir+   r   c                    t        t        t        | j                         d d            \  }}t        j                  |       ||fS )zSplit the given dict into assumptions and non-assumptions.
    Keys are taken as assumptions if they correspond to an
    entry in ``_assume_defined``.
    c                    | d   t         v S )Nr   )r   )is    r*   <lambda>z%_filter_assumptions.<locals>.<lambda>;   s    !A$/) r+   T)binary)mapdictr   itemsSymbol	_sanitize)r(   assumptionsnonassumptionss      r*   _filter_assumptionsrF   5   sE    
 #&dD)- #K [!&&r+   c                    t        | t              r|r|j                  | k(  r|S t        | fi |S t        | t              r| S t	        d      )a  Return s if s is a Symbol, else if s is a string, return either
    the matching_symbol if the names are the same or else a new symbol
    with the same assumptions as the matching symbol (or the
    assumptions as provided).

    Examples
    ========

    >>> from sympy import Symbol
    >>> from sympy.core.symbol import _symbol
    >>> _symbol('y')
    y
    >>> _.is_real is None
    True
    >>> _symbol('y', real=True).is_real
    True

    >>> x = Symbol('x')
    >>> _symbol(x, real=True)
    x
    >>> _.is_real is None  # ignore attribute if s is a Symbol
    True

    Below, the variable sym has the name 'foo':

    >>> sym = Symbol('foo', real=True)

    Since 'x' is not the same as sym's name, a new symbol is created:

    >>> _symbol('x', sym).name
    'x'

    It will acquire any assumptions give:

    >>> _symbol('x', sym, real=False).is_real
    False

    Since 'foo' is the same as sym's name, sym is returned

    >>> _symbol('foo', sym)
    foo

    Any assumptions given are ignored:

    >>> _symbol('foo', sym, real=False).is_real
    True

    NB: the symbol here may not be the same as a symbol with the same
    name defined elsewhere as a result of different assumptions.

    See Also
    ========

    sympy.core.symbol.Symbol

    z/symbol must be string for symbol name or Symbol)r!   r"   r   rB   
ValueError)smatching_symbolrD   s      r*   _symbolrK   @   sP    r !S33q8""a';''	Av	JKKr+   r9   c           
     8  
 dd}d}t        |       r| \  } } |       
|st        
|fi |S t        |      s|g}t               j                  |D cg c](  }|j	                  t
              D ]  }|j                   * c}}|D cg c]2  }|j	                  t              D ]  }|j                  j                   4 c}}z         }	||}t        
fd|	D              r |
      
t        
fd|	D              rt        
|fi |S c c}}w c c}}w )a~  
    Return a symbol whose name is derivated from *xname* but is unique
    from any other symbols in *exprs*.

    *xname* and symbol names in *exprs* are passed to *compare* to be
    converted to comparable forms. If ``compare(xname)`` is not unique,
    it is recursively passed to *modify* until unique name is acquired.

    Parameters
    ==========

    xname : str or Symbol
        Base name for the new symbol.

    exprs : Expr or iterable of Expr
        Expressions whose symbols are compared to *xname*.

    compare : function
        Unary function which transforms *xname* and symbol names from
        *exprs* to comparable form.

    modify : function
        Unary function which modifies the string. Default is appending
        the number, or increasing the number if exists.

    Examples
    ========

    By default, a number is appended to *xname* to generate unique name.
    If the number already exists, it is recursively increased.

    >>> from sympy.core.symbol import uniquely_named_symbol, Symbol
    >>> uniquely_named_symbol('x', Symbol('x'))
    x0
    >>> uniquely_named_symbol('x', (Symbol('x'), Symbol('x0')))
    x1
    >>> uniquely_named_symbol('x0', (Symbol('x1'), Symbol('x0')))
    x2

    Name generation can be controlled by passing *modify* parameter.

    >>> from sympy.abc import x
    >>> uniquely_named_symbol('x', x, modify=lambda s: 2*s)
    xx

    c                    | st        |      S t        |       dz
  }|dk7  r| |   j                         sn|dz  }|dk7  rt        t        | |dz   d  xs |dz
        dz         }| d |dz    |z   S )Nr   )r"   lenisdigitint)rI   startr<   ns       r*   numbered_string_incrz3uniquely_named_symbol.<locals>.numbered_string_incr   s    u:FQJ2gQ4<<>FA 2g Aa!efI*+a/0!a%y1}r+   Nc              3  4   K   | ]  } |      k(    y wr-   r9   ).0rI   comparexs     r*   	<genexpr>z(uniquely_named_symbol.<locals>.<genexpr>   s     -!a71:o-s   )r   )
r   rK   setunionatomsrB   r   r   funcany)xnameexprsrW   modifyrD   rT   defaulter<   namesrX   s     `       @r*   uniquely_named_symbolre      s   ^	 G5wAq'1[11uEKK8A8188#CQWW\-BCCC	DEE ~%
-u-
-1I -u-
-1g--- 	9Cs   -D
7Dc                     e Zd ZU dZdZdZded<   dZdZe	d        Z
e	d        Zedd
       Zd Zd Zed        Zeed               Zd Zd Zd Zd Zd Ze	d        Zedd       Zd ZddZd Ze	d        ZeZd Zy	)rB   u  
    Symbol class is used to create symbolic variables.

    Explanation
    ===========

    Symbolic variables are placeholders for mathematical symbols that can represent numbers, constants, or any other mathematical entities and can be used in mathematical expressions and to perform symbolic computations.

    Assumptions:

    commutative = True
    positive = True
    real = True
    imaginary = True
    complex = True
    complete list of more assumptions- :ref:`predicates`

    You can override the default assumptions in the constructor.

    Examples
    ========

    >>> from sympy import Symbol
    >>> x = Symbol("x", positive=True)
    >>> x.is_positive
    True
    >>> x.is_negative
    False

    passing in greek letters:

    >>> from sympy import Symbol
    >>> alpha = Symbol('alpha')
    >>> alpha #doctest: +SKIP
    α

    Trailing digits are automatically treated like subscripts of what precedes them in the name.
    General format to add subscript to a symbol :
    ``<var_name> = Symbol('<symbol_name>_<subscript>')``

    >>> from sympy import Symbol
    >>> alpha_i = Symbol('alpha_i')
    >>> alpha_i #doctest: +SKIP
    αᵢ

    Parameters
    ==========

    AtomicExpr: variable name
    Boolean: Assumption with a boolean value(True or False)
    F)r   _assumptions_orig_assumptions0r"   r   Tc                2    | j                   rt        S t        S r-   )is_commutativer   r   r.   s    r*   kindzSymbol.kind  s    r+   c                     y)zAllow derivatives wrt Symbols.

        Examples
        ========

        >>> from sympy import Symbol
        >>> x = Symbol('x')
        >>> x._diff_wrt
        True
        Tr9   r.   s    r*   	_diff_wrtzSymbol._diff_wrt  s     r+   Nc                
   t        | j                  dd            }|!|rd|j                  z  nd}t        d|z        t	        | j                               D ])  }| |   }|| j                  |       t        |      | |<   + y)zMRemove None, convert values to bool, check commutativity *in place*.
        commutativeTNz%s  z&%scommutativity must be True or False.)r   getr4   rH   listkeyspopbool)rD   r)   rj   whosekeyvs         r*   rC   zSymbol._sanitize   s     $KOOM4$HI!,/ECLL(RE85@B B ((*+ 	'CC Ay$#AwK	'r+   c                    | j                   }t        |      t        |      z  D ]0  }||   ||   k7  st        t        d|d||   d||                |j	                  |       |S )Nz2
                    non-matching assumptions for z(: existing value
                    is z and new value is )assumptions0rZ   rH   r   update)r/   rD   baseks       r*   _mergezSymbol._merge4  sw      [!CI- 	2A1~a(  tAwA-0 "1 2 2	2 	K r+   c                T    | j                  ||        t        j                  | |fi |S )zSymbols are identified by name and assumptions::

        >>> from sympy import Symbol
        >>> Symbol("x") == Symbol("x")
        True
        >>> Symbol("x", real=True) == Symbol("x", real=False)
        False

        )rC   rB   _Symbol__xnew_cached_r'   r   rD   s      r*   r&   zSymbol.__new__?  s*     	k3'$$S$>+>>r+   c                8   t        |t              s t        dt        t	        |            z        |j                         }|j                  dd       t        |      }t        |      }t        j                  |       }||_        ||_        ||_        ||_        |S )Nr    ro   T)r!   r"   r#   r$   r%   copy
setdefaultr   r@   r   r&   r   _assumptionsrg   rh   )r'   r   rD   assumptions_origassumptions_kbrz   r)   s          r*   __xnew__zSymbol.__xnew__L  s    $$=T$Z@PPQQ '++- 	}d3";/N+ll3) 0(& 
r+   c                0    t        j                  | |fi |S r-   )rB   r   r   s      r*   __xnew_cached_zSymbol.__xnew_cached_z  s     sD8K88r+   c                4    | j                   f| j                  fS r-   )r   rg   r.   s    r*   __getnewargs_ex__zSymbol.__getnewargs_ex__  s    d4455r+   c                N    |j                         D ]  \  }}t        | ||        y r-   )rA   setattr)r/   stater   values       r*   __setstate__zSymbol.__setstate__  s'     ;;= 	'KD%D$&	'r+   c                v    | j                   ft        t        | j                  j	                                     z   S r-   )r   tuplesortedrz   rA   r.   s    r*   r3   zSymbol._hashable_content  s,    		|eF4+<+<+B+B+D$EFFFr+   c                z    |j                   r/ddlm}  || t        j                  d      j                  ||      S y )Nr   )PowF)evaluate)is_Powsympy.core.powerr   r   One
_eval_subs)r/   oldnewr   s       r*   r   zSymbol._eval_subs  s1    ::,tQUUU3>>sCHH r+   c                    | S r-   r9   )r/   rD   s     r*   _eval_refinezSymbol._eval_refine  s    r+   c                6    | j                   j                         S r-   )rh   r   r.   s    r*   rz   zSymbol.assumptions0  s    !!&&((r+   c                    | j                         d| j                  fft        j                  j	                         t        j                  fS )Nr   )	class_keyr   r   r   sort_keyr/   orders     r*   r   zSymbol.sort_key  s2    ~~!dii\!2AEENN4DaeeKKr+   c                    | j                   durt        | j                        S t        | j                  | j                         S )NF)ro   )rj   Dummyr   r.   s    r*   as_dummyzSymbol.as_dummy  s;    #'#6#6e#CuTYY 	Ctyyd.A.AB	Cr+   c                \    |j                  d      | k(  ry ddlm}m}  ||        ||       fS )Nignorer   )imre)rq   $sympy.functions.elementary.complexesr   r   )r/   deephintsr   r   s        r*   as_real_imagzSymbol.as_real_imag  s,    99X$&CtHbh''r+   c                    |sy| |vS NFr9   )r/   wrtflagss      r*   is_constantzSymbol.is_constant  s    3r+   c                    | hS r-   r9   r.   s    r*   free_symbolszSymbol.free_symbols  s	    vr+   c                "    t         j                  S r-   )r   UniversalSetr.   s    r*   as_setzSymbol.as_set  s    ~~r+   r-   )T) r4   r5   r6   r7   is_comparabler8   __annotations__	is_Symbol	is_symbolpropertyrk   rm   staticmethodrC   r~   r&   r   r	   r   r   r   r3   r   r   rz   r   r   r   r   r   binary_symbolsr   r9   r+   r*   rB   rB      s   2h M>I
III 
   ' '&	? + +Z 9  96'GI
 ) ) L LC
(
   "Nr+   rB   c                      e Zd ZdZdZ ej                         Zej                  dd      Z	dZ
dZddZd	 Zedd
       Zd Zy)r   a  Dummy symbols are each unique, even if they have the same name:

    Examples
    ========

    >>> from sympy import Dummy
    >>> Dummy("x") == Dummy("x")
    False

    If a name is not supplied then a string value of an internal count will be
    used. This is useful when a temporary variable is needed and the name
    of the variable used in the expression is not important.

    >>> Dummy() #doctest: +SKIP
    _Dummy_10

    r   i@B i@T )dummy_indexTNc                0   |	|J d       |dt        t        j                        z   }|:t        j                  t        j                  z   }t        xj                  dz  c_        | j	                  ||        t        j                  | |fi |}||_        |S )Nz:If you specify a dummy_index, you must also provide a nameDummy_r   )r"   r   _count_base_dummy_indexrC   rB   r   r   )r'   r   r   rD   r)   s        r*   r&   zDummy.__new__  s    "#a%aa#<c%,,//D11ELL@KLLALk3'ooc47;7%
r+   c                J    | j                   | j                  f| j                  fS r-   )r   r   rg   r.   s    r*   r   zDummy.__getnewargs_ex__  s"    D,,-t/E/EFFr+   c                    | j                         d| j                  | j                  fft        j                  j                         t        j                  fS )N   )r   r   r   r   r   r   r   s     r*   r   zDummy.sort_key  sE    ~~		4++,"./0uu~~/?G 	Gr+   c                H    t         j                  |       | j                  fz   S r-   )rB   r3   r   r.   s    r*   r3   zDummy._hashable_content  s!    ''-1A1A0CCCr+   )NNr-   )r4   r5   r6   r7   r   randomRandom_prngrandintr   r8   is_Dummyr&   r   r	   r   r3   r9   r+   r*   r   r     s]    : FFMMOEeW5 IH$G G GDr+   r   c                  Z     e Zd ZdZdZdZd	dZd Zee	d               Z
 fdZd
dZ xZS )Wilda	  
    A Wild symbol matches anything, or anything
    without whatever is explicitly excluded.

    Parameters
    ==========

    name : str
        Name of the Wild instance.

    exclude : iterable, optional
        Instances in ``exclude`` will not be matched.

    properties : iterable of functions, optional
        Functions, each taking an expressions as input
        and returns a ``bool``. All functions in ``properties``
        need to return ``True`` in order for the Wild instance
        to match the expression.

    Examples
    ========

    >>> from sympy import Wild, WildFunction, cos, pi
    >>> from sympy.abc import x, y, z
    >>> a = Wild('a')
    >>> x.match(a)
    {a_: x}
    >>> pi.match(a)
    {a_: pi}
    >>> (3*x**2).match(a*x)
    {a_: 3*x}
    >>> cos(x).match(a)
    {a_: cos(x)}
    >>> b = Wild('b', exclude=[x])
    >>> (3*x**2).match(b*x)
    >>> b.match(a)
    {a_: b_}
    >>> A = WildFunction('A')
    >>> A.match(a)
    {a_: A_}

    Tips
    ====

    When using Wild, be sure to use the exclude
    keyword to make the pattern more precise.
    Without the exclude pattern, you may get matches
    that are technically correct, but not what you
    wanted. For example, using the above without
    exclude:

    >>> from sympy import symbols
    >>> a, b = symbols('a b', cls=Wild)
    >>> (2 + 3*y).match(a*x + b*y)
    {a_: 2/x, b_: 3}

    This is technically correct, because
    (2/x)*x + 3*y == 2 + 3*y, but you probably
    wanted it to not match at all. The issue is that
    you really did not want a and b to include x and y,
    and the exclude parameter lets you specify exactly
    this.  With the exclude parameter, the pattern will
    not match.

    >>> a = Wild('a', exclude=[x, y])
    >>> b = Wild('b', exclude=[x, y])
    >>> (2 + 3*y).match(a*x + b*y)

    Exclude also helps remove ambiguity from matches.

    >>> E = 2*x**3*y*z
    >>> a, b = symbols('a b', cls=Wild)
    >>> E.match(a*b)
    {a_: 2*y*z, b_: x**3}
    >>> a = Wild('a', exclude=[x, y])
    >>> E.match(a*b)
    {a_: z, b_: 2*x**3*y}
    >>> a = Wild('a', exclude=[x, y, z])
    >>> E.match(a*b)
    {a_: 2, b_: x**3*y*z}

    Wild also accepts a ``properties`` parameter:

    >>> a = Wild('a', properties=[lambda k: k.is_Integer])
    >>> E.match(a*b)
    {a_: 2, b_: x**3*y*z}

    T)exclude
propertiesc                    t        |D cg c]  }t        |       c}      }t        |      }| j                  ||        t        j                  | |||fi |S c c}w r-   )r   r   rC   r   r   )r'   r   r   r   rD   rX   s         r*   r&   zWild.__new__[  sR    W556:&
k3'}}S$K{KK 6s   Ac                H    | j                   | j                  | j                  fS r-   )r   r   r   r.   s    r*   r0   zWild.__getnewargs__a  s    		4<<99r+   c                P    t        j                  | |fi |}||_        ||_        |S r-   )rB   r   r   r   )r'   r   r   r   rD   r)   s         r*   r   zWild.__xnew__d  s,     ooc47;7#
r+   c                R    t         |          | j                  | j                  fz   S r-   )superr3   r   r   )r/   	__class__s    r*   r3   zWild._hashable_contentl  s#    w(*dllDOO-LLLr+   c                    t        fd| j                  D              ry t        fd| j                  D              sy |i }n|j	                         }|| <   |S )Nc              3  @   K   | ]  }j                  |        y wr-   )has)rV   rX   exprs     r*   rY   zWild.matches.<locals>.<genexpr>q  s     1qtxx{1s   c              3  .   K   | ]  } |        y wr-   r9   )rV   fr   s     r*   rY   zWild.matches.<locals>.<genexpr>s  s     4q1T74s   )r^   r   allr   r   )r/   r   	repl_dictr   s    `  r*   matcheszWild.matchesp  sS    1DLL114DOO44I!(I	$r+   )r9   r9   r   )r4   r5   r6   r7   is_Wildr8   r&   r0   r   r	   r   r3   r   __classcell__)r   s   @r*   r   r     sH    Wp G)IL:   M
r+   r   z"([0-9]*:[0-9]+|[a-zA-Z]?:[a-zA-Z]))r'   c                  g }t        | t              rd}d}g |D ]_  }|| v st        |      | v r|dz  }t        |      | v rt        |      }|dz  }| j                  ||      } j	                  ||dd f       a fd}| j                         } | j                  d      }	|	r| dd j                         } | st        d      | j                  d      D 
cg c]  }
|
j                          } }
t        d	 | D              st        d
      t        t        |       dz
  dd      D ]  }| |   j                         | ||dz     |j                  d|	      }| D ]  }|st        d      d|vr! | ||      fi |}|j	                  |       6t        j                  |      }g }t        t        |      dz
        D ]h  }|sd||   v s||   dk7  s||dz
     j                  d      s/||dz      j                  d      sG||dz
     dd ||dz
  <   ||dz      dd ||dz   <   j |D ]3  }d|v r|j                  d      rt        d      |j                  d      \  }}|d   t         j"                  v rM|sdn
t%        |      }t%        |      }|j	                  t        ||      D cg c]  }t        |       c}       n}|xs d}|j	                  t        t         j&                  j)                  |      t         j&                  j)                  |      dz         D cg c]  }t         j&                  |    c}       |d   r |j	                  |g       6 d}t        |      dk(  r|d   } n$t+        | D cg c]  }dj-                  |       } }r.|j/                  | D cg c]  } | ||      fi | c}       r|j/                  | D cg c]  } ||fi | c}        |st        |      dk  r|sy|d   S t1        |      S | D ]  }|j	                  t3        |fd|i|       !  t5        |       |      S c c}
w c c}w c c}w c c}w c c}w c c}w )a1  
    Transform strings into instances of :class:`Symbol` class.

    :func:`symbols` function returns a sequence of symbols with names taken
    from ``names`` argument, which can be a comma or whitespace delimited
    string, or a sequence of strings::

        >>> from sympy import symbols, Function

        >>> x, y, z = symbols('x,y,z')
        >>> a, b, c = symbols('a b c')

    The type of output is dependent on the properties of input arguments::

        >>> symbols('x')
        x
        >>> symbols('x,')
        (x,)
        >>> symbols('x,y')
        (x, y)
        >>> symbols(('a', 'b', 'c'))
        (a, b, c)
        >>> symbols(['a', 'b', 'c'])
        [a, b, c]
        >>> symbols({'a', 'b', 'c'})
        {a, b, c}

    If an iterable container is needed for a single symbol, set the ``seq``
    argument to ``True`` or terminate the symbol name with a comma::

        >>> symbols('x', seq=True)
        (x,)

    To reduce typing, range syntax is supported to create indexed symbols.
    Ranges are indicated by a colon and the type of range is determined by
    the character to the right of the colon. If the character is a digit
    then all contiguous digits to the left are taken as the nonnegative
    starting value (or 0 if there is no digit left of the colon) and all
    contiguous digits to the right are taken as 1 greater than the ending
    value::

        >>> symbols('x:10')
        (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9)

        >>> symbols('x5:10')
        (x5, x6, x7, x8, x9)
        >>> symbols('x5(:2)')
        (x50, x51)

        >>> symbols('x5:10,y:5')
        (x5, x6, x7, x8, x9, y0, y1, y2, y3, y4)

        >>> symbols(('x5:10', 'y:5'))
        ((x5, x6, x7, x8, x9), (y0, y1, y2, y3, y4))

    If the character to the right of the colon is a letter, then the single
    letter to the left (or 'a' if there is none) is taken as the start
    and all characters in the lexicographic range *through* the letter to
    the right are used as the range::

        >>> symbols('x:z')
        (x, y, z)
        >>> symbols('x:c')  # null range
        ()
        >>> symbols('x(:c)')
        (xa, xb, xc)

        >>> symbols(':c')
        (a, b, c)

        >>> symbols('a:d, x:z')
        (a, b, c, d, x, y, z)

        >>> symbols(('a:d', 'x:z'))
        ((a, b, c, d), (x, y, z))

    Multiple ranges are supported; contiguous numerical ranges should be
    separated by parentheses to disambiguate the ending number of one
    range from the starting number of the next::

        >>> symbols('x:2(1:3)')
        (x01, x02, x11, x12)
        >>> symbols(':3:2')  # parsing is from left to right
        (00, 01, 10, 11, 20, 21)

    Only one pair of parentheses surrounding ranges are removed, so to
    include parentheses around ranges, double them. And to include spaces,
    commas, or colons, escape them with a backslash::

        >>> symbols('x((a:b))')
        (x(a), x(b))
        >>> symbols(r'x(:1\,:2)')  # or r'x((:1)\,(:2))'
        (x(0,0), x(0,1))

    All newly created symbols have assumptions set according to ``args``::

        >>> a = symbols('a', integer=True)
        >>> a.is_integer
        True

        >>> x, y, z = symbols('x,y,z', real=True)
        >>> x.is_real and y.is_real and z.is_real
        True

    Despite its name, :func:`symbols` can create symbol-like objects like
    instances of Function or Wild classes. To achieve this, set ``cls``
    keyword argument to the desired type::

        >>> symbols('f,g,h', cls=Function)
        (f, g, h)

        >>> type(_[0])
        <class 'sympy.core.function.UndefinedFunction'>

    r   )z\,z\:z\ r   Nc                D    rD ]  \  }}| j                  ||      }  | S r-   )replace)rI   clliteralss      r*   literalzsymbols.<locals>.literal  s-    $ (DAq		!QA(Hr+   ,rN   zno symbols givenc              3      K   | ]  }|  y wr-   r9   )rV   rS   s     r*   rY   zsymbols.<locals>.<genexpr>  s     $1$s   zmissing symbol between commasseqzmissing symbol:()zmissing end rangeaTrp   r9   r'   )r!   r"   chrr   appendstripendswithrstriprH   splitr   rangerO   rt   _range
startswithstringdigitsrQ   ascii_lettersindexr   joinextendr   symbolsr%   )rd   r'   argsresultmarker	splitterssplitterlit_charr   as_seqrS   r<   r   r   symbolr   
split_listrI   r   ba_ib_ir   r   s                          @r*   r  r    su   h F%'	*,! 	:H5 &kU*aKF &kU*v;!h98AB< 89	:	 $#2J%%'E/00 %*KK$45q55$e$$<==s5zA~r2. 	/A#Ahnn.E!QUO	/ hhuf% -	CD !122$WT]3d3f%%||D1E*,J3u:>* 4aU1X_a!e--c2a!e//4#(Q<#4E!a%L#(Q<#3E!a%L4  C!8zz#()<==773<DAqu-'(ac!f!!f"))5c?*Ka3q6*KLH"))E"0066q9"0066q9A=M? +@q6+?+?+B +@ A &b>%%qc*#C& z?a'&qME18*1EFARWWQZFEFMME"Jq3wqz#:T#:"JKMM5"Aa3q>D>"AB[-	C^ s6{a'!9V} 	:DMM'$8C8489	: tE{6""E 6F +L+@ G"J"As$   Q-Q#QQ.Q"
Q'
c                .   fdddl m}  |       j                  }	 t        | fi |}|at	        |t
              r||j                  |j                  <   ~|S t	        |t              r||j                  |j                  <   ~|S  ||       ~|S # ~w xY w)a  
    Create symbols and inject them into the global namespace.

    Explanation
    ===========

    This calls :func:`symbols` with the same arguments and puts the results
    into the *global* namespace. It's recommended not to use :func:`var` in
    library code, where :func:`symbols` has to be used::

    Examples
    ========

    >>> from sympy import var

    >>> var('x')
    x
    >>> x # noqa: F821
    x

    >>> var('a,ab,abc')
    (a, ab, abc)
    >>> abc # noqa: F821
    abc

    >>> var('x,y', real=True)
    (x, y)
    >>> x.is_real and y.is_real # noqa: F821
    True

    See :func:`symbols` documentation for more details on what kinds of
    arguments can be passed to :func:`var`.

    c                    | D ]_  }t        |t              r||j                  |j                  <   -t        |t              r||j                  |j
                  <   W ||       a y)z4Recursively inject symbols to the global namespace. N)r!   r   	f_globalsr   r   r4   )r  framer  traverses      r*   r  zvar.<locals>.traversex  sT     	(F&%(/5,FM2390'	(r+   r   )currentframe)
inspectr  f_backr  r!   r   r  r   r   r4   )rd   r  r  r  symsr  s        @r*   varr  U  s    F( %N!!Eu%%$&-1		* K D-015. K	 u%K s   7B )B 	B Bc                    t        |  }d }t        |j                  |      }i }|D ];  }|j                  t	        |      j                  d      g       j                  |       = i }|D ]  }t        d|z  fi ||   d   j                  }||   d   |k7  r||||   d   <   d}	t        dt        ||               D ]9  }
	 d||
|	z   fz  }||vrn|	dz  }	||   |
   }t        |fi |j                  ||<   ;  |j                  |      S )a  
    Return a Tuple containing the passed expressions with symbols
    that appear the same when printed replaced with numerically
    subscripted symbols, and all Dummy symbols replaced with Symbols.

    Parameters
    ==========

    iter: list of symbols or expressions.

    Examples
    ========

    >>> from sympy.core.symbol import disambiguate
    >>> from sympy import Dummy, Symbol, Tuple
    >>> from sympy.abc import y

    >>> tup = Symbol('_x'), Dummy('x'), Dummy('x')
    >>> disambiguate(*tup)
    (x_2, x, x_1)

    >>> eqs = Tuple(Symbol('x')/y, Dummy('x')/y)
    >>> disambiguate(*eqs)
    (x_1/y, x/y)

    >>> ix = Symbol('x', integer=True)
    >>> vx = Symbol('x')
    >>> disambiguate(vx + ix)
    (x + x_1,)

    To make your own mapping of symbols to use, pass only the free symbols
    of the expressions and create a dictionary:

    >>> free = eqs.free_symbols
    >>> mapping = dict(zip(free, disambiguate(*free)))
    >>> eqs.xreplace(mapping)
    (x_1/y, x/y)

    c                Z    t        t        | j                  j                                     S r-   )r   r   rz   rA   )rX   s    r*   r=   zdisambiguate.<locals>.<lambda>  s    5 4 4 678 r+   )rs   _z%sr   r   z%s_%i)r
   r   r   r   r"   lstripr   rB   rz   r   rO   xreplace)iternew_iterrw   r  mappingrI   repsr}   mapk0skipr<   r   kis                r*   disambiguater&    sD   P d|H
8C8((s3DG =3q6==-r299!<=D 7 tqz@WQZ]%?%?@1:a=E!"'DAq#gaj/* 	7A!QX.w&		 
 ABd6boo6DH	77  T""r+   r-   )returnr   )9
__future__r   rD   r   r   basicr   r   cacher	   
containersr
   r   r   r   functionr   r   rk   r   r   logicr   	singletonr   sortingr   r   sympy.logic.boolalgr   sympy.utilities.iterablesr   r   sympy.utilities.miscr   r   r   _rer   	itertoolsr   typingr   r   rF   rK   r"   re   _uniquely_named_symbolrB   r   r   compiler   r  r  r&  r9   r+   r*   <module>r8     s    " 3    " 1 +     ' 7 +     $ 8	'@LD (*3t I.T / iZ iXADF ADH|6 |~ 
9	: ! R#j=~?#r+   