你的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^2
sage: kronecker_symbol(3,5)
_2 = -1
sage: %hist # 这只会在交互式Shell中有效,notebook中无法使用。
1: factor(100)
2: kronecker_symbol(3,5)
3: %hist
sage: _oh
_4 = {1: 2^2 * 5^2, 2: -1}
sage: _i1
_5 = 'factor(ZZ(100))\n'
sage: eval(_i1)
_6 = 2^2 * 5^2
sage: %hist
1: factor(100)
2: kronecker_symbol(3,5)
3: %hist
4: _oh
5: _i1
6: eval(_i1)
7: %hist
在本教程和其他Sage文档中,我们省略了输出结果的编号。
你还可以将会话中的输入列表保存到一个宏中。
sage: E = EllipticCurve([1,2,3,4,5])
sage: M = ModularSymbols(37)
sage: %hist
1: E = EllipticCurve([1,2,3,4,5])
2: M = ModularSymbols(37)
3: %hist
sage: %macro em 1-2
Macro`em`created. To execute, type its name (without quotes).
sage: E
Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 over
Rational Field
sage: E = 5
sage: M = None
sage: em
Executing Macro...
sage: E
Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 over
Rational Field
当使用交互命令行时,任何UNIX的终端命令都可以从Sage中执行,但是命令前面要加上感叹号!
。
sage: !ls
auto example.sage glossary.tex t tmp tut.log tut.tex
返回了当前目录的文件列表。
PATH
变量中已经包含了Sage可执行文件的目录信息,所以执行gp
,gap
,singular
,maxima
时, 可以使用在Sage中的包含那个版本。
sage: !gp
Reading 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: !singular
SINGULAR / Development
A Computer Algebra System for Polynomial Computations / version 3-0-1
0<
by: G.-M. Greuel, G. Pfister, H. Schoenemann \ October 2005
FB Mathematik der Universitaet, D-67653 Kaiserslautern \