MathGroup Archive 2000

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

Search the Archive

RE: Functional Expression Meaning (was:A Functional Expression Trick)

  • To: mathgroup at
  • Subject: [mg23892] RE: Functional Expression Meaning (was:[mg23859] A Functional Expression Trick)
  • From: "David Park" <djmp at>
  • Date: Thu, 15 Jun 2000 00:51:31 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

Dear Hartmut,

It is always a good day when you reply to one of my postings. Then I learn
how things should be done.

I slightly rewrote your routine which changes a functional expression into a
function. I turned the unwanted error messages Off and On within the routine
and added a usage message. Here it is in plain text for those who may wish
to use it.

toFunc::usage =
    "toFunc[expr] will convert an expression of pure functions into a pure \
toFunc[expr_] :=
  e =
   Evaluate[expr /. {Function[({var__} | var_), body_] :> 
                Hold[body] /. 
                      Array[Slot, {Length[{var}]}]]]], 
            Function -> Hold}] &];

It might be of interest to see the problem that prompted my posting. The problem is the very first problem in the very first section of O'Neill's Elementary Differential Geometry. Here it is:

Let f = x^2 y and g = y Sin[z] be functions on E^3. Express the following functions in terms of x, y and z.
a) f g^2
b) (df/dx)g + (dg/dy)f
c) d^2(f g)/(dy dz)
d) (d Sin[f])/dy

Of course, one could just write f and g as expressions in x,y,z and perform the indicated operations. But the whole spirit of the discussion was in terms of representing things as functions which would be applied to a Euclidean point p. So O'Neill had definitions such as (f g)[p] = f[p]g[p], and he had introduced x,y and z as coordinate functions (x[px,py,pz]=px) and not as simple variables. So I wanted to do the problem in that spirit. I can't say how many times I have come back to this simple problem and never been satisfied. This is one of the things that Mathematica should be good at, and is good at, if we can only learn how to employ it properly. So this is how I would do it using your routine. I would be interested if others can present a clear approach which retains the functional flavor of the problem.

f := #1^2*#2 & 
g := #2*Sin[#3] & 
x := #1 & 
y := #2 & 
z := #3 & 

p = {px, py, pz};

toFunc[f*g^2][x, y, z]
toFunc[%] @@ p
(#1 & )^2*(#2 & )^3*Sin[#3 & ]^2

toFunc[Derivative[1, 0, 0][f]g + Derivative[0, 1, 0][g]f][x, y, z]
toFunc[%] @@ p
(#1 & )^2*(#2 & )*Sin[#3 & ] + 2*(#1 & )*(#2 & )^2*Sin[#3 & ]
px^2*py*Sin[pz] + 2*px*py^2*Sin[pz]

Derivative[0, 1, 1][toFunc[f g]][x, y, z]
toFunc[%] @@ p
2*Cos[#3 & ]*(#1 & )^2*(#2 & )

Derivative[0, 1, 0][toFunc[Sin[f]]][x, y, z]
toFunc[%] @@ p
Cos[(#1 & )^2*(#2 & )]*(#1 & )^2


Derivative[0, 1, 0][Composition[Sin, f ]][x, y, z]
toFunc[%] @@ p
Cos[(#1 & )^2*(#2 & )]*(#1 & )^2

Thanks again, Hartmut, for your valuable advice.

David Park
djmp at 

  • Prev by Date: System of lorenz equations
  • Next by Date: Re: Newbie question: pairswise function application
  • Previous by thread: Re: System of lorenz equations
  • Next by thread: RE: Functional Expression Meaning (was:A Functional Expression Trick)