接口问题¶
后台工作¶
是的,Sage作业可以在UNIX系统的后台运行。典型的做法是输入
$ nohup sage < command_file > output_file &
nohup的优点是Sage将在您注销后继续运行。
当前Sage将在(unix)的输出中显示为“Sage ipython”或“python” top
命令,但在Sage的未来版本中,它将显示为 sage
.
参考Sage¶
参考Sage,请在参考书目中添加以下内容:
\bibitem[Sage]{sage}
Stein, William, \emph{Sage: {O}pen {S}ource {M}athematical {S}oftware
({V}ersion 2.10.2)}, The Sage~Group, 2008, {\tt http://www.sagemath.org}.
这是bibtex条目:
@manual{sage,
Key = {Sage},
Author = {William Stein},
Organization = {The Sage~Group},
Title = {{Sage}: {O}pen {S}ource {M}athematical {S}oftware ({V}ersion 2.10.2)},
Note= {{\tt http://www.sagemath.org}},
Year = 2008
}
如果您碰巧使用Sage接口来表示PARI、GAP或Singular,那么您一定也应该引用它们。同样,如果您使用的代码是使用PARI、GAP或Singular实现的,请参考相应的系统(通常可以从文档中判断函数的实现中是否使用PARI、GAP或Singular)。
对于PARI,您可以使用
@manual{PARI2,
organization = "{The PARI~Group}",
title = "{PARI/GP, version {\tt 2.1.5}}",
year = 2004,
address = "Bordeaux",
note = "available from \url{http://pari.math.u-bordeaux.fr/}"
}
或
\bibitem{PARI2} PARI/GP, version {\tt 2.1.5}, Bordeaux, 2004,
\url{http://pari.math.u-bordeaux.fr/}.
(将版本号替换为您使用的版本号)。
对于GAP,您可以使用
[GAP04] The GAP Group, GAP -- Groups, Algorithms, and Programming,
Version 4.4; 2005. (http://www.gap-system.org)
或
@manual{GAP4,
key = "GAP",
organization = "The GAP~Group",
title = "{GAP -- Groups, Algorithms, and Programming,
Version 4.4}",
year = 2005,
note = "{\tt http://www.gap-system.org}",
keywords = "groups; *; gap; manual"}
或
\bibitem[GAP]{GAP4}
The GAP~Group, \emph{GAP -- Groups, Algorithms, and Programming, Version 4.4}; 2005,
{\tt http://www.gap-system.org}.
对于单数,可以使用
[GPS05] G.-M. Greuel, G. Pfister, and H. Sch\"onemann.
{\sc Singular} 3.0. A Computer Algebra System for Polynomial
Computations. Centre for Computer Algebra, University of
Kaiserslautern (2005). {\tt http://www.singular.uni-kl.de}.
或
@TechReport{GPS05,
author = {G.-M. Greuel and G. Pfister and H. Sch\"onemann},
title = {{\sc Singular} 3.0},
type = {{A Computer Algebra System for Polynomial Computations}},
institution = {Centre for Computer Algebra},
address = {University of Kaiserslautern},
year = {2005},
note = {{\tt http://www.singular.uni-kl.de}},
}
或
\bibitem[GPS05]{GPS05}
G.-M.~Greuel, G.~Pfister, and H.~Sch\"onemann.
\newblock {{\sc Singular} 3.0}. A Computer Algebra System for Polynomial Computations.
\newblock Centre for Computer Algebra, University of Kaiserslautern (2005).
\newblock {\tt http://www.singular.uni-kl.de}.
记录您的Sage会话¶
是的,你可以记录你的会话。
(a) 修改.ipythonrc文件的第186行(或在编辑器中打开.ipythonrc并搜索“logfile”)。这将只记录您的输入行,而不是输出。
(b) 也可以通过在后台运行Sage将输出写入文件( 后台工作 )
(c) 从KDE konsole开始(这只适用于linux)。去 Settings
\(\rightarrow\) History ...
然后选择“无限制”。开始你的训练。准备好后,转到 edit
\(\rightarrow\) save history as ...
.
有些接口(例如Singular接口或GAP接口)允许您创建日志文件。对于单数,有一个logfile选项(in singular.py
). 在GAP中,使用命令 LogTo
.
Latex 转化¶
是的,你可以输出一些结果到 Latex 。
sage: M = MatrixSpace(RealField(),3,3)
sage: A = M([1,2,3, 4,5,6, 7,8,9])
sage: print(latex(A))
\left(\begin{array}{rrr}
1.00000000000000 & 2.00000000000000 & 3.00000000000000 \\
4.00000000000000 & 5.00000000000000 & 6.00000000000000 \\
7.00000000000000 & 8.00000000000000 & 9.00000000000000
\end{array}\right)
sage: view(A)
此时,应自动调用dvi预览,在单独的窗口中显示生成的LaTeX输出。
还提供多元多项式和有理函数的LaTeX预览:
sage: x = PolynomialRing(QQ,3, 'x').gens()
sage: f = x[0] + x[1] - 2*x[1]*x[2]
sage: h = f /(x[1] + x[2])
sage: print(latex(h))
\frac{-2 x_{1} x_{2} + x_{0} + x_{1}}{x_{1} + x_{2}}
Sage和其他计算机代数系统¶
如果 foo
是一个Pari,GAP(没有结束分号),单数,Maxima命令,resp.,enter gp("foo")
对于Pari, gap.eval("foo")}}
singular.eval("foo")
, maxima("foo")
,分别为。。这些程序只需将命令字符串发送给外部程序,执行它,并将结果读回Sage。因此,如果外部程序未安装并且在您的路径中,这些程序将不起作用。
命令行Sage帮助¶
如果您只知道Sage命令的一部分名称,并且想知道它在Sage中的位置,那么0.10.11中添加了一个新选项,以便于查找。只是打字 sage -grep <string>
查找 <string>
在Sage源代码中。例如,
$ sage -grep berlekamp_massey
matrix/all.py:from berlekamp_massey import berlekamp_massey
matrix/berlekamp_massey.py:def berlekamp_massey(a):
matrix/matrix.py:import berlekamp_massey
matrix/matrix.py: g =
berlekamp_massey.berlekamp_massey(cols[i].list())
类型 help(foo)
或 foo??
寻求帮助和 foo.[tab]
用于搜索Sage命令。类型 help()
对于Python命令。
例如
help(Matrix)
收益率
Help on function Matrix in module sage.matrix.constructor:
Matrix(R, nrows, ncols, entries = 0, sparse = False)
Create a matrix.
INPUT:
R -- ring
nrows -- int; number of rows
ncols -- int; number of columns
entries -- list; entries of the matrix
sparse -- bool (default: False); whether or not to store matrices as sparse
OUTPUT:
a matrix
EXAMPLES:
sage: Matrix(RationalField(), 2, 2, [1,2,3,4])
[1 2]
[3 4]
sage: Matrix(FiniteField(5), 2, 3, range(6))
[0 1 2]
[3 4 0]
sage: Matrix(IntegerRing(), 10, 10, range(100)).parent()
Full MatrixSpace of 10 by 10 dense matrices over Integer Ring
sage: Matrix(IntegerRing(), 10, 10, range(100), sparse = True).parent()
Full MatrixSpace of 10 by 10 sparse matrices over Integer Ring
在新屏幕上。键入q返回Sage屏幕。
读取文件并将其导入Sage¶
导入Sage的文件必须以 .py
,例如, foo.py
并包含合法的Python语法。有关简单示例,请参见 置换群 以上面的魔方组为例。
另一种读取文件的方法是使用 load
或 attach
命令。创建一个名为 example.sage
(位于Sage的主目录中)包含以下内容:
print("Hello World")
print(2^3)
读入并执行 example.sage
使用文件 load
命令。
sage: load("example.sage")
Hello World
8
你也可以 attach
运行会话的Sage文件:
sage: attach("example.sage")
Hello World
8
如果你改变了 example.sage
在Sage中输入一个空白行,然后 example.sage
将自动重新加载到Sage中:
sage: !emacs example.sage& #change 2^3 to 2^4
sage: #hit return
***************************************************
Reloading 'example.sage'
***************************************************
Hello World
16
不耐烦的装置¶
我们将解释安装最新版本Sage的基本步骤(它是“源”版本,而不是“二进制文件”)。
下载
sage-*.tar
(何处)*
表示版本号)从网站上保存到一个目录中,比如说HOME
. 类型tar zxvf sage-*.tar
在里面HOME
.光盘
sage-*
(我们称之为SAGE_ROOT
)和类型make
. 现在要有耐心,因为这个过程需要2个小时左右。
Sage命令的Python语言程序代码¶
假设您想知道Sage命令计算置换组中心的Python程序是什么。使用Sage的帮助界面查找文件名:
sage: PermutationGroup.center?
Type: instancemethod
Base Class: <type 'instancemethod'>
String Form: <unbound method PermutationGroup.center>
Namespace: Interactive
File: /home/wdj/sage/local/lib/python2.4/site-packages/sage/groups/permgroup.py
Definition: PermutationGroup.center(self)
现在您知道命令位于 permgroup.py
文件,并且您知道要查找该Python模块的目录。您可以使用编辑器来读取代码本身。
Sage中的“特殊功能”¶
Sage有许多特殊功能(参见参考手册http://doc.sagemath.org/html/en/reference/functions/)它们中的大多数都可以被象征性地操纵。如果没有实现这一点,则其他符号包可能具有该功能。
通过Maxima,允许一些符号操作:
sage: maxima.eval("f:bessel_y (v, w)")
'bessel_y(v,w)'
sage: maxima.eval("diff(f,w)")
'(bessel_y(v-1,w)-bessel_y(v+1,w))/2'
sage: maxima.eval("diff (jacobi_sn (u, m), u)")
'jacobi_cn(u,m)*jacobi_dn(u,m)'
sage: jsn = lambda x: jacobi("sn",x,1)
sage: P = plot(jsn,0,1, plot_points=20); Q = plot(lambda x:bessel_Y( 1, x), 1/2,1)
sage: show(P)
sage: show(Q)
除了 maxima
, pari
和 octave
也有一些特殊的功能(事实上 pari
的特殊功能用Sage包装)。
下面是一个使用Sage接口的示例(位于Sage/interfaces中/倍频程.py)与 octave
(http://www.octave.org/doc/index.html).
sage: octave("atanh(1.1)") ## optional - octave
(1.52226,-1.5708)
下面是一个使用Sage接口的示例 pari
的特殊功能。
sage: pari('2+I').besselk(3)
0.0455907718407551 + 0.0289192946582081*I
sage: pari('2').besselk(3)
0.0615104584717420
什么是Sage?¶
Sage是一个用于数论、代数和几何计算的框架,最初是为使用椭圆曲线和模形式进行计算而设计的。长期目标是使它更普遍地用于代数、几何和数论。它是开源的,根据GPL的条款可以免费获得。参考手册中的章节标题大致介绍了Sage所涵盖的主题。
Sage史¶
Sage由williamstein于2004年秋季在哈佛大学(harvarduniversity)创建,2005年1月发布了0.1版本。这个版本包括Pari,但不包括GAP或单数。版本0.2发布于3月份,版本0.3发布于4月份,版本0.4发布于7月份。在此期间,增加了对Cremona数据库、多元多项式和大型有限域的支持。此外,还编写了更多的文档。版本0.5测试版于8月发布,0.6测试版于9月发布,0.7版于当月晚些时候发布。在此期间,增加了对向量空间、环、模符号和windows用户的更多支持。在2005年10月发布的0.8版本中,Sage包含了GAP的全部分布,尽管一些GAP数据库必须单独添加,并且是单数的。添加单数并不容易,因为从源代码处编译单数很困难。版本0.9于11月发布。这个版本经历了34次发布!从0.9.34版(绝对是0.10.0版)起,Maxima和clisp都包含在Sage中。版本0.10.0于2006年1月12日发布。sage1.0的发布于2006年2月初。截至2008年2月,最新版本是2.10.2。
许多人贡献了大量的代码和其他专业知识,例如在各种操作系统的编译方面提供了帮助。通常,代码作者可以在他们文件的Python docstring的AUTHOR部分和Sage网站的credits部分得到认可。