[SciPy-user] Python evangelism question: procedural programming

0 views
Skip to first unread message

Ryan Krauss

unread,
Aug 3, 2007, 10:55:17 AM8/3/07
to SciPy Users List
I have a colleague in our electrical engineering department who today
asked me "What's good about Python?". I responded with "What's bad
about Python?"

I am used to responding to engineering colleagues in terms of Python
vs Matlab, but this particular person uses Mathematica almost
exclusively. So, he wanted to know if Python could be used like
Mathematica in terms of writing rule and procedure based programs. I
don't know how difficult this would be.

I don't do this kind of work and think of Mathematica primarily as a
symbolic algebra language, so that Python could not easily replace it.

Does anyone have experience of coming from Mathematica to Python and
whether or not I should try and convince this person to pursue Python?

Thanks,

Ryan
_______________________________________________
SciPy-user mailing list
SciPy...@scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-user

Alan G Isaac

unread,
Aug 3, 2007, 11:29:39 AM8/3/07
to SciPy Users List
I tried Mathematica awhile back and found it clumsy
for anything that did not require symbolics.
This example gives the right flavor:
http://www.larssono.com/musings/matmatpy/index.html

Your friend can have both worlds and choose as needed:
http://library.wolfram.com/infocenter/MathSource/585/
http://library.wolfram.com/infocenter/MathSource/6622/

Cheers,
Alan Isaac

Gael Varoquaux

unread,
Aug 3, 2007, 11:34:41 AM8/3/07
to SciPy Users List
On Fri, Aug 03, 2007 at 09:55:17AM -0500, Ryan Krauss wrote:
> So, he wanted to know if Python could be used like Mathematica in
> terms of writing rule and procedure based programs. I don't know how
> difficult this would be.

I think I understand what he means. Python can almost be used like this,
but there is the UI missing. Ipython is currently working on a "notebook"
UI that would address this problem. I have developped my own workflow
using a home made script ("pyreport"
http://gael-varoquaux.info/computers/pyreport/ ) to approach this
workflow. Ultimately I want to merge this with ipython's effort in order
to get nice notebook functionnality with html and pdf output, but
xurrently I don't have time for this.

I am attaching a file that shows how I use Python with Pyreport (Python
file attached, pdf file on http://gael-varoquaux.info/FORT_MOT.pdf ). The file
also shows the limits of the approach, and for larger project I use more
modular programming. This example is a bit frightening because it has
really grown longer than a Mathematica script and is a bit too complex to
have in such a monolythic code, but it is the only thing I have around.
There are also some very simple examples on pyreport's page.

So I think the answer is that it is possible with Python, but the tools
are not very developped and only slow progress is made.

My 2 cents,

Gaėl

FORT_MOT.py

Reynaldo Baquerizo

unread,
Aug 3, 2007, 11:37:33 AM8/3/07
to SciPy Users List
Ryan Krauss escribió:

> I have a colleague in our electrical engineering department who today
> asked me "What's good about Python?". I responded with "What's bad
> about Python?"
>
> I am used to responding to engineering colleagues in terms of Python
> vs Matlab, but this particular person uses Mathematica almost
> exclusively. So, he wanted to know if Python could be used like
> Mathematica in terms of writing rule and procedure based programs. I
> don't know how difficult this would be.
>
> I don't do this kind of work and think of Mathematica primarily as a
> symbolic algebra language, so that Python could not easily replace it.
>
> Does anyone have experience of coming from Mathematica to Python and
> whether or not I should try and convince this person to pursue Python?
>
it might be of interest http://www.sagemath.org/

Cheers,

Fernando Perez

unread,
Aug 3, 2007, 12:40:57 PM8/3/07
to SciPy Users List
On 8/3/07, Gael Varoquaux <gael.va...@normalesup.org> wrote:
> On Fri, Aug 03, 2007 at 09:55:17AM -0500, Ryan Krauss wrote:
> > So, he wanted to know if Python could be used like Mathematica in
> > terms of writing rule and procedure based programs. I don't know how
> > difficult this would be.
>
> I think I understand what he means. Python can almost be used like this,
> but there is the UI missing. Ipython is currently working on a "notebook"
> UI that would address this problem. I have developped my own workflow
> using a home made script ("pyreport"
> http://gael-varoquaux.info/computers/pyreport/ ) to approach this
> workflow. Ultimately I want to merge this with ipython's effort in order
> to get nice notebook functionnality with html and pdf output, but
> xurrently I don't have time for this.

You better make time soon. Min has already written a plaintext dump
format for the notebook, you'll be getting an email about that in a
minute. We need you :)

But back to the OP, I think the issue Ryan's colleague has isn't
addressed by a notebook interface, nor by SAGE (as great as SAGE is).

Mathematica's programming model/language can be very tricky to wrap
your head around, but it allows you to do *phenomenal* things in very
concise way, that would be extremely clunky in Python or any other
language I can think of.

Mathematica is very lisp-ish in its model, and its syntax for building
complex programs can be quirky, and its encapsulation model is rather
poor. But for rule-based programming it's hard to beat, it exposes
every object it has in a completely uniform way so that you can do
abstract manipulations on them, and it has very rich transformation
facilities. Doing things like "take an arbitrarily nested object,
traverse it and replace every instance of '(x-y)^4' by a polynomial
over z^2" are one-liners in Mathematica.

Honestly I'd say that if Ryan's colleague has a lot of code like that,
Python is NOT the answer for him. Rather, he should learn to use
Python because it *complements* Mathematica very well. Python is
good, easy to use and convenient to work with precisely at many of the
things that Mathematica is clunky for. They obviously have a lot of
overlap, and I personally use Python where they overlap simply because
I'm more proficient in Python these days. I'm sure he could go for
Mathematica in that region for the same reasons.

But there is definitely a domain where Mathematica is simply
unbeatable, and that goes beyond the obvious triad of (notebook,
symbolics, easy-to-control pervasive arbitrary precision).

These days my working toolbox is more or less just Python+Mathematica,
for these very reasons (and Python obviously includes C/C++/Fortran as
needed for low-level/speed work).

HTH.

Cheers,

f

Ryan Krauss

unread,
Aug 3, 2007, 2:57:04 PM8/3/07
to SciPy Users List
Thanks for all the replies. I appreciate your thoughts.

No I have a dumb question: what is the easiest way to get him a link
to these responses, since he obviously doesn't subscribe to this list.
Does it take a few days to get into Gmane? Can he see the whole
thread there easily? Is there a better way?

Reynaldo Baquerizo

unread,
Aug 3, 2007, 3:04:39 PM8/3/07
to SciPy Users List
Ryan Krauss escribió:

> Thanks for all the replies. I appreciate your thoughts.
>
> No I have a dumb question: what is the easiest way to get him a link
> to these responses, since he obviously doesn't subscribe to this list.
> Does it take a few days to get into Gmane? Can he see the whole
> thread there easily? Is there a better way?
>
Here, they are
http://groups.google.com/group/scipy-user/browse_thread/thread/bed22a18231c7709/69da385e1951c1fc#69da385e1951c1fc

Ryan Krauss

unread,
Aug 3, 2007, 3:05:06 PM8/3/07
to SciPy Users List
Reply all
Reply to author
Forward
0 new messages