RE: Function defined with If

• To: mathgroup at smc.vnet.net
• Subject: [mg71382] RE: [mg71338] Function defined with If
• From: "David Park" <djmp at earthlink.net>
• Date: Thu, 16 Nov 2006 00:53:24 -0500 (EST)

```Julián,

I'm not quite certain what you want to do. Suppose that a and b are
complicated expressions of x and y. Do you want f to be a function of x and
y, or of a and b? I am going to assume a function of x and y.

Then note the Attributes of If.

Attributes[If]
{HoldRest, Protected}

So in the f definition we have to evaluate the second and third arguments of
If.

a = x; b = y;
f[x_, y_] = If[a < b, Evaluate@a, Evaluate@b]
If[x < y, x, y]

David Park

From: Julian Aguirre [mailto:julian.aguirre at ehu.es]

Dear group,

I am trying to define a function of the variables x, y through other
quantities depending on x and y and the function If. A minimal example
is

In[1]:a = x;
b = y;
f[ x_, y_ ] = If[ a < b, a, b ]
Out[3]If[ x < y, a, b ]

How can I force Mathematica to return If[ x < y, x, y ], as I thought
it would?