SageMath is an open-source project to create mathematical software that is a free alternative to proprietary, closed-source packages. One way to access it on the Internet is through the SageMathcell server, where code can be entered and evaluated. It can also be accessed as a web service for situations requiring more interactive access to the data output.

The URL for accessing the web API is http://sagecell.sagemath.org/service. Appending a trailing slash to this URL produces a CORS error when retrieving data. The code to be executed must be URL encoded as a URL component, not a full URL. The encoded string is then POSTed to the server with a prefix code= and a JSON response returned with the result of the interaction.

Here is some simple JavaScript code to send a request to the server:

var xhr = new XMLHttpRequest();

xhr.onload = function() {

  var data = JSON.parse( xhr.response );
  callback( data.stdout );

};

xhr.open( 'POST', 'http://sagecell.sagemath.org/service', true );
xhr.setRequestHeader( 'content-type', 'application/x-www-form-urlencoded' );
xhr.send( 'code=' + encodeURIComponent( codeString ) );

The standard output is processed in the callback function.


Here is a simple interface for viewing the full JSON result returned by the server. Enter SageMath code in the input box and activate the button:


Output will go here

It appears to be necessary to include a print statement in the code in order for a result to appear in the standard output. Using a Python 3 print() function currently returns the enclosing parentheses as part of the standard output.

The server currently times out after thirty seconds, returning a success value of false.

If a URL-encoded query string is appended to the location of this page, it will be evaluated automatically as Python and the result will appear here:

Output will go here

Projects and presentations utilizing the SageMath web service:

Special Functions Explorer - SageMath

An interactive Three.js viewer for visualizing the real and imaginary parts of special functions in the complex plane. Includes most native SageMath functions of one variable and an index or modulus.

SageMath Online Integrator

A simple interface for evaluating indefinite integrals. To be compared with Wolfram’s legacy integrator.


Uploaded 2016.08.27 — Updated 2017.07.04 analyticphysics.com