RE: A Functional Programming Question

• To: mathgroup at smc.vnet.net
• Subject: [mg24734] RE: [mg24705] A Functional Programming Question
• From: "David Park" <djmp at earthlink.net>
• Date: Wed, 9 Aug 2000 02:31:35 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Thanks everybody for the replies.

I zeroed in on two of them, the one by Johannes Ludsteck and the one by
Allan Hayes because they seemed to be adaptable to a more general parallel
manipulation of equations.

Here is a somewhat more general set of parallel equations:

eqns = {(a1 x + b1)/c1 == 0, (a2 y + b2)/c2 == 0, (a3 z + b3)/c3 == 0};

Suppose that we wish to solve for the square roots of x, y and z.

Here is a routine which is an adaptation of Johannes method:

parallelmap[eqns_, op_, parms_] :=
MapThread[
Function[parm, Function[eq, op[#, parm] & /@ eq]][#2][#1] &, {eqns,
parms}]

We can now manipulate the equations in parallel, step-by-step.

parallelmap[eqns, #1#2 &, {c1, c2, c3}]
parallelmap[%, #1 - #2 &, {b1, b2, b3}]
parallelmap[%, #1/#2 &, {a1, a2, a3}]
parallelmap[%, Sqrt[#] &, {d, d, d}]

{b1 + a1 x == 0, b2 + a2 y == 0, b3 + a3 z == 0}
{a1 x == -b1, a2 y == -b2, a3 z == -b3}
{x == -(b1/a1), y == -(b2/a2), z == -(b3/a3)}
{Sqrt[x] == Sqrt[-(b1/a1)], Sqrt[y] == Sqrt[-(b2/a2)],
Sqrt[z] == Sqrt[-(b3/a3)]}

The last step works because the function only looks for one argument and we
can just put in dummy values for the second argument. Using Sqrt instead of
Sqrt[#]& will not work.

Working with Allan Hayes method, I came up with this routine:

parallelmap2[eqns_, op_, parms_] :=
Equal @@@ op[List @@@ eqns, parms]

parallelmap2[eqns2, #1*#2 & , {c1, c2, c3}]
parallelmap2[%, #1 - #2 & , {b1, b2, b3}]
parallelmap2[%, #1/#2 & , {a1, a2, a3}]
parallelmap2[%, Sqrt[#1] & , {d, d, d}]

gives the same answers.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

```

• Prev by Date: Re: Mathematica won't solve simple diff. eqn.--Correction
• Next by Date: Re: Simple Query
• Previous by thread: Re: A Functional Programming Question
• Next by thread: RE: A Functional Programming Question