Constructing expressions
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg677] Constructing expressions
- From: Scott Herod <sherod at newton.Colorado.EDU>
- Date: Sat, 8 Apr 1995 13:03:24 -0600 (MDT)
Someone asked last night about a way to construct expressions of a certain type. I erased the message but then lay awake thinking about an answer. It is similar to some things that I have had to work out in the past. Anyway, here is a suggestion. I'm not sure if I am reproducing exactly what was asked for but hopefully it is close. Here is some code: Cat[a_,b_] := ToExpression[StringJoin[ ToString[a], ToString[b]]]; ddd[x_[k_]] := Apply[x,Table[Cat[x,i],{i,k}]]; ddd[x_[k_,j__]] := Apply[x, Table[ddd[Cat[x,i][j]],{i,k}]]; Here is an example: In[25]:= ddd[t[2,2]] Out[25]= t[t1[t11, t12], t2[t21, t22]] In[28]:= ddd[t[2,2,3]] Out[28]= t[t1[t11[t111, t112, t113], t12[t121, t122, t123]], t2[t21[t211, t212, t213], t22[t221, t222, t223]]] Scott Herod Applied Mathematics University of Colorado, Boulder sherod at newton.colorado.edu