你的Sage会话

会话(session)是你从启动Sage到退出的输入、输出序列。Sage通过IPython记录所有的Sage输入。事实上,如果你用的是交互命令行(而不是notebook界面),那么任何时候你都可以通过%history%hist来得到所有输入行的列表。 你可以输入?查看更多关于IPython的信息。IPython提供带编号的提示符…并带有输入和输出缓存,所有输入都被保存并可以作为变量检索(除了方向键)。下面是一些全局变量,注意不要修改它们”:

  1. _: previous input (interactive shell and notebook)
  2. __: next previous input (interactive shell only)
  3. _oh : list of all inputs (interactive shell only)

这是一个例子:

  1. sage: factor(100)
  2. _1 = 2^2 * 5^2
  3. sage: kronecker_symbol(3,5)
  4. _2 = -1
  5. sage: %hist # 这只会在交互式Shell中有效,notebook中无法使用。
  6. 1: factor(100)
  7. 2: kronecker_symbol(3,5)
  8. 3: %hist
  9. sage: _oh
  10. _4 = {1: 2^2 * 5^2, 2: -1}
  11. sage: _i1
  12. _5 = 'factor(ZZ(100))\n'
  13. sage: eval(_i1)
  14. _6 = 2^2 * 5^2
  15. sage: %hist
  16. 1: factor(100)
  17. 2: kronecker_symbol(3,5)
  18. 3: %hist
  19. 4: _oh
  20. 5: _i1
  21. 6: eval(_i1)
  22. 7: %hist

在本教程和其他Sage文档中,我们省略了输出结果的编号。

你还可以将会话中的输入列表保存到一个宏中。

  1. sage: E = EllipticCurve([1,2,3,4,5])
  2. sage: M = ModularSymbols(37)
  3. sage: %hist
  4. 1: E = EllipticCurve([1,2,3,4,5])
  5. 2: M = ModularSymbols(37)
  6. 3: %hist
  7. sage: %macro em 1-2
  8. Macro`em`created. To execute, type its name (without quotes).
  1. sage: E
  2. Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 over
  3. Rational Field
  4. sage: E = 5
  5. sage: M = None
  6. sage: em
  7. Executing Macro...
  8. sage: E
  9. Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 over
  10. Rational Field

当使用交互命令行时,任何UNIX的终端命令都可以从Sage中执行,但是命令前面要加上感叹号!

  1. sage: !ls
  2. auto example.sage glossary.tex t tmp tut.log tut.tex

返回了当前目录的文件列表。

PATH变量中已经包含了Sage可执行文件的目录信息,所以执行gp,gap,singular,maxima时, 可以使用在Sage中的包含那个版本。

  1. sage: !gp
  2. Reading GPRC: /etc/gprc ...Done.
  3. GP/PARI CALCULATOR Version 2.2.11 (alpha)
  4. i686 running linux (ix86/GMP-4.1.4 kernel) 32-bit version
  5. ...
  6. sage: !singular
  7. SINGULAR / Development
  8. A Computer Algebra System for Polynomial Computations / version 3-0-1
  9. 0<
  10. by: G.-M. Greuel, G. Pfister, H. Schoenemann \ October 2005
  11. FB Mathematik der Universitaet, D-67653 Kaiserslautern \