[Haskell-cafe] Python?

Jacques Carette carette at mcmaster.ca
Wed May 11 16:51:57 EDT 2005


karczma at info.unicaen.fr wrote:
> Jacques Carette writes: 
> > Jerzy Karczmarczuk wrote:
> >> Syntax for 3D arrays?
> >> Give me one single language where this is natural and immediate.
> > 
> > I can think of 3: Mathematica, Maple and APL.
> 
> I can't see how Maple makes things more *natural and
> immediate* than Matlab *in this context*.

I claim that Maple (and Mathematica) are as natural and immediate as Matlab in the context of 2D arrays and matrices, 
and that (at least) Maple is more natural for n-dimensional arrays.

> Maple is rich, there are arrays, Arrays, Matrices (which are *not* multi-
> dimensional, only two), etc., based on rtables. In which sense rtables
> are more natural and immediate than multidim matrices in Matlab?
> Indexing is similar (Maple has a full plethora of adjustable indexing
> functions, but Matlab can achieve the same with the OO layer). 

You have put your finger on the reason: Maple's indexing into all objects that are an occurence of the family of 
"rectangular tables" (ie where the implementation data-structure is an rtable even though the abstract type might be 
Vector or Matrix or ...) is completely uniform, regardless of dimension.  In Matlab, you have no such abstract uniform 
interface - you have to build it yourself.

I have not looked too closely, but it appears that Mathematica offers something equivalent to Maple in this regard.

Matlab's weakness here is that the implementation (array) and the Abstract Data Type of a matrix are confounded into 
one.  In Maple, these are separate, with proper interfaces.  Of course, since it is Maple, users still have 100% 
access to the underlying implementation, for good or ill.

[Talk about initialization options]

> Why this is better than in Matlab?

I should have been clearer: I only claim at least as good as Matlab, with definite sub-cases where it is better.
  
> > Furthermore, for 'structured' matrices (including sparse), there are 
> > simple examples where both Mathematica and Maple are arbitrarily faster 
> > than Matlab on LU and QR decompositions, as well as Eigenvalue 
> > computations.   
> I would like to see some comparisons. Not that I don't believe you, but
> Matlab made some progress as well 

I don't have the time to get into detailed comparisons - and much to my horror, the internal white papers where lots 
of the leg work of doing these comparisons were never made public!  Here is a benchmark to try:
[Creates a random 30000 by 30000 matrix mb but with a banded 30-30 structure, a random 100000 vector v and solves mb*x 
= b.  Timing done on my slow Celeron laptop]
> with(LinearAlgebra):
> N:=30000: (bl,bu):=30,30:
> mb := RandomMatrix(N,outputoptions=[datatype=float,shape=band[bl,bu]]):
> v := RandomVector(N,outputoptions=[datatype=float]):
> infolevel[LinearAlgebra]:=2:
> st:=time(): LinearSolve(mb,v): time()-st;
LinearSolve:   "using method"   LU
LinearSolve:   "calling external function"
LinearSolve:   "CLAPACK"   hw_dgbtrf_
LinearSolve:   "CLAPACK"   hw_dgbtrs_

                                 1.062
[that is 1.062 seconds!]
Unless you have 6.8 Gigabytes of main memory on your computer, I would not attempt this in Matlab.


> (although all this "progress" is
> sometimes dubious, with the slowing-down of the interface, regression
> bugs, etc.; no system is ideal, Maple neither). 

All the mathematical systems suffer greatly (Maple included) from such extremely dubious "progress".  I find the new 
Maple interface close to unusable [luckily for me, work on that started after I had left the company ;-) ].  

The point I am trying to make is that being able to use extremely complex 'types' (like a Matrix has a band structure) 
is what allows Maple to beat Matlab.  And the proper use of concepts like ADTs and interfaces makes it easy to write 
uniform code even if the underlying 'type' varies greatly [There are 13 different internal rtable representations in 
Maple, not counting indexing functions, orientation, type-representation, etc -- but this is invisible to the user].

The big pain with Maple is that it is dynamically typed (this is Haskell-cafe after all!).  On the other hand, things 
like 'this is a banded(30,30) 30000x30000 matrix' still seem to be out of reach of Haskell  [because the tricks I have 
seen to encode numbers into types all make encoding the number 30000 completely unpalatable].

Jacques


More information about the Haskell-Cafe mailing list