K iJndZddlZddlmZmZmZmZmZmZm Z ddl m Z dZ GddZ Gdd e Zy) aPrettyprinter by Jurjen Bos. (I hate spammers: mail me at pietjepuk314 at the reverse of ku.oc.oohay). All objects have a method that create a "stringPict", that can be used in the str method for pretty printing. Updates by Jason Gedge (email at cs mun ca) - terminal_string() method - minor fixes and changes (mostly to prettyForm) TODO: - Allow left/center/right alignment options for above/below and top/center/bottom alignment options for left/right N)hobjvobjxsymxobjpretty_use_unicode line_widthcenter)sympy_deprecation_warningceZdZdZdZddZedZdZdZ edZ dZ d Z ed Z d Zd Zdd ZdZddZdZdZdZfdZdZdZdZdZxZS) stringPictzZAn ASCII picture. The pictures are represented as a list of equal length strings. linec~||_tj|j|_||_d|_y)zHInitialize from string. Multiline strings are centered. N)sr equalLengths splitlinespicturebaselinebinding)selfrrs f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/printing/pretty/stringpict.py__init__zstringPict.__init__s1!..q||~>    cn|sdgStd|D}|Dcgc]}t||c}Scc}w)Nc32K|]}t|ywN)r ).0rs r z*stringPict.equalLengths...s7Jt$7s)maxr )lineswidthrs rrzstringPict.equalLengths(s94K777056tU#666s2c,t|jS)z(The height of the picture in characters.)lenrrs rheightzstringPict.height1s4<<  rc2t|jdS)z'The width of the picture in characters.r)r rr%s rr"zstringPict.width5s$,,q/**rcg}|D].}t|tr t|}|j|0t d|D}t d|D}||z}g}|D]b}d|j zg}||j z } ||jz } |j|| z|jz|| | z zzdt|D cgc]} dj| } } dj| |fScc} w)zsPut a string of stringPicts next to each other. Returns string, baseline arguments for stringPict. c34K|]}|jywrrrobjs rrz"stringPict.next..Fs:3#,,:sc3VK|]!}|j|jz #ywr)r&rr+s rrz"stringPict.next..Gs'%  JJL3<< '% s') r ) isinstancestrr appendr r"rr&rzipjoin) argsobjectsarg newBaselinenewHeightBelowBaseline newHeightpicturesr, oneEmptyLine basePadding totalPaddingr!results rnextzstringPict.next9s  C#s# o NN3  :':: !$% % "  "88  =C O,L% 4K$szz|3L OO{*  { :;< =  =/28n=U"''%.==yy +-->sC?c.tj|g|S)aPut pictures next to this one. Returns string, baseline arguments for stringPict. (Multiline) strings are allowed, and are given a baseline of 0. Examples ======== >>> from sympy.printing.pretty.stringpict import stringPict >>> print(stringPict("10").right(" + ",stringPict("1\r-\r2",1))[0]) 1 10 + - 2 r r@rr5s rrightzstringPict.rightYst+d++rc.tj||fzS)ziPut pictures (left to right) at left. Returns string, baseline arguments for stringPict. rBrCs rleftzstringPict.leftjs11rc g}|D]@}|tjurt|tr t|}|j |Bt d|D}tt d|}t|D]\}}|tjus|||<|Dcgc]}|jD]}t||!}}}|dj|djz} dj|| fScc}}w)aPut pictures on top of each other, from top to bottom. Returns string, baseline arguments for stringPict. The baseline is the baseline of the second picture. Everything is centered. Baseline is the baseline of the second picture. Strings are allowed. The special value stringPict.LINE is a row of '-' extended to the width. c3`K|]&}|tjur|j(ywr)r LINEr"r+s rrz#stringPict.stack..s*+*//) IIK+s,.-rrr/) r rIr0r1r2r r enumeraterr r&rr4) r5r6r7newWidthlineObjir,r newPicturer8s rstackzstringPict.stackps C*//)jc.B o NN3  +++ T#x01 ( %FAsjoo%$  % 9@XCKKXDfT8,X,X Xaj'')GAJ,?,?? yy$k11Ys$C<cPtj|g|\}}||jfS)aPut pictures under this picture. Returns string, baseline arguments for stringPict. Baseline is baseline of top picture Examples ======== >>> from sympy.printing.pretty.stringpict import stringPict >>> print(stringPict("x+3").below( ... stringPict.LINE, '3')[0]) #doctest: +NORMALIZE_WHITESPACE x+3 --- 3 )r rPr)rr5rrs rbelowzstringPict.belows, !&&t3d3 8$--rctj||fz\}}t|j|j z |j z}||fS)zPut pictures above this picture. Returns string, baseline arguments for stringPict. Baseline is baseline of bottom picture. )r rPr$rr&r)rr5stringrs rabovezstringPict.abovesQ &++ddWn>v((*+dkkm;dmmKxrcl|j}|j}|rtsd}d}|}|r.tt |||}t|j |}|r.tt |||}t|j |}dj |j|jfS)zPut parentheses around self. Returns string, baseline arguments for stringPict. left or right can be None or empty string which means 'no paren from that side' rrr*r/)r&rrr rrDr4r) rrFrDifascii_nouglyhbreslparenrparens rparenszstringPict.parenss KKM MM "4"6AA T1 :Ffll401C UA;Fcii/0C #++& 55rct|j|jdz |jz dzdzdjfdt D}|j t |dzS)z6Precede object by a slash of the proper size. rr/c3ZK|]"}d|z dz ztddzd|zz$ywr.r/N)rrrNr&s rrz'stringPict.leftslash..s:  !a 4Q< /#a% 7 s(+)r rr&r4rangerFr )rslashr&s @r leftslashzstringPict.leftslashsz MM KKMA  -//01345  6]  yyE619566rc~|jd|jz}|jdjfdt D}t |dz }dkDr t dd}n t d}|e|j|jkDrD|j d|j|jz z}|j|}|j|}|j|jz |jz|_|j |S) zUProduce a nice root symbol. Produces ugly results for big n inserts. _r/c3FK|]}d|z dz zdzd|zzywrarcs rrz"stringPict.root..s4  6A:> "S (37 2 s!rr_z\ \\r.) rUr"r&r4rdr rFrDr)rnr?redownlinerootr&s @rrnzstringPict.rootsC ,-  6]  5&1*- A:!*a0H!$'H =QWWY)99}}S!'')hnn6F*F%GHH~~a(H~~e$ &--/9DKKMI {{4  rc t t|d<|ddurdj|jS|d|dn|jdkrd|j krt |jd|S d|ds t rd d nd d  fd }tt||j}|Dcgc]}dj|}}dj|Scc}w)zReturn the string form of self. Unless the argument line_break is set to False, it will break the expression in a form that can be printed on the terminal without being broken up. wrap_lineFr/ num_columnsrPr use_unicodeu↪ u ↪z> z >c3K }t|zd}}t|D]<\}}t|}||zkDr||||zz }t|z|}}||z }>|||dzyw)z-Yields consecutive chunks of line_width ncolsrN)r rK) rprefixr"startrNxwxncols overflow_endoverflow_firstoverflow_starts rchunksz!stringPict.render..chunks-s#F%f|&;N>L!N!L ( FDLL127??7DIIg&??{{8$$@s C7cFtjd}|jS)zCReturn the terminal width if possible, otherwise return 0. )rr)fallback)shutilget_terminal_sizecolumns)rsizes rrzstringPict.terminal_widthEs''8||rct|trdj|j|k(St|tr|j|jk(Sy)Nr/F)r0r1r4rr )ros r__eq__zstringPict.__eq__KsD a 99T\\*a/ / : &99 , ,rc t|Sr)super__hash__)r __class__s rrzstringPict.__hash__Rsw!!rc8dj|jS)Nr/)r4rr%s r__str__zstringPict.__str__Usyy&&rcVddj|j|jfzS)NzstringPict(%r,%d)r/)r4rrr%s r__repr__zstringPict.__repr__Xs#"dii &=t}}%MMMrc |j|Sr)r)rindexs r __getitem__zstringPict.__getitem__[s||E""rc,t|jSr)r$rr%s r__len__zstringPict.__len__^s466{r)r)()Fr)__name__ __module__ __qualname____doc__rIr staticmethodrr&r"r@rDrFrPrRrUr]rfrnrrrrrrrr __classcell__)rs@rr r s D 77!+..>,"2 !2!2F & 64 7 !DJ%X "'N#rr ceZdZdZed\ZZZZZ Z Z Z d dZ edZdZddZdZd Zd Zgd Zed Zy) prettyForma Extension of the stringPict class that knows about basic math applications, optimizing double minus signs. "Binding" is interpreted as follows:: ATOM this is an atom: never needs to be parenthesized FUNC this is a function application: parenthesize if added (?) DIV this is a division: make wider division if divided POW this is a power: only parenthesize if exponent MUL this is a multiplication: parenthesize if powered ADD this is an addition: parenthesize if multiplied or powered NEG this is a negative number: optimize if added, parenthesize if multiplied or powered OPEN this is an open object: parenthesize if added, multiplied, or powered (example: Piecewise) Ncvtj|||||_|tddd|xs||_y)z-Initialize from stringPict and binding power.Nz The unicode argument to prettyForm is deprecated. Only the s argument (the first positional argument) should be passed. 1.7$deprecated-pretty-printing-functionsdeprecated_since_versionactive_deprecations_target)r rrr _unicode)rrrrunicodes rrzprettyForm.__init__vsDD!X.   %*/+Q  S 1 rc6tddd|jS)Nz} The prettyForm.unicode attribute is deprecated. Use the prettyForm.s attribute instead. rrr)r rr%s rrzprettyForm.unicodes$! &+'M  O}}rc|}|jtjkDrt|j }|g}|D]t}|jtjkDrt|j }|jtjk7r|j d|j |vttj |dtjiS)zTMake a pretty addition. Addition of negative numbers is simplified. z + r)rrNEGr r]r2r@ADD)rothersr7r?s r__add__zprettyForm.__add__s ;; 'cjjl+C C{{Z^^+ #**,/{{jnn, e$ MM#  :??F3KL*..LLrc|r td|}|jtjk(rt |j }|jtjk(rt |j }|jtj k(r|jdd}ttj|tj|dtjiS)z4Make a pretty division; stacked or slashed. zCan't do slashed fraction yetr.rr) NotImplementedErrorrrDIVr r]rrDrPrI)rdenslashednums r __truediv__zprettyForm.__truediv__s %&EF F ;;*.. (cjjl+C ;;*.. (cjjl+C ;;  &))C.#C:3C3C  OO 4*.. rcddi}t|dk(r|S|}|jtjkDr3|jtjk7rt |j }|g}|D]}|jd|jvr|jtd|jtjkDr3|jtjk7rt |j }|j|t|}t|D]]}||dz ks ||dk(s||dztdk(s*|j||j||j|d_|dddk(rBtj}|ddk(r:|d}|j|jddk(rd|d<ntj}tt j|d |iS) zZMake a pretty multiplication. Parentheses are needed around +, - and neg. degree°r*rz-1rJz- r)r$rrMULrr r]rvaluesr2rrdpopinsertrr@) rrquantityr7r?len_resrNbinrDs r__mul__zprettyForm.__mul__s '  v;! K ;; 'CKK:>>,Icjjl+C C{{1~X__%66 d3i({{Z^^+ z~~0M #**,/ MM#   f+w &A7Q;6!9#4A$s)9S 1  1  a%  & !9Q<3 ..CayCq ==03s: $F1I..C (@A#AArclddj|j|j|jfzS)NzprettyForm(%r,%d,%d)r/)r4rrrr%s rrzprettyForm.__repr__s2% IIdll # MM LL) rc:|}d}|jtjk(rt|j }|jtj kDrt|j }nI|jtj k(r,|j dkDrt|j }nd}|rn|jj|j z|_t|jj|}t|j|jSt|jd|jz}t|jd|jz}t|j|dtjiS)zMake a pretty power. FrTr.r)rrPOWr r]FUNCr& prettyFuncrrD prettyArgsrFr"rU)rrYause_inline_func_formfunctopbots r__pow__zprettyForm.__pow__s, $ 99  &AHHJ'A 99z &AHHJ'A YY*// )xxzA~ +'+$ ..;AJq||11!45Dtzz!,,78 8affS]34Caggc!'')m45C399S>B*..BBr)sincostanc0|tjvrst|dk(s Jd|z|dj}|jtj kr+t|j |dzdtjiSg}|D]2}|jd|j|j4ttj|dd}t|j}t|j |dtjiS)z,Functions of one or more variables. rz'Simple function %s must have 1 argumentrr.r,N) rsimpleFunctionsr$ __pretty__rrrFrr2r r@r]ATOM)functionr5r7 argumentLists rapplyzprettyForm.applys z11 1 QEP Qq'$$&C{{jnn,!CHHXPS^rs> \\\@IIX wQwQr