
    \h>                    @   % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSK	J
r
Jr   " S S\5      rSS jrSS	 jrS
 r\" \R$                  " S5      S-  5      S-   r\" \R*                  SS5      r/ qS\S'   SqS rS rS rSS jrSS jrS rS r SS jr!S r"S S jr#g)!z;Miscellaneous stuff that does not really fit anywhere else.    )annotationsN)filldedentc                      \ rS rSrSrg)Undecidable    N)__name__
__module____qualname____firstlineno____static_attributes__r	       L/var/www/auris/envauris/lib/python3.13/site-packages/sympy/utilities/misc.pyr   r      s     	r   r   c                f    S[        [        [        U 5      5      R                  S5      4SU0UD6-   $ )a  
Strips leading and trailing empty lines from a copy of ``s``, then dedents,
fills and returns it.

Empty line stripping serves to deal with docstrings like this one that
start with a newline after the initial triple quote, inserting an empty
line at the beginning of the string.

Additional keyword arguments will be passed to ``textwrap.fill()``.

See Also
========
strlines, rawlines


width)r   r   strstrip)swkwargss      r   
filldedentr      s1      $vc!f~++D1EEfEEEr   Fc                   [        U [        5      (       d  [        S5      eSU ;   a  [        U 5      $ [	        U 5      R                  S5      (       a  SOSnU4S-  nSU ;   a  SU-  nSU-  nUS	-  nOS
U-  nSU-  nUS-  n/ nU (       a!  UR                  U SU 5        XS n U (       a  M!  U(       a'  [        U5      S:X  a  XFS   -  R                  5       S   $ XER                  U5      -  $ )a  Return a cut-and-pastable string that, when printed, is
equivalent to the input.  The lines will be surrounded by
parentheses and no line will be longer than c (default 64)
characters. If the line contains newlines characters, the
`rawlines` result will be returned.  If ``short`` is True
(default is False) then if there is one line it will be
returned without bounding parentheses.

Examples
========

>>> from sympy.utilities.misc import strlines
>>> q = 'this is a long string that should be broken into shorter lines'
>>> print(strlines(q, 40))
(
'this is a long string that should be b'
'roken into shorter lines'
)
>>> q == (
... 'this is a long string that should be b'
... 'roken into shorter lines'
... )
True

See Also
========
filldedent, rawlines
zexpecting string inputr   "'   \z(
r%s%%s%s
)z%s
r%s   z(
%s%%s%s
)z%s
%sN   r   )

isinstancer   
ValueErrorrawlinesrepr
startswithappendlen
splitlinesjoin)r   cshortqmjouts          r   strlinesr0   &   s    : a122qy{Aw!!#&&CA	
QAqyq M	QaqL	Q
C


1Ra5
B% ! SQF
&&(++vvc{?r   c                2   U R                  S5      n[        U5      S:X  a  [        US   5      $ SU ;   SU ;   /n[        S U 5       5      (       d  SU ;   d  [	        U5      (       a  / nU R                  S5      n[        U5      S-
  n[        U5       HJ  u  pgXe:w  d  U(       a  UR                  [        US-   5      5        M0  UR                  [        U5      5        ML     SS	R                  U5      -  $ S	R                  U5      nUS   (       a  S
U-  $ SU-  $ )a  Return a cut-and-pastable string that, when printed, is equivalent
to the input. Use this when there is more than one line in the
string. The string returned is formatted so it can be indented
nicely within tests; in some cases it is wrapped in the dedent
function which has to be imported from textwrap.

Examples
========

Note: because there are characters in the examples below that need
to be escaped because they are themselves within a triple quoted
docstring, expressions below look more complicated than they would
be if they were printed in an interpreter window.

>>> from sympy.utilities.misc import rawlines
>>> from sympy import TableForm
>>> s = str(TableForm([[1, 10]], headings=(None, ['a', 'bee'])))
>>> print(rawlines(s))
(
    'a bee\n'
    '-----\n'
    '1 10 '
)
>>> print(rawlines('''this
... that'''))
dedent('''\
    this
    that''')

>>> print(rawlines('''this
... that
... '''))
dedent('''\
    this
    that
    ''')

>>> s = """this
... is a triple '''
... """
>>> print(rawlines(s))
dedent("""\
    this
    is a triple '''
    """)

>>> print(rawlines('''this
... that
...     '''))
(
    'this\n'
    'that\n'
    '    '
)

See Also
========
filldedent, strlines
r   r    r   z'''z"""c              3  B   #    U  H  oR                  S 5      v   M     g7f) N)endswith).0lis     r   	<genexpr>rawlines.<locals>.<genexpr>   s     
,e;;ses   r   z
(
    %s
)z
    zdedent("""\
    %s""")zdedent('''\
    %s'''))	splitr'   r$   anyallr4   	enumerater&   r)   )r   linestriplervtrailinglastir6   s           r   r#   r#   Z   s    x GGDME
5zQE!H~qj%1*%F

,e
,,,	S[[::d#5zA~u%EAyH		$rDy/*		$r(#	 &
 b 111]]5!!9-22-22r   P   z-bithash_randomizationz	list[str]
_debug_tmpc                <   ^ ^ SSK Jn  U(       d  T $ S mU U4S jnU$ )zIf SYMPY_DEBUG is True, it will print a nice execution tree with
arguments and results of all decorated functions, else do nothing.
r   SYMPY_DEBUGc                   [         n/ q [        S-  qS nU " U0 UD6n[        S-  qU R                  < U< SU< S3n[         / :w  a  Xd" [         5      -  nUq [         R                  U5        [        S:X  a  [	        [         S   5        / q U$ )Nr    c                    SS jn[        U 5      S:X  a  g/ nU S S  H  nUR                  U" U5      5        M     UR                  U" U S   S5      5        SR                  U5      $ )Nc                    U R                  S5      nSUS   -  nUSS   H#  nUS:X  a  M  US:X  a
  USU-  -  nM  USU-  -  nM%     U$ )Nr   z+-%s
r   r     z| %s
z  %s
)r9   )r   variantxras        r   indent?debug_decorator.<locals>.maketree.<locals>.tree.<locals>.indent   s`    GGDMqtO12ABw !|X\)X\)  r   r   rM   r   )r    )r'   r&   r)   )subtreesrR   frQ   s       r   tree/debug_decorator.<locals>.maketree.<locals>.tree   sb    
 8}!Acr]# #HHVHRL!,-771:r   z = r   r   )rF   _debug_iterr
   r&   print)rV   argskwoldtmprW   rP   r   s          r   maketree!debug_decorator.<locals>.maketree   s    
q	6 tNrNqZZq1j!!A
!!*Q- Jr   c                    > T" T/U Q70 UD6$ Nr	   )r[   r   funcr^   s     r   	decorated"debug_decorator.<locals>.decorated   s    .t.v..r   )sympyrI   )rb   rI   rc   r^   s   `  @r   debug_decoratorrf      s#     ",\/ r   c                 R    SSK Jn  U(       a  [        U S[        R                  06  gg)z:
Print ``*args`` if SYMPY_DEBUG is True, else do nothing.
r   rH   fileNre   rI   rZ   sysstderr)r[   rI   s     r   debugrl      s      "t%#**% r   c                T    SSK Jn  U(       a  [        X-  [        R                  S9  gg)z}
Print ``string%args`` if SYMPY_DEBUG is True, else do nothing. This is
intended for debug messages using formatted strings.
r   rH   )rh   Nri   )stringr[   rI   s      r   debugfro      s    
 "fk

+ r   c                4   SSK Jn  U" SSSS9  Uc  [        R                  S   nUR	                  [        R
                  5      nS	/n[        R                  S
:X  a.  [        R                  R                  U 5      u  pVU(       d  U S-   n O[        R                  S:X  au  [        R                  S   R                  5       R	                  [        R
                  5      n[        R                  R                  U 5      u  pVUR                  5       U;  a  UnU H  nX-   n[        R                  R                  U5      (       a  Us  $ U HL  n	[        R                  R                  X5      n
[        R                  R                  U
5      (       d  MH  U
s  s  $    M     g)zTry to find 'executable' in the directories listed in 'path' (a
string listing directories separated by 'os.pathsep'; defaults to
os.environ['PATH']).  Returns the complete filename or None if not
found
r    )sympy_deprecation_warningz
        sympy.utilities.misc.find_executable() is deprecated. Use the standard
        library shutil.which() function instead.
        z1.7zdeprecated-find-executable)deprecated_since_versionactive_deprecations_targetNPATHrM   os2z.exewin32PATHEXT)
exceptionsrq   osenvironr9   pathsepnamepathsplitextrj   platformlowerisfiler)   )
executabler}   rq   pathsextlistbaseextpathextexecnameprV   s              r   find_executabler     s:    6	 "'#? |zz&!JJrzz"EdG	ww%gg&&z2 #f,J		 **Y'--/55bjjAgg&&z299;g%G#77>>(##OGGLL-77>>!$$H   r   c                   SSSSSSS.n[        U 5      n[        U5      R                  S5      (       a0  [        U5      R                  S	5      S
   R                  S	5      S   nON[        U5      R                  S5      (       a/  [        U5      R                  S	5      S
   R                  S	5      S   n[	        [	        U SU 5      SU5      nSU;   a  UR                  S5      S   nU(       a  UR                  XD5      nU$ )a  Return function name of `x` (if defined) else the `type(x)`.
If short is True and there is a shorter alias for the result,
return the alias.

Examples
========

>>> from sympy.utilities.misc import func_name
>>> from sympy import Matrix
>>> from sympy.abc import x
>>> func_name(Matrix.eye(3))
'MutableDenseMatrix'
>>> func_name(x < 1)
'StrictLessThan'
>>> func_name(x < 1, short=True)
'Lt'
GeGtLeLtEqNe)GreaterThanStrictGreaterThanLessThanStrictLessThanEquality
Unequalityz<type 'r   r    r   z<class 'rb   r
   .rT   )typer   r%   r9   getattrget)rO   r+   aliastypr?   s        r   	func_namer   0  s    & E q'C
3x9%%#hnnS!!$**3/2	S		Z	(	(#hnnS!!$**3/2	FA&
C	8B
byXXc]2YYrIr   c                  ^ ^^ T (       d  S $ U 4S jm[         R                  " SR                  T R                  5        VVs/ s H  u  p[         R                  " U5      PM     snn5      [         R
                  5      mUU4S j$ s  snnf )a)  Return a function that can make the replacements, given in
``reps``, on a string. The replacements should be given as mapping.

Examples
========

>>> from sympy.utilities.misc import _replace
>>> f = _replace(dict(foo='bar', d='t'))
>>> f('food')
'bart'
>>> f = _replace({})
>>> f('food')
'food'
c                    U $ ra   r	   )rO   s    r   <lambda>_replace.<locals>.<lambda>g  s    r   c                ,   > TU R                  S5         $ )Nr   )group)matchrepss    r   r   r   h  s    d5;;q>*r   |c                (   > TR                  TU 5      $ ra   )sub)rn   Dpatterns    r   r   r   k  s    '++a0r   )_recompiler)   itemsescape	MULTILINE)r   kvr   r   s   `  @@r   _replacer   W  sa     *Akk#((#'::<0<41A<0236==BG00 	1s   "Bc                    [        U5      S:X  a,  US   n[        U[        5      (       a  UnOU R                  " U6 $ [        U5      n[	        U5      " U 5      $ )a  Return ``string`` with all keys in ``reps`` replaced with
their corresponding values, longer strings first, irrespective
of the order they are given.  ``reps`` may be passed as tuples
or a single mapping.

Examples
========

>>> from sympy.utilities.misc import replace
>>> replace('foo', {'oo': 'ar', 'f': 'b'})
'bar'
>>> replace("spamham sha", ("spam", "eggs"), ("sha","md5"))
'eggsham md5'

There is no guarantee that a unique answer will be
obtained if keys in a mapping overlap (i.e. are the same
length and have some identical sequence at the
beginning/end):

>>> reps = [
...     ('ab', 'x'),
...     ('bc', 'y')]
>>> replace('abc', *reps) in ('xc', 'ay')
True

References
==========

.. [1] https://stackoverflow.com/questions/6116978/how-to-replace-multiple-substrings-of-a-string
r    r   )r'   r!   dictreplacer   )rn   r   kvs      r   r   r   n  sQ    > 4yA~!Wb$D>>2&&DzD>&!!r   c                   0 nUc  Ub  [        SU-  5      eUc  U $ UnS=pO[        U[        5      (       a  0 n[        UR	                  5       5       H:  n[        U5      S:X  d  M  [        X   5      S:X  d  M'  UR                  U5      XV'   M<     UnUnU(       aB  [        [        UR                  5       6 5       Vs/ s H  nSR                  U5      PM     snu  pO'S=pO#[        U5      [        U5      :w  a  [        S5      eU(       a(  [        R                  SSU5      nU R                  U5      n [        X5      n [        R                  X5      n	U R                  U	5      $ s  snf )ad  Return ``s`` where characters have been replaced or deleted.

SYNTAX
======

translate(s, None, deletechars):
    all characters in ``deletechars`` are deleted
translate(s, map [,deletechars]):
    all characters in ``deletechars`` (if provided) are deleted
    then the replacements defined by map are made; if the keys
    of map are strings then the longer ones are handled first.
    Multicharacter deletions should have a value of ''.
translate(s, oldchars, newchars, deletechars)
    all characters in ``deletechars`` are deleted
    then each character in ``oldchars`` is replaced with the
    corresponding character in ``newchars``

Examples
========

>>> from sympy.utilities.misc import translate
>>> abc = 'abc'
>>> translate(abc, None, 'a')
'bc'
>>> translate(abc, {'a': 'x'}, 'c')
'xb'
>>> translate(abc, {'abc': 'x', 'a': 'y'})
'x'

>>> translate('abcd', 'ac', 'AC', 'd')
'AbC'

There is no guarantee that a unique answer will be
obtained if keys in a mapping overlap are the same
length and have some identical sequences at the
beginning/end:

>>> translate(abc, {'ab': 'x', 'bc': 'y'}) in ('xc', 'ay')
True
z6c should be None when a=None is passed, instead got %srM   r    z,oldchars and newchars have different lengths)r"   r!   r   listkeysr'   popzipr   r)   r   	maketrans	translater   )
r   rQ   br*   mrr+   r   rB   valns
             r   r   r     s>   T 
By=UXYYZZ9H
AaE!&&(^q6Q;3qt9> uuQxEH $ BA,0ekkm1D,EF,Eq
,EF1
AVs1vKLLmmBA&KKAaA;;q> Gs   <E$c                    [        U 5      n[        U5      S-  nSUs=::  a  S::  a  O  OSnO&US-  S:X  a  SnOUS-  S:X  a  S	nOUS-  S
:X  a  SnOSn[        U5      U-   $ )z=Return ordinal number string of num, e.g. 1 becomes 1st.
    d      r   th
   r    str   ndr   rd)as_intabsr   )numr   r   suffixs       r   ordinalr     sm     	sAAA	Q}"}	
R1	
R1	
R1q6F?r   c                4   U(       a2   [        U [        5      (       a  [        e[        R                  " U 5      $  [        U 5      nX-
  (       a  [        U < S35      eU$ ! [         a    [        U < S35      ef = f! [         a    [        U < S35      ef = f)a   
Convert the argument to a builtin integer.

The return value is guaranteed to be equal to the input. ValueError is
raised if the input has a non-integral value. When ``strict`` is True, this
uses `__index__ <https://docs.python.org/3/reference/datamodel.html#object.__index__>`_
and when it is False it uses ``int``.


Examples
========

>>> from sympy.utilities.misc import as_int
>>> from sympy import sqrt, S

The function is primarily concerned with sanitizing input for
functions that need to work with builtin integers, so anything that
is unambiguously an integer should be returned as an int:

>>> as_int(S(3))
3

Floats, being of limited precision, are not assumed to be exact and
will raise an error unless the ``strict`` flag is False. This
precision issue becomes apparent for large floating point numbers:

>>> big = 1e23
>>> type(big) is float
True
>>> big == int(big)
True
>>> as_int(big)
Traceback (most recent call last):
...
ValueError: ... is not an integer
>>> as_int(big, strict=False)
99999999999999991611392

Input that might be a complex representation of an integer value is
also rejected by default:

>>> one = sqrt(3 + 2*sqrt(2)) - sqrt(2)
>>> int(one) == 1
True
>>> as_int(one)
Traceback (most recent call last):
...
ValueError: ... is not an integer
z is not an integer)r!   bool	TypeErroroperatorindexr"   int)r   strictresults      r   r   r     s    d 	<!T"">>!$$	<VF :q:;;  	<q:;;	<
  	<q:;;	<s   0A  A=  A:=B)F   )@   Fra   )F)NN)T)$__doc__
__future__r   r   rj   ry   rer   structtextwrapr   r   r"   r   r   r0   r#   r   calcsizeARCHr   flagsHASH_RANDOMIZATIONrF   __annotations__rY   rf   rl   ro   r   r   r   r   r   r   r   r	   r   r   <module>r      s    A "  
 	   !	* 	F&1hP3d 6??3!#$v- SYY(<eD 
I :z&,(V$N1.'"TFR&@r   