K i>4UdZddlmZddlZddlZddlZddlZddlZddl m Z m Z Gdde Z ddZdd Zd Zeej$d d zd zZeej*ddZgaded<dadZdZdZddZddZdZdZ ddZ!dZ"d dZ#y)!z;Miscellaneous stuff that does not really fit anywhere else.) annotationsN)filldedentc eZdZy) UndecidableN)__name__ __module__ __qualname__Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/utilities/misc.pyrr s r rc fdttt|jdfd|i|zS)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)rrstrstrip)swkwargss r filldedentrs1 $vc!f~++D1EEfE EEr Fct|ts tdd|vr t|St |j drdnd}|fdz}d|vrd|z}d|z}|d z}nd |z}d |z}|dz}g}|r|j |d |||d }|r|r't|d k(r||dzjd S||j|zS)aXReturn 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 zexpecting string inputr"'\z ( r%s%%s%s )z%s r%sz ( %s%%s%s )z%s %sNr) isinstancer ValueErrorrawlinesrepr startswithappendlen splitlinesjoin)rcshortqmjouts r strlinesr-&s: a 122 qy{Aw!!#&CA QA qy q  M Q a  qL Q C  1Ra5 AB%  SQCF &&(++ qvvc{?r c|jd}t|dk(rt|dSd|vd|vg}td|Dsd|vs t |rg}|j d}t|dz }t |D]D\}}||k7s|r|jt|dz+|jt|Fdd j|zSd j|}|drd |zSd |zS) axReturn 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 rrrz'''z"""c3>K|]}|jdyw) N)endswith).0lis r zrawlines..s ,2;;s  ,srz ( %s )z zdedent("""\ %s""")zdedent('''\ %s''')) splitr$r!anyallr1 enumerater#r&)rlinestriplervtrailinglastir3s r r r Zsx GGDME 5zQE!H~qj%1* %F ,e ,, S[ ::d#5zA~u% $EArDyH $rDy/* $r(#  $  b 111 ]]5 ! !9-2 2-2 2r Pz-bithash_randomizationz list[str] _debug_tmpc0ddlm}|sSdfd}|S)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_DEBUGct}gatdz ad}||i|}tdza|j|d|d}tgk7r||tz }|atj|tdk(rt tdga|S)Nrcdd}t|dk(ryg}|ddD]}|j|||j||dddj|S)Nc|jd}d|dz}|ddD]}|dk(r |dk(r |d|zz }|d|zz } |S)Nrz+-%s rrz| %s z %s )r5)rvariantxras r indentz?debug_decorator..maketree..tree..indentseGGDMqtO12*ABw !|X\)X\) *r rrIr)r)r$r#r&)subtreesrNfrMs r treez/debug_decorator..maketree..treesg 8}!Acr] $# $ HHVHRL!, -771: r z = rr)rB _debug_iterrr#print)rQargskwoldtmprRrLrs r maketreez!debug_decorator..maketrees q  6 tNrNq ZZq 1   j! !A ! !  *Q- Jr cg|i|SNr )rUrfuncrXs r decoratedz"debug_decorator..decorateds.t.v..r )sympyrE)r[rEr\rXs` @r debug_decoratorr^s#"  ,\/ r cHddlm}|rt|dtjiyy)zB Print ``*args`` if SYMPY_DEBUG is True, else do nothing. rrDfileNr]rErTsysstderr)rUrEs r debugrds " t%#**%r cRddlm}|rt||ztjyy)z Print ``string%args`` if SYMPY_DEBUG is True, else do nothing. This is intended for debug messages using formatted strings. rrD)r`Nra)stringrUrEs r debugfrgs! " fTk +r cddlm}|ddd|tjd}|j tj }d g}tj d k(r*tjj|\}}|s|d z}ntjd k(rttjd jj tj }tjj|\}}|j|vr|}|D]v}||z}tjj|r|cS|D]G} tjj| |} tjj| sC| ccSxy)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. z1.7zdeprecated-find-executable)deprecated_since_versionactive_deprecations_targetNPATHrIos2z.exewin32PATHEXT) exceptionsriosenvironr5pathsepnamepathsplitextrbplatformlowerisfiler&) executableruripathsextlistbaseextpathextexecnameprQs r find_executablersE 6 "'#?  |zz&! JJrzz "EdG ww%gg&&z2 s#f,J  **Y'--/55bjjAgg&&z2 s 99;g %G# 77>>( #O GGLLH-77>>!$H   r cddddddd}t|}t|jdr0t|jd d jd d }nIt|jd r/t|jd d jd d }t t |d |d|}d|vr|jdd}|r|j ||}|S)aReturn 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' GeGtLeLtEqNe) GreaterThanStrictGreaterThanLessThanStrictLessThanEquality Unequalityz>> from sympy.utilities.misc import _replace >>> f = _replace(dict(foo='bar', d='t')) >>> f('food') 'bart' >>> f = _replace({}) >>> f('food') 'food' c|SrZr )rKs r z_replace..gsr c,|jdS)Nr)group)matchrepss r rz_replace..hsd5;;q>*r |c(j|SrZ)sub)rfDpatterns r rz_replace..ks'++a0r )_recompiler&itemsescape MULTILINE)rkvrrs` @@r _replacerWs_ *Akk#((#'::<041aA0236==BG 00 1sA;ct|dk(r'|d}t|tr|}n|j|St|}t ||S)arReturn ``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 rr)r$rdictreplacer)rfrkvs r rrnsR> 4yA~ !W b$ D!6>>2& &Dz 8D>& !!r ci}||td|z||S|}dx}}nt|tri}t|j D]7}t |dk(st ||dk(s$|j |||<9|}|}|r@tt|jDcgc]}dj|c}\}}n'dx}}n"t |t |k7r td|r(tjdd|}|j|}t||}tj||} |j| Scc}w)aReturn ``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 %srIrz,oldchars and newchars have different lengths)rrrlistkeysr$popziprr&r maketrans translater) rrMbr'mrr(rr>valns r rrsBT By =UXYYZ Z 9H  A a E!&&(^ (q6Q;3qt9> uuQxE!H (BA,0ekkm1D,EFq F1 A Vs1v KL LmmBA& KK 2A aA ;;q>Gs,Ect|}t|dz}d|cxkrdkrnnd}n#|dzdk(rd}n|dzdk(rd }n |dzd k(rd }nd}t||zS) z=Return ordinal number string of num, e.g. 1 becomes 1st. d th rstrndrrd)as_intabsr)numrrsuffixs r ordinalrsm s A A A Q}"} R1 R1 R1 q6F?r c |r, t|trttj|S t |}||z rt |d|S#t$rt |dwxYw#t$rt |dwxYw)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__ `_ 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)rbool TypeErroroperatorindexrint)rstrictresults r rrsd <!T">>!$ $ <VF v:q:; ;  <q:; ; <  <q:; ; rsA"  ! * F&1hP3d ?6??3 ! #$v-SYY(