K iddlmZddlmZmZmZmZmZmZm Z ddl m Z ddl m Z ddlmZmZmZmZmZmZddlmZmZddlmZmZmZddlmZdd lmZdd l m!Z!dd l"m#Z#Gd d eZ$GddeZ%GddeZ&GddeZ'GddeZ(GddeZ)GddeZ*GddeZ+GddeZ,GddeZ-d Z.Gd!d"eZ/d(d#Z0d)d$Z1d(d%Z2d*d'Z3y&)+) annotations)SAddMulsympifySymbolDummyBasic)Expr) factor_terms)DefinedFunction DerivativeArgumentIndexError AppliedUndef expand_mul PoleError) fuzzy_notfuzzy_or)piIoo)Pow)Eq)sqrt) PiecewisecdeZdZUdZded<dZdZdZedZ ddZ dZ dZ d Z d Zd Zd Zy )rea Returns real part of expression. This function performs only elementary analysis and so it will fail to decompose properly more complicated expressions. If completely simplified result is needed then use ``Basic.as_real_imag()`` or perform complex expansion on instance of this function. Examples ======== >>> from sympy import re, im, I, E, symbols >>> x, y = symbols('x y', real=True) >>> re(2*E) 2*E >>> re(2*I + 17) 17 >>> re(2*I) 0 >>> re(im(x) + x*I + 2) 2 >>> re(5 + I + 2) 7 Parameters ========== arg : Expr Real or complex expression. Returns ======= expr : Expr Real part of expression. See Also ======== im tuple[Expr]argsTc|tjurtjS|tjurtjS|jr|S|jst |zjrtj S|jr|jdS|jr(t|trt|jdSggg}}}tj|}|D]}|j!t }||jr'|j#|9|j%t s|jr|j#|l|j|}|r|j#|d|j#|t'|t'|k7r'd|||fD\} } } || t)| z | zSy)Nrignorec3,K|] }t|ywNr.0xss j/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/functions/elementary/complexes.py zre.eval..iM38M)rNaNComplexInfinityis_extended_real is_imaginaryrZero is_Matrix as_real_imag is_Function isinstance conjugaterrr make_argsas_coefficientappendhaslenim clsargincludedrevertedexcludedrtermcoeff real_imagabcs r)evalzre.evalDs !%%<55L A%% %55L  ! !J   !C%!9!966M ]]##%a( ( __C!;chhqk? ",.r2hH==%D .++A.$ 11 .!)>)>OOD) !% 1 1 1 =I   ! 5 -! .$4yCM)Mx8.LM1a1v1~))*c &|tjfS)zF Returns the real number with a zero imaginary part. rr1selfdeephintss r)r3zre.as_real_imagm aff~rJc8|js|jdjr$tt|jd|dS|js|jdjr,t t t|jd|dzSyNrTevaluate)r/rrrr0rr<rNxs r)_eval_derivativezre._eval_derivativet}  1!>!>j1q4@A A >>TYYq\662Z ! a$?@A A7rJc `|jdtt|jdzz SNr)rrr<rNr?kwargss r)_eval_rewrite_as_imzre._eval_rewrite_as_im{s'yy|a499Q< 0000rJc4|jdjSr[r is_algebraicrNs r)_eval_is_algebraiczre._eval_is_algebraic~yy|(((rJcxt|jdj|jdjgSr[)rrr0is_zerorbs r) _eval_is_zerozre._eval_is_zeros.122DIIaL4H4HIJJrJc8|jdjryyNrTr is_finiterbs r)_eval_is_finitezre._eval_is_finite 99Q< ! ! "rJc8|jdjryyrirjrbs r)_eval_is_complexzre._eval_is_complexrmrJNT)__name__ __module__ __qualname____doc____annotations__r/ unbranched_singularities classmethodrIr3rXr^rcrgrlrorJr)rrsX'R JN&*&*PA1)KrJrcdeZdZUdZded<dZdZdZedZ ddZ dZ dZ d Z d Zd Zd Zy )r<a Returns imaginary part of expression. This function performs only elementary analysis and so it will fail to decompose properly more complicated expressions. If completely simplified result is needed then use ``Basic.as_real_imag()`` or perform complex expansion on instance of this function. Examples ======== >>> from sympy import re, im, E, I >>> from sympy.abc import x, y >>> im(2*E) 0 >>> im(2*I + 17) 2 >>> im(x*I) re(x) >>> im(re(x) + y) im(y) >>> im(2 + 3*I) 3 Parameters ========== arg : Expr Real or complex expression. Returns ======= expr : Expr Imaginary part of expression. See Also ======== re rrTc|tjurtjS|tjurtjS|jrtjS|j st |zjr t |zS|jr|jdS|jr)t|trt|jd Sggg}}}tj|}|D]}|j!t }|0|js|j#|8|j#|J|j%t s |jrl|j|}|r|j#|d|j#|t'|t'|k7r'd|||fD\} } } || t)| z| zSy)Nrr!c3,K|] }t|ywr$r%r&s r)r*zim.eval..r+r,)rr-r.r/r1r0rr2r3r4r5r6r<rrr7r8r9r:r;rr=s r)rIzim.evals !%%<55L A%% %55L  ! !66M   !C%!9!928O ]]##%a( ( __C!;sxx{O# #+-r2hH==%D .++A.$ 11 . .XXa[(=(=!% 1 1 1 =I   ! 5 -! .$4yCM)Mx8.LM1a1v1~))*rJc &|tjfS)zC Return the imaginary part with a zero real part. rLrMs r)r3zim.as_real_imagrQrJc8|js|jdjr$tt|jd|dS|js|jdjr,t t t|jd|dzSyrS)r/rr<rr0rrrVs r)rXzim._eval_derivativerYrJc bt |jdt|jdz zSr[)rrrr\s r)_eval_rewrite_as_rezim._eval_rewrite_as_res)r499Q<"TYYq\"2233rJc4|jdjSr[r`rbs r)rczim._eval_is_algebraicrdrJc4|jdjSr[rr/rbs r)rgzim._eval_is_zeroyy|,,,rJc8|jdjryyrirjrbs r)rlzim._eval_is_finitermrJc8|jdjryyrirjrbs r)rozim._eval_is_complexrmrJNrp)rqrrrsrtrur/rvrwrxrIr3rXrrcrgrlroryrJr)r<r<sW'R JN%*%*NA4)-rJr<ceZdZdZdZdZfdZedZdZ dZ dZ dZ d Z d Zd Zd Zd ZddZdZdZdZdZxZS)signa Returns the complex sign of an expression: Explanation =========== If the expression is real the sign will be: * $1$ if expression is positive * $0$ if expression is equal to zero * $-1$ if expression is negative If the expression is imaginary the sign will be: * $I$ if im(expression) is positive * $-I$ if im(expression) is negative Otherwise an unevaluated expression will be returned. When evaluated, the result (in general) will be ``cos(arg(expr)) + I*sin(arg(expr))``. Examples ======== >>> from sympy import sign, I >>> sign(-1) -1 >>> sign(0) 0 >>> sign(-3*I) -I >>> sign(1 + I) sign(1 + I) >>> _.evalf() 0.707106781186548 + 0.707106781186548*I Parameters ========== arg : Expr Real or imaginary expression. Returns ======= expr : Expr Complex sign of expression. See Also ======== Abs, conjugate Tc t|}||k(rC|jdjdur(|jdt |jdz S|S)NrF)superdoitrrfAbs)rNrPs __class__s r)rz sign.doitCsO GLN 91--699Q<#diil"33 3rJc|jr|j\}}g}t|}|D]}|jr| }|jr |j rCt |}|jr|tz}|jsY| }]|j|o|j||tjurt|t|k(ry|||j|zS|tjurtjS|jrtj S|jrtjS|jrtj"S|j$rt'|tr|S|j r^|j(r"|j*tj,urtSt |z}|jrtS|jrt Syyr$)is_Mul as_coeff_mulris_extended_negativeis_extended_positiver0r< is_comparablerr9rOner; _new_rawargsr-rfr1 NegativeOner4r5is_PowexpHalf) r>r?rHrunkrrFaiarg2s r)rIz sign.evalIs ::&&(GAtCQA &))A++~~U++FA!66&'BJJqM 1 # &$AEEzc#h#d)3s+3++S122 2 !%%<55L ;;66M  # #55L  # #== ??#t$   zzcgg/28D((((r ) rJcht|jdjrtjSyr[)rrrfrrrbs r) _eval_Abszsign._eval_Abs{s& TYYq\)) *55L +rJcDtt|jdSr[)rr6rrbs r)_eval_conjugatezsign._eval_conjugatesIdiil+,,rJc`|jdjr:ddlm}dt |jd|dz||jdzS|jdj rBddlm}dt |jd|dz|t |jdzzSy)Nr) DiracDeltaTrT)rr/'sympy.functions.special.delta_functionsrrr0r)rNrWrs r)rXzsign._eval_derivatives 99Q< ( ( Jz$))A,DAATYYq\*+ + YYq\ & & Jz$))A,DAAaR$))A,./0 0'rJc8|jdjryyri)ris_nonnegativerbs r)_eval_is_nonnegativezsign._eval_is_nonnegative 99Q< & & 'rJc8|jdjryyri)ris_nonpositiverbs r)_eval_is_nonpositivezsign._eval_is_nonpositiverrJc4|jdjSr[)rr0rbs r)_eval_is_imaginaryzsign._eval_is_imaginaryrdrJc4|jdjSr[rrbs r)_eval_is_integerzsign._eval_is_integerrrJc4|jdjSr[)rrfrbs r)rgzsign._eval_is_zerosyy|###rJct|jdjr*|jr|jrt j Syyyr[)rrrf is_integeris_evenrr)rNothers r) _eval_powerzsign._eval_powers@ diil** +    MM55L   ,rJc|jd}|j|d}|dk7r|j|S|dk7r|j||}t |dkrt j St j Sr[)rsubsfuncdirrrr)rNrWnlogxcdirarg0x0s r) _eval_nserieszsign._eval_nseriessiyy| YYq!_ 799R= 1988At$DDAv01550rJc J|jrtd|dkDfd|dkfdSy)Nr|r)rT)r/rr\s r)_eval_rewrite_as_Piecewisezsign._eval_rewrite_as_Piecewises/   aq\Ba=)D D rJc Dddlm}|jr||dzdz Sy)Nr Heavisiderr|rrr/rNr?r]rs r)_eval_rewrite_as_Heavisidezsign._eval_rewrite_as_Heavisides'E   S>A%) ) rJc Ntdt|df|t|z dfSri)rrrr\s r)_eval_rewrite_as_Abszsign._eval_rewrite_as_Abss&!RQZ3S>4*@AArJc P|jt|jdSr[)rr r)rNr]s r)_eval_simplifyzsign._eval_simplifysyydiil344rJr)rqrrrsrt is_complexrwrrxrIrrrXrrrrrgrrrrrr __classcell__)rs@r)rr sw4lJN //b-0)-$1E* B5rJrceZdZUdZded<dZdZdZdZdZ ddZ e dZ dZ d Zd Zd Zd Zd ZdZdZdZdZddZdZdZdZdZdZy)rab Return the absolute value of the argument. Explanation =========== This is an extension of the built-in function ``abs()`` to accept symbolic values. If you pass a SymPy expression to the built-in ``abs()``, it will pass it automatically to ``Abs()``. Examples ======== >>> from sympy import Abs, Symbol, S, I >>> Abs(-1) 1 >>> x = Symbol('x', real=True) >>> Abs(-x) Abs(x) >>> Abs(x**2) x**2 >>> abs(-x) # The Python built-in Abs(x) >>> Abs(3*x + 2*I) sqrt(9*x**2 + 4) >>> Abs(8*I) 8 Note that the Python built-in will return either an Expr or int depending on the argument:: >>> type(abs(-1)) <... 'int'> >>> type(abs(S.NegativeOne)) Abs will always return a SymPy object. Parameters ========== arg : Expr Real or complex expression. Returns ======= expr : Expr Absolute value returned can be an expression or integer depending on input arg. See Also ======== sign, conjugate rrTFcT|dk(rt|jdSt||)zE Get the first derivative of the argument to Abs(). r|r)rrr)rNargindexs r)fdiffz Abs.fdiffs+ q= ! % %$T84 4rJc < ddlm}tdrj}||St t st dtz|dj\}}|jr|js||||z Sjr g}g}jD]}|jr|jjrl|jjrV||j } t | |r|j#|k|j#t%| |j||} t | |r|j#||j#| t'|}|r|t'|dnt(j*}||zSt(j,urt(j,St(j.urt0Sddlm } m} jrj7\} }| j8r|jr>|j:rS| t(j<urt(j*St?| |zS| j@r| tC|zS| jDr)| tC|z| tF tI|zzSy| jKtLs9| | jO\}}|tP|zz}| tC||zSt | r| tCjdSt tRrjTrSjr SyjVrJjKt0t(jXr&t[djODrt0Sj\rt(j^Sj@rSj`r SjbrtP z}|j@r|Sj8ry|jedjgtdjgtdz }|rtifd |Dryk7r k7rjgt>}jk|Dcic]}|tmd c}}|jDcgc]}|j8|}}|rtifd |DstotqzSyyycc}wcc}w) Nr)signsimprzBad argument type for Abs(): %sFrT)rlogc34K|]}|jywr$) is_infinite)r'rFs r)r*zAbs.eval..Ps=Q1===sc3ZK|]"}j|jd$yw)rN)r:r)r'ir?s r)r*zAbs.eval..bs"A1CGGAFF1I.As(+T)realc3RK|]}jt| ywr$)r:r6)r'uconjs r)r*zAbs.eval..hs!FQ$((9Q<"8!Fs$')9sympy.simplify.simplifyrhasattrrr5r TypeErrortypeas_numer_denom free_symbolsrrrrr is_negativebaser9rrrrr-r.r&sympy.functions.elementary.exponentialr as_base_expr/rrris_extended_nonnegativerrrr<r:rr3rr is_positiveis_AddNegativeInfinityanyrfr1is_extended_nonpositiver0r6atomsallxreplacer rr)r>r?robjrdknownrtbnewtnewrrrexponentrFrGzrnew_conjr"r abs_free_argrs ` @r)rIzAbs.eval s4 3 $--/C #t$=S IJ JsU+!!#1 >>!..q6#a&= ::ECXX +88 0 0QUU5F5Fqvv;D!$, 1  Squu%56q6D!$, 1  T* +KE47#c3i%0QUUC9  !%%<55L !## #IC :: __.ND($$&&''" q}}, uu t9h..//H--,,!EBxL0bSH5E1FFFXXf%4y--/1!G2hqj>** c3 r#((1+' ' c< ( t  ::#''"a&8&89=#*:*:*<== ;;66M  & &J  & &4K   28D++     %8::i(399Y+?? AAA  $;34%<YYs^F<IIaL))!,Q/ ==Q !s1vt4I IIaL & &qAD & 9Y!))++rJc2|jdjs|jdjr=t|jd|dt t |jdzSt |jdtt |jd|dzt|jdtt|jd|dzzt|jdz }|jtSrS) rr/r0rrr6rr<rrewrite)rNrWrvs r)rXzAbs._eval_derivatives 99Q< ( (DIIaL,E,EdiilA=y1./0 01Btyy|,>> from sympy import arg, I, sqrt, Dummy >>> from sympy.abc import x >>> arg(2.0) 0 >>> arg(I) pi/2 >>> arg(sqrt(2) + I*sqrt(2)) pi/4 >>> arg(sqrt(3)/2 + I/2) pi/6 >>> arg(4 + 3*I) atan(3/4) >>> arg(0.8 + 0.6*I) 0.643501108793284 >>> arg(arg(arg(arg(x)))) nan >>> real = Dummy(real=True) >>> arg(arg(arg(real))) nan Parameters ========== arg : Expr Real or complex expression. Returns ======= value : Expr Returns arc tangent of arg measured in radians. Tc|}tdD]B}t||r|jd}|dk(r|jrtj cSntj Sddlm}m}t||rt|tSt||ret|jd}|jrA|dtjzz}|tjkDr|dtjzz}|S|jsot|j!\}}|j"r8t%|jDcgc]}t'|dvr|n t'|c}}t'||z}n|}t)d|j+t,Dryddlm} |j3\} } | | | } | j4r| S||k7r ||d Sycc}w) Nrrr exp_polar)rr|c38K|]}|jduywr$)r)r'rs r)r*zarg.eval.. sP!q%%-Psatan2FrT)ranger5rr/rr-rrr%periodic_argumentrr<rPiis_Atomr as_coeff_Mulrrrrrr(sympy.functions.elementary.trigonometricr(r3 is_number) r>r?rFrrr%i_rHarg_r(rWyrs r)rIzarg.evals q A!S!FF1I6a0055L  55LI c9 %$S"- - S !CHHQKBaf 9!ADD&LB {{"3'446GAt{{%)YY0 !$(7'#9QG0174 Returns the *complex conjugate* [1]_ of an argument. In mathematics, the complex conjugate of a complex number is given by changing the sign of the imaginary part. Thus, the conjugate of the complex number :math:`a + ib` (where $a$ and $b$ are real numbers) is :math:`a - ib` Examples ======== >>> from sympy import conjugate, I >>> conjugate(2) 2 >>> conjugate(I) -I >>> conjugate(3 + 2*I) 3 - 2*I >>> conjugate(5 - I) 5 + I Parameters ========== arg : Expr Real or complex expression. Returns ======= arg : Expr Complex conjugate of arg as real, imaginary or mixed expression. See Also ======== sign, Abs References ========== .. [1] https://en.wikipedia.org/wiki/Complex_conjugation Tc,|j}||Syr$)rr>r?rs r)rIzconjugate.evalb!!# ?J rJctSr$)r6rbs r)inversezconjugate.inversehsrJc6t|jddSrSrrrbs r)rzconjugate._eval_Absk499Q<$//rJc2t|jdSr[ transposerrbs r) _eval_adjointzconjugate._eval_adjointn1&&rJc |jdSr[rrbs r)rzconjugate._eval_conjugateqyy|rJc|jr$tt|jd|dS|jr%tt|jd|d SyrS)r<r6rrr0rVs r)rXzconjugate._eval_derivativetsP 99Z ! a$GH H ^^j1q4HII IrJc2t|jdSr[adjointrrbs r)_eval_transposezconjugate._eval_transposeztyy|$$rJc4|jdjSr[r`rbs r)rczconjugate._eval_is_algebraic}rdrJN)rqrrrsrtrwrxrIrBrrIrrXrRrcryrJr)r6r64sE*VN 0'J %)rJr6c2eZdZdZedZdZdZdZy)rHa Linear map transposition. Examples ======== >>> from sympy import transpose, Matrix, MatrixSymbol >>> A = MatrixSymbol('A', 25, 9) >>> transpose(A) A.T >>> B = MatrixSymbol('B', 9, 22) >>> transpose(B) B.T >>> transpose(A*B) B.T*A.T >>> M = Matrix([[4, 5], [2, 1], [90, 12]]) >>> M Matrix([ [ 4, 5], [ 2, 1], [90, 12]]) >>> transpose(M) Matrix([ [4, 2, 90], [5, 1, 12]]) Parameters ========== arg : Matrix Matrix or matrix expression to take the transpose of. Returns ======= value : Matrix Transpose of arg. c,|j}||Syr$)rRr?s r)rIztranspose.evalr@rJc2t|jdSr[r6rrbs r)rIztranspose._eval_adjointrJrJc2t|jdSr[rPrbs r)rztranspose._eval_conjugaterSrJc |jdSr[rLrbs r)rRztranspose._eval_transposerMrJN) rqrrrsrtrxrIrIrrRryrJr)rHrHs+&P '%rJrHc@eZdZdZedZdZdZdZd dZ dZ y) rQa Conjugate transpose or Hermite conjugation. Examples ======== >>> from sympy import adjoint, MatrixSymbol >>> A = MatrixSymbol('A', 10, 5) >>> adjoint(A) Adjoint(A) Parameters ========== arg : Matrix Matrix or matrix expression to take the adjoint of. Returns ======= value : Matrix Represents the conjugate transpose or Hermite conjugation of arg. cf|j}||S|j}| t|Syr$)rIrRr6r?s r)rIz adjoint.evals<! ?J!!# ?S> ! rJc |jdSr[rLrbs r)rIzadjoint._eval_adjointrMrJc2t|jdSr[rGrbs r)rzadjoint._eval_conjugaterJrJc2t|jdSr[rXrbs r)rRzadjoint._eval_transposerJrJNcb|j|jd}d|z}|r d|d|d}|S)Nrz %s^{\dagger}z\left(z \right)^{})_printr)rNprinterrrr?texs r)_latexzadjoint._latexs4nnTYYq\*# -0#6C rJcddlm}|j|jdg|}|jr ||dz}|S||dz}|S)Nr) prettyFormu†+) sympy.printing.pretty.stringpictrgrbr _use_unicode)rNrcrrgpforms r)_prettyzadjoint._prettysV?tyy|3d3   :l33E :c?*E rJr$) rqrrrsrtrxrIrIrrRrerlryrJr)rQrQs44""''rJrQc4eZdZdZdZdZedZdZdZ y) polar_lifta Lift argument to the Riemann surface of the logarithm, using the standard branch. Examples ======== >>> from sympy import Symbol, polar_lift, I >>> p = Symbol('p', polar=True) >>> x = Symbol('x') >>> polar_lift(4) 4*exp_polar(0) >>> polar_lift(-4) 4*exp_polar(I*pi) >>> polar_lift(-I) exp_polar(-I*pi/2) >>> polar_lift(I + 2) polar_lift(2 + I) >>> polar_lift(4*x) 4*polar_lift(x) >>> polar_lift(4*p) 4*p Parameters ========== arg : Expr Real or complex expression. See Also ======== sympy.functions.elementary.exponential.exp_polar periodic_argument TFcddlm}|jrD||}|dtdz t dz tfvr!ddlm}|t |zt|zS|jr |j}n|g}g}g}g}|D].}|jr||gz }|jr||gz })||gz }0t|t|krC|rt||ztt|zS|r t||zSddlm}t||dzSy)Nrr?rr%)$sympy.functions.elementary.complexesr?r/rrr%rabsrris_polarrr;rrn) r>r?argumentarr%rr@rBr7s r)rIzpolar_lift.eval%sH ==#B aAs1ub))L 2s3x// ::88D5D "C||SE!SE!SE!  " x=3t9 $X02:c8n3MMMX022LH~il22 %rJc>|jdj|S)z. Careful! any evalf of polar numbers is flaky r)r _eval_evalf)rNprecs r)rxzpolar_lift._eval_evalfIsyy|''--rJc6t|jddSrSrDrbs r)rzpolar_lift._eval_AbsMrErJN) rqrrrsrtrtrrxrIrxrryrJr)rnrns1#JHM!3!3F.0rJrnc6eZdZdZedZedZdZy)r*a Represent the argument on a quotient of the Riemann surface of the logarithm. That is, given a period $P$, always return a value in $(-P/2, P/2]$, by using $\exp(PI) = 1$. Examples ======== >>> from sympy import exp_polar, periodic_argument >>> from sympy import I, pi >>> periodic_argument(exp_polar(10*I*pi), 2*pi) 0 >>> periodic_argument(exp_polar(5*I*pi), 4*pi) pi >>> from sympy import exp_polar, periodic_argument >>> from sympy import I, pi >>> periodic_argument(exp_polar(5*I*pi), 2*pi) pi >>> periodic_argument(exp_polar(5*I*pi), 3*pi) -pi >>> periodic_argument(exp_polar(5*I*pi), pi) 0 Parameters ========== ar : Expr A polar number. period : Expr The period $P$. See Also ======== sympy.functions.elementary.exponential.exp_polar polar_lift : Lift argument to the Riemann surface of the logarithm principal_branch c ddlm}m}|jr |j}n|g}d}|D]}|j s|t |z }t||r!||jjdz }K|jrX|jj\}}||t|jz||t|jzzz }t|tr|t |jdz }y|S)Nr)r%rr|)rr%rrrrtr?r5rr3runbranched_argumentrrsrn) r>rvr%rrrvrFrr<s r)_getunbranchedz periodic_argument._getunbranchedzsI 9977D4D  A::c!f$ Ay)aee002155 ++-Bb!4FF" S[!1122 Az*c!&&)n,  rJc|jsy|tk(r"t|trt |j St|t r%|dtzk\rt |j d|S|jrY|j Dcgc]}|jr|}}t|t|j k7rt t||S|j|}|yddl m}m}|j!t||ry|tk(r|S|tk7rrvperiodrWnewargsrvrr(rrs r)rIzperiodic_argument.evals+ ** R>+UD 9 R<  R< C 6)AFF23F:A55>!A~%" @s EEc2|j\}}|tk(r*tj|}||S|j |St|tj |}ddlm}||||z tjz |zz j |S)Nrr) rrr*r~rxrrrr)rNryrrrvubrs r)rxzperiodic_argument._eval_evalfsII 6 R<*99!>> from sympy import exp_polar, unbranched_argument >>> from sympy import I, pi >>> unbranched_argument(exp_polar(15*I*pi)) 15*pi >>> unbranched_argument(exp_polar(7*I*pi)) 7*pi See also ======== periodic_argument )r*rrps r)r}r}s& S" %%rJc.eZdZdZdZdZedZdZy)ra Represent a polar number reduced to its principal branch on a quotient of the Riemann surface of the logarithm. Explanation =========== This is a function of two arguments. The first argument is a polar number `z`, and the second one a positive real number or infinity, `p`. The result is ``z mod exp_polar(I*p)``. Examples ======== >>> from sympy import exp_polar, principal_branch, oo, I, pi >>> from sympy.abc import z >>> principal_branch(z, oo) z >>> principal_branch(exp_polar(2*pi*I)*3, 2*pi) 3*exp_polar(0) >>> principal_branch(exp_polar(2*pi*I)*3*z, 2*pi) 3*principal_branch(z, 2*pi) Parameters ========== x : Expr A polar number. period : Expr Positive real number or infinity. See Also ======== sympy.functions.elementary.exponential.exp_polar polar_lift : Lift argument to the Riemann surface of the logarithm periodic_argument TFcddlm}t|trt |j d|S|t k(r|St|t }t||}||k7r|jts|jtst|}d}|jt|}t|t }|jtsG||k7r|t||z z|z}n|}|js|j|s ||dz}|S|js|d} } n|j|j\} } g} | D]} | jr| | z} | | gz } t| } t| |} | jtry| j rnt#| | k7s| dk(r[| dk7rV| dk7rQ| dk(rt%| t t'| |zSt |t| zt'| z|t%| zS| j r>t%| |dz kdk(s| |dz k(r!| dk(r|| tzt%| zSyyy)Nrrqc<t|ts t|S|Sr$)r5rrn)exprs r)mrz!principal_branch.eval..mr s!$/%d++ rJryr|rT)rr%r5rnrrrr*r:replacerrtrrrtupler/r}rsr)rNrWrr%rbargplrresrHmothersr2r?s r)rIzprincipal_branch.evals)D a $#AFF1Iv6 6 R<H q" % F+ :bff%67!23AB J+B"2r*B66*%:#AtbyM225CC||CGGI,>9Q<'C ~~bqA!1>>1>>2DAq A}}Q1#    &M6* 77$ % ==1!4;"axAGQax1v.sAw???#Iae$4S!W$As1Q3x,,T22rJN) rqrrrsrtrtrrxrIrxryrJr)rrs,&PHM1+1+f3rJrc <ddlm}|jr|S|jr |s t |St |t r|s |r t |S|jr|S|jrB|j|jDcgc]}t||dc}}|r t |S|S|jrS|jtjk(r6|jtjt|j |dS|j"r3|j|jDcgc]}t||dc}St ||rwt|j$||}g}|jddD]9}t|dd|} t|dd||} |j'| f| z;||ft)|zS|j|jDcgc]"}t |t*rt|||n|$c}Scc}wcc}wcc}w)Nr)IntegralT)pauseFr|)liftr)sympy.integrals.integralsrrtr/rnr5rr,rrr _polarifyrrrExp1rr4functionr9rr ) eqrrrr?rrlimitslimitvarrests r)rr:s2 {{  ||E"~"fe"~   BGG"''J3iT6J K a=  rww!&&(wwqvvyUCDD rwwbggNs3E:NOO B !d%8WWQR[ )EE!H5>CU12YT?D MM3&4- ( )4'E&M133rwwFHggO?BJsD1#3E:7:;OP P%KOOsH.H$'Hc|rd}tt||}|s|S|jDcic]}|t|jd}}|j |}||j Dcic]\}}|| c}}fScc}wcc}}w)a Turn all numbers in eq into their polar equivalents (under the standard choice of argument). Note that no attempt is made to guess a formal convention of adding polar numbers, expressions like $1 + x$ will generally not be altered. Note also that this function does not promote ``exp(x)`` to ``exp_polar(x)``. If ``subs`` is ``True``, all symbols which are not already polar will be substituted for polar dummies; in this case the function behaves much like :func:`~.posify`. If ``lift`` is ``True``, both addition statements and non-polar symbols are changed to their ``polar_lift()``ed versions. Note that ``lift=True`` implies ``subs=False``. Examples ======== >>> from sympy import polarify, sin, I >>> from sympy.abc import x, y >>> expr = (-x)**y >>> expr.expand() (-x)**y >>> polarify(expr) ((_x*exp_polar(I*pi))**_y, {_x: x, _y: y}) >>> polarify(expr)[0].expand() _x**_y*exp_polar(_y*I*pi) >>> polarify(x, lift=True) polar_lift(x) >>> polarify(x*(1+y), lift=True) polar_lift(x)*polar_lift(y + 1) Adds are treated carefully: >>> polarify(1 + sin((1 + I)*x)) (sin(_x*polar_lift(1 + I)) + 1, {_x: x}) FT)polar)rrrr nameritems)rrrrrepsrs r)polarifyr[sP  72; %B  24// BQAuQVV4( ( BD B B .A1. .. C.s B2 B c Xt|tr |jr|S|s&ddlm}m}t||r|t |j|St|tr2|jddtzk(rt |jd|S|jsN|jsB|js6|jr[|jdvrd|jvs|jdvr1|j|jDcgc]}t ||c}St|t rt |jd|S|j"rBt |j|}t |j$||j&xr| }||zS|j(rIt+|jddr2|j|jDcgc]}t |||c}S|j|jDcgc]}t ||dc}Scc}wcc}wcc}w) Nrr$r|r)z==z!=rvFT)r5r r,rrr% _unpolarifyrrrrr is_Boolean is_Relationalrel_oprrnrrrr4getattr)rexponents_onlyrrr%rWexpors r)rrs b% BJJ I b) ${266>:; ; b* + ad0Brwwqz>: : IIbmm    \)a277l -277RWWM[N;MN N b* %rwwqz>: : yy266>2277N.Y /1Tz ~~'"''<?rwwWW%QG  277277Ka[ND9K LLNLsHH"H'Nc6t|tr|St|}|t|j |Sd}d}|rd}|r-d}t |||}||k7rd}|}t|tr|S|r-ddlm}j |ddtddiS)a If `p` denotes the projection from the Riemann surface of the logarithm to the complex line, return a simplified version `eq'` of `eq` such that `p(eq') = p(eq)`. Also apply the substitution subs in the end. (This is a convenience, since ``unpolarify``, in a certain sense, undoes :func:`polarify`.) Examples ======== >>> from sympy import unpolarify, polar_lift, sin, I >>> unpolarify(polar_lift(I + 2)) 2 + I >>> unpolarify(sin(polar_lift(I + 7))) sin(7 + I) TFrrqr|) r5boolr unpolarifyrrrr%rn)rrrchangedrrr%s r)rrs""d B "''$-((G E "ne4 "9GB c4 J A 88Yq\1jmQ7 88rJ)F)TF)NF)4 __future__r sympy.corerrrrrr r sympy.core.exprr sympy.core.exprtoolsr sympy.core.functionr rrrrrsympy.core.logicrrsympy.core.numbersrrrsympy.core.powerrsympy.core.relationalr(sympy.functions.elementary.miscellaneousr$sympy.functions.elementary.piecewiserrr<rrr?r6rHrQrnr*r}rrrrrryrJr)rs"AAA -))0(( $9:wwtuuvr5?r5jw(/w(tyC/yCxJ)J)Z66r;o;DR0R0jgKgKT&,f3f3RPB//dMB&9rJ