search and replace in expression?




On Wed, 30 Dec 2009, Rui Maciel wrote:

< Let's say we have a list like the following:
< 
< (%i1) d:[d1,d2,d3,d4,d5,d6,d7,d8];
< (%o1)                     [d1, d2, d3, d4, d5, d6, d7, d8]
< 
< Let's suppose that I changed my mind and, instead of a list with variables 
< named d[0-8], I wish to have a list with variables named x[0-8] and two other 
< lists with variables named y[0-8] and z[0-8].

To create your list, try
d :  makelist(concat('d,i),i,1,8);

If you want to create new lists via substitution, then subst can do it
subst( makelist(concat('d,i)=concat('x,i),i,1,8), d );

although it is probably easier to create the list from scratch.

< 
< It would be great if instead of being forced to hand-write three new list 
< declarations it was possible to simply search for a pattern in a input command 
< (in this case it would be %i1), replace the search results with a new string 
< and execute the newly generated input strings.
< 
< So, does Maxima support that?
 
Yes, I believe that subst can handle most of your needs. If you have other, more 
specific questions/tasks, please ask.

Leo

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.