MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: A Functional Programming Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24775] Re: [mg24705] A Functional Programming Question
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 10 Aug 2000 00:31:58 -0400 (EDT)
  • References: <8mqvlf$1ac@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

David,
I should have pointed out that my idea, which you use in

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

only works when the underlying functions have the attribute Listable. This
is so in your examples where the functions are Product, Addition, Power,
Sqrt.
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"David Park" <djmp at earthlink.net> wrote in message
news:8mqvlf$1ac at smc.vnet.net...
> 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: SetDirectory[ ] for Folders on the Mac Desktop?
  • Next by Date: Re: ArcCos[]
  • Previous by thread: RE: A Functional Programming Question
  • Next by thread: Re: running mathematica remotely