<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-6365588202025292315</atom:id><lastBuildDate>Thu, 09 May 2013 15:56:32 +0000</lastBuildDate><category>sage python introduction open source mathematics software</category><category>sage "math software" autobiographical magma maple matlab mathematica pari</category><category>sage ipad iphone python</category><category>vmware virtualbox</category><title>Sage: Open Source Mathematics Software</title><description>This is my blog about things related to Sage.</description><link>http://sagemath.blogspot.com/</link><managingEditor>noreply@blogger.com (William Stein)</managingEditor><generator>Blogger</generator><openSearch:totalResults>48</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-6947292052011386741</guid><pubDate>Mon, 17 Dec 2012 17:00:00 +0000</pubDate><atom:updated>2012-12-17T09:00:59.218-08:00</atom:updated><title>BDFL?</title><description>&lt;br /&gt;&lt;div style="font-family: arial; font-size: small;"&gt;I just read &lt;a href="http://technicaldiscovery.blogspot.com/2012/12/passing-torch-of-numpy-and-moving-on-to.html"&gt;this blog post &lt;/a&gt;about the direction of numpy development, which might be of interest to Sage Developers. &amp;nbsp;&amp;nbsp;TL;DR -- Travis Oliphant explains that he is stepping down as head steward of Numpy, and then explains the awesome new things he's working on instead.&lt;/div&gt;&lt;div style="font-family: arial; font-size: small;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: arial; font-size: small;"&gt;This made me think about my current relationship with the Sage project, where I'm similarly considered "head steward". &amp;nbsp;I have not been super-active in the last few months in day-to-day Sage development, and haven't posted a lot on the lists. &amp;nbsp; However, in my case, this is because I'm doing some hard work to build a company (Salvus) that may be able to provide more sustainable funding for core Sage development later. &amp;nbsp; For example, yesterday, Drew Sutherland and I worked at an approach to implementing computation of &lt;i&gt;q&lt;/i&gt;-expansions of higher weight modular forms (using modular symbols) which would be much, much faster than what's in Sage (or Magma) now. &amp;nbsp;I'm not implementing it today, because I'm working on Salvus instead, so that hopefully in a year I will have all the time I need to implement exactly that algorithm and more &lt;i&gt;in Sage&lt;/i&gt;, as a result of what I'm doing now. &amp;nbsp; (Drew will implement a special case he needs for his research.)&lt;/div&gt;</description><link>http://sagemath.blogspot.com/2012/12/bdfl.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-2257828732623420606</guid><pubDate>Sat, 10 Mar 2012 15:57:00 +0000</pubDate><atom:updated>2012-03-10T07:57:51.712-08:00</atom:updated><title>Sage and Python 3?</title><description>Have you ever wondered how difficult it might be to switch Sage from Python 2.7 to Python 3.x? &amp;nbsp;Some students in my Sage course &lt;a href="http://wstein.org/edu/2012/1062/projects/final/miloshevich-nason/"&gt;made a webpage&lt;/a&gt; that summarizes the Python 3 support status of the Python packages on which Sage depends.&lt;br /&gt;&lt;br /&gt;Interesting examples:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Matplotlib doesn't support Python 3.x at all yet.&lt;/li&gt;&lt;li&gt;Mercurial doesn't support Python 3.x, and they don't have any plans to do so. (Which is another point in favor switching Sage to GIT.)&lt;/li&gt;&lt;/ul&gt;</description><link>http://sagemath.blogspot.com/2012/03/sage-and-python-3.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-462151735942772464</guid><pubDate>Thu, 08 Mar 2012 22:57:00 +0000</pubDate><atom:updated>2012-03-08T14:57:08.246-08:00</atom:updated><title>How to get access to Magma</title><description>Despite &lt;a href="http://www.sagemath.org/"&gt;Sage&lt;/a&gt; doing a lot, people still write to me asking about how to get access to &lt;a href="http://magma.maths.usyd.edu.au/magma/"&gt;Magma&lt;/a&gt;.  Here is my advice:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;You can &lt;a href="http://magma.maths.usyd.edu.au/magma/ordering/#sec_5"&gt;buy a copy of Magma here&lt;/a&gt; for only $1180.   &lt;br /&gt;&lt;/li&gt;&lt;li&gt;If your calculation will take less than 20 seconds (?), you can do it &lt;a href="http://magma.maths.usyd.edu.au/calc/"&gt;over the web for free&lt;/a&gt;.  (Historical note: I wrote the first version of that website.)&lt;/li&gt;&lt;li&gt; In Sage, use the command &lt;tt&gt;magma_free('some string')&lt;/tt&gt;, though I just checked and the Magma calculator has changed in a way that breaks this command &lt;a href="http://trac.sagemath.org/sage_trac/ticket/10499"&gt;again&lt;/a&gt;.  I'll be &lt;a href="http://trac.sagemath.org/sage_trac/ticket/12642"&gt;posting a patch to fix this&lt;/a&gt; in Sage.&lt;br /&gt;&lt;/li&gt;&lt;li&gt; Most people I know who have Magma do not buy it, but get it in exchange for contributing to Magma (I used to get it free for that reason).  Study the list of&lt;br /&gt;&lt;a href="http://magma.maths.usyd.edu.au/magma/acknowledge/#sec_3"&gt;past&lt;/a&gt; and &lt;a href="http://magma.maths.usyd.edu.au/group/members/"&gt;current&lt;/a&gt; contributors to Magma and ask the one you know the best. This is a list of people who definitely have a copy of Magma and know how to use it.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;</description><link>http://sagemath.blogspot.com/2012/03/how-to-get-access-to-magma.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-868899265282339123</guid><pubDate>Thu, 15 Dec 2011 22:42:00 +0000</pubDate><atom:updated>2011-12-15T14:42:33.854-08:00</atom:updated><title>How big is the core Sage library?</title><description>I just did the following with Sage-4.8.alpha5:&lt;br /&gt;&lt;ol&gt;&lt;li&gt; "sudo apt-get install sloccount".&lt;/li&gt;&lt;li&gt; "cp -rv SAGE_ROOT/devel/sage-main  /tmp/x"&lt;/li&gt;&lt;li&gt; Use a script [1] to rename all .pyx and .pxi files to .py.&lt;/li&gt;&lt;li&gt; Ran "sloccount *" in the /tmp/x directory, which ignores autogenerated .c/.cpp files coming from Cython.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;Here's the result for the full Sage library, which does not distinguish between Python and Cython.  Note that sloccount really only counts lines of code -- comments are blank lines are ignored.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;Totals grouped by language (dominant language first):&lt;br /&gt;python:      530370 (96.41%)&lt;br /&gt;ansic:        14538 (2.64%)&lt;br /&gt;cpp:           5188 (0.94%)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This suggests that the core Sage library is just over a "half million lines of Python and Cython source code, not counting comments and whitespace".&lt;br /&gt;&lt;br /&gt;Here's the breakdown by module:&lt;br /&gt;&lt;pre&gt;SLOC    Directory       SLOC-by-Language (Sorted)&lt;br /&gt;88903   rings           python=87720,cpp=1183&lt;br /&gt;72913   combinat        python=71629,cpp=1284&lt;br /&gt;47747   schemes         python=46255,cpp=1492&lt;br /&gt;39815   graphs          python=28377,ansic=11438&lt;br /&gt;31540   matrix          python=31540&lt;br /&gt;31019   modular         python=31012,ansic=7&lt;br /&gt;24475   libs            python=21171,ansic=2845,cpp=459&lt;br /&gt;20517   misc            python=20383,ansic=134&lt;br /&gt;18006   interfaces      python=18006&lt;br /&gt;17577   geometry        python=16936,cpp=641&lt;br /&gt;12775   categories      python=12775&lt;br /&gt;12093   server          python=12093&lt;br /&gt;11971   groups          python=11971&lt;br /&gt;11961   plot            python=11961&lt;br /&gt;10686   crypto          python=10686&lt;br /&gt;9920    modules         python=9920&lt;br /&gt;8389    symbolic        python=8260,cpp=129&lt;br /&gt;8150    algebras        python=8150&lt;br /&gt;7260    ext             python=7198,ansic=62&lt;br /&gt;7093    structure       python=7093&lt;br /&gt;6364    coding          python=6364&lt;br /&gt;5670    functions       python=5670&lt;br /&gt;5249    homology        python=5249&lt;br /&gt;4798    numerical       python=4798&lt;br /&gt;4323    quadratic_forms python=4323&lt;br /&gt;3919    gsl             python=3919&lt;br /&gt;3911    calculus        python=3911&lt;br /&gt;3879    sandpiles       python=3879&lt;br /&gt;3003    sets            python=3003&lt;br /&gt;2647    databases       python=2647&lt;br /&gt;2074    logic           python=2074&lt;br /&gt;1736    finance         python=1736&lt;br /&gt;1608    games           python=1608&lt;br /&gt;1465    monoids         python=1465&lt;br /&gt;1435    tests           python=1383,ansic=52&lt;br /&gt;1370    stats           python=1370&lt;br /&gt;971     interacts       python=971&lt;br /&gt;959     tensor          python=959&lt;br /&gt;906     lfunctions      python=906&lt;br /&gt;308     parallel        python=308&lt;br /&gt;275     probability     python=275&lt;br /&gt;219     media           python=219&lt;br /&gt;197     top_dir         python=197&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here is the script [1]:&lt;br /&gt;&lt;pre&gt;#!/usr/bin/env python&lt;br /&gt;&lt;br /&gt;import os, shutil&lt;br /&gt;&lt;br /&gt;for dirpath, dirnames, filenames in os.walk('.'):&lt;br /&gt;    for f in filenames:&lt;br /&gt;        if f.endswith('.pyx') or f.endswith('.pxi'):&lt;br /&gt;            print f&lt;br /&gt;            shutil.move(os.path.join(dirpath, f),&lt;br /&gt;                        os.path.join(dirpath, os.path.splitext(f)[0] + '.py'))&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;</description><link>http://sagemath.blogspot.com/2011/12/how-big-is-core-sage-library.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-2275785521252427200</guid><pubDate>Tue, 13 Dec 2011 22:06:00 +0000</pubDate><atom:updated>2011-12-13T14:07:21.837-08:00</atom:updated><title>Using Sage to Support Research Mathematics</title><description>When using Sage to support research mathematics, the most important point to make is to strongly encourage people to do the extra work to turn their "scruffy research code" into a patch that can be peer reviewed and included in Sage.  They will have to 100% doctest it, and the quality of their code may improve dramatically as a result.  Including code in Sage means that the code will continue to work as Sage is updated.   Also, the code is peer reviewed and has to have examples and documentation for every function.   That's a much higher bar than just "reproducible research". &lt;br /&gt;&lt;br /&gt;Moreover, getting code up to snuff to include in Sage will often also reveal mistakes that will avoid embarrassment later.  I'm fixing some issues related to a &lt;a href="http://wstein.org/papers/chow_heegner/chowheeg1.pdf"&gt;soon-to-be-done paper&lt;/a&gt; right now that I found when doing just this for &lt;a href="http://trac.sagemath.org/sage_trac/ticket/11975"&gt;trac 11975&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;This final step of turning snippets of research code into a peer-reviewed contribution to Sage is: (1) a surprisingly huge amount of very important useful work, (2) something that is emphasized as an option for Sage more than with Magma or Mathematica or Pari (say), (3) something whose value people have to be sold on, since they get no real extra academic credit for it, at present, usually, and journal referees often don't care either way (I do, but I'm probably in the minority there), and (4) something that a *lot* of research mathematicians do not do.     As an example of (4), in the last two months I've seen a ton of (separate!) bodies of code which is all sort of secret research code in various Dropbox repos, and which isn't currently squarely aimed at going into Sage.  I've also seen a bunch of code related to Edixhoven et al.'s algorithm for computing Galois representation with a similar property (there is now &lt;a href="http://trac.sagemath.org/sage_trac/ticket/12132"&gt;trac 12132&lt;/a&gt;, due to my&lt;br /&gt;urging).  &lt;br /&gt;&lt;br /&gt;I did *not* do this step yet with this &lt;a href="http://wstein.org/papers/shark/ "&gt;recently accepted paper&lt;/a&gt;.   Instead I used "scrappy research code" in &lt;a href="http://code.google.com/p/purplesage/"&gt;psage&lt;/a&gt; to do the fast L-series computations.   The referee for Math Comp didn't care either way, actually...  I hope this doesn't come back to haunt me, though there are many double checks here (e.g., BSD) so I'm not too worried.   I will do this get-it-in-Sage step at some point though.&lt;br /&gt;&lt;br /&gt;This will be better for the community in the long run, and better for individual researcher's credibility too.   And there is a lot of value in having a stable refereed snapshot of code on which a published (=very stable) paper is based.</description><link>http://sagemath.blogspot.com/2011/12/when-using-sage-to-support-research.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-2165700595963568723</guid><pubDate>Sat, 12 Nov 2011 19:47:00 +0000</pubDate><atom:updated>2011-11-15T08:58:17.214-08:00</atom:updated><title>Is the time ripe for http://sagenb.com?</title><description>On a Sage mailing list, Karl Crisman wrote: "Regarding the downtime issue [of http://sagenb.org], there have occasionally been rumors of someone or some organization starting a service which would guarantee uptime and provide support."&lt;br /&gt;&lt;br /&gt;I might do this.    It might be at &lt;a href="http://sagenb.com/"&gt;http://sagenb.com&lt;/a&gt;&amp;nbsp;(right now sagenb.com points to sagenb.org).   Here's the  "business plan".  Probably, sagenb.com would appear almost the same as &lt;a href="http://sagenb.org"&gt;sagenb.org&lt;/a&gt;, except there would be Google (?) ads on the side of your worksheets, and the revenue would go toward paying for:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;b&gt; Commercial server hosting:&lt;/b&gt; &amp;nbsp;Some Amazon EC2 instances&lt;/li&gt;&lt;li&gt;&lt;b&gt; An employee (or later, employees) to maintain the servers:&lt;/b&gt;&amp;nbsp;at the beginning, this would be me in my free time, since I have a lot of experience with this.&lt;/li&gt;&lt;li&gt;&lt;b&gt; Advertising that sagenb.com exists and we want users!:&lt;/b&gt;&amp;nbsp; Unlike sagenb.org, we would very strongly encourage as many people as possible to use sagenb.com. &amp;nbsp; The advertising and landing page would explain that though sagenb.com generates money, all that money is all given back to the Sage development community (see below).&lt;/li&gt;&lt;li&gt;&lt;b&gt; Hire employees to improve the notebook:&lt;/b&gt; Fix bugs, implement features, etc. There would be a public commitment that &lt;i&gt;all&lt;/i&gt; such work would be open sourced and get included with Sage.  This would include adding support for a for-pay "pro" subscription version, adding nicer "offline support" (via a Sage install on the user's computer), integrated spreadsheets and better data visualization and manipulation tools for Science and business applications, and enabling development of Sage's core library and patches submission entirely through the notebook, etc.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;At some point, there could be a $X/year subscription version that would remove all ads, and increase disk space available to that user.  There would also be a $Y/year university site license version with customized authentication (e.g., LDAP?) for each university. &amp;nbsp; The university site license version might also include Maple/Mathematica/Matlab/Magma pre-installed in their notebook server, assuming appropriate site licenses are honored, so sagenb.com could be something that goes beyond just a platform for "sage as math software". &amp;nbsp; We can of course also tap into the R market, given that Sage includes R.&lt;br /&gt;&lt;br /&gt;I imagine the above being done as a not-for-profit effort, so if it brought in a lot of revenue (e.g., more than needed for hosting and employees), excess money would go to the Sage Foundation to support other Sage development activities.   Regarding numbers, according to Google Analytics, right now on average well over 1000 people use sagenb.org every day. &amp;nbsp; &amp;nbsp;Standard commercial hosting costs for EC2 to support this load would be roughly $100/month.  If each visitor generates on average of 1 penny of ad revenue per day (is this a reasonable estimate -- I have no clue?), then we would expect to make $3,650 in one year, which would be enough to fund the EC2 service (at about $2000/year), with a profit of $1,650. &amp;nbsp; &lt;br /&gt;&lt;br /&gt;Now let's dream big! &amp;nbsp;There might be 1,000,000 potential daily users out there for a service like this, if it worked sufficiently well, since there are many college students (and people that use math and stats programs like R in the sciences, and R is part of Sage) in the world. &amp;nbsp; Scaling up by a factor of 1,000 would yield over $1 million/year, after paying for hosting fees. &amp;nbsp; This would be enough to fund substantial work to improve Sage, the notebook, and have a paid Patch Editor position (imagine buying out a top Sage developer professor, e.g., John Palmierri, from 50% of his teaching obligations in exchange for him spending the time he would spend teaching instead organizing that the patches to Sage get properly refereed). &amp;nbsp;Maybe we could even hire back some of the (many!) people who were Sage developers when they were mathematics grad student or postdocs, but who then went to work at a top web technology company and acquired useful experience there (and are now way too busy to work on Sage).&lt;br /&gt;&lt;br /&gt;This has the potential to make Sage a more longterm self-sustaining project.   It's probably not possible to get traditional venture capital for a not-for-profit plan like the one above, but fortunately that is not needed due to (1) the generous support the National Science Foundation is currently providing toward development on the Sage notebook, and (2) private donations to the Sage Foundation. &amp;nbsp;In particular, (2) provides enough money to bootstrap a sagenb.com for a while.&lt;br /&gt;&lt;br /&gt;I think the main potential downside is competition. &amp;nbsp;If somebody else does the same thing right now for profit without giving back their changes, and captures the market it's hard to imagine how the above would work. &amp;nbsp;Since we don't use the &lt;a href="http://www.affero.org/oagpl.html"&gt;Affero GPL&lt;/a&gt; for the Sage notebook, it is legal for somebody to do a lot of customization work to Sage and notebook, create a web-app using this customized version, and give back nothing to the community, so long as they don't redistribute their modified versions publicly.     This isn't crazy -- not so long ago, I had a major company (I won't say who out of respect) tell me they planed to do something like that. &amp;nbsp; &amp;nbsp;And "random people" suggest it somewhat regularly when I give talks about Sage. &amp;nbsp; I'm surprised it hasn't happened yet, but it definitely hasn't.&lt;br /&gt;&lt;br /&gt;So the time to do this is today. &amp;nbsp;The notebook software we have is now finally reasonably scalable, primarily due to work of Mike Hansen and Rado Kirov. &amp;nbsp;Our funding situation is good &lt;b&gt;&lt;i&gt;this year&lt;/i&gt;&lt;/b&gt;. &amp;nbsp;We have strong good will and interest right now from both the Mathematical Association of America and WebWork developers. &amp;nbsp; If we wait longer, the one chance to truly make Sage financially self-sustaining in a way that fits with my dreams and values will pass. &amp;nbsp; &lt;br /&gt;&lt;br /&gt;I hope that by making all plans open, and by having a commitment to put the profits back into Sage development, an enterprise like I describe here will be in a better position to attract users than a purely for profit venture by somebody else.</description><link>http://sagemath.blogspot.com/2011/11/is-time-ripe-for-httpsagenbcom.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-6924647088500561427</guid><pubDate>Wed, 31 Aug 2011 17:06:00 +0000</pubDate><atom:updated>2011-08-31T10:06:30.361-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>sage python introduction open source mathematics software</category><title>Sage: Creating a Viable Free   Open Source Alternative to Magma, Maple, Mathematica, and MATLAB</title><description>&lt;br /&gt;The goal of the &lt;a href="http://www.sagemath.org/"&gt;Sage project&lt;/a&gt; is to create a viable fre open source alternative to Magma, Maple(TM), Mathematica(R), and MATLAB(R), which are the most popular non-free closed source mathematical software systems. (Maple is a trademark of   Waterloo Maple Inc.  Mathematica is a registered trademark of   Wolfram Research Incorporated. MATLAB is a registered trademark of   MathWorks.  I will refer to the four systems together as ``Ma'' in   the rest of this article.)  Magma is (by far) the most advanced non-free system for structured abstract algebraic computation, Mathematica and Maple are popular and highly developed systems that shine at symbolic manipulation, and MATLAB is the most popular system for applied numerical mathematics.  Together there are over 3,000 employees working at the companies that produce the four Ma's listed above, which take in over a hundred million dollars of revenue annually.&lt;br /&gt;&lt;br /&gt;By a viable free alternative to the Ma's, we mean a system that will have the important mathematical features of each Ma, with comparable speed.  It will have 2d and 3d graphics, an interactive notebook-based graphical user interface, and documentation, including books, papers, school and college curriculum materials, etc.  A single alternative to all of the Ma's is not necessarily a drop-in replacement for any of the Ma's; in particular, it need not run programs written in the custom languages of those systems.  Thus it need not be like Octave or R, which (nearly) clone the languages of MATLAB and S, respectively. Development would instead focus on implementing functions that users demand, rather than systematically trying to implement every single function of the Ma's.  The culture, architecture, and general look and feel of such a system would be very different than that of the Ma's.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Motivation for Starting Sage&lt;/h1&gt;&lt;br /&gt;Each of the Ma's cost substantial money, and is hence expensive for me, my collaborators, and students.  The Ma's are not &lt;i&gt; owned by the community&lt;/i&gt; like Sage is, or Wikipedia is,  for that matter.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Ma's are closed, which means that the implementation of some algorithms are secret, in which case you are not allowed to modify or extend them.  &lt;br /&gt;&lt;br /&gt;The Mathematica Documentation: &lt;i&gt;"You should realize at the outset that while knowing about the internals of Mathematica may be of intellectual interest, it is usually much less important in practice than you might at first suppose.  Indeed, in almost all practical uses of Mathematica, issues about how Mathematica works inside turn out to be largely irrelevant.  Particularly in more advanced applications of Mathematica, it may sometimes seem worthwhile to try to analyze internal algorithms in order to predict which way of doing a given computation will be the most efficient. [...]  But most often the analyses will not be worthwhile. For the internals of Mathematica are quite complicated.."&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;The philosophy espoused in Sage, and indeed by the vast open source software community, is exactly the opposite.  We want you to know about the internals, and when they are quite complicated, we want you to help make them more understandable.  Indeed, Sage's growth depends on &lt;i&gt;you&lt;/i&gt; analyzing how Sage works, improving it, and contributing your improvements back.&lt;br /&gt;&lt;pre&gt;sage: crt(2, 1, 3, 5)  # Chinese Remainder Theorem&lt;br /&gt;    11 &lt;br /&gt;    sage: crt?        # ? = documentation and examples&lt;br /&gt;    Returns a solution to a Chinese Remainder Theorem...&lt;br /&gt;    ...&lt;br /&gt;    sage: crt??       # ?? = source code&lt;br /&gt;    def crt(...):&lt;br /&gt;    ...&lt;br /&gt;        g, alpha, beta = XGCD(m, n)&lt;br /&gt;        q, r = (b - a).quo_rem(g)&lt;br /&gt;        if r != 0:&lt;br /&gt;            raise ValueError("No solution ...")&lt;br /&gt;        return (a + q*alpha*m) % lcm(m, n)&lt;br /&gt;&lt;/pre&gt;Moreover, by browsing &lt;a href="http://hg.sagemath.org/sage-main/"&gt;the Mercurial repository&lt;/a&gt;, you can see exactly who wrote or modified any particular line of code in the Sage library, when they did it, and why.  Everything included in Sage is free and open source, and it will foreover remain that way.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.youtube.com/watch?v=bt_Y4pSdsHw"&gt;Linus Torvalds&lt;/a&gt;:  &lt;i&gt;"I see open source as Science.  If you don't spread your ideas in the open, if you don't allow other people to look at how your ideas work and verify that they work, you are not doing Science, you are doing Witchcraft.  Traditional software development models, where you keep things inside a company and hide what you are doing, are basically Witchcraft.  Open source is all about the fact that it is open; people can actually look at what you are doing, and they can improve it, and they can build on top of it. [...] One of my favorite quotes from history is Newton: `If I had seen further, it has been by standing on the shoulders of giants.'"&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;The design decisions of the Ma's are not made openly by the community. In contrast, important decisions about Sage development are made via open public discussions and voting that is archived on public mailing lists with thousands of subscribers.&lt;br /&gt;&lt;br /&gt;Every one of the Ma's uses a special mathematics-oriented interpreted programming language, which locks you into their product, makes writing some code outside mathematics unnecessarily difficult, and impacts the number of software engineers that are experts at programming in that language.  In contrast, the user language of Sage is primarily the mainstream free open source language Python, which is one of the world's most popular interpreted programming languages.  The Sage project neither invented nor maintains the underlying Python language, but gains immediate access to the IPython shell, Python scientific libraries (such as NumPy, SciPy, CVXopt and MatPlotLib), and a large Python community with major support from big companies such as Google. In comparison to Python, the Ma's are small players in terms of language development.  Thus for Sage most of the problems of language development are handled by someone else.&lt;br /&gt;&lt;br /&gt;The bug tracking done for three of four of the Ma's is currently secret (MATLAB has an open bug tracker, though it requires free registration to view.), which means that there is no published accounting of all known bugs, the status of work on them, and how bugs are resolved.  But the Ma's do have many bugs; see the release notes of each new version, which lists bugs that were fixed.  Sage also has bugs, which are all publicly tracked at &lt;a href="http://trac.sagemath.org/"&gt;the trac server&lt;/a&gt;, and there are numerous ``Bug Days'' workshops devoted entirely to fixing bugs in Sage.  Moreover, all discussion about resolving a given bug, including peer review of solutions, is publicly archived.  We note that sadly even some prize winning free open source systems, such as GAP, do not have an open bug tracking system, resulting in people reporting the same bugs over and over again.&lt;br /&gt;&lt;br /&gt;Each of the Ma's is a combination of secret unchangeable compiled code and less secret interpreted code.  Users with experience programming in compiled languages such as Fortran or C++ may find the loss of a compiler to be frustrating. None of the Ma's has an optimizing compiler that converts programs written in their custom interpreted language to a fast executable binary format that is not interpreted at runtime.  (MATLAB has a   compiler, but  ``the source code is still interpreted at run-time, and performance   of code should be the same whether run in standalone mode or in   MATLAB.''  Mathematica also has a Compile function, but simply   compiles expressions to a different internal format that is   interpreted, much like Sage's &lt;tt&gt;fast_callable&lt;/tt&gt; function.)  In contrast, Sage is tightly integrated with Cython.  The Cython   project has received extensive contributions from Sage developers,   and is very popular in the world of Python-based scientific   computing. Cython is a Python-to-C/C++ compiler that speeds up code execution and has support for statically declaring data types (for potentially enormous speedups) and natively calling existing C/C++/Fortran code.  For example, enter the following in a cell of &lt;a href="http://sagenb.org/"&gt;the Sage notebook&lt;/a&gt;:&lt;br /&gt;&lt;pre&gt;def python_sum2(n):&lt;br /&gt;    s = int(0)&lt;br /&gt;    for i in xrange(1, n+1):&lt;br /&gt;        s += i*i&lt;br /&gt;    return s&lt;br /&gt;&lt;/pre&gt;Then enter the following in another cell:&lt;br /&gt;&lt;pre&gt;%cython&lt;br /&gt;def cython_sum2(long n):&lt;br /&gt;    cdef long i, s = 0&lt;br /&gt;    for i in range(1, n+1):&lt;br /&gt;        s += i*i&lt;br /&gt;    return s&lt;br /&gt;&lt;/pre&gt;The second implementation, despite looking nearly identical, is nearly a hundred times faster than the first one (your timings may vary).&lt;br /&gt;&lt;pre&gt;sage: timeit('python_sum2(2*10^6)')&lt;br /&gt;5 loops, best of 3: 154 ms per loop&lt;br /&gt;sage: timeit('cython_sum2(2*10^6)')&lt;br /&gt;125 loops, best of 3: 1.76 ms per loop&lt;br /&gt;sage: 154/1.76&lt;br /&gt;87.5&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Of course, it is better to choose a different algorithm.  In case you don't remember a closed form expression for the sum of the first $n$ squares, Sage can deduce it:&lt;br /&gt;&lt;pre&gt;sage: var('k, n')&lt;br /&gt;sage: factor(sum(k^2, k, 1, n))&lt;br /&gt;1/6*(n + 1)*(2*n + 1)*n&lt;br /&gt;&lt;/pre&gt;And now our simpler fast implementation is:&lt;br /&gt;&lt;pre&gt;def sum2(n):&lt;br /&gt;    return n*(2*n+1)*(n+1)/6&lt;br /&gt;&lt;/pre&gt;Just as above, we can also use the Cython compiler:&lt;br /&gt;&lt;pre&gt;%cython&lt;br /&gt;def c_sum2(long n):&lt;br /&gt;    return n*(2*n+1)*(n+1)/6&lt;br /&gt;&lt;/pre&gt;Comparing times, we see that Cython is 10 times faster:&lt;br /&gt;&lt;pre&gt;sage: n = 2*10^6&lt;br /&gt;sage: timeit('sum2(n)')&lt;br /&gt;625 loops, best of 3: 1.41 microseconds per loop&lt;br /&gt;sage: timeit('c_sum2(n)')&lt;br /&gt;625 loops, best of 3: 0.145 microseconds per loop&lt;br /&gt;sage: 1.41/.145&lt;br /&gt;9.72413793103448&lt;br /&gt;&lt;/pre&gt;In this case, the enhanced speed comes at a cost, in that the answer is wrong when the input  is large enough to cause an overflow:&lt;br /&gt;&lt;pre&gt;sage: c_sum2(2*10^6)   # WARNING: overflow&lt;br /&gt;-407788678951258603&lt;br /&gt;&lt;/pre&gt;Cython is very powerful, but to fully benefit from it, one must understand machine level arithmetic data types, such as long, int, float, etc.  With Sage you have that option.&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;What is Sage?&lt;/h1&gt;&lt;br /&gt;The goal of Sage is to compete with the Ma's, and the intellectual property at our disposal is the complete range of GPL-compatibly licensed open source software.&lt;br /&gt;&lt;br /&gt;Sage is a self-contained free open source distribution of about 100 open source software packages and libraries that aims to address all computational areas of pure and applied mathematics.  See the &lt;a href="http://sagemath.org/packages/standard/"&gt;list of packages in Sage&lt;/a&gt;, which includes R, Pari, Singular, GAP, Maxima, GSL, Numpy, Scipy, ATLAS, Matplotlib, and many other popular programs.  The download of Sage contains all dependencies required for the normal functioning of Sage, including Python itself.  Sage includes a substantial amount of code that provides a unified Python-based &lt;i&gt;interface&lt;/i&gt; to these other packages.  Sage also includes a library of new code written in Python, Cython and C/C++, which implements a huge range of algorithms.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;History&lt;/h1&gt;&lt;br /&gt;I made the first release of Sage in February 2005, and at the time called it "&lt;b&gt;S&lt;/b&gt;oftware for &lt;b&gt;A&lt;/b&gt;rithmetic &lt;b&gt;G&lt;/b&gt;eometry &lt;b&gt;E&lt;/b&gt;xperimentation."  I was a serious user of, and contributor to, Magma at the time, and was motivated to start Sage for many of the reasons discussed above.  In particular, I was personally frustrated with the top-down closed development model of Magma, the fact that &lt;i&gt;several million lines&lt;/i&gt; of the source code of Magma are closed source, and the fees that my colleagues had to pay in order to use the substantial amount of code that I contributed to Magma.  Despite my early naive hope that Magma would be open sourced, it never was.  So I started Sage motivated by the dream that someday the single most important item of software I use on a daily basis would be free and open. David Joyner, David Kohel, Joe Wetherell, and Martin Albrecht were also involved in the development of Sage during the first year.&lt;br /&gt;&lt;br /&gt;In February 2006, the National Science Foundation funded a 2-day workshop called ``Sage Days 2006'' at UC San Diego, which had about 40 participants and speakers from several open and closed source mathematical software projects.  After doing a year of fulltime mostly solitary work on Sage, I was surprised by the positive reception  of Sage by members of the mathematical research community.  What Sage promised was something many mathematicians wanted.  Whether or not Sage would someday deliver on that promise was (and for many still is) an open question.&lt;br /&gt;&lt;br /&gt;I had decided when I started Sage that I would make it powerful enough for my research, with or without the help of anybody else, and was pleasantly surprised at this workshop to find that many other people were interested in helping, and understood the  shortcomings of existing open source software, such as GAP and PARI, and the longterm need to move beyond Magma. Six months later, I ran another Sage Days workshop, which resulted in numerous talented young graduate students, including David Harvey, David Roe, Robert Bradshaw, and Robert Miller, getting involved in Sage development.  I used startup money from University of Washington to hire Alex Clemesha as a fulltime employee to implement 2d graphics and help create a notebook interface to Sage.  I also learned that there was much broader interest in such a system, and stopped referring to Sage as being exclusively for ``arithmetic geometry''; instead, Sage became ``&lt;b&gt;S&lt;/b&gt;oftware for &lt;b&gt;A&lt;/b&gt;lgebra and &lt;b&gt;G&lt;/b&gt;eometry &lt;b&gt;E&lt;/b&gt;xperimentation.''  Today the acronym is deprecated.&lt;br /&gt;&lt;br /&gt;The year 2007 was a major turning point for Sage.  Far more people got involved with development, we had four Sage Days workshops, and prompted by Craig Citro, we instituted a requirement that all new code must have tests for 100% of the functions touched by that code, and every modification to Sage must be peer reviewed.  Our peer review process is much more open than in mathematical research journals; everything that happens is publicly archived on &lt;a href="http://trac.sagemath.org/"&gt;trac&lt;/a&gt;.  During 2007, I also secured some funding for Sage development from Microsoft Research, Google, and NSF. Also, a German graduate student studying cryptography, Martin Albrecht presented Sage at the Troph'ees du Libre competition in France, and Sage won first place in ``Scientific Software'', which led to a huge amount of good publicity, including articles in many languages around the world and appearances, for example, &lt;a href="http://science.slashdot.org/story/07/12/08/1350258/Open-Source-Sage-Takes-Aim-at-High-End-Math-Software"&gt;this Slashdot article&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;In 2008, I organized 7 Sage Days workshops at places such as IPAM (at UCLA) and the Clay Mathematics Institute, and for the first time, several people besides me made releases of Sage.  In 2009, we had 8 more Sage Days workshops, and the underlying foundations of Sage improved, including development of a powerful coercion architecture. This &lt;i&gt;coercion model&lt;/i&gt; systematically determines what happens when performing operations such as &lt;tt&gt;a + b&lt;/tt&gt;, when &lt;tt&gt;a&lt;/tt&gt; and &lt;tt&gt;b&lt;/tt&gt; are elements of potentially different rings (or groups, or modules, etc.).&lt;br /&gt;&lt;pre&gt;sage: R.&lt;x&gt; = PolynomialRing(ZZ)&lt;br /&gt;    sage: f = x + 1/2; f&lt;br /&gt;    x + 1/2&lt;br /&gt;    sage: parent(f)&lt;br /&gt;    Univariate Polynomial Ring in x over Rational Field&lt;br /&gt;&lt;/x&gt;&lt;/pre&gt;We &lt;a href="http://magma.maths.usyd.edu.au/calc/"&gt;compare this with Magma&lt;/a&gt; (V2.17-4), which has a more ad hoc coercion system:&lt;br /&gt;&lt;pre&gt;&amp;gt; R&lt;x&gt; := PolynomialRing(IntegerRing());&lt;br /&gt;    &amp;gt; x + 1/2&lt;br /&gt;        ^&lt;br /&gt;    Runtime error in '+': Bad argument types&lt;br /&gt;    Argument types given: RngUPolElt[RngInt], FldRatElt&lt;br /&gt;&lt;/x&gt;&lt;/pre&gt;&lt;br /&gt;Robert Bradshaw and I also added support for beautiful browser-based 3D graphics to Sage, which involved writing a 3D graphics library, and adapting the free open source &lt;a href="http://jmol.sourceforge.net/"&gt;JMOL Java library&lt;/a&gt; for rendering molecules to instead plot mathematical objects.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;sage: f(x,y) = sin(x - y) * y * cos(x)&lt;br /&gt;    sage: plot3d(f, (x,-3,3), (y,-3,3), color='red')&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In 2009, following a huge amount of porting work by Mike Hansen, development of algebraic combinatorics in Sage picked up substantial momentum, with the switch of the entire MuPAD-combinat group to Sage (forming &lt;a href="http://wiki.sagemath.org/combinat"&gt;sage-combinat&lt;/a&gt;), only months before the formerly free system MuPAD{\textregistered}\footnote{MuPAD is a   registered trademark of SciFace Software GmbH \&amp;amp; Co.} was bought out by Mathworks (makers of MATLAB).  In addition to work on Lie theory by Dan Bump, this also led to a massive amount of work on a category theoretic framework for Sage by Nicolas Thiery.&lt;br /&gt;&lt;br /&gt;In 2010, there were 13 Sage Days workshops in many parts of the world, and grant funding for Sage significantly improved, including new NSF funding for undergraduate curriculum development.  I also spent much of my programming time during 2010--2011 developing a number theory library called &lt;a href="http://code.google.com/p/purplesage/"&gt;psage&lt;/a&gt;, which is currently not included in Sage, but can be easily installed.&lt;br /&gt;&lt;br /&gt;Many aspects of Sage make it an ideal tool for teaching mathematics, so there's a steadily growing group of teachers using it: for example, there have been MAA PREP workshops on Sage for the last two years, and a third is likely to run next summer, there are regular posts on the Sage lists about setting up classroom servers, and there is an NSF-funded project called &lt;a href="http://utmost.aimath.org/"&gt;UTMOST&lt;/a&gt; devoted to creating undergraduate curriculum materials for Sage.&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://%20sagemath.org/library-publications.html"&gt;publications page&lt;/a&gt; lists 101 accepted publications that use Sage, 47 preprints, 22 theses, and 16 books, and there are surely many more ``in the wild'' that we are not aware of.  According to Google Analytics, the main Sage website gets about 2,500 absolute unique visitors per day, and the website &lt;a href="http://sagenb.org/"&gt;http://sagenb.org&lt;/a&gt;, which allows anybody to easily use Sage through their web browser, has around 700 absolute unique visitors per day.&lt;br /&gt;&lt;br /&gt;For many mathematicians and students, Sage is today the mature, open source, and free foundation on which they can build their research program.</description><link>http://sagemath.blogspot.com/2011/08/sage-creating-viable-free-open-source.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-7152308699518631850</guid><pubDate>Mon, 15 Nov 2010 17:15:00 +0000</pubDate><atom:updated>2010-11-19T08:57:32.648-08:00</atom:updated><title>Brief History and Motivation Behind the Sage Coercion Model</title><description>In Sage (like in Magma), most objects are either elements or parents. Think of a "parent" as a set.   This Parent/Element idea is a powerful algebraic approach to implementing mathematical objects on a computer, which does not exist in Mathematica, Maple, PARI, Maxima, and many other math software platforms. &lt;br /&gt;&lt;br /&gt;I learned about this approach from using Magma:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;%magma&lt;br /&gt;R&amp;lt;x&gt; := PolynomialRing(Integers());&lt;br /&gt;print Parent(x);&lt;br /&gt;///&lt;br /&gt;Univariate Polynomial Ring in x over Integer Ring&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;(In this blog post I'll put %magma above code that gets input to Magma; all other code gets input to Sage.  The input and output is separated by ///.)&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In Sage:&lt;/p&gt;&lt;pre&gt;R.&amp;lt;x&gt; = ZZ[]&lt;br /&gt;parent(x)&lt;br /&gt;///&lt;br /&gt;Univariate Polynomial Ring in x over Integer Ring&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre&gt;x.parent()&lt;br /&gt;///&lt;br /&gt;Univariate Polynomial Ring in x over Integer Ring&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;isinstance(ZZ, Parent)&lt;br /&gt;///&lt;br /&gt;True&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre&gt;isinstance(2, Parent)&lt;br /&gt;///&lt;br /&gt;False&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Automatic Coercions:&lt;/p&gt;&lt;p&gt;&lt;em&gt;"The primary goal of coercion is to be able to transparently do arithmetic, comparisons, etc. between elements of distinct parents."&lt;/em&gt;&lt;/p&gt;&lt;p&gt;When I used to try to get people to use Magma, perhaps the number one complaint I heard about Magma was that doing arithmetic with objects having distinct parents was difficult and frustrating.&lt;/p&gt;&lt;p&gt;For the &lt;strong&gt;first year&lt;/strong&gt;, in Sage, there was a very simple coercion system:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;If you try to compute a + b or a * b, first somehow put b into the parent of a, then do the arithmetic.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;That seriously sucked. &amp;nbsp;E.g.,&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;strong&gt;Mod(2,7) + 6&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;was completely different than&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;strong&gt;6 + Mod(2,7)&lt;/strong&gt;!&lt;/p&gt;&lt;p&gt;The first was Mod(1,7), and the second was the integer 8. &amp;nbsp; This makes understanding code difficult and unpredictable.&lt;/p&gt;&lt;p&gt;So I rewrote coercion to be a bit better (this was a really painful rewrite that I mostly did myself over several hard months of work):&lt;/p&gt;&lt;ul&gt;&lt;li&gt;If you try to compute a + b (or a*b), check for a "&lt;strong&gt;canonical coercions"&lt;/strong&gt; from the parent of a into b, or failing that, from the parent of b into a. &amp;nbsp;If there aren't any raise an error. &amp;nbsp;If there is one, use it. &amp;nbsp;There won't be both unless there is some canonical isomorphism.&amp;nbsp;&lt;/li&gt;&lt;li&gt;There are some axioms about what a canonical coercion is. &amp;nbsp;At least it is homomorphism.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Then we decided that there is a canonical homomorphism Z --&gt; Z/7Z, but there is not one Z/7Z --&gt; Z since there is no  ring homomorphism in this direction, hence the above makes sense in either order. &amp;nbsp;&lt;/p&gt;&lt;p&gt;One implication of this new model was that parent objects have to be immutable, i.e., you can't fundamentally change them after you make them. &amp;nbsp;This is why in Sage you must specify the name of the generator of a polynomial ring at creation time, and can't change it. &amp;nbsp;In Magma, it is typical to specify the name only later if you want.&lt;/p&gt;&lt;p&gt;Objects must be immutable because the canonical maps between them depend on the objects themselves, and we don't want them to just change left and right at runtime.&amp;nbsp;&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;%magma&lt;br /&gt;R := PolynomialRing(RationalField(), 2);&lt;br /&gt;f := R.1^3 + 3*R.2^3 - 4/5;&lt;br /&gt;print f;&lt;br /&gt;///&lt;br /&gt;$.1^3 + 3*$.2^3 - 4/5&lt;br /&gt;[ $.1, $.2 ]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre&gt;%magma&lt;br /&gt;AssignNames(~R, ["x", "y"]);&lt;br /&gt;print f;&lt;br /&gt;[R.1, R.2]&lt;br /&gt;///&lt;br /&gt;x^3 + 3*y^3 - 4/5&lt;br /&gt;[x, y]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre&gt;%magma&lt;br /&gt;AssignNames(~R, ["z", "w"]);&lt;br /&gt;print f;&lt;br /&gt;///&lt;br /&gt;z^3 + 3*w^3 - 4/5&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now in Sage:&lt;br /&gt;&lt;pre&gt;R = PolynomialRing(QQ)&lt;br /&gt;///&lt;br /&gt;TypeError: You must specify the names of the variables.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre&gt;R.&amp;lt;x,y&gt; = PolynomialRing(QQ)&lt;br /&gt;f = x^3 + 3*y^3 - 4/5; f&lt;br /&gt;///&lt;br /&gt;x^3 + 3*y^3 - 4/5&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Note: In Sage, you can can use a &lt;strong&gt;with block&lt;/strong&gt; to temporarily change the names if you &lt;strong&gt;&lt;em&gt;really&lt;/em&gt;&lt;/strong&gt; need to for some reason. &amp;nbsp;This is allowed since at the end of the with block the names are guaranteed to be changed back.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;with localvars(R, ['z','w']):&lt;br /&gt;    print f&lt;br /&gt;print "back?", f    &lt;br /&gt;///&lt;br /&gt;z^3 + 3*w^3 - 4/5&lt;br /&gt;back? x^3 + 3*y^3 - 4/5&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;But this new model had a major problem too, e.g.,&amp;nbsp;if x in Z[x] then "x + 1/2" would FAILS! &amp;nbsp; This is because 1/2 does not coerce into Z[x] (the parent of x), and x does not coerce into Q (the parent of 1/2).  &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Maybe the implementors of Magma have the answers? &amp;nbsp;Evidently not.&amp;nbsp;&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;%magma&lt;br /&gt;R&amp;lt;x&gt; := PolynomialRing(Integers());&lt;br /&gt;x + 1/2;&lt;br /&gt;///&lt;br /&gt;Runtime error in '+': Bad argument types&lt;br /&gt;Argument types given: RngUPolElt[RngInt], FldRatElt&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Robert Bradshaw did though, and now it is in Sage:&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;R.&amp;lt;x&gt; = ZZ[]&lt;br /&gt;x + 1/2&lt;br /&gt;///&lt;br /&gt;x + 1/2&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;His new design is (for the most part) what Sage actually uses now.&lt;/p&gt;&lt;p&gt;He launched an effort in 2008 (see the &lt;a href="http://wiki.sagemath.org/dev1"&gt;Dev Days 1 Wiki&lt;/a&gt;) to implement a rewrite of the coercion model to his new design. &amp;nbsp;This ended up swallowing up half the development effort at the workshop, and was a massive amount of work, since &lt;em&gt;&lt;strong&gt;every&lt;/strong&gt;&lt;/em&gt; parent structure and element had to have some modifications made to it.&amp;nbsp;&lt;/p&gt;&lt;p&gt;This meant people changing a lot of code all over Sage that they didn't necessarily understand, and crossing their fingers that the doctest test suite would catch their mistakes. &amp;nbsp; &amp;nbsp;This was SCARY. &amp;nbsp; After much work, none of this went into Sage. &amp;nbsp;It was just way too risky. &amp;nbsp;This failure temporarily (!) burned out some developers.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Robert Bradshaw, on the other hand, persisted and came up with a new approach that involved migrating Sage code gradually. &amp;nbsp;I.e., he made it so that the old coercion model was still fully supported simultaneously with the new one, then he migrated a couple of parent structures, and got the code into Sage. &amp;nbsp; I'm sure not everything is migrated, even today. &amp;nbsp;There are two points to what he did:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;He extended the rules so x + 1/2 works, i.e., the result of a+b need not live in the parent of a or the parent of b.&lt;/li&gt;&lt;li&gt;He made implementing coercion much more top down: simply implement various methods in a class that derives from Parent. &amp;nbsp;This meant that instead of coercion being rules and conventions that people have to understand and implement in their own code all over Sage, they just implement a small amount of code and the rules (and benefits) are all enforced automatically.&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;The Coercion Model&lt;/h2&gt;&lt;p&gt;The coercion model is explained here: &lt;a href="http://sagemath.org/doc/reference/coercion.html"&gt;http://sagemath.org/doc/reference/coercion.html&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description><link>http://sagemath.blogspot.com/2010/11/brief-history-and-motivation-behind.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-7700467219409095078</guid><pubDate>Mon, 08 Nov 2010 18:05:00 +0000</pubDate><atom:updated>2010-11-08T14:44:34.101-08:00</atom:updated><title>Getting Started With Cython</title><description>&lt;h1&gt;Getting Started With Cython&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Quote about Cython:&lt;/h2&gt;&lt;a href="http://news.ycombinator.com/item?id=1212790"&gt;Andrew Tipton&lt;/a&gt;&amp;nbsp;says&amp;nbsp;&lt;i&gt;"I'm honestly never going back to writing C again. Cython gives me all the expressiveness of Python combined with all the performance and close-to-the-metal-godlike-powers of C. I've been using it to implement high-performance graph traversal and routing algorithms and to interface with C/C++ libraries, and it's been an absolute amazing productivity boost.&lt;/i&gt;" &amp;nbsp;Yep.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Cython has two major use cases&lt;/h2&gt;&lt;ol&gt;&lt;li&gt; Extending the CPython interpreter with fast compiled modules,&lt;/li&gt;&lt;li&gt; Interfacing Python code with external C/C++ libraries. &lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;h2&gt;Cython supports type declarations&lt;/h2&gt;&lt;ol&gt;&lt;li&gt; For changing code from having dynamic Python semantics  into having static-and-fast (but less generic) C semantics.&lt;/li&gt;&lt;li&gt; Directly manipulating C data types defined in external libraries.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;h2&gt;Tutorial: Building Your First Cython Code by Hand&lt;/h2&gt;It happens in two stages:&lt;br /&gt;&lt;ol&gt;&lt;li&gt; A &lt;tt&gt;.pyx&lt;/tt&gt; file is compiled by Cython to a &lt;tt&gt;.c&lt;/tt&gt; or &lt;tt&gt;.cpp&lt;/tt&gt; file.&lt;br /&gt;&lt;/li&gt;&lt;li&gt; The &lt;tt&gt;.c&lt;/tt&gt; or &lt;tt&gt;.cpp&lt;/tt&gt; file is compild by a C compiler (such as GCC) to a &lt;tt&gt;.so&lt;/tt&gt; file. &lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;b&gt;Let's try it now:&lt;/b&gt;&lt;br /&gt;First, create a file &lt;tt&gt;sum.pyx&lt;/tt&gt; that contains the following code (see t&lt;a href="http://wstein.org/edu/2010/581d/notes/2010-11-08/"&gt;his directory for original code files&lt;/a&gt;): &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;def sum_cython(long n):&lt;br /&gt;    cdef long i, s = 0&lt;br /&gt;    for i in range(n):&lt;br /&gt;        s += i&lt;br /&gt;    return s&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;b&gt;Then use Cython to compile it:&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;Since we're using Sage, you can do &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;bash$ sage -cython sum.pyx&lt;br /&gt;bash$ ls&lt;br /&gt;sum.c  sum.pyx&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;Notice the new file &lt;tt&gt;sum.c&lt;/tt&gt;.  Compile it with &lt;tt&gt;gcc&lt;/tt&gt; as follows on &lt;b&gt;OS X&lt;/b&gt;: &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;bash$ sage -sh&lt;br /&gt;bash$ gcc -I$SAGE_ROOT/local/include/python2.6 -bundle -undefined dynamic_lookup sum.c -o sum.so &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;On &lt;b&gt;Linux&lt;/b&gt;, do: &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;bash$ sage -sh&lt;br /&gt;bash$ gcc -I$SAGE_ROOT/local/include/python2.6 -shared -fPIC sum.c -o sum.so&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;b&gt;Finally, try it out.&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;You must run Sage from the same directory that contains the file &lt;tt&gt;sum.so&lt;/tt&gt;.  When you type &lt;tt&gt;import sum&lt;/tt&gt; below, the Python interpreter sees the file &lt;tt&gt;sum.so&lt;/tt&gt;, opens it, and it contains functions and data that define a compiled "Python C-extension module", so Python can load it (like it would like a module like &lt;tt&gt;sum.py&lt;/tt&gt;). &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;bash$ sage&lt;br /&gt;-------------------------------------------------&lt;br /&gt;| Sage Version 4.6, Release Date: 2010-10-30     &lt;br /&gt;| Type notebook() for the GUI, and license() for&lt;br /&gt;-------------------------------------------------&lt;br /&gt;sage: import sum&lt;br /&gt;sage: sum.sum_cython(101)&lt;br /&gt;5050&lt;br /&gt;sage: timeit('sum.sum_cython(101)')&lt;br /&gt;625 loops, best of 3: 627 ns per loop&lt;br /&gt;sage: timeit('sum.sum_cython(101)', number=10^6)    # better quality timing&lt;br /&gt;1000000 loops, best of 3: 539 ns per loop&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Finally, take a look at the (more than 1000 line) autogenerated C file &lt;tt&gt;sum.c&lt;/tt&gt;: &lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;bash$ wc -l sum.c&lt;br /&gt;    1178 sum.c&lt;br /&gt;bash$ less sum.c&lt;br /&gt;&lt;/pre&gt;...&lt;br /&gt;&lt;br /&gt;Notice code like this, which illustrates that Cython generates code that supports &lt;em&gt;both&lt;/em&gt; Python2 and Python3: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;#if PY_MAJOR_VERSION &amp;lt; 3&lt;br /&gt;  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"&lt;br /&gt;#else&lt;br /&gt;  #define __Pyx_BUILTIN_MODULE_NAME "builtins"&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;#if PY_MAJOR_VERSION &amp;gt;= 3&lt;br /&gt;  #define Py_TPFLAGS_CHECKTYPES 0&lt;br /&gt;  #define Py_TPFLAGS_HAVE_INDEX 0&lt;br /&gt;#endif&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;The &lt;a href="http://docs.python.org/release/2.6/howto/cporting.html"&gt;official Python docs&lt;/a&gt; say: "If you are writing a new extension module, you might consider Cython. It translates a Python-like language to C. The extension modules it creates are compatible with Python 3.x and 2.x."  &lt;br /&gt;&lt;br /&gt;If you scroll down further you'll get past the boilerplate and see the actual code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;...&lt;br /&gt;  /* "/Users/wstein/edu/2010-2011/581d/notes/2010-11-08/sum.pyx":2&lt;br /&gt; * def sum_cython(long n):&lt;br /&gt; *     cdef long i, s = 0             # &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;br /&gt; *     for i in range(n):&lt;br /&gt; *         s += i&lt;br /&gt; */&lt;br /&gt;  __pyx_v_s = 0;&lt;br /&gt;&lt;br /&gt;  /* "/Users/wstein/edu/2010-2011/581d/notes/2010-11-08/sum.pyx":3&lt;br /&gt; * def sum_cython(long n):&lt;br /&gt; *     cdef long i, s = 0&lt;br /&gt; *     for i in range(n):             # &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;br /&gt; *         s += i&lt;br /&gt; *     return s&lt;br /&gt; */&lt;br /&gt;  __pyx_t_1 = __pyx_v_n;&lt;br /&gt;  for (__pyx_t_2 = 0; __pyx_t_2 &amp;lt; __pyx_t_1; __pyx_t_2+=1) {&lt;br /&gt;    __pyx_v_i = __pyx_t_2;&lt;br /&gt;&lt;br /&gt;    /* "/Users/wstein/edu/2010-2011/581d/notes/2010-11-08/sum.pyx":4&lt;br /&gt; *     cdef long i, s = 0&lt;br /&gt; *     for i in range(n):&lt;br /&gt; *         s += i             # &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;br /&gt; *     return s&lt;br /&gt; */&lt;br /&gt;    __pyx_v_s += __pyx_v_i;&lt;br /&gt;  }&lt;br /&gt;...&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;There is a big comment that shows the original Cython code with context and a little arrow&lt;span class="Apple-style-span" style="font-family: monospace;"&gt;&amp;nbsp;&lt;/span&gt;pointing at the current line (these comment blocks with context were I think the first thing I personally added to Pyrex... before, it just gave that first line with the .pyx filename and line number, but nothing else).  Below that big comment, there is the actual C code that Cython generates.  For example, the Cython code &lt;tt&gt; s += i&lt;/tt&gt; is turned into the C code &lt;tt&gt;__pyx_v_s += __pyx_v_i;&lt;/tt&gt;.  &lt;br /&gt;&lt;h2&gt;&lt;br /&gt;&lt;/h2&gt;&lt;h2&gt;The Same Extension From Scratch, for Comparison&lt;/h2&gt;If you read &lt;a href="http://docs.python.org/extending/"&gt;Extending and Embedding Python&lt;/a&gt; you'll see how you could write a C extension module from scratch that does the same thing as sum.so above.   Let's see what this is like, for comparison.  Given how simple sum.pyx is, this isn't so hard.  When creating more complicated Cython code---e.g., new extension classes, more complicated type conversions, and memory management---writing C code directly quickly becomes unwieldy.   &lt;br /&gt;First, create a file &lt;tt&gt;sum2.c&lt;/tt&gt; as follows:  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;#include &amp;lt;Python.h&amp;gt;&lt;br /&gt;&lt;br /&gt;static PyObject * &lt;br /&gt;sum2_sum_c(PyObject *self, PyObject *n_arg)&lt;br /&gt;{&lt;br /&gt;    long i, s=0, n = PyInt_AsLong(n_arg);&lt;br /&gt;    &lt;br /&gt;    for (i=0; i&amp;lt;n; i++)  {&lt;br /&gt; s += i;&lt;br /&gt;    }&lt;br /&gt;    PyObject* t = PyInt_FromLong(s);&lt;br /&gt;    return t;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static PyMethodDef Sum2Methods[] = {&lt;br /&gt;    {"sum_c", sum2_sum_c, METH_O, "Sum the numbers up to n."},&lt;br /&gt;    {NULL, NULL, 0, NULL} /* Sentinel */&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;PyMODINIT_FUNC&lt;br /&gt;initsum2(void)&lt;br /&gt;{&lt;br /&gt;    PyObject *m;&lt;br /&gt;    m = Py_InitModule("sum2", Sum2Methods);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;Now compile and run it as before: &lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;bash$ sage -sh&lt;/pre&gt;&lt;pre&gt;bash$ gcc -I$SAGE_ROOT/local/include/python2.6 -bundle -undefined dynamic_lookup sum2.c -o sum2.so &lt;br /&gt;bash$ sage&lt;br /&gt;...&lt;br /&gt;sage: import sum2&lt;br /&gt;sage: sum2.sum_c(101)&lt;br /&gt;5050&lt;br /&gt;sage: import sum&lt;br /&gt;sage: sum.sum_cython(101)&lt;br /&gt;5050&lt;br /&gt;sage: timeit('sum.sum_cython(1000000r)')&lt;br /&gt;125 loops, best of 3: 2.54 ms per loop&lt;br /&gt;sage: timeit('sum2.sum_c(1000000r)')&lt;br /&gt;125 loops, best of 3: 2.03 ms per loop&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;Note that this is a little faster than the corresponding Cython code. This is because the Cython code is more careful, checking various error conditions, etc.  &lt;br /&gt;&lt;br /&gt;Note that the C code is 5 times as long as the Cython code.  &lt;br /&gt;&lt;h2&gt;Building Extensions using Setuptools Instead&lt;/h2&gt;In nontrivial projects, the Cython step of transforming your code from .pyx to .c is typically done by explicitly calling cython somehow (this will change in the newest version of Cython), but the step of running the C compiler is usually done using either distutils or setuptools.  To use the tools, one creates a file "setup.py" which defines the extensions in your project, and Python itself then runs a C compiler for you, with the proper options, includes paths, etc.  &lt;br /&gt;&lt;br /&gt;Let's create a new setuptools project that includes the sum and sum2 extensions that we defined above.  First, create the following file and call it &lt;tt&gt;setup.py&lt;/tt&gt;. This should be in the same directory as sum.c and sum2.c. &lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;from setuptools import setup, Extension&lt;br /&gt;&lt;br /&gt;ext_modules = [&lt;br /&gt;    Extension("sum", ["sum.c"]),&lt;br /&gt;    Extension("sum2", ["sum2.c"])&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;setup(&lt;br /&gt;    name = 'sum',&lt;br /&gt;    version = '0.1',&lt;br /&gt;    ext_modules = ext_modules)&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;Then type &lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;bash$ rm *.so  # make sure something happens&lt;br /&gt;bash$ sage setup.py develop&lt;br /&gt;...&lt;br /&gt;bash$ ls *.so&lt;br /&gt;sum.so sum2.so&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Notice that running &lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;setup.py develop&lt;/pre&gt;&lt;br /&gt;resulted in Python generating the right gcc commmand lines for your platform.  You don't have to do anything differently on Linux, OS X, etc.   &lt;br /&gt;&lt;br /&gt;If you change &lt;tt&gt;sum2.c&lt;/tt&gt;, and want to rebuild it, just type &lt;tt&gt;sage setup.py develop&lt;/tt&gt; again to rebuild &lt;tt&gt;sum2.so&lt;/tt&gt; If you change &lt;tt&gt;sum.pyx&lt;/tt&gt;, you have to manually run Cython: &lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;sage -cython sum.pyx&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;then again do &lt;tt&gt;sage setup.py develop&lt;/tt&gt; to rebuild sum.so. Try this now. In sum.pyx, change &lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;for i in range(n):&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;to &lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;for i in range(1,n+1):&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;then rebuild: &lt;br /&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;bash$ sage -cython sum.pyx&lt;br /&gt;...&lt;br /&gt;bash$ sage setup.py develop&lt;br /&gt;...&lt;br /&gt;bash$ sage&lt;br /&gt;...&lt;br /&gt;sage: import sum&lt;br /&gt;sage: sum.sum_cython(100)&lt;br /&gt;5050&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;There are ways to make setup.py automatically notice when sum.pyx changes, and run Cython.  A nice implementation of this will be in the next Cython release.   See the setup.py and build_system.py files  &lt;a href="http://code.google.com/p/purplesage/source/browse/"&gt;of Purple sage&lt;/a&gt; for an example of how to write a little build system write now (before the new version of Cython).  &lt;br /&gt;&lt;h2&gt;An Automated Way to Experiment&lt;/h2&gt;Given any single Cython file such as &lt;tt&gt;sum.pyx&lt;/tt&gt;, in Sage you can do &lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;sage: load sum.pyx&lt;br /&gt;Compiling sum.pyx...&lt;br /&gt;sage: sum_cython(100)&lt;br /&gt;5050&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;Behind the scenes, Sage created a setup.py file, ran Cython, made a new module, compiled it, and imported everything it defines into the global namespace.   If you look in the spyx subdirectory of the directory listed below, &lt;b&gt;&lt;i&gt;before&lt;/i&gt;&lt;/b&gt; you exit Sage (!), then you'll see all this. &lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;sage: SAGE_TMP&lt;br /&gt;'/Users/wstein/.sage//temp/deep.local/14837/'&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You can also do  &lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;sage: attach sum.pyx&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then every time sum.pyx changes, Sage will notice this and reload it. This can be useful for development of small chunks of Cython code.  &lt;br /&gt;&lt;br /&gt;You can also use the Sage notebook, and put &lt;tt&gt;%cython&lt;/tt&gt; as the first line of a notebook cell.  The rest of the cell will be compiled exactly as if it were written to a &lt;tt&gt;.pyx&lt;/tt&gt; file and loaded as above.  In fact, that is almost exactly what happens behind the scenes.  &lt;br /&gt;&lt;h2&gt;Next Time&lt;/h2&gt;Now that we understand at a reasonably deep level what Cython really is and does, it is time to learn about the various constructs of the language: &lt;br /&gt;&lt;ol&gt;&lt;li&gt; How to create extension classes using Cython. &lt;/li&gt;&lt;li&gt; How to call external C/C++ library code.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;We will rewrite our sum.pyx file first to use a class.  Then we'll rewrite it again to make use of the MPIR (or GMP) C library for arithmetic, and again to make use of the C++ NTL library.</description><link>http://sagemath.blogspot.com/2010/11/getting-started-with-cython.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-2004035015265016155</guid><pubDate>Wed, 03 Nov 2010 16:54:00 +0000</pubDate><atom:updated>2010-11-03T09:54:55.857-07:00</atom:updated><title>Cython, Sage, and the Need for Speed</title><description>Cython seriously rocks, at least for much of what I need.  It's still the killer feature of Python/Sage, IMHO.  And meetings like EuroScipy last summer really confirmed that, where almost every other talk used Cython.  &lt;br /&gt;&lt;br /&gt;&lt;h2&gt;History&lt;/h2&gt;&lt;br /&gt;Greg Ewing wrote "Pyrex" in 2002--2004..., which I guess he named&lt;br /&gt;after some cooking ware.  It is amazing, but to understand this you&lt;br /&gt;must take a quick tour of &lt;a href="http://docs.python.org/extending/"&gt;Extending and embedding&lt;/a&gt; and the &lt;a href="http://docs.python.org/c-api/"&gt;Python/C API reference&lt;/a&gt;. Pyrex let you write basically Python-ish code that gets magically turned into C extension code. &lt;br /&gt;&lt;br /&gt;In 2007 I forked it (discuss why briefly) and named Cython after &lt;a href="http://cython.livejournal.com/"&gt;this punk rock guy&lt;/a&gt;.&lt;br /&gt;            &lt;br /&gt;At that time, Robert Bradshaw and Stefen Behnel spent a lot of time improving Cython, implementing tons of _optimizations_ and new features.&lt;br /&gt;&lt;br /&gt;Cython is now very popular in the "Scientific computing using Python" world.  It is also heavily used in Sage. &lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Are You Serious?&lt;/h2&gt;If you want to use a computer for math research, and you are serious (not some lazy person who fiddles then gives up), you will likely run into situations where you need code to run fast.  Writing such code only in Python (or any other interpreter) is often impossible.&lt;br /&gt;&lt;br /&gt;If you want to write fast code on a computer, and don't want to mess with assembler, the only option right now is C, or something with equivalent speed... Cython!  By "fast" I mean 100-1000 times what you'll get out of Python on certain tasks.  I also mean code that is evil, scary, and dangerous... if you aren't careful with preconditions.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Compiled versus Interpreted Code&lt;/h2&gt;Here's how interpreter code usually runs.&lt;br /&gt;&lt;pre&gt;    1. Check a bunch of conditions then do one single thing.&lt;br /&gt;    2. Check a bunch of conditions then do one single thing.&lt;br /&gt;    ...&lt;br /&gt;    10^6. Check a bunch of conditions then do one single thing.&lt;br /&gt;&lt;/pre&gt;Here's how compiled (C, Cython, etc.) can can be written:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    1. Check some conditions (optional, but a good idea);&lt;br /&gt;    2. Do very unsafe stuff with no checks at all (but they &lt;br /&gt;       in theory should be safe given 1).&lt;br /&gt;    ...&lt;br /&gt;    10^6. Do very unsafe stuff with no checks at all (but they &lt;br /&gt;       in theory should be safe given 1).&lt;br /&gt;&lt;/pre&gt;The problem is that all the checks in step 1 (in either case) can easily take over 100 times as long as "do very unsafe stuff".&lt;br /&gt;&lt;br /&gt;TYPICAL EXAMPLE:&lt;br /&gt;&lt;pre&gt;sage: def sum_sage(n):&lt;br /&gt;...       s = 1&lt;br /&gt;...       for i in range(n):&lt;br /&gt;...           s += i&lt;br /&gt;...       return s&lt;br /&gt;sage: timeit('sum_sage(100000r)')&lt;br /&gt;5 loops, best of 3: 84.6 ms per loop&lt;br /&gt;sage: %python&lt;br /&gt;sage: def sum_python(n):&lt;br /&gt;...       s = 1&lt;br /&gt;...       for i in range(n):&lt;br /&gt;...           s += i&lt;br /&gt;...       return s    &lt;br /&gt;sage: 84.6/5.88&lt;br /&gt;14.3877551020408&lt;br /&gt;sage: timeit('sum_python(100000r)')&lt;br /&gt;125 loops, best of 3: 5.88 ms per loop&lt;br /&gt;sage: %cython&lt;br /&gt;sage: def sum_cython(int n):&lt;br /&gt;...       cdef int i, s = 1&lt;br /&gt;...       for i in range(n):&lt;br /&gt;...           s += i&lt;br /&gt;...       return s&lt;br /&gt;sage: timeit('sum_cython(100000r)')&lt;br /&gt;625 loops, best of 3: 61.6 µs per loop&lt;br /&gt;sage: 5.88 / 0.061&lt;br /&gt;96.3934426229508   &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Let me explain what's going in the above.  How, e.g., in the first one (sum_sage), the program is doing a sort of monologue: "I have to add a Python int to a Sage int.  I don't have any code to do that directly (that would get too complicated, and they are so big and complicated and different objects, and they might change, oh my).  So I'll convert the Python int to Sage int, because that's the only conversion I know. OK, I do that via (it used to be base 10 string parsing!) some code Gonzalo Tornaria wrote that is scary complicated... and once that is done, I got my new MPIR-based Sage integer, which I think add to s. The addition takes some memory that points to the two MPIR integers, and since Python numbers are supposed to be immutable, I make yet another MPIR number (wrapped in a Python object), which is the result of asking MPIR to add them.  MPIR numbers are also very complicated objects, involving stuff like limbs, and C structs, which hardly anybody fully understands.  Despite these integers happening to be small, there is still quite some overhead in the addition, but it happens (taking a small fraction of the total runtime).  Then we move on to the next step in the loop!"&lt;br /&gt;&lt;br /&gt;With sum_python, the loop is similar, but MPIR isn't involved, and there are no conversions.  This buys a 14-fold speedup.  But it is still not super fast, since many new Python objects get created, the code is for "potentially huge integers", hence a potentially complicated data structure has to be checked for, etc.   &lt;br /&gt;&lt;br /&gt;With sum_cython, the integers are only C ints, which are a 32 or 64-bit location in memory.  Doing "s += i" just modifies in place that position in memory.  There's no conversions or type checks done at all at run time.  It's really fast... 1386 times faster than the first version!!!&lt;br /&gt;&lt;br /&gt;Key point: If you truly understand what is going on, you'll see that this isn't Sage being fundamentally broken.  Instead, you'll hopefully be able to look at a block of Sage code and have a clue about how to figure out what it is really doing in order to see whether writing a new implementation of the same algorithm using Cython (which will likely mean directly working with C level data structures) is likely to give you a big speedup.  If you look at the innermost statement in a loop, and there's a big monologue about what is really going on, then you might get a 1000-fold speedup by using Cython.  &lt;br /&gt;&lt;br /&gt;In mathematics, general theorems -- once we have them -- are almost always much better than proofs of special cases. In math, proving a special case can often seem more awkward and unnatural than proving the general case (e.g., how would you proof that ever integer of the form a^2 + 7*a + 5 factors uniquely as a product of primes!?).  With general theorems in math, the statements are often simple and clear so applying them is easier than applying theorems that are only about some very special case, which has often more elaborate hypothesis.  In mathematics, usually a general theorem is simply all around much better than a theorem about some very special cases (especially if both are available). &lt;br /&gt;&lt;br /&gt;In contrast, when writing computer programs, algorithms to solve very general cases of problems often have significant drawbacks in terms of speed (and sometimes complexity) over algorithms for special cases. Since you are mathematicians, you should constantly guard against your instincts from math research which can point you in exactly the wrong direction for writing very fast code.  Often implementations of very general algorithms _are_ easier to understand, and are much less buggy than a bunch of implementations of special cases.  However, there are also usually very severe performance penalties in implementing only the general case.    Watch out.  &lt;br /&gt;&lt;br /&gt;A huge part of understanding the point of Cython for writing fast math code is that you must accept that you're going to write a lot of "ugly" (from a mathematicians perspective) code that only deals with special cases. But it's beautiful from the perspective of somebody who absolutely needs fast code for a specific research application; your fast code can lead to whole new frontiers of research.&lt;br /&gt;&lt;br /&gt;Continuing the example from above:&lt;br /&gt;&lt;pre&gt;sage: sum_python(10^8)&lt;br /&gt;4999999950000001&lt;br /&gt;sage: sum_cython(10^8)&lt;br /&gt;887459713&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Yep, we just implemented only a special case in Cython!&lt;br /&gt;&lt;br /&gt;---------------&lt;br /&gt;&lt;br /&gt;Useful things to do if you want Cython enlightenment (all at once, no order):&lt;br /&gt;&lt;ul&gt;&lt;li&gt; Definitely read/skim &lt;a href="http://docs.python.org/extending/"&gt;Extending&lt;/a&gt; and try all   examples.  This is critical if you want to understand Cython with any depth at all.  Don't think: I don't need to know any of this, because I have Cython.  Yes, after you play with this a bit you may never explicitly use it.  But you do need to know it.  &lt;/li&gt; &lt;li&gt; Oh, definitely learn the C language if you haven't already.  This is &lt;br /&gt;&lt;a href="http://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628"&gt;the book&lt;/a&gt;. There are courses.  It's crazy not to learn C, anyways, since it (along with C++) is hugely popular, and a massive amount of code is written in C/C++.  (See, e.g., http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html where C and C++ together are the most popular, by a long margin.)&lt;br /&gt;&lt;br /&gt;&lt;li&gt; Obviously, read &lt;a href="http://docs.cython.org/"&gt;http://docs.cython.org/&lt;/a&gt; until it is burned into  your brain.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt; Look at the code that Cython generates (use "cython -a" for a nice  HTML view). &lt;br /&gt;&lt;/ul&gt;</description><link>http://sagemath.blogspot.com/2010/11/cython-sage-and-need-for-speed.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-154695821094904706</guid><pubDate>Mon, 01 Nov 2010 05:23:00 +0000</pubDate><atom:updated>2010-11-01T16:00:05.888-07:00</atom:updated><title>How to Referee Sage Trac Tickets</title><description>The current workflow and tools for peer review in Sage are not perfect, and it's clear they can be improved in many ways.  However, the current system is also stable and works well, and though it will surely evolve over time, it is well worth learning.  This post is about the current Sage peer review workflow.  I will restrict my discussion to tickets that involve the Sage library, not standard or optional packages or other scripts not in the Sage library.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Why Referee a Ticket?&lt;/h2&gt;There are a couple of reasons that you might referee a ticket:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;You want to contribute to Sage development, but don't know where to start.  There's a list &lt;a target="_new" href="http://trac.sagemath.org/sage_trac/report/30"&gt;right here of about 200 tickets&lt;/a&gt; (sorted by component) that need review, and probably some require only background you know something about.&lt;br /&gt;&lt;br /&gt;&lt;li&gt; You want a specific chunk of code to get into Sage that somebody else wrote. If you care about this code, you are probably qualified to review it.&lt;br /&gt;&lt;br /&gt;&lt;li&gt; Somebody asked you to review a certain ticket, perhaps in exchange for them reviewing one of your tickets. &lt;br /&gt;&lt;/ol&gt;Refereeing trac tickets is different than refereeing papers for inclusion in a journal in several ways.  There is no central editor that assigns tickets to reviewers -- anybody (you, right now!) can just jump in and start refereeing tickets.  Also, everything about refereeing is completely open and archived (hopefully) forever.   &lt;h2&gt;What To Expect&lt;/h2&gt;The code attached to a trac ticket can do all kinds of things, including:  &lt;ol&gt;&lt;li&gt; Fix a little (or huge) bug.&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Add documentation to a function.&lt;br /&gt;&lt;br /&gt;&lt;li&gt; Introduce a new feature to Sage (and possibly new bugs!).&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Change the name of an existing function. &lt;br /&gt;&lt;br /&gt;&lt;li&gt; Raise (or lower) the "doctest coverage" of Sage. &lt;br /&gt;&lt;/ol&gt;&lt;h2&gt;How to Referee a Ticket&lt;/h2&gt;Refereeing a ticket involves several steps.  The steps below are mainly aimed at tickets that add new capabilities to Sage, but I've included some remarks about other types of tickets in another section below. &lt;ol&gt;&lt;li&gt; Use Mercurial queues to apply all the patches on the trac ticket to your own (very recent, usually alpha) version of Sage, then type "sage -br" to rebuild the Sage library.   You download&lt;br /&gt;each foo.patch, then do "hg qimport foo.patch" followed by "hg qpush" (I personally use this &lt;a target="_new" href="http://sage.math.washington.edu/home/wstein/bin/hgqimport"&gt;little script&lt;/a&gt;).   Note: this can be automated; type "sage -merge" to learn how.   If you can't apply the patch, then the ticket may "need work", i.e., the author has to rebase the patches; note this and change the Action at the bottom of the ticket page to "needs work". &lt;br /&gt;&lt;br /&gt;&lt;li&gt;Test out the code to make sure the doctests work, using "sage -t affected_files" and "make ptest" in the SAGE_ROOT directory.  Doing "make ptest" is a good idea, since often a change in one part of Sage breaks something far, far away that was written by somebody else long, long ago.  (Again, see "sage -merge" for automating this.)  If any tests fail, the ticket probably "needs work"; note this and change the action to "needs work".  I often do this testing on sage.math.washington.edu, since it has 24 processors.&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Make sure that every function introduced in the code, even ones that start with underscores (!), have examples that fully illustrate how they work.  Make sure that all input parameters to these functions are tested in the examples, and ensure that the function is actually being used by the examples.  If the patch is large you can do "sage --coverageall" both before and after applying the patches, and make sure the coverage score doesn't go down.  Also, make sure the docstrings are laid out according to our standard template, e.g.,&lt;br /&gt;&lt;pre&gt;"""&lt;br /&gt;Short description... (one sentence usually)&lt;br /&gt;&lt;br /&gt;Long description... (optional but sometimes good)&lt;br /&gt;&lt;br /&gt;INPUT:&lt;br /&gt;    - param1 -- description of&lt;br /&gt;      the first param&lt;br /&gt;    - param2 -- description of&lt;br /&gt;      the second param&lt;br /&gt;OUTPUT:&lt;br /&gt;    - description of output&lt;br /&gt;&lt;br /&gt;AUTHORS: &lt;br /&gt;    - Sage Developer1&lt;br /&gt;    - Sage Developer2&lt;br /&gt;&lt;br /&gt;EXAMPLES::&lt;br /&gt;&lt;br /&gt;    sage: 2+2&lt;br /&gt;    4&lt;br /&gt;&lt;br /&gt;TESTS::&lt;br /&gt;&lt;br /&gt;    sage: further examples nobody should look at.&lt;br /&gt;"""&lt;br /&gt;&lt;/pre&gt;It is essential that there be two colons after "EXAMPLES" and a blank line!!  Also, do not omit the INPUT/OUTPUT blocks, since I often get complaints from end users that these are missing.&lt;br /&gt;&lt;br /&gt;&lt;li&gt; If you've got this far without marking the ticket "needs work", then every function in the new code should work and have solid docstrings, including INPUT/OUTPUT blocks and examples that illustrate how the function works.  Much of what you did in 1-3 is pretty routine (and yes, there are people working on trying to automate some of this).  In this step, you finally get to have more fun and be creative: think seriously about whether the code is "probably correct" and sufficiently well documented to read.  If not, do not give the code a positive review.  The Sage library is already huge, and we don't want new code that is just going to cause a lot of pain to maintain later (there are other places for such code, such as &lt;a target="_new"  href="http://purple.sagemath.org"&gt;Purple Sage&lt;/a&gt;).  Basically, at this point, pretend you are a playtester or hacker and try to break the functionality introduced by the trac ticket.  Some techniques include:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt; Throw random input at the functions and see what happens.&lt;br /&gt;&lt;li&gt; If you know any theorems or conjectures that leads to consistency checks on the functions, try them out.  For example, if a function factors something as a product, try factoring products, then multiplying the factors back together.  If the function computes the Ramanujan tau function, try it on large inputs and test the standard congruences.&lt;br /&gt;&lt;li&gt;If the functions are implemented in other software (e.g., Magma or Mathematica) write a little program to systematically compare the output of Sage and the other system for some range of values.  Also, compare timings; if code is 100 times slower in Sage than Magma, there better be a good reason for this. &lt;br /&gt;&lt;li&gt; Very often when reading code, your "devious mind" will think of ways to potentially break it.  Make sure that you have a sage prompt up, so you can try out your ideas for breaking the code.  If anything succeeds at breaking the code, put that in your report and set the trac Action to "Needs work".  Also, if you think of good doctests to add, note these.&lt;br /&gt;&lt;/ul&gt;&lt;/ol&gt;&lt;h2&gt;Special Cases&lt;/h2&gt;As mentioned above, most of the steps above assume that the code attached to the trac ticket is implementing new features.    &lt;ul&gt;&lt;li&gt; If the code fixes a bug, then if at all possible, there should be a new doctest that illustrates that the bug is fixed.  This doctest should mention the relevant trac ticket.&lt;br /&gt;&lt;br /&gt;&lt;li&gt; If a trac ticket mainly adds new documentation, pay special attention to the English grammar, writing, etc.  In my experience, almost nobody (definitely not me!) ever writes a few paragraphs of English without making several mistakes, typos, etc.&lt;br /&gt;&lt;br /&gt;&lt;li&gt; If the code changes the name of an existing function, then this must happen in accordance with our deprecation policy.  You have to leave the old function name in place and add a deprecation warning.  This can be removed after ONE YEAR.  The proper way to do this is to put the following at the top of the function:&lt;br /&gt;&lt;pre&gt;from sage.misc.misc import deprecation&lt;br /&gt;deprecation("function_name is deprecated...")&lt;br /&gt;&lt;/pre&gt;Also, you may want to put in the Sage version number to give people a clue about when to remove the function (see the second argument to the deprecation function).&lt;br /&gt;&lt;/ul&gt;The core Sage library is meant to be mature, stable and highly polished, and function names, class names, etc., are not allowed to just be changed left and right.  There are other places to post code that &lt;em&gt;uses&lt;/em&gt; Sage, but which is not yet stable.   &lt;h2&gt;Posting Patches as the Referee&lt;/h2&gt;Often when going through the above steps, it is easiest to just make changes directly to the source code.  E.g., if you see documentation misspelled, or think of examples to add.  Just make a new patch that has all these changes and post a "referee patch".  If you do this, then you should notify the original patch author(s), so they can referee your referee patch.  This can get a little confusing, but usually sorts itself out.    &lt;h2&gt;Summary&lt;/h2&gt;&lt;br /&gt;I hope you can see from the above that refereeing tickets can be really fun.  Think of it as a game to break whatever is posted on a trac ticket.  It's much better if you find issues now when the author is still interested in the code, rather than some poor user finding bugs a few years later when the author of the code has moved on to other things and forgotten everything about the code.  The core Sage library can only someday become high quality with your help as referees.  And getting substantial code into Sage itself can only have any hope of attaining a similar status to publishing in a peer reviewed journal if this process of code refereeing itself gets refined, documented, and results in good quality mathematical software.&lt;br /&gt;&lt;br /&gt;Remember, the goal is that only high quality code goes into Sage that satisfies the requirements outlined above; this is much more important than worrying about following "bureaucratic protocols".</description><link>http://sagemath.blogspot.com/2010/10/how-to-referee-sage-trac-tickets.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-5431249888852454876</guid><pubDate>Wed, 27 Oct 2010 01:44:00 +0000</pubDate><atom:updated>2010-10-26T18:44:08.247-07:00</atom:updated><title>Sage as a Python Library?</title><description>When I started Sage I viewed it as a distribution of a bunch of math software, and Python as just the interpreter language I happen to use at the time.  I didn't even know if using Python as the language would last.   However, it's also possible to think of Sage as a Python library.  &lt;br /&gt;&lt;br /&gt;Anyway, it has occurred to me (a few times, and again recently) that it would be possible to make much of the Sage distribution, without Python of course, into a Python library.  What I mean is the following.  You would have a big Python library called "sagemath", say, and inside of that would be a huge HG repository.  In that repository, one would check in the source code for many of the standard Sage spkg's... e.g., GAP, Pari, etc.   When you type &lt;br /&gt;&lt;br /&gt;python setup.py install&lt;br /&gt;&lt;br /&gt;then GAP, Pari, etc., would all get built, controlled by some Python scripts, then installed as package_data in the sagemath directory of &lt;your python=""&gt;/site-packages/.   &lt;br /&gt;&lt;br /&gt;From a technical perspective, I don't see any reason why this couldn't be made to work.   HG can handle this much data, and "python setup.py install" can do anything.      It does lead to a very different way of looking at Sage though, and it could help untangle things in interesting ways.&lt;br /&gt;&lt;br /&gt;(1) Have a Python library called "sagecore", which is just the most important standard spkg's (e.g., Singular, PARI, etc.), perhaps eventually built *only* as shared object libraries (no standalone interpreters). &lt;br /&gt;&lt;br /&gt;(2) Have a Python library which is the current Sage library (we already have this), and which can be installed assuming sagecore is installed.&lt;br /&gt;&lt;br /&gt;(3) Have other Python libraries (like psage: http://code.google.com/p/purplesage/source/browse/), which depend on (2).   Maybe a lot of the "sage-combinat" code could also be moved to such a library, so they can escape the "combinat patch queue" madness.  Maybe many other research groups in algebraic topology, differential geometry, special functions, etc., will start developing such libraries... on their own, and share them with the community (but without having to deal directly with the sage project until they want to). &lt;br /&gt;&lt;br /&gt;To emphasize (3), when people want to write a lot of mathematics code in some area, e.g., differential geometry, they would just make a new library that depends on Sage (the library in (2)).   We do the work needed to make it easy for people to write code outside of the Sage library, which depends on Sage.  Especially writing Cython code like this can be difficult and confusing, and we don't explain it all in any Sage documentation.  It actually took me quite a while to figure out how to do it today (with psage).  &lt;br /&gt;&lt;br /&gt;The core Sage library (2) above would continue to have a higher and higher level of code review, tough referee process etc.  However, the development models for (3) would be up to the authors of those libraries.&lt;br /&gt;&lt;br /&gt;The above is already how the ecosystem with Python (http://pypi.python.org/pypi), Perl (http://www.cpan.org/), R, etc., work.  Fortunately, Python has reasonably good support already for this.    &lt;br /&gt;&lt;br /&gt;I think without a shift in this direction, Sage is going to be very frustrating for people writing research oriented code. &lt;br /&gt;&lt;br /&gt;Fortunately, it's possible to do everything I'm describing above without  disturbing the mainline Sage project itself, at least for now.&lt;/your&gt;</description><link>http://sagemath.blogspot.com/2010/10/sage-as-python-library.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-8866902583154105281</guid><pubDate>Mon, 25 Oct 2010 19:25:00 +0000</pubDate><atom:updated>2010-10-27T12:09:09.473-07:00</atom:updated><title>Revision Control and Sage</title><description>&amp;nbsp;The main target audience of this blog post is mathematics researchers who are relatively new to revision control in the context of Sage.&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Background&lt;/h1&gt;&lt;br /&gt;In the 1990s when I first started using revision control, it was a major, major pain in the arse.  Making a tarball snapshot of the project directory with a date-stamp was better!  In 2005 when I started Sage, I didn't know any better, and didn't both with revision control for the first year.  In 2006, Gonzalo Tornaria told me that things had improved, and got me to use Darcs.  That lasted just over a year, when I switched Sage to use Mercurial.  The switch was due to major headaches installing Darcs (a Haskell program), and Darcs hanging when our repo got too big and complicated.&lt;br /&gt;&lt;br /&gt;We are fortunate that today many difficult problems and design decisions for revision control have been addressed through lots of work.  Revision control is amazingly good now compared to what it was 15 years ago!&lt;br /&gt;&lt;br /&gt;Some milestones: RCS, CVS, Subversion, Bitkeeper &amp;amp; Monotone, Darcs, Git/Mercurial/Bazaar&lt;br /&gt;&lt;br /&gt;A reference: see &lt;a href="http://hgbook.red-bean.com/read/how-did-we-get-here.html"&gt;the Mercurial guide&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Getting started with Mercurial&lt;/h1&gt;In sage we use "hg" = (Mercurial).  Why?&lt;br /&gt;&lt;br /&gt;- Because I chose it in early 2007, when Darcs started sucking too much&lt;br /&gt;- &lt;i&gt;Distributed&lt;/i&gt; is the way to go these days.  (Modern)&lt;br /&gt;- Bazaar far too unstable in 2007, to put it mildly.  Bazaar is by&amp;nbsp;the people who made Ubuntu, and is much more stable today.&lt;br /&gt;- GIT badly documented, too hard to setup, etc... back in 2007; again, git is much better today.&lt;br /&gt;&lt;br /&gt;---&amp;gt; so Mercurial was the only reasonable choice then.  It was just "good enough" at&amp;nbsp;the time that we could survive.  Hence Mercurial.&lt;br /&gt;&lt;br /&gt;Mercurial comes with Sage, and you can use it like so:&lt;br /&gt;&amp;nbsp;&amp;nbsp;- "sage -hg" &lt;br /&gt;&amp;nbsp;&amp;nbsp;- sage: install_scripts command&lt;br /&gt;&amp;nbsp;&amp;nbsp;- sage: hg_sage.[tab]&lt;br /&gt;&lt;br /&gt;- Or Install: easy to install standalone on OS X, Linux, &lt;i&gt;and&lt;/i&gt; Windows. &lt;br /&gt;&lt;br /&gt;- You can do "$ sudo easy_install mercurial" to install systemwide&amp;nbsp;the latest version into your default system wide Python. &amp;nbsp;&amp;nbsp;It will probably appear in /usr/local/bin/hg&lt;br /&gt;&lt;br /&gt;Documentation for hg:&lt;br /&gt;- &lt;a href="http://mercurial.selenic.com/"&gt;http://mercurial.selenic.com/&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://hgbook.red-bean.com/"&gt;http://hgbook.red-bean.com/&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://mercurial.selenic.com/learn/"&gt;http://mercurial.selenic.com/learn/&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://hginit.com/"&gt;http://hginit.com/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Project Hosting&lt;/h1&gt;&lt;br /&gt;If you create your own HG projects, you can easily host them on &lt;a href="http://code.google.com/"&gt;Google Code&lt;/a&gt;&amp;nbsp;(and also&amp;nbsp;&lt;a href="http://bitbucket.org/"&gt;http://bitbucket.org/&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;I'm doing this a lot lately with smaller projects, including:&lt;br /&gt;- &lt;a href="http://code.google.com/p/purplesage/"&gt;Purple Sage&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://code.google.com/p/sagenb/"&gt;Sage Notebook&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;- Other systems.  Google code only does HG and Subversion.  &lt;br /&gt;But there are also similar hosting services for git and bazaar:&lt;br /&gt;- &lt;a href="http://github.com/"&gt;github&lt;/a&gt;    -- free hosting for git projects&lt;br /&gt;- &lt;a href="https://launchpad.net/"&gt;Bazaar's Launchpad&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;- Sourceforge: The first major free hosting site I heard of is &lt;a hjref="http://sourceforge.net" href="http://www.blogger.com/post-edit.g?blogID=6365588202025292315&amp;amp;postID=8866902583154105281"&gt;sourceforge.net&lt;/a&gt;, which offers hosting for all sorts of repos, including mercurial. It is more general, but not as "clean and focused" in abilities as the above, e.g., their mailing lists are often plagued by spam, and I seem to recall a lot of banner ads.&lt;br /&gt;&lt;br /&gt;These hosting services are a very popular and fairly &lt;i&gt;new thing&lt;/i&gt; (but not too new); all but sourceforge became popular well after I started Sage.  They provide much, much more than just what the revision control systems do; they are more than just a place to host your code repository.  They all provide:&lt;br /&gt;&lt;br /&gt;- code hosting (of course)&lt;br /&gt;- bug tracking&lt;br /&gt;- code review&lt;br /&gt;- mailing lists, wiki's, etc. &lt;br /&gt;&lt;br /&gt;Sage isn't hosted on one of these probably because they are so&amp;nbsp;new, and Sage is older.  This may change. &amp;nbsp;Also, Sage is really, really big (Google code has a 2GB limit).&lt;br /&gt;&lt;br /&gt;Main point: if you want to start a small project with a small number of other people -- example, writing a research paper and some corresponding code -- you can in seconds&amp;nbsp;&lt;i&gt;easily&lt;/i&gt; get the full suite of hosting, bug tracking, code review, etc., totally for free, backed up, high quality, etc.  Obviously, you are trusting your data to either Google, Github, or Canonical, but you can easily backup most of it (e.g., the repos, mailing lists).&lt;br /&gt;&lt;br /&gt;They want you to use them: "431,000 people hosting over 1,330,000 git repositories" (from github)&lt;br /&gt;&lt;br /&gt;Story: In 2006, when I came to UW, Randy Leveque (a professor in applied math) found out about me running the Sage project, and wanted to know how to get Mercurial, Wiki's, trac, etc., setup, so that he could organize his software development project(s).  I explained some basics, and I think he and his students setup various project infrastructure, and ran into assorted troubles. Today, I would just say "http://code.google.com" (or github, etc.) and be done with it!  And Randy would be up and running with more tools than before in a matter of minutes.&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Command line mercurial&lt;/h1&gt;&lt;br /&gt;The main point of the rest of this lecture will be about how to use Mercurial.  It's very hard to beat the official Mercurial Quickstart, which we'll just go over together in class:&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://mercurial.selenic.com/quickstart/"&gt;Mercurial Quickstart&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;- Make a directory in your computer be under revision control&lt;br /&gt;- Setup your .hgrc file, if you haven't already.&lt;br /&gt;- Try cloning a remote repository, e.g., &lt;a href="http://code.google.com/p/purplesage/source/checkout"&gt;purple sage&lt;/a&gt;&lt;br /&gt;- Try committing a change that spans multiple files, so you can see that all the changes are together.  Then view the commit via "hg serve -p 8200".   &lt;br /&gt;&lt;br /&gt;WARNING: on OS X with the sage-included hg, this "hg serve" crashed for me with "Trace/BPT trap" when I visited http://localhost:8200.  I opened &lt;a href="http://trac.sagemath.org/sage_trac/ticket/10171"&gt;trac ticket 10171&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So I did "sudo easy_install mercurial" to get a new version systemwide, and now this works for me: "/usr/local/bin/hg serve -p 8200" &lt;br /&gt;&lt;br /&gt;A future blog post may cover more advanced HG topics, including branching, cloning, queues, and bundles.</description><link>http://sagemath.blogspot.com/2010/10/revision-control-and-sage.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-4704435237740825005</guid><pubDate>Mon, 04 Oct 2010 23:47:00 +0000</pubDate><atom:updated>2010-10-07T11:41:33.278-07:00</atom:updated><title>Standalone C/C++ libraries that are included in Sage</title><description>Every copy of &lt;a href="http://sagemath.org/"&gt;Sage&lt;/a&gt; includes many free open source C/C++ libraries, which can also be used standalone without Sage.  They got into Sage because enough people really cared about using them, and felt it was worth the effort to convince other people that these should be included in Sage. Thus every single library also provides some key functionality to Sage.  Thus understanding the main points about these libraries should be of interest to anybody who knows C/C++ who wants to do mathematical computation.  Moreover, most of these libraries were written in C/C++ because the authors had already mastered the underlying algorithms, and really wanted an implementation that was extremely fast, often potentially orders of magnitude faster than what they might implement using only an interpreter, such as Python, Maple or Magma.&lt;br /&gt;&lt;br /&gt;It's also possible using Cython (or even ctypes) to directly call any of the functionality of the libraries below from Python (hence Sage). Thus it is vital that you know about these libraries if you want to write fast code using the Sage framework. &lt;br /&gt;&lt;br /&gt;When you want to look at the source code for any of these libraries, you can download the Sage source code from &lt;a href="http://boxen.math.washington.edu/sage/src/"&gt;here&lt;/a&gt; or &lt;a href="http://sagemath.org/download-source.html"&gt;here&lt;/a&gt;, unpack it, look in the directory sage-x.y.z/spkg/standard/, and for any "spkg" (=tar, bzip2) file there, unpack it, e.g.,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;wstein@sage:$ tar jxvf mpir-1.2.2.p1.spkg&lt;br /&gt;wstein@sage:$ cd mpir-1.2.2.p1/src/&lt;br /&gt;wstein@sage:$ ls&lt;br /&gt;acinclude.m4     doc               missing        &lt;br /&gt;...&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Note that you can't unpack the spkg files included in a binary of Sage, since they are actually empty placeholders.  &lt;br /&gt;&lt;br /&gt;You can also find direct links to all of the standard spkg by going to &lt;a href="http://sagemath.org/packages/standard/"&gt;this page&lt;/a&gt;, along with short descriptions of each. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Arithmetic&lt;/h1&gt;&lt;ul&gt;&lt;li&gt; mpir (written in C and assembler; has a C++ interface): this is a library for doing fast arithmetic with arbitrary precision integers and rationals.  It's very fast and cross-platform, and it's used by many other libraries.  (NOTE: MPIR was started as an angry fork" of GMP=Gnu Multiprecision Library.  GMP is used by Magma, Maple, and Mathematica; I've been told Mathematica doesn't use MPIR because of the overlap of Sage and MPIR developers, and their general suspicion toward the Sage project.)&lt;br /&gt;&lt;/li&gt;&lt;li&gt; mpfr (C library with C++ interface): this is a library for doing arithmetic with fixed precision floating point numbers, i.e., decimals with a given fixed choice of precision.  "Floating-point numbers are a lot like sandpiles: Every time you move one you lose a little sand and pick up a little dirt." [Kernighan and Plauger].  MPFR is used by Magma (for details, google for "mpfr magma"), and several other libraries and systems out there.  The number theory system and library PARI does *NOT* use MPFR; since PARI also does arbitrary precision floating point arithmetic, you see that PARI includes alternative implementations of some of the same algorithms (note: PARI also has its own alternative to MPIR).  MPFR is unusual in that the main author -- Paul Zimmerman -- is unusually careful for somebody who works with floating point numbers, and my understanding is that all the algorithms in MPFR are proven to give the claimed precision.  Basically, MPFR generalizes IEEE standards (that define what floating point arithmetic means) to arbitrary precision.  MPFR also supports numerous "rounding modes".  The mpmath Python library is in some cases faster than MPFR, but it has very different standards of rigor.&lt;/li&gt;&lt;li&gt; mpfi (C library): mpfi is built on top of MPFR, and implements arbitrary precision floating point "interval arithmetic".  Interval arithmetic is an idea where you do arithmetic on intervals [a,b],&lt;br /&gt;and apply functions to them.  Given two intervals, their sum, product, quotient, etc., is another interval.  The actual "feel" of using this is that you're working with floating point numbers, and as you lose precision due to rounding errors, the computer keeps track of the loss every step of the way... and in some cases you can quickly discover you have no bits left at all! MPFI is nicely integrated into Sage (by Carl Witty), and is a pretty sophisticated and robust implementation of interval arithmetic, on which some other things in Sage are built, such as the field QQbar of all algebraic numbers.&lt;/li&gt;&lt;li&gt; flint (C library): "Flint" is an abbreviation for "Fast Library for Number Theory".  However, I've listed it here under basic arithmetic, since so far in Sage at least we only use FLINT for arithmetic with polynomials over Z[x] and (Z/nZ)[x].  (Sage should use it for Q[x], but still doesn't; see the horendously painful trac ticket, number 4000!)  The main initial challenge and reason for existence of flint was to multiply polynomials in Z[x] more quickly than Magma (hence any other software on the planet), and FLINT succeeded.  Now FLINT also does many other relevant polynomial algorithms, e.g., GCD, addition, etc.  Most new development is going into "FLINT2", which is a total rewrite of FLINT, with an incompatible C interface.  Bill Hart's vision is that eventually FLINT2 have capabilities sort of like PARI.  Sage users have found at least one serious bug involving f,g in Z[x] where f*g was computed incorrectly.&lt;/li&gt;&lt;li&gt; znpoly (C libary): (by David Harvey) one version of znpoly is included in FLINT, and another is a standalone package in Sage. The point of this library is to do fast arithmetic in (Z/nZ)[x]. ("Monsky-Washnitzer!" we once found a very subtle bug in  znpoly-in-FLINT that only appeared when multiplying polynomials of huge degree.)&lt;/li&gt;&lt;li&gt; givaro (C++ library): in Sage we use it entirely for fast arithmetic over small-cardinality finite fields, up to cardinality "2 to the power 16".  Givaro makes a log table and does all multiplications as additions of small ints.  Givaro actually does a lot more, e.g., arithmetic with algebraic numbers, and a bunch of matrix algorithms, including Block Wiedemann, which we don't even try to make available in Sage.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;NOTE: The C library API conventions of mpir (gmp), mpfr, mpfi, flint and zn_poly are all pretty similar.  Once you learn one, the others are comfortable to use.  Givaro is totally different than the others because it is a C++ library, and hence has operator overloading available. The upshot: in Givaro, you type "c=a+b" to add two numbers, but in the other libaries (when used from C) you type, maybe "mpz_add(c,a,b)".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Number Theory&lt;/h1&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt; pari (C library; interpreter): a hugely powerful C library (and interactive interpreter) for number theory.  This library is very, very good and fast for doing computations of many functions relevant to number theory, of "class groups of number fields", and for certain computations with elliptic curves.  It also has functions for univariate polynomial factorization and arithmetic over number fields and finite fields.  PARI has a barbaric stack-based memory scheme, which can be quite annoying.  Key Point: PARI is easy to build on my iPhone, which says something.  That said, we have Neil Sloane, 2007: ``I would like to thank everyone who responded to my question about installing PARI on an iMAC.  The consensus was that it would be simplest to install Sage, which includes PARI and many other things.  I tried this and it worked! Thanks!  Neil (It is such a shock when things actually work!!)''  PARI is very tightly integrated into Sage.&lt;/li&gt;&lt;li&gt; ntl (C++ library): a C++ library aimed at providing foundations for implementing number theory algorithms.  It provides C++ classes for polynomials, vectors, and matrices over ZZ, Z/pZ, GF(q), (Z/pZ)[x], and RR, and algorithms for each.  Some algorithms, e.g., for polynomial factorization in ZZ[x], are very sophisticated.  Others, e.g., Hermite form of matrices over ZZ, are naive.  In fact, most of the matrix algebra in NTL is naive, at least compared to what is in IML, Linbox, Sage and Magma.  NTL is very stable and considered "done" by its author.&lt;/li&gt;&lt;li&gt; eclib (C++, standalone program): This is John Cremona's prized collection of C++ code that he wrote for computing elliptic curves, both finding them (using "modular symbols") and computing tricky things about them (via the "mwrank" program).  It's a large amount of C++ code that Cremona developed over nearly 2 decades.  There is still much functionality in there that could be made more readily available in Sage via Cython, but for which nobody has put in the effort to do so (I'm sure Cremona would be very helpful in providing guidance).&lt;/li&gt;&lt;li&gt; lcalc (C++ library, standalone program): This is Mike Rubinstein's C++ library for computing with "motivic L-functions", which are generalizations of the Riemann zeta function, of great importance in number theory.  It's particularly good at computing tons of zeros of such functions in their critical strip, hence getting information about generalizations of the Riemann Hypothesis.  It's the best general purpose L-functions program for computing zeros.&lt;/li&gt;&lt;li&gt; sympow (standalone C program): Though technically not a library it could be adapted into one.  Sympow is a C program written by Mark Watkins for quickly computing special values of symmetric power L-functions (so related to what lcalc does).  It has no dependencies (instead of PARI), because Mark didn't want to have to license sympow under the GPL.&lt;/li&gt;&lt;li&gt; ratpoints (C library): Michael Stoll's highly optimized C program for searching for certain rational points on hyperelliptic curves (i.e. of the form y^2 = f(x)).  This library goes back to the early 1990s and work of Elkies.  I believe this is in Sage for one reason only: Robert Miller wanted to implement 2-descent, and he needed this.  (Unfortunately, Miller's implementation is only done in the case when there is a rational 2-torsion point.)  This library could be made more useful in Sage, via making it so functionality in sage.libs.ratpoints is easily available for hyperelliptic curves...&lt;/li&gt;&lt;li&gt; genus2reduction (standalone C program that uses PARI): Not technically a library.  This a C program that depends on PARI, and quickly computes "stuff" about genus 2 curves over the rational numbers... which as far as I know is fairly unique in what it does.  A. Brumer used it recently for a large scale computation, and pointed out that it has stability issues.&lt;/li&gt;&lt;li&gt; flintqs (C++ program): This is a standalone C++ program that implements the quadratic sieve algorithm for integer factorization (which is good at factoring p*q with p and q of similar size and p*q up to maybe 100 digits).  I think that this algorithm is also implemented in PARI, though in some cases flintqs is faster.  A silly fact is that a better version of this program is evidently in FLINT itself, but for some reason Sage doesn't use it.  &lt;/li&gt;&lt;li&gt; ecm (C library and C program; uses MPFR, MPIR): This implements the elliptic curve integer factorization algorithm, which Hendrik Lenstra invented, and is good at factoring p*n with p a prime with up to 30 (?) or so digits.  There is another highly optimized implementation of the same algorithm as part of PARI, but ECM is in some (all?) cases better.  It also has a huge number of tunable parameters.  The ECM program is also often run standalone by people, sometimes on clusters, to attempt to factor integers.  NOTE: Sage has a "factor" command, which just calls PARI. One could imagine it calling ECM and flintqs, etc., but nobody has made it do so... though many have tried.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h1&gt;Linear Algebra&lt;/h1&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt; IML (C library): "Integer matrix library".  This library solves A*X = B, with A and B matrices over the integers.  It does this by solving "A*X = B (mod p^n)" for several prime powers p^n, which involves computing the reduced row echelon form of A mod p (for various p) quickly... which is in turn done via matrix multiplication over matrices with double precision entries.  It is the fastest software in the world for solving AX=B in many cases, especially as the entries of A and B get huge.  &lt;/li&gt;&lt;li&gt; Linbox (C++ library): asymptotically fast black box linear algebra algorithms.  It was just a "research sandbox", but "we" (mainly Clement Pernet) got Linbox whipped into shape enough to be of use in Sage for certain things.  It is used at least for: matrix multiplication and computation of characteristic polynomials of matrices over the integers and finite fields, and asymptotically fast echelon form of matrices over finite field.  I don't think it is used for much else yet.  Implementing fast versions of the above in general is a gargantuan task, and we had done much of it (but no good charpoly!)  natively in Sage before using Linbox, so now multiple implementations are available -- Linbox's are usually faster. Until Linbox/Sage, there were no fast open source programs for asymptoically fast exact linear algebra -- Magma was the only game in town (neither Maple or Mathematica are good at this either).&lt;/li&gt;&lt;li&gt; m4ri (C library): "Mary" -- scary fast arithmetic with matrices over the finite field GF(2) with 2 elements.  This library uses various tricks (involving so-called "Gray codes") and asymptotically fast divide-and-conquer algorithms to compute reduced row echelon form and do matrix multiplication with matrices over GF(2).  It is memory efficient and is the world's fastest at many benchmarks.  There is related work (on "m4ri(e)") to do arithmetic over GF(2^n) and also some work by Boothby and Bradshaw on GF(p^n) for small p and n.  &lt;/li&gt;&lt;li&gt; libfplll (C++ library): floating point LLL.  The whole point of fpLLL is to implement very fast algorithms for computing LLL reduced basis for lattices, possibly with rounding error if you are not careful.  LLL gets used as a key algorithm in many other algorithms (e.g., polynomial factorization).  Magma also uses some variant of libfplll, and an older rewritten version of fpLLL is in PARI.  If you look, e.g., at Mathematica, it does have some sort of limited LLL implementation, but it is nowhere near as sophisticated as what is available overall in Sage... NTL and PARI also have their own interfaces to LLL, which can have various pros and cons over using fpLLL directly.  (In Sage, you can make a matrix over the integers and call the LLL or LLL_gram methods on it.)  Magma also uses fpLLL.  &lt;/li&gt;&lt;li&gt; polybori (C++ library): commutative algebra with boolean rings, which are characteristic 2 rings such that x^2 = x for every element of the ring.  Evidently, polybori is important in cryptography and circuit design (?).  I have personally never succeeded in really understanding how or seeing for myself polybori do well on benchmarks. Polybori is why the boost-cropped package is in Sage, which provides some C++ datastructure and algorithms. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h1&gt;Combinatorics&lt;/h1&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt; symmetrica (C++ library): a C++ library for doing very fast arithmetic with symmetric functions.  The combinatorics code in Sage builds on this.&lt;/li&gt;&lt;li&gt; cliquer (C library): for finding cliques (=maximal complete subgraphs) in a graph.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Geometry&lt;/h1&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt; gfan (C++ program): "groebner fans" -- for computing a geometric object that parametrizes all Groebner basis for an ideal.&lt;/li&gt;&lt;li&gt; cddlib (C library): for computing with convex polytopes that gfan requires, using the "double description" method (whatever that is).  There is code in sage.geometry.polyhedra that also uses cddlib.&lt;/li&gt;&lt;li&gt; glpk (C library): the GNU linear programming toolkit.  This is a good free open source program for "linear programming".  There are also commercial programs (e.g., CPLEX) for linear programming, and whenever people talk about linear programming software they always point out that some commercial programs are way, way faster than glpk.  But glpk is in Sage. &lt;/li&gt;&lt;li&gt; palp (C program): computes stuff about lattice polytopes, like all the integers points in one.  There is a big Sage package that builds on top of this.  Evidently, this is of substantial interest to some physicists.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h1&gt;Numerical applied math&lt;/h1&gt;&lt;ul&gt;&lt;li&gt; gsl (C library): implements core algorithms of scientific computing, is very stable and considered "done" by its authors. New relevant code goes into other libraries that use GSL.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h1&gt;Non mathematics&lt;/h1&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt; readline: provides command line editing, which is used by IPython, PARI, Singular, etc.  Often misbuilt or not available on various platforms, so included in Sage.  Readline is perhaps famous for being a key reason that both PARI and clisp are licenced under the GPL.&lt;/li&gt;&lt;li&gt; bzip2: bzip2 compression; easily usable from Sage via "import bz2".  NOTE: this is used by the Sage build system so it is in SAGE_ROOT/spkg/base instead of SAGE_ROOT/spkg/standard/.&lt;/li&gt;&lt;li&gt; zlib: gzip-compatible compression; makes it so you can easily "gzip" files, and even work with gzip'd files in memory from Python.&lt;/li&gt;&lt;/ul&gt;</description><link>http://sagemath.blogspot.com/2010/10/standalone-cc-libraries-that-are.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-7949210375903976827</guid><pubDate>Mon, 27 Sep 2010 03:23:00 +0000</pubDate><atom:updated>2010-09-26T20:23:44.388-07:00</atom:updated><title>The Sagemath Cluster's Fileserver</title><description>In addition to being involved in programming in Sage, I am also the systems administrator for the "Sagemath cluster" of computers, which are used for Sage development, and also support mathematics research.  This is a cluster of 5 machines with 128GB RAM and 24 cores in each machine, along with a 24 terabyte Sun X4540 fileserver. &lt;br /&gt;&lt;br /&gt;When we setup this cluster nearly 2 years ago, we installed OpenSolaris and ZFS on the fileserver.  It's run very solidly, in that the uptime was over 600 days a few days ago.  However, no software would really work well on OpenSolaris for me -- top crashed usually, emacs crashed, stuff just didn't work.   I never got Sage to build.   Also, USB disks were a major pain on this machine, which complicated backups.  Also, I frankly found the performance of ZFS and NFS-from-ZFS to be disappointing.   In addition, nobody had a clue how to do maintenance and security updates on this server, meaning it was probable a danger. &lt;br /&gt;&lt;br /&gt;Then Sun got bought by Oracle, and Oracle killed OpenSolaris.  Also, I started getting really into MongoDB for database work related to the modular forms database project, and it would be nice to be able to run a MongoDB server and other related software and servers directly on my fileserver (yes, MongoDB supports Solaris, but...).  Getting anything to work on Solaris costs too much time and confusion.     So I decided to delete OpenSolaris and install Linux.   Since there's many terabytes of data on the fileserver, and dozens of people using it, this involved many rsync's back and forth. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I eventually succeed in installing Ubuntu 10.04.1 LTS Server on disk.math.  I setup a big 20TB software RAID-5 array on disk.math (with 2 spares), and added it to an LVM2 (=logical volume management) volume group.&lt;br /&gt;&lt;br /&gt;I created 3 partitions:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;home -- 3.5 terabytes: &amp;nbsp;for people's home directories&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;scratch -- 3.5 terabytes; &amp;nbsp;for scratch that is available on all machines on the cluster&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;lmfdb -- 3.5 terabytes; &amp;nbsp;for the L-functions and modular forms database project.&lt;br /&gt;&lt;br /&gt;Thus over 7.5 terabytes is not allocated at all right now. &amp;nbsp;This could be added to the lmfdb partition as needed.&lt;br /&gt;&lt;br /&gt;The RAID-5 array has impressive (to me) performance:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; root@disk:/dev# /sbin/hdparm -t /dev/md0&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; /dev/md0:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; Timing buffered disk reads: &amp;nbsp;1638 MB in &amp;nbsp;3.00 seconds = 545.88 MB/sec&lt;br /&gt;&lt;br /&gt;All the above 3.5TB partitions are NFS exported from disk.math, and (will all be) mounted on the other machines in the cluster.&lt;br /&gt;&lt;br /&gt;By using LVM, we will still get snapshotting (like ZFS has), which is important for robust backups over rsync, and is great for users (like me!) who accidentally delete important files. &lt;br /&gt;&lt;br /&gt;I chose 3.5TB for the partitions above, since that size is easy to backup using 4TB external USB disks.  Now that I'm running linux on disk.math, it will be easy to just plug in a physical disk to the fileserver and make a complete backup, then unplug it and swap in another backup disk, etc. &lt;br /&gt;&lt;br /&gt;----&lt;br /&gt;&lt;br /&gt;Some general sysadmin comments about, in case people are interested. &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; (1) Oracle shutdown access to firmware upgrades, which meant I couldn't upgrade the firmware on disk.math. &amp;nbsp;Maybe it would have been possible via phone calls, etc., but I was so pissed off to see Oracle do something that lame. &amp;nbsp;It's just evil to not give away firmware upgrades for hardware. &amp;nbsp;Give me a break. &amp;nbsp;Oracle sucks. &amp;nbsp; I'm really glad I just happened to upgrade the firmware on all my other Sun boxes recently.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; (2) The remote console -- which is needed to install from a CD image on disk.math -- does not work correctly on 64-bit OS X or 64-bit Linux. &amp;nbsp; &amp;nbsp;It just fails with "not supported on this platform" errors, but with no hint as to why. &amp;nbsp; By installing a 32-bit Linux into a virtual machine, I was able to get this to work.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;(3) Linux NFS + software RAID + Linux LVM2 (=logical volume management) does roughly "the same thing" as ZFS did on the old disk.math machine. &amp;nbsp; I spent about equal time with the documentation for both systems, RAID+LVM2+NFS and ZFS, and the documentation for RAID+LVM2+NFS is definitely less professional, but at the same time vastly more helpful. &amp;nbsp;There's lots of good step-by-step guides, forums, and just generally a *ton* of useful help out there. &amp;nbsp;With the ZFS documentation, there is basically one canonical document, which though professional, is just really frustrating as soon as you have a question not answered in it. &amp;nbsp; &amp;nbsp; I personally greatly prefer the Linux ecosystem. &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;(4) RAID+LVM2+NFS is much more modular than ZFS. &amp;nbsp; Each part of the system can be used by itself without the other parts, each has its own documentation, and each can make use of the other in multiple flexible and surprising ways. &amp;nbsp; &amp;nbsp;It's very impressive. &amp;nbsp; &amp;nbsp;One of the reasons I chose ZFS+Solaris instead of Linux+whatever 2 years ago is that I didn't realize that Linux offers similar capabilities.... because it didn't back in 2001 when I was learning tons about Linux. &amp;nbsp;But it does now. &amp;nbsp;Linux on the server has really, really improved over the years. &amp;nbsp; (I've been using Linux since 1993.)</description><link>http://sagemath.blogspot.com/2010/09/sagemath-clusters-fileserver.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-3732870939068738602</guid><pubDate>Tue, 17 Aug 2010 21:42:00 +0000</pubDate><atom:updated>2010-08-18T15:29:27.252-07:00</atom:updated><title>*-Overflow</title><description>I spent some time obsessively browsing &lt;a href="http://mathoverflow.net/"&gt;http://mathoverflow.net&lt;/a&gt; during the last few days (and posting too), and it is a really awesome site.&amp;nbsp; I found out about it last December, when I visited Berkeley to give a talk, and had lunch with one of the guys that runs the site, but didn't pay much attention to it until recently.&amp;nbsp; It's much more suitable for discussion of &lt;i&gt;research-level mathematics&lt;/i&gt; than general use and development of Sage.      &lt;br /&gt;&lt;br /&gt;&lt;a href="http://mathoverflow.net/"&gt;Mathoverflow&lt;/a&gt; is interesting in that their comment system supports jsmath with realtime preview, which is something the TinyMCE editor in &lt;a href="http://sagenb.org/"&gt;the Sage notebook &lt;/a&gt;doesn't do.   It's also something that &lt;a href="http://stackoverflow.com/"&gt;http://stackoverflow.com&lt;/a&gt; doesn't do, as far as I can tell.    The&amp;nbsp; grad students at Berkeley that organize &lt;a href="http://mathoverflow.net/"&gt;mathoverflow&lt;/a&gt; probably somehow hacked jsmath into the comment system. &lt;br /&gt;&lt;br /&gt;I was very surprised to learn that Mathoverflow and Stackoverflow (and all the dozens and dozens of stackoverflow-based sites) are closed source.   There is &lt;a href="http://stackexchange.com/"&gt;a company&lt;/a&gt; that runs stackoverflow and hosts related sites, and keeping their code closed is &lt;a href="http://meta.stackoverflow.com/questions/14656/the-stackoverflow-source-code"&gt;part of their business model&lt;/a&gt;.  &lt;br /&gt;&lt;br /&gt;Some people sort of forked something related to stackexchange at some point, and created this:   &lt;a href="http://wiki.github.com/cnprog/CNPROG/"&gt;CNPROG&lt;/a&gt;, which is fortunately based on Python.&amp;nbsp; There are about&lt;a href="http://wiki.github.com/cnprog/CNPROG/who-are-using-cnprog"&gt; 20 sites&lt;/a&gt; using CNPROG now, including one for &lt;a href="http://advice.mechanicalkern.com/"&gt;all questions about the use of Python in science, mathematics, and engineering&lt;/a&gt;.&lt;br /&gt;I tried this site, answering a question about &lt;a href="http://cython.org/"&gt;Cython&lt;/a&gt;, and it is snappy and clean. &lt;br /&gt;&lt;br /&gt;Perhaps I will add &lt;a href="http://www.math.union.edu/%7Edpvc/jsMath/"&gt;jsmath&lt;/a&gt; or &lt;a href="http://www.mathjax.org/"&gt;mathjax&lt;/a&gt; support to cnprog and start another site (http://q.sagemath.org ?), say on using math software as an aid to mathematical research.  The site would not be specific to Sage or restricted to open source.   The FAQ would say that all questions must be of the form: "(How) can I use a computer to compute XYZ, where XYZ should be some sort of advanced mathematical question."    The emphasis on "advanced" and "research" is that there are already &lt;a href="http://math.stackexchange.com/"&gt;other sites&lt;/a&gt; about how to do elementary stuff (=people's homework), and it will provide an excuse to keep that out, which will greatly raise the quality.&amp;nbsp;&amp;nbsp; It is, after all, exactly this uncompromising focus on research that makes &lt;a href="http://mathoverflow.net/"&gt;http://mathoverflow.net&lt;/a&gt; so interesting.&lt;br /&gt;&lt;br /&gt;EDIT: I've now created &lt;a href="http://ask.sagemath.org/"&gt;http://ask.sagemath.org&lt;/a&gt; which is based on&lt;a href="http://askbot.org/"&gt; http://askbot.org&lt;/a&gt;, which is in turn based on CNPROG.&amp;nbsp;</description><link>http://sagemath.blogspot.com/2010/08/overflow.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-7073540061022744707</guid><pubDate>Mon, 07 Jun 2010 09:47:00 +0000</pubDate><atom:updated>2010-06-07T05:51:38.874-07:00</atom:updated><title>PARI on the iPAD (a component of Sage)</title><description>&lt;div class="separator" style="clear: both; text-align: left;"&gt;I got PARI (&lt;a href="http://pari.math.u-bordeaux.fr/"&gt;http://pari.math.u-bordeaux.fr/&lt;/a&gt;), which is a very powerful C program for doing number theory, to run natively on my iPad and iPhone!&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_urfwuonbW3E/TAy7Z6ad9OI/AAAAAAAAJls/n-IPiYxowxY/s1600/photo+(1).PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/_urfwuonbW3E/TAy7Z6ad9OI/AAAAAAAAJls/n-IPiYxowxY/s640/photo+(1).PNG" width="480" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;"All" I had to do was:&lt;br /&gt;&lt;br /&gt;1. Jailbreak my iPad using Spirit.&lt;br /&gt;2. Make a gcc wrapper script on my MAC laptop that can cross-compiler binaries for iPhoneOS, and put this script first in my path (I called it gcc):&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;#!/bin/sh&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;# the following is all on one line:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6 -mthumb -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk/ &amp;nbsp;"$@"&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"&gt;3. Download the PARI source code and extract it:&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;code&gt;&lt;a href="http://www.blogger.com/pub/pari/unix/pari-2.3.5.tar.gz" style="color: blue; text-decoration: none;"&gt;pari-2.3.5.tar.gz&lt;/a&gt;&lt;/code&gt;&lt;/div&gt;&lt;div&gt;4. Configure and build PARI (this requires that you have the latex XCode installed).&lt;/div&gt;&lt;div&gt;5. The build fails, so I edited the file src/kernel/none/mp_indep.c in a somewhat random way to get it to compile. &amp;nbsp;More precisely, I commented out lines 794-801, and replaced them by:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;# &amp;nbsp;define INDEX0 1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;# &amp;nbsp;define INDEX1 0&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;6. Copy &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Odarwin-i386/gp-sta&lt;/span&gt; over to the iPad/iPhone using ssh (I installed an ssh daemon using Cydia).&amp;nbsp;&lt;/div&gt;&lt;div&gt;7. Run it, via iSSH (purchased from the App store) connected to localhost -- see above.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here is a &lt;a href="http://sage.math.washington.edu/home/wstein/patches/gp-static-iphone"&gt;link to my gp-sta&lt;/a&gt;, in case you want to just drop it on your phone and run it. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If I can put a simple GUI on this, I may try to submit this to the App store, so that anybody can trivially install GP for free. &amp;nbsp; Another possibility would be to get it included in Cydia.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This is of course just a tiny step on the way to porting Sage to the iPad.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Addendum&lt;/h2&gt;&lt;br /&gt;I was also able to build Pari *directly* on the iPhone with readline support.  Installing GCC was pretty crazy. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;William-A-Steins-iPad:~/pari/pari-2.3.5 mobile$ Odarwin-arm/gp-sta &lt;br /&gt;                                 GP/PARI CALCULATOR Version 2.3.5 (released)&lt;br /&gt;                            arm running darwin (portable C kernel) 32-bit version&lt;br /&gt;                      compiled: Jun  7 2010, gcc-4.2.1 (Based on Apple Inc. build 5555)&lt;br /&gt;                             (readline v6.0 enabled, extended help not available)&lt;br /&gt;&lt;br /&gt;                                    Copyright (C) 2000-2006 The PARI Group&lt;br /&gt;&lt;br /&gt;PARI/GP is free software, covered by the GNU General Public License, and comes WITHOUT ANY WARRANTY &lt;br /&gt;WHATSOEVER.&lt;br /&gt;&lt;br /&gt;Type ? for help, \q to quit.&lt;br /&gt;Type ?12 for how to get moral (and possibly technical) support.&lt;br /&gt;&lt;br /&gt;parisize = 4000000, primelimit = 500000&lt;br /&gt;? 2+3&lt;br /&gt;%1 = 5&lt;br /&gt;? &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;My notes for installing GCC on the iphone:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;1) Install this&lt;br /&gt;&lt;br /&gt;  http://files.getdropbox.com/u/876743/fake-libgcc_1.0_iphoneos-arm.deb&lt;br /&gt;&lt;br /&gt;dpkg -i fake-libgcc_1.0_iphoneos-arm.deb&lt;br /&gt;&lt;br /&gt;2) apt-get install iphone-gcc&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3) Install headers:&lt;br /&gt;&lt;br /&gt;Copy these over, which I got from http://www.megaupload.com/?d=55ZNOCKI, and extra to /usr/include&lt;br /&gt;&lt;br /&gt;   sdk-2.0-headers.tar.gz&lt;br /&gt;&lt;br /&gt;I literally just put them in /usr/include/   &lt;br /&gt;&lt;br /&gt;4) Missing&lt;br /&gt;&lt;br /&gt;  /usr/lib/libgcc_s.1.dylib&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;wget http://apt.saurik.com/debs/libgcc_4.2-20080410-1-6_iphoneos-arm.deb&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5) Hmm:&lt;br /&gt;&lt;br /&gt;  http://blog.aaronash.com/?p=15&lt;br /&gt;&lt;br /&gt;I downloaded this and extracted it as lib, and had to use some funny password.   &lt;br /&gt;"aksblog.co.nr"&lt;br /&gt;Then I copied lib/libSystem.dylib to /usr/lib/ on my iPad&lt;br /&gt;&lt;br /&gt;... and now gcc seems to work! &lt;br /&gt;&lt;br /&gt;6) This isn't needed for some reason: Make it so I can sign my apps:&lt;br /&gt;&lt;br /&gt;    apt-get install ldid  &lt;br /&gt;&lt;br /&gt;ldid -S main&lt;br /&gt;&lt;br /&gt;Maybe I don't need this only because I'm not making a gui yet. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;7) Compiling runs into fork limits a lot, so raise the limit:&lt;br /&gt;&lt;br /&gt;William-A-Steins-iPad:~/pari/pari-2.3.5 mobile$ sysctl -w kern.maxprocperuid=64&lt;br /&gt;kern.maxprocperuid: 26&lt;br /&gt;sysctl: kern.maxprocperuid: Operation not permitted&lt;br /&gt;William-A-Steins-iPad:~/pari/pari-2.3.5 mobile$ sudo sysctl -w kern.maxprocperuid=64&lt;br /&gt;Password:&lt;br /&gt;kern.maxprocperuid: 26 -&gt; 64&lt;br /&gt;&lt;/pre&gt;</description><link>http://sagemath.blogspot.com/2010/06/pari-on-ipad-component-of-sage.html</link><author>noreply@blogger.com (William Stein)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_urfwuonbW3E/TAy7Z6ad9OI/AAAAAAAAJls/n-IPiYxowxY/s72-c/photo+(1).PNG' height='72' width='72'/></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-8054847908906869165</guid><pubDate>Sat, 08 May 2010 01:10:00 +0000</pubDate><atom:updated>2010-05-07T18:11:54.697-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>sage ipad iphone python</category><title>A Python on iPad benchmark</title><description>Now that my iPad is really &lt;b&gt;mine&lt;/b&gt;, i.e., &lt;a href="http://spiritjb.com/"&gt;jailbroken&lt;/a&gt;, I installed Python on it and tried a large integer arithmetic benchmark.   I'm curious because this will indicate something about the performance of fully porting Sage to the iPad (though of course &lt;a href="http://sagemath.org"&gt;Sage&lt;/a&gt; would use MPIR for large integers...). &lt;br /&gt;&lt;br /&gt;First, on my 64-bit 2.6Ghz Intel Dunnington box (sage.math.washington.edu):&lt;br /&gt;&lt;pre&gt;&gt;&gt;&gt; import resource&lt;br /&gt;&gt;&gt;&gt; def cputime(s=0): return sum(resource.getrusage(resource.RUSAGE_SELF)[:2])-s&lt;br /&gt;... &lt;br /&gt;&gt;&gt;&gt; t=cputime()&lt;br /&gt;&gt;&gt;&gt; a=3**(10**6)&lt;br /&gt;&gt;&gt;&gt; cputime()-t&lt;br /&gt;0.53000000000000003&lt;br /&gt;&gt;&gt;&gt; b=a*(a+1)&lt;br /&gt;&gt;&gt;&gt; cputime()-t&lt;br /&gt;2.46&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Next on my laptop, which is a top-end macbook air (64-bit intel core2 duo running 64-bit python 2.6.x):&lt;br /&gt;&lt;pre&gt;&gt;&gt;&gt; t=cputime()&lt;br /&gt;&gt;&gt;&gt; a=3**(10**6)&lt;br /&gt;&gt;&gt;&gt; cputime()-t&lt;br /&gt;0.64609700000000003&lt;br /&gt;&gt;&gt;&gt; b=a*(a+1)&lt;br /&gt;&gt;&gt;&gt; cputime()-t&lt;br /&gt;3.1051849999999996&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And, on the iPad&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&gt;&gt;&gt; t=cputime()&lt;br /&gt;&gt;&gt;&gt; a=3**(10**6)&lt;br /&gt;&gt;&gt;&gt; cputime()-t&lt;br /&gt;2.3500000000000014&lt;br /&gt;&gt;&gt;&gt; b=a*(a+1)&lt;br /&gt;&gt;&gt;&gt; cputime()-t&lt;br /&gt;9.5899999999999963&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Not bad!!   Note that 32-bit versus 64-bit (and Python 2.5 versus 2.6) may be relevant, depending on how Python big integer arithmetic is implemented. &lt;br /&gt;&lt;br /&gt;&lt;p&gt;As a bonus, I have an older iPhone 3G (not 3Gs), where we get:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&gt;&gt;&gt; t=cputime()&lt;br /&gt;&gt;&gt;&gt; a=3**(10**6)&lt;br /&gt;&gt;&gt;&gt; cputime()-t&lt;br /&gt;7.6699999999999999&lt;br /&gt;&gt;&gt;&gt; b=a*(a+1)&lt;br /&gt;&gt;&gt;&gt; cputime()-t&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wow, so the iPhone 3G at this benchmark is about TEN TIMES slower than the iPad.  No wonder the iPad feels snappier. &lt;br /&gt;&lt;hr&gt;&lt;br /&gt;Note that I view genuinely porting Sage to the iPad/iPhone as something that will only ever be available to people who jailbreak their devices.  This is because Apple bans running any interpreter except Javascript on the iPhone.   (Of course, I can always hope that Apple will get sued into opening up their app store...)   For a person like me, a jailbroken iPad is &lt;i&gt;dramatically superior&lt;/i&gt; to the standard iPad -- full multitasking, ssh access, Python, being able to easily change screen brightness, having full access to the filesystem, etc.   Now if only I had Sage!  (Of course, Sage usable on the iPad via the web, but sometimes I don't have reliable network access.)</description><link>http://sagemath.blogspot.com/2010/05/python-on-ipad-benchmark.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-7784288988683923550</guid><pubDate>Mon, 07 Dec 2009 19:32:00 +0000</pubDate><atom:updated>2009-12-07T11:55:52.941-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>sage "math software" autobiographical magma maple matlab mathematica pari</category><title>Mathematical Software and Me: A Very Personal Recollection</title><description>[You can also read a &lt;a href="http://wstein.org/mathsoftbio/history.pdf"&gt;pdf version of this blog post.&lt;/a&gt;]&lt;br /&gt;&lt;br /&gt;I find it difficult for me to write a history of Sage without writing&lt;br /&gt;a history of my personal involvement with mathematical software.  I&lt;br /&gt;loved using calculators since my earliest memories.  My father somehow&lt;br /&gt;got a mechanical electric adding machine for me when I was quite&lt;br /&gt;young, back in the 1970s, and I spent a great deal of time filling&lt;br /&gt;ribbons of paper with it.  Then he got me an old TI scientific&lt;br /&gt;calculator from a yard sale, with a LED readout.  At age 11, when I&lt;br /&gt;moved from Oregon to Texas, I bought a sliderule, which was pretty&lt;br /&gt;exciting for a while.  Then in junior high I finally got a real&lt;br /&gt;scientific calculator, a little Casio, whose instruction manual I&lt;br /&gt;devoured.  This was my first inroduction to trigonometry, statistics,&lt;br /&gt;and many other bits of computational mathematics.  I was prepared&lt;br /&gt;though, since I had done elementary school on an unusual&lt;br /&gt;work-at-your-pace alternative curriculum, and had already worked&lt;br /&gt;through 10th grade level mathematics.&lt;br /&gt; &lt;br /&gt;The first mathematical computer software I ever used was Mathematica,&lt;br /&gt;back in 1992 on a Windows 3.1 PC, when I was a 17-year old&lt;br /&gt;undergraduate at Northern Arizona University in Flagstaff, Arizona.&lt;br /&gt;&lt;br /&gt;Naturally, my copy of Mathematica was pirated, since like many&lt;br /&gt;students I was extremely poor at the time.  The only thing I found it&lt;br /&gt;useful for at the time was drawing 3d plots (just for fun), and even&lt;br /&gt;then it was frustrating, since there was no way to interactively&lt;br /&gt;change the viewpoint.  I also obtained a copy of MATHCAD somehow,&lt;br /&gt;which I found much more useful than Mathematica.  This is perhaps not&lt;br /&gt;surprising, because at the time I was a computer engineering&lt;br /&gt;undergraduate, so taking courses in Physics, Electrical Engineering,&lt;br /&gt;Programming, etc..  I was definitely not a mathematics major: I&lt;br /&gt;remember once finishing a multivariable calculus class and thinking&lt;br /&gt;``this is the last mathematics class I'll ever take"!  I also used&lt;br /&gt;Maple for about an hour or two in a computer lab for a mathematics&lt;br /&gt;course I took, but found it very cumbersome; this was a token 1-hour&lt;br /&gt;introduction to math software that professors gave their students,&lt;br /&gt;perhaps to justify the grant that paid for the computer lab.  At the&lt;br /&gt;time, I viewed Maple, Mathematica, and MATHCAD as software that didn't&lt;br /&gt;really go beyond scientific calculators in any exciting way.&lt;br /&gt;&lt;br /&gt;My next encounter with mathematics software was in early 1994 when I&lt;br /&gt;became a mathematics major, after accidentally encountering an&lt;br /&gt;abstract algebra book misfiled under computer science in a used&lt;br /&gt;bookstore, and being instantly mesmerized by ideas such as groups,&lt;br /&gt;rings, and fields.  I was in another small computer lab and stumbled&lt;br /&gt;on printouts of the documentation (Northern Arizona University&lt;br /&gt;professor) Mike Falk had for Cayley, which was the predecessor to&lt;br /&gt;Magma.  I was amazed and excited, since the capabilities and ideas in&lt;br /&gt;Cayley went so far beyond anything I had thought was even possible in&lt;br /&gt;mathematical software before.  I'm pretty sure I never got to actually&lt;br /&gt;use Cayley though, since like now, the software was very expensive&lt;br /&gt;and hard to get.  Instead, I just spent a lot of time reading the&lt;br /&gt;reference manual full of its beautiful examples of computing with&lt;br /&gt;groups, rings, and fields, which were the very objects that had&lt;br /&gt;enticed me into mathematics in the first place.  &lt;br /&gt;&lt;br /&gt;In fact, after that brief encounter with Cayley, I didn't touch&lt;br /&gt;mathematics software again, or even do any nontrivial computer&lt;br /&gt;programming for 3 years.  This was because in 1994 I became intensely&lt;br /&gt;interested in theoretical mathematics, and spent most of my time&lt;br /&gt;during the next 3 years systematically doing exercises in mathematics&lt;br /&gt;books, ranging from basic books on linear algebra and combinatorics&lt;br /&gt;(which was big in Arizona) to Hartshorne's Algebraic Geometry.&lt;br /&gt;&lt;br /&gt;In 1997, I was a graduate student at Berkeley, and didn't want to&lt;br /&gt;teach so much, so I landed a job (funded by the NSF VIGRE program) in&lt;br /&gt;the department for one year doing programming of curriculum materials&lt;br /&gt;for an undergraduate linear algebra course, along with fellow graduate&lt;br /&gt;student Tom Insel.  Though I had been using Linux for years, I had&lt;br /&gt;never thought about free software, or that actual people could&lt;br /&gt;contribute to it.  I thought of Linux as ``Unix that I can install on&lt;br /&gt;my own computer", and back then one still paid for Linux by buying a&lt;br /&gt;CD, since downloading over a modem was way too slow.  Tom and I spent&lt;br /&gt;a lot of time working on our project together, and he told me how he&lt;br /&gt;had written some software included in Slackware (a Linux&lt;br /&gt;distribution), so got free copies of the CD when new versions came&lt;br /&gt;out.  Hey, anybody can contribute to Linux!  &lt;br /&gt;&lt;br /&gt;I also remember Tom complaining frequently about how we were forced to&lt;br /&gt;program in MATLAB for our project, and he mentioned many other&lt;br /&gt;alternatives that would have been better for what we were doing,&lt;br /&gt;including Java.  We were doing GUI programming, with a tiny, tiny bit&lt;br /&gt;of actual mathematics thrown in, and MATLAB's handle-based system for&lt;br /&gt;writing graphical users interfaces was really painful.  I had a lot of&lt;br /&gt;experience with C/C++/Windows 3.1 GUI programming from my computer&lt;br /&gt;science undergraduate days, and agreed that MATLAB was pretty awkward&lt;br /&gt;for what we were doing at the time.  In retrospect, what we did was&lt;br /&gt;probably pointless, and perhaps never got used.  However, the&lt;br /&gt;experience was extremely valuable for both of us, and I'm glad NSF&lt;br /&gt;funded it.&lt;br /&gt;&lt;br /&gt;In the meantime, my Ph.D. thesis was going nowhere, despite nearly 3&lt;br /&gt;years of graduate school.  One day, I heard about a problem Ken Ribet&lt;br /&gt;was asking all the graduate students: ``Is there a prime number p such&lt;br /&gt;that the Hecke algebra at level p is ramified at p?"  It's the first&lt;br /&gt;research problem I can ever remember hearing that was almost certainly&lt;br /&gt;impossible to solve without using a computer.  Fellow grad students&lt;br /&gt;Janos Csirik (now at D.E. Shaw), Matt Baker (now at Georgia Tech), and&lt;br /&gt;I searched and found one paper by Hijikata (?), I think from the mid&lt;br /&gt;1970s, which gave an algorithm that might allow one to answer the&lt;br /&gt;above question for specific p's.  But to implement the algorithm, it&lt;br /&gt;was necessary to compute class numbers of a huge number of quadratic&lt;br /&gt;fields, and none of the mathematics software I had ever heard of until&lt;br /&gt;then could do this.  Janos and Matt mentioned PARI, and I installed it&lt;br /&gt;on my computer.  And indeed, it could quickly and easily compute class&lt;br /&gt;groups!  PARI was also the first free mathematical software I&lt;br /&gt;encountered.&lt;br /&gt;&lt;br /&gt;So I started coding up the algorithm (the Eichler-Selberg trace&lt;br /&gt;formula) in PARI.  I had a lot of experience with C++, which is a real&lt;br /&gt;programming language with user defined data types, exception handling,&lt;br /&gt;templates, etc.  I rememember in 1992 carefully reading several C++&lt;br /&gt;book cover-to-cover, and I wrote a large amount of code (video games!)&lt;br /&gt;in C++ long, long ago.  In contrast, PARI was an immediate shock.&lt;br /&gt;This was a language with no local variables, no real scoping, only a&lt;br /&gt;couple of builtin types, and for a while I thought (incorrectly) that&lt;br /&gt;entire function definitions always had to be on one line, since that&lt;br /&gt;was the case in example code I found.  But the algebraic&lt;br /&gt;number theory algorithms implemented in the internal library were&lt;br /&gt;amazing, deep, and very fast.  So I implemented the trace formula, and&lt;br /&gt;ran it to try to answer Ribet's question.  The program did not&lt;br /&gt;work---basic consistency checks failed.  It turned out that there was&lt;br /&gt;a major bug in the algorithm for computing class groups.  In&lt;br /&gt;particular, the function qfbclassno, silently returned wrong&lt;br /&gt;answers.&lt;br /&gt;&lt;br /&gt;You would think that qfbclassno would be fixed by now.  But no.  It's&lt;br /&gt;only frickin' 12 years later!!  I just checked right now, and the&lt;br /&gt;documentation for PARI still says ``Important warning. For $D &lt; 0$,&lt;br /&gt;this function may give incorrect results when the class group has a&lt;br /&gt;low exponent (has many cyclic factors), because implementing Shanks's&lt;br /&gt;method in full generality slows it down immensely.''  This is buried&lt;br /&gt;in the documentation.  The only change is that I think in 1997 the&lt;br /&gt;documentation said that the authors were ``too lazy'' to implement the&lt;br /&gt;full algorithm.  Note: In the 1990s the function was classno instead at that&lt;br /&gt;  time.  I found in tutorial.tex from&lt;br /&gt;  &lt;a href="http://pari.math.u-bordeaux.fr/pub/pari/unix/OLD/pari-1.39a.tar.gz"&gt;pari-1.39a.tar.gz&lt;/a&gt;:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;    Type {\tt classno($-$10007)}. GP tells us that the result is&lt;br /&gt;    77. However, you may have noticed in the explanation above that&lt;br /&gt;    the result is only usually correct.  This is because the&lt;br /&gt;    implementers of the algorithm have been lazy and have not put the&lt;br /&gt;    complete Shanks algorithm in PARI, causing it to fail in certain&lt;br /&gt;    very rare cases. In practice, it is almost always correct, and the&lt;br /&gt;    much more powerful {\tt buchimag} program, which {\it is}&lt;br /&gt;    complete, can give confirmation.  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So I worked around that problem, and was able to run the algorithm for&lt;br /&gt;all primes up to about 300, but didn't find any primes as in Ribet's&lt;br /&gt;question.  A few weeks later, at the Arizona Winter School in March&lt;br /&gt;1998 in Tucson, Arizona&lt;br /&gt;(&lt;a href="http://math.arizona.edu/~swc/aws/98/98GenlInfo.html"&gt;AWS&lt;/a&gt;), I mentioned&lt;br /&gt;this to Joe Wetherell (who was another Berkeley grad student), while&lt;br /&gt;we were walking to lunch, and he told me he had written a program---also&lt;br /&gt;in PARI---for computing with modular symbols (following John Cremona's&lt;br /&gt;book), with which I might be able to push the computation a little&lt;br /&gt;further.  He gave me a copy later, and I started playing around with&lt;br /&gt;it, and computed the discriminants of all of the Hecke algebras of&lt;br /&gt;prime level up to about 500. NOTE: That program lives on here, in case&lt;br /&gt;you're interested: &lt;a href="http://wstein.org/Tables/heckegp.html"&gt;tables&lt;/a&gt;. &lt;br /&gt;And it still works (here with GP 2.4.3)!!!&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;? M37 = modsym(37,+1);\\&lt;br /&gt;1. Generating M-symbols                 (0 ms)\\&lt;br /&gt;2. Hashing M-symbols                    (2 ms)\\&lt;br /&gt;3. Quotienting out by relations         (3 ms)\\&lt;br /&gt;4. Computing the kernel of delta        (0 ms)\\&lt;br /&gt;Total time.......................       (5 ms)\\&lt;br /&gt;? factor(charpoly(T(2,M37)))\\&lt;br /&gt;\%27 =\\&lt;br /&gt;%[x 1]\\&lt;br /&gt;%[x + 2 1]\\&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Again, I didn't find any examples, and I wrote to Ken Ribet to tell&lt;br /&gt;him.  Then I hopped on a plane and flew to Cambridge, England, to&lt;br /&gt;visit Kevin Buzzard.&lt;br /&gt;&lt;br /&gt;Once I got settled in Cambridge, I rechecked my calculations for some&lt;br /&gt;reason... and found an example for the prime $p=389$!  Somehow, I had&lt;br /&gt;just missed the example in my previous check.  I was extremely excited&lt;br /&gt;as I wrote to Ken Ribet, with my first ever genuine contribution to research&lt;br /&gt;mathematics, which appears in a big paper Ken published on the&lt;br /&gt;Manin-Mumford conjecture---I had shown that his new theorem definitely&lt;br /&gt;did not prove that conjecture for all modular curves.  I was also hooked&lt;br /&gt;on computing modular forms, and started making tables.  It was also&lt;br /&gt;the height of the mad cow disease scare in England, so I became a&lt;br /&gt;vegetarian.&lt;br /&gt;&lt;br /&gt;I tried to push the PARI program that Joe Wetherell had given me to&lt;br /&gt;make bigger tables, but it very quickly ran out of steam.  The main&lt;br /&gt;algorithms that the modular symbols algorithm relies on are all manner&lt;br /&gt;of linear algebra over the rational numbers, including computation of&lt;br /&gt;characteristic polynomials, and kernels of sparse and dense matrices,&lt;br /&gt;and also factorization of polynomials over the integers.  Despite its&lt;br /&gt;first rate algebraic number theory capabilities, PARI was (and still&lt;br /&gt;is) terrible at linear algebra with really big matrices over the rational&lt;br /&gt;numbers.  Also, I found the PARI programming language unbearably&lt;br /&gt;naive.&lt;br /&gt;&lt;br /&gt;So I spent the summer of 1998 writing a much more general C++ program&lt;br /&gt;for computing with modular forms called HECKE.  Here it is:&lt;br /&gt;&lt;a href="http://wstein.org/Tables/hecke-cpp.html"&gt;hecke&lt;/a&gt;. If you grab the file&lt;br /&gt;&lt;tt&gt;hecke-july99.gz&lt;/tt&gt; from that web page, and drop it on just about any Linux&lt;br /&gt;box, it should just work: NOTE&lt;br /&gt;Here is Hecke which I just tried on a Core 2:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;% ./hecke-july99&lt;br /&gt;HECKE Version 0.4, Copyright (C) 1999 William A. Stein&lt;br /&gt;HECKE comes with ABSOLUTELY NO WARRANTY.&lt;br /&gt;This is free software, and you are welcome to redistribute it&lt;br /&gt;under certain conditions; read the included COPYING file for details.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;         HECKE:  Modular Forms Calculator   Version 0.4 (July 9, 1999)&lt;br /&gt;&lt;br /&gt;                       William Stein&lt;br /&gt;Send bug reports and suggestions to was@math.berkeley.edu.&lt;br /&gt;Type ? for help.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Anyway, I spent all my time for many months&lt;br /&gt;writing HECKE.  This program built on several other C++ math&lt;br /&gt;libraries, including LiDIA and NTL.  It doesn't use PARI, because&lt;br /&gt;using PARI from C is...  really weird, and LiDIA/NTL had equivalent&lt;br /&gt;functionality at the time.  Much of the time I spent on HECKE involved&lt;br /&gt;(1) designing algorithms, generalizing work in Cremona's book, etc.,&lt;br /&gt;and (2) implementing and optimizing algorithms for linear algebra over&lt;br /&gt;the rational numbers.  For (2), Kevin Buzzard hooked me up with the&lt;br /&gt;same code Cremona used, which Cremona had got from some South American&lt;br /&gt;student at Cambridge named Luis (?).  I then spent a large amount of&lt;br /&gt;time optimizing that code for my computations.  The actual linear&lt;br /&gt;algebra algorithms in that code were very naive compared to the&lt;br /&gt;algorithms in Sage now, but they were better than anything available&lt;br /&gt;in any other software I was aware of, or in research papers at the&lt;br /&gt;time.  &lt;br /&gt;&lt;br /&gt;I was able to compute many fairly sophisticated tables using HECKE,&lt;br /&gt;and it soon became the canonical software for computing with modular&lt;br /&gt;forms, since it was the only software generally available for such&lt;br /&gt;computations.  This is perhaps similar to how NAUTY was for a very&lt;br /&gt;long time the canonical software for computing graph automorphism&lt;br /&gt;groups.  Naturally, I made HECKE freely available on my webpage.  I&lt;br /&gt;remember once getting an email from Ken Ono, who has probably written&lt;br /&gt;over 100 papers on modular forms, many inspired by concrete examples.&lt;br /&gt;He had run across HECKE on my web page, installed it, and was totally&lt;br /&gt;blown away by the capabilities of HECKE, and how useful it would be&lt;br /&gt;for his research.  A whole new world had opened up to him, and he told&lt;br /&gt;me he was promptly ordering a new fast computer specifically to run&lt;br /&gt;HECKE on.  I was happy to help.  Also, my thesis work was starting to&lt;br /&gt;go well, because the computations I was doing was suggesting&lt;br /&gt;interesting new (and do-able) mathematics, left and right.&lt;br /&gt;&lt;br /&gt;Then, in 1999, David Kohel---who had been a Berkeley grad student with&lt;br /&gt;me until December 1996---was visiting Berkeley from Sydney, Australia,&lt;br /&gt;and told me about implementing algorithms related to his thesis in&lt;br /&gt;Magma.  I think this was the first I had ever heard of Magma, despite&lt;br /&gt;Magma having been around for several years.  Magma was expensive and&lt;br /&gt;nearly impossible to get unless you knew the right person, since it&lt;br /&gt;was sold via informal channels.  I think there was an install on the&lt;br /&gt;computers in Berkeley, but those computers were ancient vintage&lt;br /&gt;1990-ish Sun workstations, so nobody would seriously try to use them.&lt;br /&gt;Anyway, David had implemented code for computing with rational&lt;br /&gt;quaternion algebras, and this was the only implementation of that&lt;br /&gt;algorithm in the world.  Coincidentally, I had extended an old idea of&lt;br /&gt;Ribet to come up with a new algorithm for computing Tamagawa numbers&lt;br /&gt;of modular abelian varieties (see &lt;a href="http://wstein.org/papers/ants/"&gt;ants&lt;/a&gt; and&lt;br /&gt; &lt;a href="http://wstein.org/papers/compgrp/"&gt;compgrp&lt;/a&gt;).  I really, really wanted to&lt;br /&gt;implement my algorithm, because it would allow me to compute all of&lt;br /&gt;the invariants in the Birch and Swinnerton-Dyer conjecture (except&lt;br /&gt;Sha) for most rank 0 modular abelian varieties, which would be a huge&lt;br /&gt;step forward.  But my algorithm fundamentally relied on exactly the&lt;br /&gt;computations in rational quaternion algebras that David Kohel had&lt;br /&gt;implemented in Magma.  And that was no small undertaking---it's a&lt;br /&gt;complicated algorithm, it takes somebody familiar with the relevant&lt;br /&gt;theory months to implement and optimize, and it builds on many other&lt;br /&gt;basic capabilities.  I had a thesis to finish.  David---who was then&lt;br /&gt;officially a Magma developer, was able to give me a copy of Magma for&lt;br /&gt;my own computer, which had his code in it.  Combining all this with&lt;br /&gt;HECKE, and copying and pasting, I was the first person ever to systematically&lt;br /&gt;compute Tamagawa numbers of general modular abelian varieties (at primes&lt;br /&gt;of multiplicative reduction).&lt;br /&gt;&lt;br /&gt;So in 1999 David Kohel put me in a situation where I was fundamentally&lt;br /&gt;dependent on a closed source non-free program in order to continue my&lt;br /&gt;own research.  Ironically, during the same afternoon in my apartment&lt;br /&gt;in Berkeley, he mentioned the GNU Public License (GPL), and suggested&lt;br /&gt;I released HECKE under the GPL.  Before that moment, I had never even&lt;br /&gt;heard of the GPL.  I did as he suggested, but had no idea what it&lt;br /&gt;meant really.  That was perhaps fortunate, since the dependencies of&lt;br /&gt;HECKE are NTL and LIDIA, and the NTL license is GPL, but the LIDIA&lt;br /&gt;license is GPL incompatible, so technically I guess HECKE can't be&lt;br /&gt;distributed.  Incidentally, LIDIA is still licensed under a&lt;br /&gt;GPL-incompatible license, despite many emails I've received suggesting&lt;br /&gt;the license would change to GPL---licenses don't change easily, due&lt;br /&gt;to having to get agreement from all copyright owners. &lt;br /&gt;&lt;br /&gt;I obviously had to actually use Magma at some level in order to do&lt;br /&gt;these computations.  Despite having a lot of experience with&lt;br /&gt;programming, I initially found the Magma language and system extremely&lt;br /&gt;hard to learn or do anything with.  It was certainly much harder to&lt;br /&gt;use initially than PARI.  On the one hand, Magma is a massive system, with&lt;br /&gt;thousands of commands and thousands of pages of reference manual documenation, but&lt;br /&gt;on the other hand there is very little in the way of ``introspection",&lt;br /&gt;i.e., given an object A, it is hard to get context sensitive help&lt;br /&gt;about A.  However, one thing was clear: Magma was dramatically better&lt;br /&gt;at dense linear algebra over the rational numbers than HECKE. It was&lt;br /&gt;a whole different world.  We're talking jaw dropping speed.  In fact,&lt;br /&gt;Magma in the late 1990s on an old computer, was far faster at large&lt;br /&gt;linear algebra over the rationals than Maple or Mathematica is today&lt;br /&gt;on the latest hardware.  I would soon find out the reason.    &lt;br /&gt;&lt;br /&gt;Allan Steel is an enthusiastic Australian, who was an undergraduate at&lt;br /&gt;University of Sydney in the early 1990s and fell in love with the&lt;br /&gt;Magma project.  I guess David Kohel told John Cannon about me in 1999,&lt;br /&gt;and Allan happen to be visiting Berkeley for a conference, so Allan&lt;br /&gt;and I met.  We ended up talking a huge amount over 3 days.  Allan&lt;br /&gt;answered my every question about the language and the system---usually&lt;br /&gt;with an answer about how he had implemented it that way for a&lt;br /&gt;certain reason.  So within a few days I knew Magma well enough to be&lt;br /&gt;quite productive in it.  Also, Allan gave me some hints about why&lt;br /&gt;linear algebra was so fast: together with polynomial and integer&lt;br /&gt;arithmetic, asymptotically fast linear algebra was one of his main&lt;br /&gt;interests.  He explained an exciting array of algorithms, many of&lt;br /&gt;which he had developed or---more importantly---made practical.&lt;br /&gt;There were dozens of tricks that I had never heard of, such as&lt;br /&gt;rational reconstruction, multimodular algorithms, p-adic algorithms,&lt;br /&gt;etc., which were far beyond what I had done with HECKE, or seen in any&lt;br /&gt;other software.  And they meant that it would be possible to push my&lt;br /&gt;modular forms computations much farther.  All I had to do was rewrite&lt;br /&gt;HECKE in Magma.&lt;br /&gt;&lt;br /&gt;It was my last year of graduate school at Berkeley, and I probably&lt;br /&gt;should have been writing my thesis, but instead John Cannon flew me&lt;br /&gt;down to Sydney, Australia, to work with the Magma group for a month&lt;br /&gt;and do a complete new implementation of all the algorithms in HECKE on&lt;br /&gt;top of Magma.  I shared an office with Claus Fieker, a German who has&lt;br /&gt;implemented a large amount of the algebraic number theory in Magma,&lt;br /&gt;among other things.  As I started doing this, I had some serious&lt;br /&gt;concerns, including: Magma did not allow users to define their own&lt;br /&gt;types (or classes), there is no exception handling, there is no ``eval&lt;br /&gt;statement", no way for users to write compiled code, Magma is closed&lt;br /&gt;source, and Magma is not free.  I raised all of these concerns with&lt;br /&gt;Cannon and others, and was assured at the time that they would all be&lt;br /&gt;addressed really soon, except the free part.  Regarding free, they&lt;br /&gt;said that I could give copies of Magma to whoever I wanted, so long as&lt;br /&gt;I checked with John Cannon first.&lt;br /&gt;&lt;br /&gt;I don't remember why exactly, but I remember once during that month in&lt;br /&gt;1999 going on a walk through the park near the U Sydney campus near a&lt;br /&gt;pond of ducks, sitting on a bench, and realizing that I was making a&lt;br /&gt;huge sacrifice of my freedom as a researcher by going down this path.&lt;br /&gt;Magma was not open source---John Cannon had absolute control over the&lt;br /&gt;system.  Magma was not free.  And as a language, Magma was&lt;br /&gt;significantly behind C++.  It didn't even have a sensible notion of&lt;br /&gt;scope, and one added new data types by entering entries in big tables,&lt;br /&gt;then recompiling the kernel.  I asked Cannon why it was so far behind,&lt;br /&gt;and he explained that the grants he was able to secure simply wouldn't&lt;br /&gt;pay for language design.  The people who supported Magma with funding&lt;br /&gt;(mainly granting agencies) would only support implementing and&lt;br /&gt;optimizing mathematical algorithms, and the license fees only paid&lt;br /&gt;enough to support ``maintenance", which mainly meant the person who&lt;br /&gt;collected the license fees and distributed Magma via ftp.  Ten years&lt;br /&gt;later the Magma language has hardly improved at all.  They finally&lt;br /&gt;have exception handling, but still no user defined types, etc., etc.&lt;br /&gt;The library of functionality implemented in Magma is huge though; the&lt;br /&gt;issues with the language didn't stop people from implementing many&lt;br /&gt;exciting algorithms, which have supported huge amounts of research in&lt;br /&gt;number theory and other areas.&lt;br /&gt;&lt;br /&gt;I sat down on that park bench, and realized what a dangerous path I&lt;br /&gt;was taking in giving up so much freedom so early in my career.  I&lt;br /&gt;resolved at that moment not to do it.  At that moment I started&lt;br /&gt;designing what would eventually become Sage.  I started thinking about&lt;br /&gt;the language I would implement (I had taken a course in writing&lt;br /&gt;interpreters when I was a student), about implementing all the linear&lt;br /&gt;algebra algorithms Allan had hinted at (but given no details), etc.&lt;br /&gt;I then realized that if I did this, I would have to do it by myself,&lt;br /&gt;since almost everybody I knew used Magma, and would consider my plan&lt;br /&gt;too difficult and pointless.  I wouldn't get to do number theory for&lt;br /&gt;years.  My spirit broke.  And Cannon told me that many of my issues&lt;br /&gt;with Magma would be addressed within a year.&lt;br /&gt;&lt;br /&gt;I spent the next 5 years writing and using Magma.  I gave dozens and&lt;br /&gt;dozens of talks all over, and convinced anybody who wanted to do&lt;br /&gt;computations with modular forms that Magma was the way to go.  I gave&lt;br /&gt;away free copies of Magma (with John Cannon's official blessing),&lt;br /&gt;taught undergraduate courses using Magma, and was generally very&lt;br /&gt;productive.  Also in 2003, I had a real job and money, so I started&lt;br /&gt;forming this philosophy of software, where I would judge what software&lt;br /&gt;I used purely based on capability and functionality, and not on price&lt;br /&gt;or openness.  I started using Microsoft Windows fulltime, since it&lt;br /&gt;best supported my PDA and had the widest range of software.  I bought&lt;br /&gt;some $500 (with educational discount) suite of Adobe software for&lt;br /&gt;video editing, photos, vector graphics, etc.  And of course I used&lt;br /&gt;Magma.  I was a well paid academic at a well-endowed university&lt;br /&gt;(Harvard), and wanted the best that money could buy.&lt;br /&gt;&lt;br /&gt;In 2002, William Randolph Hearst III also donated money to Harvard to&lt;br /&gt;buy me a cluster computers, and by 2003, I wanted to easily script&lt;br /&gt;running lots of computations in parallel.  Since Magma didn't have any&lt;br /&gt;parallel capabilities, I stumbled on some language called ``Python"&lt;br /&gt;(Version 2.3), which looked a lot like Magma, but was designed for&lt;br /&gt;general purpose scripting.  I started using it to run many&lt;br /&gt;computations in parallel on that cluster.  It was the best tool I&lt;br /&gt;could find for the job.&lt;br /&gt;&lt;br /&gt;I also started working much harder on making the number theory data I&lt;br /&gt;was computing with Magma available online, and naturally I turned to&lt;br /&gt;Python.  Dimitar Jetchev (a Harvard undergrad) and I wrote Python code&lt;br /&gt;to make the data easily queryable via a web interface, and also wrote&lt;br /&gt;code that made it so one could do computations in Magma (and PARI in&lt;br /&gt;some cases) over the web.  One incarnation of this is hosted on the&lt;br /&gt;Magma website: &lt;a href="http://magma.maths.usyd.edu.au/calc/"&gt;calc&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;As I learned about Python, a funny thing happened.  I had by this&lt;br /&gt;point developed a large list of issues with Magma.  For example, the&lt;br /&gt;documentation and examples in the Magma reference manual aren't&lt;br /&gt;automatically tested to ensure they give the claimed output, and they&lt;br /&gt;often get out of sync with the actual code.  Python is in many ways&lt;br /&gt;similar to Magma -- the language itself feels somewhat similar, and it&lt;br /&gt;has the same ``batteries included" philosophy.  The surprising thing&lt;br /&gt;was that Python had solved the dozens of major problems I had with&lt;br /&gt;Magma!  I was excited about this in 2003, and so during my next (and&lt;br /&gt;last) trip to work with the Magma group in Sydney, and started trying&lt;br /&gt;to incorporate these solutions into my new Magma code, and to explain&lt;br /&gt;what I had learned to John and others.  Right after I returned from&lt;br /&gt;Sydney, I recall excitedly explaining all of this to David Goldschmidt&lt;br /&gt;at a reception at an AMS meeting.    &lt;br /&gt;&lt;br /&gt;I was quite surprised when a month or two later, in early 2004, John&lt;br /&gt;Cannon really soundly rejected my ideas and even had one of his&lt;br /&gt;employees rewrite my new modular abelian varieties code to get rid of&lt;br /&gt;them.  In retrospect, now that I run a large software development&lt;br /&gt;project, I can understand why he didn't get what I was doing.  But I&lt;br /&gt;was really suprised then.  Second, I went to a big Magma conference at&lt;br /&gt;IHP in Paris, where Manjul Bharghava (a young professor at Princeton),&lt;br /&gt;me, and many other people gave some series of talks.  I recall&lt;br /&gt;listening to Manjul's talk as he described a research problem he was&lt;br /&gt;working on, and during his talk he explained that the whole thrust of&lt;br /&gt;his research was seriously stymmied because Magma is closed source.&lt;br /&gt;He needed to adapt some relatively minor part of the some algorithm in&lt;br /&gt;Magma related to quadratic forms, and simply couldn't due to it not&lt;br /&gt;being in the interpreter level of Magma.  This just didn't seem right.&lt;br /&gt;&lt;br /&gt;I also had lunch with John Cannon during that workshop, where he&lt;br /&gt;explained some big plans he had to edit a huge sequence of volumes&lt;br /&gt;about the mathematics behind algorithms implemented in Magma.  I&lt;br /&gt;suggested that it would be nice if these were freely available, and he&lt;br /&gt;did not think that would be possible.  He made good on his idea, and I&lt;br /&gt;actually published a paper in the first such volume:&lt;br /&gt;&lt;a href="http://wstein.org/papers/bsdmagma/"&gt;bsdmagma&lt;/a&gt;.  I wrote that paper in Windows&lt;br /&gt;using Microsoft Word (and converted to LaTeX using WinEdt, a non-free&lt;br /&gt;LaTeX frontend, only at the very end)!&lt;br /&gt;&lt;br /&gt;Finally, at that IHP workshop I learned two other things.  First, I&lt;br /&gt;learned that a workshop is an incredibly efficient way to develop&lt;br /&gt;mathematical software, far more efficient than the Magma model of&lt;br /&gt;hiring people for months at a time and flying them to Sydney, and&lt;br /&gt;certainly vastly more efficient than what Maple, Mathematica, and&lt;br /&gt;Matlab do, which costs literally costs hundreds of millions of dollars&lt;br /&gt;per year.  Second, I recall overhearing conversations about the Magma&lt;br /&gt;language during tea breaks by some locals who were interested in the&lt;br /&gt;workshop, but had not drank the Magma koolaid, and in these&lt;br /&gt;conversations it became clear that I wasn't the only person that found&lt;br /&gt;the Magma language to be deficient.&lt;br /&gt;&lt;br /&gt;I started reading slashdot in early 2004, mainly for the interesting&lt;br /&gt;tech news, and the comments kept mentioning ``open source", which was&lt;br /&gt;honestly something I had paid almost no attention to until then.&lt;br /&gt;Intrigued I decided to look around and see how open source mathematics&lt;br /&gt;software had done since I had abandoned it in 1999.  NTL was no longer&lt;br /&gt;being actively developed, the LiDIA project was nearly dead, PARI&lt;br /&gt;hadn't changed much (except to break all my old code), but with some&lt;br /&gt;more algorithms for relative number fields.  So in five years, the&lt;br /&gt;situation with the open source number theory software environment had&lt;br /&gt;got worse.  I realized that I was probably partly to blame, having&lt;br /&gt;tried to convince every number theorist I knew to use Magma, and often&lt;br /&gt;given them free access to ensure they could.  I had helped hook a&lt;br /&gt;generation. &lt;br /&gt;&lt;br /&gt;About this time I was also writing an elementary number theory book&lt;br /&gt;(which eventually became this book: &lt;a href="http://wstein.org/ent/"&gt;ent&lt;/a&gt;).  I had&lt;br /&gt;planned to have a chapter about number theory using each of&lt;br /&gt;Mathematica, PARI, Magma, and Maple.  I had the first three programs,&lt;br /&gt;but didn't have access to Maple.  Somebody suggested that being a&lt;br /&gt;faculty member and writing a book should be a good argument for Maple&lt;br /&gt;to send me a free copy, so I contacted them.  A person from Maplesoft&lt;br /&gt;called me back, and explained that though I was writing a book with a&lt;br /&gt;chapter on Maple, they could not give me a free copy.  However, they&lt;br /&gt;could give me the special academic discount of 500 dollars.  I asked&lt;br /&gt;if he could do better, and he called me back the next day and said:&lt;br /&gt;``If you can get 4 of your colleagues to also buy Maple at 250&lt;br /&gt;dollars/each then I can sell you Maple for 250 dollars."  I was&lt;br /&gt;offended, so I ``obtained'' a ``trial'' copy, and started writing my&lt;br /&gt;chapter anyways.  I started trying all the same things as I had easily&lt;br /&gt;done in PARI and Magma, e.g., checking primality of numbers, etc.  I&lt;br /&gt;was totally surprised to find that Maple was terrible, being massively&lt;br /&gt;slower than Pari, Magma or Mathematica for most elementary number&lt;br /&gt;theory computations relevant to my book.  (Maplesoft was bought by&lt;br /&gt;some Japanese company a few months ago, by the way.)&lt;br /&gt;&lt;br /&gt;I also installed Linux in a virtual machine (under Windows), to see&lt;br /&gt;what all the fuss was about, and found I started using Linux all the&lt;br /&gt;time instead of Windows, because the software was better (even Magma&lt;br /&gt;runs much better under Linux than Windows).  I deleted Windows and&lt;br /&gt;installed Linux.  I was also starting to definitively realize that my&lt;br /&gt;huge list of problems with Magma would never, ever get resolved, and&lt;br /&gt;was getting increasingly frustrated by these problems because Python&lt;br /&gt;didn't have them.  &lt;br /&gt;&lt;br /&gt;I started talking a lot with Thomas Barnet-Lamb about a crazy idea to&lt;br /&gt;create a new open source math software system with readable&lt;br /&gt;implementations of algorithms, and nothing hidden in some stupid&lt;br /&gt;proprietary layer.  Thomas was then a first year Harvard grad student&lt;br /&gt;who had won some international computer programming competition, so&lt;br /&gt;I figured he would enjoy talking about software.  I also talked a lot&lt;br /&gt;with Dylan Thurston about this crazy idea; Dylan had started grad&lt;br /&gt;school at the same time as me at Berkeley, graduated the same time,&lt;br /&gt;and had the same first two jobs as me, was also an Assistant&lt;br /&gt;Professor.  Both Thomas and Dylan gave me many ideas for programming&lt;br /&gt;languages to consider, including OCaml (which Thomas liked), Haskell&lt;br /&gt;(which Dylan was a huge fan of), etc.  After having used Magma for&lt;br /&gt;years, with its highly optimized algorithms, I desperately needed a&lt;br /&gt;fast language.  But I also wanted a language that was easy to read,&lt;br /&gt;and that mathematicians could pick up without too much trouble, since&lt;br /&gt;I wanted people like Manjul to someday use this system and not have&lt;br /&gt;their research cut off.  And I knew from experience that unreadable&lt;br /&gt;source code is no better than closed source.  &lt;br /&gt;&lt;br /&gt;I'm not going to go into negatives of any languages.  Though I used&lt;br /&gt;Python a lot, for a long time I didn't consider it seriously at all&lt;br /&gt;for this crazy project, since I tried implementing some basic&lt;br /&gt;arithmetic algorithms in Python and found that they were vastly too&lt;br /&gt;slow to compete with Magma (or C).  I had also tried quite hard to use&lt;br /&gt;SWIG to make C++ available in Python, but SWIG is extremely frustring,&lt;br /&gt;and has horrible performance (due to multiple layers of wrapping), at&lt;br /&gt;least compared to what Magma could do.  &lt;br /&gt;&lt;br /&gt;In October 2004, I was flying back from Europe (the Paris Magma&lt;br /&gt;conference) and started reading the Python/C API reference manual&lt;br /&gt;straight through.  I realized that Python is far, far more than just&lt;br /&gt;an interpreter.  It is a C library that implements everything you&lt;br /&gt;need, and has a well defined and well documented API.  I did some&lt;br /&gt;sample benchmarks on the plane, and found not surprisingly that I&lt;br /&gt;could write code as extensions to Python that was just as fast as&lt;br /&gt;anything one could write for Magma by modifying the Magma kernel,&lt;br /&gt;since under the hood, both were written in C.  Also, on the flight, I&lt;br /&gt;realized that because the Python/C interface uses reference counting,&lt;br /&gt;it would be vastly easier to write the C extensions I would need using&lt;br /&gt;some sort of language I would design.  I got home and somehow stumbled&lt;br /&gt;onto Pyrex, which was exactly what I was planning to write.  I tried&lt;br /&gt;it out, did benchmarks, and realized that I had a winner.&lt;br /&gt;&lt;br /&gt;With Pyrex and Python, I could implement algorithms and make them as&lt;br /&gt;fast as anything in Magma, assuming I could figure out the right&lt;br /&gt;algorithm.  Moreover, the dozens of issues I had with Magma, many of&lt;br /&gt;which were simply a function of them not having the resources to do&lt;br /&gt;language development, were already solved in Python.  And Python would&lt;br /&gt;continue to move forward with no work from me.  It was mid-2004 and&lt;br /&gt;because of Python, the overall software ecosystem was much better than&lt;br /&gt;in 1999, despite open source number theory software having not moved&lt;br /&gt;forward much.  &lt;br /&gt;&lt;br /&gt;I started going to (and sometimes hosting) the Boston Python user&lt;br /&gt;group meetings, which was quite large, and gave me much useful&lt;br /&gt;feedback.  And I decided it was time to move past my test and&lt;br /&gt;prototype stage and get to work.  My plan, as I had explained it to&lt;br /&gt;Thomas, was to create a complete new system from the ground up using&lt;br /&gt;Python + Pyrex.  All the code would have an easy to read Python&lt;br /&gt;implementation that was well documented, in some cases there would be&lt;br /&gt;a much faster Pyrex implementation of the same code, etc.  With my&lt;br /&gt;naive plan in hand, I sat down with the main elliptic curves file of&lt;br /&gt;the PARI source code, and started to translate.   &lt;br /&gt;&lt;br /&gt;I think I made it through one function.  Where some might have&lt;br /&gt;doggedly persisted for years with such an approach, I quickly ran out&lt;br /&gt;of patience.  In fact, when it comes to software and programming I can&lt;br /&gt;be extremely impatient.  I realized that my entire plan was insane,&lt;br /&gt;and would take too long.  I had discussions with Thomas, Dylan, and&lt;br /&gt;others, and everybody I knew who was seriously into number theory&lt;br /&gt;computation was using Magma, so I realized that I was going to have to&lt;br /&gt;do this entire project myself.  So I realized translating was doomed.&lt;br /&gt;Somehow, even with all my experience, I had massively underestimated&lt;br /&gt;the complexity of the algorithmic edifice that is any serious&lt;br /&gt;mathematical software system.&lt;br /&gt;&lt;br /&gt;I read the PARI C API reference, and used Pyrex to write a wrapper so&lt;br /&gt;that I could call some basic PARI functions from Python. I implemented&lt;br /&gt;basic rational and integer types using Pyrex and GMP, and the&lt;br /&gt;performance was reasonable.  One day, I was using Matplotlib (a Python&lt;br /&gt;library) to draw some plots for Barry Mazur that involved explicit&lt;br /&gt;computation with the incomplete Gamma function, and was frustrated&lt;br /&gt;because neither PARI nor Magma had an implementation of this special&lt;br /&gt;function at the time.  Harvard had a Mathematica site license, so I&lt;br /&gt;had a copy of Mathematica, and I wrote code using the pexpect Python&lt;br /&gt;library to hold open a single Mathematica session and use it to&lt;br /&gt;compute the incomplete Gamma function.  Problem solved.  This was when&lt;br /&gt;the interfaces between Sage and other mathematics software systems was&lt;br /&gt;born.&lt;br /&gt;&lt;br /&gt;In January 2005, I was at the AMS meeting in Atlanta, Georgia, hacking&lt;br /&gt;on my code, and David Joyner walked up to me and asked what I was&lt;br /&gt;doing.  Until then, I had not shown my Python/Pyrex math software&lt;br /&gt;project to people.  There were a few reasons, including feeling sure&lt;br /&gt;that it was massively too difficult to pull off, that working on&lt;br /&gt;something like this would seriously piss off John Cannon, etc.  But&lt;br /&gt;feeling brave, I showed David what I was doing and I was surprised&lt;br /&gt;that he found it interesting.  I promised to post a copy online, which&lt;br /&gt;he could download.    &lt;br /&gt;&lt;br /&gt;David Joyner is the first to admit that it's a good idea to make&lt;br /&gt;software easy for him!  So I had to make it easy for him to download&lt;br /&gt;and install my program, which I called Manin at the time (after one of&lt;br /&gt;my favorite mathematicians).  My target audience wasn't ``Debian"; it&lt;br /&gt;wasn't ``Python programmers"; it wasn't elite hackers---it was David&lt;br /&gt;Joyner.  I had to make this program trivial for him to install, work&lt;br /&gt;with, develop, etc.  I thought about how it had literally taken me&lt;br /&gt;huge amounts of time just to build Python, GMP, PARI, etc. all from&lt;br /&gt;source in a directory for development, and realized that there was no&lt;br /&gt;way in hell David would get anywhere on Manin if I told him that his&lt;br /&gt;first step was to figure out how to build all those programs, then get&lt;br /&gt;back to me.  So I setup something that would do it all automatically&lt;br /&gt;in a self contained way.  He tried it, it ``just worked", and he got&lt;br /&gt;really excited and started writing code for Manin.  David is a coding&lt;br /&gt;theorist, and wanted group theory and coding theory functionality in&lt;br /&gt;Manin, but didn't want to write it all himself from scratch, so he&lt;br /&gt;asked in email about making Manin and GAP talk to each other somehow.&lt;br /&gt;I showed him my pexpect code for controlling Mathematica, and he&lt;br /&gt;adapted it to create a GAP interface.   &lt;br /&gt;&lt;br /&gt;David also works at the US Naval Academy where he evidently teaches a&lt;br /&gt;lot of Calculus and Differential Equations courses.  He was having so&lt;br /&gt;much fun with Manin, he asked about adding something to do symbolic&lt;br /&gt;calculus to Manin.  This was 2005, and I personally had never used any&lt;br /&gt;symbolic calculus software aside from Mathematica and Maple 12 years&lt;br /&gt;earlier, since I viewed computational symbolic calculus as pretty much&lt;br /&gt;irrelevant for most computational number theory, and the Calculus I&lt;br /&gt;had taught never required a computer since computers weren't allowed&lt;br /&gt;on exams.  (I now think no computational technique should be a priori&lt;br /&gt;viewed as irrelevant to research in number theory!)  So I asked David&lt;br /&gt;about the available open source options, and he said they were Axiom&lt;br /&gt;and Maxima, neither of which I had ever heard of.  I can't remember&lt;br /&gt;how we chose Maxima instead of Axiom, but it was some combination of&lt;br /&gt;Maxima being easier to build, easier to understand, and having about&lt;br /&gt;1000 times as many users.  In any case, like with PARI, GMP, and&lt;br /&gt;Python, I added Maxima and GAP to the Manin distribution.  I also&lt;br /&gt;changed the name from Manin to SAGE = Software for Algebra and&lt;br /&gt;Geometry Experimentation.&lt;br /&gt;&lt;br /&gt;David also convinced me Sage needed commutative algebra.  At first, he&lt;br /&gt;talked to people and tried to implement everything from scratch, but&lt;br /&gt;even the resulting arithmetic was dreadfully slow.  Groebner basis&lt;br /&gt;would be a nightmare waiting on the horizon.  We were both impatient,&lt;br /&gt;so we decided to try to find an open source program already out here,&lt;br /&gt;and just use it.  There were two choices: Macaulay 2 and Singular,&lt;br /&gt;which had a lot of overlap in functionality.  For what we wanted---basic &lt;br /&gt;commutative algebra---they both did all we needed.  Singular&lt;br /&gt;built from source easily in a few minutes on every computer I cared&lt;br /&gt;about.  Macaulay 2 was ridiculously hard to build and took a long&lt;br /&gt;time.  I think based mostly on that, we chose Singular.  Also, it was&lt;br /&gt;encouraging that Singular had a relatively large development team, and&lt;br /&gt;did better in some benchmarks I tried.&lt;br /&gt;&lt;br /&gt;At the same time as all this, I was traveling a lot and interviewing&lt;br /&gt;for tons of tenure/tenure track jobs all over the place.  I got some&lt;br /&gt;job offers with tenure, and suddenly had the crazy idea that if I&lt;br /&gt;worked fulltime on SAGE for a year two, my career could not be&lt;br /&gt;destroyed.  This really encouraged me.  My number theory research&lt;br /&gt;slowed a lot, and I spent all my extra time on SAGE for a while.&lt;br /&gt;&lt;br /&gt;Remember David Kohel, who six years ago in 1999 first introduced me to&lt;br /&gt;Magma?  It turns out that like me he spent years and years writing a&lt;br /&gt;large library of software on top of Magma for number theory and&lt;br /&gt;cryptography research.  However, at some point he had a fairly serious&lt;br /&gt;falling out with the Magma group, whose details I will omit.  Suffice&lt;br /&gt;to say, like me he was motivated to at least look for other options.&lt;br /&gt;He started building and using Sage, and started doing huge amounts of&lt;br /&gt;work on Sage as well, e.g., introducing morphisms and categories&lt;br /&gt;systematically into Sage, and implementing tons of code related to&lt;br /&gt;elliptic curves, algebraic varieties, etc.  David Kohel was a&lt;br /&gt;Biologist as an undergraduate and has an amazing eye for general&lt;br /&gt;structure. He also had many technical issues with Magma, which were&lt;br /&gt;mostly different than mine.  For example, he felt that the Magma&lt;br /&gt;developers had made a mistake with the design of morphisms, and he&lt;br /&gt;didn't want Sage to make the same mistakes.  And he was right to&lt;br /&gt;worry, since for things I didn't care too much about, I would usually&lt;br /&gt;just copy Magma... or as David would say, ``copy Magma's mistakes".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I moved to San Diego and Joe Wetherell who first introduced me to&lt;br /&gt;modular symbols in 1997 also got involved in Sage development, though&lt;br /&gt;mostly from the conversation point of view.  Joe had long ago quit&lt;br /&gt;grad school to start a software company in the early 1990s, then&lt;br /&gt;retired from that and went back to grad school, so he had a fairly&lt;br /&gt;mature perspective on software development, and he knew a huge amount&lt;br /&gt;about number theory and optimized algorithms.  So 2005 was a long,&lt;br /&gt;long year in which David Kohel in Australia, David Joyner in Maryland,&lt;br /&gt;and me in San Diego, wrote code.&lt;br /&gt;&lt;br /&gt;At the end of 2005, the three of us had written a ton of code,&lt;br /&gt;integrated numerous components togethers, and finally had something.&lt;br /&gt;On December 6, Jaap Spies mentioned Sage on the sci.math.symbolic&lt;br /&gt;newsgroup, in response to which some guy named Richard Fateman&lt;br /&gt;declared Sage a curiosity and made some unencouraging assertions about&lt;br /&gt;the way the world works (regarding users, funding, etc.):&lt;br /&gt;&lt;br /&gt;   &lt;a href="http://mathforum.org/kb/message.jspa?messageID=4132045&amp;tstart=0"&gt;mathforum&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I was certain deep down inside that Sage would fail anyways, that what&lt;br /&gt;we wanted to do with Sage was totally impossible, so Fateman's&lt;br /&gt;comments couldn't discourage me further.  I just didn't care that Sage&lt;br /&gt;was doomed.  I couldn't help pushing further.&lt;br /&gt;&lt;br /&gt;John Cannon found out about Sage, maybe as a result of the postings on&lt;br /&gt;sci.math.symbolic, and right before Christmas in 2005 he sent me this&lt;br /&gt;email:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;---------------------------------------------------------------&lt;br /&gt;Date: Mon, 19 Dec 2005 16:54:09 -0800&lt;br /&gt;From: "John Cannon" &lt;john@maths.usyd.edu.au&gt;&lt;br /&gt;Subject: Magma calculator&lt;br /&gt;William,&lt;br /&gt;&lt;br /&gt;This is to formally advise you that your permission to run a&lt;br /&gt;general-purpose calculator based on Magma ends on Dec 31, &lt;br /&gt;2005. This was originally set up at your request so students &lt;br /&gt;in your courses at Harvard could have easy access to Magma.&lt;br /&gt; &lt;br /&gt;Please confirm receipt of this letter.&lt;br /&gt;Wishing you a happy Christmas,&lt;br /&gt;John&lt;br /&gt;---------------------------------------------------------------&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This single email seriously scared me.  Though I was working on Sage&lt;br /&gt;very hard for nearly a year at this point, I honestly didn't then&lt;br /&gt;expect Sage to really be able to replace Magma for me.  Magma was the&lt;br /&gt;commercially funded result of fulltime work over decades (really&lt;br /&gt;starting in 1973 with the first version of Cayley).  The amount of&lt;br /&gt;work to get from what I had with Sage in December 2005 to what I had&lt;br /&gt;with Magma in December 2000, was still absolutely momentous.  I didn't&lt;br /&gt;even know if it could be done by a single human being.  Moreover, as&lt;br /&gt;far as I could tell many of the critical linear algebras algorithms I&lt;br /&gt;needed (to make the difference between a calculation taking a minute&lt;br /&gt;or a year) existed only in the secret kernel of Magma and Allan&lt;br /&gt;Steel's head, and they were going to stay locked there forever as far&lt;br /&gt;as I could tell.  For example, in June 2004 (before Sage existed),&lt;br /&gt;Allan and I were together at the ANTS VI conference.  I started asking&lt;br /&gt;Allan to explain some of the algorithms, and he would explain things&lt;br /&gt;to a point, but not nearly enough to do an actual implementation.  And&lt;br /&gt;he gave me this look, like he knew I was trying to get something out&lt;br /&gt;of him.&lt;br /&gt;&lt;br /&gt;Isn't it weird that mathematics can be done that way?  In 2004, almost&lt;br /&gt;everybody in the world doing serious computations with elliptic&lt;br /&gt;curves, modular forms, etc., were using Magma.  Magma was the industry&lt;br /&gt;standard, Magma had won for the forseable future.  David Kohel and I&lt;br /&gt;were a big reason why.  And yet what kind of mathematics is it, when&lt;br /&gt;much of my work fundamentally depends on a bunch of secret algorithms?&lt;br /&gt;That's just insane.  Moreover, it turns out that these algorithms I'm&lt;br /&gt;alluding to are really beautiful (and they are now standard and in&lt;br /&gt;some cases better than what's in Magma, in my opinion, thanks to great&lt;br /&gt;work of people like Giesbrecht, Perent, Kaltofen, Storjohann,&lt;br /&gt;Saunders, Albrecht, etc.).   &lt;br /&gt;&lt;br /&gt;Anyway, John Cannon's email above seriously scared me.  I wasn't in&lt;br /&gt;any way confident that Sage would ever replace Magma for my work and&lt;br /&gt;teaching, and I had big plans involving interactive mathematical web&lt;br /&gt;pages.  These plans were temporarily on hold as I was drawn into&lt;br /&gt;Sage. But there were still there.  What John did with that email is&lt;br /&gt;tell me, in no uncertain terms, that if I was going to create those&lt;br /&gt;interactive mathematical web pages, they couldn't depend on&lt;br /&gt;Magma. ``This is to formally advise you that your permission to run a&lt;br /&gt;general-purpose calculator based on Magma ends."  I was scared.  It&lt;br /&gt;was also the first time I saw just how much power John Cannon had over&lt;br /&gt;my life and over my dreams.  That email was sent on a whim.  I hadn't&lt;br /&gt;got any official permission to run that Magma calculator for a&lt;br /&gt;specific amount of time (just open ended permission).  What John made&lt;br /&gt;crystal clear to me was that he could destroy my entire longterm plans&lt;br /&gt;on a whim.  I looked around for other options, and there just weren't&lt;br /&gt;any.  Sage had to succeed.  But still I was certain that it just&lt;br /&gt;wasn't humanly possible, given that I had to do almost all the work,&lt;br /&gt;with limited funding and time.&lt;br /&gt;&lt;br /&gt;At this time I had an NSF grant, and also startup money at UCSD, hence&lt;br /&gt;I could rebudget some of my NSF grant.  David Joyner suggested that we&lt;br /&gt;run a ``Sage Days", which I guess was named after the East Coast&lt;br /&gt;Computer Algebra Days (ECCAD).  David and I organized the first one,&lt;br /&gt;and David did an amazing job inviting a great cast of speakers,&lt;br /&gt;including Steve Linton (of GAP), Sebastian Pauli (of KANT), etc., and&lt;br /&gt;Joe Buhler who also lives in San Diego made sure we scheduled the&lt;br /&gt;workshop so that a lot of people would show up.  We had Sage Days in&lt;br /&gt;early February, and I released Sage version 1.0 during my talk, which&lt;br /&gt;started the workshop.  The talks went well, people were extremely&lt;br /&gt;enthusiastic about Sage, the coding sprints were intense: the first&lt;br /&gt;version of Sagetex was written, and the current sophisticated GAP&lt;br /&gt;interface was written then by Steven Linton, Kiran Kedlaya and David&lt;br /&gt;Roe wrote that Macaulay 2 interface, and I had the first spark of&lt;br /&gt;insight about how to create the Sage Notebook, after watching a talk&lt;br /&gt;by Robert Kern about some failed attempt to give IPython a notebook&lt;br /&gt;interface.  That was the first time I realized a notebook style&lt;br /&gt;interface had some value.  And Gonzalo Tornaria got us to finally&lt;br /&gt;start using revision control for our source (!), which meant way more&lt;br /&gt;people could easily contribute.  (I had used revision control before&lt;br /&gt;with Magma, but with Sage I had been just taking snapshots regularly.)&lt;br /&gt;&lt;br /&gt;As a direct result of Sage Days 1, development picked up.  Then I&lt;br /&gt;moved to University of Washington (Seattle) two months later.&lt;br /&gt;Somehow, during the summer of 2006 I was invited by MSRI to run a&lt;br /&gt;2-week summer workshop on modular forms for about 40 graduate&lt;br /&gt;students.  I invited David Kohel and a few other speakers.  At this&lt;br /&gt;point, honestly some aspects of Sage sucked.  I had written a massive&lt;br /&gt;amount of code, for really wide range of things.  Power series,&lt;br /&gt;fraction fields, number fields, modular symbols, linear algebra, etc.&lt;br /&gt;I probably should have just used Magma for the workshop, and indeed at&lt;br /&gt;least one speaker entirely did.  But I didn't... and this was a&lt;br /&gt;turning point.  Some of the students, such as David Harvey (grad&lt;br /&gt;student at Harvard), Robert Bradshaw (Seattle), Craig Citro, and many&lt;br /&gt;others, became highly interested in fixing the numerous flaws they ran&lt;br /&gt;into with Sage. After the talks, we had huge all night coding sprints&lt;br /&gt;in the dorm lobby.  Students constantly asked me questions about how&lt;br /&gt;to do things in Sage, and my answer was usually: ``It's easy.  Implement&lt;br /&gt;it and send me a patch!"  They made a t-shirt for the conference with&lt;br /&gt;this quote on it. &lt;br /&gt;&lt;br /&gt;Next we started planning Sage Days 2 in Seattle in late 2006.  This&lt;br /&gt;second Sage Days was also well attended and resulted in major&lt;br /&gt;fundamental development directions.  For example, David Harvey led a&lt;br /&gt;charge to redesign the coercion model and David Roe got obsessed with&lt;br /&gt;implementing every model imaginable of the p-adics (this still isn't&lt;br /&gt;really done over 3 years later).  Sebastian Pauli gave a talk in which&lt;br /&gt;he explained what anybody who takes an algebraic number theory course&lt;br /&gt;knows (or pays attention to Weil), which is that there is a number&lt;br /&gt;field and function field analogy and that all the algorithms carry&lt;br /&gt;over.  Guess what---Magma has a sophisticated implementation of all&lt;br /&gt;the relevant algorithms in the function field case, due to work of&lt;br /&gt;Florian Hess that built on work of the KANT group and others, and PARI&lt;br /&gt;has absolutely nothing for algebraic number theory over functions&lt;br /&gt;fields.  Sebastian explained that in fact Magma is the only program in&lt;br /&gt;the world that provides both sides of this analogy, I think hoping&lt;br /&gt;that we would do something about this problem.  (Now it is 2009, and&lt;br /&gt;still nothing at all has happened---Magma is the only program in the&lt;br /&gt;world for the function field half of algebraic number theory.  Gees.)&lt;br /&gt;&lt;br /&gt;We had about 13 talks on the first day of Sage Days 2.  At the end of&lt;br /&gt;the day, David Savitt (at student of Richard Taylor, and now a&lt;br /&gt;professor in Arizona) looked at me and declared me insane.&lt;br /&gt;&lt;br /&gt;After Sage Days 2, I spent over 2 very, very painful months&lt;br /&gt;implementing David Harvey's proposed coercion model.  I learned (or&lt;br /&gt;rather, remembered) how difficult certain types of changes to a large&lt;br /&gt;interrelated library can be.  Also, a student from San Diego---Alex&lt;br /&gt;Clemesha---followed me to Seattle, and I paid him fulltime to work on&lt;br /&gt;Sage using my startup money.  He implemented 2d graphics for&lt;br /&gt;mathematicians (instead of scientists, which is what matplotlib&lt;br /&gt;provides), and he also helped a lot with the first version of the Sage&lt;br /&gt;Notebook.  In fact, he was a big Mathematica user before he started&lt;br /&gt;using Sage, and he really missed the Mathematica Notebook, so he&lt;br /&gt;wanted something similar in Sage.  When he used Mathematica, he had a&lt;br /&gt;job programming webpages using webMathematica, so really wanted&lt;br /&gt;something that combined the notebook idea with a webpage.  We came up&lt;br /&gt;with various ideas.  Then I hired an undergraduate, Tom Boothby, who&lt;br /&gt;had just quit a 6-year career in web programming to go back to&lt;br /&gt;college.  Together, the three of us figured out how to write AJAX&lt;br /&gt;applications, and the first version of the notebook was born.  &lt;br /&gt;&lt;br /&gt;It was a controversial decision at the time to write a webapp&lt;br /&gt;instead of a traditional local GUI application.  There were many&lt;br /&gt;reasons we made this choice, but for me it was mainly because (1) I&lt;br /&gt;had written some serious local GUI applications before and knew that&lt;br /&gt;they are not easy to write, not portable, and hard to build from&lt;br /&gt;source, and (2) I had tried out wxMaxima (the local GUI maxima&lt;br /&gt;interface) and was just totally shocked to see how bad it was, due to&lt;br /&gt;having to reinvent the wheel---they would have to implement font&lt;br /&gt;dialogs, tabs, everything from scratch; in contrast, with a web&lt;br /&gt;application much of that comes for free.  So my motivation was&lt;br /&gt;entirely to create a desktop application quickly.  That it happen to&lt;br /&gt;later make it possible for people to collaborate easily, use a Sage&lt;br /&gt;notebook over the web, etc., is a nice bonus. And, it's clear by now&lt;br /&gt;that web applications (like Facebook, Gmail, etc.) are extremely&lt;br /&gt;popular now, and will only get way more popular in the future.&lt;br /&gt;&lt;br /&gt;In 2007, the Sage project started really picking up steam.  Bobby&lt;br /&gt;Moretti, another UW undergraduate, got obsessed with making it&lt;br /&gt;possible to actually do symbolic calculus in Sage itself.  Until&lt;br /&gt;Bobby's code was added to Sage in mid 2007, absolutely all symbolic&lt;br /&gt;Calculus in Sage had to be done via explicit unnatural calls to&lt;br /&gt;Maxima, and involved embarassing and confusing conversions.  Bobby, me&lt;br /&gt;and others spent a lot of work designing Sage's first symbolic&lt;br /&gt;calculus interface, and Bobby wrote a pure Python ``proof of concept"&lt;br /&gt;reference implementation that used Maxima via a pseudotty behind the&lt;br /&gt;scenes for everything.  This took him months, and probably had a&lt;br /&gt;negative impact on all other aspects of his life.  But he heroically&lt;br /&gt;pulled it off.  It went into Sage and changed things&lt;br /&gt;dramatically---suddenly, Sage could actually be used for some&lt;br /&gt;undergraduate courses.  This increased interest in Sage dramatically.&lt;br /&gt;&lt;br /&gt;A few months later, in November 2007, Sage was nominated for the&lt;br /&gt;Trophees du Libre, and Martin Albrecht presented Sage at the meeting&lt;br /&gt;for finalists.  We won first place in the Scientific Software&lt;br /&gt;category.  This resulted in a blitz of publicity (e.g., several&lt;br /&gt;slashdot articles, and articles in papers around the world in many&lt;br /&gt;languages), and greatly increased the number of Sage downloads.&lt;br /&gt;&lt;br /&gt;Around this time we also have Sage Days 5 at the Clay Mathematics&lt;br /&gt;Institute, and Craig Citro convinces us to switch to a 100% peer&lt;br /&gt;review and 100% doctest policy on all new Sage code.  Also, I hire&lt;br /&gt;Michael Abshoff to do release management for one year, which&lt;br /&gt;temporarily frees me up to work more on coding, grant proposals, and&lt;br /&gt;my own research.&lt;br /&gt;&lt;br /&gt;There is of course much, much more to this story.  But it's too&lt;br /&gt;recent, and sometimes a story shouldn't be told until enough time has&lt;br /&gt;elapsed.</description><link>http://sagemath.blogspot.com/2009/12/mathematical-software-and-me-very.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-3650631912846822527</guid><pubDate>Mon, 12 Oct 2009 06:56:00 +0000</pubDate><atom:updated>2009-10-12T00:11:36.930-07:00</atom:updated><title>The Sage Notebook</title><description>The &lt;a href="http://nb.sagemath.org/"&gt;Sage Notebook&lt;/a&gt; is the graphical user interface to the math software &lt;a href="http://sagemath.org/"&gt;Sage&lt;/a&gt;.  The notebook is perhaps somewhat unusual in that it is a web application that people also use locally.  It's a large program that has been written and rewritten a few times since 2006 by myself, Tom Boothby, Alex Clemesha, and many, many other people.&lt;br /&gt;&lt;br /&gt;Supported by an internal grant from University of Washington, I've been working on separating the notebook off from Sage and rewriting many parts of it to improve the robustness and fix subtle issues.   My goal is that the notebook be robust, fast, scalable, and work well outside Sage.  Also, it would be very nice to port it to run natively on Microsoft Windows.&lt;br /&gt;&lt;br /&gt;Nearly two weeks ago I had the Sage notebook stabilized and all known new bugs fixed (after separating it off from sage as a separate program and rewriting the interface stuff).  But I realized that it would be a total nightmare to introduce yet another ("Sage object") storage format, which would make refactoring code extremely painful.    So, I created an "abstract storage layer" and implemented a storage system for everything in the Sage notebook which doesn't use any special Sage-related pickles.  Some data is stored as pickled basic Python objects that can be read from any version of Python with or without Sage installed, but that is it.   Rewriting the notebook to use an abstract storage layer is the sort of thing that at first seems like it will take a day, but then takes more than a week.  Anyway, I did it (with help from Tim Dumol and Mitesh Patel). &lt;br /&gt;&lt;br /&gt;I hope people will test &lt;a href="http://standalone.sagenb.org/"&gt;http://standalone.sagenb.org/&lt;/a&gt;!  Please try it.&lt;br /&gt;&lt;br /&gt;William</description><link>http://sagemath.blogspot.com/2009/10/sage-notebook.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-3295891180613025827</guid><pubDate>Thu, 08 Oct 2009 04:29:00 +0000</pubDate><atom:updated>2009-10-07T21:46:03.771-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>vmware virtualbox</category><title>VirtualBox versus VMware Server</title><description>&lt;a href="http://www.vmware.com/"&gt;VMware&lt;/a&gt; is a program that allows you to (often safely) run several virtual computers on a single physical computer.  I have been using VMware since about 1998, have purchased valid licenses several times with my own money, and have long considered VMware the sort of enterprise level specialized software that was unlikely to be available free and open source anytime in the near future.&lt;br /&gt;&lt;br /&gt;All the web infrastructure for &lt;a href="http://sagemath.org/"&gt;http://sagemath.org&lt;/a&gt; and many related projects was knocked offline for a full day last week due to problems I had with my VMware server installation.  I thus decided to learn the free open source competitor &lt;a href="http://www.virtualbox.org/"&gt;VirtualBox&lt;/a&gt; and see how it compares to VMware, and share some of my experiences with you.   I'm comparing to VMware server running on a very high end Linux host (Sun X4450) to VirtualBox running on the same Linux host.   I vastly prefer VirtualBox now, even though I was a diehard VMware user since 1998.&lt;br /&gt;&lt;br /&gt;Ways VirtualBox is better then VMware Server:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt; Both are free, but VirtualBox is free and open source (GPLv2!), whereas VMware server is "free" and closed source.  It's possible to buy VMware server + more features for thousands of dollars / year, and I even considered it, but I *couldn't* figure out what I would get for my money from the confusing VMware site, despite coming back to it several times.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;VirtualBox is massively better at supporting OS X than VMware server: it is *impossible* (without running yet another virtual machine on my laptop!) to use the VMware server console to connect to remote virtual machines on OS X, since VMware uses a proprietary browser plugin that is only available for Windows and Linux.   In contrast, VirtualBox uses a standard remote desktop protocol, so it is easy to connect to running VirtualBox consoles from any operating system using a range of different remote desktop clients.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;VMware server limits me to 2 cores and 8GB RAM per machine. VirtualBox has no such limitations.   This is a *huge* factor for me, since the host server has 128GB RAM and 24 cores!&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt; If a virtual machines runs under VMware server and uses 4GB RAM (say), then VMware server will silently (and completely hidden) allocate around 4GB of disk space on the host filesystem.   My host server has 128GB RAM, but only a 70GB hard disk.  The net result is that I can't use the resources I have -- I have to run far less machines than I could, or give them less RAM.   VirtualBox doesn't allocate any "secret" disk space at all.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt; The web interface to VMware is extremely flaky and frustrating.  It randomly fails to work with many of my web browsers, I often have to restart it, and it is clunky.   There is no finished web interface to VirtualBox yet, but there is VBoxWeb, which is looks like it will be good when it is finished.   Also, the command line interface to VirtualBox is amazing; I think it is vastly superior to VMware Server's.  Also, there is a Python API for scripting VirtualBox machines.    After spending a day learning VirtualBox, I wrote my own scripts to automatically start from the console all of my virtual machines in the background, and open remote desktop ports for each.  I can easily see what is running using another little script, etc.  With VMware server, even starting 20 machines was a tedious and painful exercise (probably if I paid it would be easier).&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt; The VirtualBox documentation is better.  It doesn't "talk down" to me like I feel VMware's documentation does.  It's clear and useful.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt; VirtualBox is a single program that runs on Solaris, OS X, Linux and Windows.  VMware, in contrast, is several different programs -- VMware player, VMware workstation, VMware server (and several versions of that).  It can be really confusing and frustrating, with artificial limitations put on every program so as to extract your money.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt; VMware is blatantly commercial (they went public a few years ago).  Sun is also commercial, but they have a strong commitment to open source.  Of course, I don't know what will happen with the Oracle acquisition.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt; VMware completely stopped working on my main virtualization server, and despite upgrades, clean installs, etc., I absolutely could not get it to work again.   I had to switch to running it on another computer temporarily.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/ol&gt;</description><link>http://sagemath.blogspot.com/2009/10/virtualbox-versus-vmware-server.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-6962361690983322465</guid><pubDate>Fri, 03 Apr 2009 15:04:00 +0000</pubDate><atom:updated>2009-04-03T08:07:34.204-07:00</atom:updated><title>Technology in Mathematics Education - Panel</title><description>In a few hours I'll be in a panel discussion about technology in mathematics education.  I might say something like the following.&lt;br /&gt;&lt;br /&gt;Math and technology in general: To me mathematics is about solving problems by understanding them more deeply, finding ways to explore them, finding elegant proofs, looking for ways to visualize and compute with deep structure, etc.  Math software is simply another tool or technique that one can use to _massively_ enhance ones ability to solve mathematical problems.  Asking whether or not to use computer technology in mathematics is no different than asking whether or not to use "logical reasoning" or "linear algebra" or any other major tool in the mathematician's toolchest.&lt;br /&gt;&lt;br /&gt;Math and technology in teaching:&lt;br /&gt;&lt;br /&gt;A. Open Source -- I personally feel it is terrible to *train* students mainly to use closed source commercial mathematics software.  This is analogous to teaching students some weird version of linear algebra or calculus where they have to pay a license fee each time they use the fundamental theorem of calculus or compute a determinant.  Using closed software is also analogous to teaching those enthusiastic students who want to learn the proofs behind theorems that it is illegal to do so (just as it is literally illegal to learn *exactly* how Maple and Mathematica work!).  From a purely practical perspective, getting access to commercial math software is very frustrating for many students.  It should be clear that I am against teaching mathematics using closed source commercial software.&lt;br /&gt;&lt;br /&gt;B. Problem solving -- Many students are interested in mathematical software mostly because it allows them to solve *a lot* of problems that are simply impossible to do by hand.  For some (at least me) it transforms math from a tedious, error prone, and frustrating (but addictive) exercise into an exciting exploration of an amazing "virtual" world of interesting problems, ideas, and techniques.  For most people, even before computers, anything but fairly trivial algebra or calculus is nearly impossible to do correctly by hand.  Gauss (1777-1855) spent years counting the 216816 primes up to 3 million... and wrote in a letter in 1849 that there are 216745 such primes.  Any undergrad can type prime_pi(3*10^6) into Sage and get the right answer instantly.&lt;br /&gt;&lt;br /&gt;C. Regarding student skills being lost due to the existence of computers -- If you really want students to be able to do something, e.g., compute integrals without using a computer, give them in class exams on that material.  By far the main complaint I have and hear from both students and professors is that students have too limited skills at using mathematics software.  This situation is ridiculous. Would we give a degree in Software Engineering to a student who has never written a computer program? Why give a degree in techniques of "Mathematical Problem Solving" to a student who can't even use a computer to solve mathematical problems, given that computers are one of the most important basic tools in the mathematician's toolchest.</description><link>http://sagemath.blogspot.com/2009/04/technology-in-mathematics-education.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-980470736776048328</guid><pubDate>Mon, 22 Dec 2008 23:07:00 +0000</pubDate><atom:updated>2008-12-22T15:29:00.718-08:00</atom:updated><title>new hardware!</title><description>I recently received four 24-core &lt;a href="http://www.sun.com/servers/x64/x4450/&lt;br /&gt;"&gt;Sun X4450&lt;/a&gt; with 128GB RAM, and a &lt;a href="http://www.sun.com/servers/x64/x4500/"&gt;Sun X4500&lt;/a&gt; storage box with 8 cores, 32GB RAM, and 24 &lt;b&gt;terabytes&lt;/b&gt; of disk space.  It took literally less than 2 hours to install Ubuntu 8.0.4 LTS server Linux on all the 4450's (about 15 minute each), but several more days to make some sort of transition over to them.  &lt;br /&gt;&lt;br /&gt;The machines are &lt;i&gt;fast&lt;/i&gt;.  Most tests I try run twice as fast on the new machines as on the old sage.math (which was a 1.8Ghz Operton).   &lt;br /&gt;&lt;br /&gt;The first frustrating transition was that I can no longer run Magma on the new boxes, because they have a different MAC address.   I've received one user complaint so far, and expect others, though of course I hope people consider &lt;a href="http://sagemath.org"&gt;using a viable open source alternative&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I installed about 20 operating systems, including most major Linux distros, FreeBSD, and Solaris under vmware server on one of the boxes, and configured them to all use NFS. Unfortunately, we don't have an NIS/NIS+ or OpenLDAP server setup, so only I can login to those boxes :-(.  Setting up NIS or OpenLDAP clients and servers is not for the faint of heart.   Anyway, just installing that many Linuxes and configuring them with build tools and NFS took about two days, including time to download installation media.    Of all the OS's the only one I gave up on was gentoo, which is a &lt;i&gt;complete disaster&lt;/i&gt; (hours of tedious instructions that don't quite work; the live installer crashing; getting the live installer to work, but having vi crash on compilation once it boots up, etc.); that is the worst major operating system I have tried.   According to &lt;a href="http://distrowatch.com/dwres.php?resource=major"&gt;distrowatch&lt;/a&gt;, "&lt;i&gt;Gentoo Linux has lost much of its original glory in recent years. Some Gentoo users have come to a realisation that the time-consuming compiling of software packages brings only marginal speed and optimisation benefits. Ever since the resignation of Gentoo's founder and benevolent dictator from the project in 2004, the newly established Gentoo Foundation has been battling with lack of clear directions and frequent developer conflicts...&lt;/i&gt;"  The failure of Gentoo hopefully helps emphasize the importance of clear direction.&lt;br /&gt;&lt;br /&gt;Anyway, it is very nice having about two dozen cleanly installed OS's with a shared filesystem, all running on very fast hardware. &lt;br /&gt;&lt;br /&gt;We still haven't installed an operating system on the 24 terabyte disk box, and have a lot of configuration work to do.  Fortunately, Tom Boothby is working for me as a sysadmin, so he will do a lot of the hard work.</description><link>http://sagemath.blogspot.com/2008/12/new-hardware.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-7588937417082042312</guid><pubDate>Sat, 29 Nov 2008 03:44:00 +0000</pubDate><atom:updated>2008-11-28T20:51:03.254-08:00</atom:updated><title>Sage Patch Review</title><description>I just spent a lot of time during the last few days refereeing Sage patches in the &lt;a href="http://trac.sagemath.org/sage_trac/" target="_new"&gt;Sage trac server&lt;/a&gt;.  Basically, we got behind and had something like nearly a 100 patches in there that were marked as "[with patch; needs review]", which means that the patch is done, and is just waiting on review.  Some of the patches in this state hadn't been commented on since August!   In many cases they had "bit rotted", which means that they are broken, since related parts of Sage had changed after the batches had been posted.&lt;br /&gt;&lt;br /&gt;In June 2008 at Sage Days 8.5 we had a long meeting and setup a patch referee editor system, but it turned out to be a &lt;b&gt;total failure&lt;/b&gt;.    Our system was setup to be like a journal editor system, except with the addition of a weekly meeting.  Even in person, our one and only meeting was an inefficient experience, and it never worked over irc or email. &lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Review is a Generic Problem&lt;/h3&gt;&lt;br /&gt;Robert Bradshaw recently went to a Google Summer of Code Mentors summit, and told me that the number one problem open source projects have  that was discussed a lot at the summit is with patch review, in particular, with patches not getting reviewed in a timely fashion.  &lt;br /&gt;&lt;br /&gt;Review is also a big problem with mathematics journals, though with journals the turnaround time is expected to be months.  Or even years -- I have one paper that's been in the review process at Mathematics of Computation for 3 years now, and I've almost never gotten a first referee report back from that journal in less than a year from submission time!  But for some reason math journals tend to work.  That said, I had some discussions with a prominent publisher about a journal that had fallen apart because the chief editor had seriously dropped the ball, and said publisher had to spend a massive amount of his own time fixing the situation. &lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Patch Review and Paper Review&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;Reviewing a math paper is a much different experience from reviewing a software patch.  When one reviews a math paper, you basically get a potentially very interesting paper that is at the cutting edge of research, which you would be crazy to not want to read anyways (or you're just going to easily not recommend it for publication).  When you review the paper, you excitedly read it, and if things don't make sense -- or the style is bad, or whatever -- you get to ask the author to explain clearly any point that troubles you, and the author definitely will.  It's a lot of work, but it is mathematical research. &lt;br /&gt;&lt;br /&gt;Reviewing a patch is different than reviewing a math paper.  First, very often a patch fixes a subtle bug in Sage or introduces some new functionality.  If the patch fixes a subtle bug, then of course the fix itself could easily introduce a new subtle bug, or maybe not really fix the bug correctly, and the referee has to figure this out.  If the patch introduces new functionality, it could easily contain bugs, often bugs that the author of the patch hasn't thought about testing for.  Often when refereeing a patch, I bounce it back with a use case that exhibits a bug.   Some of the most common and dangerous patches are the ones that speed up existing code.   These are often some slight changes in a few places, which seem safe enough, and make some code a bit faster.  Last time I looked at one of these, I decided to loop over the first 100 obvious test cases -- about the 90th input crashed the new code (the old code worked fine on that example).   I would have never noticed that problem had I just read the patch and tried the tests included with it; it was thus critical for me to creatively think of new tests. &lt;br /&gt;&lt;br /&gt;Of course, when refereeing a math paper one also looks for subtle flaws and tests theorems for consistency, but still it has a different feel than refereeing a patch.&lt;br /&gt;And with refereeing patches there is also a &lt;i&gt;time window&lt;/i&gt;, which also a huge problem.  Patches stop working because the rest of the Sage system evolves past them -- math papers don't just stop working because somebody out there proves more theorems.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;What Should We Do?&lt;/h3&gt;&lt;br /&gt;As I said above, I believe that patch review is a major problem for the Sage project.  I think the best solution is that there be one person at any given time who acts as the "patch review manager".  This person could vary from month to month.    This position would be the analogue of release manager or more directly of the chief editor at a traditional journal.  Every few days, this person looks at the &lt;a href="http://trac.sagemath.org/sage_trac/report/10" target="_new"&gt;list of all patches that need review&lt;/a&gt; and goes through every single one, either pinging people about them, or refereeing them if possible.  Said person, must be bold enough to be able to understand code anywhere in Sage, and have a good sense of who can look at what.   If a person did that, I believe our patch review problem would be solved. &lt;br /&gt;&lt;br /&gt;If we don't do this, the Sage project will operate at reduced efficiency and new and experienced developers alike will get needlessly frustrated.  (NOTE: We currently &lt;i&gt;do&lt;/i&gt; have Michael Abshoff who does pretty much what I describe above, but he has other things he should be doing, since he is release manager.) The Sage project will have a harder time reaching its goal to be a viable alternative to Magma, Maple, Mathematica, and Matlab.   We have to work smarter and do a better job, for the sake of all the people out there currently &lt;b&gt;forced&lt;/b&gt; to use Magma, Maple, Mathematica, or Matlab, instead of an open source peer reviewed scientifically viable system like Sage aims to be.</description><link>http://sagemath.blogspot.com/2008/11/sage-patch-review.html</link><author>noreply@blogger.com (William Stein)</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-6365588202025292315.post-2740338901516193121</guid><pubDate>Mon, 24 Nov 2008 03:43:00 +0000</pubDate><atom:updated>2008-11-24T10:59:02.409-08:00</atom:updated><title>Magma and Sage</title><description>I spent the weekend working on making Sage and Magma talk to each other more robustly.  Getting different math software systems to talk to each other is a problem that the OpenMath project tried to tackle since the 1990s, but they failed.  Sage has out of necessity made real (rather than theoretical) progress toward this problem over the years, and what I did this weekend was a little step in the right direction for Sage. &lt;br /&gt;&lt;br /&gt;First, I designed with Michael Abshoff a new feature for our testing framework, so we can test only optional doctests that depend on a certain component or program being present.  Without a usable, efficient, and flexible testing system it is impossible to develop good code, so we had to do this.   Next, I worked on fixing the numerous issues with the current Sage/Magma interface, as evidenced by many existing doctests failing.  It was amusing because some of the doctests had clearly never ever succeeded, e.g., things like&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; sage: magma.eval('2')       # optional&lt;br /&gt; sage: other stuff&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;was in the tree, where the output was simply missing.&lt;br /&gt;&lt;br /&gt;Anyway, in fixing some of the much more interesting issues, for example, things like this that involve nested polynomial rings, I guess I came to understand better some of the subtleties of getting math software to talk with other math software.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sage: R.&amp;lt;x,y&gt; = QQ[]; S.&amp;lt;z,w&gt; = R[]; magma(x+z)&lt;br /&gt;boom&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The first important point is that one often &lt;i&gt;thinks&lt;/i&gt; that &lt;b&gt;the problem&lt;/b&gt; with interfacing between systems is given an object X in system (say Sage), finding a string s such that s evaluates in another system (say Magma) to something that "means the same thing" as X.   This is the problem that OpenMath attempt to solve (via XML and content dictionaries), but it is not quite the &lt;i&gt;right problem&lt;/i&gt;.   Instead, given a particular mathematical software system (e.g., Magma) in a particular state, and a view of that state by another system (e.g, Sage), the problem is to then come up with a string that evaluates to the "twin image" of X in the running Magma system.   &lt;br /&gt;&lt;br /&gt;To do this right involves careful use of caching.  Unless X is an atomic element (e.g., a simple thing like an integer) it's important to cache the version of X in Magma as an attribute of X itself.   Let's take an example where this caching is very important and subtle.  Consider our example above, which has the following Sage code as setup.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sage: R.&amp;lt;x,y&gt; = QQ[]&lt;br /&gt;sage: S.&amp;lt;z,w&gt; = R[]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This creates the nested polynomial ring (QQ[x,y])[z,w].   The new code in sage-3.2.1 (see &lt;a href="http://trac.sagemath.org/sage_trac/ticket/4601"&gt;#4601&lt;/a&gt;) does the following to convert x + z to &lt;i&gt;a particular&lt;/i&gt; Magma session.  Note that the steps to convert x+z to Magma depend on the state of a particular Magma session!   Anyway, Sage first gets the Magma version of S, then askes for the generator names of that object in the given Magma session. These are definitely &lt;b&gt;not&lt;/b&gt; z,w:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sage: m = magma(S)&lt;br /&gt;sage: m.gen_names()&lt;br /&gt;('_sage_[4]', '_sage_[5]')&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The key point is the strings returned by the gen_names command are strings that are valid in Magma and evaluate to each of the generators we're after.  They depend on time -- if you did stuff in the interface earlier you would get back different numbers (not 4 and 5).    Note that it's very important that the Python objects in Sage that _sage_[4] and _sage_[5] point to do not get garbage collected, since if they do then _sage_[4] and _sage_[5] also become invalid, which is not good. So it's important that the magma version (m above) of S is cached.   &lt;br /&gt;&lt;br /&gt;Next Sage gets the magma string version of each of the coefficients of the polynomial x+z (over the base ring R) using a similar process.  It all works very well without memory leaks, but only because of careful track of &lt;i&gt;state&lt;/i&gt; and &lt;i&gt;caching&lt;/i&gt;. &lt;br /&gt;And the resulting string expression involves the _sage_[...]'s. &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sage: (x+z)._magma_init_(magma)&lt;br /&gt;'((1/1)*1)*_sage_[4]+((1/1)*_sage_[7])*1'&lt;br /&gt;sage: magma(x+z)&lt;br /&gt;z + x&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Notice that _magma_init_ -- the function that produces the string that evaluates to something equal to x+z in magma -- now takes as input a particular Magma session (there can be dozens of these in a given Sage session, with different Magma's running on different computers all over the world).    This is a change to _magma_init_ that makes the implementation of what's described above easy.   It's an API change that might also be carried over to many of the other interfaces (?).</description><link>http://sagemath.blogspot.com/2008/11/magma-and-sage.html</link><author>noreply@blogger.com (William Stein)</author></item></channel></rss>