K i; dZddlmZddlmZddlmZddlmZdZ dZ dZ dd Z d Z dZdZd gd d fdZdZd d d d d d d d d d d gf dZy )z+Tools for setting up interactive sessions. ) GROUND_TYPES) version_tuple) init_printing)ARCHzfrom sympy import * x, y, z, t = symbols('x y z t') k, m, n = symbols('k m n', integer=True) f, g, h = symbols('f g h', cls=Function) init_printing() zjThese commands were executed: %(source)s Documentation can be found at https://docs.sympy.org/%(version)s zCould not locate IPython. Having IPython installed is greatly recommended. See http://ipython.scipy.org for more details. If you use Debian/Ubuntu, just install the 'ipython' package and start isympy again. TFNcddlm}ddlm}ddl}ddl}|ryd|j ddz}|rd}nd }d t zg} |jd } | $| jd k(r| jd |r| jd|||tdj| f} d| z} |t}d} |jdddD]}|s| dz } | d|zdzz } |}d|vrd}nd|z}| dt| |dzzz } | S)z,Create a banner for an interactive session. r) __version__) SYMPY_DEBUGNz%d.%d.%dIPythonPythonzground types: %sSYMPY_USE_CACHEnoz cache: offz debugging: onz, z,%s console for SymPy %s (Python %s-%s) (%s)  z>>> devz%s/)sourceversion)sympyrr sysos version_inforgetenvlowerappendrjoinpreexec_sourcesplitverbose_message)ipythonquietr sympy_versionr rrpython_version shell_nameinfocacheargsmessage_sourceline doc_versions _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/interactive/session.py _make_messager-s<2!  #"2"22A"66N   - .D II' (E U[[]d2 L! O$ }ndDIIdO KD=DG ~G T"3B', tOG v}t+ +G ,  K  k)  to74?)AAAAG Nc ddlm}m}m}m}m}ddlm}d}g}|||j} | D]F\} } } } } | |k(r&|| r|j|df|df|| f|dfg4|j| | fH||S)aw Wrap integer literals with Integer. This is based on the decistmt example from https://docs.python.org/3/library/tokenize.html. Only integer literals are converted. Float literals are left alone. Examples ======== >>> from sympy import Integer # noqa: F401 >>> from sympy.interactive.session import int_to_Integer >>> s = '1.2 + 1/2 - 0x12 + a1' >>> int_to_Integer(s) '1.2 +Integer (1 )/Integer (2 )-Integer (0x12 )+a1 ' >>> s = 'print (1/2)' >>> int_to_Integer(s) 'print (Integer (1 )/Integer (2 ))' >>> exec(s) 0.5 >>> exec(int_to_Integer(s)) 1/2 r)generate_tokens untokenizeNUMBERNAMEOP)StringIOcVd|vs$d|jvsd|jvryy)z] Returns true if string value num (with token NUMBER) represents an integer. .jeFT)r)nums r,_is_intzint_to_Integer.._is_intqs+ #: +sciik/Ar.Integer()) tokenizer0r1r2r3r4ior5readlineextendr) sr0r1r2r3r4r5r;resultgtoknumtokval_s r,int_to_IntegerrIUs2GFF ,,-A#$ ,1a V  MMy!S  S   MM66* + , f r.cBddl|jfd}||_y)zM Allow IPython to automatically convert integer literals to Integer. rNct j|t|}|g|i|S#t$rYwxYwN)parserI SyntaxError)cellr'kwargsast old_run_cells r, my_run_cellz7enable_automatic_int_sympification..my_run_cellsJ ( IIdO"$'DD242622    s + 77)rQrun_cell)shellrSrQrRs @@r,"enable_automatic_int_sympificationrVs>>L 3!ENr.cjddl}|jddfd }|jtf|y)z?Allow IPython to automatically create symbols (``isympy -a``). rNz8name '(?P[A-Za-z_][A-Za-z0-9_]*)' is not definedc|tur|jr|jjsjt|}|t|j dd|j dizd |j dd}|j |d |j d|j dzdy|jj|||| }|j|||y#ttf$rYnwxYw |j d|j dzdo#|j d|j dzdwxYw) zJHandle :exc:`NameError` exception and allow injection of missing symbols. Nz!%(symbol)s = Symbol('%(symbol)s')symbolF) store_historyInrzdel %s) tb_offset) NameErrortb_nextmatchstrrTgroupuser_nsKeyError IndexError InteractiveTBstructured_traceback_showtraceback) selfetypevaluetbr\r_codestb re_nameerrors r,_handlerz*enable_automatic_symbols.._handlersV I "**RZZ5G5G &&s5z2E  A'X)>?@OTV 7<<-b1DMM$eM<MM(U[[-B"B05"7  55 5" 63 E5#.!*- MM(U[[-B"B05"7DMM(U[[-B"B05"7s*0C/D+/D>D+DD++'ErL)recompileset_custom_excr])rUrprorns @r,enable_automatic_symbolsrss4N::BDL/2 )x0r.chddl}t|jtdk\r|sbt|jtdk\rddlm}nddlm}|j }d|_|j||j}|r t||r t||Sddl m }||S)zConstruct new IPython session. rN0.11z1.0)ipappF) make_IPython)r rrIPython.terminalrvIPython.frontend.terminalTerminalIPythonAppdisplay_banner initializerUrsrV IPython.Shellrw)rUargv auto_symbolsauto_int_to_Integerr rvapprws r,init_ipython_sessionrsW(()]6-BB W001]55II2;**,C"'C  NN4 IIE  $U +  .u 5 .D!!r.c8ddlmGfdd}|S)zConstruct new Python session. rInteractiveConsoleceZdZdZfdZy))init_python_session..SymPyConsolez.An interactive console with readline support. ci}j|| ddl}ddl}ddl}ddl}|j |j |j|jdt|drJ|jjd} |j||j|j|yy#t$rY)wxYw#t $rYywxYw)N)localsrz tab: completeread_history_filez~/.sympy-history)__init__ rlcompleterrAratexit set_completer Completercompleteparse_and_bindhasattrpath expanduserrOSErrorregisterwrite_history_file ImportError)rh ns_localsrrArrhistoryrs r,rz2init_python_session..SymPyConsole.__init__sI  ' 'Y ' ? J"&&{'<'r.c ddl} d} |dur" ddl} ddlm}|t } || }|durt j}n\t| ||tjtdk\rdfd _ jd | s j}|r.|r!tjtdkr t d |r.|r!tjtdkr t d t}j|d t!|||||| | t#|||}| s$t%|| j'dyt%|ddl}|j+dy#t$rdYuwxYw#t$r|dur t ddYwxYw#t$rY.wxYw)u Initialize an embedded IPython or Python session. The IPython session is initiated with the --pylab option, without the numpy imports, so that matplotlib plotting can be interactive. Parameters ========== pretty_print: boolean If True, use pretty_print to stringify; if False, use sstrrepr to stringify. order: string or None There are a few different settings for this parameter: lex (default), which is lexographic order; grlex, which is graded lexographic order; grevlex, which is reversed graded lexographic order; old, which is used for compatibility reasons and for long expressions; None, which sets it to lex. use_unicode: boolean or None If True, use unicode characters; if False, do not use unicode characters. use_latex: boolean or None If True, use latex rendering if IPython GUI's; if False, do not use latex rendering. quiet: boolean If True, init_session will not print messages regarding its status; if False, init_session will print messages regarding its status. auto_symbols: boolean If True, IPython will automatically create symbols for you. If False, it will not. The default is False. auto_int_to_Integer: boolean If True, IPython will automatically wrap int literals with Integer, so that things like 1/2 give Rational(1, 2). If False, it will not. The default is False. ipython: boolean or None If True, printing will initialize for an IPython console; if False, printing will initialize for a normal console; The default is None, which automatically determines whether we are in an ipython instance or not. str_printer: function, optional, default=None A custom string printer function. This should mimic sympy.printing.sstrrepr(). pretty_printer: function, optional, default=None A custom pretty printer. This should mimic sympy.printing.pretty(). latex_printer: function, optional, default=None A custom LaTeX printer. This should mimic sympy.printing.latex() This should mimic sympy.printing.latex(). argv: list of arguments for IPython See sympy.bin.isympy for options that can be used to initialize IPython. See Also ======== sympy.interactive.printing.init_printing: for examples and the rest of the parameters. Examples ======== >>> from sympy import init_session, Symbol, sin, sqrt >>> sin(x) #doctest: +SKIP NameError: name 'x' is not defined >>> init_session() #doctest: +SKIP >>> sin(x) #doctest: +SKIP sin(x) >>> sqrt(5) #doctest: +SKIP ___ \/ 5 >>> init_session(pretty_print=False) #doctest: +SKIP >>> sqrt(5) #doctest: +SKIP sqrt(5) >>> y + x + y**2 + x**2 #doctest: +SKIP x**2 + x + y**2 + y >>> init_session(order='grlex') #doctest: +SKIP >>> y + x + y**2 + x**2 #doctest: +SKIP x**2 + y**2 + x + y >>> init_session(order='grevlex') #doctest: +SKIP >>> y * x**2 + x * y**2 #doctest: +SKIP x**2*y + x*y**2 >>> init_session(order='old') #doctest: +SKIP >>> x**2 + y**2 + x + y #doctest: +SKIP x + y + x**2 + y**2 >>> theta = Symbol('theta') #doctest: +SKIP >>> theta #doctest: +SKIP theta >>> init_session(use_unicode=True) #doctest: +SKIP >>> theta # doctest: +SKIP θ rNF) get_ipythonTz'IPython is not available on this system)r~rrruexecc(j|dS)NF)rT)srcrYips r,zinit_session..sbkk#u6Mr.) import_allzKautomatic construction of symbols is possible only in IPython 0.11 or abovezQautomatic int to Integer transformation is possible only in IPython 0.11 or above)rY) pretty_printorder use_unicode use_latexr str_printerpretty_printer latex_printerz Exiting ...ctdS)Nz Exiting ... )printr.r,rzinit_session..s o 6r.)r)rr rr RuntimeErrorboolrinteractrrr runsource enable_pylab Exceptionmainlooprrr-rexitrr)r rrrrr!rrrrrr~r in_ipythonr rr_preexec_sourcer(rrs @r, init_sessionr,s~Je    / ]"X ? G% ";; !"4l6IK ,, -v1F FNBL 51{{HW g6I6I(J][aMb(bhiiG}W=P=P/QTabhTi/inoo$OLLL0|5)Y2). -/ GUOrs}1,44%  3l1h!0D1N $"5V["B FD!TU%*T#"c8r.