How to use the Sage Notebook_对文档的中文解释by wyf

DOC版

How to use the Sage Notebook

worksheet is an ordered list of Sage calculations with output.

session is a worksheet and a set of variables in some state.

The Sage notebook is a collection of worksheets, saved objects, and user information.

Find Help and Documentation

Get Started with Sage

Work through the tutorial (if you have trouble with it, view the static version).

Help About

Type ? immediately after the object or function and press tab or shift-enter (shift-enter overwrites output and saves to worksheet).(在有疑问的object或function后输入?,再按tab或者shift+enter即可查询此object或function

Source Code

Put ?? after the object and press tab or shift-enter (shift-enter overwrites output and saves to worksheet).(同上,用两个问号可以看见源码

Full Text Search of Docs and Source

Search the SAGE documentation by typing(在文档中进行全文搜索的命令

search_doc("my query")

in an input cell and press shift-enter. Search the source code of SAGE by typing(在源码中

search_src("my query")

and pressing shift-enter. Arbitrary regular expressions are allowed as queries.(可以使用正则表达式,高级文字匹配工具~~)

Key and Mouse Bindings

Evaluate Input

Press shift-enter. You can start several calculations at once. If you press alt-enter instead,then a new cell is created after the current one. If you press ctrl-enter then the cell is split and both pieces are evaluated separately.(

shift+enter会把当前的cell进行evaluate,并且光标进入下一个cell,没有则自动创建

alt+enter可以把当前的cell进行evaluate,并且在紧接着下面新插入一个cell

ctrl+enter把当前的cell从当期光标所在处腰斩(split)成两个cell,分别进行evaluate)

Tab Completion

Press tab while the cursor is on an identifier. On some web browsers (e.g., Opera) you must use control-space instead of tab.(就是命令(或着叫函数)只输入了一部分,就按tab,可见以此打头的所有命令,上下键选一个吧。这就是自动补全功能。

输入一个plot按一下tab看见plot3d了吗?

Insert New Cell

Put the mouse between an output and input until the horizontal line appears and click.(移动鼠标到cell的上面看见蓝粗条了吗?点一下就知道怎么回事了)

 If you press Alt-Enter in a cell, the cell is evaluated and a new cell is inserted after it.

Delete Cell

Delete all cell contents, then press backspace.(把cell里的内容都删掉,cell就会被删掉)

Split and Join Cells

Press ctrl-; in a cell to split it into two cells, and ctrl-backspace to join them. (ctrl+;此组合键chrome不支援,ctrl+backspace可以把当前的cell和之前的cell合并)

Press ctrl-enter to split a cell and evaluate both pieces.

Insert New Text Cell

Move the mouse between cells until a blue bar appears. Shift-click on the blue bar to create a new text cell. Double click on existing text to edit it. Use $...$ and $$...$$ to include typeset math in the text block.

Hide/Show Output

Click on the left side of output to toggle between hidden, shown with word wrap, and shown without word wrap.(单击输出的左侧小空白,输出的结果就收起来了)

Indenting Blocks

Highlight text and press > to indent it all and < to unindent it all (works in Safari and Firefox). In Firefox you can also press tab and shift-tab.(选中几行代码直接按tab,可以把选中的代码缩进,相当方便~

Comment/Uncomment Blocks

Highlight text and press ctrl-. to comment it and ctrl-, to uncomment it. Alternatively, use ctrl-3 andctrl-4.(ctrl+,可以注释当前选中的部分,ctrl+,可以解除注释

Paren matching

To fix unmatched or mis-matched parentheses, braces or brackets, press ctrl-0. Parentheses before the cursor will be matched, minding strings and (Python) comments.(输入(([([(然后按ctrl+0试试吧,自动括号匹配

Interrupt and Restart Sessions

Interrupt Running Calculations

Click Interrupt or press escape in any input cell. This will (attempt) to interrupt SAGE by sending many interrupt signals.(如何终止命令的执行,点击Interrupt,如果没看见就按ESC键,仿佛一样的

比如你坑爹的键入

factor(2^323-15)

然后好生等待,黄花菜都凉了

 

找到notebook开始的这个Interrupt,或者果断按ESC)

Restart

Type "restart" to restart the SAGE interpreter for a given worksheet. (You have to interrupt first.)

Special Cell Blocks

Evaluate Cell using GAP, Singular, etc.

Put "%gap", "%singular", etc. as the first input line of a cell; the rest of the cell is evaluated in that system.(通过首行注释”%某语言解释系统的名称”实现本cell的解释器修改

Shell Scripts

Begin a block with %sh to have the rest of the block evaluated as a shell script. The current working directory is maintained.

Interactive Dynamic Widgets

Put @interact on the line before a function definition. Type interact? for more details.

Autoevaluate Cells on Load

Type "%auto" on a line by itself at the beginning of a cell to automatically evaluate the cell when the worksheet is first opened.(通过首行注释“%auto”,每次打开此worksheet都会自动evaluate这个cell)

Time

Type "%time" at the beginning of the cell.(可以看到本cell运行所花的时间,

CPU time: 0.02 s,  Wall time: 0.04 s

etc.)

Useful Tips

Input Rules

Code is evaluated by exec'ing (after preparsing). Only the output of the last line of the cell is implicitly printed. If any line starts with "sage:" or ">>>" the entire block is assumed to contain text and examples, so only lines that begin with a prompt are executed. Thus you can paste in complete examples from the docs without any editing, and you can write input cells that contains non-evaluated plain text mixed with examples by starting the block with ">>>" or including an example.(一个输入内容的约定,告诉你可以把文档中的例子直接拷入cell中运行,如下:

sage: @interact
... def _(n=(10,100,1)):
...     show(factor(x^n - 1))
<html>...

Copy into a cell, evaluate it:

 

这里的逻辑大概是,前端的预处理器会把,句首的sage:或者...外加紧接在后面的一个括号删去,在去解释执行

~~多一个少一个空格其实在python里还是非常敏感的

History

Click log commands you have entered in any worksheet of this notebook.(右上角的

 

Log按钮可以看见这个worksheet的全部键入全部输出的history,like History in MATLAB~)

Typesetting All Output

Type pretty_print_default() in an input cell and press shift-enter. All future output will be typeset automatically.(可能和手动勾选Typese前的方框是一样的效果)

Files and Scripts

Loading SAGE/Python Scripts

Use "load filename.sage" and "load filename.py". Load is relative to the path you started the notebook in. The .sage files are preparsed and .py files are not. You may omit the .sage or .py extension. Files may load other files.

Attaching Scripts

Use "attach filename.sage" or "attach filename.py". Attached files are automatically reloaded when the file changes. The file $HOME/.sage/init.sage is attached on startup if it exists.

Working Directory

Each block of code is run from its own directory. If any images are created as a side effect, they will automatically be displayed.

DIR Variable

The variable DIR contains the directory from which you started the SAGE notebook. For example, to open a file in that directory, do "open(DIR+'filename')".(DIR变量储存着当前的目录名,如

/home/sage/sage-4.8

)

DATA Variable

Use the Data menu to upload images and other files, and create new files that can be shared between worksheets. The DATA variable contains the path to the data files. For example, to open a file in that directory, do "open(DATA+'filename')". If foo.sage is a Sage file that you uploaded, type "load foo.sage"; if foo.py is a Python file, you can import it by typing "import foo".

Loading and Saving Objects

Use "save obj1 obj2 ..." and "load obj1 obj2 ...". This allows for easy moving of objects from one worksheet to another, and saving of objects for later use.

Loading and Saving Sessions

Use "save_session('name')" to save all variables to an object. Use "load_session('name')" to merge in all variables from a saved session.

Customizing the Notebook CSS

If you create a file $HOME/.sage/notebook.css then it will get applied when rendering the notebook. See

 

注意在不同的浏览器会有不同的快捷键占用,建议选择主流的浏览器,以便充分使用快捷键完成必要操作。

因为据笔者推断,Sage的设计会主要考虑Chrome、Firefox(此两者开源)和IE(8、9、10版)的浏览器快捷键,免得冲突。

 

 

 

这是我昨晚上做的一个示范性的工作,你可以考虑选择下面一些工作去做

 

翻译文档的一点(其实是整理用简单的话说明白即使,想必这样做之后你也明白了许多)

 

了解http://wiki.wstein.org/edu/2012/480

 

 

 

 

左上角出现此红底白字,说明服务已断开。

posted @ 2012-06-15 09:23  iSL  阅读(418)  评论(0编辑  收藏  举报