[sci.math.symbolic] A Mathematica question.

jeff@ndcheg.cheg.nd.edu (Jeffrey C. Kantor) (08/02/88)

After spending the weekend doing Mathematica, I thought I would post a
simple question.  Suppose you want to replace every element of a list
with a corresponding element of another list, i.e.,

expr /. {a,b,c,d}->{1,2,3,4}  (NOTE: NOT A VALID STATEMENT)

where -> works on an element-by-element basis.  What is the most efficient
way of doing this?  I hacked together a rather messy bit of code that is
not very efficient.  I was looking for a one-liner.

This came up when trying to get the RungeKutta Notebook to work for a system
of ODE's rather than a single ODE.


-- 
Jeff Kantor                      US Mail:  Department of Chemical Engineering
                                           University of Notre Dame
    uucp:  iuvax!ndmath!ndcheg!jeff        Notre Dame, IN   46556  USA
internet:  jeff@ndcheg.cheg.nd.edu

zardoz@Apple.COM (Phil Wayne) (08/04/88)

In article <605@ndcheg.cheg.nd.edu> jeff@ndcheg.cheg.nd.edu (Jeffrey C. Kantor) writes:
>After spending the weekend doing Mathematica, I thought I would post a
>simple question.  Suppose you want to replace every element of a list
>with a corresponding element of another list, i.e.,
>
>expr /. {a,b,c,d}->{1,2,3,4}  (NOTE: NOT A VALID STATEMENT)
>
>where -> works on an element-by-element basis.  What is the most efficient
>way of doing this?  I hacked together a rather messy bit of code that is
>not very efficient.  I was looking for a one-liner.
>
>This came up when trying to get the RungeKutta Notebook to work for a system
>of ODE's rather than a single ODE.
>

I hate to point this out but...

If both lists are the same length (which I assume they are) then if we have

x = { some list of elements... }
y = { some other list of elements of the same length as x... }

then the *EASY* *CHEAP* and *QUICK* way to do the replacement is...
(Ohhhh, god, how can I be this devious...)

x = y

Tah....Dahhhh

--- zardoz