互动式#
用于设置交互式Symphy会话的帮助器模块。
会话#
用于设置交互式会话的工具。
- sympy.interactive.session.init_ipython_session(shell=None, argv=[], auto_symbols=False, auto_int_to_Integer=False)[源代码]#
构建新的IPython会话。
- sympy.interactive.session.init_session(ipython=None, pretty_print=True, order=None, use_unicode=None, use_latex=None, quiet=False, auto_symbols=False, auto_int_to_Integer=False, str_printer=None, pretty_printer=None, latex_printer=None, argv=[])[源代码]#
初始化嵌入式IPython或Python会话。IPython会话是用--pylab选项启动的,不需要numpy导入,这样matplotlib打印就可以交互了。
- 参数:
pretty_print: boolean
如果为True,则使用pretty_print来stringify;如果为False,则使用sstrrepr来stringify。
顺序:字符串或无
此参数有几个不同的设置:lex(默认),它是字母顺序;grlex,是分级字母顺序;grevlex,它是反向分级的字母顺序;old,它用于兼容性原因和长表达式;None,它将它设置为lex。
use_unicode: boolean or None
如果为True,则使用unicode字符;如果为False,则不使用unicode字符。
use_latex: boolean or None
如果为True,则使用latex渲染(如果为IPython GUI);如果为False,则不要使用latex渲染。
安静:布尔值
如果为True,init_session将不打印有关其状态的消息;如果为False,init_session将打印有关其状态的消息。
auto_symbols: boolean
如果为True,IPython将自动为您创建符号。如果为假,则不会。默认值为False。
auto_int_to_Integer: boolean
如果为True,IPython将自动用Integer包装int字面值,以便像1/2这样的东西给出Rational(1,2)。如果为假,则不会。默认值为False。
ipython:布尔或无
如果为True,则打印将为IPython控制台初始化;如果为False,则将为普通控制台初始化打印;默认值为None,这将自动确定我们是否在IPython实例中。
str_printer: function, optional, default=None
自定义字符串打印机函数。这应该是模仿sympy.printing.sstrrepr公司().
pretty_printer: function, optional, default=None
定制漂亮的打印机。这应该是模仿sympy.印刷。漂亮().
latex_printer: function, optional, default=None
定制 Latex 打印机。这应该是模仿sympy.印刷. Latex ()这应该模仿sympy.印刷. Latex ().
argv:IPython的参数列表
看到了吗sympy.bin.isympy公司用于初始化IPython的选项。
实例
>>> from sympy import init_session, Symbol, sin, sqrt >>> sin(x) NameError: name 'x' is not defined >>> init_session() >>> sin(x) sin(x) >>> sqrt(5) ___ \/ 5 >>> init_session(pretty_print=False) >>> sqrt(5) sqrt(5) >>> y + x + y**2 + x**2 x**2 + x + y**2 + y >>> init_session(order='grlex') >>> y + x + y**2 + x**2 x**2 + y**2 + x + y >>> init_session(order='grevlex') >>> y * x**2 + x * y**2 x**2*y + x*y**2 >>> init_session(order='old') >>> x**2 + y**2 + x + y x + y + x**2 + y**2 >>> theta = Symbol('theta') >>> theta theta >>> init_session(use_unicode=True) >>> theta θ
参见
sympy.interactive.printing.init_printing对于示例和其他参数。
- sympy.interactive.session.int_to_Integer(s)[源代码]#
用整数包装整型文字。
This is based on the decistmt example from https://docs.python.org/3/library/tokenize.html.
只转换整数文本。浮点字面值保持不变。
实例
>>> 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
印刷#
在交互会话中设置打印的工具。
- sympy.interactive.printing.init_printing(pretty_print=True, order=None, use_unicode=None, use_latex=None, wrap_line=None, num_columns=None, no_global=False, ip=None, euler=False, forecolor=None, backcolor='Transparent', fontsize='10pt', latex_mode='plain', print_builtin=True, str_printer=None, pretty_printer=None, latex_printer=None, scale=1.0, **settings)[源代码]#
根据环境初始化打印机。
- 参数:
pretty_print : bool, default=True
If
True, usepretty_print()to stringify or the provided pretty printer; ifFalse, usesstrrepr()to stringify or the provided string printer.秩序 :string或None,default='lex'
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 : bool or None, default=None
If
True, use unicode characters; ifFalse, do not use unicode characters; ifNone, make a guess based on the environment.use_latex : string, bool, or None, default=None
If
True, use default LaTeX rendering in GUI interfaces (png and mathjax); ifFalse, do not use LaTeX rendering; ifNone, make a guess based on the environment; if'png', enable LaTeX rendering with an external LaTeX compiler, falling back to matplotlib if external compilation fails; if'matplotlib', enable LaTeX rendering with matplotlib; if'mathjax', enable LaTeX text generation, for example MathJax rendering in IPython notebook or text rendering in LaTeX documents; if'svg', enable LaTeX rendering with an external latex compiler, no fallbackwrap_line : bool
如果为True,则行将在末尾换行;如果为False,则不会换行,而是作为一行继续。只有当
pretty_print是True。num_columns :int或None,默认值为None
If
int, number of columns before wrapping is set to num_columns; ifNone, number of columns before wrapping is set to terminal width. This is only relevant ifpretty_printisTrue.no_global : bool, default=False
If
True, the settings become system wide; ifFalse, use just for this console/session.ip :交互式控制台
它可以是IPython的实例,也可以是从code.InteractiveConsole.
euler : bool, optional, default=False
Loads the euler package in the LaTeX preamble for handwritten style fonts (https://www.ctan.org/pkg/euler).
前色 :string或None,可选,默认值=None
DVI setting for foreground color.
Nonemeans that either'Black','White', or'Gray'will be selected based on a guess of the IPython terminal color setting. See notes.背景色彩 :string,可选,default='Transparent'
背景色的DVI设置。见注释。
fontsize : string or int, optional, default='10pt'
要传递给前导中的LaTeX documentclass函数的字体大小。请注意,这些选项受documentclass的限制。考虑改用比例。
latex_mode :string,可选,default='plain'
The mode used in the LaTeX printer. Can be one of:
{'inline'|'plain'|'equation'|'equation*'}.print_builtin :布尔值,可选,默认值=真
如果
True然后将打印浮点和整数。如果False打印机将只打印sypy类型。str_printer :函数,可选,默认值=无
A custom string printer function. This should mimic
sstrrepr().pretty_printer :函数,可选,默认值=无
A custom pretty printer. This should mimic
pretty().latex_printer :函数,可选,默认值=无
A custom LaTeX printer. This should mimic
latex().规模 :float,可选,默认值=1.0
Scale the LaTeX output when using the
'png'or'svg'backends. Useful for high dpi screens.设置:
的任何其他设置
latex和pretty命令可用于微调输出。
实例
>>> from sympy.interactive import init_printing >>> from sympy import Symbol, sqrt >>> from sympy.abc import x, y >>> sqrt(5) sqrt(5) >>> init_printing(pretty_print=True) >>> sqrt(5) ___ \/ 5 >>> theta = Symbol('theta') >>> init_printing(use_unicode=True) >>> theta \u03b8 >>> init_printing(use_unicode=False) >>> theta theta >>> init_printing(order='lex') >>> str(y + x + y**2 + x**2) x**2 + x + y**2 + y >>> init_printing(order='grlex') >>> str(y + x + y**2 + x**2) x**2 + x + y**2 + y >>> init_printing(order='grevlex') >>> str(y * x**2 + x * y**2) x**2*y + x*y**2 >>> init_printing(order='old') >>> str(x**2 + y**2 + x + y) x**2 + x + y**2 + y >>> init_printing(num_columns=10) >>> x**2 + x + y**2 + y x + y + x**2 + y**2
笔记
The foreground and background colors can be selected when using
'png'or'svg'LaTeX rendering. Note that before theinit_printingcommand is executed, the LaTeX rendering is handled by the IPython console and not SymPy.The colors can be selected among the 68 standard colors known to
dvips, for a list see [R596]. In addition, the background color can be set to'Transparent'(which is the default value).When using the
'Auto'foreground color, the guess is based on thecolorsvariable in the IPython console, see [R597]. Hence, if that variable is set correctly in your IPython console, there is a high chance that the output will be readable, although manual settings may be needed.工具书类