K ir,ddlmZddlmZddlmZddlmZddlm Z ddl m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZddlmZddlmZdd lmZmZm Z m!Z!m"Z"m#Z#dd l$m%Z%m&Z&m'Z'm(Z(m)Z)dd l*m+Z+dd l,m-Z-dd l.m/Z/ddl0m1Z1ddl2m3Z4m5Z6ddl7m8Z8m9Z9m:Z:m;Z;mm?Z?ddl@mAZAmBZBmCZCddlDmEZEddlFmGZGddlHmIZIddlJmKZKmLZLmMZMddlNmOZOddlPmQZQmRZRmSZSmTZTmUZUmVZVddlWmXZXddlYmZZZddl[m\Z\ddl]m^Z^m_Z_m`Z`maZambZbddlcmdZdmeZemfZfddlgmhZhmiZiddljmkZkdd llmmZmdd!lnmoZompZpdd"lqmrZrdd#lsmtZtdd$lumvZvmwZwmxZxdd%lymzZzdd&l{m|Z|m}Z}dd'l~mZdd(lmZmZmZmZdd)lmZdd*lZgd+d+fd,Zd-Zd.Zd/Zd0Zd1ZdPd2ZedQd3ZedRd4ZedSd5ZedTd6Zd7ed+d+d8fd9Zd:Zd;ZdUd<ZdVd=Zd>ZdVd?Zd@ZdWdAZdBZdCZdDZdXdEZ dYdFZdZdGZe j<fdHZd[dIZdWdJZedKdLdMNe4Z3edOdLdMNe6Z5y*)\) annotations)overload) defaultdict)Product)Sum)BasicSAddMulPowSymbolsympify expand_funcFunctionDummyExpr factor_termsexpand_power_expEq) factor_nc)global_parameters) expand_log count_ops_mexpandnfloat expand_mulexpand)FloatIpiRational equal_valued) Relational) Transform)ordered)_sympify) bottom_upwalk)gammaexpsqrtlog exp_polarre)CombinatorialFunction) unpolarifyAbssign)ExpBase)HyperbolicFunction)ceiling) Piecewisepiecewise_foldpiecewise_simplify)TrigonometricFunction) BesselBasebesseljbesselibesselkbesselyjn)KroneckerDelta)Integral)Boolean) MatrixExprMatAddMatMulMatPow MatrixSymbol)togethercancelfactor) _is_sum_surds_minimal_polynomial_sq)Set)combsimp)sub_presub_post) hyperexpand)powsimp)radsimpfraction collect_abs) sqrtdenest)trigsimp exptrigsimp) deprecated) has_varietysiftsubsetsiterable)as_intNFc`t|}|rtt|||St||S)a Separates variables in an expression, if possible. By default, it separates with respect to all symbols in an expression and collects constant coefficients that are independent of symbols. Explanation =========== If ``dict=True`` then the separated terms will be returned in a dictionary keyed to their corresponding symbols. By default, all symbols in the expression will appear as keys; if symbols are provided, then all those symbols will be used as keys, and any terms in the expression containing other symbols or non-symbols will be returned keyed to the string 'coeff'. (Passing None for symbols will return the expression in a dictionary keyed to 'coeff'.) If ``force=True``, then bases of powers will be separated regardless of assumptions on the symbols involved. Notes ===== The order of the factors is determined by Mul, so that the separated expressions may not necessarily be grouped together. Although factoring is necessary to separate variables in some expressions, it is not necessary in all cases, so one should not count on the returned factors being factored. Examples ======== >>> from sympy.abc import x, y, z, alpha >>> from sympy import separatevars, sin >>> separatevars((x*y)**y) (x*y)**y >>> separatevars((x*y)**y, force=True) x**y*y**y >>> e = 2*x**2*z*sin(y)+2*z*x**2 >>> separatevars(e) 2*x**2*z*(sin(y) + 1) >>> separatevars(e, symbols=(x, y), dict=True) {'coeff': 2*z, x: x**2, y: sin(y) + 1} >>> separatevars(e, [x, y, alpha], dict=True) {'coeff': 2*z, alpha: 1, x: x**2, y: sin(y) + 1} If the expression is not really separable, or is only partially separable, separatevars will do the best it can to separate it by using factoring. >>> separatevars(x + x*y - 3*x**2) -x*(3*x - y - 1) If the expression is not separable then expr is returned unchanged or (if dict=True) then None is returned. >>> eq = 2*x + y*sin(x) >>> separatevars(eq) == eq True >>> separatevars(2*x + y*sin(x), symbols=(x, y), dict=True) is None True )r_separatevars_dict _separatevars)exprsymbolsdictforces ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/simplify/simplify.py separatevarsrg7s2F 4=D !-e"|}|r t+|n|if\}} t-|j/| }|j0s|}| |zS) NrT)rdreFre)mul multinomialre)csetwarn) isinstancer1argsis_Mul is_numberrgr mapfuncvalueslen free_symbolslist enumerateis_Powbaser Exp1r r*rposifyrJsubsis_Addargs_cnc as_coeff_Mulr )rbreargsrrchangedia_exprrepscommonc commonc_setcncnonsepars rfraras$iil ::cmmSt59A}C 188:677  4  !  {{DIIdO .DAq"1e,DG-aAG . 499d#D  {{tyyAFF*< 7B ;;5e5; AD"'&,dBZKE4 %=  d #D ;;   ?D1gDu5a8G !"X81::4e:4Q7787mG""$Q'G""5"9!z%_separatevars_dict..s.199.szsymbols must be Atoms.coeffrpr) all ValueErrorrzryr make_argsset intersectionrxappendpopitems)rbrcrretexpsymrkvs rfr`r`s.g..56 6w- t(()!WI- .Q1b5 .C . ]]4 .7|008 | q  |  ! L   "    " # * *1 - . 1aA J# /s Dc Bt|}t|tst|rt |}t |}t }|D]&}|j|jt}(i}|D]A}|jt|djDcic]\}}|| c}}Ct|D]\}}|j|||<|||jD cic]\}} | | c} }fS|jDcic]1}|j #|t#|j$fddi|j&3}}|j|}||jD cic]\}} | | c} }fScc}}wcc} }wcc}wcc} }w)a^Return ``eq`` (with generic symbols made positive) and a dictionary containing the mapping between the old and new symbols. Explanation =========== Any symbol that has positive=None will be replaced with a positive dummy symbol having the same name. This replacement will allow more symbolic processing of expressions, especially those involving powers and logarithms. A dictionary that can be sent to subs to restore ``eq`` to its original symbols is also returned. >>> from sympy import posify, Symbol, log, solve >>> from sympy.abc import x >>> posify(x + Symbol('p', positive=True) + Symbol('n', negative=True)) (_x + n + p, {_x: x}) >>> eq = 1/x >>> log(eq).expand() log(1/x) >>> log(posify(eq)[0]).expand() -log(_x) >>> p, rep = posify(eq) >>> log(p).expand().subs(rep) -log(x) It is possible to apply the same transformations to an iterable of expressions: >>> eq = x**2 - 4 >>> solve(eq, x) [-2, 2] >>> eq_x, reps = posify([eq, x]); eq_x [_x**2 - 4, _x] >>> solve(*eq_x) [2] rppositiveT)rrqrr]typerzrunionatomsr updaterrr{rry is_positivername assumptions0) eqfsymserrrrrrs rfrrsR B b% Xb\ H "Xu /A::aggfo.D / AA KK&)A,*<*<*>?$!QA? @ AbM !DAqFF4LBqE !u 51q!t555// DQ]]-B uQVV=d=ann= = DD D B .A1. ..@6 D/s# F ; F6F8 Fcbt|}|j||dz|z }|jt}|j t rt |}|jdd}t|}t|dd}|j|rt|tjSy) a9Given combinatorial term f(k) simplify its consecutive term ratio i.e. f(k+1)/f(k). The input term can be composed of functions and integer sequences which have equivalent representation in terms of gamma special function. Explanation =========== The algorithm performs three basic steps: 1. Rewrite all functions in terms of gamma, if possible. 2. Rewrite all occurrences of gamma in terms of products of gamma and rising factorial with integer, absolute constant exponent. 3. Perform simplification of nested fractions, powers and if the resulting expression is a quotient of polynomials, reduce their total degree. If f(k) is hypergeometric then as result we arrive with a quotient of polynomials of minimal degree. Otherwise None is returned. For more information on the implemented algorithm refer to: 1. W. Koepf, Algorithms for m-fold Hypergeometric Summation, Journal of Symbolic Computation (1995) 20, 399-417 rprTr*)deepcombine)ratioN)rrrewriter)hasr6r7rrrrRis_rational_functionsimplifyr Infinity)rrgs rf hypersimprs<  A q!a%1A %AuuY 1  FF2JqMAAe,Aa ,,rhcttt||f\}}||z jt}|j dd}|j |S)a; Returns True if ``f`` and ``g`` are hyper-similar. Explanation =========== Similarity in hypergeometric sense means that a quotient of f(k) and g(k) is a rational function in ``k``. This procedure is useful in solving recurrence relations. For more information see hypersimp(). TF)rvbasic)rzrurrr)rr)rrrhs rf hypersimilarrMsR GaV$ %DAq 1 eA d%(A ! !! $$rhcP|tj}t|}t|tt fr |j r|S|jdd}tt|}t|tt fr |j r|S|jrq|j|jDcgc] }t|c}}|s=t|tr-|jrt!t"j$| dS|S|r|jdd}|Scc}w)aMake all Add sub-expressions canonical wrt sign. Explanation =========== If an Add subexpression, ``a``, can have a sign extracted, as determined by could_extract_minus_sign, it is replaced with Mul(-1, a, evaluate=False). This allows signs to be extracted from powers and products. Examples ======== >>> from sympy import signsimp, exp, symbols >>> from sympy.abc import x, y >>> i = symbols('i', odd=True) >>> n = -1 + 1/x >>> n/x/(-n)**2 - 1/n/x (-1 + 1/x)/(x*(1 - 1/x)**2) - 1/(x*(-1 + 1/x)) >>> signsimp(_) 0 >>> x*n + x*-n x*(-1 + 1/x) + x*(1 - 1/x) >>> signsimp(_) 0 Since powers automatically handle leading signs >>> (-2)**i -2**i signsimp can be used to put the base of a power with an integer exponent into canonical form: >>> n**i (-1 + 1/x)**i By default, signsimp does not leave behind any hollow simplification: if making an Add canonical wrt sign didn't change the expression, the original Add is restored. If this is not desired then the keyword ``evaluate`` can be set to False: >>> e = exp(y - x) >>> signsimp(e) == e True >>> signsimp(e, evaluate=False) exp(-(x - y)) c,|jxr| |k7Srrsxs rfzsignsimp..sqxx6qbEQJrhc | Srrs rfrzsignsimp..s QB%rhFevaluatec,|jxr| |k7Srrrs rfrzsignsimp..s 7rUaZrhc | Srrrs rfrzsignsimp..s aR5rh)rrrrqrr#rreplacerPrOrrvrrsignsimpr could_extract_minus_signr r NegativeOne)rbrrrrvs rfrrcsd$-- 4=D dT:. /4<<  6HAA a$ + , xx QVV1662ahqk2 3Jr3113q}}rcE: :  II7 I H3s4D#c yrrrbkwargss rfrrs,/rhc yrrrs rfrrs25rhc yrrrs rfrrs*-rhc yrrrs rfrrs.1rhg333333?Tc d fdfd}t||}jd|jdjd|jd|jdd t|tr*|jr|j st jS|St|d d }||diStt|x} }t|tr |js|S|r.|jtrt|}|js|St t"t$t&f|j)fd fd d}t|s||S|j*s t-|}d} |dur$|jt.rd} t1|d}t3|d}t#t5|j7}t9|} | t;| j9} t=|dt=| d} |t j>ur| }n | | |}t|ts|StA|d}|jtBr|jEtF}|jtHrtK|}||}|jtHrwtK|}|jtLr tO|}|jtHr7tQ|dd}|jtHr|tA|}|StS|}|jtLr tO|}|jtTr tW|}|jtXtZr t]|d}|jt^rta|dtc|}|jtdtfr ti|}|jtjr tm|fi}|jtnr<|jq|jstnDcic]}|tA|c}}|jttr tw|fi}ddlm?}||}t5|ddt5||}|t9|}|tA|tt|}|jtXtZt&tr t|}tdd}|jq|}|j\}}|jrEttd|z dd\}}|t jur||zj|z }|jr#t|\}}|dk7rt| | z }||| zkDr| }| r| t|d}||Scc}w) aSimplifies the given expression. Explanation =========== Simplification is not a well defined term and the exact strategies this function tries can change in the future versions of SymPy. If your algorithm relies on "simplification" (whatever it is), try to determine what you need exactly - is it powsimp()?, radsimp()?, together()?, logcombine()?, or something else? And use this particular function directly, because those are well defined and thus your algorithm will be robust. Nonetheless, especially for interactive use, or when you do not know anything about the structure of the expression, simplify() tries to apply intelligent heuristics to make the input expression "simpler". For example: >>> from sympy import simplify, cos, sin >>> from sympy.abc import x, y >>> a = (x + x**2)/(x*sin(y)**2 + x*cos(y)**2) >>> a (x**2 + x)/(x*sin(y)**2 + x*cos(y)**2) >>> simplify(a) x + 1 Note that we could have obtained the same result by using specific simplification functions: >>> from sympy import trigsimp, cancel >>> trigsimp(a) (x**2 + x)/x >>> cancel(_) x + 1 In some cases, applying :func:`simplify` may actually result in some more complicated expression. The default ``ratio=1.7`` prevents more extreme cases: if (result length)/(input length) > ratio, then input is returned unmodified. The ``measure`` parameter lets you specify the function used to determine how complex an expression is. The function should take a single argument as an expression and return a number such that if expression ``a`` is more complex than expression ``b``, then ``measure(a) > measure(b)``. The default measure function is :func:`~.count_ops`, which returns the total number of operations in the expression. For example, if ``ratio=1``, ``simplify`` output cannot be longer than input. :: >>> from sympy import sqrt, simplify, count_ops, oo >>> root = 1/(sqrt(2)+3) Since ``simplify(root)`` would result in a slightly longer expression, root is returned unchanged instead:: >>> simplify(root, ratio=1) == root True If ``ratio=oo``, simplify will be applied anyway:: >>> count_ops(simplify(root, ratio=oo)) > count_ops(root) True Note that the shortest expression is not necessary the simplest, so setting ``ratio`` to 1 may not be a good idea. Heuristically, the default value ``ratio=1.7`` seems like a reasonable choice. You can easily define your own measure function based on what you feel should represent the "size" or "complexity" of the input expression. Note that some choices, such as ``lambda expr: len(str(expr))`` may appear to be good metrics, but have other problems (in this case, the measure function may slow down simplify too much for very large expressions). If you do not know what a good metric would be, the default, ``count_ops``, is a good one. For example: >>> from sympy import symbols, log >>> a, b = symbols('a b', positive=True) >>> g = log(a) + log(b) + log(a)*log(1/b) >>> h = simplify(g) >>> h log(a*b**(1 - log(a))) >>> count_ops(g) 8 >>> count_ops(h) 5 So you can see that ``h`` is simpler than ``g`` using the count_ops metric. However, we may not like how ``simplify`` (in this case, using ``logcombine``) has created the ``b**(log(1/a) + 1)`` term. A simple way to reduce this would be to give more weight to powers as operations in ``count_ops``. We can do this by using the ``visual=True`` option: >>> print(count_ops(g, visual=True)) 2*ADD + DIV + 4*LOG + MUL >>> print(count_ops(h, visual=True)) 2*LOG + MUL + POW + SUB >>> from sympy import Symbol, S >>> def my_measure(expr): ... POW = Symbol('POW') ... # Discourage powers by giving POW a weight of 10 ... count = count_ops(expr, visual=True).subs(POW, 10) ... # Every other operation gets a weight of 1 (the default) ... count = count.replace(Symbol, type(S.One)) ... return count >>> my_measure(g) 8 >>> my_measure(h) 14 >>> 15./8 > 1.7 # 1.7 is the default ratio True >>> simplify(g, measure=my_measure) -log(a)*log(b) + log(a) + log(b) Note that because ``simplify()`` internally tries many different simplification strategies and then compares them using the measure function, we get a completely different result that is still different from the input expression by doing this. If ``rational=True``, Floats will be recast as Rationals before simplification. If ``rational=None``, Floats will be recast as Rationals but the result will be recast as Floats. If rational=False(default) then nothing will be done to the Floats. If ``inverse=True``, it will be assumed that a composition of inverse functions, such as sin and asin, can be cancelled in any order. For example, ``asin(sin(x))`` will yield ``x`` without checking whether x belongs to the set where this relation is true. The default is False. Note that ``simplify()`` automatically calls ``doit()`` on the final expression. You can avoid this behavior by passing ``doit=False`` as an argument. Also, it should be noted that simplifying a boolean expression is not well defined. If the expression prefers automatic evaluation (such as :obj:`~.Eq()` or :obj:`~.Or()`), simplification will return ``True`` or ``False`` if truth value can be determined. If the expression is not evaluated by default (such as :obj:`~.Predicate()`), simplification will not reduce it and you should use :func:`~.refine` or :func:`~.ask` function. This inconsistency will be resolved in future version. See Also ======== sympy.assumptions.refine.refine : Simplification using assumptions. sympy.assumptions.ask.ask : Query for boolean expressions using assumptions. c>t|s|dSt|S)z Return the choice that has the fewest ops. In case of a tie, the expression listed first is selected. rkey)rZmin)choicesmeasures rfshorterzsimplify..shorterNs$ 7#1: 7((rhcPr|jn|}|t|Sr)doitrU)rrrrs rfdonezsimplify..doneWs#QVVX1r;r?++rhrationalrrrinverser)rrrrr_eval_simplifyNc^t|txr|jxr t| Sr)rqrrr)rhandleds rfrzsimplify..|s/*Q%!&& w:6rhc p|j|jDcgc]}t|fic}Scc}wr)rvrrr)rrrs rfrzsimplify..~s.&!&&!&&AQ8A00ABAs3F simultaneousTc.tdfdS)NnormalcSrrwsrfrz,simplify....s1rh)getattrrs`rfrzsimplify..s&Ega9&E&Grhr)r2)rrr)Quantity)quantity_simplifyr*)rrc&t|jSr)r rrrs rfrzsimplify..s#qvv,rhc|jxr\t|jdk(xrB|jdjxr'|jdjxr |j S)Nrjrrp)rsrxrr is_Numberris_commutativers rfrzsimplify..sa   AFF q  q   q    rhrp)symbolic max_terms)exponentr)Mrgetrqris_zerorr ZerorrUrrrrrrinversecombiner r r r3rr nc_simplifyr nsimplify _bottom_uprRas_content_primitiverIrrHrrr2rr1r6r7r@ kroneckersimpr8rQr: besselsimpr9r4rWr,r logcombiner/r)rNr sum_simplifyrAxreplacerrproduct_simplifysympy.physics.unitsrsympy.physics.units.utilrrrr*rXr$as_numer_denomrrTrSOnerrr)rbrrrrrrrr original_exprfloats_eexpr1expr2rrrshort hollow_mulnumerdenomndrrs ` `` @@rfrrs;v), 4( +DGU+::i1JJz84::i1 64( *F$$,,!^^qvv55T#3T:N!'''&x~66MD dE "$)) 488H%d#yyK3W$G <<  B  D dG $Dz   4 Fu%- dG HD  224 5D B B ++- .E HT-xD/I JE  ueT* dE " 5 )D xx~||C  xx d#Dz 88I "$'Dxx'$T*xx "*$TF88I&"4d);#$A|A >? xx//, xx> & GD%d;WT]D QE E6%= )E E<.0@EAR0S TE yy&(:GSIE" J >>* %D&&(LE5 ||%%1EF1 AEE>!G##%a'D $$&~1 6QBG$Dt}uW]333("dU+ :_>s#X-c dt|tsR|j|jtDcic]$}|j t r |t |fi|&c}}t|}t|ts|S|j}g}g}|D]|}ttj|dd\}}|s|j|.s jC(rhT)binaryr)rqr r rrrrrrrr[r rrr sum_combine) rrrtermss_to_tterm sum_termsotherresults rfrr s! a  JJWWS\1QUU3Z<4V441 2q A a  FFE C CT d 3 (7 5 JJt  e  3i!P"2!"2"2">> from sympy import Sum >>> from sympy.abc import x, y >>> from sympy.simplify.simplify import factor_sum >>> s = Sum(x*y, (x, 1, 3)) >>> factor_sum(s) y*Sum(x, (x, 1, 3)) >>> factor_sum(s.function, s.limits) y*Sum(x, (x, 1, 3)) )radicalclearrTr2)rr)selflimitsr1r2rTr2rrbs rf factor_sumr5>s8(!5d,F!'3t f TD  ' ''rhcd}t|tr ||}n|}t|tr ||}n|}t|t|ury|dk(rP|j|jk(rZt t |j |j zg|jS|dk(rt|j |j z dk(rt|jt|jcxk(rdk(rnn|jdd}|jdd}|jdd}|jdd} |jdd} |jdd} || k(rT| |dzk(r"t t |j ||| fS|| dzk(r"t t |j || |fSt||S)z&Helper function for Sum simplificationctj|}td|D}t|Dcgc] }||k7s | c}}t||jzg|j Scc}w)Nc3BK|]}t|ts|ywrr)rrs rfrz.sum_add..__refactor.._s:!z!S'9A:s)r rnextrfunctionr4)valrrsumvrconstants rf __refactorzsum_add..__refactor]s]}}S!:t::D6qAI678dmm+:dkk::7s A'A'rrprj) rqr rr4r5rr:rrxr ) r3r$r*r>rselfrotherrx1y1r,x2y2s rfr(r(Xs ; $4 %E" E{d6l" Q;||v}},!#ennv&F"V"VWW q[89Q>u||$FMM(:?a? Q*Aa+Ba+B a(+Aq)!,Bq)!,BAva<#-c%..1b"+.N#OO26\#-c%..1b"+.N#OO tU rhc tj|}g}g}|jdd}|D]w}t|trT|r@|j t |j jdi|g|jU|j |g|j |ydgt|z}tdD]b}t|D]R\} } || r t|D]9\} } || r | | k7st| | |} t| ts0| || <d|| <;Tdt|}t|D]\} }|| r t||}|S)z(Main function for Product simplificationrTFrjr) r rrrqrrr:rr4rxr'r{ product_mul)rrrp_tr!rr"r)r*rp_term1r,p_term2tmp_prodr%p_terms rfr r sc MM! E C C ::fd #D dG $ 7#94==#9#9#CF#C1$(KK12 4 JJt  7SX D(+#C. +JAw7"+C.+JAw7qAv#.w#H%h8%-CF&*DG + ++#YFs^) 6Aw(F) Mrhct|t|ur^|dk(rG|j|jk(r?t|j|jzg|jS|dk(r t |j|jz dk(rt |jt |jcxk(rdk(rnn|jdd}|jdd}|jdd}|jdd}|jdd}|jdd}||k(rB||dzk(rt|j|||fS||dzk(rt|j|||fSt ||S)z*Helper function for Product simplificationrrprj)rr4rr:rrxr ) r3r$r*rrArBr,rCrDs rfrFrFsN DzT%[ Q;{{ell*t}}u~~=L LL q[ 671<t{{#s5<<'8=A= Aq)AQ*BQ*B Q*Aa+Ba+BAva<#*4==1b"+#FF26\#*4==1b"+#FF tU rhcrddlm}|dzdk(r"tt|}|dz}|dzdk(r"|dk(r|S|t d|z}t d}t |||}|y|||}|D]H}t||z jdd|zz ks)t|}t||z|k(sF|cSy) zm helper function for ``nthroot`` It denests ``p**Rational(1, n)`` using its minimal polynomial r)solverjrprNg? ) sympy.solversrNrVr+r!r rLabsrr) prprecrNpnrrsolssols rf_nthroot_solverWs $ a%1* tAw  F a%1* Av HQN Bs Aq!Q'Ay A;D sRx=?? r"d({ *S/CQ1$ rhc&fd}t||S)a Takes logarithms and combines them using the following rules: - log(x) + log(y) == log(x*y) if both are positive - a*log(x) == log(x**a) if x is positive and a is real If ``force`` is ``True`` then the assumptions above will be assumed to hold if there is no assumption already in place on a quantity. For example, if ``a`` is imaginary or the argument negative, force will not perform a combination but if ``a`` is a symbol with no assumptions the change will take place. Examples ======== >>> from sympy import Symbol, symbols, log, logcombine, I >>> from sympy.abc import a, x, y, z >>> logcombine(a*log(x) + log(y) - log(z)) a*log(x) + log(y) - log(z) >>> logcombine(a*log(x) + log(y) - log(z), force=True) log(x**a*y/z) >>> x,y,z = symbols('x,y,z', positive=True) >>> a = Symbol('a', real=True) >>> logcombine(a*log(x) + log(y) - log(z)) log(x**a*y/z) The transformation is limited to factors and/or terms that contain logs, so the result depends on the initial state of expansion: >>> eq = (2 + 3*I)*log(x) >>> logcombine(eq, force=True) == eq True >>> logcombine(eq.expand(), force=True) log(x**2) + I*log(x**3) See Also ======== posify: replace all symbols with symbols having positive assumptions sympy.core.function.expand_log: expand the logarithms of products and powers; the opposite of logcombine ch|js|js|Sfd}fd}g}g}ttt j |D]Z}t |tr||rdjg|f3|js|j|Qg}g}g}|jD]} | jr7| dkr2|jtj|j| Ft | tr|| r|j| p|| r|j| |j| t|dkDr|j|||f$|r$t|j||dfJ|j|]t|dk(r7t |dtr$djg|jf|st!fdDr|S|D]\} } } tt#| } t| jdjdt%| z} | r/| jd} t| jd| z} | r/t%| | } }t | tr|fjg| f|j|| ztj'D]a}tt)t%j|D cgc]\}} | jdt%|zc} }d t%|<ct#tj'D]}|vr| vr|| }}|j+|j+kDr||}}|j|tj|jdj|jdz d z|j|j|zt |Scc} }w) Ncl|tjuxr |jxsxr|jduS)NF)r ris_extended_real)rres rfgoodaz$logcombine..f..gooda s;Q]]*R##Pu'P1C1C51P Srhcb|jd}|jxsxr|jduS)NrF)rrris_nonpositive)lrres rfgoodlogz&logcombine..f..goodlogs/q A==KE$Ka.>.>e.K Krhrrrpc3ZK|]"}t|dk(xr |dgk($yw)rprN)rx)rrlog1s rfrz(logcombine..f..;s3QqCQLA-B$q'!*2BBQs(+rkFr)rrsrrzr rrqr,rrr is_Rationalr rrxtuplerrr%r keysrr)rr\r`r$logsrotcoloaiorr_lirrnumdenrbres @rfrzlogcombine..f s RYYI S  L 4 r" $A!S!gajRQ(XX Q&& &B~~"q& !--0 2##B, " r "  "  &r7Q;KKR -rO**B1;7LLO1 $8 u:?z%(C8 HOOR- .QDQQI "GAq!WQZ AAEE!HMM!$c1g-.AUU1X A &7AqA!S!aT !!2q'* QqS! "diik" .A 3/3xx{1<'+q!q 37"1<,=!',.DaM . diik*+ ,A}rTzqbS==?S]]_4"CC DHHSM..q1$((3-2D2DQ2GG%*,,- Qtxx{]+ ,E{)1>> from sympy.simplify.simplify import inversecombine >>> from sympy import asin, sin, log, exp >>> from sympy.abc import x >>> inversecombine(asin(sin(x))) x >>> inversecombine(2*log(exp(3*x))) 6*x ct|trzt|jdtsC|jdjr|jdj t jk(r|jdj}n|jrt|drt|jdk(rjt|jdjdk(rEt|jd|jdr|jdjd}|jrP|j t jk(r3t|jtr|jjd}|S)Nrrrp)argindex) rqr,rrr*r|r}r r~ is_Functionhasattrrxr)rs rfrzinversecombine..fs b# "''!*c*rwwqz/@/@RWWQZ__XYX^X^E^WWQZ^^ ^^I 6BGG !c"''!*//&:a&?"''!*bjj!j&<=WWQZ__Q' 99AFF*"&&#&VV[[^ rhro)rbrs rfrrks,  dA rhcdfd}|jts|S|jtr|jt}|}d}||k7r|}|j d|}||k7r|S)aQ Simplify expressions with KroneckerDelta. The only simplification currently attempted is to identify multiplicative cancellation: Examples ======== >>> from sympy import KroneckerDelta, kroneckersimp >>> from sympy.abc import i >>> kroneckersimp(1 + KroneckerDelta(0, i) * KroneckerDelta(1, i)) 1 ctdD]n}tdD]^}||}||}||dzdz}||dzdz}t||tjus@t||tjus]ypy)NrjrpTF)r'rr truefalse)args1args2i1i2a1a2a3a4s rf args_cancelz"kroneckersimp..args_cancels( BAh 2Y2YBFa<(BFa<(b":'Br2J!'',A   rhc|j}|Dcgc]}t|ts|}}t|dD];\}}|j}|j}||s(tj |zcS|Scc}w)Nrj)rrrqr@r\r r) mrrrdeltasdelta1delta2ryrzrs rfcancel_kronecker_mulz+kroneckersimp..cancel_kronecker_mulsyvv!CZ>%B!CC%fa0 "NFFKKEKKE5%(vvz!  "  Ds A:A:Nc"t|tSr)rqr )rs rfrzkroneckersimp..s As);rh)rr@r6rr)rbrnewexprrs @rfrrsr  88N #  xx ||N+G D T/,,;=QR T/ Krhc  d}d}d}|}ttttzdz tt tzdz g}|jt|t|tt |}|jt |t |t t|}dtttzg}|jt|t|t|}|jt |t |t |}t d fd}|jt|t}|jt|t}|jt |t }|jt|t}d}||}||k7r|j}|S) a@ Simplify bessel-type functions. Explanation =========== This routine tries to simplify bessel-type functions. Currently it only works on the Bessel J and I functions, however. It works by looking at all such functions in turn, and eliminating factors of "I" and "-1" (actually their polar equivalents) in front of the argument. Then, functions of half-integer order are rewritten using trigonometric functions and functions of integer order (> 1) are rewritten using functions of low order. Finally, if the expression was changed, compute factorization of the result with factor(). >>> from sympy import besselj, besseli, besselsimp, polar_lift, I, S >>> from sympy.abc import z, nu >>> besselsimp(besselj(nu, z*polar_lift(-1))) exp(I*pi*nu)*besselj(nu, z) >>> besselsimp(besseli(nu, z*polar_lift(-I))) exp(-I*pi*nu/2)*besselj(nu, z) >>> besselsimp(besseli(S(-1)/2, z)) sqrt(2)*cosh(z)/(sqrt(pi)*sqrt(z)) >>> besselsimp(z*besseli(0, z) + z*(besseli(2, z))/2 + besseli(1, z)) 3*z*besseli(0, z)/2 c0tfd}|S)Ncpjtj|r ||S||Sr)rr r)nuzfactorsfrotos rfreplz*besselsimp..replacer..repls2##CMM!$45"ay r1: rh)r)rrrrs``` rfreplacerzbesselsimp..replacersg,  rhcfd}|S)Nc4||jSr)r)rrrrs rftofuncz-besselsimp..torewrite..tofuncsr1:%%b) )rhr)rrrs`` rf torewritezbesselsimp..torewrites  * rhcfd}|S)Ncztttz|z|tt tz|zzSr)r*rr r-)rrrs rfrz+besselsimp..tominus..tofuncs1qtBw<B 1"R%(8(: ;; ;rhr)rrs` rftominuszbesselsimp..tominuss  < rhrjrrcfd}|S)Nc j|dztjk(rjttt |j t j tjdj|S|jr|dkDr||jdS||S)NrpT)rv) r HalfrrWr0rr;r?rr is_Integer)rrrz0s rfrz*besselsimp..expander..repl sQ166!B ++G4<.expander s  rhcd}|jtr |t|}|jtr |t|}|S)Ncf |jfd} t|dD]o}|j\}}|dz|}|dz|}|j|s<|j|sN|j |d|dzz|z |z|z }n|S #t t f$r|cYSwxYw)Nct|Sr)rq)rbessels rfrzTbesselsimp.._bessel_simp_recursion.._use_recursion..sjF.Crhc2t|jdS)Nr)r.rrrs rfrzTbesselsimp.._bessel_simp_recursion.._use_recursion..sBqvvayMrhrrprj)findsortedrrrrr TypeError)rrbbesselsbarrbap1bap2s` rf_use_recursionzBbesselsimp.._bessel_simp_recursion.._use_recursions))$CD  $W2IJ$!ww1%ac1~%ac1~88D>dhhtn#'99RAaC4$1F#GD! $ $ "#I. K sA B"B4%BB0/B0)rr;r>)rbrs rf_bessel_simp_recursionz*besselsimp.._bessel_simp_recursions>  88G !'40D 88G !'40D rh) rr-r rr;r<rr>r=rJ) rbrrr orig_exprifactors minusfactorsrrrs @rfrrsw@  I9QrT!V$i2a&89H <<''7#X/ 0D <<''7#X/ 0D !B$(L <<'77#3\B DD <<'77#3\B DD sB  <<'!2 3D <<'!2 3D <<'!2 3D <<'!2 3D. "$ 'D y{{} Krhc^t|}t|}|td|z}|js|St|s|Sg}|jDcgc]}|j }}|D]|\}}|j s|cS|tjur)|jr3|jtjk(r|jjs|cS|j|~|j|d|}|dkrJ|dzdk(rB| td|z}t||} t!| |zt!| k(r| } | S|} | St||} t!| t!|ur%t!| |zt!|k(r t!| St#|||}||S|Scc}w)a" Compute a real nth-root of a sum of surds. Parameters ========== expr : sum of surds n : integer max_len : maximum number of surds passed as constants to ``nsimplify`` Algorithm ========= First ``nsimplify`` is used to get a candidate root; if it is not a root the minimal polynomial is computed; the answer is one of its roots. Examples ======== >>> from sympy.simplify.simplify import nthroot >>> from sympy import sqrt >>> nthroot(90 + 34*sqrt(7), 3) sqrt(7) + 3 rpNrrj) constants)rr! is_integerrKrrr is_rationalr rr|r*rr}rsortrrrW) rbrmax_lenrSrRsurdsr coeff_mulsyrress rfnthrootr7s6 4=D A hq!nA <<   E,0II6q!.."6J61}}H : QUUaff_1B1BH Q JJL (7OE axAEQJUXa^ # a5 )AqD>Xte_4at ;<t !u%A{(1+%(1a4.HTN*J{ $4 (D | K-7sF*c  tt|S#ttf$rYnwxYwt|j t dt jt dt ji}|t jus|t jur|S|s |jr t||Skdtdg|jt Dcgc]5}tjjj!|j"7ncc}wc}z zdt%dzi|D]R}t|}|j'}|j(s td|j+t-|<T|j'd } | j/\} } | j0r | j0s|Sfd } | r| | } | r| | } n"#t$r|t|| cYS|cYSwxYw| | t j2zz} | |k7s|d ur| St|| S) a  Find a simple representation for a number or, if there are free symbols or if ``rational=True``, then replace Floats with their Rational equivalents. If no change is made and rational is not False then Floats will at least be converted to Rationals. Explanation =========== For numerical expressions, a simple formula that numerically matches the given numerical expression is sought (and the input should be possible to evalf to a precision of at least 30 digits). Optionally, a list of (rationally independent) constants to include in the formula may be given. A lower tolerance may be set to find less exact matches. If no tolerance is given then the least precise value will set the tolerance (e.g. Floats default to 15 digits of precision, so would be tolerance=10**-15). With ``full=True``, a more extensive search is performed (this is useful to find simpler numbers when the tolerance is set low). When converting to rational, if rational_conversion='base10' (the default), then convert floats to rationals using their base-10 (string) representation. When rational_conversion='exact' it uses the exact, base-2 representation. Examples ======== >>> from sympy import nsimplify, sqrt, GoldenRatio, exp, I, pi >>> nsimplify(4/(1+sqrt(5)), [GoldenRatio]) -2 + 2*GoldenRatio >>> nsimplify((1/(exp(3*pi*I/5)+1))) 1/2 - I*sqrt(sqrt(5)/10 + 1/4) >>> nsimplify(I**I, [pi]) exp(-pi/2) >>> nsimplify(pi, tolerance=0.01) 22/7 >>> nsimplify(0.333333333333333, rational=True, rational_conversion='exact') 6004799503160655/18014398509481984 >>> nsimplify(0.333333333333333, rational=True) 1/3 See Also ======== sympy.core.function.nfloat infz-infrOgp= ף @zconstants must be real-valuedT)chopctjj}|j} sjshdtj_tj|dg}|:t t |d t |d|tj_S tj_tj| }|str|d}t|}|r|st|jdur(|tjtjfvrt||tj_S#|tj_wxYw)Nrrpr)rtolfullF) mpmathmpdps _to_mpmathpslqr!intidentifyrr is_finiterninf) rorigxvratrrbbprecconstants_dictrrS tolerances rfnsimplify_realz!nsimplify..nsimplify_realsyy}} \\%  ! " kk2q'*?#SQ[L#c!f+>"!FIIM!!FIIMoobND*G  !!*7#D  ~~&2fjj&++5N+N  !FIIMDFIIMsAD9B D99E)rational_conversionF)rr^rrr rr rNegativeInfinityry_real_to_rationalrrrlibmplibmpf prec_to_dps_precrevalfis_Floatrstr as_real_imagr ImaginaryUnit)rbrrrrrrr=rexprvalr.imrrrrrSs `` @@@rfrrss0l vd|$$ z "   4= ! ! e ajj f q))#  D qzzTQ%7%77 4$$ y2EFF bTjj')ll!!--agg6)))*** D T NEN<8$ NN4 zz<= =() U(;s8}% <jjDj)G  ! ! #FB LLR\\ !!6 #B #B   $T?RS S  b B TzX& T7J KKs*--:D G22H HHc  t|}td}|}i}d}||dkrtd|z }|jtD]}|}|t |j |} n|G|dk\rB|j dur4t |t||z zj t|} n7|dk(rt |} | ||<|dk7r tdt|d} |r| s t |} n| js||| fvrtj} n|d kr]| }td ttj |tj d z } t t#|| z  | z} nn|d kDrYtd ttj |tj d z } t t#|| z | z} ntj$} | ||<|j'|d S) a) Replace all reals in expr with rationals. Examples ======== >>> from sympy.simplify.simplify import _real_to_rational >>> from sympy.abc import x >>> _real_to_rational(.76 + .1*x**.5) sqrt(x)/10 + 19/25 If rational_conversion='base10', this uses the base-10 string. If rational_conversion='exact', the exact, base-2 representation is used. >>> _real_to_rational(0.333333333333333, rational_conversion='exact') 6004799503160655/18014398509481984 >>> _real_to_rational(0.333333333333333) 1/3 rNrpFexactbase10z/rational_conversion must be 'base10' or 'exact'rrrOTr)r&rr5rr!limit_denominatorrroundrrrrcr ComplexInfinityr rr,rrr) rbrrrrRr reduce_numflrrrs rfrrs, D>D ,C A DJQQy[) ggen   ! ..z:A# Q &5I#66##C N3 #g-RLS $0 !RSS"u-A!RL]]#t$))A!VBBFJJrN6::b>$A BCA!#bd),,Q.A!VBFJJrN6::b>$A BCA RT+A-AAS A B 66$T6 **rhcnd}|j}|jrtj||z fS|r^||k7rY|}|r|j nt |j d\}}||z}|jd\}}||z}|r||k7rYt|d}|jr| }| }||fS)ahReturn `p, r` where `p` is the expression obtained when Rational additive and multiplicative coefficients of `expr` have been stripped away in a naive fashion (i.e. without simplification). The operations needed to remove the coefficients will be applied to `rhs` and returned as `r`. Examples ======== >>> from sympy.simplify.simplify import clear_coefficients >>> from sympy.abc import x, y >>> from sympy import Dummy >>> expr = 4*y*(6*x + 3) >>> clear_coefficients(expr - 2) (y*(2*x + 1), 1/6) When solving 2 or more expressions like `expr = a`, `expr = b`, etc..., it is advantageous to provide a Dummy symbol for `rhs` and simply replace it with `a`, `b`, etc... in `r`. >>> rhs = Dummy('rhs') >>> clear_coefficients(expr, rhs) (y*(2*x + 1), _rhs/12) >>> _[1].subs(rhs, 2) 1/6 NTrFr) ryrcr rrrr as_coeff_Addrr)rbrhswasfreerrs rfclear_coefficientsr?s6 C   D d ## 3$;  % % '   + +T + : 4 q##T#24 q 3$; DU +D $$&ud 9rhc  #$%&t|tr.|jd}ttt t f\#$%}nttttf\#$%}d}$%fd}#$%&fd&&fd}t|#$%fr |jr|S|jdd}t|%r*|r&%t|d|d jS|St|#r,#|Dcgc]}t|| c}jS|j\}}t|} t| d s| t|| z | zS||\} }d} | t!|d z kDrd } |ddd Dcgc]}|d z }}|rt#d|D}||} i} d }d }d}d}t%d t!|D]}d}d}d}|t!|d z kr| |d}|}|d z}|t!|d z k(sdgk(rt||%rst||jd|sW||jdj}t!|}|||z ||k(r |d z }||z}||d z|d z|z|k(r |d z }||z }|r|||jd z }n|d}||d z z}|||}d }||z }| vr | ||k\r|t!|krq|| |d z dvr |d z }||z }nJt||%r:||jdj|k(r|||jd z }|d z }nn|t!|krqd}d }||z dk\r|||z d z||d dk(rt|d%r%|djd}|djd }n|d}d }t|||z %r;|||z jd|k(r#|||z jd |z }||z}|d z }n|||z |k(rd |z }||z}|d z }d}d }||zd z t!|kr||||zd z |dd k(rt|d %r%|d jd}|d jd }n|d }d }t|||zd z %rA|||zd z jd|k(r&|||zd z jd |z }||z }|d z }n|||zd z |k(rd |z }||z }|d z }|rd zdk(r|dkDr|d z }d }d } t||d z %r6||d z jd|k(r||z} ||d z jd |z }n||d z |k(r ||z} d |z }|dk(s| dk(r |s|d z}| }|}|}||zf|dd z||zfz}|||z z }|r|d z}|r|d z}|| |<||kDs|}|$||||f}||z}||z}|rl%t|d | |d }t$|d|d|z| }|t$||dd| z}||z|z}|d k7s|d k7rt|d }n$|}| r %|d }t|ts(t'|}!|!|k7rt|!| }"|||"}|S|jd}|Scc}wcc}w)a Simplify a non-commutative expression composed of multiplication and raising to a power by grouping repeated subterms into one power. Priority is given to simplifications that give the fewest number of arguments in the end (for example, in a*b*a*b*c*a*b*c simplifying to (a*b)**2*c*a*b*c gives 5 arguments while a*b*(a*b*c)**2 has 3). If ``expr`` is a sum of such terms, the sum of the simplified terms is returned. Keyword argument ``deep`` controls whether or not subexpressions nested deeper inside the main expression are simplified. See examples below. Setting `deep` to `False` can save time on nested expressions that do not need simplifying on all levels. Examples ======== >>> from sympy import symbols >>> from sympy.simplify.simplify import nc_simplify >>> a, b, c = symbols("a b c", commutative=False) >>> nc_simplify(a*b*a*b*c*a*b*c) a*b*(a*b*c)**2 >>> expr = a**2*b*a**4*b*a**4 >>> nc_simplify(expr) a**2*(b*a**4)**2 >>> nc_simplify(a*b*a*b*c**2*(a*b)**2*c**2) ((a*b)**2*c**2)**2 >>> nc_simplify(a*b*a*b + 2*a*c*a**2*c*a**2*c*a) (a*b)**2 + 2*(a*c*a)**3 >>> nc_simplify(b**-1*a**-1*(a*b)**2) a*b >>> nc_simplify(a**-1*b**-1*c*a) (b*a)**(-1)*c*a >>> expr = (a*b*a*b)**2*a*c*a*c >>> nc_simplify(expr) (a*b)**4*(a*c)**2 >>> nc_simplify(expr, deep=False) (a*b*a*b)**2*(a*c)**2 F) inv_expandc|ddDcgc]}||dk(rddgndgc}g}tdt|D]}g}d}tt||z dz D]o}g}||dz |dzD]C}||zdz|zt|ks|||||zdz|zk(s0|j|dzE|dgz }|j|q|j||Scc}w)Nrpr)r'rxr)rrrrroverlapsr,overlaprs rf _overlapsznc_simplify.._overlapss:>ab BAd1g1vA3. B Cq#d)$ AHA3t9q=1,- )1Q3!.A1uqy1}s4y0T!WQqSU1W 5Mq1u-.A3(  ) HHX  CsCcd}g}g}|D]}t|r(|jdjr|dzg|z}|dz }7t|dk(r|j |ddzn:t|dkDr,|j |d|t|dz z}g}|j ||r,|j |d|t|dz z}|t |fS)Nrrpr)rqrris_extended_negativerxrrd)_argsinv_totinversesrrr_Mul_Pows rf_reduce_inversesz%nc_simplify.._reduce_inversess  !C#t$!)I)IG9x/1 x=A%KK R0]Q&KKT8_b 9:s8}q00G C  !  KKT8_b1 2 s8}q( (Gd ##rhct|r|jdSt|frtfd|jDSy)Nrc3.K|] }|ywrr)rr get_scores rfrz1nc_simplify..get_score..s4y|4srp)rqrrsum)r_Addrrrs rfrznc_simplify..get_scoresH a QVVAY' ' D$< (4QVV44 4rhc8||k7r||kr|S|Srr)ralt_srs rfcompareznc_simplify..compares& :)E*Yq\9LrhNrrprrjTrc32K|]}t|ywr)r)rrs rfrznc_simplify..s2[^2s)rqrCrrDrErFrGr r r r rrrrrr"rxrdr'r)'rbr_Symbolrrrrrrc_args com_coeffrinvertrsimpspostpremax_simp_coeffsimpr simp_coeffr_rRrepstartendsubtermpre_exppre_argr*post_exppost_arg_pre_exp _post_expf_expralt_simprrrrs' @@@@rfrrmsR$ #yyEy*$*FFL$H!dD'$'c6$9!dD'0$4 dT4. /43F3F 99QAk!$/>?DDFF}} L Iq)[idCC C$T*MGTFT1#DbDz*!2** 2T22$A E D CN D 1c$i F&   s4y1} A$q'Cc D ! sqcz47D) *47<<?G Dq',,q/..L!A;')FAQJE!AaCE?g-FA1HCT!W\\!_$AA QUNE5oGA 1HC e g% 7 CIoAc!eHQKQqDIt,c1B1G1G71RT#Y^^A&&qCIo 19>d5719U3wqr{B'!*d+!!*//!,ajooa(!!*$uQw-.4a=3E3Ea3HG3SuQw-,,Q/#5 QeAg')c' Q 7Q;T "tCAa'8GCRL'H'"+t,"2;++A.bk&&q)"2;$s1uQw-.4Aa=3E3Ea3HH3TAa=--a036qQc!eAg(*s7qQ a1 a%CHI$uQw-.4a=3E3Ea3HH3T$sN a=--a036eAg(*$sN s71} QQJE$""#S=*WSb\9Xs]1c15D7"CX%DMF&P {476Q@$Xd1g/3$?Kd478n 5DAA7{4 !8tqyt%0DT{ D"~ dJ '4 T>"65H4*D KyyEy* KQ?+s (Y72 Y<c  d} fd d}t|tr|js|js |jr|j dddddddd}||k7r|}d}||\}}|dk\rj|ri} ||}||us||ddk\rht |}||k7rW|j|jD cgc] \} } | | f c} } }d}n|d k(r|jr |jdjr|jd jr|jdjd jr|jd jd jr|jdjd jtjurV|jd jd jtjur t|}||d} | |kr|}d}nd}|r||fS|Scc} } w) aSimplification for a sum of products targeted at the kind of blowup that occurs during summation of products. Intended to reduce expression blowup during matrix multiplication or other similar operations. Only works with algebraic expressions and does not recurse into non. Parameters ========== withsimp : bool, optional Specifies whether a flag should be returned along with the expression to indicate roughly whether simplification was successful. It is used in ``MatrixArithmetic._eval_pow_by_recursion`` to avoid attempting to simplify an expression repetitively which does not simplify. cd}|g}d}|rA|j}t|ts$|jrI|tj ur|t |jdkt |jdk7zz }n|jr |jr;|dz }|jdtjur|jd}n| }t|\}}|jr'|dt |dkzz }|j!|n.|tj ur6|js|j!|d}|dz }|j!|n|t#|jdz z }|j%|jn|j&r]t#|j}d}|jD]+} | jr|dz }| } |j!| -||||k7z z }nF|j(r:|dz }|j!|j*|s|j,j.du}|rA||fS)ajOptimized count algebraic operations with no recursion into non-algebraic args that ``core.function.count_ops`` does. Also returns whether rational functions may be present according to negative exponents of powers or non-number fractions. Returns ======= ops, ratfunc : int, bool ``ops`` is the number of algebraic operations starting at the top level expression (not recursing into non-alg children). ``ratfunc`` specifies whether the expression MAY contain rational functions which ``cancel`` MIGHT optimize. rFrpT)rrqrrcr rboolrRqrsrrrr as_two_termsrTrrrxextendrr|r}r* is_negative) rbopsrrratfuncrrrlaargsnegsrjs rf count_ops_algz"dotprodsimp..count_ops_algs & Aa'}}AEE>4q>D!##(O;;C--/1HCvvayAMM1NN,Q/B{1<<1tQU|++CKKNaee^<< A $1HCKKN3qvv;?*CKK'QVV&&$B224 !#KKO $ v00q AFF#ee//u.nonalg_subs_dummiess yyK ;;$++D!$)), 1'736< ?DQ | 499d# #!!$00rhFTN)rmodulus power_base power_exprlr,rmrrrpr)rqrrrsr|rrIrrrrr*r rrH) rbwithsimpr* simplifiedrexpropsr'r-expr3rrexpr2opsr.s @rf dotprodsimpr9s KZ1:J$DKK4;;$++ t5d%Q D=DJ(. a<-dG<D=M%$8$;q$@"5ME~%*ZZGMMO0TDAq!Q0T%U%) lt{{tyy!}/C/C 1 $$A););R)@)G)G 1 ""B'.. 1 ""B'++q}}< 1 ""B'++q}}<E$U+A.H'!"! J!)D* 3t3)1UsH z Using bottom_up from the sympy.simplify.simplify submodule is deprecated. Instead, use bottom_up from the top-level sympy namespace, like sympy.bottom_up z1.10z$deprecated-traversal-functions-moved)deprecated_since_versionactive_deprecations_targetz Using walk from the sympy.simplify.simplify submodule is deprecated. Instead, use walk from sympy.core.traversal.walk r)rbrreturnr)rbrBr<rB)rbrMr<rM)rbrr<r)NFFFT)r)F)r)rNFNr)Nr)T) __future__rtypingr collectionsrsympy.concrete.productsrsympy.concrete.summationsr sympy.corerr r r r r rrrrrrrrsympy.core.exprtoolsrsympy.core.parametersrsympy.core.functionrrrrrrsympy.core.numbersrrr r!r"sympy.core.relationalr#sympy.core.rulesr$sympy.core.sortingr%sympy.core.sympifyr&sympy.core.traversalr'rr(_walksympy.functionsr)r*r+r,r-r.(sympy.functions.combinatorial.factorialsr/$sympy.functions.elementary.complexesr0r1r2&sympy.functions.elementary.exponentialr3%sympy.functions.elementary.hyperbolicr4#sympy.functions.elementary.integersr5$sympy.functions.elementary.piecewiser6r7r8(sympy.functions.elementary.trigonometricr9sympy.functions.special.besselr:r;r<r=r>r?(sympy.functions.special.tensor_functionsr@sympy.integrals.integralsrAsympy.logic.boolalgrBsympy.matrices.expressionsrCrDrErFrG sympy.polysrHrIrJ sympy.polys.numberfields.minpolyrKrLsympy.sets.setsrMsympy.simplify.combsimprNsympy.simplify.cse_optsrOrPsympy.simplify.hyperexpandrQsympy.simplify.powsimprRsympy.simplify.radsimprSrTrUsympy.simplify.sqrtdenestrVsympy.simplify.trigsimprWrXsympy.utilities.decoratorrYsympy.utilities.iterablesrZr[r\r]sympy.utilities.miscr^rrgrar`rrrrrrrr5r(r rFrWrrrrrrrrrrr9rrhrfrhs"#+)....+3  CC,&&'G@@JFF:D7FFJBBC.'BB00R,52*AA090JJ'  "UG*T=@@:/z,^%,D N / / 5 5 - - 1 1i%UYSl 64(4)X#L20M`#L0fpf9xHL HLV>+B"#,\EP c4L J$E    z $E   rh