你的Sage会话
会话(session)是你从启动Sage到退出的输入、输出序列。Sage通过IPython记录所有的Sage输入。事实上,如果你用的是交互命令行(而不是notebook界面),那么任何时候你都可以通过%history或%hist来得到所有输入行的列表。 你可以输入?查看更多关于IPython的信息。IPython提供带编号的提示符…并带有输入和输出缓存,所有输入都被保存并可以作为变量检索(除了方向键)。下面是一些全局变量,注意不要修改它们”:
_: previous input (interactive shell and notebook)__: next previous input (interactive shell only)_oh : list of all inputs (interactive shell only)
这是一个例子:
sage: factor(100)_1 = 2^2 * 5^2sage: kronecker_symbol(3,5)_2 = -1sage: %hist # 这只会在交互式Shell中有效,notebook中无法使用。1: factor(100)2: kronecker_symbol(3,5)3: %histsage: _oh_4 = {1: 2^2 * 5^2, 2: -1}sage: _i1_5 = 'factor(ZZ(100))\n'sage: eval(_i1)_6 = 2^2 * 5^2sage: %hist1: factor(100)2: kronecker_symbol(3,5)3: %hist4: _oh5: _i16: eval(_i1)7: %hist
在本教程和其他Sage文档中,我们省略了输出结果的编号。
你还可以将会话中的输入列表保存到一个宏中。
sage: E = EllipticCurve([1,2,3,4,5])sage: M = ModularSymbols(37)sage: %hist1: E = EllipticCurve([1,2,3,4,5])2: M = ModularSymbols(37)3: %histsage: %macro em 1-2Macro`em`created. To execute, type its name (without quotes).
sage: EElliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 overRational Fieldsage: E = 5sage: M = Nonesage: emExecuting Macro...sage: EElliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 overRational Field
当使用交互命令行时,任何UNIX的终端命令都可以从Sage中执行,但是命令前面要加上感叹号!。
sage: !lsauto example.sage glossary.tex t tmp tut.log tut.tex
返回了当前目录的文件列表。
PATH变量中已经包含了Sage可执行文件的目录信息,所以执行gp,gap,singular,maxima时, 可以使用在Sage中的包含那个版本。
sage: !gpReading GPRC: /etc/gprc ...Done.GP/PARI CALCULATOR Version 2.2.11 (alpha)i686 running linux (ix86/GMP-4.1.4 kernel) 32-bit version...sage: !singularSINGULAR / DevelopmentA Computer Algebra System for Polynomial Computations / version 3-0-10<by: G.-M. Greuel, G. Pfister, H. Schoenemann \ October 2005FB Mathematik der Universitaet, D-67653 Kaiserslautern \
