Category Archives: Sage

Partial derivative notation in Sage

This post will explain the notation used to denote partial derivatives in the output from Sage.  It’s confusing at first, but a simple example will make it clear. Here is the input to Sage:

var('x y')
function('test', x, y)
show(test(x, y))
show(diff(test(x, y), x))
show(diff(test(x, y), x, 2))
show(diff(test(x, y), y))
show(diff(test(x, y), y, 2))

I defined a function of two variables called test.  When you run this in the notebook interface, you get:


The capital D denotes a derivative. The numbers in brackets indicate which variable the derivative is with respect to. In this example, 0 denotes x and 1 denotes y. The number of times a number is repeated indicates the order of the derivative. D[0] is the first derivative with respect to x, D[1] is the first derivative with respect to y, D[0,0] is the second derivative with respect to x and D[1,1] is the second derivative with respect to y.  Sage uses the same notation when typesetting equations in LaTeX, so you will have to do some manual typsetting if you want traditional partial derivative notation.

Why does Sage do it this way instead of using traditional notation?  The reason is that test is defined as a function of two variables, but Sage doesn’t know in advance what these variables will be.  test may be a function of two other functions, in which the chain rule would have to be used to display the derivatives correctly.  The extensive discussion that went into this design decision is archived in this thread.

If you’re new to Sage, I suggest you check out my Sage Beginner’s Guide.

Installing Sage 4.7 on CentOS 5

I recently upgraded my desktop workstation from an old 32-bit version of Gentoo to 64-bit CentOS 5.  I downloaded and installed the latest version of Sage, and the process went smoothly.

If you find this post helpful, please check out the Sage Beginner’s Guide at Packt Publishing.  Since I don’t use Sage every day, I actually refer to my own book on a regular basis!


Since CentOS is designed to be binary compatible with Red Hat Enterprise Linux, the correct binary to download is


Uncompress the file with tar xfz <filename>  The result is a huge directory (3.1Gb) with a self-contained version of Sage that can be run right where you uncompressed it.  As root, I moved the directory to /opt, changed ownership to root, and changed the name to sage-4.7.2.  I then edited the script /opt/sage-4.7.2/sage so that the variable SAGE_ROOT contains the correct path:


Run sage once as root to set the paths correctly.

Continue reading

Running Sage on Windows with VirtualBox

The easiest way to run Sage on Windows is with a virtual machine.  Sage is a collection of tools that were primarily developed for UNIX-based operating systems (such as Solaris or Mac OS X)  or UNIX-like operating systems (BSD, Linux, etc).  Since a standard Windows installation lacks many of the features provided by a UNIX-like environment, Sage is packaged as a Linux virtual machine.  You need free virtualization software–VMWare Player or VirtualBox–to run the virtual machine.  I find VMWare Player easier to work with, but it’s not an open-source solution.  VirtualBox is truly free software, but it’s also harder to configure.  When you download Sage, you can choose between a .ova file (for VirtualBox) or a zipped VMware virtual machine.  The easiest thing to do is choose the appropriate format for your VM.  However, it’s also possible to run the VMware image on Virtualbox, and I’ll show you how.

If you want to learn more about Sage, check out the Sage Beginner’s Guide from Packt Publishing.

Download, install, and run VirtualBox, and then click the “New” button to get started.  Also, unzip the .zip file that contains the VMware virtual machine.

VirtualBox Manager

Choose Linux and Ubuntu under OS Type:

Continue reading