Mathematica compatibility functions



Thanks for the advice Robert!

> >  Mma          Maxima
> >  -------------------
> >  Riffle        join
> >  Join          append
> >  Append        cons
> >  Union (lists) union (sets)

I read in the archives that you thought some Mma
names are poorly chosen. I have no doubt thats true.

But for the names above ?

  I have a collection of lists that I want to
  "Join" together.
  vs.
  I have a collection of lists that I want to
  "append" together.

  I want to "Append" this element to this list.
  vs.
  I want to "endcons" this element to  this list.
  (I mistakenly wrote cons above)
  
  I want to "Prepend" this element to this list.
  vs.
  I want to "cons" this element to  this list.

  I want to "Riffle"  these lists together
  vs.
  I want to "join" these lists together. (yes its unfortunate)

  "interleave" is better than either "Riffle" or "join".

But none of those names is going to change, so its "academic"!

I think choosing exactly the same names is advantageous for
two of my main goals. One is to make it as easy as possible
for a Mathematica user to begin dabbling and do somethig
useful with Maxima. If the function names are lower case, I
would still need a way to handle collisions like Append and
append, union and Union, etc. You need a set of rules
for how this is done.

The other is to make translating as easy as possible.  I
could remember the translation rules or look them up,
translate a user function, see that the output is wrong, deduce
from the output which rule I got wrong,  change it, see that
the output is finally right.

But, after I had crude versions of the functions, I was
able to shut my brain off and translate the following, and it
just worked.

mat2nten::usage = "mat2nten[mt,ddl] converts the (possibly
rectangular) matrix mt to an n-tensor using the double dimension list ddl,
with, e.g., {2,3,{4,5}} interpreted as {{2,2},{3,3},{4,5}}."
(*mat2nten:comment. Dimension list ddl is converted to ddm with every 
entry a two-component list, e.g.,  ddl={2,{3,4}}->ddm={{2,2},{3,4}}.*)
mat2nten[mt_,ddl_]:=Module[
{ddm=ddl,fmt=Flatten[mt],jm,lnd=Length[ddl]},
  For[jm=1,jm<=lnd,++jm, 
   If[  0==Length[ ddm[[jm]] ]  , ddm[[jm]]={ddl[[jm]],ddl[[jm]]}  ];  ];
   Fold[ Partition, fmt, Most[Reverse[Flatten[Transpose[ddm]]]] ]](*END 
mat2nten*)

mat2nten(mt,ddl) := block( [ddm:ddl,fmt:flatten(mt),jm,lnd:length(ddl)],
  for jm:1 thru lnd step 1 do
   if (not listp(ddm[jm])) then ddm[jm] : [ddl[jm],ddl[jm] ],
  Fold(Partition,fmt,Most(reverse(flatten(Transpose(ddm))))));

--John