Python and Math

B

Bill Cunningham

Does Python have good mathematical capabilities? I am interested in
learning a second language for mathematical purposes. I am considering
looking at python, perl, fortran, Adas out. It looked too complicated to
learn. Perl looked easy and I haven't really looked into python.

Bill
 
R

Rustom Mody

Does Python have good mathematical capabilities? I am interested in

learning a second language for mathematical purposes. I am considering

looking at python, perl, fortran, Adas out. It looked too complicated to

learn. Perl looked easy and I haven't really looked into python.

What does the word 'mathematical' connote for you?
On the whole the term is so wide that its hard to answer without some
more context.

For example there's numpy,scipy for numerical and scientific* computing, there's sage, ipython etc.


Today many people who want a general purpose programming language with
a mathematical flair, choose Haskell

For statistics R is quite unbeatable (I am told), which is not python
or any of the others you mention.

Then there are specialized theorem proving systems.

Another question you should answer is "Whats the first programming
language you know?"
 
C

Chris Angelico

Does Python have good mathematical capabilities? I am interested in
learning a second language for mathematical purposes. I am considering
looking at python, perl, fortran, Adas out. It looked too complicated to
learn. Perl looked easy and I haven't really looked into python.

Absolutely it does! In the built-in types, your integer has arbitrary
precision, and there is an arbitrary-precision Decimal type in the
standard library. There is also, naturally, a standard set of trig
functions and so on. With additional libraries, you can get numeric
and scientific functionality (lots of which is written in Fortran, as
I understand it), giving incredibly high performance for a high level
language; look into SciPy and NumPy. Strongly recommend Python for
numeric work.

ChrisA
 
G

Gary Herron

Does Python have good mathematical capabilities? I am interested in
learning a second language for mathematical purposes. I am considering
looking at python, perl, fortran, Adas out. It looked too complicated to
learn. Perl looked easy and I haven't really looked into python.

Bill

Depends on what you mean by mathematics. The language itself has a
reasonable set of numeric types and operations on those types, but what
really makes Python shine is the libraries built on Python and their
capabilities. Beside the several already mentioned, I'll add
Sage: www.sagemath.org/index.html
which presents a consistent Python interface to nearly 100 OpenSource
mathematical packages containing symbolic manipulation of all sorts of
algebra, calculus, linear algebra, plotting, rings and groups, and much
*much* more.

Gary Herron
 
S

Steven D'Aprano

Does Python have good mathematical capabilities? I am interested in
learning a second language for mathematical purposes. I am considering
looking at python, perl, fortran, Adas out. It looked too complicated to
learn. Perl looked easy and I haven't really looked into python.

Yes, Python is excellent for mathematics. Python is rapidly taking over
as the language of choice for scientific computing:

http://www.talyarkoni.org/blog/2013...hon-is-steadily-eating-other-languages-lunch/


You say you want to learn a *second* language, but you don't say what
your first language is. Nor do you say what sort of mathematics you wish
to do, or at what level. Depending on what you want to do, you might be
best off with Mathematica, if you can afford it. Otherwise, there's an
Open Source and free alternative, Sage, which uses Python.

You may find that the IPython interactive interface to Python is useful.
It presents an interface which should be familiar to anyone with
experience with Mathematica.

For symbolic maths, I like Sympy, where you can do things like this:


py> from sympy import *
py> x, y = symbols('x y')
py> diff(cos(3*x+1), x)
-3*sin(3*x + 1)
py> integrate(-3*sin(3*x+1), x)
cos(3*x + 1)


There is also Numpy and Scipy, for heavy-duty numerical mathematics.

I recommend that you start with Python 3.4, as it is the latest version
of Python, and also because I'm the author of the statistics standard
library. It's not a full-blown professional statistics language like R,
Matlab or SAS, but if you need basic scientific calculator level
statistics it is useful. Feedback on the library is always welcome.

As far as other languages go, I think that Fortran is still an excellent
language if you need to write high-powered, low-level numeric functions,
but if you just want to *use* pre-existing libraries, you are better off
with a high-level language like Python which offers interfaces to Fortran
libraries. Numpy and Scipy are very good for that.

As far as Perl goes, I find that it suffers from the same weakness as R:

http://www.talyarkoni.org/blog/2012/06/08/r-the-master-troll-of-statistical-languages/

that is, the learning curve is far to steep for my liking. I find Perl
too inconsistent, with far too many special cases and tricks, and not
enough of a consistent design. It's not as bad as PHP, but it gives me
the impression of a language where the only design principle is "Oh,
that looks cool. Hand me the welding iron, and I'll weld it on
somewhere. Anywhere will do."
 
B

Bill Cunningham

What does the word 'mathematical' connote for you?
On the whole the term is so wide that its hard to answer without some
more context.

For example there's numpy,scipy for numerical and scientific* computing,
there's sage, ipython etc.


Today many people who want a general purpose programming language with
a mathematical flair, choose Haskell

For statistics R is quite unbeatable (I am told), which is not python
or any of the others you mention.

Then there are specialized theorem proving systems.

Another question you should answer is "Whats the first programming
language you know?"

Well linear algebra and gaussian elemination. Expanding and factoring
equations of all degrees and identities. Not so much statistics. Some
geometry. Euclidean and spatial.

Bill
 
B

Bill Cunningham

You say you want to learn a *second* language, but you don't say what
your first language is. Nor do you say what sort of mathematics you wish
to do, or at what level. Depending on what you want to do, you might be
best off with Mathematica, if you can afford it. Otherwise, there's an
Open Source and free alternative, Sage, which uses Python.

I have spent a lot of time with C. But it's hard for me to learn and
there are various factors there. That sage looked good. But as a language
for *nixs and their respective APIs sockets, sys calls and such there's C.
Fortran might still be a choice. Perl looks really easy. But I haven't
gotten into any of these because I'm still halding out for one that appeals
to me.

Bill
 
R

Roy Smith

Steven D'Aprano said:
You may find that the IPython interactive interface to Python is useful.
It presents an interface which should be familiar to anyone with
experience with Mathematica.

I second the IPython suggestion. I don't use it that often, but when
I'm doing interactive number crunching, it's my tool of choice. The
ability to interactively go back and edit some block of code, then
re-execute it, is really handy when exploring a dataset. And the tight
integration of graphing/plotting libraries is awesome.

I tend to use it in the mode where I'm running the compute kernel on a
remote machine (typically a big machine in a data center somewhere) and
the display portion in a browser on my desktop.
 
M

Mark Lawrence

I second the IPython suggestion. I don't use it that often, but when
I'm doing interactive number crunching, it's my tool of choice. The
ability to interactively go back and edit some block of code, then
re-execute it, is really handy when exploring a dataset. And the tight
integration of graphing/plotting libraries is awesome.

Big +1 from me.
 
G

Grant Edwards

Does Python have good mathematical capabilities?

No.

It has very good numerical computation capabilities, but it does not
really do "math" (at least not what a mathemetician would consider
"math").
I am interested in learning a second language for mathematical
purposes.

If you want to do calculations on numbers (integral, real, complex,
vectors, matrixes), analyze and visualize data (stuff that was
traditionally done in Fortran), then Python is brilliant.

If you want to do "math" (as in the study of number theory,
topologies, proofs, and so on) then no. Python is not a good choice.
 
B

Bill Cunningham

Grant Edwards said:
No.

It has very good numerical computation capabilities, but it does not
really do "math" (at least not what a mathemetician would consider
"math").


If you want to do calculations on numbers (integral, real, complex,
vectors, matrixes), analyze and visualize data (stuff that was
traditionally done in Fortran), then Python is brilliant.

If you want to do "math" (as in the study of number theory,
topologies, proofs, and so on) then no. Python is not a good choice.

linear algebra, expanding and factoring equations of all degrees.
Geometry.

Bill
 
R

Robert Kern

No.

It has very good numerical computation capabilities, but it does not
really do "math" (at least not what a mathemetician would consider
"math").

Many mathematicians would disagree.

http://sagemath.org/

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
F

Fabien

Hi everyone,

I am new on this forum (I come from IDL and am starting to learn python)

This thread perfectly illustrates why Python is so scary to newcomers:
one question, three answers: yes, no, maybe.

Python-fans sure would argue "freedom of choice" is the most important,
but "being able to find the right tool for me in less than three days"
surely is important too. The paradox of choice ;-)

Fabien
 
R

Rustom Mody

Hi everyone,
I am new on this forum (I come from IDL and am starting to learn python)
This thread perfectly illustrates why Python is so scary to newcomers:
one question, three answers: yes, no, maybe.
Python-fans sure would argue "freedom of choice" is the most important,
but "being able to find the right tool for me in less than three days"
surely is important too. The paradox of choice ;-)

Point taken.

So let me try to give pointwise answers to the OP's questions

Expanding and factoring equations of all degrees:
http://docs.sympy.org/dev/modules/polys/wester.html

Numpy for gaussian elimination: https://gist.github.com/tkralphs/7554375
illustrates some of numpy's array-level features.

One thing about numpy that bugs me is that the docs never say how much
is taken straight from APL. So here is the APL (which I dont claim to understand):

http://dfns.dyalog.com/n_gauss_jordan.htm

Here is an online APL you can run straight from the browser:
http://baruchel.hd.free.fr/apps/apl/


The more general question:

It has very good numerical computation capabilities, but it does not
really do "math" (at least not what a mathemetician would consider
"math").

vs Robert's
Many mathematicians would disagree.

http://sagemath.org/

Traditionally mathematicians do two kinds of things - calculating and proving.
Normal mathematicians dont make too much of a distinction between the two.
The more extremists in the one camp look down - as usual - on the other thus:

The provers call the calculators as "Just applied not pure mathematicians"
The calculators say of the provers: "They are not mathematicians but logicians"
(or philosophers)" [Chris had a funny quote on this a few weeks ago]

After computers, a new area emerged - explorers - which straddles proving and calculating.

In short, Grant is speaking from the prover angle whereas Robert is speaking from the
calculator angle.

There is one more point here:

Does language-X (in this case python) have a theoretically sound (ie mathematical) foundation?

Mathematicians coming to CS never bother with this whereas computer scientists, especially
theoretical CSists, at some point or other invariably come to this.

Since its not clear whether this question is being asked, I'm not saying anything more on
it.
 
C

Chris Angelico

The provers call the calculators as "Just applied not pure mathematicians"
The calculators say of the provers: "They are not mathematicians but logicians"
(or philosophers)" [Chris had a funny quote on this a few weeks ago]

Which Chris? I don't remember either reading or writing such a quote,
and would like to. There are a good few Chrises on this list :)

ChrisA
 
R

Rustom Mody

The provers call the calculators as "Just applied not pure mathematicians"
The calculators say of the provers: "They are not mathematicians but logicians"
(or philosophers)" [Chris had a funny quote on this a few weeks ago]
Which Chris? I don't remember either reading or writing such a quote,
and would like to. There are a good few Chrises on this list :)

You!!
Something about mathematicians philosophers and waste-paper baskets
 
C

Chris Angelico

The provers call the calculators as "Just applied not pure mathematicians"
The calculators say of the provers: "They are not mathematicians but logicians"
(or philosophers)" [Chris had a funny quote on this a few weeks ago]
Which Chris? I don't remember either reading or writing such a quote,
and would like to. There are a good few Chrises on this list :)

You!!
Something about mathematicians philosophers and waste-paper baskets

Oh! Yes, I remember now. Old joke I found someplace. Physicists need
heaps of sensitive (and expensive) equipment... mathematicians need
only pencils, paper, and waste-paper baskets. And philosophers don't
even need waste-paper baskets.

ChrisA
 
G

Gene Heskett

On Mon, May 19, 2014 at 10:46 PM, Rustom Mody wrote:
The provers call the calculators as "Just applied not pure
mathematicians" The calculators say of the provers: "They are not
mathematicians but logicians" (or philosophers)" [Chris had a
funny quote on this a few weeks ago]

Which Chris? I don't remember either reading or writing such a
quote, and would like to. There are a good few Chrises on this list
:)

You!!
Something about mathematicians philosophers and waste-paper baskets

Oh! Yes, I remember now. Old joke I found someplace. Physicists need
heaps of sensitive (and expensive) equipment... mathematicians need
only pencils, paper, and waste-paper baskets. And philosophers don't
even need waste-paper baskets.

ChrisA

I gotta grin and like it, that does boil it down to the pure essence.

Cheers, Gene Heskett
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page <http://geneslinuxbox.net:6309/gene>
US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS
 
W

wxjmfauth

Le lundi 19 mai 2014 12:15:22 UTC+2, Fabien a écrit :
Hi everyone,



I am new on this forum (I come from IDL and am starting to learn python)



This thread perfectly illustrates why Python is so scary to newcomers:

one question, three answers: yes, no, maybe.



Python-fans sure would argue "freedom of choice" is the most important,

but "being able to find the right tool for me in less than three days"

surely is important too. The paradox of choice ;-)



Fabien

----------

Yesterday, I spent one hour attemepting to install IPython
for Py3.3 (win 7), I failed. I do not even succeed to
understand how. Pip, setuptools, whl or manualy with from the
zip... completely lost. There is always something not working.

This morning I installed Py 3.4.1. I do not even
succeed to put it to work.

I know Python since v 1.5.6 !

I'm able to write "Numerical Recipes" in Python,
(I did it in Py2 and Py3), I'm unable to install
a piece of software (like Python) to work with.

I'm just wondering if finally the better solution
is not to stick with an "MS C#".

jmf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top