Pure Functions
- To: mathgroup at smc.vnet.net
- Subject: [mg42551] Pure Functions
- From: Oliver Ruebenkoenig <ruebenko at imtek.uni-freiburg.de>
- Date: Tue, 15 Jul 2003 02:54:06 -0400 (EDT)
- Organization: Rechenzentrum der Universitaet Freiburg, Germany
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
I am looking for the solution to the following problem and am grateful
for any hints:
Consider the pure function:
In[1] := f = Function[ { x, y },
Function[ { a, b, c, d, e, f }, a*x + b *y + c + d + e + f] ];
I can then
In[2]:= f[ 2, 2 ]
Out[2]= Function[{a$, b$, c$, d$, e$, f$}, a$ 2 + b$ 2 + c$ + d$ + e$ +
f$]
The result is, as expected, another function. A complete call would look
like this:
In[3]:= f[ 2, 2 ][ 1, 2, 3, 4, 5, 6 ]
Out[3]= 24
Fine. Now i can for example differentiate
In[4]:= D[ f[ x, y ], { x, 1 } ]
Out[4]= Function[{a$, b$, c$, d$, e$, f$}, a$]
and a function is returned. Nice.
The problem is that i would like to use constructors and selectors to
create a new level of abstraction. For this reason i define
In[5]:= MakeMyHead[ a_, b_, c_, d_, e_, f_ ] := myHead[ a, b, c, d, e, f
];
and
In[6]:= GetTestValues[ myHead[ a_, b_, c_, d_, e_, f_ ] ] := { a, b, c, d,
e, f };
This works as follows:
In[7]:= example = MakeMyHead[ 1, 2, 3, 4, 5, 6 ]
Out[7]= myHead[1, 2, 3, 4, 5, 6]
and
In[8]:= GetTestValues[ example ]
Out[8]= {1, 2, 3, 4, 5, 6}
The problem is now that i would like a code that in pseudo code does this:
(* pseudo code
f = Function[ { x, y },
Function[ { mh_myHead },
Module[ { a, b, c, d, e, f }, { a, b, c, d, e, f } =
GetTestValues[ mh ]; a*x + b *y + c + d + e + f] ] ]
*)
a) Is it possible to hand over specific data types to functions, like myHead?
b) How can i create additional local variables in a function.
Differentiating the expression a*x + b*y + c... should be independent of
the value of the variables a,b,c,...
Any suggestions on how to do this? Much thanks in advance.
Oliver
NEW Phone number!
Oliver Ruebenkoenig, <ruebenko at imtek.de>
Phone: ++49 +761 203 7385