K iddlmZddlmZddlmZddlmZddlm Z m Z m Z ddl m Z ddlmZddlmZmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9m:Z:ddl;mdZ?d@dZ@dZAdZBdZCdAdZDdAdZEd ZFdBd!ZGd"ZHdBd#ZId$ZJdCd&ZKd'ZLdBd(ZMd)ZNd*ZOd+ZPdBd,ZQdAd-ZRdAd.ZSd/ZTdAd0ZUd1ZVd2ZWee?eAeBeDeEeFeGeHeIeKeMeOe@ePeQeReSeNeTeUf\Z=Z>Z?ZAZBZDZEZFZGZHZIZKZMZOZ@ZPZQZRZSZNZTZUeDe=feEe=fe9gZZeKeDe=feEe=fe=gfZ[ePeGe=fePeGeJe=fe9gZ\eBeJfe9gZ]eBeAeBeMeBeOeBe=fZ^eBeAeIeBeAeKfeDeFeKeBfe\eZeHe[eBeHeHe]fe9gZ_d3fd4Z`dDd5Zad6jZcedeXeeeceXeYefjecZhed7Zied8Zjed9Zkd@d:Zld;Zmd<Znd=Zod>Zpd?Zqy%)E) defaultdict)Add)cacheit)Expr)Factors gcd_terms factor_terms) expand_mul)Mul)piI)Pow)S)ordered)Dummy)sympify bottom_up)binomial)coshsinhtanhcothsechcschHyperbolicFunction)cossintancotseccscsqrtTrigonometricFunction) perfect_power)factor)greedy)identitydebug) SYMPY_DEBUGcZ|jjjS)zSimplification of rational polynomials, trying to simplify the expression, e.g. combine things like 3*x + 2*x, etc.... )normalr&expandrvs W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/simplify/fu.pyTR0r1 s" 99;    & & ((c d}t||S)zReplace sec, csc with 1/cos, 1/sin Examples ======== >>> from sympy.simplify.fu import TR1, sec, csc >>> from sympy.abc import x >>> TR1(2*csc(x) + sec(x)) 1/cos(x) + 2/sin(x) ct|tr+|jd}tjt |z St|t r+|jd}tjt|z S|SNr) isinstancer!argsrOnerr"rr/as r0fzTR1..f5sY b#  A55Q<  C  A55Q<  r2rr/r;s r0TR1r=)s R r2c d}t||S)a@Replace tan and cot with sin/cos and cos/sin Examples ======== >>> from sympy.simplify.fu import TR2 >>> from sympy.abc import x >>> from sympy import tan, cot, sin, cos >>> TR2(tan(x)) sin(x)/cos(x) >>> TR2(cot(x)) cos(x)/sin(x) >>> TR2(tan(tan(x) - sin(x)/cos(x))) 0 ct|tr&|jd}t|t |z St|t r&|jd}t |t|z S|Sr5)r6rr7rrr r9s r0r;zTR2..fSsY b#  Aq6#a&= C  Aq6#a&=  r2rr<s r0TR2r@As$ R r2c&fd}t||S)aConverts ratios involving sin and cos as follows:: sin(x)/cos(x) -> tan(x) sin(x)/(cos(x) + 1) -> tan(x/2) if half=True Examples ======== >>> from sympy.simplify.fu import TR2i >>> from sympy.abc import x, a >>> from sympy import sin, cos >>> TR2i(sin(x)/cos(x)) tan(x) Powers of the numerator and denominator are also recognized >>> TR2i(sin(x)**2/(cos(x) + 1)**2, half=True) tan(x/2)**2 The transformation does not take place unless assumptions allow (i.e. the base must be positive or the exponent must be an integer for both numerator and denominator) >>> TR2i(sin(x)**a/(cos(x) + 1)**a) sin(x)**a/(cos(x) + 1)**a c  |js|S|j\}}|js |jr|S fd |j}t |j Dcgc]"} |||r||j |f$}}|s|S|j}t |j Dcgc]"} |||r||j |f$}}|s|S fd}||||||g}|D]"}t|trt|jdd}||vrC||||k(r8|jt|jd||zdx||<||<u sxd|z} | |vs|| ||k(s|jt|jddz ||zdx||<|| <t|trft|jdd}||vs||||k(s|jt|jd|| zdx||<||<? sC|jsQ|jdtjusrt|jdtst|jdjdd}||vs||||k(s||j s|j"s|jt|jddz || zdx||<||<%|rt%||j'D cgc] \} } | s | | zc} } zt%|j'D cgc] \} } | s | | zc} } z }|t%|D cgc] \} } | | z c} } t%|D cgc] \} } | | z c} } z z}|Scc}wcc}wcc} } wcc} } wcc} } wcc} } w)Nc|jxs |jxrb|jttfvxsHxrD|j xr6t |jdk\xrtd|jDS)Nc3fK|])}tdtj|D+yw)c3K|]6}t|txs |jxr|jtu8ywN)r6ris_Powbase).0ais r0 z8TR2i..f..ok...s8,#2s+Kryy/KRWW^K,s<>N)anyr make_args)rJr:s r0rLz.TR2i..f..ok..s3=01,--*,,=s/1) is_integer is_positivefuncrris_Addlenr7rM)kehalfs r0okzTR2i..f..oksx.?3*$>*=*=AFF q *==56VV==  @r2cg}|D]Y}|jst|jdkDs)r t|n t |}||k7sG|j ||f[|rjt |D]\}\}}||=|||<t|j}|D]/}||||z}||r|||<|j ||f1~yyN) rRrSr7r&r append enumerater as_powers_dict) dddonenewkrTknewivrVrWs r0 factorizez"TR2i..f..factorizesD /88AFF a(,6!9,q/Dqy QI.  / $-dO#LAy4!"DG#Dz002-A!tAwA!Qx ! aV, - r2rFevaluaterZrD)is_Mulas_numer_denomis_Atomr]listkeyspopr6rrr7r[rrRrr8rOrPr items)r/nr^rTndoner_rdtr:a1brUrWrVs @r0r;zTR2i..f{syyI  "1 99 I @    (,QVVXJ1bAaDk!QUU1XJJI   (,QVVXJ1bAaDk!QUU1XJJI & !U!U  'A!S!q E26adadlHHS^QqT12"&&AaD1Q4QBQw1R5AaD=#affQik"2QqT!9:'++!quAs#q E26adadlHHS^adU23"&&AaD1Q4!((qvvayAEE'9qvvay#.q q)E:6adadl! HHS1-!u45"&&AaD1Q4- '0 qQWWYqwwy6tq!Aad678B #/A1/06N1q!t6N1OO OB AK Kn=6/6Ns<.OOO O  O% O% O+ O+ $O1 O7r)r/rVr;s ` r0TR2irs_s8Sj R r2cZddlmfd}|jdd}t||S)aRInduced formula: example sin(-a) = -sin(a) Examples ======== >>> from sympy.simplify.fu import TR3 >>> from sympy.abc import x, y >>> from sympy import pi >>> from sympy import cos >>> TR3(cos(y - x*(y - x))) cos(x*(x - y) + y) >>> cos(pi/2 + x) -sin(x) >>> cos(30*pi/2 + x) -cos(x) rsignsimpc Dt|ts|S|j|jd}t|ts|S|jdtj dz z j tj dz |jdz j cxurdurwn|Stttttttttttti}|t|tj dz |jdz }|S)NrrDT)r6r$rQr7rPirPrrrr r!r"type)r/fmaprvs r0r;zTR3..fs"34I WWXbggaj) *"34I GGAJa  , ,a"''!*1D0Q0Q YUY Y c3S#sCc3ODd2hQ 34B r2c"t|tSrG)r6r$xs r0zTR3..s*Q 56r2c*|jddS)Nc6|jxr |jSrG) is_numberrgrns r0rz'TR3....sakk.ahhr2c4|j|jSrGrQr7rs r0rz'TR3....sfaffaffor2replacer}s r0rzTR3..s!)) . %'r2)sympy.simplify.simplifyrvrr)r/r;rvs @r0TR3rs4$1  6 ' (B R r2c*|jddS)aIdentify values of special angles. a= 0 pi/6 pi/4 pi/3 pi/2 ---------------------------------------------------- sin(a) 0 1/2 sqrt(2)/2 sqrt(3)/2 1 cos(a) 1 sqrt(3)/2 sqrt(2)/2 1/2 0 tan(a) 0 sqt(3)/3 1 sqrt(3) -- Examples ======== >>> from sympy import pi >>> from sympy import cos, sin, tan, cot >>> for s in (0, pi/6, pi/4, pi/3, pi/2): ... print('%s %s %s %s' % (cos(s), sin(s), tan(s), cot(s))) ... 1 0 0 zoo sqrt(3)/2 1/2 sqrt(3)/3 sqrt(3) sqrt(2)/2 sqrt(2)/2 1 1 1/2 sqrt(3)/2 sqrt(3) sqrt(3)/3 0 1 zoo 0 ct|txr2|jdtz x}jxr|j dvS)Nr)rZrDrx)r6r$r7r is_Rationalq)r~rs r0rzTR4..sC q/ 0 Eq " _Q ) ) E./cc_.Dr2c|j|jdj|jdjSr5rr}s r0rzTR4.. s2 FF>166!9>>166!9>>2 3r2rr.s r0TR4rs 0 :: E 4  55r2c6fd}t||S)a+Helper for TR5 and TR6 to replace f**2 with h(g**2) Options ======= max : controls size of exponent that can appear on f e.g. if max=4 then f**4 will be changed to h(g**2)**2. pow : controls whether the exponent must be a perfect power of 2 e.g. if pow=True (and max >= 6) then f**6 will not be changed but f**8 will be changed to h(g**2)**4 >>> from sympy.simplify.fu import _TR56 as T >>> from sympy.abc import x >>> from sympy import sin, cos >>> h = lambda x: 1 - x >>> T(sin(x)**3, sin, cos, h, 4, False) (1 - cos(x)**2)*sin(x) >>> T(sin(x)**6, sin, cos, h, 6, False) (1 - cos(x)**2)**3 >>> T(sin(x)**6, sin, cos, h, 6, True) sin(x)**6 >>> T(sin(x)**8, sin, cos, h, 10, True) (1 - cos(x)**2)**4 cJ|jr|jjk(s|S|jjs|S|jdkdk(r|S|jkDdk(r|S|jdk(r|S|jdk(r(|jj ddzS|jdzdk(rZ|jdz}|jj d|jj ddz|zzS|jdk(rd}nKs!|jdzr|S|jdz}n(t |j}|s|S|jdz}|jj ddz|zS)NrTrZrDrx)rHrIrQexpis_realr7r%)r/rUpr;ghmaxpows r0_fz_TR56.._f>sg  bgglla/Ivv~~I FFQJ4 I FFSLT !I 66Q;I 66Q;Qrww||A'*+ +vvzQFFAIa)!Abggll1o,>,A*BA*EEE166A:IFFAI!"&&)IFFAIQrww||A'*+Q. .r2r)r/r;rrrrrs ````` r0_TR56r$s4!/!/F R r2c6t|ttd||S)aReplacement of sin**2 with 1 - cos(x)**2. See _TR56 docstring for advanced use of ``max`` and ``pow``. Examples ======== >>> from sympy.simplify.fu import TR5 >>> from sympy.abc import x >>> from sympy import sin >>> TR5(sin(x)**2) 1 - cos(x)**2 >>> TR5(sin(x)**-2) # unchanged sin(x)**(-2) >>> TR5(sin(x)**4) (1 - cos(x)**2)**2 c d|z SrYr}s r0rzTR5..v Qr2rr)rrrr/rrs r0TR5rd$ S#CS AAr2c6t|ttd||S)aReplacement of cos**2 with 1 - sin(x)**2. See _TR56 docstring for advanced use of ``max`` and ``pow``. Examples ======== >>> from sympy.simplify.fu import TR6 >>> from sympy.abc import x >>> from sympy import cos >>> TR6(cos(x)**2) 1 - sin(x)**2 >>> TR6(cos(x)**-2) #unchanged cos(x)**(-2) >>> TR6(cos(x)**4) (1 - sin(x)**2)**2 c d|z SrYrr}s r0rzTR6..rr2r)rrrrs r0TR6ryrr2c d}t||S)aLowering the degree of cos(x)**2. Examples ======== >>> from sympy.simplify.fu import TR7 >>> from sympy.abc import x >>> from sympy import cos >>> TR7(cos(x)**2) cos(2*x)/2 + 1/2 >>> TR7(cos(x)**2 + 1) cos(2*x)/2 + 3/2 c|jr,|jjtk(r|jdk(s|Sdtd|jj dzzdz S)NrDrZr)rHrIrQrrr7r.s r0r;zTR7..fsM bggllc1bffkIC"'',,q/)**A--r2rr<s r0TR7rs . R r2c&fd}t||S)aqConverting products of ``cos`` and/or ``sin`` to a sum or difference of ``cos`` and or ``sin`` terms. Examples ======== >>> from sympy.simplify.fu import TR8 >>> from sympy import cos, sin >>> TR8(cos(2)*cos(3)) cos(5)/2 + cos(1)/2 >>> TR8(cos(2)*sin(3)) sin(5)/2 + sin(1)/2 >>> TR8(sin(2)*sin(3)) -cos(5)/2 + cos(1)/2 c|js\|jrN|jjtt fvr,|j js|jjs|S r|jDcgc] }t|c}\}}t|d}t|d}||k7s||k7rzt||z }|jr`|jdjrGt|jdk(r/|jdj rt#|j%}|Stgt gdgi}t#j&|D]}|jtt fvr+|t)|j+|jdF|jr|j j,r~|j dkDro|jjtt fvrM|t)|jj/|jjdg|j z|dj+||t}|t } |r| st|dkDst| dkDs|S|d}t1t|t| }t3|D]Q}| j5} |j5} |j+t | | zt | | z zdz St|dkDr^|j5} |j5} |j+t | | zt | | z zdz t|dkDr^|r(|j+t |j5t| dkDr_| j5} | j5} |j+t | | z t | | z zdz t| dkDr_| r(|j+t | j5ttt#|Scc}w)NFfirstrrDrZ)rgrHrIrQrrrrOrPrhr TR8rr7rrSrRr as_coeff_MulrNrzr[ is_Integerextendminrangerl) r/rbrnr^newnnewdr7r:csrqa2rs r0r;zTR8..fsR II II GGLLS#J & VV  "''"5"5I +-+<+<+>?aJqM?DAqq&Dq&DqyDAItDy)99!7!7BGG )bggaj.?.?boo/0BIRb$+r" %Avv#s#T!W $$QVVAY/((quu//AEEAIFFKKC:-T!&&\"))166;;q>*:155*@AT !!!$ % I Ia3q6A:Q!IDz AA q 9ABB KKR"WBG 4a7 8 9!fqjBB KKR"WBG 4a7 8!fqj KKAEEG %!fqjBB KK#b2g,R"W5q8 9!fqj KKAEEG %:c4j)**Y@s>Qrr/rr;s ` r0rrs"5+n R r2c d}t||S)acSum of ``cos`` or ``sin`` terms as a product of ``cos`` or ``sin``. Examples ======== >>> from sympy.simplify.fu import TR9 >>> from sympy import cos, sin >>> TR9(cos(1) + cos(2)) 2*cos(1/2)*cos(3/2) >>> TR9(cos(1) + 2*sin(1) + 2*sin(2)) cos(1) + 4*sin(3/2)*cos(1/2) If no change is made by TR9, no re-arrangement of the expression will be made. For example, though factoring of common term is attempted, if the factored expression was not changed, the original expression will be returned: >>> TR9(cos(3) + cos(3)*cos(2)) cos(3) + cos(2)*cos(3) cD|js|Sdfd t|S)Ncn|js|Stt|j}t |dk7rd}t t |D]O}||}| t |dzt |D]*}||}| ||z}|} | |k7s| ||<d||<d}OQ|r-t |D cgc]} | s|  c} }|jr|}|St|} | s|S| \} } }}}}|rc| |k(r,| | zdzt||zdz zt||z dz zS| dkr||}}d| zt||zdz zt||z dz zS| |k(r,| | zdzt||zdz zt||z dz zS| dkr||}}d| zt||zdz zt||z dz zScc} w)NrDFrZTr rRrjrr7rSrr trig_splitrr)r/rr7hitrbrKjajwasnewrsplitgcdn1n2r:rriscosdos r0rzTR9..f..do s99 ()D4yA~s4y)"AaBz "1q5#d)4 "!!W:$ 2g g#:&)DG&*DG"&C! " "D7bBr78ByyV %E ', $CRAu8r6!8CQ N23Aqy>AA6aqA#vc1q5!)n,S!a%^;;8r6!8CQ N23Aqy>AA6aqAuS!a%^+CQ N::18s /F27F2T)rRprocess_common_addends)r/rs @r0r;zTR9..fs$yyI< ;|&b"--r2rr<s r0TR9rs.B.H R r2c&fd}t||S)aSeparate sums in ``cos`` and ``sin``. Examples ======== >>> from sympy.simplify.fu import TR10 >>> from sympy.abc import a, b, c >>> from sympy import cos, sin >>> TR10(cos(a + b)) -sin(a)*sin(b) + cos(a)*cos(b) >>> TR10(sin(a + b)) sin(a)*cos(b) + sin(b)*cos(a) >>> TR10(sin(a + b + c)) (-sin(a)*sin(b) + cos(a)*cos(b))*sin(c) + (sin(a)*cos(b) + sin(b)*cos(a))*cos(c) cN|jttfvr|S|j}|jd}|jrart t |j}nt |j}|j}tj|}|jr|tk(rEt|tt|dzt|tt|dzzSt|tt|dzt|tt|dzz S|tk(r/t|t|zt|t|zzSt|t|zt|t|zz S|S)NrFr) rQrrr7rRrjrrlr _from_argsTR10)r/r;argr7r:rrrs r0r;zTR10..fasE 773* $I GGggaj ::GCHH-.CHH~ At$Axx8q6$s1vU";;AtCF%8899q6$s1vU";;AtCF%88998q6#a&=3q6#a&=88q6#a&=3q6#a&=88 r2rrs ` r0rrOs$6 R r2c d}t||S)aSum of products to function of sum. Examples ======== >>> from sympy.simplify.fu import TR10i >>> from sympy import cos, sin, sqrt >>> from sympy.abc import x >>> TR10i(cos(1)*cos(3) + sin(1)*sin(3)) cos(2) >>> TR10i(cos(1)*sin(3) + sin(1)*cos(3) + cos(3)) cos(3) + sin(4) >>> TR10i(sqrt(2)*cos(x)*x + sqrt(6)*sin(x)*x) 2*sqrt(2)*x*sin(x + pi/6) c ( |js|Sd fd t| d}|jrtt}|jD]}d}|j ri|jD]Z}|j s|jtjus-|jjsD||j|d}n|r}|tjj|g}|D]}t|ztfD]}||vst!t#||D]z}||| t!t#||D]U}||| t%||||||z}  | } | | k7s4|j| d|||<d|||<z||rAt%||j'D cgc]} t%| D cgc]} | s|  c} c} } z}n  |} |S|jr|Scc} wcc} } w)Nc|js|Stt|j}t |dk7rd}t t |D]O}||}| t |dzt |D]*}||}| ||z}|} | |k7s| ||<d||<d}OQ|r-t |D cgc]} | s|  c} }|jr|}|St|ddi} | s|S| \} } }}}}|r,| | z} | |k(r| t||z zS| t||zzS| | z} | |k(r| t||zzS| t||z zScc} w)NrDFrZTtwor)r/rr7rrbrKrrrrrrrrrr:rrsamers r0rzTR10i..f..dos99 ()D4yA~s4y)"AaBz "1q5#d)4 "!!W:$ 2g g#:&)DG&*DG"&C! " "D7bBr78ByyV /$/E &+ #CRAtf8s1q5z>)3q1u:~%f8s1q5z>)3q1u:~%-8s /E7Ec>tt|jSrG)tupler free_symbolsr}s r0rz"TR10i..f..seGANN$;<r2rrZr)rRrrrjr7rgrHrrHalfrIrr[r8_ROOT3 _invROOT3rrSrvalues)r/byradr:rrKr7rrrbrrrrcrrs @r0r;zTR10i..fs$yyI6 &p$ <> ii%EWW +88ff"99166)9 " 2 2!"I,,Q/"#C! " !%%L''* +D * (1*ik2*AEz!&s58}!5 *A$Qx{2 (%*3uQx=%9 *#(8A;#6$,&)%(1+a *C&D&(g#&#:$(KK$426E!HQK26E!HQK$) * ** * 4"\\^#-$'a(>2(>#?#--/V QiiP )?#-sH H H  H H rr<s r0TR10irs$iV R r2Nc&fd}t||S)anFunction of double angle to product. The ``base`` argument can be used to indicate what is the un-doubled argument, e.g. if 3*pi/7 is the base then cosine and sine functions with argument 6*pi/7 will be replaced. Examples ======== >>> from sympy.simplify.fu import TR11 >>> from sympy import cos, sin, pi >>> from sympy.abc import x >>> TR11(sin(2*x)) 2*sin(x)*cos(x) >>> TR11(cos(2*x)) -sin(x)**2 + cos(x)**2 >>> TR11(sin(4*x)) 4*(-sin(x)**2 + cos(x)**2)*sin(x)*cos(x) >>> TR11(sin(4*x/3)) 4*(-sin(x/3)**2 + cos(x/3)**2)*sin(x/3)*cos(x/3) If the arguments are simply integers, no change is made unless a base is provided: >>> TR11(cos(2)) cos(2) >>> TR11(cos(4), 2) -sin(2)**2 + cos(2)**2 There is a subtle issue here in that autosimplification will convert some higher angles to lower angles >>> cos(6*pi/7) + cos(3*pi/7) -cos(pi/7) + cos(3*pi/7) The 6*pi/7 angle is now pi/7 but can be targeted with TR11 by supplying the 3*pi/7 base: >>> TR11(_, 3*pi/7) -sin(3*pi/7)**2 + cos(3*pi/7)**2 + cos(3*pi/7) c(|jttfvr|Sr|j}|dz}tj}|j r|j \}}|jttfvr|S|jd|jdk(r7t}t}|tur|dz|dzz |z Sd|z|z|z S|S|jdjs|jdj d\}}|jdzdk(ro|jdz|z|jz }tt|}tt|}|jtk(r d|z|z}|S|dz|dzz }|S)NrDrT)rational) rQrrrr8rgrr7 is_NumberrrTR11) r/r;rpcorrmrrIs r0r;zTR11..f)so 773* $I A$q& ABxx(Avvc3Z' wwqzQVVAY&II8qD1a4K++Q3q58OI%%771:**D*9DAqssQw!|cc1fQhqsslSNSN77c>1QB A1B r2r)r/rIr;s ` r0rrsT!F R r2c d}t||S)a Helper for TR11 to find half-arguments for sin in factors of num/den that appear in cos or sin factors in the den/num. Examples ======== >>> from sympy.simplify.fu import TR11, _TR11 >>> from sympy import cos, sin >>> from sympy.abc import x >>> TR11(sin(x/3)/(cos(x/6))) sin(x/3)/cos(x/6) >>> _TR11(sin(x/3)/(cos(x/6))) 2*sin(x/6) >>> TR11(sin(x/6)/(sin(x/3))) sin(x/6)/sin(x/3) >>> _TR11(sin(x/6)/(sin(x/3))) 1/(2*cos(x/6)) ct|ts|Sd}t||j\}}d}||||}||||}|S)Nc*tt}tj|D]k}|j \}}|j s#|dkDs)|j ttfvsB|t|j|jdm|Sr5) rsetr rN as_base_exprrQrrrzaddr7)flatr7firrrUs r0 sincos_argsz%_TR11..f..sincos_argshsxs#DmmD) 5~~'1<.f..handle_matchtsi! ,Av8C=(DXc]*D"d^%%d+ ,Ir2)r6rmaprh)r/rrrrs r0r;z_TR11..fdsZ"d#I !b.?.?.AB(  "h 1 "h 1 r2rr<s r0_TR11rOs*#J R r2c&fd}t||S)zSeparate sums in ``tan``. Examples ======== >>> from sympy.abc import x, y >>> from sympy import tan >>> from sympy.simplify.fu import TR12 >>> TR12(tan(x + y)) (tan(x) + tan(y))/(-tan(x)*tan(y) + 1) c|jtk(s|S|jd}|jrrt t |j}nt |j}|j }tj|}|jrtt|d}n t|}t||zdt||zz z S|S)NrFrrZ) rQrr7rRrjrrlrrTR12)r/rr7r:rrtbrs r0r;zTR12..fsww#~Iggaj ::GCHH-.CHH~ At$Axx#a&.VFRK!c!fRi-0 0 r2rrs ` r0rrs& R r2c d}t||S)aKCombine tan arguments as (tan(y) + tan(x))/(tan(x)*tan(y) - 1) -> -tan(x + y). Examples ======== >>> from sympy.simplify.fu import TR12i >>> from sympy import tan >>> from sympy.abc import a, b, c >>> ta, tb, tc = [tan(i) for i in (a, b, c)] >>> TR12i((ta + tb)/(-ta*tb + 1)) tan(a + b) >>> TR12i((ta + tb)/(ta*tb - 1)) -tan(a + b) >>> TR12i((-ta - tb)/(ta*tb - 1)) tan(a + b) >>> eq = (ta + tb)/(-ta*tb + 1)**2*(-3*ta - 3*tc)/(2*(ta*tc - 1)) >>> TR12i(eq.expand()) -3*tan(a + b)*tan(a + c)/(2*(tan(a) + tan(b) - 1)) c@ |js|js|js|S|j\}}|jr |js|Si}d}t t j|}t|D]\}}||}|rK|\} } t| jD cgc]} | jdc} } tj|| <| ||<\|jrGt|}|js|j|jtj||<|js|jjs|j j"s||j }|rU|\} } t| jD cgc]} | jdc} } |j|| <| |jz||<Rt|}|jsk|j|jtj||<|s|Sd}t t jt%|} d}t| D]\}}||}|s|| }|rtj&| |<n|jrFt|}|jr.| j|jtj| |<|jr|jjs|j j"ro||j }|rtj| |<n\t|}|jr.| j|jtj| |<+-tj| |<d}t|D cgc]} | jdc} } || }|j)tj}||r||| <n|j+| | |xxt-|  zcc<|rjt | t |z t |j/Dcgc]4\}}t|jDcgc] }t-|c}dz |z6c}}}z }|Scc} wcc} wcc} wcc}wcc}}}w)Nct|}|r`|\}}}|tjurG|jr:t |j dk(r!t d|j Dr||fSyyyyy)NrDc3<K|]}t|tywrG)r6r)rJrs r0rLz/TR12i..f..ok..sABJr3/As) as_f_sign_1r NegativeOnergrSr7all)dirrr;rs r0rWzTR12i..f..okskBA1a %!((s166{a7GA!&&AAa4KB8H(%r2rc|jrNt|jdk(r5|j\}}t|trt|tr||fSyyyyr)rRrSr7r6r)nir:rrs r0rWzTR12i..f..oksPyyS\Q.ww1a%*Q*<a4K+=%/yr2FTrZ)rRrgrHrhr7rjr rNr\rrr8r&rrrOrIrPr rextract_additivelyrlrrm)r/rnr^dokrWd_argsrbrrrrp_rn_argsrr ednewedrUr:s r0r;zTR12i..fs RYY"))I  "1vvQVVI cmmA&'v& *EAr2A1QVV4!&&)45Aq yyBZ99MM"''* !F1I 1 1RWW5H5HrwwKDAq8AaffQi89AVVCF !266 F1IByy bgg.$%EEq 1 *2I cmmLO45v&% !EAr2AsG ! F1Iyy#BZ99"MM"''2()F1I FF--1D1DrwwK()F1I!'B!yy & bgg 6,-EEq $ EEq C+AaffQi+,AQB))!%%0E "CFGGAJ 1I#a& IK% !N fc6l*3=@YY[1J1J59Q36 !8(A8(3)+,3-/0211J,KKB U59^,8(1Js*+R R $R RR/ RRrr<s r0TR12irs*aF R r2c d}t||S)aChange products of ``tan`` or ``cot``. Examples ======== >>> from sympy.simplify.fu import TR13 >>> from sympy import tan, cot >>> TR13(tan(3)*tan(2)) -tan(2)/tan(5) - tan(3)/tan(5) + 1 >>> TR13(cot(3)*cot(2)) cot(2)*cot(5) + 1 + cot(3)*cot(5) c R|js|Stgtgdgi}tj|D]Y}|j ttfvr+|t |j|jdF|dj|[|t}|t}t|dkrt|dkr|S|d}t|dkDrv|j}|j}|jdt|t||zz t|t||zz zz t|dkDrv|r(|jt|jt|dkDrv|j}|j}|jdt|t||zzzt|t||zzzt|dkDrv|r(|jt|jt|SNrrDrZ) rgrr r rNrQrzr[r7rSrl)r/r7r:rprt1t2s r0r;zTR13..f8syyIRb$+r" %Avv#s#T!W $$QVVAY/T !!!$  % I I q6A:#a&1*IDz!fqjBB KKSWSb\1CGCRL4HHI J!fqj KKAEEG %!fqjBB KKCGCRL003r73rBw<3GG H!fqj KKAEEG %Dzr2rr<s r0TR13r*s< R r2c(dfd t|S)aReturns cos(x)*cos(2*x)*...*cos(2**(k-1)*x) -> sin(2**k*x)/(2**k*sin(x)) Examples ======== >>> from sympy.simplify.fu import TRmorrie, TR8, TR3 >>> from sympy.abc import x >>> from sympy import Mul, cos, pi >>> TRmorrie(cos(x)*cos(2*x)) sin(4*x)/(4*sin(x)) >>> TRmorrie(7*Mul(*[cos(x) for x in range(10)])) 7*sin(12)*sin(16)*cos(5)*cos(7)*cos(9)/(64*sin(1)*sin(3)) Sometimes autosimplification will cause a power to be not recognized. e.g. in the following, cos(4*pi/7) automatically simplifies to -cos(3*pi/7) so only 2 of the 3 terms are recognized: >>> TRmorrie(cos(pi/7)*cos(2*pi/7)*cos(4*pi/7)) -sin(3*pi/7)*cos(3*pi/7)/(4*sin(pi/7)) A touch by TR8 resolves the expression to a Rational >>> TR8(_) -1/8 In this case, if eq is unsimplified, the answer is obtained directly: >>> eq = cos(pi/9)*cos(2*pi/9)*cos(3*pi/9)*cos(4*pi/9) >>> TRmorrie(eq) 1/16 But if angles are made canonical with TR3 then the answer is not simplified without further work: >>> TR3(eq) sin(pi/18)*cos(pi/9)*cos(2*pi/9)/2 >>> TRmorrie(_) sin(pi/18)*sin(4*pi/9)/(8*sin(pi/9)) >>> TR8(_) cos(7*pi/18)/(16*sin(pi/9)) >>> TR3(_) 1/16 The original expression would have resolve to 1/16 directly with TR8, however: >>> TR8(eq) 1/16 References ========== .. [1] https://en.wikipedia.org/wiki/Morrie%27s_law c |js|S|r&|j\}}|d|dz Stt}i}g}|jD]|}|j \}} | j rJt|tr:|jdj\} } || j| | ||<l|j|~g} |D]V} || }|j|sd} |dx}}||vr| dz } |dz}||vr| dkDrtd| z|z| zd| zz t|| zz }d}g}t| D]>}|dz}t| |zd}|j|t|||xs||}@t| D]F}|j}t| |zd}||xx|zcc<||r6|j!|H| j||zn4t|jd| z}|j|||z|r;Y| r6t#| |z|D cgc]} || D]} t| | zdc} } z}|Scc} } w)NrrZrDFre)rgrhrrjr7rrr6rrr[sortrrrrlrr )r/rrnr^r7cossotherrrrrUrr:rrTcccinewargtakeccsrbkeyr;s r0r;zTRmorrie..fsyyI $$&DAqQ71Q7? "4  A==?DAq|| 1c 2q ..0AQr"Q Q  -AQA FFHA$RAgFA!GBAgq5 Ab^AqD0RT:FDC"1XAa!!B$7 2"49d.?d3i@ A #1X) WWY!!B$7S T) #CyHHRL ) JJvt|,AEE!HQJALLDG,5 -> sU{26&I-.Q&I;<AaC%(&I(&IIKB &Is!I. rrr<s @r0TRmorrier#Ysv7r R r2c&fd}t||S)aConvert factored powers of sin and cos identities into simpler expressions. Examples ======== >>> from sympy.simplify.fu import TR14 >>> from sympy.abc import x, y >>> from sympy import cos, sin >>> TR14((cos(x) - 1)*(cos(x) + 1)) -sin(x)**2 >>> TR14((sin(x) - 1)*(sin(x) + 1)) -cos(x)**2 >>> p1 = (cos(x) + 1)*(cos(x) - 1) >>> p2 = (cos(y) - 1)*2*(cos(y) + 1) >>> p3 = (3*(cos(y) - 1))*(3*(cos(y) + 1)) >>> TR14(p1*p2*p3*(x - 1)) -18*(x - 1)*sin(x)**2*sin(y)**4 c `|js|SrP|j\}}|tjur+t |d}t |d}||k7s||k7r||z }|Sg}g}|j D]}|j r@|j\}} | js|js|j|L|}ntj} t|} | r| djttfvr9| tjur|j|n|j|| z| \} } } |j| | j| | | |ft!t#|}t%|}t!t'dx}\} }} } } }|r|j)d}|r|d}|| jr|| jr || || k(r|| || k7r|j)d}t+|| || }|| |k7r2|Dcgc]}|| }}|| xx|zcc<|j-d|n9|| |k7r1|Dcgc]}|| }}|| xx|zcc<|j-d|t/|| trt}nt}|j||  || z||| j ddzz|zF|| || k(r|| || k(r}|| || k7rr|j)d}|| }t/|| trt}nt}|j||  || z||| j ddzz|z|j|||| z|rt%||k7rt1|}|Scc}wcc}w)NFrrZrrrD)rgrhrr8TR14r7rHrrOrPr[rrQrrrrjrrSrrlrinsertr6r )r/rnr^rrrprocessr:rrrUrrr;sinotherrkrpABr rbremrs r0r;zTR14..fsyyI $$&DAq~AU+AU+19 dB  :Axx}}1  LLOEEAA! #s3:LLOLLA&HAq" NNAq{{Aq"a8 9# :(ww'(U&*%(^3"1aB AAAJQ4>>adnntqt|R5AbE> ' AA#&qtQqT?D !tt|59&:qt&:&: #A$ 'q# 6!"159&:qt&:&: #A$ 'q# 6)!A$4$'$'!LL1Q4%!*Qqtyy|_a5G*G$)NO$qTQqT\tqt|R5AbE> ' AA#$Q4D)!A$4$'$'!LL1Q4%!*Qqtyy|_a5G*G$)NO$ LL1qt $Y\ u: eB E';';s  N& N+rrs ` r0r&r&s,^@ R r2c*fd}t||S)aConvert sin(x)**-2 to 1 + cot(x)**2. See _TR56 docstring for advanced use of ``max`` and ``pow``. Examples ======== >>> from sympy.simplify.fu import TR15 >>> from sympy.abc import x >>> from sympy import sin >>> TR15(1 - 1/sin(x)**2) -cot(x)**2 c$t|trt|jts|S|j}|dzdk(r(t |j|dzz|jz Sd|z }t |ttd}||k7r|}|S)NrDrZc d|zSrYrr}s r0rz!TR15..f..b !a%r2r)r6rrIrrTR15rr r/rUiar:rrs r0r;zTR15..fY2s# 277C(@I FF q5A:!a%()"''1 1 rT "c3Sc B 7B r2rr/rrr;s `` r0r2r2I  R r2c*fd}t||S)aConvert cos(x)**-2 to 1 + tan(x)**2. See _TR56 docstring for advanced use of ``max`` and ``pow``. Examples ======== >>> from sympy.simplify.fu import TR16 >>> from sympy.abc import x >>> from sympy import cos >>> TR16(1 - 1/cos(x)**2) -tan(x)**2 c$t|trt|jts|S|j}|dzdk(r(t |j|dzz|jz Sd|z }t |ttd}||k7r|}|S)NrDrZc d|zSrYrr}s r0rz!TR16..f..r1r2r)r6rrIrrr2rrr3s r0r;zTR16..fzr5r2rr6s `` r0TR16r;jr7r2c d}t||S)aDConvert f(x)**-i to g(x)**i where either ``i`` is an integer or the base is positive and f, g are: tan, cot; sin, csc; or cos, sec. Examples ======== >>> from sympy.simplify.fu import TR111 >>> from sympy.abc import x >>> from sympy import tan >>> TR111(1 - 1/tan(x)**2) 1 - cot(x)**2 cjt|trB|jjs.|jj r|jj s|St|jtr0t|jjd|j zSt|jtr0t|jjd|j zSt|jtr0t|jjd|j zS|Sr5)r6rrIrPrrO is_negativerr r7rr"rr!r.s r0r;zTR111..fs r3  WW BFF$5$5"&&:L:LI bggs #rww||A'"&&0 0  %rww||A'"&&0 0  %rww||A'"&&0 0 r2rr<s r0TR111r?s  R r2c*fd}t||S)ahConvert tan(x)**2 to sec(x)**2 - 1 and cot(x)**2 to csc(x)**2 - 1. See _TR56 docstring for advanced use of ``max`` and ``pow``. Examples ======== >>> from sympy.simplify.fu import TR22 >>> from sympy.abc import x >>> from sympy import tan, cot >>> TR22(1 + tan(x)**2) sec(x)**2 >>> TR22(1 + cot(x)**2) csc(x)**2 ct|tr"|jjtt fvs|St |t td}t |ttd}|S)Nc |dz SrYrr}s r0rz!TR22..f.. 1q5r2rc |dz SrYrr}s r0rz!TR22..f..rCr2) r6rrIrQr rrr!r"rs r0r;zTR22..fsR2s# c (BI 2sCcs C 2sCcs C r2rr6s `` r0TR22rEs$ R r2c d}t||S)aConvert sin(x)**n and cos(x)**n with positive n to sums. Examples ======== >>> from sympy.simplify.fu import TRpower >>> from sympy.abc import x >>> from sympy import cos, sin >>> TRpower(sin(x)**6) -15*cos(2*x)/32 + 3*cos(4*x)/16 - cos(6*x)/32 + 5/16 >>> TRpower(sin(x)**3*cos(2*x)**4) (3*sin(x)/4 - sin(3*x)/4)*(cos(4*x)/2 + cos(8*x)/8 + 3/8) References ========== .. [1] https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Power-reduction_formulae c Jt|tr t|jttfs|S|j \}}|j d}|jr-|jr |jr_t|trOdd|z ztt|dzdz Dcgc]#}t||t |d|zz |zz%c}z}n|jrt|tr|dd|z ztj|dz dz zztt|dzdz Dcgc]7}t||tj|zzt|d|zz |zz9c}z}n|jr[t|trKdd|z ztt|dz Dcgc]#}t||t |d|zz |zz%c}z}n|jrt|trudd|z ztj|dz zztt|dz Dcgc]7}t||tj|zzt |d|zz |zz9c}z}|jr|d| zt||dz zz }|Scc}wcc}wcc}wcc}wr)r6rrIrrrr7rrPis_oddrrrrris_even)r/rrrnr~rTs r0r;zTRpower..fs~2s# 277S#J(GI~~1 FF1I <Fa^MM1$>%%(!ac'1%5>6=Q8RRz!S11Xc"1Q3Z$)%-QN3AaC{3C$C$)**z!S11Xammac223?DQqSz9K:;:B!QMM1$:%%(!ac'1%5:69K4LLyya1"ghq!A#... $/=Q$)9Ks*(J /t|jtS)zReturn count of trigonometric functions in expression. Examples ======== >>> from sympy.simplify.fu import L >>> from sympy.abc import x >>> from sympy import cos, sin >>> L(cos(x)+sin(x)) 2 )rcountr$r.s r0LrMs RXX+ , --r2c8t||jfSrG)rM count_opsr}s r0rr*sadAKKM2r2c ptt|}tt|}|}t|}t |t s2|j |jDcgc]}t||c}St|}|jttr@||}||||kr|}|jttr t|}|jttr-||}t!t#|}t%||||g|}t%t'|||Scc}w)a7Attempt to simplify expression by using transformation rules given in the algorithm by Fu et al. :func:`fu` will try to minimize the objective function ``measure``. By default this first minimizes the number of trig terms and then minimizes the number of total operations. Examples ======== >>> from sympy.simplify.fu import fu >>> from sympy import cos, sin, tan, pi, S, sqrt >>> from sympy.abc import x, y, a, b >>> fu(sin(50)**2 + cos(50)**2 + sin(pi/6)) 3/2 >>> fu(sqrt(6)*cos(x) + sqrt(2)*sin(x)) 2*sqrt(2)*sin(x + pi/3) CTR1 example >>> eq = sin(x)**4 - cos(y)**2 + sin(y)**2 + 2*cos(x)**2 >>> fu(eq) cos(x)**4 - 2*cos(y)**2 + 2 CTR2 example >>> fu(S.Half - cos(2*x)/2) sin(x)**2 CTR3 example >>> fu(sin(a)*(cos(b) - sin(b)) + cos(a)*(sin(b) + cos(b))) sqrt(2)*sin(a + b + pi/4) CTR4 example >>> fu(sqrt(3)*cos(x)/2 + sin(x)/2) sin(x + pi/3) Example 1 >>> fu(1-sin(2*x)**2/4-sin(y)**2-cos(x)**4) -cos(x)**2 + cos(y)**2 Example 2 >>> fu(cos(4*pi/9)) sin(pi/18) >>> fu(cos(pi/9)*cos(2*pi/9)*cos(3*pi/9)*cos(4*pi/9)) 1/16 Example 3 >>> fu(tan(7*pi/18)+tan(5*pi/18)-sqrt(3)*tan(5*pi/18)*tan(7*pi/18)) -sqrt(3) Objective function example >>> fu(sin(x)/cos(x)) # default objective function tan(x) >>> fu(sin(x)/cos(x), measure=lambda x: -x.count_ops()) # maximize op count sin(x)/cos(x) References ========== .. [1] https://www.sciencedirect.com/science/article/pii/S0895717706001609 )measure)r")r'RL1RL2rr6rrQr7fur=hasrr r@rrrr#rrs)r/rQfRL1fRL2rr:rv1rv2s r0rTrT*sL #w D #w D C B b$ rwwAAAw/ABB RB vvc32h CL72; &B 66#s RB vvc32h(3-  #r3$' 2 tBx ))BsD3cDtt}|rP|jD]@}|j\}}|dkr| }| }|||r||ndfj |BnI|r<|jD],}|t j ||fj |.n tdg}d}|D]b} || } | \}} t| dkDr1t| ddi} || } | | k7r| } d}|j || zL|j || dzd|rt|}|S)aApply ``do`` to addends of ``rv`` that (if ``key1=True``) share at least a common absolute value of their coefficient and the value of ``key2`` when applied to the argument. If ``key1`` is False ``key2`` must be supplied and will be the only key applied. rrZzmust have at least one keyFrfT) rrjr7rr[rr8 ValueErrorrSr)r/rkey2key1abscr:rr7rrTrcr rUrs r0rrsE t D  8A>>#DAq1uBB !T!W!, - 4 4Q 7  8  -A !%%a! " ) )! , -566 D C    G1 q6A:Q''AQ%Cax KK!  KK!A$    $Z Ir2z~ TR0 TR1 TR2 TR3 TR4 TR5 TR6 TR7 TR8 TR9 TR10 TR10i TR11 TR12 TR13 L TR2i TRmorrie TR12i TR14 TR15 TR16 TR111 TR22ctdSrr#rr2r0_ROOT2ra 7Nr2ctdS)Nrr`rr2r0rrrbr2cdtdz S)NrZrr`rr2r0rrs T!W9r2c ||fDcgc] }t|c}\}}|j|\}}|j|j}dx}}tj |j vr#|jtj }| }n>tj |j vr"|jtj }| }||fDcgc]}|jc}\}}d} | ||} | y| \} } } | ||} | y| \}}}| s|s| r#t| tr|||| | | f\} } } }}}||}}|sS| xs| }|xs|}t||jsy||||jd|jdt|tfS| s|s| r|r| r|rt| | jt||jury| | fDchc]}|jc}tfd||fDsy|||| jd| jdt| | jfS| r| s|r|s |r | | ||y| xs| }|xs|}|j|jk7ry| stj} |stj}| |ur)|tz}||||jdt dz dfS| |z t#k(r$|d|zz}||||jdt d z dfS| |z t%k(r$|d| zz}||||jdt d z dfSycc}wcc}wcc}w) a)Return the gcd, s1, s2, a1, a2, bool where If two is False (default) then:: a + b = gcd*(s1*f(a1) + s2*f(a2)) where f = cos if bool else sin else: if bool, a + b was +/- cos(a1)*cos(a2) +/- sin(a1)*sin(a2) and equals n1*gcd*cos(a - b) if n1 == n2 else n1*gcd*cos(a + b) else a + b was +/- cos(a1)*sin(a2) +/- sin(a1)*cos(a2) and equals n1*gcd*sin(a + b) if n1 = n2 else n1*gcd*sin(b - a) Examples ======== >>> from sympy.simplify.fu import trig_split >>> from sympy.abc import x, y, z >>> from sympy import cos, sin, sqrt >>> trig_split(cos(x), cos(y)) (1, 1, 1, x, y, True) >>> trig_split(2*cos(x), -2*cos(y)) (2, 1, -1, x, y, True) >>> trig_split(cos(x)*sin(y), cos(y)*sin(y)) (sin(y), 1, 1, x, y, True) >>> trig_split(cos(x), -sqrt(3)*sin(x), two=True) (2, 1, -1, x, pi/6, False) >>> trig_split(cos(x), sin(x), two=True) (sqrt(2), 1, 1, x, pi/4, False) >>> trig_split(cos(x), -sin(x), two=True) (sqrt(2), 1, -1, x, pi/4, False) >>> trig_split(sqrt(2)*cos(x), -sqrt(6)*sin(x), two=True) (2*sqrt(2), 1, -1, x, pi/6, False) >>> trig_split(-sqrt(6)*cos(x), -sqrt(2)*sin(x), two=True) (-2*sqrt(2), 1, 1, x, pi/3, False) >>> trig_split(cos(x)/sqrt(6), sin(x)/sqrt(2), two=True) (sqrt(6)/3, 1, 1, x, pi/6, False) >>> trig_split(-sqrt(6)*cos(x)*sin(y), -sqrt(2)*sin(x)*sin(y), two=True) (-2*sqrt(2)*sin(y), 1, 1, x, pi/3, False) >>> trig_split(cos(x), sin(x)) >>> trig_split(cos(x), sin(z)) >>> trig_split(2*cos(x), -sin(x)) >>> trig_split(cos(x), -sqrt(3)*sin(x)) >>> trig_split(cos(x)*cos(y), sin(x)*sin(z)) >>> trig_split(cos(x)*cos(y), sin(x)*sin(y)) >>> trig_split(-sqrt(6)*cos(x), sqrt(2)*sin(x)*sin(y), two=True) rZcDdx}}tj}|jr;|j\}}t |j dkDs|sy|jrt |j }n|g}|jd}t|tr|}nBt|tr|}n/|jr"|jtjur||z}ny|rd|d}t|tr|r|}nJ|}nGt|tr|r|}n2|}n/|jr"|jtjur||z}ny|tjur|||fSd||fSt|tr|}nt|tr|}||y|tjur|nd}|||fS)aReturn ``a`` as a tuple (r, c, s) such that ``a = (r or 1)*(c or 1)*(s or 1)``. Three arguments are returned (radical, c-factor, s-factor) as long as the conditions set by ``two`` are met; otherwise None is returned. If ``two`` is True there will be one or two non-None values in the tuple: c and s or c and r or s and r or s or c with c being a cosine function (if possible) else a sine, and s being a sine function (if possible) else oosine. If ``two`` is False then there will only be a c or s term in the tuple. ``two`` also require that either two cos and/or sin be present (with the condition that if the functions are the same the arguments are different or vice versa) or that a single cosine or a single sine be present with an optional radical. If the above conditions dictated by ``two`` are not met then None is returned. NrDr)rr8rgrrSr7rjrlr6rrrHrr)r:rrrrr7rrs r0 pow_cos_sinztrig_split..pow_cos_sinsl( A UU 88NN$EB166{QcxxAFF|s A!S!As#aeeqvvoaGa%3'XX!%%166/!GB1552Aq8 8dAq8 8 3 A 3 A 9 QUU?R1axr2Nrc3:K|]}|jvywrG)r7)rJrbr7s r0rLztrig_split..^s>> from sympy.simplify.fu import as_f_sign_1 >>> from sympy.abc import x >>> as_f_sign_1(x + 1) (1, x, 1) >>> as_f_sign_1(x - 1) (1, x, -1) >>> as_f_sign_1(-x + 1) (-1, x, -1) >>> as_f_sign_1(-x - 1) (-1, x, 1) >>> as_f_sign_1(2*x + 2) (2, x, 1) rDNrrZ)rRrSr7rrr8rgrrr,rrirjrk) rUr:rrrrbrlrmrrrs r0rrws* 88s166{a' 66DAqQ]]AEE "" EE 88q ++q A 2rqAA!Qw ! '1GAJ 'DAq XXa[FB %%(   C}} " VVAMM "   "** $ VVAMM "   R"$b *AAIIK *DAqAEEz!1RB RxdSAEEzArz+ ( +s :G)G.c&fd}t||S)a2Replace all hyperbolic functions with trig functions using the Osborne rule. Notes ===== ``d`` is a dummy variable to prevent automatic evaluation of trigonometric/hyperbolic functions. References ========== .. [1] https://en.wikipedia.org/wiki/Hyperbolic_function c~t|ts|S|jd}|js|zn/t j |jDcgc]}|z c}}t|t rtt|zSt|tr t|St|trtt|zSt|trt|tz St|tr t!|St|t"rt%|tz St'd|j(zcc}w)Nr unhandled %s)r6rr7rRrrrr rrrrrrr rr!rr"NotImplementedErrorrQ)r/r:rbr^s r0r;z_osborne..fs"01I GGAJxxAaCS^^!&&4IQQqS4I%J b$ SV8O D !q6M D !SV8O D !q6!8O D !q6M D !q6!8O%nrww&>? ?5Js D:rrUr^r;s ` r0_osborner{s"@( Q?r2c&fd}t||S)a1Replace all trig functions with hyperbolic functions using the Osborne rule. Notes ===== ``d`` is a dummy variable to prevent automatic evaluation of trigonometric/hyperbolic functions. References ========== .. [1] https://en.wikipedia.org/wiki/Hyperbolic_function cpt|ts|S|jdjd\}}|j t j i|tzz}t|trt|tz St|tr t|St|trt|tz St|trt|tzSt|t r t#|St|t$rt'|tzSt)d|j*z)NrT)as_Addrx)r6r$r7as_independentxreplacerr8r rrrrrrr rr!rr"rryrQ)r/constr~r:r^s r0r;z_osbornei..fs"34I771:,,Qt,<q JJ155z "U1W , b# 719  C 7N C 719  C 719  C 7N C 719 %nrww&>? ?r2rrzs ` r0 _osborneirs @( Q?r2c4 ddlm ddlm|j t }|Dcgc]}|t fc}|jt}Dcgc] \}}||f c}}t t| fdfScc}wcc}}w)aReturn an expression containing hyperbolic functions in terms of trigonometric functions. Any trigonometric functions initially present are replaced with Dummy symbols and the function to undo the masking and the conversion back to hyperbolics is also returned. It should always be true that:: t, f = hyper_as_trig(expr) expr == f(t) Examples ======== >>> from sympy.simplify.fu import hyper_as_trig, fu >>> from sympy.abc import x >>> from sympy import cosh, sinh >>> eq = sinh(x)**2 + cosh(x)**2 >>> t, f = hyper_as_trig(eq) >>> f(fu(t)) cosh(2*x) References ========== .. [1] https://en.wikipedia.org/wiki/Hyperbolic_function rru)collectc t|jttjSrG)rrdictr ImaginaryUnit)r~rr^repsrvs r0rzhyper_as_trig..&s3'(!Q  d,3./0+@r2) rrvsympy.simplify.radsimpratomsr$rrrr{) r/trigsrpmaskedrTrcrr^rrvs @@@@r0 hyper_as_trigrs41. HH* +E"' (QQL (D [[d $F $ $tq!QF $D A FA !@ @@ ) %s BBct|jtts|Stt t |S)aConvert products and powers of sin and cos to sums. Explanation =========== Applied power reduction TRpower first, then expands products, and converts products to sums with TR8. Examples ======== >>> from sympy.simplify.fu import sincos_to_sum >>> from sympy.abc import x >>> from sympy import cos, sin >>> sincos_to_sum(16*sin(x)**3*cos(2*x)**2) 7*sin(x) - 5*sin(3*x) + 3*sin(5*x) - sin(7*x) )rUrrrr rJ)exprs r0 sincos_to_sumr*s+& 88C  :gdm,--r2)F)rxFrrG)NT)r collectionsrsympy.core.addrsympy.core.cachersympy.core.exprrsympy.core.exprtoolsrrr sympy.core.functionr sympy.core.mulr sympy.core.numbersr r sympy.core.powerrsympy.core.singletonrsympy.core.sortingrsympy.core.symbolrsympy.core.sympifyrsympy.core.traversalr(sympy.functions.combinatorial.factorialsr%sympy.functions.elementary.hyperbolicrrrrrrr(sympy.functions.elementary.trigonometricrrrr r!r"r#r$sympy.ntheory.factor_r%sympy.polys.polytoolsr&sympy.strategies.treer'sympy.strategies.corer(r)sympyr*r1r=r@rsrrrrrrrrrrrrrrrr#r&r2r;r?rErJrMrjrCTR1CTR2CTR3CTR4rRrSrTrrfufuncsrziplocalsgetFUrarrrrr{rrrrr2r0rs#$ AA*$ "&#&*=<<<???/((1 )0?      o7d6r%P$N(@V.r2