Matlab vs Python (was RE: Discussion: Introducing new operators for matrix computation)

Christopher Browne cbbrowne at news.hex.net
Mon Jul 17 21:29:16 EDT 2000


Centuries ago, Nostradamus foresaw a time when Paul Prescod would say: 
>Huaiyu Zhu wrote:
>> ...
>> As to the claim that additional operators for linear algebra is
>> somehow comparable to the special syntaxes/quirks of various
>> programming languages, no real argument has been presented so far. 
>
>Okay, then, let me try.
>
>> It's more like: If I don't care
>> and don't use such things, they must belong to a special domain and be
>> somehow comparable to some other things that I do know and dislike.
>
>Let me rephrase: "If MOST Python programmers don't care and don't use
>such things, they must belong to a special domain." I think that's a
>good operative definition of "domain specific". That's the crux of the
>argument. Don't throw complex numbers back in my face because they
>required *minimal new syntax*. There is already more "extra" syntax in
>the language for matrices than for complex numbers.
>
>I don't know why you have the impression that matrix operators have
>been compared to anything that people dislike. Most people have compared
>them to things that they *do* like, but must do through function syntax
>because Python doesn't pander to my particular needs or your particular
>needs, but rather those of most average programmers. I like XML 
>processing and I daresay there are more books sold on it than on 
>Matlab. But I've never asked for special, XML-specific syntax.
>
>Maybe you should consider how to scale back your syntactic request.
>Perhaps a single keyword or symbol at the beginning of an expression
>could make it element-wise or matrix-wise.

Another approach would be to create some form of "macro rewriting"
system that would allow you to feed in expressions in some
_descriptive_ form that would then rewrite this into (possibly
optimized) Python that would execute this.

By far the best comparison I can think of is the Common Lisp "Series"
implementation, findable at <http://series.sourceforge.net/>.

CL Series provides a "language" in which you can represent sequential
descriptions; it is described thus:

 "A series is a data structure much like a sequence, with similar
  kinds of operations. The difference is that in many situations,
  operations on series may be composed functionally and yet execute
  iteratively, without the need to construct intermediate series
  values explicitly. In this manner, series provide both the clarity
  of a functional programming style and the efficiency of an iterative
  programming style."

CL uses macro expansion to expand these into CL expressions, and this
expansion includes significant optimizations based on pipelining the
generation of series elements.  You might compose several series
together, and the final result will be computed in an optimized
(perhaps optimal) manner.

The result is that you write your original code using a _descriptive_
series representation, and the system rewrites that into code that
_performs_ the series operations.  

I would think the extension to what would be done in Python to be
"obvious;" the "Matrix Math" package would accept input in a modified
Python syntax that supports its matrix operators, and then rewrites
this to generate Python code that either:
  a) Expresses it iteratively, in Python form, or
  b) Expresses it using some compiled extensions that can make it Real
     Fast.
-- 
cbbrowne at hex.net - <http://www.hex.net/~cbbrowne/>
Necessity  is the  mother  of  invention. Insanity  is  the mother  of
straitjackets.



More information about the Python-list mailing list