The SymPy tutorial (1.3) in Julia

Table of contents

About SymPy.jl

The SymPy package for Julia allows Julia users to interact with python's SymPy module in a mostly seamless manner, thanks to the power of the PyCall package for Julia. The following pages reexpress the SymPy tutorial illustrating the associated Julia commands. There are some changes, but mostly modest ones.

The SymPy package for Julia essentially does:

Such objects may be created using the SymPy syntax:

using SymPy
x, y = symbols("x, y")
(x, y)

Alternatively, the @vars macro may be used:

@vars a b real=true
(a, b)
from sympy import *

This imports all functions and modules from the base sympy module into the user's namespace. By default, SymPy imports all functions from sympy – but no modules, as there would be several conflicts with fundamental Julia objects (e.g., Matrix). As such, modules must be qualified, as in sympy.Matrix. (SymPy exports the underlying sympy object.) For other modules, SymPy provides the function import_from to load functions from a given module.

The functions imported by SymPy are specialized so that their first argument is of symbolic type. This is not always appropriate, as some SymPy functions naturally take integer values for the first entry. An example is ones. Either the integer can be made symbolic (as with Sym(1)) or the function can be qualified, as in sympy.ones.

A quick example:

@vars x
A = [1 x; x x^3]  # Matrix{Sym}
using LinearAlgebra
A.shape, size(A)
((2, 2), (2, 2))