
Taming math and physics using SymPy [pdf] - ivan_ah
http://minireference.com/static/tutorials/sympy_tutorial.pdf
======
lutusp
It would have been useful to say that sympy means "symbolic Python" or, more
generally, "a symbolic mathematics library". This means one can submit
algebraic and differential equations to be solved, and sympy can solve a great
number of them.

[http://docs.sympy.org/dev/modules/solvers/solvers.html](http://docs.sympy.org/dev/modules/solvers/solvers.html)

~~~
JadeNB
> It would have been useful to say that sympy means "symbolic Python" or, more
> generally, "a symbolic mathematics library". This means one can submit
> algebraic and differential equations to be solved, and sympy can solve a
> great number of them.

I'm not sure I understand this comment; SymPy here is the name of the program
([http://sympy.org](http://sympy.org)), not the author's abbreviation. Surely
one need not explain the etymology of the name of a program in order to give a
tutorial on it?

If, on the other hand, you meant that it is good to learn how to use any sort
of symbolic mathematics library, not just SymPy, then that is certainly
true—but the author's advice appears to be quite specific to SymPy.

~~~
lutusp
> SymPy here is the name of the program
> ([http://sympy.org](http://sympy.org)), not the author's abbreviation.

It's not a program, it's the name of a Python library responsible for
mathematical functions:

[http://sympy.org/en/index.html](http://sympy.org/en/index.html)

Quote: "SymPy is a Python library for symbolic mathematics."

> Surely one need not explain the etymology of the name of a program in order
> to give a tutorial on it?

It's useful to know what these terms mean.

> ... but the author's advice appears to be quite specific to SymPy.

Yes, no problem there. SymPy's abilities appear in IPython
([http://en.wikipedia.org/wiki/IPython](http://en.wikipedia.org/wiki/IPython))
and Sage ([http://www.sagemath.org/](http://www.sagemath.org/)) to some extent
also -- I've been involved in these projects for years.

My Sage tutorial: [http://arachnoid.com/sage](http://arachnoid.com/sage)

My IPython tutorial:
[http://www.arachnoid.com/IPython](http://www.arachnoid.com/IPython)

My Python tutorial:
[http://www.arachnoid.com/python](http://www.arachnoid.com/python)

~~~
tjl
SymPy doesn't appear in IPython, but IPython is aware of SymPy if it's
installed so you can get nice printing of math in the notebook. Also, why link
to the Wikipedia page for IPython and not the homepage?

For most people, I'd actually recommend the use of the IPython notebook for
doing any SymPy work as you can get the nicely formatted math and inline
plots. If one is doing debugging, then you're better off in one of the Python
IDEs.

The PyDy guys who work on the sympy.mechanics module have done some nice
IPython worksheets.

The SymPy tutorial that's part of the SymPy docs isn't too bad and there's the
SymPy live shell so one can try things out.

While we've mostly moved away from IRC, we're now on Gitter and there's also
the mailing list if you have specific questions.

Note: I'm a SymPy developer (and a GSoC 2014 mentor).

------
zokier
> Special care is required when specifying rational numbers, because integer
> division might not produce the answer you want. In other words, Python will
> not automatically convert the answer to a floating point number, but instead
> round the answer to the closest integer

Note that this applies only to Python2, Py3k does float-division by default
and integer division with // operator:

    
    
        Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
        Type "help", "copyright", "credits" or "license" for more information.
        >>> 1/7
        0
        >>> from __future__ import division
        >>> 1/7
        0.14285714285714285
        >>> 1//7
        0
        >>>

~~~
tjl
There's a couple of other things you can do. Since those are Python integers,
you can specify a SymPy Integer instead with Integer(1)/7 instead. The other
thing you can do is S(1)/7\. Both of these should work.

------
jbarrow
I've never used SymPy, but after looking through the tutorial, it looks like a
nicer symbolic mathematical library than Theano. I know that the libraries
have different focuses; Theano is about speed and tensors, while SymPy appears
to be about algebra, but I would be interested in seeing if they have similar
capabilities.

~~~
krastanov
They are different projects with different goals, but some of the sympy team
do try to employ sympy's capabilities in order to help theano generate better
optimized code.

------
like_do_i_care
Python really is taking centre stage these days - glad to see. I still use R
sometimes, but my Python usage grows daily. Also nice I can stick a web front
end on things via Django or Flask.

~~~
tormeh
Maybe someday we can say goodbye to Matlab. So many toolboxes to replace,
though.

~~~
tjl
SciPy is the closer analog to Matlab. That said, it is missing many toolboxes.

------
dergachev
Good stuff, but maybe it would be nice to do a mini tutorial in the blog post
itself. I only like PDFs if I'm going to spend 20m+ reading something.

~~~
ivan_ah
Good idea. It would make a nice series of blog posts... though I must say the
easy-to-print PDF format has some nice things going for it too ;)

~~~
zokier
I think IPython notebook would be the best format for this.

~~~
lutusp
Complete agreement -- IPython is a nice, relatively lightweight mathematical
environment based on Python. Runs locally in a browser [EDIT: and command line
as well]. Easy to use. Free.

My IPython tutorial:
[http://www.arachnoid.com/IPython](http://www.arachnoid.com/IPython)

~~~
zokier
> Runs locally in a browser

And in terminal or a native Qt-based app. The Python runs always natively (ie
not in browser), notebook/browser is merely a frontend to it.

~~~
lutusp
Yes, thank you -- I edited my earlier post to reflect this.

------
Edmond
by the way your students might like jasymchat.com, it is a mobile web app for
jasymca..not as capable as sympy but ideal for undergrad work...shoot me a
message if you have any thoughts.

------
graycat
The PDF has

"Calculus is the study of the properties of functions."

Better would be:

Calculus is some mathematics for analyzing systems that change continuously,
usually over time. The first motivation, by Newton, was to analyze the motion
of the planets. Since then, calculus is central in nearly all of of physics,
most of engineering, a lot of chemistry, much of the rest of mathematics, and
also probability and statistics.

Calculus works, first, with real valued functions of a real variable. An
example would be the speed of a baseball as a function of time. Later calculus
works with real valued functions of several real variables.

The first important concept in calculus is 'rate of change' or the 'first
derivative' of a function.

The second important concept is the integral which in effect 'adds up'
changes. Integration can be used both to define and to find areas and volumes,
e.g., the volume or the surface area of a sphere. Or if apply a force of 500
pounds to a car weighing 3000 pounds, how much time will the car need to
accelerate from 0 to 60 MPH?

The fundamental theorem of calculus is that, with mild assumptions, if take
the first derivative of a function and integrate that, then get back the
original function.

Sometimes we have some information about the first derivative of a function
and want to find the function; in this way we have a start on the subject
differential equations. Some of the elementary parts of differential equations
are also in a first course in calculus.

Here is a simple differential equation: Suppose t denotes time in days and our
revenue per day is y(t). Suppose we know the revenue now, that is, at t = 0.
So, we know y(0). Suppose we believe that we will have saturated our market
when our revenue reaches b per day. Suppose we believe that the rate of growth
of revenue is directly proportional to both the number of our current
customers and also the number of our target customers we do not yet have.
Calculus denotes the rate of growth as y'(t). Then for some constant k we have

y'(t) = k y(t) (b - y(t))

Then with integration in calculus, we can find y(t). What we get, depending on
k, is a lazy S curve that rises slowly, then more rapidly, then slowly, and
approaches b from below. So, this is an elementary case of differential
equations. At one point, this differential equation and its solution kept
FedEx from going out of business.

Differential equations are important in calculating trajectories of space
craft, how to get a fighter jet to 60,000 feet in least time, the analysis of
analog circuits in electronic engineering, Maxwell's equations in electricity
and magnetism, the differential geometry of general relativity, Newton's
second law, the heat equation, the stiffness of beams, etc.

Calculus is one of the main pillars of mathematics, science, engineering,
technology, and civilization.

