CoCalc Public Fileswww / talks / 2006-05-11-sage_how_works / current.tex
Author: William A. Stein
1
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3%  (c)  William Stein
4%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6\documentclass{beamer}
7\usepackage{beamerthemesplit}
8\usepackage{pgfpages}
9
10%\pgfpagesuselayout{4 on 1}[letterpaper,landscape, border shrink=5mm]
11%\setbeamercolor{background canvas}{bg=black!0}
12
13\usepackage{graphicx}
14\newcommand{\page}[1]{\frame{#1}}
15
16\usepackage{amsmath}
17\usepackage{amsfonts}
18\usepackage{amssymb}
19\usepackage{amsthm}
20\usepackage{graphicx}
21\usepackage{pstricks}
22\usepackage{color}
23\definecolor{dbluecolor}{rgb}{0,0,0.6}
24\definecolor{dredcolor}{rgb}{.5,0.0,0.0}
25\definecolor{dgreencolor}{rgb}{0,0.4,0}
26\definecolor{blue}{rgb}{.02, .02, .908}
27\newcommand{\dred}{\color{dredcolor}\bf}
28\newcommand{\dblue}{\color{dbluecolor}\bf}
29\newcommand{\dgreen}{\color{dgreencolor}\bf}
30%\newcommand{\dred}{\bf}
31%\newcommand{\dblue}{\bf}
32%\newcommand{\dgreen}{\bf}
33
34\usepackage{xspace}  % to allow for text macros that don't eat space
35\newcommand{\SAGE}{{\color{blue}\sf SAGE}\xspace }
36\newcommand{\sage}{\SAGE}
37
38\newcommand{\graph}[1]{\includegraphics[width=0.45\textwidth]{#1}}
39
40\title{How SAGE Works: Interfaces}
41\author{William Stein (University of Washington)}
42\date{May 11, 2006: UW SAGE Seminar\vspace{2ex}\\
43\includegraphics[width=1.5in]{icon-5}}
44\bibliographystyle{amsalpha}
45\newcommand{\Q}{\mathbb{Q}}
46\newcommand{\Z}{\mathbb{Z}}
47\newcommand{\defn}[1]{{\em #1}}
48% ---- SHA ----
49\DeclareFontEncoding{OT2}{}{} % to enable usage of cyrillic fonts
50  \newcommand{\textcyr}[1]{%
51    {\fontencoding{OT2}\fontfamily{wncyr}\fontseries{m}\fontshape{n}%
52     \selectfont #1}}
53\newcommand{\Sha}{{\mbox{\textcyr{Sh}}}}
54\DeclareMathOperator{\rank}{rank}
55\DeclareMathOperator{\Vis}{Vis}
56\DeclareMathOperator{\HH}{H}
57\DeclareMathOperator{\Ker}{Ker}
58\DeclareMathOperator{\ord}{ord}
59\renewcommand{\H}{\HH}
60\newcommand{\hra}{\hookrightarrow}
61\newcommand{\isom}{\cong}
62\newcommand{\ds}{\displaystyle}
63\renewcommand{\t}[1]{\begin{center}{\large{\dblue #1}}\end{center}}
64
65
66\begin{document}
67
68\page{
69\maketitle
70}
71
72
73\begin{frame}
74\begin{abstract}
75  This talk will be aimed at people who want to understand the
76  architecture of \SAGE.  Today I will explain some of the details
77  about how \SAGE interfaces with computer algebra systems and
78  how people interface with \sage.
79\begin{enumerate}
80   \item How \sage{} {\dblue interfaces} with other computer algebra systems.
81   \item How \sage{} {\dblue interfaces} with users via their web-browsers.
82\end{enumerate}
83\end{abstract}
84\end{frame}
85
86\begin{frame}
87\t{Part I: How \sage{} {\dblue interfaces} with other computer algebra systems.}
88\end{frame}
89
90\begin{frame}
91\t{Class Hierarchy}
92\includegraphics[width=1.1\textwidth]{classdia}
93
94(examples)
95\end{frame}
96
97\begin{frame}
98\t{Pexpect and Pseudotty's}
99\begin{itemize}
100\item {\dblue Pseudotty:} A device which appears to an application program
101as an ordinary terminal but which is {\em in fact} connected to a
102different process.  Pseudo-ttys have a slave half and a control half.
103
104\item {\dblue Pexpect:} {\em makes Python a better tool for controlling
105  other applications.}  ({\tt pexpect.sourceforge.net})
106
107  Pexpect is a pure Python module for spawning child applications;
108  controlling them; and responding to expected patterns in their
109  output.  Pexpect works like Don Libes' Expect. Pexpect allows your
110  script to spawn a child application and control it as if a human
111  were typing commands.
112\end{itemize}
113\end{frame}
114
115\begin{frame}[fragile]
116\t{Using pexpect: The Basic Idea}
117\begin{verbatim}
118sage: import pexpect
119sage: p = pexpect.spawn('gp --emacs --fast --quiet')
120sage: p.maxread = 100000   # crucial for speed!!!
121sage: p.expect('\\? ')
1220
123sage: p.sendline('factor(2006)')
12413
125sage: p.expect('\\? ')
1260
127sage: p.before
128'factor(2006)\r\n\r\n[2 1]\r\n\r\n[17 1]\r\n\r\n
129 [59 1]\r\n\r\n'
130sage: p.close()
131\end{verbatim}
132\end{frame}
133
134\begin{frame}
135\t{Difficulties}
136\begin{enumerate}
137\item Getting subprocesses (and their children!) to quit when you
138quit \sage{}.
139\item I/O Prompts: make very obscure or embed control codes.
140\item Control-C: How to break out of a computation.
141\item Large I/O: use files.
142\item Remote servers: Use the network -- will greatly improve
143         this summer (Yi Qiang).
144\item Readline (weird formatting in server); often there are
145debug modes, e.g., in Maple; or emacs modes.
146\item Support for direct interaction -- coding sprint at Sage Days 1.
147\item Unknown number of return values -- Magma.
148\end{enumerate}
149\end{frame}
150
151\begin{frame}
152\t{How to Create a New Interface}
153\begin{enumerate}
154\item Decide which of the following programs
155is most similar to your program:
156gap, gnuplot, magma, maxima, genus2reduction, gp, mwrank, ecm,
157kash, maple, octave, singular, gfan, macaulay2, mathematica
158\item Copy {\tt sage/interfaces/similarsys.py} and modify
159as appropriate.  Use the {\tt log=} option to interface
160constructor for debuging.
161\item Figure out what the true, false, equality, etc., symbols
162are in your system and code those into the interface.
163\item Provide special functionality for tab completion (listing
164all defined functions), help on functions, etc.
165\end{enumerate}
166
167\end{frame}
168
169\begin{frame}
170\t{How to Improve an Existing Interface}
171Let $C$ be a computer algebra system, e.g., Maple,
172Macaulay2, etc.
173\begin{enumerate}
174\item Systematically work through a standard
175tutorial for $C$ but using the SAGE interface;
176record anything that is difficult, impossible,
177or {\em unnatural} to do.  Add functionality
178to interface to remedy these problems.
179\item Try the interface I and if I.[tab] doesn't
180give all functions in the system, figure out how
181to get them and tell me!
182\item Write conversion functions between SAGE objects
183and objects in $C$, e.g., matrices.  We need far
184more of these!
185\end{enumerate}
186\end{frame}
187
188\begin{frame}
189\t{Part II: Web Browser Interfaces to SAGE}
190\begin{enumerate}
191\item Simple cgi-bin script interface
192\item SAJAX -- an AJAX interface to SAGE
193\item SAGE Web Notebook -- brand new local web-server interface
194\end{enumerate}
195\end{frame}
196
197
198\begin{frame}
199\t{1. Simple cgi-bin script interface}
200This is at
201{\tt http://modular.math.washington.edu/calc/},
202but people have copied it for Kash, MAGMA, etc.
203
204\begin{enumerate}
205\item Started so Keith Conrad's student at UCONN could use
206PARI easily for their number theory class.
207\item Uses apache2 and some simple Python cgi-bin scripts.
208\item Provided way to try out MAGMA'' (and variant is
209now available at MAGMA website.)
210\end{enumerate}
211\end{frame}
212
213\begin{frame}[fragile]
214\begin{verbatim}
215Date: Mon, 19 Dec 2005 16:54:09 -0800
216From: "John Cannon" <john@maths.usyd.edu.au>
217William,
218
220run a general-purpose calculator based on Magma ends on
221Dec 31, 2005. [...]
222
223Note that this does NOT affect the use of Magma in your
224modular forms site.  Nor is it likely that we would
225withdraw permission for this use of Magma provided that
226Magma is properly acknowledged (as it has been in the
227past).  In fact we are encouraging the use of Magma as
228part of the backend in similar servers.
229
230Please confirm receipt of this letter.
231Wishing you a happy Christmas,
232John
233\end{verbatim}
234\end{frame}
235
236
237\begin{frame}
238\t{2. SAJAX: AJAX interface to SAGE}
239Aaron Klem found an AJAX terminal application at
240{\tt http://antony.lesuisse.org/qweb/trac/wiki/AjaxTerm}.
241It's a stand-alone webserver written with Python combined with
242a javascript page.
243
244I modified it to make
245  {\tt http://modular.math.washington.edu:8389/}
246
247\begin{enumerate}
248\item No authentication -- need chroot.  The AJAX term web
249server runs as a normal process.   When a user connects,
250a chroot'd SAGE session starts set to timeout after an
251hour.
252\item Multiple connections at once are allowed.
253\item {\em Rumored} to be unusably slow, though I've
254not experienced this (i.e., it's great if the server
255is in on campus'').
256\item No graphics.  No scrollback.  Cut and paste
257is very difficult.
258\item Tab completion, history, etc., work well.
259\item Hard to setup (because of chroot jail).
260\end{enumerate}
261\end{frame}
262
263\begin{frame}
264\t{3. The SAGE Web Notebook}
265Alex Clemesha and I wrote it from scratch as part of SAGE
266(on Monday).
267It uses that Python has (as part of the standard library!)
268a web server built in.
269\begin{itemize}
270\item Completely standalone.
271\item Python for webserver; some Javascript in the web page.
272\item Not done!  But I already like using it more than command line!
273\item Saves all I/O to a disk file whenever possible (if you gave
274  optional name='file' argument).
275\item Multiple people connect to a single session at
276  once.
277\item May become the standard SAGE interface; you start a local server
278  on your computer (e.g., via Cygwin or VMware under Windows), connect
279  to a local web address, and use SAGE.  Or connect to a university
280  server and use SAGE; same interface!
281\item Completely avoids need to create GUI for SAGE.
282\end{itemize}
283\end{frame}
284
285
286\begin{frame}[fragile]
287\t{SAGE Web Notebook: TODO List}
288{\tiny\begin{verbatim}
290   [] The "move to the current input box" javascript *only* works
291      with firefox (not opera, not konqueror); also this should
292      just keep the page position where it is rather than move it.
293      Moving to a more AJAX-ish model would alternatively fix this, maybe.
294   [] A. Clemesha: shrink/expand input/output blocks
295   [] A. Clemesha: When hit shift-enter the next text box should be made
296      into focus.
297   [] Add plain text annotation that is not evaluated
298      between blocks (maybe in html?)
299      E.g., just make ctrl-enter on a block by HTML-it.
300   [] Ability to interrupt running calculations directly
301      from the web interface (no console access)
302   [] Nice animation while a computation is proceeding.
303   [] Some way to show output as it is computed.
304   [] Option to delete blocks
305   [] Make block expand if enter a lot of text into it.
306   [] Evaluate the entire worksheet
307   [] Theme-able / skin-able
308   [] Embedded graphics from plots;
309       also embed png from latexing of math objects (so they look nice).
311   [] Save session objects as to log objects so don't have to re-eval?
312   [] The entire page is resent/updated every time you hit shift-enter;
313      using 'AJAX' this flicker/lag could be completely eliminated.
314   [] When pressing shift-enter a line feed is inserted temporarily
315      into the inbox, which is unnerving.
316
317Try it and send me some ideas!
318\end{verbatim}
319}
320\end{frame}
321
322\end{document}
323
324