       ```Hi Groupers:

I've written a program to calculate the forces on charged particles. The
program works well except that parts are less than elegant.  The key
questions I have concern the Thread function:

==========================================

Question 1:
------------

In:=

Out=
{f[a,b],f[a,c]}

We see that if "a" does not have head "List" it is automatically
Now if a, b and c are defined as follows:

In:=
a={q1,{x1,y1,z1}};b={q2,{x2,y2,z2}};c={q3,{x3,y3,z3}};

I would LIKE to have the following output when I apply Thread:

{f[{q1,{x1,y1,z1}},{q2,{x2,y2,z2}}],f[{q1,{x1,y1,z1}},{q3,{x3,y3,z3}]}

In:=

Out=
{f[q1,{q2,{x2,y2,z2}}],f[{x1,y1,z1},{q3,{x3,y3,z3}}]}

Is there a way to force Thread to give me what I want?

================================================================ I can
make a workaround but its not very elegant:

In[ ]:=
t=Table[a,{2}];

Out[]=
{f[{q1,{x1,y1,z1}},{q2,{x2,y2,z2}}],f[{q1,{x1,y1,z1}},{q3,{x3,y3,z3}}]}

================================================================

Question 2:
-------------

I would like to be able to Thread g across two lists as follows:

In:=
ccs={a,b}; oc={x,y};

Out=
{g[a,x],g[b,y]}

But unfortunately, since ccs and oc are lists, and since g is designed
to operate on lists, g executes before the thread takes place.

If g is undefined everything is ok:

In:=

Out=
{g[{a1,a2},{x1,x2}],g[{b1,b2},{y1,y2}]}

If I now define g:

In:=
g[x1_List,x2_List]:=x1+x2^2

I would now LIKE the output of the Thread statement to be:

In:=
{g[{a1,a2},{x1,x2}],g[{b1,b2},{y1,y2}]}

Out=
{{a1 + x1^2, a2 + x2^2}, {b1 + y1^2, b2 + y2^2}}

In:=

Out=
{{a1 + x1^2, b1 + y1^2}, {a2 + x2^2, b2 + y2^2}}

The reason (I believe) is that the g function executes before the Thread
operates.  The function "List" is  threaded over the sublists as in the
following:

In:=
Thread[{{a1 + x1^2, a2 + x2^2}, {b1 + y1^2, b2 + y2^2}}]

Out=
{{a1 + x1^2, b1 + y1^2}, {a2 + x2^2, b2 + y2^2}}

Is there a way of forcing Thread to keep its argument unevaluated until
after it operates?

=============================================== I am currently using the
following workaround, but I don't like it:

In:=
Clear[f]

Out=
{{a1 + x1^2, a2 + x2^2}, {b1 + y1^2, b2 + y2^2}}
===============================================

Is there a better way?

Cheers,

Des Penny
Physical Science Dept.
Southern Utah University
Cedar City, UT 84720

Office: (435) 586-7708
FAX:  (435) 865-8051
email: penny@suu.edu

Home: (435) 586-2286
email: dpenny@iname.com

```

• Prev by Date: Re: Altering terms of an Expression
• Next by Date: Re: Display - Funkion
• Prev by thread: New version of OpenGL viewer for Mathematica