       defining a function whose parameter must be a function with two parameters

• To: mathgroup at smc.vnet.net
• Subject: [mg130992] defining a function whose parameter must be a function with two parameters
• From: Roman <rschmied at gmail.com>
• Date: Sat, 1 Jun 2013 06:28:29 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-outx@smc.vnet.net
• Delivered-to: mathgroup-newsendx@smc.vnet.net

```Dear all,
I am trying to define a function F which will only execute if its parameter is a function with two parameters. Let's say I define it thus, without any checks on the parameter pattern f:

In := F[f_] := f[2,3]

There are several ways of calling F:
1) pass it a function of two parameters:
In := F[Function[{a,b},a^2-b^2]]
Out = -5

2) pass it an anonymous function of two parameters:
In := F[#1^2-#2^2 &]
Out = -5

3) pass it a pre-defined function:
In := g[a_,b_] = a^2-b^2;
In := F[g]
Out = -5

My question is: how can I define a pattern in the definition of F[f_] such that this function F will execute these three cases while not executing if called with any other kind of parameter? The following calls should fail, for example:

In := F[Function[{a,b,c},a^2-b^2-3c]]
Out = F[Function[{a,b,c},a^2-b^2-3c]]

In := F[#1^2-#2^2-3#3 &]
Out = F[#1^2-#2^2-3#3 &]

In := h[a_,b_,c_] = a^2-b^2-3c;
In := F[h]
Out = F[h]

Further, for bonus points, if there are multiple definitions of a function, I'd like to pick the one with two parameters:
In := k[a_,b_] = a^2-b^2;
In := k[a_,b_,c_] = a^2-b^2-3c;
In := F[k]
Out = -5

Thanks for any help!
Roman

```

• Prev by Date: Re: Help needed on how plot a stereographic projection
• Next by Date: Re: diffusion PDE
• Previous by thread: Re: Help needed on how plot a stereographic projection
• Next by thread: Re: defining a function whose parameter must be a function