Mathematica compatibility functions



[I sent this from the wrong address again, I can't figure out what
 rule my MUA is using. I canceled it the faulty post, but it might 
go through anyway. ]

> Yes, a rule that will generalize and be easy to apply would be
> good. If the identifiers are legal in Maxima, then maple_XXX, mma_XXX, with
> XXX exactly as it appears in the other language is a good choice.

I suppose you could also say "add an underscore between each cap
and lowercase letter and then lowercase the whole thing. Then
prepend 'mma_'. " But that is starting to look?complicated when compared
to the identity map.

Consider these

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]]]] ]];


mat2nten(mt,ddl) := block( [ddm:ddl,fmt:flatten(ensurelist(mt)),
? ? ?jm,lnd:Length(ddl)],
? for jm:1 thru lnd step 1 do
? ?if 0 = Length(dd[jm]) then ddm[jm]:[ddl[jm],ddl[jm] ],
? Fold(Partition,fmt,Most(reverse(flatten(Transpose(ddm))))));

The function above is a working example.

Compare to this

mat2nten(mt,ddl) := block( [ddm:ddl,fmt:flatten(ensurelist(mt)),
? ? ?jm,lnd:mma_Length(ddl)],
? for jm:1 thru lnd step 1 do
? ?if 0 = mma_Length(dd[jm]) then ddm[jm]:[ddl[jm],ddl[jm] ],
? mma_Fold(mma_Partition,fmt,mma_Most(reverse(flatten(mma_Transpose(ddm))))));

That's certainly uglier and harder to read, but not
prohibitively so. Probably worth the cost. Eventually
flatten and reverse would need compatibility layers as
well. Eg, in only one of the two calls to mma_Length, would
length() work rather than mma_Length(), but when
translating, it would be safer ?and easier to call
mma_Length every time.

John