# Expand List Operation

On applying a multiplication and subtraction on a list, like so:

x = 2y - 4;


Where y is a list containing fractions of complex numbers generated from dynamic input, instead of getting a new list with that operation applied to each element of the list, instead the output is simplified, in the form:

-4 + 2{element1, element2, element3, etc}


This means I can't then apply normal list functions to x. How can I convert this style of input into just one list:

{-4 + element1, -4 + element2, -4 + element3}


When I make y non-dynamic, it formats it correctly, so that seems to be part of the issue.

My exact code is this:

mirror[v_] := v^2
a = 3;
b = 4;
{Slider2D[Dynamic[{a, b}], {{-10, 0}, {10, 100}, 1}], Dynamic[{a, b}]}

y = Dynamic[Replace[t, Solve[-1/D[mirror[t], t] == (mirror[t] - b)/(t - a), t]]];
x = 2 y - a

• You do have a space (for multiplication) between 2 and y, right ? – b.gates.you.know.what May 4 '13 at 12:04
• It doesn't make any difference either way. – varkor May 4 '13 at 12:08
• Try making the multiplication explicit: x=2*y-4 – bill s May 4 '13 at 12:20
• @Varkor Maybe the issue is with the usage of Dynamic; could you post a more detailed example of your actual code ? – b.gates.you.know.what May 4 '13 at 12:43
• I think Dynamic is the issue. I've edited my post with the code I've used. – varkor May 4 '13 at 12:57

The head of y in your setup is Dynamic not List. That is why Plus and Times will not operate as you expected -- y is not a List. Perhaps this will have the behavior you seek:

mirror[v_] := v^2
a = 3;
b = 4;
{Slider2D[Dynamic[{a, b}], {{-10, 0}, {10, 100}, 1}], Dynamic[{a, b}]}

y := Replace[t, Solve[-1/D[mirror[t], t] == (mirror[t] - b)/(t - a), t]];
Dynamic[x = 2 y - a]


The general rule of thumb is to put Dynamic around what is to be displayed, not around component variables or expressions. (It is more complicated than this, of course, but most times, var = Dynamic[..] will not be the thing to do.)

Note also the use of SetDelayed (:=) in the assignment for y. This makes y represent a formula that is evaluated only when Dynamic[x = 2 y - a] is updated.

• Thank you! I was using Dynamic when I should have been using SetDelayed – it makes much more sense now! – varkor May 5 '13 at 11:08